hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pinctrl/pinctrl-pic32.c
....@@ -1,17 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * PIC32 pinctrl driver
34 *
45 * Joshua Henderson, <joshua.henderson@microchip.com>
56 * Copyright (C) 2015 Microchip Technology Inc. All rights reserved.
6
- *
7
- * This program is free software; you can distribute it and/or modify it
8
- * under the terms of the GNU General Public License (Version 2) as
9
- * published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope it will be useful, but WITHOUT
12
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
- * for more details.
157 */
168 #include <linux/clk.h>
179 #include <linux/gpio/driver.h>
....@@ -1998,7 +1990,10 @@
19981990 {
19991991 struct pic32_gpio_bank *bank = gpiochip_get_data(chip);
20001992
2001
- return !!(readl(bank->reg_base + TRIS_REG) & BIT(offset));
1993
+ if (readl(bank->reg_base + TRIS_REG) & BIT(offset))
1994
+ return GPIO_LINE_DIRECTION_IN;
1995
+
1996
+ return GPIO_LINE_DIRECTION_OUT;
20021997 }
20031998
20041999 static void pic32_gpio_irq_ack(struct irq_data *data)
....@@ -2210,7 +2205,7 @@
22102205 struct pic32_gpio_bank *bank;
22112206 u32 id;
22122207 int irq, ret;
2213
- struct resource *res;
2208
+ struct gpio_irq_chip *girq;
22142209
22152210 if (of_property_read_u32(np, "microchip,gpio-bank", &id)) {
22162211 dev_err(&pdev->dev, "microchip,gpio-bank property not found\n");
....@@ -2224,16 +2219,13 @@
22242219
22252220 bank = &pic32_gpio_banks[id];
22262221
2227
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2228
- bank->reg_base = devm_ioremap_resource(&pdev->dev, res);
2222
+ bank->reg_base = devm_platform_ioremap_resource(pdev, 0);
22292223 if (IS_ERR(bank->reg_base))
22302224 return PTR_ERR(bank->reg_base);
22312225
22322226 irq = platform_get_irq(pdev, 0);
2233
- if (irq < 0) {
2234
- dev_err(&pdev->dev, "irq get failed\n");
2227
+ if (irq < 0)
22352228 return irq;
2236
- }
22372229
22382230 bank->clk = devm_clk_get(&pdev->dev, NULL);
22392231 if (IS_ERR(bank->clk)) {
....@@ -2250,25 +2242,23 @@
22502242
22512243 bank->gpio_chip.parent = &pdev->dev;
22522244 bank->gpio_chip.of_node = np;
2245
+ girq = &bank->gpio_chip.irq;
2246
+ girq->chip = &bank->irq_chip;
2247
+ girq->parent_handler = pic32_gpio_irq_handler;
2248
+ girq->num_parents = 1;
2249
+ girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents),
2250
+ GFP_KERNEL);
2251
+ if (!girq->parents)
2252
+ return -ENOMEM;
2253
+ girq->default_type = IRQ_TYPE_NONE;
2254
+ girq->handler = handle_level_irq;
2255
+ girq->parents[0] = irq;
22532256 ret = gpiochip_add_data(&bank->gpio_chip, bank);
22542257 if (ret < 0) {
22552258 dev_err(&pdev->dev, "Failed to add GPIO chip %u: %d\n",
22562259 id, ret);
22572260 return ret;
22582261 }
2259
-
2260
- ret = gpiochip_irqchip_add(&bank->gpio_chip, &bank->irq_chip,
2261
- 0, handle_level_irq, IRQ_TYPE_NONE);
2262
- if (ret < 0) {
2263
- dev_err(&pdev->dev, "Failed to add IRQ chip %u: %d\n",
2264
- id, ret);
2265
- gpiochip_remove(&bank->gpio_chip);
2266
- return ret;
2267
- }
2268
-
2269
- gpiochip_set_chained_irqchip(&bank->gpio_chip, &bank->irq_chip,
2270
- irq, pic32_gpio_irq_handler);
2271
-
22722262 return 0;
22732263 }
22742264