Lines Matching +full:regulator +full:- +full:system +full:- +full:load

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",
29 struct regulation_constraints *constraints = &(*init_data)->constraints; in of_get_regulation_constraints()
37 n_phandles = of_count_phandle_with_args(np, "regulator-coupled-with", in of_get_regulation_constraints()
41 constraints->name = of_get_property(np, "regulator-name", NULL); in of_get_regulation_constraints()
43 if (!of_property_read_u32(np, "regulator-min-microvolt", &pval)) in of_get_regulation_constraints()
44 constraints->min_uV = pval; in of_get_regulation_constraints()
46 if (!of_property_read_u32(np, "regulator-max-microvolt", &pval)) in of_get_regulation_constraints()
47 constraints->max_uV = pval; in of_get_regulation_constraints()
50 if (constraints->min_uV != constraints->max_uV) in of_get_regulation_constraints()
51 constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; in of_get_regulation_constraints()
54 if (constraints->min_uV && constraints->max_uV) in of_get_regulation_constraints()
55 constraints->apply_uV = true; in of_get_regulation_constraints()
57 if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval)) in of_get_regulation_constraints()
58 constraints->uV_offset = pval; in of_get_regulation_constraints()
59 if (!of_property_read_u32(np, "regulator-min-microamp", &pval)) in of_get_regulation_constraints()
60 constraints->min_uA = pval; in of_get_regulation_constraints()
61 if (!of_property_read_u32(np, "regulator-max-microamp", &pval)) in of_get_regulation_constraints()
62 constraints->max_uA = pval; in of_get_regulation_constraints()
64 if (!of_property_read_u32(np, "regulator-input-current-limit-microamp", in of_get_regulation_constraints()
66 constraints->ilim_uA = pval; in of_get_regulation_constraints()
69 if (constraints->min_uA != constraints->max_uA) in of_get_regulation_constraints()
70 constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT; in of_get_regulation_constraints()
72 constraints->boot_on = of_property_read_bool(np, "regulator-boot-on"); in of_get_regulation_constraints()
73 constraints->always_on = of_property_read_bool(np, "regulator-always-on"); in of_get_regulation_constraints()
74 if (!constraints->always_on) /* status change should be possible. */ in of_get_regulation_constraints()
75 constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; in of_get_regulation_constraints()
77 constraints->pull_down = of_property_read_bool(np, "regulator-pull-down"); in of_get_regulation_constraints()
79 if (of_property_read_bool(np, "regulator-allow-bypass")) in of_get_regulation_constraints()
80 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS; in of_get_regulation_constraints()
82 if (of_property_read_bool(np, "regulator-allow-set-load")) in of_get_regulation_constraints()
83 constraints->valid_ops_mask |= REGULATOR_CHANGE_DRMS; in of_get_regulation_constraints()
85 ret = of_property_read_u32(np, "regulator-ramp-delay", &pval); in of_get_regulation_constraints()
88 constraints->ramp_delay = pval; in of_get_regulation_constraints()
90 constraints->ramp_disable = true; in of_get_regulation_constraints()
93 ret = of_property_read_u32(np, "regulator-settling-time-us", &pval); in of_get_regulation_constraints()
95 constraints->settling_time = pval; in of_get_regulation_constraints()
97 ret = of_property_read_u32(np, "regulator-settling-time-up-us", &pval); in of_get_regulation_constraints()
99 constraints->settling_time_up = pval; in of_get_regulation_constraints()
100 if (constraints->settling_time_up && constraints->settling_time) { in of_get_regulation_constraints()
101 …pr_warn("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-up-us… in of_get_regulation_constraints()
103 constraints->settling_time_up = 0; in of_get_regulation_constraints()
106 ret = of_property_read_u32(np, "regulator-settling-time-down-us", in of_get_regulation_constraints()
109 constraints->settling_time_down = pval; in of_get_regulation_constraints()
110 if (constraints->settling_time_down && constraints->settling_time) { in of_get_regulation_constraints()
111 …n("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-down-us'\n", in of_get_regulation_constraints()
113 constraints->settling_time_down = 0; in of_get_regulation_constraints()
116 ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval); in of_get_regulation_constraints()
118 constraints->enable_time = pval; in of_get_regulation_constraints()
120 constraints->soft_start = of_property_read_bool(np, in of_get_regulation_constraints()
121 "regulator-soft-start"); in of_get_regulation_constraints()
122 ret = of_property_read_u32(np, "regulator-active-discharge", &pval); in of_get_regulation_constraints()
124 constraints->active_discharge = in of_get_regulation_constraints()
129 if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) { in of_get_regulation_constraints()
130 if (desc && desc->of_map_mode) { in of_get_regulation_constraints()
131 mode = desc->of_map_mode(pval); in of_get_regulation_constraints()
135 constraints->initial_mode = mode; in of_get_regulation_constraints()
142 len = of_property_count_elems_of_size(np, "regulator-allowed-modes", in of_get_regulation_constraints()
145 if (desc && desc->of_map_mode) { in of_get_regulation_constraints()
148 "regulator-allowed-modes", i, &pval); in of_get_regulation_constraints()
154 mode = desc->of_map_mode(pval); in of_get_regulation_constraints()
156 pr_err("%pOFn: invalid regulator-allowed-modes element %u\n", in of_get_regulation_constraints()
159 constraints->valid_modes_mask |= mode; in of_get_regulation_constraints()
161 if (constraints->valid_modes_mask) in of_get_regulation_constraints()
162 constraints->valid_ops_mask in of_get_regulation_constraints()
169 if (!of_property_read_u32(np, "regulator-system-load", &pval)) in of_get_regulation_constraints()
170 constraints->system_load = pval; in of_get_regulation_constraints()
173 constraints->max_spread = devm_kzalloc(dev, in of_get_regulation_constraints()
174 sizeof(*constraints->max_spread) * n_phandles, in of_get_regulation_constraints()
177 if (!constraints->max_spread) in of_get_regulation_constraints()
178 return -ENOMEM; in of_get_regulation_constraints()
180 of_property_read_u32_array(np, "regulator-coupled-max-spread", in of_get_regulation_constraints()
181 constraints->max_spread, n_phandles); in of_get_regulation_constraints()
184 if (!of_property_read_u32(np, "regulator-max-step-microvolt", in of_get_regulation_constraints()
186 constraints->max_uV_step = pval; in of_get_regulation_constraints()
188 constraints->over_current_protection = of_property_read_bool(np, in of_get_regulation_constraints()
189 "regulator-over-current-protection"); in of_get_regulation_constraints()
194 suspend_state = &constraints->state_mem; in of_get_regulation_constraints()
197 suspend_state = &constraints->state_disk; in of_get_regulation_constraints()
200 suspend_state = &constraints->state_standby; in of_get_regulation_constraints()
212 if (!of_property_read_u32(suspend_np, "regulator-mode", in of_get_regulation_constraints()
214 if (desc && desc->of_map_mode) { in of_get_regulation_constraints()
215 mode = desc->of_map_mode(pval); in of_get_regulation_constraints()
220 suspend_state->mode = mode; in of_get_regulation_constraints()
228 "regulator-on-in-suspend")) in of_get_regulation_constraints()
229 suspend_state->enabled = ENABLE_IN_SUSPEND; in of_get_regulation_constraints()
231 "regulator-off-in-suspend")) in of_get_regulation_constraints()
232 suspend_state->enabled = DISABLE_IN_SUSPEND; in of_get_regulation_constraints()
235 "regulator-suspend-min-microvolt", &pval)) in of_get_regulation_constraints()
236 suspend_state->min_uV = pval; in of_get_regulation_constraints()
239 "regulator-suspend-max-microvolt", &pval)) in of_get_regulation_constraints()
240 suspend_state->max_uV = pval; in of_get_regulation_constraints()
243 "regulator-suspend-microvolt", &pval)) in of_get_regulation_constraints()
244 suspend_state->uV = pval; in of_get_regulation_constraints()
246 suspend_state->uV = suspend_state->min_uV; in of_get_regulation_constraints()
249 "regulator-changeable-in-suspend")) in of_get_regulation_constraints()
250 suspend_state->changeable = true; in of_get_regulation_constraints()
253 constraints->initial_state = PM_SUSPEND_MEM; in of_get_regulation_constraints()
264 * of_get_regulator_init_data - extract regulator_init_data structure info
266 * @node: regulator device node
267 * @desc: regulator description
303 for (i = 0; i < devm_matches->num_matches; i++) in devm_of_regulator_put_matches()
304 of_node_put(devm_matches->matches[i].of_node); in devm_of_regulator_put_matches()
308 * of_regulator_match - extract multiple regulator init data from device tree.
314 * This function uses a match table specified by the regulator driver to
315 * parse regulator init data from the device tree. @node is expected to
317 * regulator. The data parsed from a child node will be matched to a regulator
318 * based on either the deprecated property regulator-compatible if present,
321 * regulator.
336 return -EINVAL; in of_regulator_match()
342 return -ENOMEM; in of_regulator_match()
344 devm_matches->matches = matches; in of_regulator_match()
345 devm_matches->num_matches = num_matches; in of_regulator_match()
351 match->init_data = NULL; in of_regulator_match()
352 match->of_node = NULL; in of_regulator_match()
357 "regulator-compatible", NULL); in of_regulator_match()
359 name = child->name; in of_regulator_match()
362 if (match->of_node) in of_regulator_match()
365 if (strcmp(match->name, name)) in of_regulator_match()
368 match->init_data = in of_regulator_match()
370 match->desc); in of_regulator_match()
371 if (!match->init_data) { in of_regulator_match()
373 "failed to parse DT for regulator %pOFn\n", in of_regulator_match()
376 return -EINVAL; in of_regulator_match()
378 match->of_node = of_node_get(child); in of_regulator_match()
395 if (!dev->of_node || !desc->of_match) in regulator_of_get_init_node()
398 if (desc->regulators_node) { in regulator_of_get_init_node()
399 search = of_get_child_by_name(dev->of_node, in regulator_of_get_init_node()
400 desc->regulators_node); in regulator_of_get_init_node()
402 search = of_node_get(dev->of_node); in regulator_of_get_init_node()
404 if (!strcmp(desc->of_match, search->name)) in regulator_of_get_init_node()
409 dev_dbg(dev, "Failed to find regulator container node '%s'\n", in regulator_of_get_init_node()
410 desc->regulators_node); in regulator_of_get_init_node()
415 name = of_get_property(child, "regulator-compatible", NULL); in regulator_of_get_init_node()
417 name = child->name; in regulator_of_get_init_node()
419 if (!strcmp(desc->of_match, name)) { in regulator_of_get_init_node()
444 dev_err(dev, "failed to parse DT for regulator %pOFn\n", child); in regulator_of_get_init_data()
448 if (desc->of_parse_cb) { in regulator_of_get_init_data()
451 ret = desc->of_parse_cb(child, desc, config); in regulator_of_get_init_data()
453 if (ret == -EPROBE_DEFER) { in regulator_of_get_init_data()
455 return ERR_PTR(-EPROBE_DEFER); in regulator_of_get_init_data()
458 "driver callback failed to parse DT for regulator %pOFn\n", in regulator_of_get_init_data()
488 struct device_node *node = rdev->dev.of_node; in of_get_n_coupled()
492 "regulator-coupled-with", in of_get_n_coupled()
498 /* Looks for "to_find" device_node in src's "regulator-coupled-with" property */
507 "regulator-coupled-with", in of_coupling_find_node()
512 "regulator-coupled-with", i); in of_coupling_find_node()
533 * of_check_coupling_data - Parse rdev's coupling properties and check data
538 * - rdev's max_spread is greater than 0
539 * - all coupled regulators have the same max_spread
540 * - all coupled regulators have the same number of regulator_dev phandles
541 * - all regulators are linked to each other
547 struct device_node *node = rdev->dev.of_node; in of_check_coupling_data()
556 int max_spread = rdev->constraints->max_spread[i]; in of_check_coupling_data()
560 dev_err(&rdev->dev, "max_spread value invalid\n"); in of_check_coupling_data()
565 "regulator-coupled-with", i); in of_check_coupling_data()
571 "regulator-coupled-with", in of_check_coupling_data()
575 dev_err(&rdev->dev, "number of coupled reg phandles mismatch\n"); in of_check_coupling_data()
581 dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n"); in of_check_coupling_data()
586 if (of_property_read_u32_index(c_node, "regulator-coupled-max-spread", in of_check_coupling_data()
593 dev_err(&rdev->dev, in of_check_coupling_data()
609 * of_parse_coupled regulator - Get regulator_dev pointer from rdev's property
611 * "regulator-coupled-with" property
620 struct device_node *node = rdev->dev.of_node; in of_parse_coupled_regulator()
624 c_node = of_parse_phandle(node, "regulator-coupled-with", index); in of_parse_coupled_regulator()