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