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

sh-pfc: Add DT support

Support device instantiation through the device tree. The compatible
property is used to select the SoC pinmux information.

Set the gpio_chip device field to the PFC device to enable automatic
GPIO OF support.

Cc: devicetree-discuss@lists.ozlabs.org
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Laurent Pinchart and committed by
Linus Walleij
fe1c9a82 3a7f520e

+314 -1
+135
Documentation/devicetree/bindings/pinctrl/renesas,pfc-pinctrl.txt
··· 1 + * Renesas Pin Function Controller (GPIO and Pin Mux/Config) 2 + 3 + The Pin Function Controller (PFC) is a Pin Mux/Config controller. On SH7372, 4 + SH73A0, R8A73A4 and R8A7740 it also acts as a GPIO controller. 5 + 6 + 7 + Pin Control 8 + ----------- 9 + 10 + Required Properties: 11 + 12 + - compatible: should be one of the following. 13 + - "renesas,pfc-r8a73a4": for R8A73A4 (R-Mobile APE6) compatible pin-controller. 14 + - "renesas,pfc-r8a7740": for R8A7740 (R-Mobile A1) compatible pin-controller. 15 + - "renesas,pfc-r8a7778": for R8A7778 (R-Mobile M1) compatible pin-controller. 16 + - "renesas,pfc-r8a7779": for R8A7779 (R-Car H1) compatible pin-controller. 17 + - "renesas,pfc-r8a7790": for R8A7790 (R-Car H2) compatible pin-controller. 18 + - "renesas,pfc-sh7372": for SH7372 (SH-Mobile AP4) compatible pin-controller. 19 + - "renesas,pfc-sh73a0": for SH73A0 (SH-Mobile AG5) compatible pin-controller. 20 + 21 + - reg: Base address and length of each memory resource used by the pin 22 + controller hardware module. 23 + 24 + Optional properties: 25 + 26 + - #gpio-range-cells: Mandatory when the PFC doesn't handle GPIO, forbidden 27 + otherwise. Should be 3. 28 + 29 + The PFC node also acts as a container for pin configuration nodes. Please refer 30 + to pinctrl-bindings.txt in this directory for the definition of the term "pin 31 + configuration node" and for the common pinctrl bindings used by client devices. 32 + 33 + Each pin configuration node represents desired functions to select on a pin 34 + group or a list of pin groups. The functions and pin groups can be specified 35 + directly in the pin configuration node, or grouped in child subnodes. Several 36 + functions can thus be referenced as a single pin configuration node by client 37 + devices. 38 + 39 + A configuration node or subnode must contain a function and reference at least 40 + one pin group. 41 + 42 + All pin configuration nodes and subnodes names are ignored. All of those nodes 43 + are parsed through phandles and processed purely based on their content. 44 + 45 + Pin Configuration Node Properties: 46 + 47 + - renesas,groups : An array of strings, each string containing the name of a pin 48 + group. 49 + 50 + - renesas,function: A string containing the name of the function to mux to the 51 + pin group(s) specified by the renesas,groups property 52 + 53 + Valid values for pin, group and function names can be found in the group and 54 + function arrays of the PFC data file corresponding to the SoC 55 + (drivers/pinctrl/sh-pfc/pfc-*.c) 56 + 57 + 58 + GPIO 59 + ---- 60 + 61 + On SH7372, SH73A0, R8A73A4 and R8A7740 the PFC node is also a GPIO controller 62 + node. 63 + 64 + Required Properties: 65 + 66 + - gpio-controller: Marks the device node as a gpio controller. 67 + 68 + - #gpio-cells: Should be 2. The first cell is the GPIO number and the second 69 + cell specifies GPIO flags, as defined in <dt-bindings/gpio/gpio.h>. Only the 70 + GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported. 71 + 72 + The syntax of the gpio specifier used by client nodes should be the following 73 + with values derived from the SoC user manual. 74 + 75 + <[phandle of the gpio controller node] 76 + [pin number within the gpio controller] 77 + [flags]> 78 + 79 + On other mach-shmobile platforms GPIO is handled by the gpio-rcar driver. 80 + Please refer to Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt 81 + for documentation of the GPIO device tree bindings on those platforms. 82 + 83 + 84 + Examples 85 + -------- 86 + 87 + Example 1: SH73A0 (SH-Mobile AG5) pin controller node 88 + 89 + pfc: pfc@e6050000 { 90 + compatible = "renesas,pfc-sh73a0"; 91 + reg = <0xe6050000 0x8000>, 92 + <0xe605801c 0x1c>; 93 + gpio-controller; 94 + #gpio-cells = <2>; 95 + }; 96 + 97 + Example 2: A GPIO LED node that references a GPIO 98 + 99 + #include <dt-bindings/gpio/gpio.h> 100 + 101 + leds { 102 + compatible = "gpio-leds"; 103 + led1 { 104 + gpios = <&pfc 20 GPIO_ACTIVE_LOW>; 105 + }; 106 + }; 107 + 108 + Example 3: KZM-A9-GT (SH-Mobile AG5) default pin state hog and pin control maps 109 + for the MMCIF and SCIFA4 devices 110 + 111 + &pfc { 112 + pinctrl-0 = <&scifa4_pins>; 113 + pinctrl-names = "default"; 114 + 115 + mmcif_pins: mmcif { 116 + renesas,groups = "mmc0_data8_0", "mmc0_ctrl_0"; 117 + renesas,function = "mmc0"; 118 + }; 119 + 120 + scifa4_pins: scifa4 { 121 + renesas,groups = "scifa4_data", "scifa4_ctrl"; 122 + renesas,function = "scifa4"; 123 + }; 124 + }; 125 + 126 + Example 4: KZM-A9-GT (SH-Mobile AG5) default pin state for the MMCIF device 127 + 128 + &mmcif { 129 + pinctrl-0 = <&mmcif_pins>; 130 + pinctrl-names = "default"; 131 + 132 + bus-width = <8>; 133 + vmmc-supply = <&reg_1p8v>; 134 + status = "okay"; 135 + };
+63 -1
drivers/pinctrl/sh-pfc/core.c
··· 18 18 #include <linux/ioport.h> 19 19 #include <linux/kernel.h> 20 20 #include <linux/module.h> 21 + #include <linux/of.h> 22 + #include <linux/of_device.h> 21 23 #include <linux/pinctrl/machine.h> 22 24 #include <linux/platform_device.h> 23 25 #include <linux/slab.h> ··· 350 348 return 0; 351 349 } 352 350 351 + #ifdef CONFIG_OF 352 + static const struct of_device_id sh_pfc_of_table[] = { 353 + #ifdef CONFIG_PINCTRL_PFC_R8A73A4 354 + { 355 + .compatible = "renesas,pfc-r8a73a4", 356 + .data = &r8a73a4_pinmux_info, 357 + }, 358 + #endif 359 + #ifdef CONFIG_PINCTRL_PFC_R8A7740 360 + { 361 + .compatible = "renesas,pfc-r8a7740", 362 + .data = &r8a7740_pinmux_info, 363 + }, 364 + #endif 365 + #ifdef CONFIG_PINCTRL_PFC_R8A7778 366 + { 367 + .compatible = "renesas,pfc-r8a7778", 368 + .data = &r8a7778_pinmux_info, 369 + }, 370 + #endif 371 + #ifdef CONFIG_PINCTRL_PFC_R8A7779 372 + { 373 + .compatible = "renesas,pfc-r8a7779", 374 + .data = &r8a7779_pinmux_info, 375 + }, 376 + #endif 377 + #ifdef CONFIG_PINCTRL_PFC_R8A7790 378 + { 379 + .compatible = "renesas,pfc-r8a7790", 380 + .data = &r8a7790_pinmux_info, 381 + }, 382 + #endif 383 + #ifdef CONFIG_PINCTRL_PFC_SH7372 384 + { 385 + .compatible = "renesas,pfc-sh7372", 386 + .data = &sh7372_pinmux_info, 387 + }, 388 + #endif 389 + #ifdef CONFIG_PINCTRL_PFC_SH73A0 390 + { 391 + .compatible = "renesas,pfc-sh73a0", 392 + .data = &sh73a0_pinmux_info, 393 + }, 394 + #endif 395 + { }, 396 + }; 397 + MODULE_DEVICE_TABLE(of, sh_pfc_of_table); 398 + #endif 399 + 353 400 static int sh_pfc_probe(struct platform_device *pdev) 354 401 { 402 + const struct platform_device_id *platid = platform_get_device_id(pdev); 403 + #ifdef CONFIG_OF 404 + struct device_node *np = pdev->dev.of_node; 405 + #endif 355 406 const struct sh_pfc_soc_info *info; 356 407 struct sh_pfc *pfc; 357 408 int ret; 358 409 359 - info = (void *)pdev->id_entry->driver_data; 410 + #ifdef CONFIG_OF 411 + if (np) 412 + info = of_match_device(sh_pfc_of_table, &pdev->dev)->data; 413 + else 414 + #endif 415 + info = platid ? (const void *)platid->driver_data : NULL; 416 + 360 417 if (info == NULL) 361 418 return -ENODEV; 362 419 ··· 541 480 .driver = { 542 481 .name = DRV_NAME, 543 482 .owner = THIS_MODULE, 483 + .of_match_table = of_match_ptr(sh_pfc_of_table), 544 484 }, 545 485 }; 546 486
+116
drivers/pinctrl/sh-pfc/pinctrl.c
··· 14 14 #include <linux/err.h> 15 15 #include <linux/init.h> 16 16 #include <linux/module.h> 17 + #include <linux/of.h> 17 18 #include <linux/pinctrl/consumer.h> 19 + #include <linux/pinctrl/machine.h> 18 20 #include <linux/pinctrl/pinconf.h> 19 21 #include <linux/pinctrl/pinconf-generic.h> 20 22 #include <linux/pinctrl/pinctrl.h> ··· 74 72 seq_printf(s, "%s", DRV_NAME); 75 73 } 76 74 75 + static int sh_pfc_dt_subnode_to_map(struct device *dev, struct device_node *np, 76 + struct pinctrl_map **map, 77 + unsigned int *num_maps, unsigned int *index) 78 + { 79 + struct pinctrl_map *maps = *map; 80 + unsigned int nmaps = *num_maps; 81 + unsigned int idx = *index; 82 + const char *function = NULL; 83 + struct property *prop; 84 + const char *group; 85 + int ret; 86 + 87 + /* Parse the function and configuration properties. At least a function 88 + * or one configuration must be specified. 89 + */ 90 + ret = of_property_read_string(np, "renesas,function", &function); 91 + if (ret < 0 && ret != -EINVAL) { 92 + dev_err(dev, "Invalid function in DT\n"); 93 + return ret; 94 + } 95 + 96 + if (!function) { 97 + dev_err(dev, "DT node must contain at least one function\n"); 98 + goto done; 99 + } 100 + 101 + /* Count the number of groups and reallocate mappings. */ 102 + ret = of_property_count_strings(np, "renesas,groups"); 103 + if (ret < 0 && ret != -EINVAL) { 104 + dev_err(dev, "Invalid pin groups list in DT\n"); 105 + goto done; 106 + } 107 + 108 + if (!ret) { 109 + dev_err(dev, "No group provided in DT node\n"); 110 + ret = -ENODEV; 111 + goto done; 112 + } 113 + 114 + nmaps += ret; 115 + 116 + maps = krealloc(maps, sizeof(*maps) * nmaps, GFP_KERNEL); 117 + if (maps == NULL) { 118 + ret = -ENOMEM; 119 + goto done; 120 + } 121 + 122 + *map = maps; 123 + *num_maps = nmaps; 124 + 125 + /* Iterate over pins and groups and create the mappings. */ 126 + of_property_for_each_string(np, "renesas,groups", prop, group) { 127 + maps[idx].type = PIN_MAP_TYPE_MUX_GROUP; 128 + maps[idx].data.mux.group = group; 129 + maps[idx].data.mux.function = function; 130 + idx++; 131 + } 132 + 133 + ret = 0; 134 + 135 + done: 136 + *index = idx; 137 + return ret; 138 + } 139 + 140 + static void sh_pfc_dt_free_map(struct pinctrl_dev *pctldev, 141 + struct pinctrl_map *map, unsigned num_maps) 142 + { 143 + kfree(map); 144 + } 145 + 146 + static int sh_pfc_dt_node_to_map(struct pinctrl_dev *pctldev, 147 + struct device_node *np, 148 + struct pinctrl_map **map, unsigned *num_maps) 149 + { 150 + struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); 151 + struct device *dev = pmx->pfc->dev; 152 + struct device_node *child; 153 + unsigned int index; 154 + int ret; 155 + 156 + *map = NULL; 157 + *num_maps = 0; 158 + index = 0; 159 + 160 + for_each_child_of_node(np, child) { 161 + ret = sh_pfc_dt_subnode_to_map(dev, child, map, num_maps, 162 + &index); 163 + if (ret < 0) 164 + goto done; 165 + } 166 + 167 + /* If no mapping has been found in child nodes try the config node. */ 168 + if (*num_maps == 0) { 169 + ret = sh_pfc_dt_subnode_to_map(dev, np, map, num_maps, &index); 170 + if (ret < 0) 171 + goto done; 172 + } 173 + 174 + if (*num_maps) 175 + return 0; 176 + 177 + dev_err(dev, "no mapping found in node %s\n", np->full_name); 178 + ret = -EINVAL; 179 + 180 + done: 181 + if (ret < 0) 182 + sh_pfc_dt_free_map(pctldev, *map, *num_maps); 183 + 184 + return ret; 185 + } 186 + 77 187 static const struct pinctrl_ops sh_pfc_pinctrl_ops = { 78 188 .get_groups_count = sh_pfc_get_groups_count, 79 189 .get_group_name = sh_pfc_get_group_name, 80 190 .get_group_pins = sh_pfc_get_group_pins, 81 191 .pin_dbg_show = sh_pfc_pin_dbg_show, 192 + .dt_node_to_map = sh_pfc_dt_node_to_map, 193 + .dt_free_map = sh_pfc_dt_free_map, 82 194 }; 83 195 84 196 static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)