1 From 9ff2bc0c9458f0eecde6d9b52a899fd2bb1dd3a3 Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Tue, 8 May 2012 15:10:36 +0200
4 Subject: [PATCH 5/6] mt9p031: Add support for regulators
6 Enable the regulators when powering the sensor up, and disable them when
9 The regulators are mandatory. Boards that don't allow controlling the
10 sensor power lines must provide fixed voltage regulators.
12 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
14 drivers/media/i2c/mt9p031.c | 24 ++++++++++++++++++++++++
15 1 file changed, 24 insertions(+)
17 diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
18 index e0bad59..ecf4492 100644
19 --- a/drivers/media/i2c/mt9p031.c
20 +++ b/drivers/media/i2c/mt9p031.c
22 #include <linux/i2c.h>
23 #include <linux/log2.h>
25 +#include <linux/regulator/consumer.h>
26 #include <linux/slab.h>
27 #include <linux/videodev2.h>
29 @@ -121,6 +122,10 @@ struct mt9p031 {
30 struct mutex power_lock; /* lock to protect power_count */
33 + struct regulator *vaa;
34 + struct regulator *vdd;
35 + struct regulator *vdd_io;
37 enum mt9p031_model model;
38 struct aptina_pll pll;
40 @@ -264,6 +269,11 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
41 usleep_range(1000, 2000);
44 + /* Bring up the supplies */
45 + regulator_enable(mt9p031->vdd);
46 + regulator_enable(mt9p031->vdd_io);
47 + regulator_enable(mt9p031->vaa);
50 if (mt9p031->pdata->set_xclk)
51 mt9p031->pdata->set_xclk(&mt9p031->subdev,
52 @@ -285,6 +295,10 @@ static void mt9p031_power_off(struct mt9p031 *mt9p031)
53 usleep_range(1000, 2000);
56 + regulator_disable(mt9p031->vaa);
57 + regulator_disable(mt9p031->vdd_io);
58 + regulator_disable(mt9p031->vdd);
60 if (mt9p031->pdata->set_xclk)
61 mt9p031->pdata->set_xclk(&mt9p031->subdev, 0);
63 @@ -937,6 +951,16 @@ static int mt9p031_probe(struct i2c_client *client,
64 mt9p031->model = did->driver_data;
67 + mt9p031->vaa = devm_regulator_get(&client->dev, "vaa");
68 + mt9p031->vdd = devm_regulator_get(&client->dev, "vdd");
69 + mt9p031->vdd_io = devm_regulator_get(&client->dev, "vdd_io");
71 + if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) ||
72 + IS_ERR(mt9p031->vdd_io)) {
73 + dev_err(&client->dev, "Unable to get regulators\n");
77 v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6);
79 v4l2_ctrl_new_std(&mt9p031->ctrls, &mt9p031_ctrl_ops,