2007-10-12 01:53:58 +04:00
/*
* Platform IDE driver
*
* Copyright ( C ) 2007 MontaVista Software
*
* Maintainer : Kumar Gala < galak @ kernel . crashing . org >
*
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation ; either version 2 of the License , or ( at your
* option ) any later version .
*/
# include <linux/types.h>
# include <linux/init.h>
# include <linux/kernel.h>
# include <linux/ide.h>
# include <linux/ioport.h>
# include <linux/module.h>
2008-02-02 02:02:30 +03:00
# include <linux/ata_platform.h>
2007-10-12 01:53:58 +04:00
# include <linux/platform_device.h>
# include <linux/io.h>
2008-01-26 22:13:05 +03:00
static void __devinit plat_ide_setup_ports ( hw_regs_t * hw ,
void __iomem * base ,
void __iomem * ctrl ,
struct pata_platform_info * pdata ,
int irq )
2007-10-12 01:53:58 +04:00
{
unsigned long port = ( unsigned long ) base ;
2007-10-20 02:32:31 +04:00
int i ;
2007-10-12 01:53:58 +04:00
2008-04-27 17:38:32 +04:00
hw - > io_ports . data_addr = port ;
2007-10-12 01:53:58 +04:00
port + = ( 1 < < pdata - > ioport_shift ) ;
2008-04-27 17:38:32 +04:00
for ( i = 1 ; i < = 7 ;
2007-10-12 01:53:58 +04:00
i + + , port + = ( 1 < < pdata - > ioport_shift ) )
2008-04-27 17:38:32 +04:00
hw - > io_ports_array [ i ] = port ;
2007-10-12 01:53:58 +04:00
2008-04-27 17:38:32 +04:00
hw - > io_ports . ctl_addr = ( unsigned long ) ctrl ;
2007-10-12 01:53:58 +04:00
2008-01-26 22:13:05 +03:00
hw - > irq = irq ;
2007-10-12 01:53:58 +04:00
2008-01-26 22:13:05 +03:00
hw - > chipset = ide_generic ;
2007-10-12 01:53:58 +04:00
}
2008-07-16 22:33:42 +04:00
static const struct ide_port_info platform_ide_port_info = {
. host_flags = IDE_HFLAG_NO_DMA ,
} ;
2007-10-12 01:53:58 +04:00
static int __devinit plat_ide_probe ( struct platform_device * pdev )
{
struct resource * res_base , * res_alt , * res_irq ;
2008-02-02 01:09:35 +03:00
void __iomem * base , * alt_base ;
2007-10-12 01:53:58 +04:00
struct pata_platform_info * pdata ;
2008-07-23 21:55:57 +04:00
struct ide_host * host ;
2008-07-23 21:55:50 +04:00
int ret = 0 , mmio = 0 ;
hw_regs_t hw , * hws [ ] = { & hw , NULL , NULL , NULL } ;
2008-07-16 22:33:42 +04:00
struct ide_port_info d = platform_ide_port_info ;
2007-10-12 01:53:58 +04:00
pdata = pdev - > dev . platform_data ;
/* get a pointer to the register memory */
res_base = platform_get_resource ( pdev , IORESOURCE_IO , 0 ) ;
res_alt = platform_get_resource ( pdev , IORESOURCE_IO , 1 ) ;
if ( ! res_base | | ! res_alt ) {
res_base = platform_get_resource ( pdev , IORESOURCE_MEM , 0 ) ;
res_alt = platform_get_resource ( pdev , IORESOURCE_MEM , 1 ) ;
if ( ! res_base | | ! res_alt ) {
ret = - ENOMEM ;
goto out ;
}
mmio = 1 ;
}
res_irq = platform_get_resource ( pdev , IORESOURCE_IRQ , 0 ) ;
if ( ! res_irq ) {
ret = - EINVAL ;
goto out ;
}
if ( mmio ) {
2008-02-02 01:09:35 +03:00
base = devm_ioremap ( & pdev - > dev ,
2007-10-12 01:53:58 +04:00
res_base - > start , res_base - > end - res_base - > start + 1 ) ;
2008-02-02 01:09:35 +03:00
alt_base = devm_ioremap ( & pdev - > dev ,
2007-10-12 01:53:58 +04:00
res_alt - > start , res_alt - > end - res_alt - > start + 1 ) ;
} else {
2008-02-02 01:09:35 +03:00
base = devm_ioport_map ( & pdev - > dev ,
2007-10-12 01:53:58 +04:00
res_base - > start , res_base - > end - res_base - > start + 1 ) ;
2008-02-02 01:09:35 +03:00
alt_base = devm_ioport_map ( & pdev - > dev ,
2007-10-12 01:53:58 +04:00
res_alt - > start , res_alt - > end - res_alt - > start + 1 ) ;
}
2008-01-26 22:13:05 +03:00
memset ( & hw , 0 , sizeof ( hw ) ) ;
2008-02-02 01:09:35 +03:00
plat_ide_setup_ports ( & hw , base , alt_base , pdata , res_irq - > start ) ;
2008-01-26 22:13:05 +03:00
hw . dev = & pdev - > dev ;
2008-07-23 21:55:54 +04:00
if ( mmio )
2008-07-16 22:33:42 +04:00
d . host_flags | = IDE_HFLAG_MMIO ;
2008-01-26 22:13:05 +03:00
ide: add ide_host_add() helper
Add ide_host_add() helper which does ide_host_alloc()+ide_host_register(),
then convert ide_setup_pci_device[s](), ide_legacy_device_add() and some
host drivers to use it.
While at it:
* Fix ide_setup_pci_device[s](), ide_arm.c, gayle.c, ide-4drives.c,
macide.c, q40ide.c, cmd640.c and cs5520.c to return correct error value.
* -ENOENT -> -ENOMEM in rapide.c, ide-h8300.c, ide-generic.c, au1xxx-ide.c
and pmac.c
* -ENODEV -> -ENOMEM in palm_bk3710.c, ide_platform.c and delkin_cb.c
* -1 -> -ENOMEM in ide-pnp.c
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
2008-07-23 21:55:57 +04:00
ret = ide_host_add ( & d , hws , & host ) ;
if ( ret )
2008-07-23 21:55:57 +04:00
goto out ;
2007-10-12 01:53:58 +04:00
2008-07-23 21:55:57 +04:00
platform_set_drvdata ( pdev , host ) ;
2007-10-12 01:53:58 +04:00
return 0 ;
out :
return ret ;
}
static int __devexit plat_ide_remove ( struct platform_device * pdev )
{
2008-07-23 21:55:57 +04:00
struct ide_host * host = pdev - > dev . driver_data ;
2007-10-12 01:53:58 +04:00
2008-07-23 21:55:57 +04:00
ide_host_remove ( host ) ;
2007-10-12 01:53:58 +04:00
return 0 ;
}
static struct platform_driver platform_ide_driver = {
. driver = {
. name = " pata_platform " ,
2008-04-19 00:41:57 +04:00
. owner = THIS_MODULE ,
2007-10-12 01:53:58 +04:00
} ,
. probe = plat_ide_probe ,
. remove = __devexit_p ( plat_ide_remove ) ,
} ;
static int __init platform_ide_init ( void )
{
return platform_driver_register ( & platform_ide_driver ) ;
}
static void __exit platform_ide_exit ( void )
{
platform_driver_unregister ( & platform_ide_driver ) ;
}
MODULE_DESCRIPTION ( " Platform IDE driver " ) ;
MODULE_LICENSE ( " GPL " ) ;
2008-04-19 00:41:57 +04:00
MODULE_ALIAS ( " platform:pata_platform " ) ;
2007-10-12 01:53:58 +04:00
module_init ( platform_ide_init ) ;
module_exit ( platform_ide_exit ) ;