Lines Matching +full:dt +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2017-2025 Arm Ltd.
5 * Generic DT driven Allwinner pinctrl driver routines.
7 * described in the DT. Then hands those tables of to the traditional
10 * out in a per-SoC .c file. This code generates this table, like so:
18 * SUNXI_FUNCTION(0x2, "mmc0"), // based on pingroup found in DT:
19 * // mmc0-pins {
36 #include "pinctrl-sunxi.h"
46 static u8 sunxi_pinctrl_dt_read_pinmux(const struct device_node *node, in sunxi_pinctrl_dt_read_pinmux() argument
52 num_elems = of_property_count_u32_elems(node, "allwinner,pinmux"); in sunxi_pinctrl_dt_read_pinmux()
57 index = num_elems - 1; in sunxi_pinctrl_dt_read_pinmux()
59 ret = of_property_read_u32_index(node, "allwinner,pinmux", index, in sunxi_pinctrl_dt_read_pinmux()
79 int port_base = desc->pin_base / PINS_PER_BANK; in init_pins_table()
88 desc->npins += pins_per_bank[i]; in init_pins_table()
97 name_size += (pins_per_bank[i] - 10) * 5; in init_pins_table()
101 if (desc->npins == 0) { in init_pins_table()
103 return ERR_PTR(-EINVAL); in init_pins_table()
106 pins = devm_kzalloc(dev, desc->npins * sizeof(*pins), GFP_KERNEL); in init_pins_table()
108 return ERR_PTR(-ENOMEM); in init_pins_table()
113 return ERR_PTR(-ENOMEM); in init_pins_table()
123 cur_pin->pin.number = (port_base + i) * PINS_PER_BANK + j; in init_pins_table()
124 cur_pin->pin.name = cur_name; in init_pins_table()
134 * child node of the pinctrl DT node to find all advertised functions.
135 * Provide memory to hold the per-function information and assign it to
138 * an "irq" function at the end, for those pins in IRQ-capable ports.
139 * We do not fill in the extra functions (those describe in DT nodes) yet.
148 struct device_node *node; in prepare_function_table() local
155 * - one for GPIO in in prepare_function_table()
156 * - one for GPIO out in prepare_function_table()
157 * - one for the sentinel signalling the end of the list in prepare_function_table()
169 int bank = pin->pin.number / PINS_PER_BANK; in prepare_function_table()
172 pin->variant++; in prepare_function_table()
178 * Go over each pin group (every child of the pinctrl DT node) and in prepare_function_table()
183 for_each_child_of_node(pnode, node) { in prepare_function_table()
186 of_property_for_each_string(node, "pins", prop, name) { in prepare_function_table()
204 return -ENOMEM; in prepare_function_table()
214 int bank = pin->pin.number / PINS_PER_BANK; in prepare_function_table()
215 int lastfunc = pin->variant + 1; in prepare_function_table()
228 func[lastfunc].irqnum = pin->pin.number % PINS_PER_BANK; in prepare_function_table()
235 pin->functions = func; in prepare_function_table()
238 func += pin->variant + 3; in prepare_function_table()
244 pin->variant = 2; in prepare_function_table()
256 static void fill_pin_function(struct device *dev, struct device_node *node, in fill_pin_function() argument
265 if (of_property_read_string(node, "function", &funcname)) { in fill_pin_function()
271 of_property_for_each_string(node, "pins", prop, name) { in fill_pin_function()
278 of_node_full_name(node), name); in fill_pin_function()
284 muxval = sunxi_pinctrl_dt_read_pinmux(node, index); in fill_pin_function()
287 of_node_full_name(node), name); in fill_pin_function()
293 * Check for double definitions by comparing the to-be-added in fill_pin_function()
302 if (strcmp(func->name, funcname) && in fill_pin_function()
303 func->muxval != muxval) in fill_pin_function()
307 if (!strcmp(func->name, funcname) && in fill_pin_function()
308 muxval == func->muxval) in fill_pin_function()
325 func->muxval = muxval; in fill_pin_function()
326 func->name = funcname; in fill_pin_function()
337 * Then iterate over all pinctrl DT node children to enter the function name
347 struct device_node *pnode = pdev->dev.of_node, *node; in sunxi_pinctrl_dt_table_init() local
351 pins = init_pins_table(&pdev->dev, pins_per_bank, desc); in sunxi_pinctrl_dt_table_init()
355 ret = prepare_function_table(&pdev->dev, pnode, pins, desc->npins, in sunxi_pinctrl_dt_table_init()
364 for_each_child_of_node(pnode, node) in sunxi_pinctrl_dt_table_init()
365 fill_pin_function(&pdev->dev, node, pins, desc->npins); in sunxi_pinctrl_dt_table_init()
368 for (i = 0; i < desc->npins; i++) in sunxi_pinctrl_dt_table_init()
371 desc->pins = pins; in sunxi_pinctrl_dt_table_init()