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