From: Rui Miguel Silva <rui.silva@linaro.org>
To: mchehab@kernel.org, sakari.ailus@linux.intel.com,
hverkuil@xs4all.nl, Rob Herring <robh+dt@kernel.org>
Cc: linux-media@vger.kernel.org,
Fabio Estevam <fabio.estevam@nxp.com>,
devicetree@vger.kernel.org, Ryan Harkin <ryan.harkin@linaro.org>,
Rui Miguel Silva <rui.silva@linaro.org>
Subject: [PATCH 4/4] media: ov2680: add regulators to supply control
Date: Mon, 7 May 2018 16:56:55 +0100 [thread overview]
Message-ID: <20180507155655.1555-5-rui.silva@linaro.org> (raw)
In-Reply-To: <20180507155655.1555-1-rui.silva@linaro.org>
Add the code to control the regulators for the analogue and digital power
supplies.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
---
drivers/media/i2c/ov2680.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 8962b397211a..07bb475c970c 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -19,6 +19,7 @@
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ctrls.h>
@@ -65,6 +66,14 @@ struct reg_value {
u8 val;
};
+static const char * const ov2680_supply_name[] = {
+ "DOVDD",
+ "DVDD",
+ "AVDD",
+};
+
+#define OV2680_NUM_SUPPLIES ARRAY_SIZE(ov2680_supply_name)
+
struct ov2680_mode_info {
const char *name;
enum ov2680_mode_id id;
@@ -97,6 +106,7 @@ struct ov2680_dev {
struct media_pad pad;
struct clk *xvclk;
u32 xvclk_freq;
+ struct regulator_bulk_data supplies[OV2680_NUM_SUPPLIES];
struct gpio_desc *reset_gpio;
struct mutex lock; /* protect members */
@@ -522,6 +532,7 @@ static int ov2680_power_off(struct ov2680_dev *sensor)
clk_disable_unprepare(sensor->xvclk);
ov2680_power_down(sensor);
+ regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies);
sensor->is_enabled = false;
return 0;
@@ -535,6 +546,12 @@ static int ov2680_power_on(struct ov2680_dev *sensor)
if (sensor->is_enabled)
return 0;
+ ret = regulator_bulk_enable(OV2680_NUM_SUPPLIES, sensor->supplies);
+ if (ret < 0) {
+ dev_err(dev, "failed to enable regulators: %d\n", ret);
+ return ret;
+ }
+
if (!sensor->reset_gpio) {
ret = ov2680_write_reg(sensor, OV2680_REG_SOFT_RESET, 0x01);
if (ret != 0) {
@@ -962,6 +979,18 @@ static int ov2680_v4l2_init(struct ov2680_dev *sensor)
return ret;
}
+static int ov2680_get_regulators(struct ov2680_dev *sensor)
+{
+ int i;
+
+ for (i = 0; i < OV2680_NUM_SUPPLIES; i++)
+ sensor->supplies[i].supply = ov2680_supply_name[i];
+
+ return devm_regulator_bulk_get(&sensor->i2c_client->dev,
+ OV2680_NUM_SUPPLIES,
+ sensor->supplies);
+}
+
static int ov2680_check_id(struct ov2680_dev *sensor)
{
struct device *dev = ov2680_to_dev(sensor);
@@ -1034,6 +1063,12 @@ static int ov2680_probe(struct i2c_client *client)
if (ret < 0)
return ret;
+ ret = ov2680_get_regulators(sensor);
+ if (ret < 0) {
+ dev_err(dev, "failed to get regulators\n");
+ return ret;
+ }
+
mutex_init(&sensor->lock);
ret = ov2680_v4l2_init(sensor);
--
2.17.0
next prev parent reply other threads:[~2018-05-07 15:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-07 15:56 [PATCH 0/4] media: ov2680: follow up from initial version Rui Miguel Silva
2018-05-07 15:56 ` [PATCH 1/4] media: ov2680: dt: add voltage supplies as required Rui Miguel Silva
2018-05-07 15:56 ` [PATCH 2/4] media: ov2680: dt: rename gpio to reset and fix polarity Rui Miguel Silva
2018-05-07 15:56 ` [PATCH 3/4] media: ov2680: rename powerdown gpio " Rui Miguel Silva
2018-05-07 15:56 ` Rui Miguel Silva [this message]
2018-05-08 13:29 ` [PATCH 0/4] media: ov2680: follow up from initial version Fabio Estevam
2018-05-08 13:52 ` Rui Miguel Silva
2018-05-08 13:55 ` Fabio Estevam
2018-05-08 20:03 ` Sakari Ailus
2018-05-09 11:03 ` Rui Miguel Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180507155655.1555-5-rui.silva@linaro.org \
--to=rui.silva@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=fabio.estevam@nxp.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=robh+dt@kernel.org \
--cc=ryan.harkin@linaro.org \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).