Lines Matching +full:pin +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/pinctrl/pinconf-generic.h>
20 #include <dt-bindings/pinctrl/qcom,pmic-mpp.h>
23 #include "../pinctrl-utils.h"
88 * struct pm8xxx_pin_data - dynamic configuration for a pin
90 * @mode: operating mode for the pin (digital, analog or current sink)
91 * @input: pin is input
92 * @output: pin is output
93 * @high_z: pin is floating
134 {"qcom,amux-route", PM8XXX_CONFIG_AMUX, 0},
135 {"qcom,analog-level", PM8XXX_CONFIG_ALEVEL, 0},
166 struct pm8xxx_pin_data *pin) in pm8xxx_mpp_update() argument
174 switch (pin->mode) { in pm8xxx_mpp_update()
176 if (pin->dtest) { in pm8xxx_mpp_update()
178 ctrl = pin->dtest - 1; in pm8xxx_mpp_update()
179 } else if (pin->input && pin->output) { in pm8xxx_mpp_update()
181 if (pin->high_z) in pm8xxx_mpp_update()
183 else if (pin->pullup == 600) in pm8xxx_mpp_update()
185 else if (pin->pullup == 10000) in pm8xxx_mpp_update()
189 } else if (pin->input) { in pm8xxx_mpp_update()
191 if (pin->dtest) in pm8xxx_mpp_update()
192 ctrl = pin->dtest; in pm8xxx_mpp_update()
197 ctrl = !!pin->output_value; in pm8xxx_mpp_update()
198 if (pin->paired) in pm8xxx_mpp_update()
202 level = pin->power_source; in pm8xxx_mpp_update()
205 if (pin->output) { in pm8xxx_mpp_update()
207 level = pin->aout_level; in pm8xxx_mpp_update()
208 ctrl = pin->output_value; in pm8xxx_mpp_update()
209 if (pin->paired) in pm8xxx_mpp_update()
213 level = pin->amux; in pm8xxx_mpp_update()
218 level = (pin->drive_strength / 5) - 1; in pm8xxx_mpp_update()
219 if (pin->dtest) { in pm8xxx_mpp_update()
221 ctrl = pin->dtest - 1; in pm8xxx_mpp_update()
224 ctrl = pin->output_value; in pm8xxx_mpp_update()
225 if (pin->paired) in pm8xxx_mpp_update()
230 return -EINVAL; in pm8xxx_mpp_update()
234 ret = regmap_write(pctrl->regmap, pin->reg, val); in pm8xxx_mpp_update()
236 dev_err(pctrl->dev, "failed to write register\n"); in pm8xxx_mpp_update()
245 return pctrl->npins; in pm8xxx_get_groups_count()
262 *pins = &pctrl->desc.pins[group].number; in pm8xxx_get_group_pins()
295 *num_groups = pctrl->npins; in pm8xxx_get_function_groups()
304 struct pm8xxx_pin_data *pin = pctrl->desc.pins[group].drv_data; in pm8xxx_pinmux_set_mux() local
306 pin->mode = function; in pm8xxx_pinmux_set_mux()
307 pm8xxx_mpp_update(pctrl, pin); in pm8xxx_pinmux_set_mux()
324 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; in pm8xxx_pin_config_get() local
330 arg = pin->pullup; in pm8xxx_pin_config_get()
333 arg = pin->high_z; in pm8xxx_pin_config_get()
336 arg = pin->input; in pm8xxx_pin_config_get()
339 arg = pin->output_value; in pm8xxx_pin_config_get()
342 arg = pin->power_source; in pm8xxx_pin_config_get()
345 arg = pin->drive_strength; in pm8xxx_pin_config_get()
348 arg = pin->dtest; in pm8xxx_pin_config_get()
351 arg = pin->amux; in pm8xxx_pin_config_get()
354 arg = pin->aout_level; in pm8xxx_pin_config_get()
357 arg = pin->paired; in pm8xxx_pin_config_get()
360 return -EINVAL; in pm8xxx_pin_config_get()
374 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; in pm8xxx_pin_config_set() local
385 pin->pullup = arg; in pm8xxx_pin_config_set()
388 pin->high_z = true; in pm8xxx_pin_config_set()
391 pin->input = true; in pm8xxx_pin_config_set()
394 pin->output = true; in pm8xxx_pin_config_set()
395 pin->output_value = !!arg; in pm8xxx_pin_config_set()
398 pin->power_source = arg; in pm8xxx_pin_config_set()
401 pin->drive_strength = arg; in pm8xxx_pin_config_set()
404 pin->dtest = arg; in pm8xxx_pin_config_set()
407 pin->amux = arg; in pm8xxx_pin_config_set()
410 pin->aout_level = arg; in pm8xxx_pin_config_set()
413 pin->paired = !!arg; in pm8xxx_pin_config_set()
416 dev_err(pctrl->dev, in pm8xxx_pin_config_set()
419 return -EINVAL; in pm8xxx_pin_config_set()
423 pm8xxx_mpp_update(pctrl, pin); in pm8xxx_pin_config_set()
446 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; in pm8xxx_mpp_direction_input() local
448 switch (pin->mode) { in pm8xxx_mpp_direction_input()
450 pin->input = true; in pm8xxx_mpp_direction_input()
453 pin->input = true; in pm8xxx_mpp_direction_input()
454 pin->output = true; in pm8xxx_mpp_direction_input()
457 return -EINVAL; in pm8xxx_mpp_direction_input()
460 pm8xxx_mpp_update(pctrl, pin); in pm8xxx_mpp_direction_input()
470 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; in pm8xxx_mpp_direction_output() local
472 switch (pin->mode) { in pm8xxx_mpp_direction_output()
474 pin->output = true; in pm8xxx_mpp_direction_output()
477 pin->input = false; in pm8xxx_mpp_direction_output()
478 pin->output = true; in pm8xxx_mpp_direction_output()
481 pin->input = false; in pm8xxx_mpp_direction_output()
482 pin->output = true; in pm8xxx_mpp_direction_output()
486 pm8xxx_mpp_update(pctrl, pin); in pm8xxx_mpp_direction_output()
494 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; in pm8xxx_mpp_get() local
498 if (!pin->input) in pm8xxx_mpp_get()
499 return !!pin->output_value; in pm8xxx_mpp_get()
501 irq = chip->to_irq(chip, offset); in pm8xxx_mpp_get()
515 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; in pm8xxx_mpp_set() local
517 pin->output_value = !!value; in pm8xxx_mpp_set()
519 pm8xxx_mpp_update(pctrl, pin); in pm8xxx_mpp_set()
526 if (chip->of_gpio_n_cells < 2) in pm8xxx_mpp_of_xlate()
527 return -EINVAL; in pm8xxx_mpp_of_xlate()
530 *flags = gpio_desc->args[1]; in pm8xxx_mpp_of_xlate()
532 return gpio_desc->args[0] - PM8XXX_MPP_PHYSICAL_OFFSET; in pm8xxx_mpp_of_xlate()
546 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data; in pm8xxx_mpp_dbg_show_one() local
558 seq_printf(s, " mpp%-2d:", offset + PM8XXX_MPP_PHYSICAL_OFFSET); in pm8xxx_mpp_dbg_show_one()
560 switch (pin->mode) { in pm8xxx_mpp_dbg_show_one()
563 if (pin->dtest) { in pm8xxx_mpp_dbg_show_one()
564 seq_printf(s, "dtest%d\n", pin->dtest); in pm8xxx_mpp_dbg_show_one()
565 } else if (pin->input && pin->output) { in pm8xxx_mpp_dbg_show_one()
566 if (pin->high_z) in pm8xxx_mpp_dbg_show_one()
567 seq_puts(s, "bi-dir high-z"); in pm8xxx_mpp_dbg_show_one()
569 seq_printf(s, "bi-dir %dOhm", pin->pullup); in pm8xxx_mpp_dbg_show_one()
570 } else if (pin->input) { in pm8xxx_mpp_dbg_show_one()
571 if (pin->dtest) in pm8xxx_mpp_dbg_show_one()
572 seq_printf(s, "in dtest%d", pin->dtest); in pm8xxx_mpp_dbg_show_one()
575 } else if (pin->output) { in pm8xxx_mpp_dbg_show_one()
578 if (!pin->paired) { in pm8xxx_mpp_dbg_show_one()
579 seq_puts(s, pin->output_value ? in pm8xxx_mpp_dbg_show_one()
582 seq_puts(s, pin->output_value ? in pm8xxx_mpp_dbg_show_one()
589 if (pin->output) { in pm8xxx_mpp_dbg_show_one()
590 seq_printf(s, "out %s ", aout_lvls[pin->aout_level]); in pm8xxx_mpp_dbg_show_one()
591 if (!pin->paired) { in pm8xxx_mpp_dbg_show_one()
592 seq_puts(s, pin->output_value ? in pm8xxx_mpp_dbg_show_one()
595 seq_puts(s, pin->output_value ? in pm8xxx_mpp_dbg_show_one()
599 seq_printf(s, "input mux %s", amuxs[pin->amux]); in pm8xxx_mpp_dbg_show_one()
603 seq_printf(s, " sink %dmA ", pin->drive_strength); in pm8xxx_mpp_dbg_show_one()
604 if (pin->dtest) { in pm8xxx_mpp_dbg_show_one()
605 seq_printf(s, "dtest%d", pin->dtest); in pm8xxx_mpp_dbg_show_one()
607 if (!pin->paired) { in pm8xxx_mpp_dbg_show_one()
608 seq_puts(s, pin->output_value ? in pm8xxx_mpp_dbg_show_one()
611 seq_puts(s, pin->output_value ? in pm8xxx_mpp_dbg_show_one()
621 unsigned gpio = chip->base; in pm8xxx_mpp_dbg_show()
624 for (i = 0; i < chip->ngpio; i++, gpio++) { in pm8xxx_mpp_dbg_show()
645 struct pm8xxx_pin_data *pin) in pm8xxx_pin_populate() argument
653 ret = regmap_read(pctrl->regmap, pin->reg, &val); in pm8xxx_pin_populate()
655 dev_err(pctrl->dev, "failed to read register\n"); in pm8xxx_pin_populate()
665 pin->mode = PM8XXX_MPP_DIGITAL; in pm8xxx_pin_populate()
666 pin->input = true; in pm8xxx_pin_populate()
667 pin->power_source = level; in pm8xxx_pin_populate()
668 pin->dtest = ctrl; in pm8xxx_pin_populate()
671 pin->mode = PM8XXX_MPP_DIGITAL; in pm8xxx_pin_populate()
672 pin->output = true; in pm8xxx_pin_populate()
673 pin->power_source = level; in pm8xxx_pin_populate()
674 pin->output_value = !!(ctrl & BIT(0)); in pm8xxx_pin_populate()
675 pin->paired = !!(ctrl & BIT(1)); in pm8xxx_pin_populate()
678 pin->mode = PM8XXX_MPP_DIGITAL; in pm8xxx_pin_populate()
679 pin->input = true; in pm8xxx_pin_populate()
680 pin->output = true; in pm8xxx_pin_populate()
681 pin->power_source = level; in pm8xxx_pin_populate()
684 pin->pullup = 600; in pm8xxx_pin_populate()
687 pin->high_z = true; in pm8xxx_pin_populate()
690 pin->pullup = 10000; in pm8xxx_pin_populate()
693 pin->pullup = 30000; in pm8xxx_pin_populate()
698 pin->mode = PM8XXX_MPP_ANALOG; in pm8xxx_pin_populate()
699 pin->input = true; in pm8xxx_pin_populate()
700 pin->amux = level; in pm8xxx_pin_populate()
703 pin->mode = PM8XXX_MPP_ANALOG; in pm8xxx_pin_populate()
704 pin->output = true; in pm8xxx_pin_populate()
705 pin->aout_level = level; in pm8xxx_pin_populate()
706 pin->output_value = !!(ctrl & BIT(0)); in pm8xxx_pin_populate()
707 pin->paired = !!(ctrl & BIT(1)); in pm8xxx_pin_populate()
710 pin->mode = PM8XXX_MPP_SINK; in pm8xxx_pin_populate()
711 pin->drive_strength = 5 * (level + 1); in pm8xxx_pin_populate()
712 pin->output_value = !!(ctrl & BIT(0)); in pm8xxx_pin_populate()
713 pin->paired = !!(ctrl & BIT(1)); in pm8xxx_pin_populate()
716 pin->mode = PM8XXX_MPP_SINK; in pm8xxx_pin_populate()
717 pin->dtest = ctrl + 1; in pm8xxx_pin_populate()
718 pin->drive_strength = 5 * (level + 1); in pm8xxx_pin_populate()
721 pin->mode = PM8XXX_MPP_DIGITAL; in pm8xxx_pin_populate()
722 pin->power_source = level; in pm8xxx_pin_populate()
724 pin->dtest = ctrl; in pm8xxx_pin_populate()
736 struct pm8xxx_mpp *pctrl = container_of(domain->host_data, in pm8xxx_mpp_domain_translate()
739 if (fwspec->param_count != 2 || in pm8xxx_mpp_domain_translate()
740 fwspec->param[0] < PM8XXX_MPP_PHYSICAL_OFFSET || in pm8xxx_mpp_domain_translate()
741 fwspec->param[0] > pctrl->chip.ngpio) in pm8xxx_mpp_domain_translate()
742 return -EINVAL; in pm8xxx_mpp_domain_translate()
744 *hwirq = fwspec->param[0] - PM8XXX_MPP_PHYSICAL_OFFSET; in pm8xxx_mpp_domain_translate()
745 *type = fwspec->param[1]; in pm8xxx_mpp_domain_translate()
781 { .compatible = "qcom,pm8018-mpp", .data = (void *) 6 },
782 { .compatible = "qcom,pm8038-mpp", .data = (void *) 6 },
783 { .compatible = "qcom,pm8058-mpp", .data = (void *) 12 },
784 { .compatible = "qcom,pm8821-mpp", .data = (void *) 4 },
785 { .compatible = "qcom,pm8917-mpp", .data = (void *) 10 },
786 { .compatible = "qcom,pm8921-mpp", .data = (void *) 12 },
802 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); in pm8xxx_mpp_probe()
804 return -ENOMEM; in pm8xxx_mpp_probe()
806 pctrl->dev = &pdev->dev; in pm8xxx_mpp_probe()
807 pctrl->npins = (uintptr_t) device_get_match_data(&pdev->dev); in pm8xxx_mpp_probe()
809 pctrl->regmap = dev_get_regmap(pdev->dev.parent, NULL); in pm8xxx_mpp_probe()
810 if (!pctrl->regmap) { in pm8xxx_mpp_probe()
811 dev_err(&pdev->dev, "parent regmap unavailable\n"); in pm8xxx_mpp_probe()
812 return -ENXIO; in pm8xxx_mpp_probe()
815 pctrl->desc = pm8xxx_pinctrl_desc; in pm8xxx_mpp_probe()
816 pctrl->desc.npins = pctrl->npins; in pm8xxx_mpp_probe()
818 pins = devm_kcalloc(&pdev->dev, in pm8xxx_mpp_probe()
819 pctrl->desc.npins, in pm8xxx_mpp_probe()
823 return -ENOMEM; in pm8xxx_mpp_probe()
825 pin_data = devm_kcalloc(&pdev->dev, in pm8xxx_mpp_probe()
826 pctrl->desc.npins, in pm8xxx_mpp_probe()
830 return -ENOMEM; in pm8xxx_mpp_probe()
832 for (i = 0; i < pctrl->desc.npins; i++) { in pm8xxx_mpp_probe()
843 pctrl->desc.pins = pins; in pm8xxx_mpp_probe()
845 pctrl->desc.num_custom_params = ARRAY_SIZE(pm8xxx_mpp_bindings); in pm8xxx_mpp_probe()
846 pctrl->desc.custom_params = pm8xxx_mpp_bindings; in pm8xxx_mpp_probe()
848 pctrl->desc.custom_conf_items = pm8xxx_conf_items; in pm8xxx_mpp_probe()
851 pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &pctrl->desc, pctrl); in pm8xxx_mpp_probe()
852 if (IS_ERR(pctrl->pctrl)) { in pm8xxx_mpp_probe()
853 dev_err(&pdev->dev, "couldn't register pm8xxx mpp driver\n"); in pm8xxx_mpp_probe()
854 return PTR_ERR(pctrl->pctrl); in pm8xxx_mpp_probe()
857 pctrl->chip = pm8xxx_mpp_template; in pm8xxx_mpp_probe()
858 pctrl->chip.base = -1; in pm8xxx_mpp_probe()
859 pctrl->chip.parent = &pdev->dev; in pm8xxx_mpp_probe()
860 pctrl->chip.of_gpio_n_cells = 2; in pm8xxx_mpp_probe()
861 pctrl->chip.label = dev_name(pctrl->dev); in pm8xxx_mpp_probe()
862 pctrl->chip.ngpio = pctrl->npins; in pm8xxx_mpp_probe()
864 parent_node = of_irq_find_parent(pctrl->dev->of_node); in pm8xxx_mpp_probe()
866 return -ENXIO; in pm8xxx_mpp_probe()
871 return -ENXIO; in pm8xxx_mpp_probe()
873 pctrl->irq.name = "ssbi-mpp"; in pm8xxx_mpp_probe()
874 pctrl->irq.irq_mask_ack = irq_chip_mask_ack_parent; in pm8xxx_mpp_probe()
875 pctrl->irq.irq_unmask = irq_chip_unmask_parent; in pm8xxx_mpp_probe()
876 pctrl->irq.irq_set_type = irq_chip_set_type_parent; in pm8xxx_mpp_probe()
877 pctrl->irq.flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_SKIP_SET_WAKE; in pm8xxx_mpp_probe()
879 girq = &pctrl->chip.irq; in pm8xxx_mpp_probe()
880 girq->chip = &pctrl->irq; in pm8xxx_mpp_probe()
881 girq->default_type = IRQ_TYPE_NONE; in pm8xxx_mpp_probe()
882 girq->handler = handle_level_irq; in pm8xxx_mpp_probe()
883 girq->fwnode = of_node_to_fwnode(pctrl->dev->of_node); in pm8xxx_mpp_probe()
884 girq->parent_domain = parent_domain; in pm8xxx_mpp_probe()
885 if (of_device_is_compatible(pdev->dev.of_node, "qcom,pm8821-mpp")) in pm8xxx_mpp_probe()
886 girq->child_to_parent_hwirq = pm8821_mpp_child_to_parent_hwirq; in pm8xxx_mpp_probe()
888 girq->child_to_parent_hwirq = pm8xxx_mpp_child_to_parent_hwirq; in pm8xxx_mpp_probe()
889 girq->populate_parent_alloc_arg = gpiochip_populate_parent_fwspec_twocell; in pm8xxx_mpp_probe()
890 girq->child_offset_to_irq = pm8xxx_mpp_child_offset_to_irq; in pm8xxx_mpp_probe()
891 girq->child_irq_domain_ops.translate = pm8xxx_mpp_domain_translate; in pm8xxx_mpp_probe()
893 ret = gpiochip_add_data(&pctrl->chip, pctrl); in pm8xxx_mpp_probe()
895 dev_err(&pdev->dev, "failed register gpiochip\n"); in pm8xxx_mpp_probe()
899 ret = gpiochip_add_pin_range(&pctrl->chip, in pm8xxx_mpp_probe()
900 dev_name(pctrl->dev), in pm8xxx_mpp_probe()
901 0, 0, pctrl->chip.ngpio); in pm8xxx_mpp_probe()
903 dev_err(pctrl->dev, "failed to add pin range\n"); in pm8xxx_mpp_probe()
909 dev_dbg(&pdev->dev, "Qualcomm pm8xxx mpp driver probed\n"); in pm8xxx_mpp_probe()
914 gpiochip_remove(&pctrl->chip); in pm8xxx_mpp_probe()
923 gpiochip_remove(&pctrl->chip); in pm8xxx_mpp_remove()
930 .name = "qcom-ssbi-mpp",