hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-mb86s7x.c
....@@ -1,19 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/drivers/gpio/gpio-mb86s7x.c
34 *
45 * Copyright (C) 2015 Fujitsu Semiconductor Limited
56 * Copyright (C) 2015 Linaro Ltd.
6
- *
7
- * This program is free software: you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation, version 2 of the License.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
157 */
168
9
+#include <linux/acpi.h>
1710 #include <linux/io.h>
1811 #include <linux/init.h>
1912 #include <linux/clk.h>
....@@ -26,6 +19,9 @@
2619 #include <linux/platform_device.h>
2720 #include <linux/spinlock.h>
2821 #include <linux/slab.h>
22
+
23
+#include "gpiolib.h"
24
+#include "gpiolib-acpi.h"
2925
3026 /*
3127 * Only first 8bits of a register correspond to each pin,
....@@ -143,10 +139,25 @@
143139 spin_unlock_irqrestore(&gchip->lock, flags);
144140 }
145141
142
+static int mb86s70_gpio_to_irq(struct gpio_chip *gc, unsigned int offset)
143
+{
144
+ int irq, index;
145
+
146
+ for (index = 0;; index++) {
147
+ irq = platform_get_irq(to_platform_device(gc->parent), index);
148
+ if (irq < 0)
149
+ return irq;
150
+ if (irq == 0)
151
+ break;
152
+ if (irq_get_irq_data(irq)->hwirq == offset)
153
+ return irq;
154
+ }
155
+ return -EINVAL;
156
+}
157
+
146158 static int mb86s70_gpio_probe(struct platform_device *pdev)
147159 {
148160 struct mb86s70_gpio_chip *gchip;
149
- struct resource *res;
150161 int ret;
151162
152163 gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL);
....@@ -155,12 +166,11 @@
155166
156167 platform_set_drvdata(pdev, gchip);
157168
158
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
159
- gchip->base = devm_ioremap_resource(&pdev->dev, res);
169
+ gchip->base = devm_platform_ioremap_resource(pdev, 0);
160170 if (IS_ERR(gchip->base))
161171 return PTR_ERR(gchip->base);
162172
163
- gchip->clk = devm_clk_get(&pdev->dev, NULL);
173
+ gchip->clk = devm_clk_get_optional(&pdev->dev, NULL);
164174 if (IS_ERR(gchip->clk))
165175 return PTR_ERR(gchip->clk);
166176
....@@ -176,6 +186,7 @@
176186 gchip->gc.free = mb86s70_gpio_free;
177187 gchip->gc.get = mb86s70_gpio_get;
178188 gchip->gc.set = mb86s70_gpio_set;
189
+ gchip->gc.to_irq = mb86s70_gpio_to_irq;
179190 gchip->gc.label = dev_name(&pdev->dev);
180191 gchip->gc.ngpio = 32;
181192 gchip->gc.owner = THIS_MODULE;
....@@ -186,15 +197,19 @@
186197 if (ret) {
187198 dev_err(&pdev->dev, "couldn't register gpio driver\n");
188199 clk_disable_unprepare(gchip->clk);
200
+ return ret;
189201 }
190202
191
- return ret;
203
+ acpi_gpiochip_request_interrupts(&gchip->gc);
204
+
205
+ return 0;
192206 }
193207
194208 static int mb86s70_gpio_remove(struct platform_device *pdev)
195209 {
196210 struct mb86s70_gpio_chip *gchip = platform_get_drvdata(pdev);
197211
212
+ acpi_gpiochip_free_interrupts(&gchip->gc);
198213 gpiochip_remove(&gchip->gc);
199214 clk_disable_unprepare(gchip->clk);
200215
....@@ -207,10 +222,19 @@
207222 };
208223 MODULE_DEVICE_TABLE(of, mb86s70_gpio_dt_ids);
209224
225
+#ifdef CONFIG_ACPI
226
+static const struct acpi_device_id mb86s70_gpio_acpi_ids[] = {
227
+ { "SCX0007" },
228
+ { /* sentinel */ }
229
+};
230
+MODULE_DEVICE_TABLE(acpi, mb86s70_gpio_acpi_ids);
231
+#endif
232
+
210233 static struct platform_driver mb86s70_gpio_driver = {
211234 .driver = {
212235 .name = "mb86s70-gpio",
213236 .of_match_table = mb86s70_gpio_dt_ids,
237
+ .acpi_match_table = ACPI_PTR(mb86s70_gpio_acpi_ids),
214238 },
215239 .probe = mb86s70_gpio_probe,
216240 .remove = mb86s70_gpio_remove,