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>
|
2011-08-04 08:29:51 +00:00
|
|
|
#include <linux/interrupt.h>
|
2007-10-11 21:53:58 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
|
2012-12-21 21:21:03 +00:00
|
|
|
static void plat_ide_setup_ports(struct ide_hw *hw, 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
|
|
|
};
|
|
|
|
|
2012-12-21 21:21:03 +00:00
|
|
|
static int plat_ide_probe(struct platform_device *pdev)
|
2007-10-11 21:53:58 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2013-07-30 08:16:47 +00:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2007-10-11 21:53:58 +00:00
|
|
|
|
|
|
|
/* 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,
|
2009-11-23 18:30:34 +00:00
|
|
|
res_base->start, resource_size(res_base));
|
2008-02-01 22:09:35 +00:00
|
|
|
alt_base = devm_ioremap(&pdev->dev,
|
2009-11-23 18:30:34 +00:00
|
|
|
res_alt->start, resource_size(res_alt));
|
2007-10-11 21:53:58 +00:00
|
|
|
} else {
|
2008-02-01 22:09:35 +00:00
|
|
|
base = devm_ioport_map(&pdev->dev,
|
2009-11-23 18:30:34 +00:00
|
|
|
res_base->start, resource_size(res_base));
|
2008-02-01 22:09:35 +00:00
|
|
|
alt_base = devm_ioport_map(&pdev->dev,
|
2009-11-23 18:30:34 +00:00
|
|
|
res_alt->start, resource_size(res_alt));
|
2007-10-11 21:53:58 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2011-08-04 08:29:51 +00:00
|
|
|
d.irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
|
|
|
|
if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE)
|
|
|
|
d.irq_flags |= IRQF_SHARED;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-12-21 21:21:03 +00:00
|
|
|
static int plat_ide_remove(struct platform_device *pdev)
|
2007-10-11 21:53:58 +00:00
|
|
|
{
|
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",
|
|
|
|
},
|
|
|
|
.probe = plat_ide_probe,
|
2012-12-21 21:21:03 +00:00
|
|
|
.remove = plat_ide_remove,
|
2007-10-11 21:53:58 +00:00
|
|
|
};
|
|
|
|
|
2014-04-09 07:28:01 +00:00
|
|
|
module_platform_driver(platform_ide_driver);
|
2007-10-11 21:53:58 +00:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Platform IDE driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-18 20:41:57 +00:00
|
|
|
MODULE_ALIAS("platform:pata_platform");
|