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

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
16 #include <linux/pinctrl/pinconf-generic.h>
20 #include <dt-bindings/pinctrl/qcom,pmic-mpp.h>
23 #include "../pinctrl-utils.h"
28 * Pull Up Values - it indicates whether a pull-up should be
106 * struct pmic_mpp_pad - keep current MPP settings
114 * @num_sources: Number of power-sources supported by this MPP.
115 * @power_source: Current power-source used.
121 * @dtest: DTEST route selector
149 {"qcom,amux-route", PMIC_MPP_CONF_AMUX_ROUTE, 0},
150 {"qcom,analog-level", PMIC_MPP_CONF_ANALOG_LEVEL, 0},
182 ret = regmap_read(state->map, pad->base + addr, &val); in pmic_mpp_read()
184 dev_err(state->dev, "read 0x%x failed\n", addr); in pmic_mpp_read()
197 ret = regmap_write(state->map, pad->base + addr, val); in pmic_mpp_write()
199 dev_err(state->dev, "write 0x%x failed\n", addr); in pmic_mpp_write()
207 return pctldev->desc->npins; in pmic_mpp_get_groups_count()
213 return pctldev->desc->pins[pin].name; in pmic_mpp_get_group_name()
220 *pins = &pctldev->desc->pins[pin].number; in pmic_mpp_get_group_pins()
250 *num_qgroups = pctldev->desc->npins; in pmic_mpp_get_function_groups()
262 switch (pad->function) { in pmic_mpp_write_mode_ctl()
264 if (pad->input_enabled && pad->output_enabled) in pmic_mpp_write_mode_ctl()
266 else if (pad->input_enabled) in pmic_mpp_write_mode_ctl()
272 if (pad->input_enabled && pad->output_enabled) in pmic_mpp_write_mode_ctl()
274 else if (pad->input_enabled) in pmic_mpp_write_mode_ctl()
285 if (pad->dtest) in pmic_mpp_write_mode_ctl()
286 sel = PMIC_MPP_SELECTOR_DTEST_FIRST + pad->dtest - 1; in pmic_mpp_write_mode_ctl()
287 else if (pad->paired) in pmic_mpp_write_mode_ctl()
292 en = !!pad->out_value; in pmic_mpp_write_mode_ctl()
309 pad = pctldev->desc->pins[pin].drv_data; in pmic_mpp_set_mux()
311 pad->function = function; in pmic_mpp_set_mux()
317 val = pad->is_enabled << PMIC_MPP_REG_MASTER_EN_SHIFT; in pmic_mpp_set_mux()
336 pad = pctldev->desc->pins[pin].drv_data; in pmic_mpp_config_get()
340 if (pad->pullup != PMIC_MPP_PULL_UP_OPEN) in pmic_mpp_config_get()
341 return -EINVAL; in pmic_mpp_config_get()
345 switch (pad->pullup) { in pmic_mpp_config_get()
356 return -EINVAL; in pmic_mpp_config_get()
360 if (pad->is_enabled) in pmic_mpp_config_get()
361 return -EINVAL; in pmic_mpp_config_get()
365 arg = pad->power_source; in pmic_mpp_config_get()
368 if (!pad->input_enabled) in pmic_mpp_config_get()
369 return -EINVAL; in pmic_mpp_config_get()
373 arg = pad->out_value; in pmic_mpp_config_get()
376 arg = pad->dtest; in pmic_mpp_config_get()
379 arg = pad->amux_input; in pmic_mpp_config_get()
382 if (!pad->paired) in pmic_mpp_config_get()
383 return -EINVAL; in pmic_mpp_config_get()
387 arg = pad->drive_strength; in pmic_mpp_config_get()
390 arg = pad->aout_level; in pmic_mpp_config_get()
393 return -EINVAL; in pmic_mpp_config_get()
410 pad = pctldev->desc->pins[pin].drv_data; in pmic_mpp_config_set()
413 pad->is_enabled = true; in pmic_mpp_config_set()
421 pad->pullup = PMIC_MPP_PULL_UP_OPEN; in pmic_mpp_config_set()
426 pad->pullup = PMIC_MPP_PULL_UP_0P6KOHM; in pmic_mpp_config_set()
429 pad->pullup = PMIC_MPP_PULL_UP_10KOHM; in pmic_mpp_config_set()
432 pad->pullup = PMIC_MPP_PULL_UP_30KOHM; in pmic_mpp_config_set()
435 return -EINVAL; in pmic_mpp_config_set()
439 pad->is_enabled = false; in pmic_mpp_config_set()
442 if (arg >= pad->num_sources) in pmic_mpp_config_set()
443 return -EINVAL; in pmic_mpp_config_set()
444 pad->power_source = arg; in pmic_mpp_config_set()
447 pad->input_enabled = arg ? true : false; in pmic_mpp_config_set()
450 pad->output_enabled = true; in pmic_mpp_config_set()
451 pad->out_value = arg; in pmic_mpp_config_set()
454 pad->dtest = arg; in pmic_mpp_config_set()
457 pad->drive_strength = arg; in pmic_mpp_config_set()
461 return -EINVAL; in pmic_mpp_config_set()
462 pad->amux_input = arg; in pmic_mpp_config_set()
465 pad->aout_level = arg; in pmic_mpp_config_set()
468 pad->paired = !!arg; in pmic_mpp_config_set()
471 return -EINVAL; in pmic_mpp_config_set()
475 val = pad->power_source << PMIC_MPP_REG_VIN_SHIFT; in pmic_mpp_config_set()
481 if (pad->has_pullup) { in pmic_mpp_config_set()
482 val = pad->pullup << PMIC_MPP_REG_PULL_SHIFT; in pmic_mpp_config_set()
490 val = pad->amux_input & PMIC_MPP_REG_AIN_ROUTE_MASK; in pmic_mpp_config_set()
496 ret = pmic_mpp_write(state, pad, PMIC_MPP_REG_AOUT_CTL, pad->aout_level); in pmic_mpp_config_set()
504 ret = pmic_mpp_write(state, pad, PMIC_MPP_REG_SINK_CTL, pad->drive_strength); in pmic_mpp_config_set()
508 val = pad->is_enabled << PMIC_MPP_REG_MASTER_EN_SHIFT; in pmic_mpp_config_set()
524 pad = pctldev->desc->pins[pin].drv_data; in pmic_mpp_config_dbg_show()
526 seq_printf(s, " mpp%-2d:", pin + PMIC_MPP_PHYSICAL_OFFSET); in pmic_mpp_config_dbg_show()
528 if (!pad->is_enabled) { in pmic_mpp_config_dbg_show()
529 seq_puts(s, " ---"); in pmic_mpp_config_dbg_show()
532 if (pad->input_enabled) { in pmic_mpp_config_dbg_show()
538 pad->out_value = ret; in pmic_mpp_config_dbg_show()
541 seq_printf(s, " %-4s", pad->output_enabled ? "out" : "in"); in pmic_mpp_config_dbg_show()
542 seq_printf(s, " %-7s", pmic_mpp_functions[pad->function]); in pmic_mpp_config_dbg_show()
543 seq_printf(s, " vin-%d", pad->power_source); in pmic_mpp_config_dbg_show()
544 seq_printf(s, " %d", pad->aout_level); in pmic_mpp_config_dbg_show()
545 if (pad->has_pullup) in pmic_mpp_config_dbg_show()
546 seq_printf(s, " %-8s", biases[pad->pullup]); in pmic_mpp_config_dbg_show()
547 seq_printf(s, " %-4s", pad->out_value ? "high" : "low"); in pmic_mpp_config_dbg_show()
548 if (pad->dtest) in pmic_mpp_config_dbg_show()
549 seq_printf(s, " dtest%d", pad->dtest); in pmic_mpp_config_dbg_show()
550 if (pad->paired) in pmic_mpp_config_dbg_show()
569 return pmic_mpp_config_set(state->ctrl, pin, &config, 1); in pmic_mpp_direction_input()
580 return pmic_mpp_config_set(state->ctrl, pin, &config, 1); in pmic_mpp_direction_output()
589 pad = state->ctrl->desc->pins[pin].drv_data; in pmic_mpp_get()
591 if (pad->input_enabled) { in pmic_mpp_get()
596 pad->out_value = ret & PMIC_MPP_REG_RT_STS_VAL_MASK; in pmic_mpp_get()
599 return !!pad->out_value; in pmic_mpp_get()
609 pmic_mpp_config_set(state->ctrl, pin, &config, 1); in pmic_mpp_set()
616 if (chip->of_gpio_n_cells < 2) in pmic_mpp_of_xlate()
617 return -EINVAL; in pmic_mpp_of_xlate()
620 *flags = gpio_desc->args[1]; in pmic_mpp_of_xlate()
622 return gpio_desc->args[0] - PMIC_MPP_PHYSICAL_OFFSET; in pmic_mpp_of_xlate()
630 for (i = 0; i < chip->ngpio; i++) { in pmic_mpp_dbg_show()
631 pmic_mpp_config_dbg_show(state->ctrl, s, i); in pmic_mpp_dbg_show()
658 dev_err(state->dev, "incorrect block type 0x%x at 0x%x\n", in pmic_mpp_populate()
659 type, pad->base); in pmic_mpp_populate()
660 return -ENODEV; in pmic_mpp_populate()
673 pad->num_sources = 4; in pmic_mpp_populate()
676 pad->num_sources = 8; in pmic_mpp_populate()
679 dev_err(state->dev, "unknown MPP type 0x%x at 0x%x\n", in pmic_mpp_populate()
680 subtype, pad->base); in pmic_mpp_populate()
681 return -ENODEV; in pmic_mpp_populate()
688 pad->out_value = val & PMIC_MPP_REG_MODE_VALUE_MASK; in pmic_mpp_populate()
695 pad->input_enabled = true; in pmic_mpp_populate()
696 pad->output_enabled = false; in pmic_mpp_populate()
697 pad->function = PMIC_MPP_DIGITAL; in pmic_mpp_populate()
700 pad->input_enabled = false; in pmic_mpp_populate()
701 pad->output_enabled = true; in pmic_mpp_populate()
702 pad->function = PMIC_MPP_DIGITAL; in pmic_mpp_populate()
705 pad->input_enabled = true; in pmic_mpp_populate()
706 pad->output_enabled = true; in pmic_mpp_populate()
707 pad->function = PMIC_MPP_DIGITAL; in pmic_mpp_populate()
710 pad->input_enabled = true; in pmic_mpp_populate()
711 pad->output_enabled = true; in pmic_mpp_populate()
712 pad->function = PMIC_MPP_ANALOG; in pmic_mpp_populate()
715 pad->input_enabled = true; in pmic_mpp_populate()
716 pad->output_enabled = false; in pmic_mpp_populate()
717 pad->function = PMIC_MPP_ANALOG; in pmic_mpp_populate()
720 pad->input_enabled = false; in pmic_mpp_populate()
721 pad->output_enabled = true; in pmic_mpp_populate()
722 pad->function = PMIC_MPP_ANALOG; in pmic_mpp_populate()
725 pad->input_enabled = false; in pmic_mpp_populate()
726 pad->output_enabled = true; in pmic_mpp_populate()
727 pad->function = PMIC_MPP_SINK; in pmic_mpp_populate()
730 dev_err(state->dev, "unknown MPP direction\n"); in pmic_mpp_populate()
731 return -ENODEV; in pmic_mpp_populate()
738 pad->dtest = sel + 1; in pmic_mpp_populate()
740 pad->paired = true; in pmic_mpp_populate()
746 pad->power_source = val >> PMIC_MPP_REG_VIN_SHIFT; in pmic_mpp_populate()
747 pad->power_source &= PMIC_MPP_REG_VIN_MASK; in pmic_mpp_populate()
755 pad->pullup = val >> PMIC_MPP_REG_PULL_SHIFT; in pmic_mpp_populate()
756 pad->pullup &= PMIC_MPP_REG_PULL_MASK; in pmic_mpp_populate()
757 pad->has_pullup = true; in pmic_mpp_populate()
764 pad->amux_input = val >> PMIC_MPP_REG_AIN_ROUTE_SHIFT; in pmic_mpp_populate()
765 pad->amux_input &= PMIC_MPP_REG_AIN_ROUTE_MASK; in pmic_mpp_populate()
771 pad->drive_strength = val; in pmic_mpp_populate()
777 pad->aout_level = val; in pmic_mpp_populate()
783 pad->is_enabled = !!val; in pmic_mpp_populate()
793 struct pmic_mpp_state *state = container_of(domain->host_data, in pmic_mpp_domain_translate()
797 if (fwspec->param_count != 2 || in pmic_mpp_domain_translate()
798 fwspec->param[0] < 1 || fwspec->param[0] > state->chip.ngpio) in pmic_mpp_domain_translate()
799 return -EINVAL; in pmic_mpp_domain_translate()
801 *hwirq = fwspec->param[0] - PMIC_MPP_PHYSICAL_OFFSET; in pmic_mpp_domain_translate()
802 *type = fwspec->param[1]; in pmic_mpp_domain_translate()
842 .name = "spmi-mpp",
856 struct device *dev = &pdev->dev; in pmic_mpp_probe()
865 ret = of_property_read_u32(dev->of_node, "reg", &reg); in pmic_mpp_probe()
871 npins = (uintptr_t) device_get_match_data(&pdev->dev); in pmic_mpp_probe()
877 return -ENOMEM; in pmic_mpp_probe()
881 state->dev = &pdev->dev; in pmic_mpp_probe()
882 state->map = dev_get_regmap(dev->parent, NULL); in pmic_mpp_probe()
886 return -ENOMEM; in pmic_mpp_probe()
890 return -ENOMEM; in pmic_mpp_probe()
894 return -ENOMEM; in pmic_mpp_probe()
896 pctrldesc->pctlops = &pmic_mpp_pinctrl_ops; in pmic_mpp_probe()
897 pctrldesc->pmxops = &pmic_mpp_pinmux_ops; in pmic_mpp_probe()
898 pctrldesc->confops = &pmic_mpp_pinconf_ops; in pmic_mpp_probe()
899 pctrldesc->owner = THIS_MODULE; in pmic_mpp_probe()
900 pctrldesc->name = dev_name(dev); in pmic_mpp_probe()
901 pctrldesc->pins = pindesc; in pmic_mpp_probe()
902 pctrldesc->npins = npins; in pmic_mpp_probe()
904 pctrldesc->num_custom_params = ARRAY_SIZE(pmic_mpp_bindings); in pmic_mpp_probe()
905 pctrldesc->custom_params = pmic_mpp_bindings; in pmic_mpp_probe()
907 pctrldesc->custom_conf_items = pmic_conf_items; in pmic_mpp_probe()
912 pindesc->drv_data = pad; in pmic_mpp_probe()
913 pindesc->number = i; in pmic_mpp_probe()
914 pindesc->name = pmic_mpp_groups[i]; in pmic_mpp_probe()
916 pad->base = reg + i * PMIC_MPP_ADDRESS_RANGE; in pmic_mpp_probe()
923 state->chip = pmic_mpp_gpio_template; in pmic_mpp_probe()
924 state->chip.parent = dev; in pmic_mpp_probe()
925 state->chip.base = -1; in pmic_mpp_probe()
926 state->chip.ngpio = npins; in pmic_mpp_probe()
927 state->chip.label = dev_name(dev); in pmic_mpp_probe()
928 state->chip.of_gpio_n_cells = 2; in pmic_mpp_probe()
929 state->chip.can_sleep = false; in pmic_mpp_probe()
931 state->ctrl = devm_pinctrl_register(dev, pctrldesc, state); in pmic_mpp_probe()
932 if (IS_ERR(state->ctrl)) in pmic_mpp_probe()
933 return PTR_ERR(state->ctrl); in pmic_mpp_probe()
935 parent_node = of_irq_find_parent(state->dev->of_node); in pmic_mpp_probe()
937 return -ENXIO; in pmic_mpp_probe()
942 return -ENXIO; in pmic_mpp_probe()
944 girq = &state->chip.irq; in pmic_mpp_probe()
946 girq->default_type = IRQ_TYPE_NONE; in pmic_mpp_probe()
947 girq->handler = handle_level_irq; in pmic_mpp_probe()
948 girq->fwnode = dev_fwnode(state->dev); in pmic_mpp_probe()
949 girq->parent_domain = parent_domain; in pmic_mpp_probe()
950 girq->child_to_parent_hwirq = pmic_mpp_child_to_parent_hwirq; in pmic_mpp_probe()
951 girq->populate_parent_alloc_arg = gpiochip_populate_parent_fwspec_fourcell; in pmic_mpp_probe()
952 girq->child_offset_to_irq = pmic_mpp_child_offset_to_irq; in pmic_mpp_probe()
953 girq->child_irq_domain_ops.translate = pmic_mpp_domain_translate; in pmic_mpp_probe()
955 ret = gpiochip_add_data(&state->chip, state); in pmic_mpp_probe()
957 dev_err(state->dev, "can't add gpio chip\n"); in pmic_mpp_probe()
961 ret = gpiochip_add_pin_range(&state->chip, dev_name(dev), 0, 0, npins); in pmic_mpp_probe()
970 gpiochip_remove(&state->chip); in pmic_mpp_probe()
978 gpiochip_remove(&state->chip); in pmic_mpp_remove()
982 { .compatible = "qcom,pm8019-mpp", .data = (void *) 6 },
983 { .compatible = "qcom,pm8226-mpp", .data = (void *) 8 },
984 { .compatible = "qcom,pm8841-mpp", .data = (void *) 4 },
985 { .compatible = "qcom,pm8916-mpp", .data = (void *) 4 },
986 { .compatible = "qcom,pm8937-mpp", .data = (void *) 4 },
987 { .compatible = "qcom,pm8941-mpp", .data = (void *) 8 },
988 { .compatible = "qcom,pm8950-mpp", .data = (void *) 4 },
989 { .compatible = "qcom,pmi8950-mpp", .data = (void *) 4 },
990 { .compatible = "qcom,pm8994-mpp", .data = (void *) 8 },
991 { .compatible = "qcom,pma8084-mpp", .data = (void *) 8 },
992 { .compatible = "qcom,pmi8994-mpp", .data = (void *) 4 },
1000 .name = "qcom-spmi-mpp",
1009 MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
1011 MODULE_ALIAS("platform:qcom-spmi-mpp");