1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2007 MontaVista Software
7 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
10 #include <linux/types.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/ide.h>
14 #include <linux/ioport.h>
15 #include <linux/module.h>
16 #include <linux/ata_platform.h>
17 #include <linux/platform_device.h>
18 #include <linux/interrupt.h>
21 static void plat_ide_setup_ports(struct ide_hw *hw, void __iomem *base,
23 struct pata_platform_info *pdata, int irq)
25 unsigned long port = (unsigned long)base;
28 hw->io_ports.data_addr = port;
30 port += (1 << pdata->ioport_shift);
32 i++, port += (1 << pdata->ioport_shift))
33 hw->io_ports_array[i] = port;
35 hw->io_ports.ctl_addr = (unsigned long)ctrl;
40 static const struct ide_port_info platform_ide_port_info = {
41 .host_flags = IDE_HFLAG_NO_DMA,
42 .chipset = ide_generic,
45 static int plat_ide_probe(struct platform_device *pdev)
47 struct resource *res_base, *res_alt, *res_irq;
48 void __iomem *base, *alt_base;
49 struct pata_platform_info *pdata;
50 struct ide_host *host;
51 int ret = 0, mmio = 0;
52 struct ide_hw hw, *hws[] = { &hw };
53 struct ide_port_info d = platform_ide_port_info;
55 pdata = dev_get_platdata(&pdev->dev);
57 /* get a pointer to the register memory */
58 res_base = platform_get_resource(pdev, IORESOURCE_IO, 0);
59 res_alt = platform_get_resource(pdev, IORESOURCE_IO, 1);
61 if (!res_base || !res_alt) {
62 res_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
63 res_alt = platform_get_resource(pdev, IORESOURCE_MEM, 1);
64 if (!res_base || !res_alt) {
71 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
78 base = devm_ioremap(&pdev->dev,
79 res_base->start, resource_size(res_base));
80 alt_base = devm_ioremap(&pdev->dev,
81 res_alt->start, resource_size(res_alt));
83 base = devm_ioport_map(&pdev->dev,
84 res_base->start, resource_size(res_base));
85 alt_base = devm_ioport_map(&pdev->dev,
86 res_alt->start, resource_size(res_alt));
89 memset(&hw, 0, sizeof(hw));
90 plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
93 d.irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
94 if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE)
95 d.irq_flags |= IRQF_SHARED;
98 d.host_flags |= IDE_HFLAG_MMIO;
100 ret = ide_host_add(&d, hws, 1, &host);
104 platform_set_drvdata(pdev, host);
112 static int plat_ide_remove(struct platform_device *pdev)
114 struct ide_host *host = dev_get_drvdata(&pdev->dev);
116 ide_host_remove(host);
121 static struct platform_driver platform_ide_driver = {
123 .name = "pata_platform",
125 .probe = plat_ide_probe,
126 .remove = plat_ide_remove,
129 module_platform_driver(platform_ide_driver);
131 MODULE_DESCRIPTION("Platform IDE driver");
132 MODULE_LICENSE("GPL");
133 MODULE_ALIAS("platform:pata_platform");