hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/drivers/gpio/gpio-zx.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ZTE ZX296702 GPIO driver
34 *
45 * Author: Jun Nie <jun.nie@linaro.org>
56 *
67 * Copyright (C) 2015 Linaro Ltd.
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 version 2 as
10
- * published by the Free Software Foundation.
118 */
129 #include <linux/bitops.h>
1310 #include <linux/device.h>
....@@ -218,25 +215,22 @@
218215 {
219216 struct device *dev = &pdev->dev;
220217 struct zx_gpio *chip;
221
- struct resource *res;
218
+ struct gpio_irq_chip *girq;
222219 int irq, id, ret;
223220
224221 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
225222 if (!chip)
226223 return -ENOMEM;
227224
228
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
229
- chip->base = devm_ioremap_resource(dev, res);
225
+ chip->base = devm_platform_ioremap_resource(pdev, 0);
230226 if (IS_ERR(chip->base))
231227 return PTR_ERR(chip->base);
232228
233
- raw_spin_lock_init(&chip->lock);
234
- if (of_property_read_bool(dev->of_node, "gpio-ranges")) {
235
- chip->gc.request = gpiochip_generic_request;
236
- chip->gc.free = gpiochip_generic_free;
237
- }
238
-
239229 id = of_alias_get_id(dev->of_node, "gpio");
230
+
231
+ raw_spin_lock_init(&chip->lock);
232
+ chip->gc.request = gpiochip_generic_request;
233
+ chip->gc.free = gpiochip_generic_free;
240234 chip->gc.direction_input = zx_direction_input;
241235 chip->gc.direction_output = zx_direction_output;
242236 chip->gc.get = zx_get_value;
....@@ -247,32 +241,30 @@
247241 chip->gc.parent = dev;
248242 chip->gc.owner = THIS_MODULE;
249243
250
- ret = gpiochip_add_data(&chip->gc, chip);
251
- if (ret)
252
- return ret;
253
-
254244 /*
255245 * irq_chip support
256246 */
257247 writew_relaxed(0xffff, chip->base + ZX_GPIO_IM);
258248 writew_relaxed(0, chip->base + ZX_GPIO_IE);
259249 irq = platform_get_irq(pdev, 0);
260
- if (irq < 0) {
261
- dev_err(dev, "invalid IRQ\n");
262
- gpiochip_remove(&chip->gc);
263
- return -ENODEV;
264
- }
250
+ if (irq < 0)
251
+ return irq;
252
+ girq = &chip->gc.irq;
253
+ girq->chip = &zx_irqchip;
254
+ girq->parent_handler = zx_irq_handler;
255
+ girq->num_parents = 1;
256
+ girq->parents = devm_kcalloc(&pdev->dev, 1,
257
+ sizeof(*girq->parents),
258
+ GFP_KERNEL);
259
+ if (!girq->parents)
260
+ return -ENOMEM;
261
+ girq->parents[0] = irq;
262
+ girq->default_type = IRQ_TYPE_NONE;
263
+ girq->handler = handle_simple_irq;
265264
266
- ret = gpiochip_irqchip_add(&chip->gc, &zx_irqchip,
267
- 0, handle_simple_irq,
268
- IRQ_TYPE_NONE);
269
- if (ret) {
270
- dev_err(dev, "could not add irqchip\n");
271
- gpiochip_remove(&chip->gc);
265
+ ret = gpiochip_add_data(&chip->gc, chip);
266
+ if (ret)
272267 return ret;
273
- }
274
- gpiochip_set_chained_irqchip(&chip->gc, &zx_irqchip,
275
- irq, zx_irq_handler);
276268
277269 platform_set_drvdata(pdev, chip);
278270 dev_info(dev, "ZX GPIO chip registered\n");