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

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",
42 "regulator-ov-%s-microvolt",
43 "regulator-temp-%s-kelvin",
44 "regulator-uv-%s-microvolt",
47 &constraints->over_curr_limits,
48 &constraints->over_voltage_limits,
49 &constraints->temp_limits,
50 &constraints->under_voltage_limits,
63 &limits[i]->prot, &limits[i]->err, &limits[i]->warn,
74 constraints->over_current_detection = set[0];
75 constraints->over_voltage_detection = set[1];
76 constraints->over_temp_detection = set[2];
77 constraints->under_voltage_detection = set[3];
85 struct regulation_constraints *constraints = &(*init_data)->constraints;
93 n_phandles = of_count_phandle_with_args(np, "regulator-coupled-with",
97 constraints->name = of_get_property(np, "regulator-name", NULL);
99 if (!of_property_read_u32(np, "regulator-min-microvolt", &pval))
100 constraints->min_uV = pval;
102 if (!of_property_read_u32(np, "regulator-max-microvolt", &pval))
103 constraints->max_uV = pval;
106 if (constraints->min_uV != constraints->max_uV)
107 constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
110 if (constraints->min_uV && constraints->max_uV)
111 constraints->apply_uV = true;
113 if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval))
114 constraints->uV_offset = pval;
115 if (!of_property_read_u32(np, "regulator-min-microamp", &pval))
116 constraints->min_uA = pval;
117 if (!of_property_read_u32(np, "regulator-max-microamp", &pval))
118 constraints->max_uA = pval;
120 if (!of_property_read_u32(np, "regulator-input-current-limit-microamp",
122 constraints->ilim_uA = pval;
125 if (constraints->min_uA != constraints->max_uA)
126 constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT;
128 if (!of_property_read_u32(np, "regulator-power-budget-milliwatt", &pval))
129 constraints->pw_budget_mW = pval;
131 constraints->boot_on = of_property_read_bool(np, "regulator-boot-on");
132 constraints->always_on = of_property_read_bool(np, "regulator-always-on");
133 if (!constraints->always_on) /* status change should be possible. */
134 constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
136 constraints->pull_down = of_property_read_bool(np, "regulator-pull-down");
137 constraints->system_critical = of_property_read_bool(np,
138 "system-critical-regulator");
140 if (of_property_read_bool(np, "regulator-allow-bypass"))
141 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS;
143 if (of_property_read_bool(np, "regulator-allow-set-load"))
144 constraints->valid_ops_mask |= REGULATOR_CHANGE_DRMS;
146 ret = of_property_read_u32(np, "regulator-ramp-delay", &pval);
149 constraints->ramp_delay = pval;
151 constraints->ramp_disable = true;
154 ret = of_property_read_u32(np, "regulator-settling-time-us", &pval);
156 constraints->settling_time = pval;
158 ret = of_property_read_u32(np, "regulator-settling-time-up-us", &pval);
160 constraints->settling_time_up = pval;
161 if (constraints->settling_time_up && constraints->settling_time) {
162 pr_warn("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-up-us'\n",
164 constraints->settling_time_up = 0;
167 ret = of_property_read_u32(np, "regulator-settling-time-down-us",
170 constraints->settling_time_down = pval;
171 if (constraints->settling_time_down && constraints->settling_time) {
172 pr_warn("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-down-us'\n",
174 constraints->settling_time_down = 0;
177 ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval);
179 constraints->enable_time = pval;
181 ret = of_property_read_u32(np, "regulator-uv-less-critical-window-ms", &pval);
183 constraints->uv_less_critical_window_ms = pval;
185 constraints->uv_less_critical_window_ms =
188 constraints->soft_start = of_property_read_bool(np,
189 "regulator-soft-start");
190 ret = of_property_read_u32(np, "regulator-active-discharge", &pval);
192 constraints->active_discharge =
197 if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) {
198 if (desc && desc->of_map_mode) {
199 mode = desc->of_map_mode(pval);
203 constraints->initial_mode = mode;
210 len = of_property_count_elems_of_size(np, "regulator-allowed-modes",
213 if (desc && desc->of_map_mode) {
216 "regulator-allowed-modes", i, &pval);
222 mode = desc->of_map_mode(pval);
224 pr_err("%pOFn: invalid regulator-allowed-modes element %u\n",
227 constraints->valid_modes_mask |= mode;
229 if (constraints->valid_modes_mask)
230 constraints->valid_ops_mask
237 if (!of_property_read_u32(np, "regulator-system-load", &pval))
238 constraints->system_load = pval;
241 constraints->max_spread = devm_kzalloc(dev,
242 sizeof(*constraints->max_spread) * n_phandles,
245 if (!constraints->max_spread)
246 return -ENOMEM;
248 of_property_read_u32_array(np, "regulator-coupled-max-spread",
249 constraints->max_spread, n_phandles);
252 if (!of_property_read_u32(np, "regulator-max-step-microvolt",
254 constraints->max_uV_step = pval;
256 constraints->over_current_protection = of_property_read_bool(np,
257 "regulator-over-current-protection");
264 suspend_state = &constraints->state_mem;
267 suspend_state = &constraints->state_disk;
270 suspend_state = &constraints->state_standby;
286 if (!of_property_read_u32(suspend_np, "regulator-mode",
288 if (desc && desc->of_map_mode) {
289 mode = desc->of_map_mode(pval);
294 suspend_state->mode = mode;
302 "regulator-on-in-suspend"))
303 suspend_state->enabled = ENABLE_IN_SUSPEND;
305 "regulator-off-in-suspend"))
306 suspend_state->enabled = DISABLE_IN_SUSPEND;
309 "regulator-suspend-min-microvolt", &pval))
310 suspend_state->min_uV = pval;
313 "regulator-suspend-max-microvolt", &pval))
314 suspend_state->max_uV = pval;
317 "regulator-suspend-microvolt", &pval))
318 suspend_state->uV = pval;
320 suspend_state->uV = suspend_state->min_uV;
323 "regulator-changeable-in-suspend"))
324 suspend_state->changeable = true;
327 constraints->initial_state = PM_SUSPEND_MEM;
338 * of_get_regulator_init_data - extract regulator_init_data structure info
340 * @node: regulator device node
341 * @desc: regulator description
379 for (i = 0; i < devm_matches->num_matches; i++)
380 of_node_put(devm_matches->matches[i].of_node);
384 * of_regulator_match - extract multiple regulator init data from device tree.
390 * This function uses a match table specified by the regulator driver to
391 * parse regulator init data from the device tree. @node is expected to
393 * regulator. The data parsed from a child node will be matched to a regulator
394 * based on either the deprecated property regulator-compatible if present,
397 * regulator.
412 return -EINVAL;
418 return -ENOMEM;
420 devm_matches->matches = matches;
421 devm_matches->num_matches = num_matches;
427 match->init_data = NULL;
428 match->of_node = NULL;
433 "regulator-compatible", NULL);
435 name = child->name;
438 if (match->of_node)
441 if (strcmp(match->name, name))
444 match->init_data =
446 match->desc);
447 if (!match->init_data) {
449 "failed to parse DT for regulator %pOFn\n",
454 match->of_node = of_node_get(child);
466 match->init_data = NULL;
467 if (match->of_node) {
468 of_node_put(match->of_node);
469 match->of_node = NULL;
472 return -EINVAL;
483 if (!dev->of_node || !desc->of_match)
486 if (desc->regulators_node) {
487 search = of_get_child_by_name(dev->of_node,
488 desc->regulators_node);
490 search = of_node_get(dev->of_node);
492 if (!strcmp(desc->of_match, search->name))
497 dev_dbg(dev, "Failed to find regulator container node '%s'\n",
498 desc->regulators_node);
503 name = of_get_property(child, "regulator-compatible", NULL);
505 if (!desc->of_match_full_name)
506 name = child->name;
508 name = child->full_name;
511 if (!strcmp(desc->of_match, name)) {
534 child = regulator_of_get_init_node(config->dev, desc);
540 dev_err(dev, "failed to parse DT for regulator %pOFn\n", child);
544 if (desc->of_parse_cb) {
547 ret = desc->of_parse_cb(child, desc, config);
549 if (ret == -EPROBE_DEFER) {
551 return ERR_PTR(-EPROBE_DEFER);
554 "driver callback failed to parse DT for regulator %pOFn\n",
571 * of_get_child_regulator - get a child regulator device node
574 * @prop_name: Combination regulator supply name and "-supply"
577 * Extract the child regulator device node corresponding to the supply name.
579 * Return: Pointer to the &struct device_node corresponding to the regulator
605 * of_get_regulator - get a regulator device node based on supply name
608 * @supply: regulator supply name
610 * Extract the regulator device node corresponding to the supply name.
612 * Return: Pointer to the &struct device_node corresponding to the regulator
621 dev_dbg(dev, "Looking up %s-supply from device node %pOF\n", supply, node);
623 snprintf(prop_name, 64, "%s-supply", supply);
628 regnode = of_get_child_regulator(dev->of_node, prop_name);
632 dev_dbg(dev, "Looking up %s property in node %pOF failed\n", prop_name, dev->of_node);
646 * of_regulator_dev_lookup - lookup a regulator device with device tree only
647 * @dev: Device pointer for regulator supply lookup.
648 * @np: Device node pointer for regulator supply lookup.
649 * @supply: Supply name or regulator ID.
660 * * -%ENODEV if lookup fails permanently.
661 * * -%EPROBE_DEFER if lookup could succeed in the future.
680 return ERR_PTR(-EPROBE_DEFER);
683 return ERR_PTR(-ENODEV);
686 struct regulator *_of_regulator_get(struct device *dev, struct device_node *node,
701 * of_regulator_get - get regulator via device tree lookup
703 * @node: device node for regulator "consumer"
706 * Return: pointer to struct regulator corresponding to the regulator producer,
709 * This is intended for use by consumers that want to get a regulator
713 struct regulator *of_regulator_get(struct device *dev,
722 * of_regulator_get_optional - get optional regulator via device tree lookup
724 * @node: device node for regulator "consumer"
727 * Return: pointer to struct regulator corresponding to the regulator producer,
730 * This is intended for use by consumers that want to get a regulator
735 struct regulator *of_regulator_get_optional(struct device *dev,
748 struct device_node *node = rdev->dev.of_node;
752 "regulator-coupled-with",
758 /* Looks for "to_find" device_node in src's "regulator-coupled-with" property */
767 "regulator-coupled-with",
772 "regulator-coupled-with", i);
793 * of_check_coupling_data - Parse rdev's coupling properties and check data
798 * - rdev's max_spread is greater than 0
799 * - all coupled regulators have the same max_spread
800 * - all coupled regulators have the same number of regulator_dev phandles
801 * - all regulators are linked to each other
807 struct device_node *node = rdev->dev.of_node;
816 int max_spread = rdev->constraints->max_spread[i];
820 dev_err(&rdev->dev, "max_spread value invalid\n");
825 "regulator-coupled-with", i);
831 "regulator-coupled-with",
835 dev_err(&rdev->dev, "number of coupled reg phandles mismatch\n");
841 dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n");
846 if (of_property_read_u32_index(c_node, "regulator-coupled-max-spread",
853 dev_err(&rdev->dev,
869 * of_parse_coupled_regulator() - Get regulator_dev pointer from rdev's property
871 * "regulator-coupled-with" property
880 struct device_node *node = rdev->dev.of_node;
884 c_node = of_parse_phandle(node, "regulator-coupled-with", index);
896 * Check if name is a supply name according to the '*-supply' pattern
898 * return length of supply name without the -supply
905 /* string need to be at minimum len(x-supply) */
908 for (i = strs - 6; i > 0; i--) {
909 /* find first '-' and check if right part is supply */
910 if (name[i] != '-')
920 * of_regulator_bulk_get_all - get multiple regulator consumers
926 * This helper function allows drivers to get several regulator
939 struct regulator *tmp;
946 * first pass: get numbers of xxx-supply
951 i = is_supply_name(prop->name);
958 memcpy(name, prop->name, i);
980 return -ENOMEM;
984 while (--n >= 0)