hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/ata/pata_rb532_cf.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * A low-level PATA driver to handle a Compact Flash connected on the
34 * Mikrotik's RouterBoard 532 board.
....@@ -12,11 +13,6 @@
1213 * Also was based on the driver for Linux 2.4.xx published by Mikrotik for
1314 * their RouterBoard 1xx and 5xx series devices. The original Mikrotik code
1415 * 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
- *
2016 */
2117
2218 #include <linux/gfp.h>
....@@ -27,7 +23,7 @@
2723 #include <linux/io.h>
2824 #include <linux/interrupt.h>
2925 #include <linux/irq.h>
30
-#include <linux/gpio.h>
26
+#include <linux/gpio/consumer.h>
3127
3228 #include <linux/libata.h>
3329 #include <scsi/scsi_host.h>
....@@ -49,7 +45,7 @@
4945
5046 struct rb532_cf_info {
5147 void __iomem *iobase;
52
- unsigned int gpio_line;
48
+ struct gpio_desc *gpio_line;
5349 unsigned int irq;
5450 };
5551
....@@ -60,7 +56,7 @@
6056 struct ata_host *ah = dev_instance;
6157 struct rb532_cf_info *info = ah->private_data;
6258
63
- if (gpio_get_value(info->gpio_line)) {
59
+ if (gpiod_get_value(info->gpio_line)) {
6460 irq_set_irq_type(info->irq, IRQ_TYPE_LEVEL_LOW);
6561 ata_sff_interrupt(info->irq, dev_instance);
6662 } else {
....@@ -106,10 +102,9 @@
106102 static int rb532_pata_driver_probe(struct platform_device *pdev)
107103 {
108104 int irq;
109
- int gpio;
105
+ struct gpio_desc *gpiod;
110106 struct resource *res;
111107 struct ata_host *ah;
112
- struct cf_device *pdata;
113108 struct rb532_cf_info *info;
114109 int ret;
115110
....@@ -127,23 +122,12 @@
127122 if (!irq)
128123 return -EINVAL;
129124
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)) {
138127 dev_err(&pdev->dev, "no GPIO found for irq%d\n", irq);
139
- return -ENOENT;
128
+ return PTR_ERR(gpiod);
140129 }
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);
147131
148132 /* allocate host */
149133 ah = ata_host_alloc(&pdev->dev, RB500_CF_MAXPORTS);
....@@ -155,43 +139,29 @@
155139 return -ENOMEM;
156140
157141 ah->private_data = info;
158
- info->gpio_line = gpio;
142
+ info->gpio_line = gpiod;
159143 info->irq = irq;
160144
161
- info->iobase = devm_ioremap_nocache(&pdev->dev, res->start,
145
+ info->iobase = devm_ioremap(&pdev->dev, res->start,
162146 resource_size(res));
163147 if (!info->iobase)
164148 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
- }
172149
173150 rb532_pata_setup_ports(ah);
174151
175152 ret = ata_host_activate(ah, irq, rb532_pata_irq_handler,
176153 IRQF_TRIGGER_LOW, &rb532_pata_sht);
177154 if (ret)
178
- goto err_free_gpio;
155
+ return ret;
179156
180157 return 0;
181
-
182
-err_free_gpio:
183
- gpio_free(gpio);
184
-
185
- return ret;
186158 }
187159
188160 static int rb532_pata_driver_remove(struct platform_device *pdev)
189161 {
190162 struct ata_host *ah = platform_get_drvdata(pdev);
191
- struct rb532_cf_info *info = ah->private_data;
192163
193164 ata_host_detach(ah);
194
- gpio_free(info->gpio_line);
195165
196166 return 0;
197167 }