Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'intel-gpio-v5.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel into gpio/for-next

intel-gpio for v5.19-1

* Introduce helpers to iterate over GPIO chip nodes and covert some drivers

gpiolib:
- Introduce a helper to get first GPIO controller node
- Introduce gpiochip_node_count() helper
- Introduce for_each_gpiochip_node() loop helper

pinctrl:
- meson: Replace custom code by gpiochip_node_count() call
- meson: Enable COMPILE_TEST
- meson: Rename REG_* to MESON_REG_*
- armada-37xx: Reuse GPIO fwnode in armada_37xx_irqchip_register()
- armada-37xx: Switch to use fwnode instead of of_node
- samsung: Switch to use for_each_gpiochip_node() helper
- samsung: Drop redundant node parameter in samsung_banks_of_node_get()
- npcm7xx: Switch to use for_each_gpiochip_node() helper
- renesas: rza1: Switch to use for_each_gpiochip_node() helper
- renesas: rza1: Replace custom code by gpiochip_node_count() call
- stm32: Switch to use for_each_gpiochip_node() helper
- stm32: Replace custom code by gpiochip_node_count() call

+227 -258
+12 -10
drivers/gpio/gpiolib-acpi.c
··· 108 108 * controller does not have GPIO chip registered at the moment. This is to 109 109 * support probe deferral. 110 110 */ 111 - static struct gpio_desc *acpi_get_gpiod(char *path, int pin) 111 + static struct gpio_desc *acpi_get_gpiod(char *path, unsigned int pin) 112 112 { 113 113 struct gpio_chip *chip; 114 114 acpi_handle handle; ··· 136 136 * as it is intended for use outside of the GPIO layer (in a similar fashion to 137 137 * gpiod_get_index() for example) it also holds a reference to the GPIO device. 138 138 */ 139 - struct gpio_desc *acpi_get_and_request_gpiod(char *path, int pin, char *label) 139 + struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, char *label) 140 140 { 141 141 struct gpio_desc *gpio; 142 142 int ret; ··· 317 317 return desc; 318 318 } 319 319 320 - static bool acpi_gpio_in_ignore_list(const char *controller_in, int pin_in) 320 + static bool acpi_gpio_in_ignore_list(const char *controller_in, unsigned int pin_in) 321 321 { 322 322 const char *controller, *pin_str; 323 - int len, pin; 323 + unsigned int pin; 324 324 char *endp; 325 + int len; 325 326 326 327 controller = ignore_wake; 327 328 while (controller) { ··· 355 354 static bool acpi_gpio_irq_is_wake(struct device *parent, 356 355 struct acpi_resource_gpio *agpio) 357 356 { 358 - int pin = agpio->pin_table[0]; 357 + unsigned int pin = agpio->pin_table[0]; 359 358 360 359 if (agpio->wake_capable != ACPI_WAKE_CAPABLE) 361 360 return false; 362 361 363 362 if (acpi_gpio_in_ignore_list(dev_name(parent), pin)) { 364 - dev_info(parent, "Ignoring wakeup on pin %d\n", pin); 363 + dev_info(parent, "Ignoring wakeup on pin %u\n", pin); 365 364 return false; 366 365 } 367 366 ··· 379 378 struct acpi_gpio_event *event; 380 379 irq_handler_t handler = NULL; 381 380 struct gpio_desc *desc; 382 - int ret, pin, irq; 381 + unsigned int pin; 382 + int ret, irq; 383 383 384 384 if (!acpi_gpio_get_irq_resource(ares, &agpio)) 385 385 return AE_OK; ··· 389 387 pin = agpio->pin_table[0]; 390 388 391 389 if (pin <= 255) { 392 - char ev_name[5]; 393 - sprintf(ev_name, "_%c%02hhX", 390 + char ev_name[8]; 391 + sprintf(ev_name, "_%c%02X", 394 392 agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', 395 393 pin); 396 394 if (ACPI_SUCCESS(acpi_get_handle(handle, ev_name, &evt_handle))) ··· 1100 1098 1101 1099 length = min_t(u16, agpio->pin_table_length, pin_index + bits); 1102 1100 for (i = pin_index; i < length; ++i) { 1103 - int pin = agpio->pin_table[i]; 1101 + unsigned int pin = agpio->pin_table[i]; 1104 1102 struct acpi_gpio_connection *conn; 1105 1103 struct gpio_desc *desc; 1106 1104 bool found;
+1 -1
drivers/pinctrl/meson/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 menuconfig PINCTRL_MESON 3 3 tristate "Amlogic SoC pinctrl drivers" 4 - depends on ARCH_MESON 4 + depends on ARCH_MESON || COMPILE_TEST 5 5 depends on OF 6 6 default y 7 7 select PINMUX
+24 -28
drivers/pinctrl/meson/pinctrl-meson.c
··· 49 49 #include <linux/pinctrl/pinctrl.h> 50 50 #include <linux/pinctrl/pinmux.h> 51 51 #include <linux/platform_device.h> 52 + #include <linux/property.h> 52 53 #include <linux/regmap.h> 53 54 #include <linux/seq_file.h> 54 55 ··· 219 218 unsigned int pin, 220 219 bool out) 221 220 { 222 - return meson_pinconf_set_gpio_bit(pc, pin, REG_DIR, !out); 221 + return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_DIR, !out); 223 222 } 224 223 225 224 static int meson_pinconf_get_output(struct meson_pinctrl *pc, 226 225 unsigned int pin) 227 226 { 228 - int ret = meson_pinconf_get_gpio_bit(pc, pin, REG_DIR); 227 + int ret = meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_DIR); 229 228 230 229 if (ret < 0) 231 230 return ret; ··· 237 236 unsigned int pin, 238 237 bool high) 239 238 { 240 - return meson_pinconf_set_gpio_bit(pc, pin, REG_OUT, high); 239 + return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_OUT, high); 241 240 } 242 241 243 242 static int meson_pinconf_get_drive(struct meson_pinctrl *pc, 244 243 unsigned int pin) 245 244 { 246 - return meson_pinconf_get_gpio_bit(pc, pin, REG_OUT); 245 + return meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_OUT); 247 246 } 248 247 249 248 static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc, ··· 270 269 if (ret) 271 270 return ret; 272 271 273 - meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit); 272 + meson_calc_reg_and_bit(bank, pin, MESON_REG_PULLEN, &reg, &bit); 274 273 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0); 275 274 if (ret) 276 275 return ret; ··· 289 288 if (ret) 290 289 return ret; 291 290 292 - meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit); 291 + meson_calc_reg_and_bit(bank, pin, MESON_REG_PULL, &reg, &bit); 293 292 if (pull_up) 294 293 val = BIT(bit); 295 294 ··· 297 296 if (ret) 298 297 return ret; 299 298 300 - meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit); 299 + meson_calc_reg_and_bit(bank, pin, MESON_REG_PULLEN, &reg, &bit); 301 300 ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), BIT(bit)); 302 301 if (ret) 303 302 return ret; ··· 322 321 if (ret) 323 322 return ret; 324 323 325 - meson_calc_reg_and_bit(bank, pin, REG_DS, &reg, &bit); 324 + meson_calc_reg_and_bit(bank, pin, MESON_REG_DS, &reg, &bit); 326 325 327 326 if (drive_strength_ua <= 500) { 328 327 ds_val = MESON_PINCONF_DRV_500UA; ··· 408 407 if (ret) 409 408 return ret; 410 409 411 - meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit); 410 + meson_calc_reg_and_bit(bank, pin, MESON_REG_PULLEN, &reg, &bit); 412 411 413 412 ret = regmap_read(pc->reg_pullen, reg, &val); 414 413 if (ret) ··· 417 416 if (!(val & BIT(bit))) { 418 417 conf = PIN_CONFIG_BIAS_DISABLE; 419 418 } else { 420 - meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit); 419 + meson_calc_reg_and_bit(bank, pin, MESON_REG_PULL, &reg, &bit); 421 420 422 421 ret = regmap_read(pc->reg_pull, reg, &val); 423 422 if (ret) ··· 448 447 if (ret) 449 448 return ret; 450 449 451 - meson_calc_reg_and_bit(bank, pin, REG_DS, &reg, &bit); 450 + meson_calc_reg_and_bit(bank, pin, MESON_REG_DS, &reg, &bit); 452 451 453 452 ret = regmap_read(pc->reg_ds, reg, &val); 454 453 if (ret) ··· 596 595 if (ret) 597 596 return ret; 598 597 599 - meson_calc_reg_and_bit(bank, gpio, REG_IN, &reg, &bit); 598 + meson_calc_reg_and_bit(bank, gpio, MESON_REG_IN, &reg, &bit); 600 599 regmap_read(pc->reg_gpio, reg, &val); 601 600 602 601 return !!(val & BIT(bit)); ··· 663 662 return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config); 664 663 } 665 664 666 - static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc, 667 - struct device_node *node) 665 + static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc) 668 666 { 669 - struct device_node *np, *gpio_np = NULL; 667 + struct device_node *gpio_np; 668 + unsigned int chips; 670 669 671 - for_each_child_of_node(node, np) { 672 - if (!of_find_property(np, "gpio-controller", NULL)) 673 - continue; 674 - if (gpio_np) { 675 - dev_err(pc->dev, "multiple gpio nodes\n"); 676 - of_node_put(np); 677 - return -EINVAL; 678 - } 679 - gpio_np = np; 680 - } 681 - 682 - if (!gpio_np) { 670 + chips = gpiochip_node_count(pc->dev); 671 + if (!chips) { 683 672 dev_err(pc->dev, "no gpio node found\n"); 684 673 return -EINVAL; 685 674 } 675 + if (chips > 1) { 676 + dev_err(pc->dev, "multiple gpio nodes\n"); 677 + return -EINVAL; 678 + } 686 679 680 + gpio_np = to_of_node(gpiochip_node_get_first(pc->dev)); 687 681 pc->of_node = gpio_np; 688 682 689 683 pc->reg_mux = meson_map_resource(pc, gpio_np, "mux"); ··· 747 751 pc->dev = dev; 748 752 pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev); 749 753 750 - ret = meson_pinctrl_parse_dt(pc, dev->of_node); 754 + ret = meson_pinctrl_parse_dt(pc); 751 755 if (ret) 752 756 return ret; 753 757
+14 -14
drivers/pinctrl/meson/pinctrl-meson.h
··· 63 63 * enum meson_reg_type - type of registers encoded in @meson_reg_desc 64 64 */ 65 65 enum meson_reg_type { 66 - REG_PULLEN, 67 - REG_PULL, 68 - REG_DIR, 69 - REG_OUT, 70 - REG_IN, 71 - REG_DS, 72 - NUM_REG, 66 + MESON_REG_PULLEN, 67 + MESON_REG_PULL, 68 + MESON_REG_DIR, 69 + MESON_REG_OUT, 70 + MESON_REG_IN, 71 + MESON_REG_DS, 72 + MESON_NUM_REG, 73 73 }; 74 74 75 75 /** ··· 102 102 unsigned int last; 103 103 int irq_first; 104 104 int irq_last; 105 - struct meson_reg_desc regs[NUM_REG]; 105 + struct meson_reg_desc regs[MESON_NUM_REG]; 106 106 }; 107 107 108 108 struct meson_pinctrl_data { ··· 150 150 .irq_first = fi, \ 151 151 .irq_last = li, \ 152 152 .regs = { \ 153 - [REG_PULLEN] = { per, peb }, \ 154 - [REG_PULL] = { pr, pb }, \ 155 - [REG_DIR] = { dr, db }, \ 156 - [REG_OUT] = { or, ob }, \ 157 - [REG_IN] = { ir, ib }, \ 158 - [REG_DS] = { dsr, dsb }, \ 153 + [MESON_REG_PULLEN] = { per, peb }, \ 154 + [MESON_REG_PULL] = { pr, pb }, \ 155 + [MESON_REG_DIR] = { dr, db }, \ 156 + [MESON_REG_OUT] = { or, ob }, \ 157 + [MESON_REG_IN] = { ir, ib }, \ 158 + [MESON_REG_DS] = { dsr, dsb }, \ 159 159 }, \ 160 160 } 161 161
+10 -24
drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
··· 21 21 #include <linux/pinctrl/pinctrl.h> 22 22 #include <linux/pinctrl/pinmux.h> 23 23 #include <linux/platform_device.h> 24 + #include <linux/property.h> 24 25 #include <linux/regmap.h> 25 26 #include <linux/slab.h> 26 27 #include <linux/string_helpers.h> ··· 727 726 struct gpio_chip *gc = &info->gpio_chip; 728 727 struct irq_chip *irqchip = &info->irq_chip; 729 728 struct gpio_irq_chip *girq = &gc->irq; 729 + struct device_node *np = to_of_node(gc->fwnode); 730 730 struct device *dev = &pdev->dev; 731 - struct device_node *np; 732 - int ret = -ENODEV, i, nr_irq_parent; 731 + unsigned int i, nr_irq_parent; 733 732 734 - /* Check if we have at least one gpio-controller child node */ 735 - for_each_child_of_node(dev->of_node, np) { 736 - if (of_property_read_bool(np, "gpio-controller")) { 737 - ret = 0; 738 - break; 739 - } 740 - } 741 - if (ret) 742 - return dev_err_probe(dev, ret, "no gpio-controller child node\n"); 743 - 744 - nr_irq_parent = of_irq_count(np); 745 733 spin_lock_init(&info->irq_lock); 746 734 735 + nr_irq_parent = of_irq_count(np); 747 736 if (!nr_irq_parent) { 748 737 dev_err(dev, "invalid or no IRQ\n"); 749 738 return 0; ··· 778 787 struct armada_37xx_pinctrl *info) 779 788 { 780 789 struct device *dev = &pdev->dev; 781 - struct device_node *np; 790 + struct fwnode_handle *fwnode; 782 791 struct gpio_chip *gc; 783 - int ret = -ENODEV; 792 + int ret; 784 793 785 - for_each_child_of_node(dev->of_node, np) { 786 - if (of_find_property(np, "gpio-controller", NULL)) { 787 - ret = 0; 788 - break; 789 - } 790 - } 791 - if (ret) 792 - return ret; 794 + fwnode = gpiochip_node_get_first(dev); 795 + if (!fwnode) 796 + return -ENODEV; 793 797 794 798 info->gpio_chip = armada_37xx_gpiolib_chip; 795 799 ··· 792 806 gc->ngpio = info->data->nr_pins; 793 807 gc->parent = dev; 794 808 gc->base = -1; 795 - gc->of_node = np; 809 + gc->fwnode = fwnode; 796 810 gc->label = info->data->name; 797 811 798 812 ret = armada_37xx_irqchip_register(pdev, info);
+60 -78
drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c
··· 17 17 #include <linux/pinctrl/pinctrl.h> 18 18 #include <linux/pinctrl/pinmux.h> 19 19 #include <linux/platform_device.h> 20 + #include <linux/property.h> 20 21 #include <linux/regmap.h> 21 22 22 23 /* GCR registers */ ··· 1863 1862 { 1864 1863 int ret = -ENXIO; 1865 1864 struct resource res; 1866 - int id = 0, irq; 1867 - struct device_node *np; 1868 - struct of_phandle_args pinspec; 1865 + struct device *dev = pctrl->dev; 1866 + struct fwnode_reference_args args; 1867 + struct fwnode_handle *child; 1868 + int id = 0; 1869 1869 1870 - for_each_available_child_of_node(pctrl->dev->of_node, np) 1871 - if (of_find_property(np, "gpio-controller", NULL)) { 1872 - ret = of_address_to_resource(np, 0, &res); 1873 - if (ret < 0) { 1874 - dev_err(pctrl->dev, 1875 - "Resource fail for GPIO bank %u\n", id); 1876 - return ret; 1877 - } 1870 + for_each_gpiochip_node(dev, child) { 1871 + struct device_node *np = to_of_node(child); 1878 1872 1879 - pctrl->gpio_bank[id].base = 1880 - ioremap(res.start, resource_size(&res)); 1881 - 1882 - irq = irq_of_parse_and_map(np, 0); 1883 - if (irq < 0) { 1884 - dev_err(pctrl->dev, 1885 - "No IRQ for GPIO bank %u\n", id); 1886 - ret = irq; 1887 - return ret; 1888 - } 1889 - 1890 - ret = bgpio_init(&pctrl->gpio_bank[id].gc, 1891 - pctrl->dev, 4, 1892 - pctrl->gpio_bank[id].base + 1893 - NPCM7XX_GP_N_DIN, 1894 - pctrl->gpio_bank[id].base + 1895 - NPCM7XX_GP_N_DOUT, 1896 - NULL, 1897 - NULL, 1898 - pctrl->gpio_bank[id].base + 1899 - NPCM7XX_GP_N_IEM, 1900 - BGPIOF_READ_OUTPUT_REG_SET); 1901 - if (ret) { 1902 - dev_err(pctrl->dev, "bgpio_init() failed\n"); 1903 - return ret; 1904 - } 1905 - 1906 - ret = of_parse_phandle_with_fixed_args(np, 1907 - "gpio-ranges", 3, 1908 - 0, &pinspec); 1909 - if (ret < 0) { 1910 - dev_err(pctrl->dev, 1911 - "gpio-ranges fail for GPIO bank %u\n", 1912 - id); 1913 - return ret; 1914 - } 1915 - 1916 - pctrl->gpio_bank[id].irq = irq; 1917 - pctrl->gpio_bank[id].irq_chip = npcmgpio_irqchip; 1918 - pctrl->gpio_bank[id].gc.parent = pctrl->dev; 1919 - pctrl->gpio_bank[id].irqbase = 1920 - id * NPCM7XX_GPIO_PER_BANK; 1921 - pctrl->gpio_bank[id].pinctrl_id = pinspec.args[0]; 1922 - pctrl->gpio_bank[id].gc.base = pinspec.args[1]; 1923 - pctrl->gpio_bank[id].gc.ngpio = pinspec.args[2]; 1924 - pctrl->gpio_bank[id].gc.owner = THIS_MODULE; 1925 - pctrl->gpio_bank[id].gc.label = 1926 - devm_kasprintf(pctrl->dev, GFP_KERNEL, "%pOF", 1927 - np); 1928 - if (pctrl->gpio_bank[id].gc.label == NULL) 1929 - return -ENOMEM; 1930 - 1931 - pctrl->gpio_bank[id].gc.dbg_show = npcmgpio_dbg_show; 1932 - pctrl->gpio_bank[id].direction_input = 1933 - pctrl->gpio_bank[id].gc.direction_input; 1934 - pctrl->gpio_bank[id].gc.direction_input = 1935 - npcmgpio_direction_input; 1936 - pctrl->gpio_bank[id].direction_output = 1937 - pctrl->gpio_bank[id].gc.direction_output; 1938 - pctrl->gpio_bank[id].gc.direction_output = 1939 - npcmgpio_direction_output; 1940 - pctrl->gpio_bank[id].request = 1941 - pctrl->gpio_bank[id].gc.request; 1942 - pctrl->gpio_bank[id].gc.request = npcmgpio_gpio_request; 1943 - pctrl->gpio_bank[id].gc.free = npcmgpio_gpio_free; 1944 - pctrl->gpio_bank[id].gc.of_node = np; 1945 - id++; 1873 + ret = of_address_to_resource(np, 0, &res); 1874 + if (ret < 0) { 1875 + dev_err(dev, "Resource fail for GPIO bank %u\n", id); 1876 + return ret; 1946 1877 } 1878 + 1879 + pctrl->gpio_bank[id].base = ioremap(res.start, resource_size(&res)); 1880 + 1881 + ret = bgpio_init(&pctrl->gpio_bank[id].gc, dev, 4, 1882 + pctrl->gpio_bank[id].base + NPCM7XX_GP_N_DIN, 1883 + pctrl->gpio_bank[id].base + NPCM7XX_GP_N_DOUT, 1884 + NULL, 1885 + NULL, 1886 + pctrl->gpio_bank[id].base + NPCM7XX_GP_N_IEM, 1887 + BGPIOF_READ_OUTPUT_REG_SET); 1888 + if (ret) { 1889 + dev_err(dev, "bgpio_init() failed\n"); 1890 + return ret; 1891 + } 1892 + 1893 + ret = fwnode_property_get_reference_args(child, "gpio-ranges", NULL, 3, 0, &args); 1894 + if (ret < 0) { 1895 + dev_err(dev, "gpio-ranges fail for GPIO bank %u\n", id); 1896 + return ret; 1897 + } 1898 + 1899 + ret = irq_of_parse_and_map(np, 0); 1900 + if (ret < 0) { 1901 + dev_err(dev, "No IRQ for GPIO bank %u\n", id); 1902 + return ret; 1903 + } 1904 + pctrl->gpio_bank[id].irq = ret; 1905 + pctrl->gpio_bank[id].irq_chip = npcmgpio_irqchip; 1906 + pctrl->gpio_bank[id].irqbase = id * NPCM7XX_GPIO_PER_BANK; 1907 + pctrl->gpio_bank[id].pinctrl_id = args.args[0]; 1908 + pctrl->gpio_bank[id].gc.base = args.args[1]; 1909 + pctrl->gpio_bank[id].gc.ngpio = args.args[2]; 1910 + pctrl->gpio_bank[id].gc.owner = THIS_MODULE; 1911 + pctrl->gpio_bank[id].gc.parent = dev; 1912 + pctrl->gpio_bank[id].gc.fwnode = child; 1913 + pctrl->gpio_bank[id].gc.label = devm_kasprintf(dev, GFP_KERNEL, "%pfw", child); 1914 + if (pctrl->gpio_bank[id].gc.label == NULL) 1915 + return -ENOMEM; 1916 + 1917 + pctrl->gpio_bank[id].gc.dbg_show = npcmgpio_dbg_show; 1918 + pctrl->gpio_bank[id].direction_input = pctrl->gpio_bank[id].gc.direction_input; 1919 + pctrl->gpio_bank[id].gc.direction_input = npcmgpio_direction_input; 1920 + pctrl->gpio_bank[id].direction_output = pctrl->gpio_bank[id].gc.direction_output; 1921 + pctrl->gpio_bank[id].gc.direction_output = npcmgpio_direction_output; 1922 + pctrl->gpio_bank[id].request = pctrl->gpio_bank[id].gc.request; 1923 + pctrl->gpio_bank[id].gc.request = npcmgpio_gpio_request; 1924 + pctrl->gpio_bank[id].gc.free = npcmgpio_gpio_free; 1925 + id++; 1926 + } 1947 1927 1948 1928 pctrl->bank_num = id; 1949 1929 return ret;
+14 -33
drivers/pinctrl/renesas/pinctrl-rza1.c
··· 24 24 #include <linux/pinctrl/pinconf-generic.h> 25 25 #include <linux/pinctrl/pinctrl.h> 26 26 #include <linux/pinctrl/pinmux.h> 27 + #include <linux/property.h> 27 28 #include <linux/slab.h> 28 29 29 30 #include "../core.h" ··· 1155 1154 * RZ/A1 pin controller driver operations 1156 1155 */ 1157 1156 1158 - static unsigned int rza1_count_gpio_chips(struct device_node *np) 1159 - { 1160 - struct device_node *child; 1161 - unsigned int count = 0; 1162 - 1163 - for_each_child_of_node(np, child) { 1164 - if (!of_property_read_bool(child, "gpio-controller")) 1165 - continue; 1166 - 1167 - count++; 1168 - } 1169 - 1170 - return count; 1171 - } 1172 - 1173 1157 /** 1174 1158 * rza1_parse_gpiochip() - parse and register a gpio chip and pin range 1175 1159 * ··· 1162 1176 * defined by gpio device tree binding documentation. 1163 1177 * 1164 1178 * @rza1_pctl: RZ/A1 pin controller device 1165 - * @np: of gpio-controller node 1179 + * @fwnode: gpio-controller firmware node 1166 1180 * @chip: gpio chip to register to gpiolib 1167 1181 * @range: pin range to register to pinctrl core 1168 1182 */ 1169 1183 static int rza1_parse_gpiochip(struct rza1_pinctrl *rza1_pctl, 1170 - struct device_node *np, 1184 + struct fwnode_handle *fwnode, 1171 1185 struct gpio_chip *chip, 1172 1186 struct pinctrl_gpio_range *range) 1173 1187 { 1174 1188 const char *list_name = "gpio-ranges"; 1175 - struct of_phandle_args of_args; 1189 + struct fwnode_reference_args args; 1176 1190 unsigned int gpioport; 1177 1191 u32 pinctrl_base; 1178 1192 int ret; 1179 1193 1180 - ret = of_parse_phandle_with_fixed_args(np, list_name, 3, 0, &of_args); 1194 + ret = fwnode_property_get_reference_args(fwnode, list_name, NULL, 3, 0, &args); 1181 1195 if (ret) { 1182 1196 dev_err(rza1_pctl->dev, "Unable to parse %s list property\n", 1183 1197 list_name); ··· 1188 1202 * Find out on which port this gpio-chip maps to by inspecting the 1189 1203 * second argument of the "gpio-ranges" property. 1190 1204 */ 1191 - pinctrl_base = of_args.args[1]; 1205 + pinctrl_base = args.args[1]; 1192 1206 gpioport = RZA1_PIN_ID_TO_PORT(pinctrl_base); 1193 1207 if (gpioport >= RZA1_NPORTS) { 1194 1208 dev_err(rza1_pctl->dev, ··· 1198 1212 1199 1213 *chip = rza1_gpiochip_template; 1200 1214 chip->base = -1; 1201 - chip->label = devm_kasprintf(rza1_pctl->dev, GFP_KERNEL, "%pOFn", 1202 - np); 1215 + chip->ngpio = args.args[2]; 1216 + chip->label = devm_kasprintf(rza1_pctl->dev, GFP_KERNEL, "%pfwP", fwnode); 1203 1217 if (!chip->label) 1204 1218 return -ENOMEM; 1205 1219 1206 - chip->ngpio = of_args.args[2]; 1207 - chip->of_node = np; 1220 + chip->fwnode = fwnode; 1208 1221 chip->parent = rza1_pctl->dev; 1209 1222 1210 1223 range->id = gpioport; 1211 1224 range->name = chip->label; 1212 1225 range->pin_base = range->base = pinctrl_base; 1213 - range->npins = of_args.args[2]; 1226 + range->npins = args.args[2]; 1214 1227 range->gc = chip; 1215 1228 1216 1229 ret = devm_gpiochip_add_data(rza1_pctl->dev, chip, ··· 1232 1247 */ 1233 1248 static int rza1_gpio_register(struct rza1_pinctrl *rza1_pctl) 1234 1249 { 1235 - struct device_node *np = rza1_pctl->dev->of_node; 1236 1250 struct pinctrl_gpio_range *gpio_ranges; 1237 1251 struct gpio_chip *gpio_chips; 1238 - struct device_node *child; 1252 + struct fwnode_handle *child; 1239 1253 unsigned int ngpiochips; 1240 1254 unsigned int i; 1241 1255 int ret; 1242 1256 1243 - ngpiochips = rza1_count_gpio_chips(np); 1257 + ngpiochips = gpiochip_node_count(rza1_pctl->dev); 1244 1258 if (ngpiochips == 0) { 1245 1259 dev_dbg(rza1_pctl->dev, "No gpiochip registered\n"); 1246 1260 return 0; ··· 1253 1269 return -ENOMEM; 1254 1270 1255 1271 i = 0; 1256 - for_each_child_of_node(np, child) { 1257 - if (!of_property_read_bool(child, "gpio-controller")) 1258 - continue; 1259 - 1272 + for_each_gpiochip_node(rza1_pctl->dev, child) { 1260 1273 ret = rza1_parse_gpiochip(rza1_pctl, child, &gpio_chips[i], 1261 1274 &gpio_ranges[i]); 1262 1275 if (ret) { 1263 - of_node_put(child); 1276 + fwnode_handle_put(child); 1264 1277 return ret; 1265 1278 } 1266 1279
+4 -4
drivers/pinctrl/samsung/pinctrl-exynos.c
··· 307 307 } 308 308 bank->irq_chip->chip.name = bank->name; 309 309 310 - bank->irq_domain = irq_domain_add_linear(bank->of_node, 310 + bank->irq_domain = irq_domain_create_linear(bank->fwnode, 311 311 bank->nr_pins, &exynos_eint_irqd_ops, bank); 312 312 if (!bank->irq_domain) { 313 313 dev_err(dev, "gpio irq domain add failed\n"); ··· 565 565 } 566 566 bank->irq_chip->chip.name = bank->name; 567 567 568 - bank->irq_domain = irq_domain_add_linear(bank->of_node, 568 + bank->irq_domain = irq_domain_create_linear(bank->fwnode, 569 569 bank->nr_pins, &exynos_eint_irqd_ops, bank); 570 570 if (!bank->irq_domain) { 571 571 dev_err(dev, "wkup irq domain add failed\n"); ··· 573 573 return -ENXIO; 574 574 } 575 575 576 - if (!of_find_property(bank->of_node, "interrupts", NULL)) { 576 + if (!fwnode_property_present(bank->fwnode, "interrupts")) { 577 577 bank->eint_type = EINT_TYPE_WKUP_MUX; 578 578 ++muxed_banks; 579 579 continue; ··· 588 588 } 589 589 590 590 for (idx = 0; idx < bank->nr_pins; ++idx) { 591 - irq = irq_of_parse_and_map(bank->of_node, idx); 591 + irq = irq_of_parse_and_map(to_of_node(bank->fwnode), idx); 592 592 if (!irq) { 593 593 dev_err(dev, "irq number for eint-%s-%d not found\n", 594 594 bank->name, idx);
+1 -1
drivers/pinctrl/samsung/pinctrl-s3c24xx.c
··· 525 525 ops = (bank->eint_offset == 0) ? &s3c24xx_gpf_irq_ops 526 526 : &s3c24xx_gpg_irq_ops; 527 527 528 - bank->irq_domain = irq_domain_add_linear(bank->of_node, 528 + bank->irq_domain = irq_domain_create_linear(bank->fwnode, 529 529 bank->nr_pins, ops, ddata); 530 530 if (!bank->irq_domain) { 531 531 dev_err(dev, "wkup irq domain add failed\n");
+2 -2
drivers/pinctrl/samsung/pinctrl-s3c64xx.c
··· 471 471 mask = bank->eint_mask; 472 472 nr_eints = fls(mask); 473 473 474 - bank->irq_domain = irq_domain_add_linear(bank->of_node, 474 + bank->irq_domain = irq_domain_create_linear(bank->fwnode, 475 475 nr_eints, &s3c64xx_gpio_irqd_ops, bank); 476 476 if (!bank->irq_domain) { 477 477 dev_err(dev, "gpio irq domain add failed\n"); ··· 743 743 return -ENOMEM; 744 744 ddata->bank = bank; 745 745 746 - bank->irq_domain = irq_domain_add_linear(bank->of_node, 746 + bank->irq_domain = irq_domain_create_linear(bank->fwnode, 747 747 nr_eints, &s3c64xx_eint0_irqd_ops, ddata); 748 748 if (!bank->irq_domain) { 749 749 dev_err(dev, "wkup irq domain add failed\n");
+14 -16
drivers/pinctrl/samsung/pinctrl-samsung.c
··· 18 18 #include <linux/init.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/io.h> 21 + #include <linux/property.h> 21 22 #include <linux/slab.h> 22 23 #include <linux/err.h> 23 24 #include <linux/gpio/driver.h> ··· 967 966 gc->base = bank->grange.base; 968 967 gc->ngpio = bank->nr_pins; 969 968 gc->parent = &pdev->dev; 970 - gc->of_node = bank->of_node; 969 + gc->fwnode = bank->fwnode; 971 970 gc->label = bank->name; 972 971 973 972 ret = devm_gpiochip_add_data(&pdev->dev, gc, bank); ··· 1003 1002 return &(of_data->ctrl[id]); 1004 1003 } 1005 1004 1006 - static void samsung_banks_of_node_put(struct samsung_pinctrl_drv_data *d) 1005 + static void samsung_banks_node_put(struct samsung_pinctrl_drv_data *d) 1007 1006 { 1008 1007 struct samsung_pin_bank *bank; 1009 1008 unsigned int i; 1010 1009 1011 1010 bank = d->pin_banks; 1012 1011 for (i = 0; i < d->nr_banks; ++i, ++bank) 1013 - of_node_put(bank->of_node); 1012 + fwnode_handle_put(bank->fwnode); 1014 1013 } 1015 1014 1016 1015 /* 1017 1016 * Iterate over all driver pin banks to find one matching the name of node, 1018 1017 * skipping optional "-gpio" node suffix. When found, assign node to the bank. 1019 1018 */ 1020 - static void samsung_banks_of_node_get(struct device *dev, 1021 - struct samsung_pinctrl_drv_data *d, 1022 - struct device_node *node) 1019 + static void samsung_banks_node_get(struct device *dev, struct samsung_pinctrl_drv_data *d) 1023 1020 { 1024 1021 const char *suffix = "-gpio-bank"; 1025 1022 struct samsung_pin_bank *bank; 1026 - struct device_node *child; 1023 + struct fwnode_handle *child; 1027 1024 /* Pin bank names are up to 4 characters */ 1028 1025 char node_name[20]; 1029 1026 unsigned int i; ··· 1037 1038 continue; 1038 1039 } 1039 1040 1040 - for_each_child_of_node(node, child) { 1041 - if (!of_find_property(child, "gpio-controller", NULL)) 1042 - continue; 1043 - if (of_node_name_eq(child, node_name)) 1041 + for_each_gpiochip_node(dev, child) { 1042 + struct device_node *np = to_of_node(child); 1043 + 1044 + if (of_node_name_eq(np, node_name)) 1044 1045 break; 1045 - else if (of_node_name_eq(child, bank->name)) 1046 + if (of_node_name_eq(np, bank->name)) 1046 1047 break; 1047 1048 } 1048 1049 1049 1050 if (child) 1050 - bank->of_node = child; 1051 + bank->fwnode = child; 1051 1052 else 1052 1053 dev_warn(dev, "Missing node for bank %s - invalid DTB\n", 1053 1054 bank->name); ··· 1060 1061 samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, 1061 1062 struct platform_device *pdev) 1062 1063 { 1063 - struct device_node *node = pdev->dev.of_node; 1064 1064 const struct samsung_pin_bank_data *bdata; 1065 1065 const struct samsung_pin_ctrl *ctrl; 1066 1066 struct samsung_pin_bank *bank; ··· 1123 1125 */ 1124 1126 d->virt_base = virt_base[0]; 1125 1127 1126 - samsung_banks_of_node_get(&pdev->dev, d, node); 1128 + samsung_banks_node_get(&pdev->dev, d); 1127 1129 1128 1130 d->pin_base = pin_base; 1129 1131 pin_base += d->nr_pins; ··· 1184 1186 err_unregister: 1185 1187 samsung_pinctrl_unregister(pdev, drvdata); 1186 1188 err_put_banks: 1187 - samsung_banks_of_node_put(drvdata); 1189 + samsung_banks_node_put(drvdata); 1188 1190 return ret; 1189 1191 } 1190 1192
+1 -1
drivers/pinctrl/samsung/pinctrl-samsung.h
··· 165 165 166 166 u32 pin_base; 167 167 void *soc_priv; 168 - struct device_node *of_node; 168 + struct fwnode_handle *fwnode; 169 169 struct samsung_pinctrl_drv_data *drvdata; 170 170 struct irq_domain *irq_domain; 171 171 struct gpio_chip gpio_chip;
+36 -44
drivers/pinctrl/stm32/pinctrl-stm32.c
··· 24 24 #include <linux/pinctrl/pinctrl.h> 25 25 #include <linux/pinctrl/pinmux.h> 26 26 #include <linux/platform_device.h> 27 + #include <linux/property.h> 27 28 #include <linux/regmap.h> 28 29 #include <linux/reset.h> 29 30 #include <linux/slab.h> ··· 1216 1215 .pin_config_dbg_show = stm32_pconf_dbg_show, 1217 1216 }; 1218 1217 1219 - static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, 1220 - struct device_node *np) 1218 + static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode_handle *fwnode) 1221 1219 { 1222 1220 struct stm32_gpio_bank *bank = &pctl->banks[pctl->nbanks]; 1223 1221 int bank_ioport_nr; 1224 1222 struct pinctrl_gpio_range *range = &bank->range; 1225 - struct of_phandle_args args; 1223 + struct fwnode_reference_args args; 1226 1224 struct device *dev = pctl->dev; 1227 1225 struct resource res; 1228 1226 int npins = STM32_GPIO_PINS_PER_BANK; ··· 1230 1230 if (!IS_ERR(bank->rstc)) 1231 1231 reset_control_deassert(bank->rstc); 1232 1232 1233 - if (of_address_to_resource(np, 0, &res)) 1233 + if (of_address_to_resource(to_of_node(fwnode), 0, &res)) 1234 1234 return -ENODEV; 1235 1235 1236 1236 bank->base = devm_ioremap_resource(dev, &res); ··· 1245 1245 1246 1246 bank->gpio_chip = stm32_gpio_template; 1247 1247 1248 - of_property_read_string(np, "st,bank-name", &bank->gpio_chip.label); 1248 + fwnode_property_read_string(fwnode, "st,bank-name", &bank->gpio_chip.label); 1249 1249 1250 - if (!of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, i, &args)) { 1250 + if (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, i, &args)) { 1251 1251 bank_nr = args.args[1] / STM32_GPIO_PINS_PER_BANK; 1252 1252 bank->gpio_chip.base = args.args[1]; 1253 1253 1254 1254 /* get the last defined gpio line (offset + nb of pins) */ 1255 1255 npins = args.args[0] + args.args[2]; 1256 - while (!of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, ++i, &args)) 1256 + while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args)) 1257 1257 npins = max(npins, (int)(args.args[0] + args.args[2])); 1258 1258 } else { 1259 1259 bank_nr = pctl->nbanks; ··· 1268 1268 &pctl->banks[bank_nr].range); 1269 1269 } 1270 1270 1271 - if (of_property_read_u32(np, "st,bank-ioport", &bank_ioport_nr)) 1271 + if (fwnode_property_read_u32(fwnode, "st,bank-ioport", &bank_ioport_nr)) 1272 1272 bank_ioport_nr = bank_nr; 1273 1273 1274 1274 bank->gpio_chip.base = bank_nr * STM32_GPIO_PINS_PER_BANK; 1275 1275 1276 1276 bank->gpio_chip.ngpio = npins; 1277 - bank->gpio_chip.of_node = np; 1277 + bank->gpio_chip.fwnode = fwnode; 1278 1278 bank->gpio_chip.parent = dev; 1279 1279 bank->bank_nr = bank_nr; 1280 1280 bank->bank_ioport_nr = bank_ioport_nr; 1281 1281 spin_lock_init(&bank->lock); 1282 1282 1283 1283 /* create irq hierarchical domain */ 1284 - bank->fwnode = of_node_to_fwnode(np); 1284 + bank->fwnode = fwnode; 1285 1285 1286 1286 bank->domain = irq_domain_create_hierarchy(pctl->domain, 0, 1287 1287 STM32_GPIO_IRQ_LINE, bank->fwnode, ··· 1418 1418 int stm32_pctl_probe(struct platform_device *pdev) 1419 1419 { 1420 1420 struct device_node *np = pdev->dev.of_node; 1421 - struct device_node *child; 1421 + struct fwnode_handle *child; 1422 1422 const struct of_device_id *match; 1423 1423 struct device *dev = &pdev->dev; 1424 1424 struct stm32_pinctrl *pctl; 1425 1425 struct pinctrl_pin_desc *pins; 1426 - int i, ret, hwlock_id, banks = 0; 1426 + int i, ret, hwlock_id; 1427 + unsigned int banks; 1427 1428 1428 1429 if (!np) 1429 1430 return -EINVAL; ··· 1514 1513 return PTR_ERR(pctl->pctl_dev); 1515 1514 } 1516 1515 1517 - for_each_available_child_of_node(np, child) 1518 - if (of_property_read_bool(child, "gpio-controller")) 1519 - banks++; 1520 - 1516 + banks = gpiochip_node_count(dev); 1521 1517 if (!banks) { 1522 1518 dev_err(dev, "at least one GPIO bank is required\n"); 1523 1519 return -EINVAL; ··· 1525 1527 return -ENOMEM; 1526 1528 1527 1529 i = 0; 1528 - for_each_available_child_of_node(np, child) { 1530 + for_each_gpiochip_node(dev, child) { 1529 1531 struct stm32_gpio_bank *bank = &pctl->banks[i]; 1532 + struct device_node *np = to_of_node(child); 1530 1533 1531 - if (of_property_read_bool(child, "gpio-controller")) { 1532 - bank->rstc = of_reset_control_get_exclusive(child, 1533 - NULL); 1534 - if (PTR_ERR(bank->rstc) == -EPROBE_DEFER) { 1535 - of_node_put(child); 1536 - return -EPROBE_DEFER; 1537 - } 1538 - 1539 - bank->clk = of_clk_get_by_name(child, NULL); 1540 - if (IS_ERR(bank->clk)) { 1541 - if (PTR_ERR(bank->clk) != -EPROBE_DEFER) 1542 - dev_err(dev, 1543 - "failed to get clk (%ld)\n", 1544 - PTR_ERR(bank->clk)); 1545 - of_node_put(child); 1546 - return PTR_ERR(bank->clk); 1547 - } 1548 - i++; 1534 + bank->rstc = of_reset_control_get_exclusive(np, NULL); 1535 + if (PTR_ERR(bank->rstc) == -EPROBE_DEFER) { 1536 + fwnode_handle_put(child); 1537 + return -EPROBE_DEFER; 1549 1538 } 1539 + 1540 + bank->clk = of_clk_get_by_name(np, NULL); 1541 + if (IS_ERR(bank->clk)) { 1542 + if (PTR_ERR(bank->clk) != -EPROBE_DEFER) 1543 + dev_err(dev, "failed to get clk (%ld)\n", PTR_ERR(bank->clk)); 1544 + fwnode_handle_put(child); 1545 + return PTR_ERR(bank->clk); 1546 + } 1547 + i++; 1550 1548 } 1551 1549 1552 - for_each_available_child_of_node(np, child) { 1553 - if (of_property_read_bool(child, "gpio-controller")) { 1554 - ret = stm32_gpiolib_register_bank(pctl, child); 1555 - if (ret) { 1556 - of_node_put(child); 1557 - return ret; 1558 - } 1559 - 1560 - pctl->nbanks++; 1550 + for_each_gpiochip_node(dev, child) { 1551 + ret = stm32_gpiolib_register_bank(pctl, child); 1552 + if (ret) { 1553 + fwnode_handle_put(child); 1554 + return ret; 1561 1555 } 1556 + 1557 + pctl->nbanks++; 1562 1558 } 1563 1559 1564 1560 dev_info(dev, "Pinctrl STM32 initialized\n");
+7 -1
include/linux/gpio/consumer.h
··· 688 688 int devm_acpi_dev_add_driver_gpios(struct device *dev, 689 689 const struct acpi_gpio_mapping *gpios); 690 690 691 - struct gpio_desc *acpi_get_and_request_gpiod(char *path, int pin, char *label); 691 + struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, char *label); 692 692 693 693 #else /* CONFIG_GPIOLIB && CONFIG_ACPI */ 694 694 ··· 703 703 const struct acpi_gpio_mapping *gpios) 704 704 { 705 705 return -ENXIO; 706 + } 707 + 708 + static inline struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, 709 + char *label) 710 + { 711 + return ERR_PTR(-ENOSYS); 706 712 } 707 713 708 714 #endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
+27 -1
include/linux/gpio/driver.h
··· 3 3 #define __LINUX_GPIO_DRIVER_H 4 4 5 5 #include <linux/device.h> 6 - #include <linux/types.h> 7 6 #include <linux/irq.h> 8 7 #include <linux/irqchip/chained_irq.h> 9 8 #include <linux/irqdomain.h> 10 9 #include <linux/lockdep.h> 11 10 #include <linux/pinctrl/pinctrl.h> 12 11 #include <linux/pinctrl/pinconf-generic.h> 12 + #include <linux/property.h> 13 + #include <linux/types.h> 13 14 14 15 struct gpio_desc; 15 16 struct of_phandle_args; ··· 750 749 WARN_ON(1); 751 750 } 752 751 #endif /* CONFIG_GPIOLIB */ 752 + 753 + #define for_each_gpiochip_node(dev, child) \ 754 + device_for_each_child_node(dev, child) \ 755 + if (!fwnode_property_present(child, "gpio-controller")) {} else 756 + 757 + static inline unsigned int gpiochip_node_count(struct device *dev) 758 + { 759 + struct fwnode_handle *child; 760 + unsigned int count = 0; 761 + 762 + for_each_gpiochip_node(dev, child) 763 + count++; 764 + 765 + return count; 766 + } 767 + 768 + static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev) 769 + { 770 + struct fwnode_handle *fwnode; 771 + 772 + for_each_gpiochip_node(dev, fwnode) 773 + return fwnode; 774 + 775 + return NULL; 776 + } 753 777 754 778 #endif /* __LINUX_GPIO_DRIVER_H */