|
@@ -166,6 +166,10 @@ static void of_get_regulation_constraints(struct device_node *np,
|
|
|
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");
|
|
|
|
|
@@ -435,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;
|
|
|
+}
|