Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Platform IDE driver |
| 4 | * |
| 5 | * Copyright (C) 2007 MontaVista Software |
| 6 | * |
| 7 | * Maintainer: Kumar Gala <galak@kernel.crashing.org> |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 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> |
Jeff Garzik | 0a87e3e | 2008-02-01 18:02:30 -0500 | [diff] [blame] | 16 | #include <linux/ata_platform.h> |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Thomas Gleixner | 89e9aad | 2011-08-04 01:29:51 -0700 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 19 | #include <linux/io.h> |
| 20 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 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) |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 24 | { |
| 25 | unsigned long port = (unsigned long)base; |
Bartlomiej Zolnierkiewicz | baa8f3e | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 26 | int i; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 27 | |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 28 | hw->io_ports.data_addr = port; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 29 | |
| 30 | port += (1 << pdata->ioport_shift); |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 31 | for (i = 1; i <= 7; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 32 | i++, port += (1 << pdata->ioport_shift)) |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 33 | hw->io_ports_array[i] = port; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 34 | |
Bartlomiej Zolnierkiewicz | 4c3032d | 2008-04-27 15:38:32 +0200 | [diff] [blame] | 35 | hw->io_ports.ctl_addr = (unsigned long)ctrl; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 36 | |
Bartlomiej Zolnierkiewicz | 57c802e | 2008-01-26 20:13:05 +0100 | [diff] [blame] | 37 | hw->irq = irq; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Bartlomiej Zolnierkiewicz | 7b60fa1 | 2008-07-16 20:33:42 +0200 | [diff] [blame] | 40 | static const struct ide_port_info platform_ide_port_info = { |
| 41 | .host_flags = IDE_HFLAG_NO_DMA, |
Bartlomiej Zolnierkiewicz | 29e52cf | 2009-05-17 19:12:22 +0200 | [diff] [blame] | 42 | .chipset = ide_generic, |
Bartlomiej Zolnierkiewicz | 7b60fa1 | 2008-07-16 20:33:42 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 45 | static int plat_ide_probe(struct platform_device *pdev) |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 46 | { |
| 47 | struct resource *res_base, *res_alt, *res_irq; |
Bartlomiej Zolnierkiewicz | 0424493 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 48 | void __iomem *base, *alt_base; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 49 | struct pata_platform_info *pdata; |
Bartlomiej Zolnierkiewicz | 48c3c10 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 50 | struct ide_host *host; |
Bartlomiej Zolnierkiewicz | c97c6ac | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 51 | int ret = 0, mmio = 0; |
Bartlomiej Zolnierkiewicz | 9f36d31 | 2009-05-17 19:12:25 +0200 | [diff] [blame] | 52 | struct ide_hw hw, *hws[] = { &hw }; |
Bartlomiej Zolnierkiewicz | 7b60fa1 | 2008-07-16 20:33:42 +0200 | [diff] [blame] | 53 | struct ide_port_info d = platform_ide_port_info; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 54 | |
Jingoo Han | 7b6b561 | 2013-07-30 17:16:47 +0900 | [diff] [blame] | 55 | pdata = dev_get_platdata(&pdev->dev); |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 56 | |
| 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); |
| 60 | |
| 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; |
| 67 | } |
| 68 | mmio = 1; |
| 69 | } |
| 70 | |
| 71 | res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 72 | if (!res_irq) { |
| 73 | ret = -EINVAL; |
| 74 | goto out; |
| 75 | } |
| 76 | |
| 77 | if (mmio) { |
Bartlomiej Zolnierkiewicz | 0424493 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 78 | base = devm_ioremap(&pdev->dev, |
H Hartley Sweeten | 30433d8 | 2009-11-23 10:30:34 -0800 | [diff] [blame] | 79 | res_base->start, resource_size(res_base)); |
Bartlomiej Zolnierkiewicz | 0424493 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 80 | alt_base = devm_ioremap(&pdev->dev, |
H Hartley Sweeten | 30433d8 | 2009-11-23 10:30:34 -0800 | [diff] [blame] | 81 | res_alt->start, resource_size(res_alt)); |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 82 | } else { |
Bartlomiej Zolnierkiewicz | 0424493 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 83 | base = devm_ioport_map(&pdev->dev, |
H Hartley Sweeten | 30433d8 | 2009-11-23 10:30:34 -0800 | [diff] [blame] | 84 | res_base->start, resource_size(res_base)); |
Bartlomiej Zolnierkiewicz | 0424493 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 85 | alt_base = devm_ioport_map(&pdev->dev, |
H Hartley Sweeten | 30433d8 | 2009-11-23 10:30:34 -0800 | [diff] [blame] | 86 | res_alt->start, resource_size(res_alt)); |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Bartlomiej Zolnierkiewicz | 57c802e | 2008-01-26 20:13:05 +0100 | [diff] [blame] | 89 | memset(&hw, 0, sizeof(hw)); |
Bartlomiej Zolnierkiewicz | 0424493 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 90 | plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start); |
Bartlomiej Zolnierkiewicz | 57c802e | 2008-01-26 20:13:05 +0100 | [diff] [blame] | 91 | hw.dev = &pdev->dev; |
| 92 | |
Thomas Gleixner | 89e9aad | 2011-08-04 01:29:51 -0700 | [diff] [blame] | 93 | d.irq_flags = res_irq->flags & IRQF_TRIGGER_MASK; |
| 94 | if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE) |
| 95 | d.irq_flags |= IRQF_SHARED; |
| 96 | |
Bartlomiej Zolnierkiewicz | 761052e | 2008-07-23 19:55:54 +0200 | [diff] [blame] | 97 | if (mmio) |
Bartlomiej Zolnierkiewicz | 7b60fa1 | 2008-07-16 20:33:42 +0200 | [diff] [blame] | 98 | d.host_flags |= IDE_HFLAG_MMIO; |
Bartlomiej Zolnierkiewicz | 57c802e | 2008-01-26 20:13:05 +0100 | [diff] [blame] | 99 | |
Bartlomiej Zolnierkiewicz | dca3983 | 2009-05-17 19:12:24 +0200 | [diff] [blame] | 100 | ret = ide_host_add(&d, hws, 1, &host); |
Bartlomiej Zolnierkiewicz | 6f904d0 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 101 | if (ret) |
Bartlomiej Zolnierkiewicz | 48c3c10 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 102 | goto out; |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 103 | |
Bartlomiej Zolnierkiewicz | 48c3c10 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 104 | platform_set_drvdata(pdev, host); |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | |
| 108 | out: |
| 109 | return ret; |
| 110 | } |
| 111 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 112 | static int plat_ide_remove(struct platform_device *pdev) |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 113 | { |
Greg Kroah-Hartman | fcb5207 | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 114 | struct ide_host *host = dev_get_drvdata(&pdev->dev); |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 115 | |
Bartlomiej Zolnierkiewicz | 48c3c10 | 2008-07-23 19:55:57 +0200 | [diff] [blame] | 116 | ide_host_remove(host); |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static struct platform_driver platform_ide_driver = { |
| 122 | .driver = { |
| 123 | .name = "pata_platform", |
| 124 | }, |
| 125 | .probe = plat_ide_probe, |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 126 | .remove = plat_ide_remove, |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 127 | }; |
| 128 | |
Christoph Jaeger | a53dae4 | 2014-04-09 09:28:01 +0200 | [diff] [blame] | 129 | module_platform_driver(platform_ide_driver); |
Anton Vorontsov | 8cb1f56 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 130 | |
| 131 | MODULE_DESCRIPTION("Platform IDE driver"); |
| 132 | MODULE_LICENSE("GPL"); |
Kay Sievers | 458622f | 2008-04-18 13:41:57 -0700 | [diff] [blame] | 133 | MODULE_ALIAS("platform:pata_platform"); |