hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/gpio/gpio-sodaville.c
....@@ -1,26 +1,22 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * GPIO interface for Intel Sodaville SoCs.
34 *
45 * Copyright (c) 2010, 2011 Intel Corporation
56 *
67 * Author: Hans J. Koch <hjk@linutronix.de>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License 2 as published
10
- * by the Free Software Foundation.
11
- *
128 */
139
1410 #include <linux/errno.h>
11
+#include <linux/gpio/driver.h>
1512 #include <linux/init.h>
13
+#include <linux/interrupt.h>
1614 #include <linux/io.h>
1715 #include <linux/irq.h>
18
-#include <linux/interrupt.h>
1916 #include <linux/kernel.h>
17
+#include <linux/of_irq.h>
2018 #include <linux/pci.h>
2119 #include <linux/platform_device.h>
22
-#include <linux/of_irq.h>
23
-#include <linux/gpio/driver.h>
2420
2521 #define DRV_NAME "sdv_gpio"
2622 #define SDV_NUM_PUB_GPIOS 12
....@@ -80,18 +76,15 @@
8076 static irqreturn_t sdv_gpio_pub_irq_handler(int irq, void *data)
8177 {
8278 struct sdv_gpio_chip_data *sd = data;
83
- u32 irq_stat = readl(sd->gpio_pub_base + GPSTR);
79
+ unsigned long irq_stat = readl(sd->gpio_pub_base + GPSTR);
80
+ int irq_bit;
8481
8582 irq_stat &= readl(sd->gpio_pub_base + GPIO_INT);
8683 if (!irq_stat)
8784 return IRQ_NONE;
8885
89
- while (irq_stat) {
90
- u32 irq_bit = __fls(irq_stat);
91
-
92
- irq_stat &= ~BIT(irq_bit);
86
+ for_each_set_bit(irq_bit, &irq_stat, 32)
9387 generic_handle_irq(irq_find_mapping(sd->id, irq_bit));
94
- }
9588
9689 return IRQ_HANDLED;
9790 }
....@@ -155,8 +148,10 @@
155148 * we unmask & ACK the IRQ before the source of the interrupt is gone
156149 * then the interrupt is active again.
157150 */
158
- sd->gc = irq_alloc_generic_chip("sdv-gpio", 1, sd->irq_base,
159
- sd->gpio_pub_base, handle_fasteoi_irq);
151
+ sd->gc = devm_irq_alloc_generic_chip(&pdev->dev, "sdv-gpio", 1,
152
+ sd->irq_base,
153
+ sd->gpio_pub_base,
154
+ handle_fasteoi_irq);
160155 if (!sd->gc)
161156 return -ENOMEM;
162157
....@@ -186,70 +181,52 @@
186181 const struct pci_device_id *pci_id)
187182 {
188183 struct sdv_gpio_chip_data *sd;
189
- unsigned long addr;
190
- const void *prop;
191
- int len;
192184 int ret;
193185 u32 mux_val;
194186
195
- sd = kzalloc(sizeof(struct sdv_gpio_chip_data), GFP_KERNEL);
187
+ sd = devm_kzalloc(&pdev->dev, sizeof(*sd), GFP_KERNEL);
196188 if (!sd)
197189 return -ENOMEM;
198
- ret = pci_enable_device(pdev);
190
+
191
+ ret = pcim_enable_device(pdev);
199192 if (ret) {
200193 dev_err(&pdev->dev, "can't enable device.\n");
201
- goto done;
194
+ return ret;
202195 }
203196
204
- ret = pci_request_region(pdev, GPIO_BAR, DRV_NAME);
197
+ ret = pcim_iomap_regions(pdev, 1 << GPIO_BAR, DRV_NAME);
205198 if (ret) {
206199 dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR);
207
- goto disable_pci;
200
+ return ret;
208201 }
209202
210
- addr = pci_resource_start(pdev, GPIO_BAR);
211
- if (!addr) {
212
- ret = -ENODEV;
213
- goto release_reg;
214
- }
215
- sd->gpio_pub_base = ioremap(addr, pci_resource_len(pdev, GPIO_BAR));
203
+ sd->gpio_pub_base = pcim_iomap_table(pdev)[GPIO_BAR];
216204
217
- prop = of_get_property(pdev->dev.of_node, "intel,muxctl", &len);
218
- if (prop && len == 4) {
219
- mux_val = of_read_number(prop, 1);
205
+ ret = of_property_read_u32(pdev->dev.of_node, "intel,muxctl", &mux_val);
206
+ if (!ret)
220207 writel(mux_val, sd->gpio_pub_base + GPMUXCTL);
221
- }
222208
223209 ret = bgpio_init(&sd->chip, &pdev->dev, 4,
224210 sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR,
225211 NULL, sd->gpio_pub_base + GPOER, NULL, 0);
226212 if (ret)
227
- goto unmap;
213
+ return ret;
214
+
228215 sd->chip.ngpio = SDV_NUM_PUB_GPIOS;
229216
230
- ret = gpiochip_add_data(&sd->chip, sd);
217
+ ret = devm_gpiochip_add_data(&pdev->dev, &sd->chip, sd);
231218 if (ret < 0) {
232219 dev_err(&pdev->dev, "gpiochip_add() failed.\n");
233
- goto unmap;
220
+ return ret;
234221 }
235222
236223 ret = sdv_register_irqsupport(sd, pdev);
237224 if (ret)
238
- goto unmap;
225
+ return ret;
239226
240227 pci_set_drvdata(pdev, sd);
241228 dev_info(&pdev->dev, "Sodaville GPIO driver registered.\n");
242229 return 0;
243
-
244
-unmap:
245
- iounmap(sd->gpio_pub_base);
246
-release_reg:
247
- pci_release_region(pdev, GPIO_BAR);
248
-disable_pci:
249
- pci_disable_device(pdev);
250
-done:
251
- kfree(sd);
252
- return ret;
253230 }
254231
255232 static const struct pci_device_id sdv_gpio_pci_ids[] = {