aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Hilman <khilman@linaro.org>2014-09-25 12:57:57 -0400
committerKevin Hilman <khilman@linaro.org>2014-09-25 12:57:57 -0400
commitcd8caa18deff6d2d87a4e3161b4dd8c6da3c4f38 (patch)
tree1587224b5b96274a950dae310b298006322f3844
parent20651e0b218e3684fee5e46319a1ba363c864179 (diff)
parent7179569aeb52197fd2a9909ba226c4c9cc0e2e2a (diff)
Merge branch 'topic/voltage-ev' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator into avs-next
-rw-r--r--drivers/regulator/core.c63
-rw-r--r--include/linux/regulator/consumer.h20
2 files changed, 76 insertions, 7 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a3c3785901f5..dabc8e8862c8 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);
@@ -2369,6 +2369,55 @@ int regulator_is_supported_voltage(struct regulator *regulator,
2369} 2369}
2370EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); 2370EXPORT_SYMBOL_GPL(regulator_is_supported_voltage);
2371 2371
2372static int _regulator_call_set_voltage(struct regulator_dev *rdev,
2373 int min_uV, int max_uV,
2374 unsigned *selector)
2375{
2376 struct pre_voltage_change_data data;
2377 int ret;
2378
2379 data.old_uV = _regulator_get_voltage(rdev);
2380 data.min_uV = min_uV;
2381 data.max_uV = max_uV;
2382 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
2383 &data);
2384 if (ret & NOTIFY_STOP_MASK)
2385 return -EINVAL;
2386
2387 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, selector);
2388 if (ret >= 0)
2389 return ret;
2390
2391 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE,
2392 (void *)data.old_uV);
2393
2394 return ret;
2395}
2396
2397static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev,
2398 int uV, unsigned selector)
2399{
2400 struct pre_voltage_change_data data;
2401 int ret;
2402
2403 data.old_uV = _regulator_get_voltage(rdev);
2404 data.min_uV = uV;
2405 data.max_uV = uV;
2406 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
2407 &data);
2408 if (ret & NOTIFY_STOP_MASK)
2409 return -EINVAL;
2410
2411 ret = rdev->desc->ops->set_voltage_sel(rdev, selector);
2412 if (ret >= 0)
2413 return ret;
2414
2415 _notifier_call_chain(rdev, REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE,
2416 (void *)data.old_uV);
2417
2418 return ret;
2419}
2420
2372static int _regulator_do_set_voltage(struct regulator_dev *rdev, 2421static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2373 int min_uV, int max_uV) 2422 int min_uV, int max_uV)
2374{ 2423{
@@ -2396,8 +2445,8 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2396 } 2445 }
2397 2446
2398 if (rdev->desc->ops->set_voltage) { 2447 if (rdev->desc->ops->set_voltage) {
2399 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, 2448 ret = _regulator_call_set_voltage(rdev, min_uV, max_uV,
2400 &selector); 2449 &selector);
2401 2450
2402 if (ret >= 0) { 2451 if (ret >= 0) {
2403 if (rdev->desc->ops->list_voltage) 2452 if (rdev->desc->ops->list_voltage)
@@ -2432,8 +2481,8 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2432 if (old_selector == selector) 2481 if (old_selector == selector)
2433 ret = 0; 2482 ret = 0;
2434 else 2483 else
2435 ret = rdev->desc->ops->set_voltage_sel( 2484 ret = _regulator_call_set_voltage_sel(
2436 rdev, ret); 2485 rdev, best_val, selector);
2437 } else { 2486 } else {
2438 ret = -EINVAL; 2487 ret = -EINVAL;
2439 } 2488 }
@@ -3079,11 +3128,11 @@ EXPORT_SYMBOL_GPL(regulator_unregister_notifier);
3079/* notify regulator consumers and downstream regulator consumers. 3128/* notify regulator consumers and downstream regulator consumers.
3080 * Note mutex must be held by caller. 3129 * Note mutex must be held by caller.
3081 */ 3130 */
3082static void _notifier_call_chain(struct regulator_dev *rdev, 3131static int _notifier_call_chain(struct regulator_dev *rdev,
3083 unsigned long event, void *data) 3132 unsigned long event, void *data)
3084{ 3133{
3085 /* call rdev chain first */ 3134 /* call rdev chain first */
3086 blocking_notifier_call_chain(&rdev->notifier, event, data); 3135 return blocking_notifier_call_chain(&rdev->notifier, event, data);
3087} 3136}
3088 3137
3089/** 3138/**
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