aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/regulator/core.c63
-rw-r--r--drivers/regulator/tps65217-regulator.c114
-rw-r--r--drivers/regulator/tps65910-regulator.c13
-rw-r--r--include/linux/regulator/consumer.h20
4 files changed, 109 insertions, 101 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 44b4045b98d8..cd87c0c37034 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -102,7 +102,7 @@ static int _regulator_disable(struct regulator_dev *rdev);
102static int _regulator_get_voltage(struct regulator_dev *rdev); 102static int _regulator_get_voltage(struct regulator_dev *rdev);
103static int _regulator_get_current_limit(struct regulator_dev *rdev); 103static int _regulator_get_current_limit(struct regulator_dev *rdev);
104static unsigned int _regulator_get_mode(struct regulator_dev *rdev); 104static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
105static void _notifier_call_chain(struct regulator_dev *rdev, 105static int _notifier_call_chain(struct regulator_dev *rdev,
106 unsigned long event, void *data); 106 unsigned long event, void *data);
107static int _regulator_do_set_voltage(struct regulator_dev *rdev, 107static int _regulator_do_set_voltage(struct regulator_dev *rdev,
108 int min_uV, int max_uV); 108 int min_uV, int max_uV);
@@ -2406,6 +2406,55 @@ int regulator_is_supported_voltage(struct regulator *regulator,
2406} 2406}
2407EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); 2407EXPORT_SYMBOL_GPL(regulator_is_supported_voltage);
2408 2408
2409static int _regulator_call_set_voltage(struct regulator_dev *rdev,
2410 int min_uV, int max_uV,
2411 unsigned *selector)
2412{
2413 struct pre_voltage_change_data data;
2414 int ret;
2415
2416 data.old_uV = _regulator_get_voltage(rdev);
2417 data.min_uV = min_uV;
2418 data.max_uV = max_uV;
2419 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
2420 &data);
2421 if (ret & NOTIFY_STOP_MASK)
2422 return -EINVAL;
2423
2424 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, selector);
2425 if (ret >= 0)
2426 return ret;
2427
2428 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE,
2429 (void *)data.old_uV);
2430
2431 return ret;
2432}
2433
2434static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev,
2435 int uV, unsigned selector)
2436{
2437 struct pre_voltage_change_data data;
2438 int ret;
2439
2440 data.old_uV = _regulator_get_voltage(rdev);
2441 data.min_uV = uV;
2442 data.max_uV = uV;
2443 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
2444 &data);
2445 if (ret & NOTIFY_STOP_MASK)
2446 return -EINVAL;
2447
2448 ret = rdev->desc->ops->set_voltage_sel(rdev, selector);
2449 if (ret >= 0)
2450 return ret;
2451
2452 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE,
2453 (void *)data.old_uV);
2454
2455 return ret;
2456}
2457
2409static int _regulator_do_set_voltage(struct regulator_dev *rdev, 2458static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2410 int min_uV, int max_uV) 2459 int min_uV, int max_uV)
2411{ 2460{
@@ -2433,8 +2482,8 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2433 } 2482 }
2434 2483
2435 if (rdev->desc->ops->set_voltage) { 2484 if (rdev->desc->ops->set_voltage) {
2436 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, 2485 ret = _regulator_call_set_voltage(rdev, min_uV, max_uV,
2437 &selector); 2486 &selector);
2438 2487
2439 if (ret >= 0) { 2488 if (ret >= 0) {
2440 if (rdev->desc->ops->list_voltage) 2489 if (rdev->desc->ops->list_voltage)
@@ -2469,8 +2518,8 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2469 if (old_selector == selector) 2518 if (old_selector == selector)
2470 ret = 0; 2519 ret = 0;
2471 else 2520 else
2472 ret = rdev->desc->ops->set_voltage_sel( 2521 ret = _regulator_call_set_voltage_sel(
2473 rdev, ret); 2522 rdev, best_val, selector);
2474 } else { 2523 } else {
2475 ret = -EINVAL; 2524 ret = -EINVAL;
2476 } 2525 }
@@ -3116,11 +3165,11 @@ EXPORT_SYMBOL_GPL(regulator_unregister_notifier);
3116/* notify regulator consumers and downstream regulator consumers. 3165/* notify regulator consumers and downstream regulator consumers.
3117 * Note mutex must be held by caller. 3166 * Note mutex must be held by caller.
3118 */ 3167 */
3119static void _notifier_call_chain(struct regulator_dev *rdev, 3168static int _notifier_call_chain(struct regulator_dev *rdev,
3120 unsigned long event, void *data) 3169 unsigned long event, void *data)
3121{ 3170{
3122 /* call rdev chain first */ 3171 /* call rdev chain first */
3123 blocking_notifier_call_chain(&rdev->notifier, event, data); 3172 return blocking_notifier_call_chain(&rdev->notifier, event, data);
3124} 3173}
3125 3174
3126/** 3175/**
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index d58db72a63b0..adbe4fc5cf07 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -27,10 +27,13 @@
27#include <linux/regulator/machine.h> 27#include <linux/regulator/machine.h>
28#include <linux/mfd/tps65217.h> 28#include <linux/mfd/tps65217.h>
29 29
30#define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t, _lr, _nlr) \ 30#define TPS65217_REGULATOR(_name, _id, _of_match, _ops, _n, _vr, _vm, _em, \
31 _t, _lr, _nlr) \
31 { \ 32 { \
32 .name = _name, \ 33 .name = _name, \
33 .id = _id, \ 34 .id = _id, \
35 .of_match = of_match_ptr(_of_match), \
36 .regulators_node= of_match_ptr("regulators"), \
34 .ops = &_ops, \ 37 .ops = &_ops, \
35 .n_voltages = _n, \ 38 .n_voltages = _n, \
36 .type = REGULATOR_VOLTAGE, \ 39 .type = REGULATOR_VOLTAGE, \
@@ -138,87 +141,40 @@ static struct regulator_ops tps65217_pmic_ldo1_ops = {
138}; 141};
139 142
140static const struct regulator_desc regulators[] = { 143static const struct regulator_desc regulators[] = {
141 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64, 144 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, "dcdc1",
142 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK, 145 tps65217_pmic_ops, 64, TPS65217_REG_DEFDCDC1,
143 TPS65217_ENABLE_DC1_EN, NULL, tps65217_uv1_ranges, 146 TPS65217_DEFDCDCX_DCDC_MASK, TPS65217_ENABLE_DC1_EN,
144 2), /* DCDC1 voltage range: 900000 ~ 1800000 */ 147 NULL, tps65217_uv1_ranges, 2),
145 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64, 148 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, "dcdc2",
146 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK, 149 tps65217_pmic_ops, 64, TPS65217_REG_DEFDCDC2,
147 TPS65217_ENABLE_DC2_EN, NULL, tps65217_uv1_ranges, 150 TPS65217_DEFDCDCX_DCDC_MASK, TPS65217_ENABLE_DC2_EN,
151 NULL, tps65217_uv1_ranges,
148 ARRAY_SIZE(tps65217_uv1_ranges)), 152 ARRAY_SIZE(tps65217_uv1_ranges)),
149 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64, 153 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, "dcdc3",
150 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK, 154 tps65217_pmic_ops, 64, TPS65217_REG_DEFDCDC3,
151 TPS65217_ENABLE_DC3_EN, NULL, tps65217_uv1_ranges, 155 TPS65217_DEFDCDCX_DCDC_MASK, TPS65217_ENABLE_DC3_EN,
152 1), /* DCDC3 voltage range: 900000 ~ 1500000 */ 156 NULL, tps65217_uv1_ranges, 1),
153 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16, 157 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, "ldo1",
154 TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK, 158 tps65217_pmic_ldo1_ops, 16, TPS65217_REG_DEFLDO1,
155 TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table, NULL, 0), 159 TPS65217_DEFLDO1_LDO1_MASK, TPS65217_ENABLE_LDO1_EN,
156 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64, 160 LDO1_VSEL_table, NULL, 0),
157 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK, 161 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, "ldo2", tps65217_pmic_ops,
158 TPS65217_ENABLE_LDO2_EN, NULL, tps65217_uv1_ranges, 162 64, TPS65217_REG_DEFLDO2,
163 TPS65217_DEFLDO2_LDO2_MASK, TPS65217_ENABLE_LDO2_EN,
164 NULL, tps65217_uv1_ranges,
159 ARRAY_SIZE(tps65217_uv1_ranges)), 165 ARRAY_SIZE(tps65217_uv1_ranges)),
160 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32, 166 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, "ldo3", tps65217_pmic_ops,
161 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK, 167 32, TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK,
162 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, 168 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN,
163 NULL, tps65217_uv2_ranges, 169 NULL, tps65217_uv2_ranges,
164 ARRAY_SIZE(tps65217_uv2_ranges)), 170 ARRAY_SIZE(tps65217_uv2_ranges)),
165 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32, 171 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, "ldo4", tps65217_pmic_ops,
166 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK, 172 32, TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK,
167 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, 173 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN,
168 NULL, tps65217_uv2_ranges, 174 NULL, tps65217_uv2_ranges,
169 ARRAY_SIZE(tps65217_uv2_ranges)), 175 ARRAY_SIZE(tps65217_uv2_ranges)),
170}; 176};
171 177
172#ifdef CONFIG_OF
173static struct of_regulator_match reg_matches[] = {
174 { .name = "dcdc1", .driver_data = (void *)TPS65217_DCDC_1 },
175 { .name = "dcdc2", .driver_data = (void *)TPS65217_DCDC_2 },
176 { .name = "dcdc3", .driver_data = (void *)TPS65217_DCDC_3 },
177 { .name = "ldo1", .driver_data = (void *)TPS65217_LDO_1 },
178 { .name = "ldo2", .driver_data = (void *)TPS65217_LDO_2 },
179 { .name = "ldo3", .driver_data = (void *)TPS65217_LDO_3 },
180 { .name = "ldo4", .driver_data = (void *)TPS65217_LDO_4 },
181};
182
183static struct tps65217_board *tps65217_parse_dt(struct platform_device *pdev)
184{
185 struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
186 struct device_node *node = tps->dev->of_node;
187 struct tps65217_board *pdata;
188 struct device_node *regs;
189 int i, count;
190
191 regs = of_get_child_by_name(node, "regulators");
192 if (!regs)
193 return NULL;
194
195 count = of_regulator_match(&pdev->dev, regs, reg_matches,
196 TPS65217_NUM_REGULATOR);
197 of_node_put(regs);
198 if ((count < 0) || (count > TPS65217_NUM_REGULATOR))
199 return NULL;
200
201 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
202 if (!pdata)
203 return NULL;
204
205 for (i = 0; i < count; i++) {
206 if (!reg_matches[i].of_node)
207 continue;
208
209 pdata->tps65217_init_data[i] = reg_matches[i].init_data;
210 pdata->of_node[i] = reg_matches[i].of_node;
211 }
212
213 return pdata;
214}
215#else
216static struct tps65217_board *tps65217_parse_dt(struct platform_device *pdev)
217{
218 return NULL;
219}
220#endif
221
222static int tps65217_regulator_probe(struct platform_device *pdev) 178static int tps65217_regulator_probe(struct platform_device *pdev)
223{ 179{
224 struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent); 180 struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
@@ -227,14 +183,6 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
227 struct regulator_config config = { }; 183 struct regulator_config config = { };
228 int i; 184 int i;
229 185
230 if (tps->dev->of_node)
231 pdata = tps65217_parse_dt(pdev);
232
233 if (!pdata) {
234 dev_err(&pdev->dev, "Platform data not found\n");
235 return -EINVAL;
236 }
237
238 if (tps65217_chip_id(tps) != TPS65217) { 186 if (tps65217_chip_id(tps) != TPS65217) {
239 dev_err(&pdev->dev, "Invalid tps chip version\n"); 187 dev_err(&pdev->dev, "Invalid tps chip version\n");
240 return -ENODEV; 188 return -ENODEV;
@@ -245,11 +193,10 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
245 for (i = 0; i < TPS65217_NUM_REGULATOR; i++) { 193 for (i = 0; i < TPS65217_NUM_REGULATOR; i++) {
246 /* Register the regulators */ 194 /* Register the regulators */
247 config.dev = tps->dev; 195 config.dev = tps->dev;
248 config.init_data = pdata->tps65217_init_data[i]; 196 if (pdata)
197 config.init_data = pdata->tps65217_init_data[i];
249 config.driver_data = tps; 198 config.driver_data = tps;
250 config.regmap = tps->regmap; 199 config.regmap = tps->regmap;
251 if (tps->dev->of_node)
252 config.of_node = pdata->of_node[i];
253 200
254 rdev = devm_regulator_register(&pdev->dev, &regulators[i], 201 rdev = devm_regulator_register(&pdev->dev, &regulators[i],
255 &config); 202 &config);
@@ -259,6 +206,7 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
259 return PTR_ERR(rdev); 206 return PTR_ERR(rdev);
260 } 207 }
261 } 208 }
209
262 return 0; 210 return 0;
263} 211}
264 212
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index e584c998b55f..18fc991175bc 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -1047,7 +1047,7 @@ static struct tps65910_board *tps65910_parse_dt_reg_data(
1047 *tps65910_reg_matches = matches; 1047 *tps65910_reg_matches = matches;
1048 1048
1049 for (idx = 0; idx < count; idx++) { 1049 for (idx = 0; idx < count; idx++) {
1050 if (!matches[idx].init_data || !matches[idx].of_node) 1050 if (!matches[idx].of_node)
1051 continue; 1051 continue;
1052 1052
1053 pmic_plat_data->tps65910_pmic_init_data[idx] = 1053 pmic_plat_data->tps65910_pmic_init_data[idx] =
@@ -1077,7 +1077,6 @@ static int tps65910_probe(struct platform_device *pdev)
1077 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); 1077 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1078 struct regulator_config config = { }; 1078 struct regulator_config config = { };
1079 struct tps_info *info; 1079 struct tps_info *info;
1080 struct regulator_init_data *reg_data;
1081 struct regulator_dev *rdev; 1080 struct regulator_dev *rdev;
1082 struct tps65910_reg *pmic; 1081 struct tps65910_reg *pmic;
1083 struct tps65910_board *pmic_plat_data; 1082 struct tps65910_board *pmic_plat_data;
@@ -1140,14 +1139,6 @@ static int tps65910_probe(struct platform_device *pdev)
1140 1139
1141 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS; 1140 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1142 i++, info++) { 1141 i++, info++) {
1143
1144 reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
1145
1146 /* Regulator API handles empty constraints but not NULL
1147 * constraints */
1148 if (!reg_data)
1149 continue;
1150
1151 /* Register the regulators */ 1142 /* Register the regulators */
1152 pmic->info[i] = info; 1143 pmic->info[i] = info;
1153 1144
@@ -1199,7 +1190,7 @@ static int tps65910_probe(struct platform_device *pdev)
1199 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED; 1190 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1200 1191
1201 config.dev = tps65910->dev; 1192 config.dev = tps65910->dev;
1202 config.init_data = reg_data; 1193 config.init_data = pmic_plat_data->tps65910_pmic_init_data[i];
1203 config.driver_data = pmic; 1194 config.driver_data = pmic;
1204 config.regmap = tps65910->regmap; 1195 config.regmap = tps65910->regmap;
1205 1196
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index f8a8733068a7..d347c805f923 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -93,7 +93,12 @@ struct regmap;
93 * OVER_TEMP Regulator over temp. 93 * OVER_TEMP Regulator over temp.
94 * FORCE_DISABLE Regulator forcibly shut down by software. 94 * FORCE_DISABLE Regulator forcibly shut down by software.
95 * VOLTAGE_CHANGE Regulator voltage changed. 95 * VOLTAGE_CHANGE Regulator voltage changed.
96 * Data passed is old voltage cast to (void *).
96 * DISABLE Regulator was disabled. 97 * DISABLE Regulator was disabled.
98 * PRE_VOLTAGE_CHANGE Regulator is about to have voltage changed.
99 * Data passed is "struct pre_voltage_change_data"
100 * ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason.
101 * Data passed is old voltage cast to (void *).
97 * 102 *
98 * NOTE: These events can be OR'ed together when passed into handler. 103 * NOTE: These events can be OR'ed together when passed into handler.
99 */ 104 */
@@ -106,6 +111,21 @@ struct regmap;
106#define REGULATOR_EVENT_FORCE_DISABLE 0x20 111#define REGULATOR_EVENT_FORCE_DISABLE 0x20
107#define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40 112#define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40
108#define REGULATOR_EVENT_DISABLE 0x80 113#define REGULATOR_EVENT_DISABLE 0x80
114#define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100
115#define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200
116
117/**
118 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
119 *
120 * @old_uV: Current voltage before change.
121 * @min_uV: Min voltage we'll change to.
122 * @max_uV: Max voltage we'll change to.
123 */
124struct pre_voltage_change_data {
125 unsigned long old_uV;
126 unsigned long min_uV;
127 unsigned long max_uV;
128};
109 129
110struct regulator; 130struct regulator;
111 131