Lines Matching +full:amux +full:- +full:route

1 // SPDX-License-Identifier: GPL-2.0-only
18 #include <linux/pinctrl/pinconf-generic.h>
23 #include <dt-bindings/pinctrl/qcom,pmic-mpp.h>
26 #include "../pinctrl-utils.h"
91 * struct pm8xxx_pin_data - dynamic configuration for a pin
100 * @dtest: DTEST route selector
101 * @amux: input muxing in analog mode
119 u8 amux;
136 {"qcom,amux-route", PM8XXX_CONFIG_AMUX, 0},
137 {"qcom,analog-level", PM8XXX_CONFIG_ALEVEL, 0},
176 switch (pin->mode) {
178 if (pin->dtest) {
180 ctrl = pin->dtest - 1;
181 } else if (pin->input && pin->output) {
183 if (pin->high_z)
185 else if (pin->pullup == 600)
187 else if (pin->pullup == 10000)
191 } else if (pin->input) {
193 if (pin->dtest)
194 ctrl = pin->dtest;
199 ctrl = !!pin->output_value;
200 if (pin->paired)
204 level = pin->power_source;
207 if (pin->output) {
209 level = pin->aout_level;
210 ctrl = pin->output_value;
211 if (pin->paired)
215 level = pin->amux;
220 level = (pin->drive_strength / 5) - 1;
221 if (pin->dtest) {
223 ctrl = pin->dtest - 1;
226 ctrl = pin->output_value;
227 if (pin->paired)
232 return -EINVAL;
236 ret = regmap_write(pctrl->regmap, pin->reg, val);
238 dev_err(pctrl->dev, "failed to write register\n");
247 return pctrl->npins;
264 *pins = &pctrl->desc.pins[group].number;
297 *num_groups = pctrl->npins;
306 struct pm8xxx_pin_data *pin = pctrl->desc.pins[group].drv_data;
308 pin->mode = function;
326 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
332 arg = pin->pullup;
335 arg = pin->high_z;
338 arg = pin->input;
341 arg = pin->output_value;
344 arg = pin->power_source;
347 arg = pin->drive_strength;
350 arg = pin->dtest;
353 arg = pin->amux;
356 arg = pin->aout_level;
359 arg = pin->paired;
362 return -EINVAL;
376 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
387 pin->pullup = arg;
390 pin->high_z = true;
393 pin->input = true;
396 pin->output = true;
397 pin->output_value = !!arg;
400 pin->power_source = arg;
403 pin->drive_strength = arg;
406 pin->dtest = arg;
409 pin->amux = arg;
412 pin->aout_level = arg;
415 pin->paired = !!arg;
418 dev_err(pctrl->dev,
421 return -EINVAL;
448 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
450 switch (pin->mode) {
452 pin->input = true;
455 pin->input = true;
456 pin->output = true;
459 return -EINVAL;
472 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
474 switch (pin->mode) {
476 pin->output = true;
479 pin->input = false;
480 pin->output = true;
483 pin->input = false;
484 pin->output = true;
496 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
500 if (!pin->input)
501 return !!pin->output_value;
503 irq = chip->to_irq(chip, offset);
517 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
519 pin->output_value = !!value;
528 if (chip->of_gpio_n_cells < 2)
529 return -EINVAL;
532 *flags = gpio_desc->args[1];
534 return gpio_desc->args[0] - PM8XXX_MPP_PHYSICAL_OFFSET;
547 struct pm8xxx_pin_data *pin = pctrl->desc.pins[offset].drv_data;
559 seq_printf(s, " mpp%-2d:", offset + PM8XXX_MPP_PHYSICAL_OFFSET);
561 switch (pin->mode) {
564 if (pin->dtest) {
565 seq_printf(s, "dtest%d\n", pin->dtest);
566 } else if (pin->input && pin->output) {
567 if (pin->high_z)
568 seq_puts(s, "bi-dir high-z");
570 seq_printf(s, "bi-dir %dOhm", pin->pullup);
571 } else if (pin->input) {
572 if (pin->dtest)
573 seq_printf(s, "in dtest%d", pin->dtest);
576 } else if (pin->output) {
579 if (!pin->paired) {
580 seq_puts(s, str_high_low(pin->output_value));
582 seq_puts(s, pin->output_value ?
589 if (pin->output) {
590 seq_printf(s, "out %s ", aout_lvls[pin->aout_level]);
591 if (!pin->paired) {
592 seq_puts(s, str_high_low(pin->output_value));
594 seq_puts(s, pin->output_value ?
598 seq_printf(s, "input mux %s", amuxs[pin->amux]);
602 seq_printf(s, " sink %dmA ", pin->drive_strength);
603 if (pin->dtest) {
604 seq_printf(s, "dtest%d", pin->dtest);
606 if (!pin->paired) {
607 seq_puts(s, str_high_low(pin->output_value));
609 seq_puts(s, pin->output_value ?
619 unsigned gpio = chip->base;
622 for (i = 0; i < chip->ngpio; i++, gpio++) {
651 ret = regmap_read(pctrl->regmap, pin->reg, &val);
653 dev_err(pctrl->dev, "failed to read register\n");
663 pin->mode = PM8XXX_MPP_DIGITAL;
664 pin->input = true;
665 pin->power_source = level;
666 pin->dtest = ctrl;
669 pin->mode = PM8XXX_MPP_DIGITAL;
670 pin->output = true;
671 pin->power_source = level;
672 pin->output_value = !!(ctrl & BIT(0));
673 pin->paired = !!(ctrl & BIT(1));
676 pin->mode = PM8XXX_MPP_DIGITAL;
677 pin->input = true;
678 pin->output = true;
679 pin->power_source = level;
682 pin->pullup = 600;
685 pin->high_z = true;
688 pin->pullup = 10000;
691 pin->pullup = 30000;
696 pin->mode = PM8XXX_MPP_ANALOG;
697 pin->input = true;
698 pin->amux = level;
701 pin->mode = PM8XXX_MPP_ANALOG;
702 pin->output = true;
703 pin->aout_level = level;
704 pin->output_value = !!(ctrl & BIT(0));
705 pin->paired = !!(ctrl & BIT(1));
708 pin->mode = PM8XXX_MPP_SINK;
709 pin->drive_strength = 5 * (level + 1);
710 pin->output_value = !!(ctrl & BIT(0));
711 pin->paired = !!(ctrl & BIT(1));
714 pin->mode = PM8XXX_MPP_SINK;
715 pin->dtest = ctrl + 1;
716 pin->drive_strength = 5 * (level + 1);
719 pin->mode = PM8XXX_MPP_DIGITAL;
720 pin->power_source = level;
722 pin->dtest = ctrl;
734 struct pm8xxx_mpp *pctrl = container_of(domain->host_data,
737 if (fwspec->param_count != 2 ||
738 fwspec->param[0] < PM8XXX_MPP_PHYSICAL_OFFSET ||
739 fwspec->param[0] > pctrl->chip.ngpio)
740 return -EINVAL;
742 *hwirq = fwspec->param[0] - PM8XXX_MPP_PHYSICAL_OFFSET;
743 *type = fwspec->param[1];
793 .name = "ssbi-mpp",
805 { .compatible = "qcom,pm8018-mpp", .data = (void *) 6 },
806 { .compatible = "qcom,pm8038-mpp", .data = (void *) 6 },
807 { .compatible = "qcom,pm8058-mpp", .data = (void *) 12 },
808 { .compatible = "qcom,pm8821-mpp", .data = (void *) 4 },
809 { .compatible = "qcom,pm8917-mpp", .data = (void *) 10 },
810 { .compatible = "qcom,pm8921-mpp", .data = (void *) 12 },
826 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
828 return -ENOMEM;
830 pctrl->dev = &pdev->dev;
831 pctrl->npins = (uintptr_t) device_get_match_data(&pdev->dev);
833 pctrl->regmap = dev_get_regmap(pdev->dev.parent, NULL);
834 if (!pctrl->regmap) {
835 dev_err(&pdev->dev, "parent regmap unavailable\n");
836 return -ENXIO;
839 pctrl->desc = pm8xxx_pinctrl_desc;
840 pctrl->desc.npins = pctrl->npins;
842 pins = devm_kcalloc(&pdev->dev,
843 pctrl->desc.npins,
847 return -ENOMEM;
849 pin_data = devm_kcalloc(&pdev->dev,
850 pctrl->desc.npins,
854 return -ENOMEM;
856 for (i = 0; i < pctrl->desc.npins; i++) {
867 pctrl->desc.pins = pins;
869 pctrl->desc.num_custom_params = ARRAY_SIZE(pm8xxx_mpp_bindings);
870 pctrl->desc.custom_params = pm8xxx_mpp_bindings;
872 pctrl->desc.custom_conf_items = pm8xxx_conf_items;
875 pctrl->pctrl = devm_pinctrl_register(&pdev->dev, &pctrl->desc, pctrl);
876 if (IS_ERR(pctrl->pctrl)) {
877 dev_err(&pdev->dev, "couldn't register pm8xxx mpp driver\n");
878 return PTR_ERR(pctrl->pctrl);
881 pctrl->chip = pm8xxx_mpp_template;
882 pctrl->chip.base = -1;
883 pctrl->chip.parent = &pdev->dev;
884 pctrl->chip.of_gpio_n_cells = 2;
885 pctrl->chip.label = dev_name(pctrl->dev);
886 pctrl->chip.ngpio = pctrl->npins;
888 parent_node = of_irq_find_parent(pctrl->dev->of_node);
890 return -ENXIO;
895 return -ENXIO;
897 girq = &pctrl->chip.irq;
899 girq->default_type = IRQ_TYPE_NONE;
900 girq->handler = handle_level_irq;
901 girq->fwnode = dev_fwnode(pctrl->dev);
902 girq->parent_domain = parent_domain;
903 if (of_device_is_compatible(pdev->dev.of_node, "qcom,pm8821-mpp"))
904 girq->child_to_parent_hwirq = pm8821_mpp_child_to_parent_hwirq;
906 girq->child_to_parent_hwirq = pm8xxx_mpp_child_to_parent_hwirq;
907 girq->populate_parent_alloc_arg = gpiochip_populate_parent_fwspec_twocell;
908 girq->child_offset_to_irq = pm8xxx_mpp_child_offset_to_irq;
909 girq->child_irq_domain_ops.translate = pm8xxx_mpp_domain_translate;
911 ret = gpiochip_add_data(&pctrl->chip, pctrl);
913 dev_err(&pdev->dev, "failed register gpiochip\n");
917 ret = gpiochip_add_pin_range(&pctrl->chip,
918 dev_name(pctrl->dev),
919 0, 0, pctrl->chip.ngpio);
921 dev_err(pctrl->dev, "failed to add pin range\n");
927 dev_dbg(&pdev->dev, "Qualcomm pm8xxx mpp driver probed\n");
932 gpiochip_remove(&pctrl->chip);
941 gpiochip_remove(&pctrl->chip);
946 .name = "qcom-ssbi-mpp",