Lines Matching +full:regulator +full:- +full:coupled +full:- +full:with

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * OF helpers for regulator framework
12 #include <linux/regulator/machine.h>
13 #include <linux/regulator/driver.h>
14 #include <linux/regulator/of_regulator.h>
19 [PM_SUSPEND_STANDBY] = "regulator-state-standby",
20 [PM_SUSPEND_MEM] = "regulator-state-mem",
21 [PM_SUSPEND_MAX] = "regulator-state-disk",
41 "regulator-oc-%s-microamp", in of_get_regulator_prot_limits()
42 "regulator-ov-%s-microvolt", in of_get_regulator_prot_limits()
43 "regulator-temp-%s-kelvin", in of_get_regulator_prot_limits()
44 "regulator-uv-%s-microvolt", in of_get_regulator_prot_limits()
47 &constraints->over_curr_limits, in of_get_regulator_prot_limits()
48 &constraints->over_voltage_limits, in of_get_regulator_prot_limits()
49 &constraints->temp_limits, in of_get_regulator_prot_limits()
50 &constraints->under_voltage_limits, in of_get_regulator_prot_limits()
63 &limits[i]->prot, &limits[i]->err, &limits[i]->warn, in of_get_regulator_prot_limits()
74 constraints->over_current_detection = set[0]; in of_get_regulator_prot_limits()
75 constraints->over_voltage_detection = set[1]; in of_get_regulator_prot_limits()
76 constraints->over_temp_detection = set[2]; in of_get_regulator_prot_limits()
77 constraints->under_voltage_detection = set[3]; in of_get_regulator_prot_limits()
85 struct regulation_constraints *constraints = &(*init_data)->constraints; in of_get_regulation_constraints()
93 n_phandles = of_count_phandle_with_args(np, "regulator-coupled-with", in of_get_regulation_constraints()
97 constraints->name = of_get_property(np, "regulator-name", NULL); in of_get_regulation_constraints()
99 if (!of_property_read_u32(np, "regulator-min-microvolt", &pval)) in of_get_regulation_constraints()
100 constraints->min_uV = pval; in of_get_regulation_constraints()
102 if (!of_property_read_u32(np, "regulator-max-microvolt", &pval)) in of_get_regulation_constraints()
103 constraints->max_uV = pval; in of_get_regulation_constraints()
106 if (constraints->min_uV != constraints->max_uV) in of_get_regulation_constraints()
107 constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; in of_get_regulation_constraints()
110 if (constraints->min_uV && constraints->max_uV) in of_get_regulation_constraints()
111 constraints->apply_uV = true; in of_get_regulation_constraints()
113 if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval)) in of_get_regulation_constraints()
114 constraints->uV_offset = pval; in of_get_regulation_constraints()
115 if (!of_property_read_u32(np, "regulator-min-microamp", &pval)) in of_get_regulation_constraints()
116 constraints->min_uA = pval; in of_get_regulation_constraints()
117 if (!of_property_read_u32(np, "regulator-max-microamp", &pval)) in of_get_regulation_constraints()
118 constraints->max_uA = pval; in of_get_regulation_constraints()
120 if (!of_property_read_u32(np, "regulator-input-current-limit-microamp", in of_get_regulation_constraints()
122 constraints->ilim_uA = pval; in of_get_regulation_constraints()
125 if (constraints->min_uA != constraints->max_uA) in of_get_regulation_constraints()
126 constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT; in of_get_regulation_constraints()
128 constraints->boot_on = of_property_read_bool(np, "regulator-boot-on"); in of_get_regulation_constraints()
129 constraints->always_on = of_property_read_bool(np, "regulator-always-on"); in of_get_regulation_constraints()
130 if (!constraints->always_on) /* status change should be possible. */ in of_get_regulation_constraints()
131 constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; in of_get_regulation_constraints()
133 constraints->pull_down = of_property_read_bool(np, "regulator-pull-down"); in of_get_regulation_constraints()
134 constraints->system_critical = of_property_read_bool(np, in of_get_regulation_constraints()
135 "system-critical-regulator"); in of_get_regulation_constraints()
137 if (of_property_read_bool(np, "regulator-allow-bypass")) in of_get_regulation_constraints()
138 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS; in of_get_regulation_constraints()
140 if (of_property_read_bool(np, "regulator-allow-set-load")) in of_get_regulation_constraints()
141 constraints->valid_ops_mask |= REGULATOR_CHANGE_DRMS; in of_get_regulation_constraints()
143 ret = of_property_read_u32(np, "regulator-ramp-delay", &pval); in of_get_regulation_constraints()
146 constraints->ramp_delay = pval; in of_get_regulation_constraints()
148 constraints->ramp_disable = true; in of_get_regulation_constraints()
151 ret = of_property_read_u32(np, "regulator-settling-time-us", &pval); in of_get_regulation_constraints()
153 constraints->settling_time = pval; in of_get_regulation_constraints()
155 ret = of_property_read_u32(np, "regulator-settling-time-up-us", &pval); in of_get_regulation_constraints()
157 constraints->settling_time_up = pval; in of_get_regulation_constraints()
158 if (constraints->settling_time_up && constraints->settling_time) { in of_get_regulation_constraints()
159 …pr_warn("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-up-us… in of_get_regulation_constraints()
161 constraints->settling_time_up = 0; in of_get_regulation_constraints()
164 ret = of_property_read_u32(np, "regulator-settling-time-down-us", in of_get_regulation_constraints()
167 constraints->settling_time_down = pval; in of_get_regulation_constraints()
168 if (constraints->settling_time_down && constraints->settling_time) { in of_get_regulation_constraints()
169 …n("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-down-us'\n", in of_get_regulation_constraints()
171 constraints->settling_time_down = 0; in of_get_regulation_constraints()
174 ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval); in of_get_regulation_constraints()
176 constraints->enable_time = pval; in of_get_regulation_constraints()
178 ret = of_property_read_u32(np, "regulator-uv-survival-time-ms", &pval); in of_get_regulation_constraints()
180 constraints->uv_less_critical_window_ms = pval; in of_get_regulation_constraints()
182 constraints->uv_less_critical_window_ms = in of_get_regulation_constraints()
185 constraints->soft_start = of_property_read_bool(np, in of_get_regulation_constraints()
186 "regulator-soft-start"); in of_get_regulation_constraints()
187 ret = of_property_read_u32(np, "regulator-active-discharge", &pval); in of_get_regulation_constraints()
189 constraints->active_discharge = in of_get_regulation_constraints()
194 if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) { in of_get_regulation_constraints()
195 if (desc && desc->of_map_mode) { in of_get_regulation_constraints()
196 mode = desc->of_map_mode(pval); in of_get_regulation_constraints()
200 constraints->initial_mode = mode; in of_get_regulation_constraints()
207 len = of_property_count_elems_of_size(np, "regulator-allowed-modes", in of_get_regulation_constraints()
210 if (desc && desc->of_map_mode) { in of_get_regulation_constraints()
213 "regulator-allowed-modes", i, &pval); in of_get_regulation_constraints()
219 mode = desc->of_map_mode(pval); in of_get_regulation_constraints()
221 pr_err("%pOFn: invalid regulator-allowed-modes element %u\n", in of_get_regulation_constraints()
224 constraints->valid_modes_mask |= mode; in of_get_regulation_constraints()
226 if (constraints->valid_modes_mask) in of_get_regulation_constraints()
227 constraints->valid_ops_mask in of_get_regulation_constraints()
234 if (!of_property_read_u32(np, "regulator-system-load", &pval)) in of_get_regulation_constraints()
235 constraints->system_load = pval; in of_get_regulation_constraints()
238 constraints->max_spread = devm_kzalloc(dev, in of_get_regulation_constraints()
239 sizeof(*constraints->max_spread) * n_phandles, in of_get_regulation_constraints()
242 if (!constraints->max_spread) in of_get_regulation_constraints()
243 return -ENOMEM; in of_get_regulation_constraints()
245 of_property_read_u32_array(np, "regulator-coupled-max-spread", in of_get_regulation_constraints()
246 constraints->max_spread, n_phandles); in of_get_regulation_constraints()
249 if (!of_property_read_u32(np, "regulator-max-step-microvolt", in of_get_regulation_constraints()
251 constraints->max_uV_step = pval; in of_get_regulation_constraints()
253 constraints->over_current_protection = of_property_read_bool(np, in of_get_regulation_constraints()
254 "regulator-over-current-protection"); in of_get_regulation_constraints()
261 suspend_state = &constraints->state_mem; in of_get_regulation_constraints()
264 suspend_state = &constraints->state_disk; in of_get_regulation_constraints()
267 suspend_state = &constraints->state_standby; in of_get_regulation_constraints()
283 if (!of_property_read_u32(suspend_np, "regulator-mode", in of_get_regulation_constraints()
285 if (desc && desc->of_map_mode) { in of_get_regulation_constraints()
286 mode = desc->of_map_mode(pval); in of_get_regulation_constraints()
291 suspend_state->mode = mode; in of_get_regulation_constraints()
299 "regulator-on-in-suspend")) in of_get_regulation_constraints()
300 suspend_state->enabled = ENABLE_IN_SUSPEND; in of_get_regulation_constraints()
302 "regulator-off-in-suspend")) in of_get_regulation_constraints()
303 suspend_state->enabled = DISABLE_IN_SUSPEND; in of_get_regulation_constraints()
306 "regulator-suspend-min-microvolt", &pval)) in of_get_regulation_constraints()
307 suspend_state->min_uV = pval; in of_get_regulation_constraints()
310 "regulator-suspend-max-microvolt", &pval)) in of_get_regulation_constraints()
311 suspend_state->max_uV = pval; in of_get_regulation_constraints()
314 "regulator-suspend-microvolt", &pval)) in of_get_regulation_constraints()
315 suspend_state->uV = pval; in of_get_regulation_constraints()
317 suspend_state->uV = suspend_state->min_uV; in of_get_regulation_constraints()
320 "regulator-changeable-in-suspend")) in of_get_regulation_constraints()
321 suspend_state->changeable = true; in of_get_regulation_constraints()
324 constraints->initial_state = PM_SUSPEND_MEM; in of_get_regulation_constraints()
335 * of_get_regulator_init_data - extract regulator_init_data structure info
337 * @node: regulator device node
338 * @desc: regulator description
376 for (i = 0; i < devm_matches->num_matches; i++) in devm_of_regulator_put_matches()
377 of_node_put(devm_matches->matches[i].of_node); in devm_of_regulator_put_matches()
381 * of_regulator_match - extract multiple regulator init data from device tree.
387 * This function uses a match table specified by the regulator driver to
388 * parse regulator init data from the device tree. @node is expected to
390 * regulator. The data parsed from a child node will be matched to a regulator
391 * based on either the deprecated property regulator-compatible if present,
394 * regulator.
409 return -EINVAL; in of_regulator_match()
415 return -ENOMEM; in of_regulator_match()
417 devm_matches->matches = matches; in of_regulator_match()
418 devm_matches->num_matches = num_matches; in of_regulator_match()
424 match->init_data = NULL; in of_regulator_match()
425 match->of_node = NULL; in of_regulator_match()
430 "regulator-compatible", NULL); in of_regulator_match()
432 name = child->name; in of_regulator_match()
435 if (match->of_node) in of_regulator_match()
438 if (strcmp(match->name, name)) in of_regulator_match()
441 match->init_data = in of_regulator_match()
443 match->desc); in of_regulator_match()
444 if (!match->init_data) { in of_regulator_match()
446 "failed to parse DT for regulator %pOFn\n", in of_regulator_match()
449 return -EINVAL; in of_regulator_match()
451 match->of_node = of_node_get(child); in of_regulator_match()
468 if (!dev->of_node || !desc->of_match) in regulator_of_get_init_node()
471 if (desc->regulators_node) { in regulator_of_get_init_node()
472 search = of_get_child_by_name(dev->of_node, in regulator_of_get_init_node()
473 desc->regulators_node); in regulator_of_get_init_node()
475 search = of_node_get(dev->of_node); in regulator_of_get_init_node()
477 if (!strcmp(desc->of_match, search->name)) in regulator_of_get_init_node()
482 dev_dbg(dev, "Failed to find regulator container node '%s'\n", in regulator_of_get_init_node()
483 desc->regulators_node); in regulator_of_get_init_node()
488 name = of_get_property(child, "regulator-compatible", NULL); in regulator_of_get_init_node()
490 if (!desc->of_match_full_name) in regulator_of_get_init_node()
491 name = child->name; in regulator_of_get_init_node()
493 name = child->full_name; in regulator_of_get_init_node()
496 if (!strcmp(desc->of_match, name)) { in regulator_of_get_init_node()
519 child = regulator_of_get_init_node(config->dev, desc); in regulator_of_get_init_data()
525 dev_err(dev, "failed to parse DT for regulator %pOFn\n", child); in regulator_of_get_init_data()
529 if (desc->of_parse_cb) { in regulator_of_get_init_data()
532 ret = desc->of_parse_cb(child, desc, config); in regulator_of_get_init_data()
534 if (ret == -EPROBE_DEFER) { in regulator_of_get_init_data()
536 return ERR_PTR(-EPROBE_DEFER); in regulator_of_get_init_data()
539 "driver callback failed to parse DT for regulator %pOFn\n", in regulator_of_get_init_data()
556 * of_get_child_regulator - get a child regulator device node
559 * @prop_name: Combination regulator supply name and "-supply"
562 * Extract the child regulator device node corresponding to the supply name.
564 * Return: Pointer to the &struct device_node corresponding to the regulator
590 * of_get_regulator - get a regulator device node based on supply name
591 * @dev: Device pointer for the consumer (of regulator) device
592 * @supply: regulator supply name
594 * Extract the regulator device node corresponding to the supply name.
596 * Return: Pointer to the &struct device_node corresponding to the regulator
604 dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); in of_get_regulator()
606 snprintf(prop_name, 64, "%s-supply", supply); in of_get_regulator()
607 regnode = of_parse_phandle(dev->of_node, prop_name, 0); in of_get_regulator()
611 regnode = of_get_child_regulator(dev->of_node, prop_name); in of_get_regulator()
615 dev_dbg(dev, "Looking up %s property in node %pOF failed\n", prop_name, dev->of_node); in of_get_regulator()
629 * of_regulator_dev_lookup - lookup a regulator device with device tree only
630 * @dev: Device pointer for regulator supply lookup.
631 * @supply: Supply name or regulator ID.
637 * corresponds to the name @supply and with the embedded &struct device
642 * * -%ENODEV if lookup fails permanently.
643 * * -%EPROBE_DEFER if lookup could succeed in the future.
662 return ERR_PTR(-EPROBE_DEFER); in of_regulator_dev_lookup()
665 return ERR_PTR(-ENODEV); in of_regulator_dev_lookup()
669 * Returns number of regulators coupled with rdev.
673 struct device_node *node = rdev->dev.of_node; in of_get_n_coupled()
677 "regulator-coupled-with", in of_get_n_coupled()
683 /* Looks for "to_find" device_node in src's "regulator-coupled-with" property */
692 "regulator-coupled-with", in of_coupling_find_node()
697 "regulator-coupled-with", i); in of_coupling_find_node()
718 * of_check_coupling_data - Parse rdev's coupling properties and check data
723 * - rdev's max_spread is greater than 0
724 * - all coupled regulators have the same max_spread
725 * - all coupled regulators have the same number of regulator_dev phandles
726 * - all regulators are linked to each other
732 struct device_node *node = rdev->dev.of_node; in of_check_coupling_data()
741 int max_spread = rdev->constraints->max_spread[i]; in of_check_coupling_data()
745 dev_err(&rdev->dev, "max_spread value invalid\n"); in of_check_coupling_data()
750 "regulator-coupled-with", i); in of_check_coupling_data()
756 "regulator-coupled-with", in of_check_coupling_data()
760 dev_err(&rdev->dev, "number of coupled reg phandles mismatch\n"); in of_check_coupling_data()
766 dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n"); in of_check_coupling_data()
771 if (of_property_read_u32_index(c_node, "regulator-coupled-max-spread", in of_check_coupling_data()
778 dev_err(&rdev->dev, in of_check_coupling_data()
779 "coupled regulators max_spread mismatch\n"); in of_check_coupling_data()
794 * of_parse_coupled_regulator() - Get regulator_dev pointer from rdev's property
796 * "regulator-coupled-with" property
805 struct device_node *node = rdev->dev.of_node; in of_parse_coupled_regulator()
809 c_node = of_parse_phandle(node, "regulator-coupled-with", index); in of_parse_coupled_regulator()
821 * Check if name is a supply name according to the '*-supply' pattern
823 * return length of supply name without the -supply
830 /* string need to be at minimum len(x-supply) */ in is_supply_name()
833 for (i = strs - 6; i > 0; i--) { in is_supply_name()
834 /* find first '-' and check if right part is supply */ in is_supply_name()
835 if (name[i] != '-') in is_supply_name()
845 * of_regulator_bulk_get_all - get multiple regulator consumers
851 * This helper function allows drivers to get several regulator
864 struct regulator *tmp; in of_regulator_bulk_get_all()
871 * first pass: get numbers of xxx-supply in of_regulator_bulk_get_all()
876 i = is_supply_name(prop->name); in of_regulator_bulk_get_all()
883 memcpy(name, prop->name, i); in of_regulator_bulk_get_all()
905 return -ENOMEM; in of_regulator_bulk_get_all()
909 while (--n >= 0) in of_regulator_bulk_get_all()