.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * A low-level PATA driver to handle a Compact Flash connected on the |
---|
3 | 4 | * Mikrotik's RouterBoard 532 board. |
---|
.. | .. |
---|
12 | 13 | * Also was based on the driver for Linux 2.4.xx published by Mikrotik for |
---|
13 | 14 | * their RouterBoard 1xx and 5xx series devices. The original Mikrotik code |
---|
14 | 15 | * seems not to have a license. |
---|
15 | | - * |
---|
16 | | - * This program is free software; you can redistribute it and/or modify |
---|
17 | | - * it under the terms of the GNU General Public License version 2 as |
---|
18 | | - * published by the Free Software Foundation. |
---|
19 | | - * |
---|
20 | 16 | */ |
---|
21 | 17 | |
---|
22 | 18 | #include <linux/gfp.h> |
---|
.. | .. |
---|
27 | 23 | #include <linux/io.h> |
---|
28 | 24 | #include <linux/interrupt.h> |
---|
29 | 25 | #include <linux/irq.h> |
---|
30 | | -#include <linux/gpio.h> |
---|
| 26 | +#include <linux/gpio/consumer.h> |
---|
31 | 27 | |
---|
32 | 28 | #include <linux/libata.h> |
---|
33 | 29 | #include <scsi/scsi_host.h> |
---|
.. | .. |
---|
49 | 45 | |
---|
50 | 46 | struct rb532_cf_info { |
---|
51 | 47 | void __iomem *iobase; |
---|
52 | | - unsigned int gpio_line; |
---|
| 48 | + struct gpio_desc *gpio_line; |
---|
53 | 49 | unsigned int irq; |
---|
54 | 50 | }; |
---|
55 | 51 | |
---|
.. | .. |
---|
60 | 56 | struct ata_host *ah = dev_instance; |
---|
61 | 57 | struct rb532_cf_info *info = ah->private_data; |
---|
62 | 58 | |
---|
63 | | - if (gpio_get_value(info->gpio_line)) { |
---|
| 59 | + if (gpiod_get_value(info->gpio_line)) { |
---|
64 | 60 | irq_set_irq_type(info->irq, IRQ_TYPE_LEVEL_LOW); |
---|
65 | 61 | ata_sff_interrupt(info->irq, dev_instance); |
---|
66 | 62 | } else { |
---|
.. | .. |
---|
106 | 102 | static int rb532_pata_driver_probe(struct platform_device *pdev) |
---|
107 | 103 | { |
---|
108 | 104 | int irq; |
---|
109 | | - int gpio; |
---|
| 105 | + struct gpio_desc *gpiod; |
---|
110 | 106 | struct resource *res; |
---|
111 | 107 | struct ata_host *ah; |
---|
112 | | - struct cf_device *pdata; |
---|
113 | 108 | struct rb532_cf_info *info; |
---|
114 | 109 | int ret; |
---|
115 | 110 | |
---|
.. | .. |
---|
127 | 122 | if (!irq) |
---|
128 | 123 | return -EINVAL; |
---|
129 | 124 | |
---|
130 | | - pdata = dev_get_platdata(&pdev->dev); |
---|
131 | | - if (!pdata) { |
---|
132 | | - dev_err(&pdev->dev, "no platform data specified\n"); |
---|
133 | | - return -EINVAL; |
---|
134 | | - } |
---|
135 | | - |
---|
136 | | - gpio = pdata->gpio_pin; |
---|
137 | | - if (gpio < 0) { |
---|
| 125 | + gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_IN); |
---|
| 126 | + if (IS_ERR(gpiod)) { |
---|
138 | 127 | dev_err(&pdev->dev, "no GPIO found for irq%d\n", irq); |
---|
139 | | - return -ENOENT; |
---|
| 128 | + return PTR_ERR(gpiod); |
---|
140 | 129 | } |
---|
141 | | - |
---|
142 | | - ret = gpio_request(gpio, DRV_NAME); |
---|
143 | | - if (ret) { |
---|
144 | | - dev_err(&pdev->dev, "GPIO request failed\n"); |
---|
145 | | - return ret; |
---|
146 | | - } |
---|
| 130 | + gpiod_set_consumer_name(gpiod, DRV_NAME); |
---|
147 | 131 | |
---|
148 | 132 | /* allocate host */ |
---|
149 | 133 | ah = ata_host_alloc(&pdev->dev, RB500_CF_MAXPORTS); |
---|
.. | .. |
---|
155 | 139 | return -ENOMEM; |
---|
156 | 140 | |
---|
157 | 141 | ah->private_data = info; |
---|
158 | | - info->gpio_line = gpio; |
---|
| 142 | + info->gpio_line = gpiod; |
---|
159 | 143 | info->irq = irq; |
---|
160 | 144 | |
---|
161 | | - info->iobase = devm_ioremap_nocache(&pdev->dev, res->start, |
---|
| 145 | + info->iobase = devm_ioremap(&pdev->dev, res->start, |
---|
162 | 146 | resource_size(res)); |
---|
163 | 147 | if (!info->iobase) |
---|
164 | 148 | return -ENOMEM; |
---|
165 | | - |
---|
166 | | - ret = gpio_direction_input(gpio); |
---|
167 | | - if (ret) { |
---|
168 | | - dev_err(&pdev->dev, "unable to set GPIO direction, err=%d\n", |
---|
169 | | - ret); |
---|
170 | | - goto err_free_gpio; |
---|
171 | | - } |
---|
172 | 149 | |
---|
173 | 150 | rb532_pata_setup_ports(ah); |
---|
174 | 151 | |
---|
175 | 152 | ret = ata_host_activate(ah, irq, rb532_pata_irq_handler, |
---|
176 | 153 | IRQF_TRIGGER_LOW, &rb532_pata_sht); |
---|
177 | 154 | if (ret) |
---|
178 | | - goto err_free_gpio; |
---|
| 155 | + return ret; |
---|
179 | 156 | |
---|
180 | 157 | return 0; |
---|
181 | | - |
---|
182 | | -err_free_gpio: |
---|
183 | | - gpio_free(gpio); |
---|
184 | | - |
---|
185 | | - return ret; |
---|
186 | 158 | } |
---|
187 | 159 | |
---|
188 | 160 | static int rb532_pata_driver_remove(struct platform_device *pdev) |
---|
189 | 161 | { |
---|
190 | 162 | struct ata_host *ah = platform_get_drvdata(pdev); |
---|
191 | | - struct rb532_cf_info *info = ah->private_data; |
---|
192 | 163 | |
---|
193 | 164 | ata_host_detach(ah); |
---|
194 | | - gpio_free(info->gpio_line); |
---|
195 | 165 | |
---|
196 | 166 | return 0; |
---|
197 | 167 | } |
---|