2007-10-11 21:53:58 +00: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-01 23:02:30 +00:00
|
|
|
#include <linux/ata_platform.h>
|
2007-10-11 21:53:58 +00:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
|
2009-05-17 17:12:25 +00:00
|
|
|
static void __devinit plat_ide_setup_ports(struct ide_hw *hw,
|
2008-01-26 19:13:05 +00:00
|
|
|
void __iomem *base,
|
|
|
|
void __iomem *ctrl,
|
|
|
|
struct pata_platform_info *pdata,
|
|
|
|
int irq)
|
2007-10-11 21:53:58 +00:00
|
|
|
{
|
|
|
|
unsigned long port = (unsigned long)base;
|
2007-10-19 22:32:31 +00:00
|
|
|
int i;
|
2007-10-11 21:53:58 +00:00
|
|
|
|
2008-04-27 13:38:32 +00:00
|
|
|
hw->io_ports.data_addr = port;
|
2007-10-11 21:53:58 +00:00
|
|
|
|
|
|
|
port += (1 << pdata->ioport_shift);
|
2008-04-27 13:38:32 +00:00
|
|
|
for (i = 1; i <= 7;
|
2007-10-11 21:53:58 +00:00
|
|
|
i++, port += (1 << pdata->ioport_shift))
|
2008-04-27 13:38:32 +00:00
|
|
|
hw->io_ports_array[i] = port;
|
2007-10-11 21:53:58 +00:00
|
|
|
|
2008-04-27 13:38:32 +00:00
|
|
|
hw->io_ports.ctl_addr = (unsigned long)ctrl;
|
2007-10-11 21:53:58 +00:00
|
|
|
|
2008-01-26 19:13:05 +00:00
|
|
|
hw->irq = irq;
|
2007-10-11 21:53:58 +00:00
|
|
|
}
|
|
|
|
|
2008-07-16 18:33:42 +00:00
|
|
|
static const struct ide_port_info platform_ide_port_info = {
|
|
|
|
.host_flags = IDE_HFLAG_NO_DMA,
|
2009-05-17 17:12:22 +00:00
|
|
|
.chipset = ide_generic,
|
2008-07-16 18:33:42 +00:00
|
|
|
};
|
|
|
|
|
2007-10-11 21:53:58 +00:00
|
|
|
static int __devinit plat_ide_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct resource *res_base, *res_alt, *res_irq;
|
2008-02-01 22:09:35 +00:00
|
|
|
void __iomem *base, *alt_base;
|
2007-10-11 21:53:58 +00:00
|
|
|
struct pata_platform_info *pdata;
|
2008-07-23 17:55:57 +00:00
|
|
|
struct ide_host *host;
|
2008-07-23 17:55:50 +00:00
|
|
|
int ret = 0, mmio = 0;
|
2009-05-17 17:12:25 +00:00
|
|
|
struct ide_hw hw, *hws[] = { &hw };
|
2008-07-16 18:33:42 +00:00
|
|
|
struct ide_port_info d = platform_ide_port_info;
|
2007-10-11 21:53:58 +00: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-01 22:09:35 +00:00
|
|
|
base = devm_ioremap(&pdev->dev,
|
2007-10-11 21:53:58 +00:00
|
|
|
res_base->start, res_base->end - res_base->start + 1);
|
2008-02-01 22:09:35 +00:00
|
|
|
alt_base = devm_ioremap(&pdev->dev,
|
2007-10-11 21:53:58 +00:00
|
|
|
res_alt->start, res_alt->end - res_alt->start + 1);
|
|
|
|
} else {
|
2008-02-01 22:09:35 +00:00
|
|
|
base = devm_ioport_map(&pdev->dev,
|
2007-10-11 21:53:58 +00:00
|
|
|
res_base->start, res_base->end - res_base->start + 1);
|
2008-02-01 22:09:35 +00:00
|
|
|
alt_base = devm_ioport_map(&pdev->dev,
|
2007-10-11 21:53:58 +00:00
|
|
|
res_alt->start, res_alt->end - res_alt->start + 1);
|
|
|
|
}
|
|
|
|
|
2008-01-26 19:13:05 +00:00
|
|
|
memset(&hw, 0, sizeof(hw));
|
2008-02-01 22:09:35 +00:00
|
|
|
plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
|
2008-01-26 19:13:05 +00:00
|
|
|
hw.dev = &pdev->dev;
|
|
|
|
|
2008-07-23 17:55:54 +00:00
|
|
|
if (mmio)
|
2008-07-16 18:33:42 +00:00
|
|
|
d.host_flags |= IDE_HFLAG_MMIO;
|
2008-01-26 19:13:05 +00:00
|
|
|
|
2009-05-17 17:12:24 +00:00
|
|
|
ret = ide_host_add(&d, hws, 1, &host);
|
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 17:55:57 +00:00
|
|
|
if (ret)
|
2008-07-23 17:55:57 +00:00
|
|
|
goto out;
|
2007-10-11 21:53:58 +00:00
|
|
|
|
2008-07-23 17:55:57 +00:00
|
|
|
platform_set_drvdata(pdev, host);
|
2007-10-11 21:53:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit plat_ide_remove(struct platform_device *pdev)
|
|
|
|
{
|
2009-04-30 21:43:31 +00:00
|
|
|
struct ide_host *host = dev_get_drvdata(&pdev->dev);
|
2007-10-11 21:53:58 +00:00
|
|
|
|
2008-07-23 17:55:57 +00:00
|
|
|
ide_host_remove(host);
|
2007-10-11 21:53:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver platform_ide_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "pata_platform",
|
2008-04-18 20:41:57 +00:00
|
|
|
.owner = THIS_MODULE,
|
2007-10-11 21:53:58 +00: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-18 20:41:57 +00:00
|
|
|
MODULE_ALIAS("platform:pata_platform");
|
2007-10-11 21:53:58 +00:00
|
|
|
|
|
|
|
module_init(platform_ide_init);
|
|
|
|
module_exit(platform_ide_exit);
|