hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pinctrl/pinctrl-st.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2013 STMicroelectronics (R&D) Limited.
34 * Authors:
45 * Srinivas Kandagatla <srinivas.kandagatla@st.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 */
107
118 #include <linux/init.h>
....@@ -15,8 +12,9 @@
1512 #include <linux/io.h>
1613 #include <linux/of.h>
1714 #include <linux/of_irq.h>
18
-#include <linux/of_gpio.h>
15
+#include <linux/of_gpio.h> /* of_get_named_gpio() */
1916 #include <linux/of_address.h>
17
+#include <linux/gpio/driver.h>
2018 #include <linux/regmap.h>
2119 #include <linux/mfd/syscon.h>
2220 #include <linux/pinctrl/pinctrl.h>
....@@ -543,7 +541,6 @@
543541 st_regmap_field_bit_set_clear_pin(rt_p->delay_0, delay & 0x1, pin);
544542 /* 2 bit delay, msb */
545543 st_regmap_field_bit_set_clear_pin(rt_p->delay_1, delay & 0x2, pin);
546
-
547544 }
548545
549546 static void st_pinconf_set_retime_dedicated(struct st_pinctrl *info,
....@@ -748,7 +745,10 @@
748745 function = st_pctl_get_pin_function(&pc, offset);
749746 if (function) {
750747 st_pinconf_get_direction(&pc, offset, &config);
751
- return !ST_PINCONF_UNPACK_OE(config);
748
+ if (ST_PINCONF_UNPACK_OE(config))
749
+ return GPIO_LINE_DIRECTION_OUT;
750
+
751
+ return GPIO_LINE_DIRECTION_IN;
752752 }
753753
754754 /*
....@@ -760,7 +760,10 @@
760760 direction |= ((value >> offset) & 0x1) << i;
761761 }
762762
763
- return (direction == ST_GPIO_DIRECTION_IN);
763
+ if (direction == ST_GPIO_DIRECTION_IN)
764
+ return GPIO_LINE_DIRECTION_IN;
765
+
766
+ return GPIO_LINE_DIRECTION_OUT;
764767 }
765768
766769 /* Pinctrl Groups */
....@@ -817,8 +820,8 @@
817820
818821 grp = st_pctl_find_group_by_name(info, np->name);
819822 if (!grp) {
820
- dev_err(info->dev, "unable to find group for node %s\n",
821
- np->name);
823
+ dev_err(info->dev, "unable to find group for node %pOFn\n",
824
+ np);
822825 return -EINVAL;
823826 }
824827
....@@ -998,6 +1001,7 @@
9981001 unsigned int function;
9991002 int offset = st_gpio_pin(pin_id);
10001003 char f[16];
1004
+ int oe;
10011005
10021006 mutex_unlock(&pctldev->mutex);
10031007 pc = st_get_pio_control(pctldev, pin_id);
....@@ -1010,10 +1014,11 @@
10101014 else
10111015 snprintf(f, 5, "GPIO");
10121016
1017
+ oe = st_gpio_get_direction(&pc_to_bank(pc)->gpio_chip, offset);
10131018 seq_printf(s, "[OE:%d,PU:%ld,OD:%ld]\t%s\n"
10141019 "\t\t[retime:%ld,invclk:%ld,clknotdat:%ld,"
10151020 "de:%ld,rt-clk:%ld,rt-delay:%ld]",
1016
- !st_gpio_get_direction(&pc_to_bank(pc)->gpio_chip, offset),
1021
+ (oe == GPIO_LINE_DIRECTION_OUT),
10171022 ST_PINCONF_UNPACK_PU(config),
10181023 ST_PINCONF_UNPACK_OD(config),
10191024 f,
....@@ -1170,7 +1175,7 @@
11701175 struct property *pp;
11711176 struct st_pinconf *conf;
11721177 struct device_node *pins;
1173
- int i = 0, npins = 0, nr_props;
1178
+ int i = 0, npins = 0, nr_props, ret = 0;
11741179
11751180 pins = of_get_child_by_name(np, "st,pins");
11761181 if (!pins)
....@@ -1184,8 +1189,9 @@
11841189 if (pp->length / sizeof(__be32) >= OF_GPIO_ARGS_MIN) {
11851190 npins++;
11861191 } else {
1187
- pr_warn("Invalid st,pins in %s node\n", np->name);
1188
- return -EINVAL;
1192
+ pr_warn("Invalid st,pins in %pOFn node\n", np);
1193
+ ret = -EINVAL;
1194
+ goto out_put_node;
11891195 }
11901196 }
11911197
....@@ -1195,8 +1201,10 @@
11951201 grp->pin_conf = devm_kcalloc(info->dev,
11961202 npins, sizeof(*conf), GFP_KERNEL);
11971203
1198
- if (!grp->pins || !grp->pin_conf)
1199
- return -ENOMEM;
1204
+ if (!grp->pins || !grp->pin_conf) {
1205
+ ret = -ENOMEM;
1206
+ goto out_put_node;
1207
+ }
12001208
12011209 /* <bank offset mux direction rt_type rt_delay rt_clk> */
12021210 for_each_property_of_node(pins, pp) {
....@@ -1229,9 +1237,11 @@
12291237 }
12301238 i++;
12311239 }
1240
+
1241
+out_put_node:
12321242 of_node_put(pins);
12331243
1234
- return 0;
1244
+ return ret;
12351245 }
12361246
12371247 static int st_pctl_parse_functions(struct device_node *np,
....@@ -1260,8 +1270,10 @@
12601270 grp = &info->groups[*grp_index];
12611271 *grp_index += 1;
12621272 ret = st_pctl_dt_parse_groups(child, grp, info, i++);
1263
- if (ret)
1273
+ if (ret) {
1274
+ of_node_put(child);
12641275 return ret;
1276
+ }
12651277 }
12661278 dev_info(info->dev, "Function[%d\t name:%s,\tgroups:%d]\n",
12671279 index, func->name, func->ngroups);
....@@ -1472,7 +1484,7 @@
14721484 struct device *dev = info->dev;
14731485 int bank_num = of_alias_get_id(np, "gpio");
14741486 struct resource res, irq_res;
1475
- int gpio_irq = 0, err;
1487
+ int err;
14761488
14771489 if (of_address_to_resource(np, 0, &res))
14781490 return -ENODEV;
....@@ -1495,12 +1507,6 @@
14951507 range->pin_base = range->base = range->id * ST_GPIO_PINS_PER_BANK;
14961508 range->npins = bank->gpio_chip.ngpio;
14971509 range->gc = &bank->gpio_chip;
1498
- err = gpiochip_add_data(&bank->gpio_chip, bank);
1499
- if (err) {
1500
- dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_num);
1501
- return err;
1502
- }
1503
- dev_info(dev, "%s bank added.\n", range->name);
15041510
15051511 /**
15061512 * GPIO bank can have one of the two possible types of
....@@ -1522,23 +1528,40 @@
15221528 */
15231529
15241530 if (of_irq_to_resource(np, 0, &irq_res) > 0) {
1525
- gpio_irq = irq_res.start;
1526
- gpiochip_set_chained_irqchip(&bank->gpio_chip, &st_gpio_irqchip,
1527
- gpio_irq, st_gpio_irq_handler);
1531
+ struct gpio_irq_chip *girq;
1532
+ int gpio_irq = irq_res.start;
1533
+
1534
+ /* This is not a valid IRQ */
1535
+ if (gpio_irq <= 0) {
1536
+ dev_err(dev, "invalid IRQ for %pOF bank\n", np);
1537
+ goto skip_irq;
1538
+ }
1539
+ /* We need to have a mux as well */
1540
+ if (!info->irqmux_base) {
1541
+ dev_err(dev, "no irqmux for %pOF bank\n", np);
1542
+ goto skip_irq;
1543
+ }
1544
+
1545
+ girq = &bank->gpio_chip.irq;
1546
+ girq->chip = &st_gpio_irqchip;
1547
+ girq->parent_handler = st_gpio_irq_handler;
1548
+ girq->num_parents = 1;
1549
+ girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents),
1550
+ GFP_KERNEL);
1551
+ if (!girq->parents)
1552
+ return -ENOMEM;
1553
+ girq->parents[0] = gpio_irq;
1554
+ girq->default_type = IRQ_TYPE_NONE;
1555
+ girq->handler = handle_simple_irq;
15281556 }
15291557
1530
- if (info->irqmux_base || gpio_irq > 0) {
1531
- err = gpiochip_irqchip_add(&bank->gpio_chip, &st_gpio_irqchip,
1532
- 0, handle_simple_irq,
1533
- IRQ_TYPE_NONE);
1534
- if (err) {
1535
- gpiochip_remove(&bank->gpio_chip);
1536
- dev_info(dev, "could not add irqchip\n");
1537
- return err;
1538
- }
1539
- } else {
1540
- dev_info(dev, "No IRQ support for %pOF bank\n", np);
1558
+skip_irq:
1559
+ err = gpiochip_add_data(&bank->gpio_chip, bank);
1560
+ if (err) {
1561
+ dev_err(dev, "Failed to add gpiochip(%d)!\n", bank_num);
1562
+ return err;
15411563 }
1564
+ dev_info(dev, "%s bank added.\n", range->name);
15421565
15431566 return 0;
15441567 }
....@@ -1621,8 +1644,10 @@
16211644 if (of_property_read_bool(child, "gpio-controller")) {
16221645 const char *bank_name = NULL;
16231646 ret = st_gpiolib_register_bank(info, bank, child);
1624
- if (ret)
1647
+ if (ret) {
1648
+ of_node_put(child);
16251649 return ret;
1650
+ }
16261651
16271652 k = info->banks[bank].range.pin_base;
16281653 bank_name = info->banks[bank].range.name;
....@@ -1639,6 +1664,7 @@
16391664 i++, &grp_index);
16401665 if (ret) {
16411666 dev_err(&pdev->dev, "No functions found.\n");
1667
+ of_node_put(child);
16421668 return ret;
16431669 }
16441670 }