Lines Matching +full:single +full:- +full:chip
1 // SPDX-License-Identifier: GPL-2.0
23 #define DRIVER_NAME "pinctrl-rza2"
51 #define RZA2_PDR(port) (0x0000 + (port) * 2) /* Direction 16-bit */
52 #define RZA2_PODR(port) (0x0040 + (port)) /* Output Data 8-bit */
53 #define RZA2_PIDR(port) (0x0060 + (port)) /* Input Data 8-bit */
54 #define RZA2_PMR(port) (0x0080 + (port)) /* Mode 8-bit */
55 #define RZA2_DSCR(port) (0x0140 + (port) * 2) /* Drive 16-bit */
56 #define RZA2_PFS(port, pin) (0x0200 + ((port) * 8) + (pin)) /* Fnct 8-bit */
58 #define RZA2_PWPR 0x02ff /* Write Protect 8-bit */
59 #define RZA2_PFENET 0x0820 /* Ethernet Pins 8-bit */
60 #define RZA2_PPOC 0x0900 /* Dedicated Pins 32-bit */
61 #define RZA2_PHMOMO 0x0980 /* Peripheral Pins 32-bit */
62 #define RZA2_PCKIO 0x09d0 /* CKIO Drive 8-bit */
79 /* Set pin to 'Non-use (Hi-z input protection)' */ in rza2_set_pin_function()
127 static int rza2_chip_get_direction(struct gpio_chip *chip, unsigned int offset) in rza2_chip_get_direction() argument
129 struct rza2_pinctrl_priv *priv = gpiochip_get_data(chip); in rza2_chip_get_direction()
134 reg16 = readw(priv->base + RZA2_PDR(port)); in rza2_chip_get_direction()
144 * This GPIO controller has a default Hi-Z state that is not input or in rza2_chip_get_direction()
147 rza2_pin_to_gpio(priv->base, offset, 1); in rza2_chip_get_direction()
152 static int rza2_chip_direction_input(struct gpio_chip *chip, in rza2_chip_direction_input() argument
155 struct rza2_pinctrl_priv *priv = gpiochip_get_data(chip); in rza2_chip_direction_input()
157 rza2_pin_to_gpio(priv->base, offset, 1); in rza2_chip_direction_input()
162 static int rza2_chip_get(struct gpio_chip *chip, unsigned int offset) in rza2_chip_get() argument
164 struct rza2_pinctrl_priv *priv = gpiochip_get_data(chip); in rza2_chip_get()
168 return !!(readb(priv->base + RZA2_PIDR(port)) & BIT(pin)); in rza2_chip_get()
171 static void rza2_chip_set(struct gpio_chip *chip, unsigned int offset, in rza2_chip_set() argument
174 struct rza2_pinctrl_priv *priv = gpiochip_get_data(chip); in rza2_chip_set()
179 new_value = readb(priv->base + RZA2_PODR(port)); in rza2_chip_set()
186 writeb(new_value, priv->base + RZA2_PODR(port)); in rza2_chip_set()
189 static int rza2_chip_direction_output(struct gpio_chip *chip, in rza2_chip_direction_output() argument
192 struct rza2_pinctrl_priv *priv = gpiochip_get_data(chip); in rza2_chip_direction_output()
194 rza2_chip_set(chip, offset, val); in rza2_chip_direction_output()
195 rza2_pin_to_gpio(priv->base, offset, 0); in rza2_chip_direction_output()
226 static struct gpio_chip chip = { variable
228 .base = -1,
238 struct device_node *np = priv->dev->of_node; in rza2_gpio_register()
242 chip.label = devm_kasprintf(priv->dev, GFP_KERNEL, "%pOFn", np); in rza2_gpio_register()
243 chip.of_node = np; in rza2_gpio_register()
244 chip.parent = priv->dev; in rza2_gpio_register()
245 chip.ngpio = priv->npins; in rza2_gpio_register()
247 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, in rza2_gpio_register()
250 dev_err(priv->dev, "Unable to parse gpio-ranges\n"); in rza2_gpio_register()
256 (of_args.args[2] != priv->npins)) { in rza2_gpio_register()
257 dev_err(priv->dev, "gpio-ranges does not match selected SOC\n"); in rza2_gpio_register()
258 return -EINVAL; in rza2_gpio_register()
260 priv->gpio_range.id = 0; in rza2_gpio_register()
261 priv->gpio_range.pin_base = priv->gpio_range.base = 0; in rza2_gpio_register()
262 priv->gpio_range.npins = priv->npins; in rza2_gpio_register()
263 priv->gpio_range.name = chip.label; in rza2_gpio_register()
264 priv->gpio_range.gc = &chip; in rza2_gpio_register()
266 /* Register our gpio chip with gpiolib */ in rza2_gpio_register()
267 ret = devm_gpiochip_add_data(priv->dev, &chip, priv); in rza2_gpio_register()
272 pinctrl_add_gpio_range(priv->pctl, &priv->gpio_range); in rza2_gpio_register()
274 dev_dbg(priv->dev, "Registered gpio controller\n"); in rza2_gpio_register()
285 pins = devm_kcalloc(priv->dev, priv->npins, sizeof(*pins), GFP_KERNEL); in rza2_pinctrl_register()
287 return -ENOMEM; in rza2_pinctrl_register()
289 priv->pins = pins; in rza2_pinctrl_register()
290 priv->desc.pins = pins; in rza2_pinctrl_register()
291 priv->desc.npins = priv->npins; in rza2_pinctrl_register()
293 for (i = 0; i < priv->npins; i++) { in rza2_pinctrl_register()
298 ret = devm_pinctrl_register_and_init(priv->dev, &priv->desc, priv, in rza2_pinctrl_register()
299 &priv->pctl); in rza2_pinctrl_register()
301 dev_err(priv->dev, "pinctrl registration failed\n"); in rza2_pinctrl_register()
305 ret = pinctrl_enable(priv->pctl); in rza2_pinctrl_register()
307 dev_err(priv->dev, "pinctrl enable failed\n"); in rza2_pinctrl_register()
313 dev_err(priv->dev, "GPIO registration failed\n"); in rza2_pinctrl_register()
321 * For each DT node, create a single pin mapping. That pin mapping will only
322 * contain a single group of pins, and that group of pins will only have a
323 * single function that can be selected.
339 dev_info(priv->dev, "Missing pinmux property\n"); in rza2_dt_node_to_map()
340 return -ENOENT; in rza2_dt_node_to_map()
342 npins = of_pins->length / sizeof(u32); in rza2_dt_node_to_map()
344 pins = devm_kcalloc(priv->dev, npins, sizeof(*pins), GFP_KERNEL); in rza2_dt_node_to_map()
345 psel_val = devm_kcalloc(priv->dev, npins, sizeof(*psel_val), in rza2_dt_node_to_map()
347 pin_fn = devm_kzalloc(priv->dev, sizeof(*pin_fn), GFP_KERNEL); in rza2_dt_node_to_map()
349 return -ENOMEM; in rza2_dt_node_to_map()
362 /* Register a single pin group listing all the pins we read from DT */ in rza2_dt_node_to_map()
363 gsel = pinctrl_generic_add_group(pctldev, np->name, pins, npins, NULL); in rza2_dt_node_to_map()
368 * Register a single group function where the 'data' is an array PSEL in rza2_dt_node_to_map()
371 pin_fn[0] = np->name; in rza2_dt_node_to_map()
372 fsel = pinmux_generic_add_function(pctldev, np->name, pin_fn, 1, in rza2_dt_node_to_map()
379 dev_dbg(priv->dev, "Parsed %pOF with %d pins\n", np, npins); in rza2_dt_node_to_map()
385 ret = -ENOMEM; in rza2_dt_node_to_map()
389 (*map)->type = PIN_MAP_TYPE_MUX_GROUP; in rza2_dt_node_to_map()
390 (*map)->data.mux.group = np->name; in rza2_dt_node_to_map()
391 (*map)->data.mux.function = np->name; in rza2_dt_node_to_map()
402 dev_err(priv->dev, "Unable to parse DT node %s\n", np->name); in rza2_dt_node_to_map()
431 return -EINVAL; in rza2_set_mux()
435 return -EINVAL; in rza2_set_mux()
437 psel_val = func->data; in rza2_set_mux()
439 for (i = 0; i < grp->num_pins; ++i) { in rza2_set_mux()
440 dev_dbg(priv->dev, "Setting P%c_%d to PSEL=%d\n", in rza2_set_mux()
441 port_names[RZA2_PIN_ID_TO_PORT(grp->pins[i])], in rza2_set_mux()
442 RZA2_PIN_ID_TO_PIN(grp->pins[i]), in rza2_set_mux()
445 priv->base, in rza2_set_mux()
446 RZA2_PIN_ID_TO_PORT(grp->pins[i]), in rza2_set_mux()
447 RZA2_PIN_ID_TO_PIN(grp->pins[i]), in rza2_set_mux()
467 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in rza2_pinctrl_probe()
469 return -ENOMEM; in rza2_pinctrl_probe()
471 priv->dev = &pdev->dev; in rza2_pinctrl_probe()
473 priv->base = devm_platform_ioremap_resource(pdev, 0); in rza2_pinctrl_probe()
474 if (IS_ERR(priv->base)) in rza2_pinctrl_probe()
475 return PTR_ERR(priv->base); in rza2_pinctrl_probe()
479 priv->npins = (int)(uintptr_t)of_device_get_match_data(&pdev->dev) * in rza2_pinctrl_probe()
482 priv->desc.name = DRIVER_NAME; in rza2_pinctrl_probe()
483 priv->desc.pctlops = &rza2_pinctrl_ops; in rza2_pinctrl_probe()
484 priv->desc.pmxops = &rza2_pinmux_ops; in rza2_pinctrl_probe()
485 priv->desc.owner = THIS_MODULE; in rza2_pinctrl_probe()
491 dev_info(&pdev->dev, "Registered ports P0 - P%c\n", in rza2_pinctrl_probe()
492 port_names[priv->desc.npins / RZA2_PINS_PER_PORT - 1]); in rza2_pinctrl_probe()
498 { .compatible = "renesas,r7s9210-pinctrl", .data = (void *)22, },