Lines Matching +full:stmfx +full:- +full:0300
1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for STMicroelectronics Multi-Function eXpander (STMFX) GPIO expander
10 #include <linux/mfd/stmfx.h>
17 #include "pinctrl-utils.h"
50 * STMFX pinctrl can have up to 24 pins if STMFX other functions are not used.
51 * Pins availability is managed thanks to gpio-ranges property.
82 struct stmfx *stmfx; member
111 ret = regmap_read(pctl->stmfx->map, reg, &value); in stmfx_gpio_get()
122 regmap_write_bits(pctl->stmfx->map, reg + get_reg(offset), in stmfx_gpio_set()
134 ret = regmap_read(pctl->stmfx->map, reg, &val); in stmfx_gpio_get_direction()
136 * On stmfx, gpio pins direction is (0)input, (1)output. in stmfx_gpio_get_direction()
153 return regmap_write_bits(pctl->stmfx->map, reg, mask, 0); in stmfx_gpio_direction_input()
165 return regmap_write_bits(pctl->stmfx->map, reg, mask, mask); in stmfx_gpio_direction_output()
175 ret = regmap_read(pctl->stmfx->map, reg, &pupd); in stmfx_pinconf_get_pupd()
188 return regmap_write_bits(pctl->stmfx->map, reg, mask, pupd ? mask : 0); in stmfx_pinconf_set_pupd()
198 ret = regmap_read(pctl->stmfx->map, reg, &type); in stmfx_pinconf_get_type()
211 return regmap_write_bits(pctl->stmfx->map, reg, mask, type ? mask : 0); in stmfx_pinconf_set_type()
225 return -EINVAL; in stmfx_pinconf_get()
227 dir = stmfx_gpio_get_direction(&pctl->gpio_chip, pin); in stmfx_pinconf_get()
267 return -EINVAL; in stmfx_pinconf_get()
269 ret = stmfx_gpio_get(&pctl->gpio_chip, pin); in stmfx_pinconf_get()
276 return -ENOTSUPP; in stmfx_pinconf_get()
295 dev_err(pctldev->dev, "pin %d is not available\n", pin); in stmfx_pinconf_set()
296 return -EINVAL; in stmfx_pinconf_set()
333 ret = stmfx_gpio_direction_output(&pctl->gpio_chip, in stmfx_pinconf_set()
339 return -ENOTSUPP; in stmfx_pinconf_set()
357 dir = stmfx_gpio_get_direction(&pctl->gpio_chip, offset); in stmfx_pinconf_dbg_show()
366 val = stmfx_gpio_get(&pctl->gpio_chip, offset); in stmfx_pinconf_dbg_show()
373 seq_printf(s, "open drain %s internal pull-up ", in stmfx_pinconf_dbg_show()
380 seq_printf(s, "with internal pull-%s ", in stmfx_pinconf_dbg_show()
409 return -ENOTSUPP; in stmfx_pinctrl_get_group_pins()
424 u32 reg = get_reg(data->hwirq); in stmfx_pinctrl_irq_mask()
425 u32 mask = get_mask(data->hwirq); in stmfx_pinctrl_irq_mask()
427 pctl->irq_gpi_src[reg] &= ~mask; in stmfx_pinctrl_irq_mask()
434 u32 reg = get_reg(data->hwirq); in stmfx_pinctrl_irq_unmask()
435 u32 mask = get_mask(data->hwirq); in stmfx_pinctrl_irq_unmask()
437 pctl->irq_gpi_src[reg] |= mask; in stmfx_pinctrl_irq_unmask()
444 u32 reg = get_reg(data->hwirq); in stmfx_pinctrl_irq_set_type()
445 u32 mask = get_mask(data->hwirq); in stmfx_pinctrl_irq_set_type()
448 return -EINVAL; in stmfx_pinctrl_irq_set_type()
451 pctl->irq_gpi_evt[reg] |= mask; in stmfx_pinctrl_irq_set_type()
454 pctl->irq_gpi_evt[reg] &= ~mask; in stmfx_pinctrl_irq_set_type()
459 pctl->irq_gpi_type[reg] |= mask; in stmfx_pinctrl_irq_set_type()
461 pctl->irq_gpi_type[reg] &= ~mask; in stmfx_pinctrl_irq_set_type()
471 pctl->irq_toggle_edge[reg] |= mask; in stmfx_pinctrl_irq_set_type()
473 pctl->irq_toggle_edge[reg] &= mask; in stmfx_pinctrl_irq_set_type()
483 mutex_lock(&pctl->lock); in stmfx_pinctrl_irq_bus_lock()
490 u32 reg = get_reg(data->hwirq); in stmfx_pinctrl_irq_bus_sync_unlock()
491 u32 mask = get_mask(data->hwirq); in stmfx_pinctrl_irq_bus_sync_unlock()
498 if (pctl->irq_toggle_edge[reg] & mask) { in stmfx_pinctrl_irq_bus_sync_unlock()
499 if (stmfx_gpio_get(gpio_chip, data->hwirq)) in stmfx_pinctrl_irq_bus_sync_unlock()
500 pctl->irq_gpi_type[reg] &= ~mask; in stmfx_pinctrl_irq_bus_sync_unlock()
502 pctl->irq_gpi_type[reg] |= mask; in stmfx_pinctrl_irq_bus_sync_unlock()
505 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_EVT, in stmfx_pinctrl_irq_bus_sync_unlock()
506 pctl->irq_gpi_evt, NR_GPIO_REGS); in stmfx_pinctrl_irq_bus_sync_unlock()
507 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_TYPE, in stmfx_pinctrl_irq_bus_sync_unlock()
508 pctl->irq_gpi_type, NR_GPIO_REGS); in stmfx_pinctrl_irq_bus_sync_unlock()
509 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_irq_bus_sync_unlock()
510 pctl->irq_gpi_src, NR_GPIO_REGS); in stmfx_pinctrl_irq_bus_sync_unlock()
512 mutex_unlock(&pctl->lock); in stmfx_pinctrl_irq_bus_sync_unlock()
520 ret = stmfx_gpio_direction_input(gpio_chip, data->hwirq); in stmfx_gpio_irq_request_resources()
524 return gpiochip_reqres_irq(gpio_chip, data->hwirq); in stmfx_gpio_irq_request_resources()
531 return gpiochip_relres_irq(gpio_chip, data->hwirq); in stmfx_gpio_irq_release_resources()
541 if (!(pctl->irq_toggle_edge[reg] & mask)) in stmfx_pinctrl_irq_toggle_trigger()
544 val = stmfx_gpio_get(&pctl->gpio_chip, offset); in stmfx_pinctrl_irq_toggle_trigger()
549 pctl->irq_gpi_type[reg] &= mask; in stmfx_pinctrl_irq_toggle_trigger()
550 regmap_write_bits(pctl->stmfx->map, in stmfx_pinctrl_irq_toggle_trigger()
555 pctl->irq_gpi_type[reg] |= mask; in stmfx_pinctrl_irq_toggle_trigger()
556 regmap_write_bits(pctl->stmfx->map, in stmfx_pinctrl_irq_toggle_trigger()
565 struct gpio_chip *gc = &pctl->gpio_chip; in stmfx_pinctrl_irq_thread_fn()
571 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_IRQ_GPI_PENDING, in stmfx_pinctrl_irq_thread_fn()
576 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_irq_thread_fn()
582 for_each_set_bit(n, &status, gc->ngpio) { in stmfx_pinctrl_irq_thread_fn()
583 handle_nested_irq(irq_find_mapping(gc->irq.domain, n)); in stmfx_pinctrl_irq_thread_fn()
587 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_irq_thread_fn()
588 pctl->irq_gpi_src, NR_GPIO_REGS); in stmfx_pinctrl_irq_thread_fn()
596 struct pinctrl_dev *pctl_dev = pctl->pctl_dev; in stmfx_pinctrl_gpio_function_enable()
599 pctl->gpio_valid_mask = GENMASK(15, 0); in stmfx_pinctrl_gpio_function_enable()
604 pctl->gpio_valid_mask |= GENMASK(19, 16); in stmfx_pinctrl_gpio_function_enable()
610 pctl->gpio_valid_mask |= GENMASK(23, 20); in stmfx_pinctrl_gpio_function_enable()
613 return stmfx_function_enable(pctl->stmfx, func); in stmfx_pinctrl_gpio_function_enable()
618 struct stmfx *stmfx = dev_get_drvdata(pdev->dev.parent); in stmfx_pinctrl_probe() local
619 struct device_node *np = pdev->dev.of_node; in stmfx_pinctrl_probe()
624 pctl = devm_kzalloc(stmfx->dev, sizeof(*pctl), GFP_KERNEL); in stmfx_pinctrl_probe()
626 return -ENOMEM; in stmfx_pinctrl_probe()
630 pctl->dev = &pdev->dev; in stmfx_pinctrl_probe()
631 pctl->stmfx = stmfx; in stmfx_pinctrl_probe()
633 if (!of_find_property(np, "gpio-ranges", NULL)) { in stmfx_pinctrl_probe()
634 dev_err(pctl->dev, "missing required gpio-ranges property\n"); in stmfx_pinctrl_probe()
635 return -EINVAL; in stmfx_pinctrl_probe()
640 return -ENXIO; in stmfx_pinctrl_probe()
642 mutex_init(&pctl->lock); in stmfx_pinctrl_probe()
645 pctl->pctl_desc.name = "stmfx-pinctrl"; in stmfx_pinctrl_probe()
646 pctl->pctl_desc.pctlops = &stmfx_pinctrl_ops; in stmfx_pinctrl_probe()
647 pctl->pctl_desc.confops = &stmfx_pinconf_ops; in stmfx_pinctrl_probe()
648 pctl->pctl_desc.pins = stmfx_pins; in stmfx_pinctrl_probe()
649 pctl->pctl_desc.npins = ARRAY_SIZE(stmfx_pins); in stmfx_pinctrl_probe()
650 pctl->pctl_desc.owner = THIS_MODULE; in stmfx_pinctrl_probe()
651 pctl->pctl_desc.link_consumers = true; in stmfx_pinctrl_probe()
653 ret = devm_pinctrl_register_and_init(pctl->dev, &pctl->pctl_desc, in stmfx_pinctrl_probe()
654 pctl, &pctl->pctl_dev); in stmfx_pinctrl_probe()
656 dev_err(pctl->dev, "pinctrl registration failed\n"); in stmfx_pinctrl_probe()
660 ret = pinctrl_enable(pctl->pctl_dev); in stmfx_pinctrl_probe()
662 dev_err(pctl->dev, "pinctrl enable failed\n"); in stmfx_pinctrl_probe()
667 pctl->gpio_chip.label = "stmfx-gpio"; in stmfx_pinctrl_probe()
668 pctl->gpio_chip.parent = pctl->dev; in stmfx_pinctrl_probe()
669 pctl->gpio_chip.get_direction = stmfx_gpio_get_direction; in stmfx_pinctrl_probe()
670 pctl->gpio_chip.direction_input = stmfx_gpio_direction_input; in stmfx_pinctrl_probe()
671 pctl->gpio_chip.direction_output = stmfx_gpio_direction_output; in stmfx_pinctrl_probe()
672 pctl->gpio_chip.get = stmfx_gpio_get; in stmfx_pinctrl_probe()
673 pctl->gpio_chip.set = stmfx_gpio_set; in stmfx_pinctrl_probe()
674 pctl->gpio_chip.set_config = gpiochip_generic_config; in stmfx_pinctrl_probe()
675 pctl->gpio_chip.base = -1; in stmfx_pinctrl_probe()
676 pctl->gpio_chip.ngpio = pctl->pctl_desc.npins; in stmfx_pinctrl_probe()
677 pctl->gpio_chip.can_sleep = true; in stmfx_pinctrl_probe()
678 pctl->gpio_chip.of_node = np; in stmfx_pinctrl_probe()
680 pctl->irq_chip.name = dev_name(pctl->dev); in stmfx_pinctrl_probe()
681 pctl->irq_chip.irq_mask = stmfx_pinctrl_irq_mask; in stmfx_pinctrl_probe()
682 pctl->irq_chip.irq_unmask = stmfx_pinctrl_irq_unmask; in stmfx_pinctrl_probe()
683 pctl->irq_chip.irq_set_type = stmfx_pinctrl_irq_set_type; in stmfx_pinctrl_probe()
684 pctl->irq_chip.irq_bus_lock = stmfx_pinctrl_irq_bus_lock; in stmfx_pinctrl_probe()
685 pctl->irq_chip.irq_bus_sync_unlock = stmfx_pinctrl_irq_bus_sync_unlock; in stmfx_pinctrl_probe()
686 pctl->irq_chip.irq_request_resources = stmfx_gpio_irq_request_resources; in stmfx_pinctrl_probe()
687 pctl->irq_chip.irq_release_resources = stmfx_gpio_irq_release_resources; in stmfx_pinctrl_probe()
689 girq = &pctl->gpio_chip.irq; in stmfx_pinctrl_probe()
690 girq->chip = &pctl->irq_chip; in stmfx_pinctrl_probe()
692 girq->parent_handler = NULL; in stmfx_pinctrl_probe()
693 girq->num_parents = 0; in stmfx_pinctrl_probe()
694 girq->parents = NULL; in stmfx_pinctrl_probe()
695 girq->default_type = IRQ_TYPE_NONE; in stmfx_pinctrl_probe()
696 girq->handler = handle_bad_irq; in stmfx_pinctrl_probe()
697 girq->threaded = true; in stmfx_pinctrl_probe()
699 ret = devm_gpiochip_add_data(pctl->dev, &pctl->gpio_chip, pctl); in stmfx_pinctrl_probe()
701 dev_err(pctl->dev, "gpio_chip registration failed\n"); in stmfx_pinctrl_probe()
709 ret = devm_request_threaded_irq(pctl->dev, irq, NULL, in stmfx_pinctrl_probe()
712 pctl->irq_chip.name, pctl); in stmfx_pinctrl_probe()
714 dev_err(pctl->dev, "cannot request irq%d\n", irq); in stmfx_pinctrl_probe()
718 dev_info(pctl->dev, in stmfx_pinctrl_probe()
719 "%ld GPIOs available\n", hweight_long(pctl->gpio_valid_mask)); in stmfx_pinctrl_probe()
726 struct stmfx *stmfx = dev_get_drvdata(pdev->dev.parent); in stmfx_pinctrl_remove() local
728 return stmfx_function_disable(stmfx, in stmfx_pinctrl_remove()
739 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_STATE, in stmfx_pinctrl_backup_regs()
740 &pctl->bkp_gpio_state, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
743 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_DIR, in stmfx_pinctrl_backup_regs()
744 &pctl->bkp_gpio_dir, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
747 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_TYPE, in stmfx_pinctrl_backup_regs()
748 &pctl->bkp_gpio_type, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
751 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_PUPD, in stmfx_pinctrl_backup_regs()
752 &pctl->bkp_gpio_pupd, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
763 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_DIR, in stmfx_pinctrl_restore_regs()
764 pctl->bkp_gpio_dir, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
767 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_TYPE, in stmfx_pinctrl_restore_regs()
768 pctl->bkp_gpio_type, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
771 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_PUPD, in stmfx_pinctrl_restore_regs()
772 pctl->bkp_gpio_pupd, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
775 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPO_SET, in stmfx_pinctrl_restore_regs()
776 pctl->bkp_gpio_state, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
779 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_EVT, in stmfx_pinctrl_restore_regs()
780 pctl->irq_gpi_evt, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
783 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_TYPE, in stmfx_pinctrl_restore_regs()
784 pctl->irq_gpi_type, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
787 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_restore_regs()
788 pctl->irq_gpi_src, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
802 dev_err(pctl->dev, "registers backup failure\n"); in stmfx_pinctrl_suspend()
816 dev_err(pctl->dev, "registers restoration failure\n"); in stmfx_pinctrl_resume()
828 { .compatible = "st,stmfx-0300-pinctrl", },
835 .name = "stmfx-pinctrl",
844 MODULE_DESCRIPTION("STMFX pinctrl/GPIO driver");