Lines Matching full:pctl
107 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc); in stmfx_gpio_get() local
113 ret = regmap_read(pctl->stmfx->map, reg, &value); in stmfx_gpio_get()
120 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc); in stmfx_gpio_set() local
124 regmap_write_bits(pctl->stmfx->map, reg + get_reg(offset), in stmfx_gpio_set()
130 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc); in stmfx_gpio_get_direction() local
136 ret = regmap_read(pctl->stmfx->map, reg, &val); in stmfx_gpio_get_direction()
151 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc); in stmfx_gpio_direction_input() local
155 return regmap_write_bits(pctl->stmfx->map, reg, mask, 0); in stmfx_gpio_direction_input()
161 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc); in stmfx_gpio_direction_output() local
167 return regmap_write_bits(pctl->stmfx->map, reg, mask, mask); in stmfx_gpio_direction_output()
170 static int stmfx_pinconf_get_pupd(struct stmfx_pinctrl *pctl, in stmfx_pinconf_get_pupd() argument
177 ret = regmap_read(pctl->stmfx->map, reg, &pupd); in stmfx_pinconf_get_pupd()
184 static int stmfx_pinconf_set_pupd(struct stmfx_pinctrl *pctl, in stmfx_pinconf_set_pupd() argument
190 return regmap_write_bits(pctl->stmfx->map, reg, mask, pupd ? mask : 0); in stmfx_pinconf_set_pupd()
193 static int stmfx_pinconf_get_type(struct stmfx_pinctrl *pctl, in stmfx_pinconf_get_type() argument
200 ret = regmap_read(pctl->stmfx->map, reg, &type); in stmfx_pinconf_get_type()
207 static int stmfx_pinconf_set_type(struct stmfx_pinctrl *pctl, in stmfx_pinconf_set_type() argument
213 return regmap_write_bits(pctl->stmfx->map, reg, mask, type ? mask : 0); in stmfx_pinconf_set_type()
219 struct stmfx_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in stmfx_pinconf_get() local
229 dir = stmfx_gpio_get_direction(&pctl->gpio_chip, pin); in stmfx_pinconf_get()
239 type = stmfx_pinconf_get_type(pctl, pin); in stmfx_pinconf_get()
242 pupd = stmfx_pinconf_get_pupd(pctl, pin); in stmfx_pinconf_get()
271 ret = stmfx_gpio_get(&pctl->gpio_chip, pin); in stmfx_pinconf_get()
289 struct stmfx_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in stmfx_pinconf_set() local
309 ret = stmfx_pinconf_set_type(pctl, pin, 0); in stmfx_pinconf_set()
314 ret = stmfx_pinconf_set_type(pctl, pin, 1); in stmfx_pinconf_set()
317 ret = stmfx_pinconf_set_pupd(pctl, pin, 0); in stmfx_pinconf_set()
322 ret = stmfx_pinconf_set_type(pctl, pin, 1); in stmfx_pinconf_set()
325 ret = stmfx_pinconf_set_pupd(pctl, pin, 1); in stmfx_pinconf_set()
330 ret = stmfx_pinconf_set_type(pctl, pin, 1); in stmfx_pinconf_set()
335 ret = stmfx_gpio_direction_output(&pctl->gpio_chip, in stmfx_pinconf_set()
351 struct stmfx_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in stmfx_pinconf_dbg_show() local
359 dir = stmfx_gpio_get_direction(&pctl->gpio_chip, offset); in stmfx_pinconf_dbg_show()
362 type = stmfx_pinconf_get_type(pctl, offset); in stmfx_pinconf_dbg_show()
365 pupd = stmfx_pinconf_get_pupd(pctl, offset); in stmfx_pinconf_dbg_show()
368 val = stmfx_gpio_get(&pctl->gpio_chip, offset); in stmfx_pinconf_dbg_show()
425 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip); in stmfx_pinctrl_irq_mask() local
429 pctl->irq_gpi_src[reg] &= ~mask; in stmfx_pinctrl_irq_mask()
436 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip); in stmfx_pinctrl_irq_unmask() local
441 pctl->irq_gpi_src[reg] |= mask; in stmfx_pinctrl_irq_unmask()
447 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip); in stmfx_pinctrl_irq_set_type() local
455 pctl->irq_gpi_evt[reg] |= mask; in stmfx_pinctrl_irq_set_type()
458 pctl->irq_gpi_evt[reg] &= ~mask; in stmfx_pinctrl_irq_set_type()
463 pctl->irq_gpi_type[reg] |= mask; in stmfx_pinctrl_irq_set_type()
465 pctl->irq_gpi_type[reg] &= ~mask; in stmfx_pinctrl_irq_set_type()
475 pctl->irq_toggle_edge[reg] |= mask; in stmfx_pinctrl_irq_set_type()
477 pctl->irq_toggle_edge[reg] &= mask; in stmfx_pinctrl_irq_set_type()
485 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip); in stmfx_pinctrl_irq_bus_lock() local
487 mutex_lock(&pctl->lock); in stmfx_pinctrl_irq_bus_lock()
493 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip); in stmfx_pinctrl_irq_bus_sync_unlock() local
502 if (pctl->irq_toggle_edge[reg] & mask) { in stmfx_pinctrl_irq_bus_sync_unlock()
504 pctl->irq_gpi_type[reg] &= ~mask; in stmfx_pinctrl_irq_bus_sync_unlock()
506 pctl->irq_gpi_type[reg] |= mask; in stmfx_pinctrl_irq_bus_sync_unlock()
509 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_EVT, in stmfx_pinctrl_irq_bus_sync_unlock()
510 pctl->irq_gpi_evt, NR_GPIO_REGS); in stmfx_pinctrl_irq_bus_sync_unlock()
511 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_TYPE, in stmfx_pinctrl_irq_bus_sync_unlock()
512 pctl->irq_gpi_type, NR_GPIO_REGS); in stmfx_pinctrl_irq_bus_sync_unlock()
513 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_irq_bus_sync_unlock()
514 pctl->irq_gpi_src, NR_GPIO_REGS); in stmfx_pinctrl_irq_bus_sync_unlock()
516 mutex_unlock(&pctl->lock); in stmfx_pinctrl_irq_bus_sync_unlock()
538 static void stmfx_pinctrl_irq_toggle_trigger(struct stmfx_pinctrl *pctl, in stmfx_pinctrl_irq_toggle_trigger() argument
545 if (!(pctl->irq_toggle_edge[reg] & mask)) in stmfx_pinctrl_irq_toggle_trigger()
548 val = stmfx_gpio_get(&pctl->gpio_chip, offset); in stmfx_pinctrl_irq_toggle_trigger()
553 pctl->irq_gpi_type[reg] &= mask; in stmfx_pinctrl_irq_toggle_trigger()
554 regmap_write_bits(pctl->stmfx->map, in stmfx_pinctrl_irq_toggle_trigger()
559 pctl->irq_gpi_type[reg] |= mask; in stmfx_pinctrl_irq_toggle_trigger()
560 regmap_write_bits(pctl->stmfx->map, in stmfx_pinctrl_irq_toggle_trigger()
568 struct stmfx_pinctrl *pctl = (struct stmfx_pinctrl *)dev_id; in stmfx_pinctrl_irq_thread_fn() local
569 struct gpio_chip *gc = &pctl->gpio_chip; in stmfx_pinctrl_irq_thread_fn()
575 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_IRQ_GPI_PENDING, in stmfx_pinctrl_irq_thread_fn()
580 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_irq_thread_fn()
588 stmfx_pinctrl_irq_toggle_trigger(pctl, n); in stmfx_pinctrl_irq_thread_fn()
591 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_irq_thread_fn()
592 pctl->irq_gpi_src, NR_GPIO_REGS); in stmfx_pinctrl_irq_thread_fn()
600 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip); in stmfx_pinctrl_irq_print_chip() local
602 seq_printf(p, dev_name(pctl->dev)); in stmfx_pinctrl_irq_print_chip()
617 static int stmfx_pinctrl_gpio_function_enable(struct stmfx_pinctrl *pctl) in stmfx_pinctrl_gpio_function_enable() argument
620 struct pinctrl_dev *pctl_dev = pctl->pctl_dev; in stmfx_pinctrl_gpio_function_enable()
623 pctl->gpio_valid_mask = GENMASK(15, 0); in stmfx_pinctrl_gpio_function_enable()
628 pctl->gpio_valid_mask |= GENMASK(19, 16); in stmfx_pinctrl_gpio_function_enable()
634 pctl->gpio_valid_mask |= GENMASK(23, 20); in stmfx_pinctrl_gpio_function_enable()
637 return stmfx_function_enable(pctl->stmfx, func); in stmfx_pinctrl_gpio_function_enable()
644 struct stmfx_pinctrl *pctl; in stmfx_pinctrl_probe() local
648 pctl = devm_kzalloc(stmfx->dev, sizeof(*pctl), GFP_KERNEL); in stmfx_pinctrl_probe()
649 if (!pctl) in stmfx_pinctrl_probe()
652 platform_set_drvdata(pdev, pctl); in stmfx_pinctrl_probe()
654 pctl->dev = &pdev->dev; in stmfx_pinctrl_probe()
655 pctl->stmfx = stmfx; in stmfx_pinctrl_probe()
658 dev_err(pctl->dev, "missing required gpio-ranges property\n"); in stmfx_pinctrl_probe()
666 mutex_init(&pctl->lock); in stmfx_pinctrl_probe()
669 pctl->pctl_desc.name = "stmfx-pinctrl"; in stmfx_pinctrl_probe()
670 pctl->pctl_desc.pctlops = &stmfx_pinctrl_ops; in stmfx_pinctrl_probe()
671 pctl->pctl_desc.confops = &stmfx_pinconf_ops; in stmfx_pinctrl_probe()
672 pctl->pctl_desc.pins = stmfx_pins; in stmfx_pinctrl_probe()
673 pctl->pctl_desc.npins = ARRAY_SIZE(stmfx_pins); in stmfx_pinctrl_probe()
674 pctl->pctl_desc.owner = THIS_MODULE; in stmfx_pinctrl_probe()
675 pctl->pctl_desc.link_consumers = true; in stmfx_pinctrl_probe()
677 ret = devm_pinctrl_register_and_init(pctl->dev, &pctl->pctl_desc, in stmfx_pinctrl_probe()
678 pctl, &pctl->pctl_dev); in stmfx_pinctrl_probe()
680 dev_err(pctl->dev, "pinctrl registration failed\n"); in stmfx_pinctrl_probe()
684 ret = pinctrl_enable(pctl->pctl_dev); in stmfx_pinctrl_probe()
686 dev_err(pctl->dev, "pinctrl enable failed\n"); in stmfx_pinctrl_probe()
691 pctl->gpio_chip.label = "stmfx-gpio"; in stmfx_pinctrl_probe()
692 pctl->gpio_chip.parent = pctl->dev; in stmfx_pinctrl_probe()
693 pctl->gpio_chip.get_direction = stmfx_gpio_get_direction; in stmfx_pinctrl_probe()
694 pctl->gpio_chip.direction_input = stmfx_gpio_direction_input; in stmfx_pinctrl_probe()
695 pctl->gpio_chip.direction_output = stmfx_gpio_direction_output; in stmfx_pinctrl_probe()
696 pctl->gpio_chip.get = stmfx_gpio_get; in stmfx_pinctrl_probe()
697 pctl->gpio_chip.set = stmfx_gpio_set; in stmfx_pinctrl_probe()
698 pctl->gpio_chip.set_config = gpiochip_generic_config; in stmfx_pinctrl_probe()
699 pctl->gpio_chip.base = -1; in stmfx_pinctrl_probe()
700 pctl->gpio_chip.ngpio = pctl->pctl_desc.npins; in stmfx_pinctrl_probe()
701 pctl->gpio_chip.can_sleep = true; in stmfx_pinctrl_probe()
703 girq = &pctl->gpio_chip.irq; in stmfx_pinctrl_probe()
713 ret = devm_gpiochip_add_data(pctl->dev, &pctl->gpio_chip, pctl); in stmfx_pinctrl_probe()
715 dev_err(pctl->dev, "gpio_chip registration failed\n"); in stmfx_pinctrl_probe()
719 ret = stmfx_pinctrl_gpio_function_enable(pctl); in stmfx_pinctrl_probe()
723 ret = devm_request_threaded_irq(pctl->dev, irq, NULL, in stmfx_pinctrl_probe()
726 dev_name(pctl->dev), pctl); in stmfx_pinctrl_probe()
728 dev_err(pctl->dev, "cannot request irq%d\n", irq); in stmfx_pinctrl_probe()
732 dev_info(pctl->dev, in stmfx_pinctrl_probe()
733 "%ld GPIOs available\n", hweight_long(pctl->gpio_valid_mask)); in stmfx_pinctrl_probe()
753 static int stmfx_pinctrl_backup_regs(struct stmfx_pinctrl *pctl) in stmfx_pinctrl_backup_regs() argument
757 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_STATE, in stmfx_pinctrl_backup_regs()
758 &pctl->bkp_gpio_state, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
761 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_DIR, in stmfx_pinctrl_backup_regs()
762 &pctl->bkp_gpio_dir, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
765 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_TYPE, in stmfx_pinctrl_backup_regs()
766 &pctl->bkp_gpio_type, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
769 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_PUPD, in stmfx_pinctrl_backup_regs()
770 &pctl->bkp_gpio_pupd, NR_GPIO_REGS); in stmfx_pinctrl_backup_regs()
777 static int stmfx_pinctrl_restore_regs(struct stmfx_pinctrl *pctl) in stmfx_pinctrl_restore_regs() argument
781 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_DIR, in stmfx_pinctrl_restore_regs()
782 pctl->bkp_gpio_dir, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
785 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_TYPE, in stmfx_pinctrl_restore_regs()
786 pctl->bkp_gpio_type, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
789 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_PUPD, in stmfx_pinctrl_restore_regs()
790 pctl->bkp_gpio_pupd, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
793 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPO_SET, in stmfx_pinctrl_restore_regs()
794 pctl->bkp_gpio_state, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
797 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_EVT, in stmfx_pinctrl_restore_regs()
798 pctl->irq_gpi_evt, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
801 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_TYPE, in stmfx_pinctrl_restore_regs()
802 pctl->irq_gpi_type, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
805 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC, in stmfx_pinctrl_restore_regs()
806 pctl->irq_gpi_src, NR_GPIO_REGS); in stmfx_pinctrl_restore_regs()
815 struct stmfx_pinctrl *pctl = dev_get_drvdata(dev); in stmfx_pinctrl_suspend() local
818 ret = stmfx_pinctrl_backup_regs(pctl); in stmfx_pinctrl_suspend()
820 dev_err(pctl->dev, "registers backup failure\n"); in stmfx_pinctrl_suspend()
829 struct stmfx_pinctrl *pctl = dev_get_drvdata(dev); in stmfx_pinctrl_resume() local
832 ret = stmfx_pinctrl_restore_regs(pctl); in stmfx_pinctrl_resume()
834 dev_err(pctl->dev, "registers restoration failure\n"); in stmfx_pinctrl_resume()