Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / ide / ide_platform.c
blob91639fd6c276bb9a321410e636d3ed36833d37c0
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Platform IDE driver
5 * Copyright (C) 2007 MontaVista Software
7 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
8 */
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>
19 #include <linux/io.h>
21 static void plat_ide_setup_ports(struct ide_hw *hw, void __iomem *base,
22 void __iomem *ctrl,
23 struct pata_platform_info *pdata, int irq)
25 unsigned long port = (unsigned long)base;
26 int i;
28 hw->io_ports.data_addr = port;
30 port += (1 << pdata->ioport_shift);
31 for (i = 1; i <= 7;
32 i++, port += (1 << pdata->ioport_shift))
33 hw->io_ports_array[i] = port;
35 hw->io_ports.ctl_addr = (unsigned long)ctrl;
37 hw->irq = irq;
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) {
65 ret = -ENOMEM;
66 goto out;
68 mmio = 1;
71 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
72 if (!res_irq) {
73 ret = -EINVAL;
74 goto out;
77 if (mmio) {
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));
82 } else {
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);
91 hw.dev = &pdev->dev;
93 d.irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
94 if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE)
95 d.irq_flags |= IRQF_SHARED;
97 if (mmio)
98 d.host_flags |= IDE_HFLAG_MMIO;
100 ret = ide_host_add(&d, hws, 1, &host);
101 if (ret)
102 goto out;
104 platform_set_drvdata(pdev, host);
106 return 0;
108 out:
109 return ret;
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);
118 return 0;
121 static struct platform_driver platform_ide_driver = {
122 .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");