diff mbox

m5mols: Improved power on routine

Message ID 1364910056-25636-1-git-send-email-s.nawrocki@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

From: Andrzej Hajda <a.hajda@samsung.com>

The regulator bulk API doesn't guarantee an order in which regulators
are enabled or disabled. Make sure the regulators are enabled
sequentially, as specified in the sensor's datasheet.
Additionally a 1ms delay is added after the reset GPIO (de)assertion.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/media/i2c/m5mols/m5mols_core.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/media/i2c/m5mols/m5mols_core.c b/drivers/media/i2c/m5mols/m5mols_core.c
index 0b899cb..a364781 100644
--- a/drivers/media/i2c/m5mols/m5mols_core.c
+++ b/drivers/media/i2c/m5mols/m5mols_core.c
@@ -740,6 +740,24 @@  static const struct v4l2_subdev_video_ops m5mols_video_ops = {
 	.s_stream	= m5mols_s_stream,
 };
 
+static int regulator_bulk_enable_sync(int num_consumers,
+				      struct regulator_bulk_data *consumers)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(supplies); ++i) {
+		ret = regulator_enable(supplies[i].consumer);
+		if (ret < 0) {
+			for (; i >= 0; --i)
+				regulator_disable(supplies[i].consumer);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static int m5mols_sensor_power(struct m5mols_info *info, bool enable)
 {
 	struct v4l2_subdev *sd = &info->sd;
@@ -757,13 +775,15 @@  static int m5mols_sensor_power(struct m5mols_info *info, bool enable)
 				return ret;
 		}
 
-		ret = regulator_bulk_enable(ARRAY_SIZE(supplies), supplies);
+		ret = regulator_bulk_enable_sync(ARRAY_SIZE(supplies),
+						  supplies);
 		if (ret) {
 			info->set_power(&client->dev, 0);
 			return ret;
 		}
 
 		gpio_set_value(pdata->gpio_reset, !pdata->reset_polarity);
+		usleep_range(1000, 1000);
 		info->power = 1;
 
 		return ret;
@@ -777,6 +797,7 @@  static int m5mols_sensor_power(struct m5mols_info *info, bool enable)
 		info->set_power(&client->dev, 0);
 
 	gpio_set_value(pdata->gpio_reset, pdata->reset_polarity);
+	usleep_range(1000, 1000);
 
 	info->isp_ready = 0;
 	info->power = 0;