hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/pinctrl/pinctrl-pistachio.c
....@@ -1,15 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Pistachio SoC pinctrl driver
34 *
45 * Copyright (C) 2014 Imagination Technologies Ltd.
56 * Copyright (C) 2014 Google, Inc.
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms and conditions of the GNU General Public License,
9
- * version 2, as published by the Free Software Foundation.
107 */
118
12
-#include <linux/gpio.h>
139 #include <linux/gpio/driver.h>
1410 #include <linux/interrupt.h>
1511 #include <linux/io.h>
....@@ -1170,7 +1166,10 @@
11701166 {
11711167 struct pistachio_gpio_bank *bank = gpiochip_get_data(chip);
11721168
1173
- return !(gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset));
1169
+ if (gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset))
1170
+ return GPIO_LINE_DIRECTION_OUT;
1171
+
1172
+ return GPIO_LINE_DIRECTION_IN;
11741173 }
11751174
11761175 static int pistachio_gpio_get(struct gpio_chip *chip, unsigned offset)
....@@ -1356,6 +1355,7 @@
13561355 for (i = 0; i < pctl->nbanks; i++) {
13571356 char child_name[sizeof("gpioXX")];
13581357 struct device_node *child;
1358
+ struct gpio_irq_chip *girq;
13591359
13601360 snprintf(child_name, sizeof(child_name), "gpio%d", i);
13611361 child = of_get_child_by_name(node, child_name);
....@@ -1374,10 +1374,10 @@
13741374 }
13751375
13761376 irq = irq_of_parse_and_map(child, 0);
1377
- if (irq < 0) {
1378
- dev_err(pctl->dev, "No IRQ for bank %u: %d\n", i, irq);
1377
+ if (!irq) {
1378
+ dev_err(pctl->dev, "No IRQ for bank %u\n", i);
13791379 of_node_put(child);
1380
- ret = irq;
1380
+ ret = -EINVAL;
13811381 goto err;
13821382 }
13831383
....@@ -1387,23 +1387,28 @@
13871387
13881388 bank->gpio_chip.parent = pctl->dev;
13891389 bank->gpio_chip.of_node = child;
1390
+
1391
+ girq = &bank->gpio_chip.irq;
1392
+ girq->chip = &bank->irq_chip;
1393
+ girq->parent_handler = pistachio_gpio_irq_handler;
1394
+ girq->num_parents = 1;
1395
+ girq->parents = devm_kcalloc(pctl->dev, 1,
1396
+ sizeof(*girq->parents),
1397
+ GFP_KERNEL);
1398
+ if (!girq->parents) {
1399
+ ret = -ENOMEM;
1400
+ goto err;
1401
+ }
1402
+ girq->parents[0] = irq;
1403
+ girq->default_type = IRQ_TYPE_NONE;
1404
+ girq->handler = handle_level_irq;
1405
+
13901406 ret = gpiochip_add_data(&bank->gpio_chip, bank);
13911407 if (ret < 0) {
13921408 dev_err(pctl->dev, "Failed to add GPIO chip %u: %d\n",
13931409 i, ret);
13941410 goto err;
13951411 }
1396
-
1397
- ret = gpiochip_irqchip_add(&bank->gpio_chip, &bank->irq_chip,
1398
- 0, handle_level_irq, IRQ_TYPE_NONE);
1399
- if (ret < 0) {
1400
- dev_err(pctl->dev, "Failed to add IRQ chip %u: %d\n",
1401
- i, ret);
1402
- gpiochip_remove(&bank->gpio_chip);
1403
- goto err;
1404
- }
1405
- gpiochip_set_chained_irqchip(&bank->gpio_chip, &bank->irq_chip,
1406
- irq, pistachio_gpio_irq_handler);
14071412
14081413 ret = gpiochip_add_pin_range(&bank->gpio_chip,
14091414 dev_name(pctl->dev), 0,
....@@ -1433,7 +1438,6 @@
14331438 static int pistachio_pinctrl_probe(struct platform_device *pdev)
14341439 {
14351440 struct pistachio_pinctrl *pctl;
1436
- struct resource *res;
14371441
14381442 pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL);
14391443 if (!pctl)
....@@ -1441,8 +1445,7 @@
14411445 pctl->dev = &pdev->dev;
14421446 dev_set_drvdata(&pdev->dev, pctl);
14431447
1444
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1445
- pctl->base = devm_ioremap_resource(&pdev->dev, res);
1448
+ pctl->base = devm_platform_ioremap_resource(pdev, 0);
14461449 if (IS_ERR(pctl->base))
14471450 return PTR_ERR(pctl->base);
14481451