Lines Matching defs:pctl

105 	struct stmfx_pinctrl *pctl = gpiochip_get_data(gc);
111 ret = regmap_read(pctl->stmfx->map, reg, &value);
118 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc);
122 regmap_write_bits(pctl->stmfx->map, reg + get_reg(offset),
128 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc);
134 ret = regmap_read(pctl->stmfx->map, reg, &val);
149 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc);
153 return regmap_write_bits(pctl->stmfx->map, reg, mask, 0);
159 struct stmfx_pinctrl *pctl = gpiochip_get_data(gc);
165 return regmap_write_bits(pctl->stmfx->map, reg, mask, mask);
168 static int stmfx_pinconf_get_pupd(struct stmfx_pinctrl *pctl,
175 ret = regmap_read(pctl->stmfx->map, reg, &pupd);
182 static int stmfx_pinconf_set_pupd(struct stmfx_pinctrl *pctl,
188 return regmap_write_bits(pctl->stmfx->map, reg, mask, pupd ? mask : 0);
191 static int stmfx_pinconf_get_type(struct stmfx_pinctrl *pctl,
198 ret = regmap_read(pctl->stmfx->map, reg, &type);
205 static int stmfx_pinconf_set_type(struct stmfx_pinctrl *pctl,
211 return regmap_write_bits(pctl->stmfx->map, reg, mask, type ? mask : 0);
217 struct stmfx_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
227 dir = stmfx_gpio_get_direction(&pctl->gpio_chip, pin);
237 type = stmfx_pinconf_get_type(pctl, pin);
240 pupd = stmfx_pinconf_get_pupd(pctl, pin);
269 ret = stmfx_gpio_get(&pctl->gpio_chip, pin);
287 struct stmfx_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
307 ret = stmfx_pinconf_set_type(pctl, pin, 0);
312 ret = stmfx_pinconf_set_type(pctl, pin, 1);
315 ret = stmfx_pinconf_set_pupd(pctl, pin, 0);
320 ret = stmfx_pinconf_set_type(pctl, pin, 1);
323 ret = stmfx_pinconf_set_pupd(pctl, pin, 1);
328 ret = stmfx_pinconf_set_type(pctl, pin, 1);
333 ret = stmfx_gpio_direction_output(&pctl->gpio_chip,
349 struct stmfx_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
357 dir = stmfx_gpio_get_direction(&pctl->gpio_chip, offset);
360 type = stmfx_pinconf_get_type(pctl, offset);
363 pupd = stmfx_pinconf_get_pupd(pctl, offset);
366 val = stmfx_gpio_get(&pctl->gpio_chip, offset);
423 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip);
427 pctl->irq_gpi_src[reg] &= ~mask;
433 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip);
437 pctl->irq_gpi_src[reg] |= mask;
443 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip);
451 pctl->irq_gpi_evt[reg] |= mask;
454 pctl->irq_gpi_evt[reg] &= ~mask;
459 pctl->irq_gpi_type[reg] |= mask;
461 pctl->irq_gpi_type[reg] &= ~mask;
471 pctl->irq_toggle_edge[reg] |= mask;
473 pctl->irq_toggle_edge[reg] &= mask;
481 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip);
483 mutex_lock(&pctl->lock);
489 struct stmfx_pinctrl *pctl = gpiochip_get_data(gpio_chip);
498 if (pctl->irq_toggle_edge[reg] & mask) {
500 pctl->irq_gpi_type[reg] &= ~mask;
502 pctl->irq_gpi_type[reg] |= mask;
505 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_EVT,
506 pctl->irq_gpi_evt, NR_GPIO_REGS);
507 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_TYPE,
508 pctl->irq_gpi_type, NR_GPIO_REGS);
509 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC,
510 pctl->irq_gpi_src, NR_GPIO_REGS);
512 mutex_unlock(&pctl->lock);
534 static void stmfx_pinctrl_irq_toggle_trigger(struct stmfx_pinctrl *pctl,
541 if (!(pctl->irq_toggle_edge[reg] & mask))
544 val = stmfx_gpio_get(&pctl->gpio_chip, offset);
549 pctl->irq_gpi_type[reg] &= mask;
550 regmap_write_bits(pctl->stmfx->map,
555 pctl->irq_gpi_type[reg] |= mask;
556 regmap_write_bits(pctl->stmfx->map,
564 struct stmfx_pinctrl *pctl = (struct stmfx_pinctrl *)dev_id;
565 struct gpio_chip *gc = &pctl->gpio_chip;
571 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_IRQ_GPI_PENDING,
576 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC,
584 stmfx_pinctrl_irq_toggle_trigger(pctl, n);
587 regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC,
588 pctl->irq_gpi_src, NR_GPIO_REGS);
593 static int stmfx_pinctrl_gpio_function_enable(struct stmfx_pinctrl *pctl)
596 struct pinctrl_dev *pctl_dev = pctl->pctl_dev;
599 pctl->gpio_valid_mask = GENMASK(15, 0);
604 pctl->gpio_valid_mask |= GENMASK(19, 16);
610 pctl->gpio_valid_mask |= GENMASK(23, 20);
613 return stmfx_function_enable(pctl->stmfx, func);
620 struct stmfx_pinctrl *pctl;
624 pctl = devm_kzalloc(stmfx->dev, sizeof(*pctl), GFP_KERNEL);
625 if (!pctl)
628 platform_set_drvdata(pdev, pctl);
630 pctl->dev = &pdev->dev;
631 pctl->stmfx = stmfx;
634 dev_err(pctl->dev, "missing required gpio-ranges property\n");
642 mutex_init(&pctl->lock);
645 pctl->pctl_desc.name = "stmfx-pinctrl";
646 pctl->pctl_desc.pctlops = &stmfx_pinctrl_ops;
647 pctl->pctl_desc.confops = &stmfx_pinconf_ops;
648 pctl->pctl_desc.pins = stmfx_pins;
649 pctl->pctl_desc.npins = ARRAY_SIZE(stmfx_pins);
650 pctl->pctl_desc.owner = THIS_MODULE;
651 pctl->pctl_desc.link_consumers = true;
653 ret = devm_pinctrl_register_and_init(pctl->dev, &pctl->pctl_desc,
654 pctl, &pctl->pctl_dev);
656 dev_err(pctl->dev, "pinctrl registration failed\n");
660 ret = pinctrl_enable(pctl->pctl_dev);
662 dev_err(pctl->dev, "pinctrl enable failed\n");
667 pctl->gpio_chip.label = "stmfx-gpio";
668 pctl->gpio_chip.parent = pctl->dev;
669 pctl->gpio_chip.get_direction = stmfx_gpio_get_direction;
670 pctl->gpio_chip.direction_input = stmfx_gpio_direction_input;
671 pctl->gpio_chip.direction_output = stmfx_gpio_direction_output;
672 pctl->gpio_chip.get = stmfx_gpio_get;
673 pctl->gpio_chip.set = stmfx_gpio_set;
674 pctl->gpio_chip.set_config = gpiochip_generic_config;
675 pctl->gpio_chip.base = -1;
676 pctl->gpio_chip.ngpio = pctl->pctl_desc.npins;
677 pctl->gpio_chip.can_sleep = true;
678 pctl->gpio_chip.of_node = np;
680 pctl->irq_chip.name = dev_name(pctl->dev);
681 pctl->irq_chip.irq_mask = stmfx_pinctrl_irq_mask;
682 pctl->irq_chip.irq_unmask = stmfx_pinctrl_irq_unmask;
683 pctl->irq_chip.irq_set_type = stmfx_pinctrl_irq_set_type;
684 pctl->irq_chip.irq_bus_lock = stmfx_pinctrl_irq_bus_lock;
685 pctl->irq_chip.irq_bus_sync_unlock = stmfx_pinctrl_irq_bus_sync_unlock;
686 pctl->irq_chip.irq_request_resources = stmfx_gpio_irq_request_resources;
687 pctl->irq_chip.irq_release_resources = stmfx_gpio_irq_release_resources;
689 girq = &pctl->gpio_chip.irq;
690 girq->chip = &pctl->irq_chip;
699 ret = devm_gpiochip_add_data(pctl->dev, &pctl->gpio_chip, pctl);
701 dev_err(pctl->dev, "gpio_chip registration failed\n");
705 ret = stmfx_pinctrl_gpio_function_enable(pctl);
709 ret = devm_request_threaded_irq(pctl->dev, irq, NULL,
712 pctl->irq_chip.name, pctl);
714 dev_err(pctl->dev, "cannot request irq%d\n", irq);
718 dev_info(pctl->dev,
719 "%ld GPIOs available\n", hweight_long(pctl->gpio_valid_mask));
735 static int stmfx_pinctrl_backup_regs(struct stmfx_pinctrl *pctl)
739 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_STATE,
740 &pctl->bkp_gpio_state, NR_GPIO_REGS);
743 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_DIR,
744 &pctl->bkp_gpio_dir, NR_GPIO_REGS);
747 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_TYPE,
748 &pctl->bkp_gpio_type, NR_GPIO_REGS);
751 ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_GPIO_PUPD,
752 &pctl->bkp_gpio_pupd, NR_GPIO_REGS);
759 static int stmfx_pinctrl_restore_regs(struct stmfx_pinctrl *pctl)
763 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_DIR,
764 pctl->bkp_gpio_dir, NR_GPIO_REGS);
767 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_TYPE,
768 pctl->bkp_gpio_type, NR_GPIO_REGS);
771 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPIO_PUPD,
772 pctl->bkp_gpio_pupd, NR_GPIO_REGS);
775 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_GPO_SET,
776 pctl->bkp_gpio_state, NR_GPIO_REGS);
779 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_EVT,
780 pctl->irq_gpi_evt, NR_GPIO_REGS);
783 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_TYPE,
784 pctl->irq_gpi_type, NR_GPIO_REGS);
787 ret = regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC,
788 pctl->irq_gpi_src, NR_GPIO_REGS);
797 struct stmfx_pinctrl *pctl = dev_get_drvdata(dev);
800 ret = stmfx_pinctrl_backup_regs(pctl);
802 dev_err(pctl->dev, "registers backup failure\n");
811 struct stmfx_pinctrl *pctl = dev_get_drvdata(dev);
814 ret = stmfx_pinctrl_restore_regs(pctl);
816 dev_err(pctl->dev, "registers restoration failure\n");