Lines Matching +full:- +full:pinfunc

1 // SPDX-License-Identifier: GPL-2.0-only
8 * Based on: pinctrl-pistachio.c
13 #include <dt-bindings/pinctrl/apple.h>
26 #include "pinctrl-utils.h"
77 /* No locking needed to mask/unmask IRQs as the interrupt mode is per pin-register. */
81 regmap_update_bits(pctl->map, REG_GPIO(pin), mask, value); in apple_gpio_set_reg()
90 ret = regmap_read(pctl->map, REG_GPIO(pin), &val); in apple_gpio_get_reg()
106 u32 pinfunc, pin, func; in apple_gpio_dt_node_to_map() local
119 dev_err(pctl->dev, in apple_gpio_dt_node_to_map()
122 return ret ? ret : -EINVAL; in apple_gpio_dt_node_to_map()
132 ret = of_property_read_u32_index(node, "pinmux", i, &pinfunc); in apple_gpio_dt_node_to_map()
136 pin = APPLE_PIN(pinfunc); in apple_gpio_dt_node_to_map()
137 func = APPLE_FUNC(pinfunc); in apple_gpio_dt_node_to_map()
140 ret = -EINVAL; in apple_gpio_dt_node_to_map()
145 function_name = pinmux_generic_get_function_name(pctl->pctldev, func); in apple_gpio_dt_node_to_map()
146 ret = pinctrl_utils_add_map_mux(pctl->pctldev, map, in apple_gpio_dt_node_to_map()
212 reg = readl_relaxed(pctl->base + REG_GPIO(offset)); in apple_gpio_get()
253 unsigned int irqgrp = FIELD_GET(REG_GPIOx_GRP, apple_gpio_get_reg(pctl, data->hwirq)); in apple_gpio_irq_ack()
255 writel(BIT(data->hwirq % 32), pctl->base + REG_IRQ(irqgrp, data->hwirq)); in apple_gpio_irq_ack()
281 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, in apple_gpio_irq_mask()
283 gpiochip_disable_irq(gc, data->hwirq); in apple_gpio_irq_mask()
292 gpiochip_enable_irq(gc, data->hwirq); in apple_gpio_irq_unmask()
293 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, in apple_gpio_irq_unmask()
302 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_GRP, in apple_gpio_irq_startup()
305 apple_gpio_direction_input(chip, data->hwirq); in apple_gpio_irq_startup()
317 return -EINVAL; in apple_gpio_irq_set_type()
319 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, in apple_gpio_irq_set_type()
338 pctl = container_of(grpp - *grpp, typeof(*pctl), irqgrps[0]); in apple_gpio_irq_handler()
339 gc = &pctl->gpio_chip; in apple_gpio_irq_handler()
342 for (pinh = 0; pinh < gc->ngpio; pinh += 32) { in apple_gpio_irq_handler()
343 pending = readl_relaxed(pctl->base + REG_IRQ(*grpp, pinh)); in apple_gpio_irq_handler()
345 generic_handle_domain_irq(gc->irq.domain, pinh + pinl); in apple_gpio_irq_handler()
351 .name = "Apple-GPIO",
365 struct gpio_irq_chip *girq = &pctl->gpio_chip.irq; in apple_gpio_register()
369 pctl->gpio_chip.label = dev_name(pctl->dev); in apple_gpio_register()
370 pctl->gpio_chip.request = gpiochip_generic_request; in apple_gpio_register()
371 pctl->gpio_chip.free = gpiochip_generic_free; in apple_gpio_register()
372 pctl->gpio_chip.get_direction = apple_gpio_get_direction; in apple_gpio_register()
373 pctl->gpio_chip.direction_input = apple_gpio_direction_input; in apple_gpio_register()
374 pctl->gpio_chip.direction_output = apple_gpio_direction_output; in apple_gpio_register()
375 pctl->gpio_chip.get = apple_gpio_get; in apple_gpio_register()
376 pctl->gpio_chip.set = apple_gpio_set; in apple_gpio_register()
377 pctl->gpio_chip.base = -1; in apple_gpio_register()
378 pctl->gpio_chip.ngpio = pctl->pinctrl_desc.npins; in apple_gpio_register()
379 pctl->gpio_chip.parent = pctl->dev; in apple_gpio_register()
381 if (girq->num_parents) { in apple_gpio_register()
385 girq->parent_handler = apple_gpio_irq_handler; in apple_gpio_register()
387 girq->parents = kmalloc_array(girq->num_parents, in apple_gpio_register()
388 sizeof(*girq->parents), in apple_gpio_register()
390 irq_data = kmalloc_array(girq->num_parents, sizeof(*irq_data), in apple_gpio_register()
392 if (!girq->parents || !irq_data) { in apple_gpio_register()
393 ret = -ENOMEM; in apple_gpio_register()
397 for (i = 0; i < girq->num_parents; i++) { in apple_gpio_register()
398 ret = platform_get_irq(to_platform_device(pctl->dev), i); in apple_gpio_register()
402 girq->parents[i] = ret; in apple_gpio_register()
403 pctl->irqgrps[i] = i; in apple_gpio_register()
404 irq_data[i] = &pctl->irqgrps[i]; in apple_gpio_register()
407 girq->parent_handler_data_array = irq_data; in apple_gpio_register()
408 girq->per_parent_data = true; in apple_gpio_register()
409 girq->default_type = IRQ_TYPE_NONE; in apple_gpio_register()
410 girq->handler = handle_level_irq; in apple_gpio_register()
413 ret = devm_gpiochip_add_data(pctl->dev, &pctl->gpio_chip, pctl); in apple_gpio_register()
416 kfree(girq->parents); in apple_gpio_register()
435 if (of_property_read_bool(pdev->dev.of_node, "interrupt-controller")) { in apple_gpio_pinctrl_probe()
441 pctl = devm_kzalloc(&pdev->dev, struct_size(pctl, irqgrps, nirqs), in apple_gpio_pinctrl_probe()
444 return -ENOMEM; in apple_gpio_pinctrl_probe()
445 pctl->dev = &pdev->dev; in apple_gpio_pinctrl_probe()
446 pctl->gpio_chip.irq.num_parents = nirqs; in apple_gpio_pinctrl_probe()
447 dev_set_drvdata(&pdev->dev, pctl); in apple_gpio_pinctrl_probe()
449 if (of_property_read_u32(pdev->dev.of_node, "apple,npins", &npins)) in apple_gpio_pinctrl_probe()
450 return dev_err_probe(&pdev->dev, -EINVAL, in apple_gpio_pinctrl_probe()
453 pins = devm_kmalloc_array(&pdev->dev, npins, sizeof(pins[0]), in apple_gpio_pinctrl_probe()
455 pin_names = devm_kmalloc_array(&pdev->dev, npins, sizeof(pin_names[0]), in apple_gpio_pinctrl_probe()
457 pin_nums = devm_kmalloc_array(&pdev->dev, npins, sizeof(pin_nums[0]), in apple_gpio_pinctrl_probe()
460 return -ENOMEM; in apple_gpio_pinctrl_probe()
462 pctl->base = devm_platform_ioremap_resource(pdev, 0); in apple_gpio_pinctrl_probe()
463 if (IS_ERR(pctl->base)) in apple_gpio_pinctrl_probe()
464 return PTR_ERR(pctl->base); in apple_gpio_pinctrl_probe()
466 pctl->map = devm_regmap_init_mmio(&pdev->dev, pctl->base, &regmap_config); in apple_gpio_pinctrl_probe()
467 if (IS_ERR(pctl->map)) in apple_gpio_pinctrl_probe()
468 return dev_err_probe(&pdev->dev, PTR_ERR(pctl->map), in apple_gpio_pinctrl_probe()
473 pins[i].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "PIN%u", i); in apple_gpio_pinctrl_probe()
479 pctl->pinctrl_desc.name = dev_name(pctl->dev); in apple_gpio_pinctrl_probe()
480 pctl->pinctrl_desc.pins = pins; in apple_gpio_pinctrl_probe()
481 pctl->pinctrl_desc.npins = npins; in apple_gpio_pinctrl_probe()
482 pctl->pinctrl_desc.pctlops = &apple_gpio_pinctrl_ops; in apple_gpio_pinctrl_probe()
483 pctl->pinctrl_desc.pmxops = &apple_gpio_pinmux_ops; in apple_gpio_pinctrl_probe()
485 pctl->pctldev = devm_pinctrl_register(&pdev->dev, &pctl->pinctrl_desc, pctl); in apple_gpio_pinctrl_probe()
486 if (IS_ERR(pctl->pctldev)) in apple_gpio_pinctrl_probe()
487 return dev_err_probe(&pdev->dev, PTR_ERR(pctl->pctldev), in apple_gpio_pinctrl_probe()
491 res = pinctrl_generic_add_group(pctl->pctldev, pins[i].name, in apple_gpio_pinctrl_probe()
494 return dev_err_probe(pctl->dev, res, in apple_gpio_pinctrl_probe()
499 res = pinmux_generic_add_function(pctl->pctldev, pinmux_functions[i], in apple_gpio_pinctrl_probe()
502 return dev_err_probe(pctl->dev, res, in apple_gpio_pinctrl_probe()
517 .name = "apple-gpio-pinctrl",