aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2015-07-17 17:41:54 -0400
committerMark Brown <broonie@kernel.org>2015-07-24 13:28:46 -0400
commit3a003baeec246f604ed1d2e0087560d7f15edcc6 (patch)
tree6b9e16f35e605a1b23386be578df569b599e978b
parentbc0195aad0daa2ad5b0d76cce22b167bc3435590 (diff)
regulator: Add over current protection (OCP) support
Some regulators can automatically shut down when they detect an over current event. Add an op (set_over_current_protection) and a DT property + constraint to support this capability. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt1
-rw-r--r--drivers/regulator/core.c9
-rw-r--r--drivers/regulator/of_regulator.c3
-rw-r--r--include/linux/regulator/driver.h1
-rw-r--r--include/linux/regulator/machine.h1
5 files changed, 15 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index db88feb28c03..24bd422cecd5 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -42,6 +42,7 @@ Optional properties:
42- regulator-system-load: Load in uA present on regulator that is not captured by 42- regulator-system-load: Load in uA present on regulator that is not captured by
43 any consumer request. 43 any consumer request.
44- regulator-pull-down: Enable pull down resistor when the regulator is disabled. 44- regulator-pull-down: Enable pull down resistor when the regulator is disabled.
45- regulator-over-current-protection: Enable over current protection.
45 46
46Deprecated properties: 47Deprecated properties:
47- regulator-compatible: If a regulator chip contains multiple 48- regulator-compatible: If a regulator chip contains multiple
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index c9f72019bd68..520413e2bca0 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1081,6 +1081,15 @@ static int set_machine_constraints(struct regulator_dev *rdev,
1081 } 1081 }
1082 } 1082 }
1083 1083
1084 if (rdev->constraints->over_current_protection
1085 && ops->set_over_current_protection) {
1086 ret = ops->set_over_current_protection(rdev);
1087 if (ret < 0) {
1088 rdev_err(rdev, "failed to set over current protection\n");
1089 goto out;
1090 }
1091 }
1092
1084 print_constraints(rdev); 1093 print_constraints(rdev);
1085 return 0; 1094 return 0;
1086out: 1095out:
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index b1c485b24ab2..250700c853bf 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -107,6 +107,9 @@ static void of_get_regulation_constraints(struct device_node *np,
107 if (!of_property_read_u32(np, "regulator-system-load", &pval)) 107 if (!of_property_read_u32(np, "regulator-system-load", &pval))
108 constraints->system_load = pval; 108 constraints->system_load = pval;
109 109
110 constraints->over_current_protection = of_property_read_bool(np,
111 "regulator-over-current-protection");
112
110 for (i = 0; i < ARRAY_SIZE(regulator_states); i++) { 113 for (i = 0; i < ARRAY_SIZE(regulator_states); i++) {
111 switch (i) { 114 switch (i) {
112 case PM_SUSPEND_MEM: 115 case PM_SUSPEND_MEM:
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 4db9fbe4889d..45932228cbf5 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -148,6 +148,7 @@ struct regulator_ops {
148 int (*get_current_limit) (struct regulator_dev *); 148 int (*get_current_limit) (struct regulator_dev *);
149 149
150 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA); 150 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
151 int (*set_over_current_protection) (struct regulator_dev *);
151 152
152 /* enable/disable regulator */ 153 /* enable/disable regulator */
153 int (*enable) (struct regulator_dev *); 154 int (*enable) (struct regulator_dev *);
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index b11be1260129..a1067d0b3991 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -147,6 +147,7 @@ struct regulation_constraints {
147 unsigned ramp_disable:1; /* disable ramp delay */ 147 unsigned ramp_disable:1; /* disable ramp delay */
148 unsigned soft_start:1; /* ramp voltage slowly */ 148 unsigned soft_start:1; /* ramp voltage slowly */
149 unsigned pull_down:1; /* pull down resistor when regulator off */ 149 unsigned pull_down:1; /* pull down resistor when regulator off */
150 unsigned over_current_protection:1; /* auto disable on over current */
150}; 151};
151 152
152/** 153/**