Lines Matching +full:pctl +full:- +full:regmap
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Based on: pinctrl-pistachio.c
13 #include <dt-bindings/pinctrl/apple.h>
24 #include <linux/regmap.h>
29 #include "pinctrl-utils.h"
38 struct regmap *map;
80 /* No locking needed to mask/unmask IRQs as the interrupt mode is per pin-register. */
81 static void apple_gpio_set_reg(struct apple_gpio_pinctrl *pctl, in apple_gpio_set_reg() argument
84 regmap_update_bits(pctl->map, REG_GPIO(pin), mask, value); in apple_gpio_set_reg()
87 static u32 apple_gpio_get_reg(struct apple_gpio_pinctrl *pctl, in apple_gpio_get_reg() argument
93 ret = regmap_read(pctl->map, REG_GPIO(pin), &val); in apple_gpio_get_reg()
108 struct apple_gpio_pinctrl *pctl; in apple_gpio_dt_node_to_map() local
118 pctl = pinctrl_dev_get_drvdata(pctldev); in apple_gpio_dt_node_to_map()
122 dev_err(pctl->dev, in apple_gpio_dt_node_to_map()
125 return ret ? ret : -EINVAL; in apple_gpio_dt_node_to_map()
143 ret = -EINVAL; in apple_gpio_dt_node_to_map()
148 function_name = pinmux_generic_get_function_name(pctl->pctldev, func); in apple_gpio_dt_node_to_map()
149 ret = pinctrl_utils_add_map_mux(pctl->pctldev, map, in apple_gpio_dt_node_to_map()
176 struct apple_gpio_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in apple_gpio_pinmux_set() local
179 pctl, group, REG_GPIOx_PERIPH | REG_GPIOx_INPUT_ENABLE, in apple_gpio_pinmux_set()
197 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); in apple_gpio_get_direction() local
198 unsigned int reg = apple_gpio_get_reg(pctl, offset); in apple_gpio_get_direction()
207 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); in apple_gpio_get() local
208 unsigned int reg = apple_gpio_get_reg(pctl, offset); in apple_gpio_get()
212 * cached regmap value) in apple_gpio_get()
215 reg = readl_relaxed(pctl->base + REG_GPIO(offset)); in apple_gpio_get()
222 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); in apple_gpio_set() local
224 apple_gpio_set_reg(pctl, offset, REG_GPIOx_DATA, value ? REG_GPIOx_DATA : 0); in apple_gpio_set()
229 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); in apple_gpio_direction_input() local
231 apple_gpio_set_reg(pctl, offset, in apple_gpio_direction_input()
242 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); in apple_gpio_direction_output() local
244 apple_gpio_set_reg(pctl, offset, in apple_gpio_direction_output()
255 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(irq_data_get_irq_chip_data(data)); in apple_gpio_irq_ack() local
256 unsigned int irqgrp = FIELD_GET(REG_GPIOx_GRP, apple_gpio_get_reg(pctl, data->hwirq)); in apple_gpio_irq_ack()
258 writel(BIT(data->hwirq % 32), pctl->base + REG_IRQ(irqgrp, data->hwirq)); in apple_gpio_irq_ack()
282 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(gc); in apple_gpio_irq_mask() local
284 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, in apple_gpio_irq_mask()
286 gpiochip_disable_irq(gc, data->hwirq); in apple_gpio_irq_mask()
292 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(gc); in apple_gpio_irq_unmask() local
295 gpiochip_enable_irq(gc, data->hwirq); in apple_gpio_irq_unmask()
296 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, in apple_gpio_irq_unmask()
303 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); in apple_gpio_irq_startup() local
305 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_GRP, in apple_gpio_irq_startup()
308 apple_gpio_direction_input(chip, data->hwirq); in apple_gpio_irq_startup()
316 struct apple_gpio_pinctrl *pctl = gpiochip_get_data(irq_data_get_irq_chip_data(data)); in apple_gpio_irq_set_type() local
320 return -EINVAL; in apple_gpio_irq_set_type()
322 apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, in apple_gpio_irq_set_type()
336 struct apple_gpio_pinctrl *pctl; in apple_gpio_irq_handler() local
341 pctl = container_of(grpp - *grpp, typeof(*pctl), irqgrps[0]); in apple_gpio_irq_handler()
342 gc = &pctl->gpio_chip; in apple_gpio_irq_handler()
345 for (pinh = 0; pinh < gc->ngpio; pinh += 32) { in apple_gpio_irq_handler()
346 pending = readl_relaxed(pctl->base + REG_IRQ(*grpp, pinh)); in apple_gpio_irq_handler()
348 generic_handle_domain_irq(gc->irq.domain, pinh + pinl); in apple_gpio_irq_handler()
354 .name = "Apple-GPIO",
366 static int apple_gpio_register(struct apple_gpio_pinctrl *pctl) in apple_gpio_register() argument
368 struct gpio_irq_chip *girq = &pctl->gpio_chip.irq; in apple_gpio_register()
372 pctl->gpio_chip.label = dev_name(pctl->dev); in apple_gpio_register()
373 pctl->gpio_chip.request = gpiochip_generic_request; in apple_gpio_register()
374 pctl->gpio_chip.free = gpiochip_generic_free; in apple_gpio_register()
375 pctl->gpio_chip.get_direction = apple_gpio_get_direction; in apple_gpio_register()
376 pctl->gpio_chip.direction_input = apple_gpio_direction_input; in apple_gpio_register()
377 pctl->gpio_chip.direction_output = apple_gpio_direction_output; in apple_gpio_register()
378 pctl->gpio_chip.get = apple_gpio_get; in apple_gpio_register()
379 pctl->gpio_chip.set = apple_gpio_set; in apple_gpio_register()
380 pctl->gpio_chip.base = -1; in apple_gpio_register()
381 pctl->gpio_chip.ngpio = pctl->pinctrl_desc.npins; in apple_gpio_register()
382 pctl->gpio_chip.parent = pctl->dev; in apple_gpio_register()
384 if (girq->num_parents) { in apple_gpio_register()
388 girq->parent_handler = apple_gpio_irq_handler; in apple_gpio_register()
390 girq->parents = kmalloc_array(girq->num_parents, in apple_gpio_register()
391 sizeof(*girq->parents), in apple_gpio_register()
393 irq_data = kmalloc_array(girq->num_parents, sizeof(*irq_data), in apple_gpio_register()
395 if (!girq->parents || !irq_data) { in apple_gpio_register()
396 ret = -ENOMEM; in apple_gpio_register()
400 for (i = 0; i < girq->num_parents; i++) { in apple_gpio_register()
401 ret = platform_get_irq(to_platform_device(pctl->dev), i); in apple_gpio_register()
405 girq->parents[i] = ret; in apple_gpio_register()
406 pctl->irqgrps[i] = i; in apple_gpio_register()
407 irq_data[i] = &pctl->irqgrps[i]; in apple_gpio_register()
410 girq->parent_handler_data_array = irq_data; in apple_gpio_register()
411 girq->per_parent_data = true; in apple_gpio_register()
412 girq->default_type = IRQ_TYPE_NONE; in apple_gpio_register()
413 girq->handler = handle_level_irq; in apple_gpio_register()
416 ret = devm_gpiochip_add_data(pctl->dev, &pctl->gpio_chip, pctl); in apple_gpio_register()
419 kfree(girq->parents); in apple_gpio_register()
427 struct apple_gpio_pinctrl *pctl; in apple_gpio_pinctrl_probe() local
438 if (of_property_read_bool(pdev->dev.of_node, "interrupt-controller")) { in apple_gpio_pinctrl_probe()
444 pctl = devm_kzalloc(&pdev->dev, struct_size(pctl, irqgrps, nirqs), in apple_gpio_pinctrl_probe()
446 if (!pctl) in apple_gpio_pinctrl_probe()
447 return -ENOMEM; in apple_gpio_pinctrl_probe()
448 pctl->dev = &pdev->dev; in apple_gpio_pinctrl_probe()
449 pctl->gpio_chip.irq.num_parents = nirqs; in apple_gpio_pinctrl_probe()
450 dev_set_drvdata(&pdev->dev, pctl); in apple_gpio_pinctrl_probe()
452 if (of_property_read_u32(pdev->dev.of_node, "apple,npins", &npins)) in apple_gpio_pinctrl_probe()
453 return dev_err_probe(&pdev->dev, -EINVAL, in apple_gpio_pinctrl_probe()
456 pins = devm_kmalloc_array(&pdev->dev, npins, sizeof(pins[0]), in apple_gpio_pinctrl_probe()
458 pin_names = devm_kmalloc_array(&pdev->dev, npins, sizeof(pin_names[0]), in apple_gpio_pinctrl_probe()
460 pin_nums = devm_kmalloc_array(&pdev->dev, npins, sizeof(pin_nums[0]), in apple_gpio_pinctrl_probe()
463 return -ENOMEM; in apple_gpio_pinctrl_probe()
465 pctl->base = devm_platform_ioremap_resource(pdev, 0); in apple_gpio_pinctrl_probe()
466 if (IS_ERR(pctl->base)) in apple_gpio_pinctrl_probe()
467 return PTR_ERR(pctl->base); in apple_gpio_pinctrl_probe()
469 pctl->map = devm_regmap_init_mmio(&pdev->dev, pctl->base, ®map_config); in apple_gpio_pinctrl_probe()
470 if (IS_ERR(pctl->map)) in apple_gpio_pinctrl_probe()
471 return dev_err_probe(&pdev->dev, PTR_ERR(pctl->map), in apple_gpio_pinctrl_probe()
472 "Failed to create regmap\n"); in apple_gpio_pinctrl_probe()
476 pins[i].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "PIN%u", i); in apple_gpio_pinctrl_probe()
478 return -ENOMEM; in apple_gpio_pinctrl_probe()
480 pins[i].drv_data = pctl; in apple_gpio_pinctrl_probe()
485 pctl->pinctrl_desc.name = dev_name(pctl->dev); in apple_gpio_pinctrl_probe()
486 pctl->pinctrl_desc.pins = pins; in apple_gpio_pinctrl_probe()
487 pctl->pinctrl_desc.npins = npins; in apple_gpio_pinctrl_probe()
488 pctl->pinctrl_desc.pctlops = &apple_gpio_pinctrl_ops; in apple_gpio_pinctrl_probe()
489 pctl->pinctrl_desc.pmxops = &apple_gpio_pinmux_ops; in apple_gpio_pinctrl_probe()
491 pctl->pctldev = devm_pinctrl_register(&pdev->dev, &pctl->pinctrl_desc, pctl); in apple_gpio_pinctrl_probe()
492 if (IS_ERR(pctl->pctldev)) in apple_gpio_pinctrl_probe()
493 return dev_err_probe(&pdev->dev, PTR_ERR(pctl->pctldev), in apple_gpio_pinctrl_probe()
497 res = pinctrl_generic_add_group(pctl->pctldev, pins[i].name, in apple_gpio_pinctrl_probe()
498 pin_nums + i, 1, pctl); in apple_gpio_pinctrl_probe()
500 return dev_err_probe(pctl->dev, res, in apple_gpio_pinctrl_probe()
505 res = pinmux_generic_add_function(pctl->pctldev, pinmux_functions[i], in apple_gpio_pinctrl_probe()
506 pin_names, npins, pctl); in apple_gpio_pinctrl_probe()
508 return dev_err_probe(pctl->dev, res, in apple_gpio_pinctrl_probe()
512 return apple_gpio_register(pctl); in apple_gpio_pinctrl_probe()
523 .name = "apple-gpio-pinctrl",