regulator: Expand regulator notifier events
Alex Frid [Wed, 20 Jul 2011 22:04:06 +0000 (15:04 -0700)]
Add regulator enable notifications (not sent by the current code).
Add voltage notifications sent only if regulator output is actually
changed (keep intact existing voltage change notification that is
sent unconditionally - even if voltage change was not allowed by
constraints, or no actual change since regulator is disabled):

PRE_ENABLE     Regulator is to be enabled
POST_ENABLE    Regulator was enabled
OUT_PRECHANGE  Regulator is enabled and its voltage is to be changed
OUT_POSTCHANGE Regulator is enabled and its voltage was changed

Bug 853132

Original-Change-Id: I2759ada1c5d1e43f746f6c866f9b3c203b68aed6
Reviewed-on: http://git-master/r/42262
Tested-by: Aleksandr Frid <afrid@nvidia.com>
Reviewed-by: Scott Williams <scwilliams@nvidia.com>
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Karan Jhavar <kjhavar@nvidia.com>
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>

Rebase-Id: Rdac9b19d1f999e889aae8e2eb72f9b60057dd05a

drivers/regulator/core.c
include/linux/regulator/consumer.h

index 029a73c..c7e7373 100644 (file)
@@ -1433,6 +1433,8 @@ static int _regulator_enable(struct regulator_dev *rdev)
                        }
 
                        trace_regulator_enable(rdev_get_name(rdev));
+                       _notifier_call_chain(
+                               rdev, REGULATOR_EVENT_PRE_ENABLE, NULL);
 
                        /* Allow the regulator to ramp; it would be useful
                         * to extend this for bulk operations so that the
@@ -1450,6 +1452,8 @@ static int _regulator_enable(struct regulator_dev *rdev)
                                udelay(delay);
                        }
 
+                       _notifier_call_chain(
+                               rdev, REGULATOR_EVENT_POST_ENABLE, NULL);
                        trace_regulator_enable_complete(rdev_get_name(rdev));
 
                } else if (ret < 0) {
@@ -1804,6 +1808,10 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
        min_uV += rdev->constraints->uV_offset;
        max_uV += rdev->constraints->uV_offset;
 
+       if (_regulator_is_enabled(rdev))
+               _notifier_call_chain(rdev, REGULATOR_EVENT_OUT_PRECHANGE,
+                                    NULL);
+
        if (rdev->desc->ops->set_voltage) {
                ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV,
                                                   &selector);
@@ -1871,6 +1879,10 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
                _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE,
                                     NULL);
 
+       if (_regulator_is_enabled(rdev))
+               _notifier_call_chain(rdev, REGULATOR_EVENT_OUT_POSTCHANGE,
+                                    NULL);
+
        trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector);
 
        return ret;
index f2698a0..0241af2 100644 (file)
  * FORCE_DISABLE  Regulator forcibly shut down by software.
  * VOLTAGE_CHANGE Regulator voltage changed.
  * DISABLE        Regulator was disabled.
+ * PRE_ENABLE     Regulator is to be enabled
+ * POST_ENABLE    Regulator was enabled
+ * OUT_PRECHANGE  Regulator is enabled and its voltage is to be changed
+ * OUT_POSTCHANGE Regulator is enabled and its voltage was changed
  *
  * NOTE: These events can be OR'ed together when passed into handler.
  */
 #define REGULATOR_EVENT_FORCE_DISABLE          0x20
 #define REGULATOR_EVENT_VOLTAGE_CHANGE         0x40
 #define REGULATOR_EVENT_DISABLE                0x80
+#define REGULATOR_EVENT_PRE_ENABLE             0x100
+#define REGULATOR_EVENT_POST_ENABLE            0x200
+#define REGULATOR_EVENT_OUT_PRECHANGE          0x400
+#define REGULATOR_EVENT_OUT_POSTCHANGE         0x800
 
 struct regulator;