aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/of_regulator.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-08 13:08:57 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-08 13:08:57 -0700
commit68cc38ff33f38424d0456f9a1ecfec4683226a7e (patch)
treefa96b657dca1893ee8da5e858a0b6692f038fad1 /drivers/regulator/of_regulator.c
parentMerge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux (diff)
parentMerge branch 'regulator-4.17' into regulator-4.18 merge window (diff)
downloadlinux-dev-68cc38ff33f38424d0456f9a1ecfec4683226a7e.tar.xz
linux-dev-68cc38ff33f38424d0456f9a1ecfec4683226a7e.zip
Merge tag 'regulator-v4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown: "Quite a lot of core work this time around, though not 100% successful. We gained support for runtime mode changes thanks to David Collins and improved support for write only regulators (ones where we can't read back the configuration) from Douglas Anderson. There's been quite a bit of work from Linus Walleij on converting from specfying GPIOs by numbers to descriptors. Sadly the testing turned out to be less good than we had hoped and so a lot of this had to be reverted. We also have the start of updates to use coupled regulators from Maciej Purski, unfortunately there are further problems there so the last couple of patches have been reverted. We also have new drivers for BD71837 and SY8106A devices, SAW regulators on Qualcomm SPMI and dropped support for some preproduction chips that never made it to market from the AB8500 driver" * tag 'regulator-v4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (57 commits) regulator: gpio: Revert ARM: pxa, regulator: fix building ezx e680 regulator: Revert coupled regulator support again regulator: wm8994: Fix shared GPIOs regulator: max77686: Fix shared GPIOs regulator: bd71837: BD71837 PMIC regulator driver regulator: bd71837: Devicetree bindings for BD71837 regulators regulator: gpio: Get enable GPIO using GPIO descriptor regulator: fixed: Convert to use GPIO descriptor only regulator: s2mps11: Fix boot on Odroid XU3 dt-bindings: qcom_spmi: Document SAW support regulator: qcom_spmi: Add support for SAW regulator: tps65090: Pass descriptor instead of GPIO number regulator: s5m8767: Pass descriptor instead of GPIO number regulator: pfuze100: Delete reference to ena_gpio regulator: max8952: Pass descriptor instead of GPIO number regulator: lp8788-ldo: Pass descriptor instead of GPIO number regulator: lm363x: Pass descriptor instead of GPIO number regulator: max8973: Pass descriptor instead of GPIO number regulator: mc13xxx-core: Switch to SPDX identifier ...
Diffstat (limited to 'drivers/regulator/of_regulator.c')
-rw-r--r--drivers/regulator/of_regulator.c193
1 files changed, 186 insertions, 7 deletions
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index f47264fa1940..638f17d4c848 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -31,7 +31,8 @@ static void of_get_regulation_constraints(struct device_node *np,
struct regulation_constraints *constraints = &(*init_data)->constraints;
struct regulator_state *suspend_state;
struct device_node *suspend_np;
- int ret, i;
+ unsigned int mode;
+ int ret, i, len;
u32 pval;
constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -124,20 +125,51 @@ static void of_get_regulation_constraints(struct device_node *np,
if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) {
if (desc && desc->of_map_mode) {
- ret = desc->of_map_mode(pval);
- if (ret == -EINVAL)
+ mode = desc->of_map_mode(pval);
+ if (mode == REGULATOR_MODE_INVALID)
pr_err("%s: invalid mode %u\n", np->name, pval);
else
- constraints->initial_mode = ret;
+ constraints->initial_mode = mode;
} else {
pr_warn("%s: mapping for mode %d not defined\n",
np->name, pval);
}
}
+ len = of_property_count_elems_of_size(np, "regulator-allowed-modes",
+ sizeof(u32));
+ if (len > 0) {
+ if (desc && desc->of_map_mode) {
+ for (i = 0; i < len; i++) {
+ ret = of_property_read_u32_index(np,
+ "regulator-allowed-modes", i, &pval);
+ if (ret) {
+ pr_err("%s: couldn't read allowed modes index %d, ret=%d\n",
+ np->name, i, ret);
+ break;
+ }
+ mode = desc->of_map_mode(pval);
+ if (mode == REGULATOR_MODE_INVALID)
+ pr_err("%s: invalid regulator-allowed-modes element %u\n",
+ np->name, pval);
+ else
+ constraints->valid_modes_mask |= mode;
+ }
+ if (constraints->valid_modes_mask)
+ constraints->valid_ops_mask
+ |= REGULATOR_CHANGE_MODE;
+ } else {
+ pr_warn("%s: mode mapping not defined\n", np->name);
+ }
+ }
+
if (!of_property_read_u32(np, "regulator-system-load", &pval))
constraints->system_load = pval;
+ if (!of_property_read_u32(np, "regulator-coupled-max-spread",
+ &pval))
+ constraints->max_spread = pval;
+
constraints->over_current_protection = of_property_read_bool(np,
"regulator-over-current-protection");
@@ -163,12 +195,12 @@ static void of_get_regulation_constraints(struct device_node *np,
if (!of_property_read_u32(suspend_np, "regulator-mode",
&pval)) {
if (desc && desc->of_map_mode) {
- ret = desc->of_map_mode(pval);
- if (ret == -EINVAL)
+ mode = desc->of_map_mode(pval);
+ if (mode == REGULATOR_MODE_INVALID)
pr_err("%s: invalid mode %u\n",
np->name, pval);
else
- suspend_state->mode = ret;
+ suspend_state->mode = mode;
} else {
pr_warn("%s: mapping for mode %d not defined\n",
np->name, pval);
@@ -407,3 +439,150 @@ struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
return dev ? dev_to_rdev(dev) : NULL;
}
+
+/*
+ * Returns number of regulators coupled with rdev.
+ */
+int of_get_n_coupled(struct regulator_dev *rdev)
+{
+ struct device_node *node = rdev->dev.of_node;
+ int n_phandles;
+
+ n_phandles = of_count_phandle_with_args(node,
+ "regulator-coupled-with",
+ NULL);
+
+ return (n_phandles > 0) ? n_phandles : 0;
+}
+
+/* Looks for "to_find" device_node in src's "regulator-coupled-with" property */
+static bool of_coupling_find_node(struct device_node *src,
+ struct device_node *to_find)
+{
+ int n_phandles, i;
+ bool found = false;
+
+ n_phandles = of_count_phandle_with_args(src,
+ "regulator-coupled-with",
+ NULL);
+
+ for (i = 0; i < n_phandles; i++) {
+ struct device_node *tmp = of_parse_phandle(src,
+ "regulator-coupled-with", i);
+
+ if (!tmp)
+ break;
+
+ /* found */
+ if (tmp == to_find)
+ found = true;
+
+ of_node_put(tmp);
+
+ if (found)
+ break;
+ }
+
+ return found;
+}
+
+/**
+ * of_check_coupling_data - Parse rdev's coupling properties and check data
+ * consistency
+ * @rdev - pointer to regulator_dev whose data is checked
+ *
+ * Function checks if all the following conditions are met:
+ * - rdev's max_spread is greater than 0
+ * - all coupled regulators have the same max_spread
+ * - all coupled regulators have the same number of regulator_dev phandles
+ * - all regulators are linked to each other
+ *
+ * Returns true if all conditions are met.
+ */
+bool of_check_coupling_data(struct regulator_dev *rdev)
+{
+ int max_spread = rdev->constraints->max_spread;
+ struct device_node *node = rdev->dev.of_node;
+ int n_phandles = of_get_n_coupled(rdev);
+ struct device_node *c_node;
+ int i;
+ bool ret = true;
+
+ if (max_spread <= 0) {
+ dev_err(&rdev->dev, "max_spread value invalid\n");
+ return false;
+ }
+
+ /* iterate over rdev's phandles */
+ for (i = 0; i < n_phandles; i++) {
+ int c_max_spread, c_n_phandles;
+
+ c_node = of_parse_phandle(node,
+ "regulator-coupled-with", i);
+
+ if (!c_node)
+ ret = false;
+
+ c_n_phandles = of_count_phandle_with_args(c_node,
+ "regulator-coupled-with",
+ NULL);
+
+ if (c_n_phandles != n_phandles) {
+ dev_err(&rdev->dev, "number of couped reg phandles mismatch\n");
+ ret = false;
+ goto clean;
+ }
+
+ if (of_property_read_u32(c_node, "regulator-coupled-max-spread",
+ &c_max_spread)) {
+ ret = false;
+ goto clean;
+ }
+
+ if (c_max_spread != max_spread) {
+ dev_err(&rdev->dev,
+ "coupled regulators max_spread mismatch\n");
+ ret = false;
+ goto clean;
+ }
+
+ if (!of_coupling_find_node(c_node, node)) {
+ dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n");
+ ret = false;
+ }
+
+clean:
+ of_node_put(c_node);
+ if (!ret)
+ break;
+ }
+
+ return ret;
+}
+
+/**
+ * of_parse_coupled regulator - Get regulator_dev pointer from rdev's property
+ * @rdev: Pointer to regulator_dev, whose DTS is used as a source to parse
+ * "regulator-coupled-with" property
+ * @index: Index in phandles array
+ *
+ * Returns the regulator_dev pointer parsed from DTS. If it has not been yet
+ * registered, returns NULL
+ */
+struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
+ int index)
+{
+ struct device_node *node = rdev->dev.of_node;
+ struct device_node *c_node;
+ struct regulator_dev *c_rdev;
+
+ c_node = of_parse_phandle(node, "regulator-coupled-with", index);
+ if (!c_node)
+ return NULL;
+
+ c_rdev = of_find_regulator_by_node(c_node);
+
+ of_node_put(c_node);
+
+ return c_rdev;
+}