.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2013 STMicroelectronics (R&D) Limited. |
---|
3 | 4 | * Authors: |
---|
4 | 5 | * 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. |
---|
9 | 6 | */ |
---|
10 | 7 | |
---|
11 | 8 | #include <linux/init.h> |
---|
.. | .. |
---|
15 | 12 | #include <linux/io.h> |
---|
16 | 13 | #include <linux/of.h> |
---|
17 | 14 | #include <linux/of_irq.h> |
---|
18 | | -#include <linux/of_gpio.h> |
---|
| 15 | +#include <linux/of_gpio.h> /* of_get_named_gpio() */ |
---|
19 | 16 | #include <linux/of_address.h> |
---|
| 17 | +#include <linux/gpio/driver.h> |
---|
20 | 18 | #include <linux/regmap.h> |
---|
21 | 19 | #include <linux/mfd/syscon.h> |
---|
22 | 20 | #include <linux/pinctrl/pinctrl.h> |
---|
.. | .. |
---|
543 | 541 | st_regmap_field_bit_set_clear_pin(rt_p->delay_0, delay & 0x1, pin); |
---|
544 | 542 | /* 2 bit delay, msb */ |
---|
545 | 543 | st_regmap_field_bit_set_clear_pin(rt_p->delay_1, delay & 0x2, pin); |
---|
546 | | - |
---|
547 | 544 | } |
---|
548 | 545 | |
---|
549 | 546 | static void st_pinconf_set_retime_dedicated(struct st_pinctrl *info, |
---|
.. | .. |
---|
748 | 745 | function = st_pctl_get_pin_function(&pc, offset); |
---|
749 | 746 | if (function) { |
---|
750 | 747 | 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; |
---|
752 | 752 | } |
---|
753 | 753 | |
---|
754 | 754 | /* |
---|
.. | .. |
---|
760 | 760 | direction |= ((value >> offset) & 0x1) << i; |
---|
761 | 761 | } |
---|
762 | 762 | |
---|
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; |
---|
764 | 767 | } |
---|
765 | 768 | |
---|
766 | 769 | /* Pinctrl Groups */ |
---|
.. | .. |
---|
817 | 820 | |
---|
818 | 821 | grp = st_pctl_find_group_by_name(info, np->name); |
---|
819 | 822 | 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); |
---|
822 | 825 | return -EINVAL; |
---|
823 | 826 | } |
---|
824 | 827 | |
---|
.. | .. |
---|
998 | 1001 | unsigned int function; |
---|
999 | 1002 | int offset = st_gpio_pin(pin_id); |
---|
1000 | 1003 | char f[16]; |
---|
| 1004 | + int oe; |
---|
1001 | 1005 | |
---|
1002 | 1006 | mutex_unlock(&pctldev->mutex); |
---|
1003 | 1007 | pc = st_get_pio_control(pctldev, pin_id); |
---|
.. | .. |
---|
1010 | 1014 | else |
---|
1011 | 1015 | snprintf(f, 5, "GPIO"); |
---|
1012 | 1016 | |
---|
| 1017 | + oe = st_gpio_get_direction(&pc_to_bank(pc)->gpio_chip, offset); |
---|
1013 | 1018 | seq_printf(s, "[OE:%d,PU:%ld,OD:%ld]\t%s\n" |
---|
1014 | 1019 | "\t\t[retime:%ld,invclk:%ld,clknotdat:%ld," |
---|
1015 | 1020 | "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), |
---|
1017 | 1022 | ST_PINCONF_UNPACK_PU(config), |
---|
1018 | 1023 | ST_PINCONF_UNPACK_OD(config), |
---|
1019 | 1024 | f, |
---|
.. | .. |
---|
1170 | 1175 | struct property *pp; |
---|
1171 | 1176 | struct st_pinconf *conf; |
---|
1172 | 1177 | struct device_node *pins; |
---|
1173 | | - int i = 0, npins = 0, nr_props; |
---|
| 1178 | + int i = 0, npins = 0, nr_props, ret = 0; |
---|
1174 | 1179 | |
---|
1175 | 1180 | pins = of_get_child_by_name(np, "st,pins"); |
---|
1176 | 1181 | if (!pins) |
---|
.. | .. |
---|
1184 | 1189 | if (pp->length / sizeof(__be32) >= OF_GPIO_ARGS_MIN) { |
---|
1185 | 1190 | npins++; |
---|
1186 | 1191 | } 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; |
---|
1189 | 1195 | } |
---|
1190 | 1196 | } |
---|
1191 | 1197 | |
---|
.. | .. |
---|
1195 | 1201 | grp->pin_conf = devm_kcalloc(info->dev, |
---|
1196 | 1202 | npins, sizeof(*conf), GFP_KERNEL); |
---|
1197 | 1203 | |
---|
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 | + } |
---|
1200 | 1208 | |
---|
1201 | 1209 | /* <bank offset mux direction rt_type rt_delay rt_clk> */ |
---|
1202 | 1210 | for_each_property_of_node(pins, pp) { |
---|
.. | .. |
---|
1229 | 1237 | } |
---|
1230 | 1238 | i++; |
---|
1231 | 1239 | } |
---|
| 1240 | + |
---|
| 1241 | +out_put_node: |
---|
1232 | 1242 | of_node_put(pins); |
---|
1233 | 1243 | |
---|
1234 | | - return 0; |
---|
| 1244 | + return ret; |
---|
1235 | 1245 | } |
---|
1236 | 1246 | |
---|
1237 | 1247 | static int st_pctl_parse_functions(struct device_node *np, |
---|
.. | .. |
---|
1260 | 1270 | grp = &info->groups[*grp_index]; |
---|
1261 | 1271 | *grp_index += 1; |
---|
1262 | 1272 | ret = st_pctl_dt_parse_groups(child, grp, info, i++); |
---|
1263 | | - if (ret) |
---|
| 1273 | + if (ret) { |
---|
| 1274 | + of_node_put(child); |
---|
1264 | 1275 | return ret; |
---|
| 1276 | + } |
---|
1265 | 1277 | } |
---|
1266 | 1278 | dev_info(info->dev, "Function[%d\t name:%s,\tgroups:%d]\n", |
---|
1267 | 1279 | index, func->name, func->ngroups); |
---|
.. | .. |
---|
1472 | 1484 | struct device *dev = info->dev; |
---|
1473 | 1485 | int bank_num = of_alias_get_id(np, "gpio"); |
---|
1474 | 1486 | struct resource res, irq_res; |
---|
1475 | | - int gpio_irq = 0, err; |
---|
| 1487 | + int err; |
---|
1476 | 1488 | |
---|
1477 | 1489 | if (of_address_to_resource(np, 0, &res)) |
---|
1478 | 1490 | return -ENODEV; |
---|
.. | .. |
---|
1495 | 1507 | range->pin_base = range->base = range->id * ST_GPIO_PINS_PER_BANK; |
---|
1496 | 1508 | range->npins = bank->gpio_chip.ngpio; |
---|
1497 | 1509 | 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); |
---|
1504 | 1510 | |
---|
1505 | 1511 | /** |
---|
1506 | 1512 | * GPIO bank can have one of the two possible types of |
---|
.. | .. |
---|
1522 | 1528 | */ |
---|
1523 | 1529 | |
---|
1524 | 1530 | 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; |
---|
1528 | 1556 | } |
---|
1529 | 1557 | |
---|
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; |
---|
1541 | 1563 | } |
---|
| 1564 | + dev_info(dev, "%s bank added.\n", range->name); |
---|
1542 | 1565 | |
---|
1543 | 1566 | return 0; |
---|
1544 | 1567 | } |
---|
.. | .. |
---|
1621 | 1644 | if (of_property_read_bool(child, "gpio-controller")) { |
---|
1622 | 1645 | const char *bank_name = NULL; |
---|
1623 | 1646 | ret = st_gpiolib_register_bank(info, bank, child); |
---|
1624 | | - if (ret) |
---|
| 1647 | + if (ret) { |
---|
| 1648 | + of_node_put(child); |
---|
1625 | 1649 | return ret; |
---|
| 1650 | + } |
---|
1626 | 1651 | |
---|
1627 | 1652 | k = info->banks[bank].range.pin_base; |
---|
1628 | 1653 | bank_name = info->banks[bank].range.name; |
---|
.. | .. |
---|
1639 | 1664 | i++, &grp_index); |
---|
1640 | 1665 | if (ret) { |
---|
1641 | 1666 | dev_err(&pdev->dev, "No functions found.\n"); |
---|
| 1667 | + of_node_put(child); |
---|
1642 | 1668 | return ret; |
---|
1643 | 1669 | } |
---|
1644 | 1670 | } |
---|