2020-05-19 01:18:31

by Roman Kovalivskyi

[permalink] [raw]
Subject: [PATCH v2 0/6] ov5647 driver improvement

Driver for ov5647 camera sensor lacks some important functionality, such
as ability to query device format and resolution or operations with
power down mode. Patches from Raspberry kernel source tree[1] fixes
those issues and improves quality of mentioned driver.

Changes since v1 [2]:
* Added DT bindings documentation for PWDN GPIO and non-continuous clock mode
* Patch 2: "media: ov5647: Add support for PWDN GPIO."
* Replaced msleep with usleep_range
* Patch 3: "media: ov5647: Add support for non-continuous clock mode"
* Added check if bus type is correct one
* Replaced storing of all flags to storing whether clock is continuous
* Added of_node_put(np) in case if v4l2_fwnode_endpoint_parse fails

[1] - https://github.com/raspberrypi/linux
[2] - https://lore.kernel.org/patchwork/cover/1223179/

Dave Stevenson (5):
media: ov5647: Add set_fmt and get_fmt calls.
media: ov5647: Add support for PWDN GPIO.
media: ov5647: Add support for non-continuous clock mode
media: ov5647: Use gpiod_set_value_cansleep
media: dt-bindings: ov5647: Add property for PWDN control

Roman Kovalivskyi (1):
media: dt-bindings: ov5647: Add property for non-continuous clock

.../devicetree/bindings/media/i2c/ov5647.txt | 7 ++
drivers/media/i2c/ov5647.c | 77 ++++++++++++++++++-
2 files changed, 80 insertions(+), 4 deletions(-)

--
2.17.1


2020-05-19 01:18:36

by Roman Kovalivskyi

[permalink] [raw]
Subject: [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.

From: Dave Stevenson <[email protected]>

There's no way to query the subdevice for the supported
resolutions. Add set_fmt and get_fmt implementations. Since there's
only one format supported set_fmt does nothing and get returns single
format.

Signed-off-by: Dave Stevenson <[email protected]>
Signed-off-by: Roman Kovalivskyi <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
---
drivers/media/i2c/ov5647.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index e7d2e5b4ad4b..3e587eb0a30e 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -463,8 +463,30 @@ static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,
return 0;
}

+static int ov5647_set_get_fmt(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg,
+ struct v4l2_subdev_format *format)
+{
+ struct v4l2_mbus_framefmt *fmt = &format->format;
+
+ if (format->pad != 0)
+ return -EINVAL;
+
+ /* Only one format is supported, so return that */
+ memset(fmt, 0, sizeof(*fmt));
+ fmt->code = MEDIA_BUS_FMT_SBGGR8_1X8;
+ fmt->colorspace = V4L2_COLORSPACE_SRGB;
+ fmt->field = V4L2_FIELD_NONE;
+ fmt->width = 640;
+ fmt->height = 480;
+
+ return 0;
+}
+
static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = {
.enum_mbus_code = ov5647_enum_mbus_code,
+ .set_fmt = ov5647_set_get_fmt,
+ .get_fmt = ov5647_set_get_fmt,
};

static const struct v4l2_subdev_ops ov5647_subdev_ops = {
--
2.17.1

2020-05-19 01:18:47

by Roman Kovalivskyi

[permalink] [raw]
Subject: [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO.

From: Dave Stevenson <[email protected]>

Add support for an optional GPIO connected to PWDN on the sensor. This
allows the use of hardware standby mode where internal device clock
and circuit activities are halted.

Please nothe that power is off when PWDN is high.

Signed-off-by: Dave Stevenson <[email protected]>
Signed-off-by: Roman Kovalivskyi <[email protected]>
---
drivers/media/i2c/ov5647.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 3e587eb0a30e..796cc80f8ee1 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -21,6 +21,7 @@

#include <linux/clk.h>
#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/io.h>
@@ -35,6 +36,13 @@

#define SENSOR_NAME "ov5647"

+/*
+ * From the datasheet, "20ms after PWDN goes low or 20ms after RESETB goes
+ * high if reset is inserted after PWDN goes high, host can access sensor's
+ * SCCB to initialize sensor."
+ */
+#define PWDN_ACTIVE_DELAY_MS 20
+
#define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5)
#define MIPI_CTRL00_BUS_IDLE BIT(2)
#define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0)
@@ -86,6 +94,7 @@ struct ov5647 {
unsigned int height;
int power_count;
struct clk *xclk;
+ struct gpio_desc *pwdn;
};

static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
@@ -93,6 +102,11 @@ static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
return container_of(sd, struct ov5647, sd);
}

+static inline void msleep_range(unsigned int delay_base)
+{
+ usleep_range(delay_base * 1000, delay_base * 1000 + 5000);
+}
+
static struct regval_list sensor_oe_disable_regs[] = {
{0x3000, 0x00},
{0x3001, 0x00},
@@ -355,6 +369,11 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
if (on && !ov5647->power_count) {
dev_dbg(&client->dev, "OV5647 power on\n");

+ if (ov5647->pwdn) {
+ gpiod_set_value(ov5647->pwdn, 0);
+ msleep_range(PWDN_ACTIVE_DELAY_MS);
+ }
+
ret = clk_prepare_enable(ov5647->xclk);
if (ret < 0) {
dev_err(&client->dev, "clk prepare enable failed\n");
@@ -392,6 +411,8 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
dev_dbg(&client->dev, "soft stby failed\n");

clk_disable_unprepare(ov5647->xclk);
+
+ gpiod_set_value(ov5647->pwdn, 1);
}

/* Update the power count. */
@@ -603,6 +624,10 @@ static int ov5647_probe(struct i2c_client *client)
return -EINVAL;
}

+ /* Request the power down GPIO asserted */
+ sensor->pwdn = devm_gpiod_get_optional(&client->dev, "pwdn",
+ GPIOD_OUT_HIGH);
+
mutex_init(&sensor->lock);

sd = &sensor->sd;
@@ -616,7 +641,15 @@ static int ov5647_probe(struct i2c_client *client)
if (ret < 0)
goto mutex_remove;

+ if (sensor->pwdn) {
+ gpiod_set_value(sensor->pwdn, 0);
+ msleep_range(PWDN_ACTIVE_DELAY_MS);
+ }
+
ret = ov5647_detect(sd);
+
+ gpiod_set_value(sensor->pwdn, 1);
+
if (ret < 0)
goto error;

--
2.17.1

2020-05-19 01:19:08

by Roman Kovalivskyi

[permalink] [raw]
Subject: [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control

From: Dave Stevenson <[email protected]>

Add optional GPIO pwdn to connect to the PWDN line on the sensor.

Signed-off-by: Dave Stevenson <[email protected]>
Signed-off-by: Roman Kovalivskyi <[email protected]>
---
Documentation/devicetree/bindings/media/i2c/ov5647.txt | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/i2c/ov5647.txt b/Documentation/devicetree/bindings/media/i2c/ov5647.txt
index 22e44945b661..70f06c24f470 100644
--- a/Documentation/devicetree/bindings/media/i2c/ov5647.txt
+++ b/Documentation/devicetree/bindings/media/i2c/ov5647.txt
@@ -10,6 +10,9 @@ Required properties:
- reg : I2C slave address of the sensor.
- clocks : Reference to the xclk clock.

+Optional Properties:
+- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.
+
The common video interfaces bindings (see video-interfaces.txt) should be
used to specify link to the image data receiver. The OV5647 device
node should contain one 'port' child node with an 'endpoint' subnode.
@@ -26,6 +29,7 @@ Example:
compatible = "ovti,ov5647";
reg = <0x36>;
clocks = <&camera_clk>;
+ pwdn-gpios = <&pioE 29 GPIO_ACTIVE_HIGH>;
port {
camera_1: endpoint {
remote-endpoint = <&csi1_ep1>;
--
2.17.1

2020-05-19 01:19:36

by Roman Kovalivskyi

[permalink] [raw]
Subject: [PATCH v2 6/6] media: dt-bindings: ov5647: Add property for non-continuous clock

Add optional clock-noncontinuous property to configure whether the
clock is continuous or not.

Signed-off-by: Roman Kovalivskyi <[email protected]>
---
Documentation/devicetree/bindings/media/i2c/ov5647.txt | 3 +++
1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/i2c/ov5647.txt b/Documentation/devicetree/bindings/media/i2c/ov5647.txt
index 70f06c24f470..fefba0a69b07 100644
--- a/Documentation/devicetree/bindings/media/i2c/ov5647.txt
+++ b/Documentation/devicetree/bindings/media/i2c/ov5647.txt
@@ -12,6 +12,8 @@ Required properties:

Optional Properties:
- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.
+- clock-noncontinuous: presence of this boolean property decides whether the
+ MIPI CSI-2 clock is continuous or non-continuous.

The common video interfaces bindings (see video-interfaces.txt) should be
used to specify link to the image data receiver. The OV5647 device
@@ -33,6 +35,7 @@ Example:
port {
camera_1: endpoint {
remote-endpoint = <&csi1_ep1>;
+ clock-noncontinuous;
};
};
};
--
2.17.1

2020-05-19 01:21:37

by Roman Kovalivskyi

[permalink] [raw]
Subject: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode

From: Dave Stevenson <[email protected]>

The driver was only supporting continuous clock mode
although this was not stated anywhere.
Non-continuous clock saves a small amount of power and
on some SoCs is easier to interface with.

Signed-off-by: Dave Stevenson <[email protected]>
Signed-off-by: Roman Kovalivskyi <[email protected]>
---
drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 796cc80f8ee1..10f35c637f91 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -44,6 +44,7 @@
#define PWDN_ACTIVE_DELAY_MS 20

#define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5)
+#define MIPI_CTRL00_LINE_SYNC_ENABLE BIT(4)
#define MIPI_CTRL00_BUS_IDLE BIT(2)
#define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0)

@@ -95,6 +96,7 @@ struct ov5647 {
int power_count;
struct clk *xclk;
struct gpio_desc *pwdn;
+ bool is_clock_contiguous;
};

static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
@@ -274,9 +276,15 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)

static int ov5647_stream_on(struct v4l2_subdev *sd)
{
+ struct ov5647 *ov5647 = to_state(sd);
+ u8 val = MIPI_CTRL00_BUS_IDLE;
int ret;

- ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
+ if (ov5647->is_clock_contiguous)
+ val |= MIPI_CTRL00_CLOCK_LANE_GATE |
+ MIPI_CTRL00_LINE_SYNC_ENABLE;
+
+ ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, val);
if (ret < 0)
return ret;

@@ -573,7 +581,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
.open = ov5647_open,
};

-static int ov5647_parse_dt(struct device_node *np)
+static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
{
struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
struct device_node *ep;
@@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)

ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);

+ if (!ret) {
+ of_node_put(ep);
+ of_node_put(np);
+ return ret;
+ }
+
+ if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
+ || bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)
+ sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
+ & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
+
of_node_put(ep);
return ret;
}
@@ -604,7 +623,7 @@ static int ov5647_probe(struct i2c_client *client)
return -ENOMEM;

if (IS_ENABLED(CONFIG_OF) && np) {
- ret = ov5647_parse_dt(np);
+ ret = ov5647_parse_dt(sensor, np);
if (ret) {
dev_err(dev, "DT parsing error: %d\n", ret);
return ret;
--
2.17.1

2020-05-19 01:22:25

by Roman Kovalivskyi

[permalink] [raw]
Subject: [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep

From: Dave Stevenson <[email protected]>

All calls to the gpio library are in contexts that can sleep,
therefore there is no issue with having those GPIOs controlled
by controllers which require sleeping (eg I2C GPIO expanders).

Switch to using gpiod_set_value_cansleep instead of gpiod_set_value
to avoid triggering the warning in gpiolib should the GPIO
controller need to sleep.

Signed-off-by: Dave Stevenson <[email protected]>
Signed-off-by: Roman Kovalivskyi <[email protected]>
---
drivers/media/i2c/ov5647.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 10f35c637f91..7600b4844f16 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -378,7 +378,7 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
dev_dbg(&client->dev, "OV5647 power on\n");

if (ov5647->pwdn) {
- gpiod_set_value(ov5647->pwdn, 0);
+ gpiod_set_value_cansleep(ov5647->pwdn, 0);
msleep_range(PWDN_ACTIVE_DELAY_MS);
}

@@ -420,7 +420,7 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)

clk_disable_unprepare(ov5647->xclk);

- gpiod_set_value(ov5647->pwdn, 1);
+ gpiod_set_value_cansleep(ov5647->pwdn, 1);
}

/* Update the power count. */
@@ -661,13 +661,13 @@ static int ov5647_probe(struct i2c_client *client)
goto mutex_remove;

if (sensor->pwdn) {
- gpiod_set_value(sensor->pwdn, 0);
+ gpiod_set_value_cansleep(sensor->pwdn, 0);
msleep_range(PWDN_ACTIVE_DELAY_MS);
}

ret = ov5647_detect(sd);

- gpiod_set_value(sensor->pwdn, 1);
+ gpiod_set_value_cansleep(sensor->pwdn, 1);

if (ret < 0)
goto error;
--
2.17.1

2020-05-19 11:26:02

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.

Hi Dave,

Thanks for the patchset.

On Tue, May 19, 2020 at 04:16:16AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <[email protected]>
>
> There's no way to query the subdevice for the supported
> resolutions. Add set_fmt and get_fmt implementations. Since there's
> only one format supported set_fmt does nothing and get returns single
> format.
>
> Signed-off-by: Dave Stevenson <[email protected]>
> Signed-off-by: Roman Kovalivskyi <[email protected]>
> Reviewed-by: Jacopo Mondi <[email protected]>
> ---
> drivers/media/i2c/ov5647.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index e7d2e5b4ad4b..3e587eb0a30e 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -463,8 +463,30 @@ static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,
> return 0;
> }
>
> +static int ov5647_set_get_fmt(struct v4l2_subdev *sd,
> + struct v4l2_subdev_pad_config *cfg,
> + struct v4l2_subdev_format *format)
> +{
> + struct v4l2_mbus_framefmt *fmt = &format->format;
> +
> + if (format->pad != 0)
> + return -EINVAL;

No need to check the pad, the caller already has checked for it.

> +
> + /* Only one format is supported, so return that */
> + memset(fmt, 0, sizeof(*fmt));
> + fmt->code = MEDIA_BUS_FMT_SBGGR8_1X8;
> + fmt->colorspace = V4L2_COLORSPACE_SRGB;
> + fmt->field = V4L2_FIELD_NONE;
> + fmt->width = 640;
> + fmt->height = 480;
> +
> + return 0;
> +}
> +
> static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = {
> .enum_mbus_code = ov5647_enum_mbus_code,
> + .set_fmt = ov5647_set_get_fmt,
> + .get_fmt = ov5647_set_get_fmt,
> };
>
> static const struct v4l2_subdev_ops ov5647_subdev_ops = {

--
Kind regards,

Sakari Ailus

2020-05-19 11:53:56

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.

On Tue, May 19, 2020 at 02:24:03PM +0300, Sakari Ailus wrote:
> Hi Dave,

I meant to say "Hi Roman".

--
Sakari Ailus

2020-05-19 11:55:17

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control

Hi Roman,

On Tue, May 19, 2020 at 04:16:20AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <[email protected]>
>
> Add optional GPIO pwdn to connect to the PWDN line on the sensor.
>
> Signed-off-by: Dave Stevenson <[email protected]>
> Signed-off-by: Roman Kovalivskyi <[email protected]>

This patch should precede the corresponding driver patch.

--
Sakari Ailus

2020-05-19 11:59:03

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode

Hi Roman,

On Tue, May 19, 2020 at 04:16:18AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <[email protected]>
>
> The driver was only supporting continuous clock mode
> although this was not stated anywhere.
> Non-continuous clock saves a small amount of power and
> on some SoCs is easier to interface with.
>
> Signed-off-by: Dave Stevenson <[email protected]>
> Signed-off-by: Roman Kovalivskyi <[email protected]>
> ---
> drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
> 1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index 796cc80f8ee1..10f35c637f91 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -44,6 +44,7 @@
> #define PWDN_ACTIVE_DELAY_MS 20
>
> #define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5)
> +#define MIPI_CTRL00_LINE_SYNC_ENABLE BIT(4)
> #define MIPI_CTRL00_BUS_IDLE BIT(2)
> #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0)
>
> @@ -95,6 +96,7 @@ struct ov5647 {
> int power_count;
> struct clk *xclk;
> struct gpio_desc *pwdn;
> + bool is_clock_contiguous;
> };
>
> static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
> @@ -274,9 +276,15 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)
>
> static int ov5647_stream_on(struct v4l2_subdev *sd)
> {
> + struct ov5647 *ov5647 = to_state(sd);
> + u8 val = MIPI_CTRL00_BUS_IDLE;
> int ret;
>
> - ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
> + if (ov5647->is_clock_contiguous)
> + val |= MIPI_CTRL00_CLOCK_LANE_GATE |
> + MIPI_CTRL00_LINE_SYNC_ENABLE;
> +
> + ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, val);
> if (ret < 0)
> return ret;
>
> @@ -573,7 +581,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
> .open = ov5647_open,
> };
>
> -static int ov5647_parse_dt(struct device_node *np)
> +static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
> {
> struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
> struct device_node *ep;
> @@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)
>
> ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
>

Extra newline.

> + if (!ret) {
> + of_node_put(ep);
> + of_node_put(np);

Why to put np as well?

> + return ret;

Please add a label at the end; it makes error handling easier.

> + }
> +
> + if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
> + || bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)

I bet this device is D-PHY only.

> + sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
> + & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;

Now that you're making use of bus specific parameters, please set the bus
type first before calling v4l2_fwnode_endpoint_parse().

> +
> of_node_put(ep);
> return ret;
> }
> @@ -604,7 +623,7 @@ static int ov5647_probe(struct i2c_client *client)
> return -ENOMEM;
>
> if (IS_ENABLED(CONFIG_OF) && np) {
> - ret = ov5647_parse_dt(np);
> + ret = ov5647_parse_dt(sensor, np);
> if (ret) {
> dev_err(dev, "DT parsing error: %d\n", ret);
> return ret;

--
Kind regards,

Sakari Ailus

2020-05-19 12:00:44

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep

On Tue, May 19, 2020 at 04:16:19AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <[email protected]>
>
> All calls to the gpio library are in contexts that can sleep,
> therefore there is no issue with having those GPIOs controlled
> by controllers which require sleeping (eg I2C GPIO expanders).
>
> Switch to using gpiod_set_value_cansleep instead of gpiod_set_value
> to avoid triggering the warning in gpiolib should the GPIO
> controller need to sleep.
>
> Signed-off-by: Dave Stevenson <[email protected]>
> Signed-off-by: Roman Kovalivskyi <[email protected]>

This needs to be merged with the 2nd patch.

--
Sakari Ailus

2020-06-18 10:15:16

by jacopo mondi

[permalink] [raw]
Subject: Re: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode

Hi Roman, Sakari

On Tue, May 19, 2020 at 02:57:07PM +0300, Sakari Ailus wrote:
> Hi Roman,
>
> On Tue, May 19, 2020 at 04:16:18AM +0300, Roman Kovalivskyi wrote:
> > From: Dave Stevenson <[email protected]>
> >
> > The driver was only supporting continuous clock mode
> > although this was not stated anywhere.
> > Non-continuous clock saves a small amount of power and
> > on some SoCs is easier to interface with.
> >

not much to add to what Sakari said, apart for

> > Signed-off-by: Dave Stevenson <[email protected]>
> > Signed-off-by: Roman Kovalivskyi <[email protected]>
> > ---
> > drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
> > 1 file changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> > index 796cc80f8ee1..10f35c637f91 100644
> > --- a/drivers/media/i2c/ov5647.c
> > +++ b/drivers/media/i2c/ov5647.c
> > @@ -44,6 +44,7 @@
> > #define PWDN_ACTIVE_DELAY_MS 20
> >
> > #define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5)
> > +#define MIPI_CTRL00_LINE_SYNC_ENABLE BIT(4)
> > #define MIPI_CTRL00_BUS_IDLE BIT(2)
> > #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0)
> >
> > @@ -95,6 +96,7 @@ struct ov5647 {
> > int power_count;
> > struct clk *xclk;
> > struct gpio_desc *pwdn;
> > + bool is_clock_contiguous;

the clock is 'continuous' not contigous :)

I plan to upport more ov5647 patches soon, Roman are you planning a
resend of this series or should I do so (keeping your signoffs of
course)

Thanks
j

> > };
> >
> > static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
> > @@ -274,9 +276,15 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)
> >
> > static int ov5647_stream_on(struct v4l2_subdev *sd)
> > {
> > + struct ov5647 *ov5647 = to_state(sd);
> > + u8 val = MIPI_CTRL00_BUS_IDLE;
> > int ret;
> >
> > - ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
> > + if (ov5647->is_clock_contiguous)
> > + val |= MIPI_CTRL00_CLOCK_LANE_GATE |
> > + MIPI_CTRL00_LINE_SYNC_ENABLE;
> > +
> > + ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, val);
> > if (ret < 0)
> > return ret;
> >
> > @@ -573,7 +581,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
> > .open = ov5647_open,
> > };
> >
> > -static int ov5647_parse_dt(struct device_node *np)
> > +static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
> > {
> > struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
> > struct device_node *ep;
> > @@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)
> >
> > ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
> >
>
> Extra newline.
>
> > + if (!ret) {
> > + of_node_put(ep);
> > + of_node_put(np);
>
> Why to put np as well?
>
> > + return ret;
>
> Please add a label at the end; it makes error handling easier.
>
> > + }
> > +
> > + if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
> > + || bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)
>
> I bet this device is D-PHY only.
>
> > + sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
> > + & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
>
> Now that you're making use of bus specific parameters, please set the bus
> type first before calling v4l2_fwnode_endpoint_parse().
>
> > +
> > of_node_put(ep);
> > return ret;
> > }
> > @@ -604,7 +623,7 @@ static int ov5647_probe(struct i2c_client *client)
> > return -ENOMEM;
> >
> > if (IS_ENABLED(CONFIG_OF) && np) {
> > - ret = ov5647_parse_dt(np);
> > + ret = ov5647_parse_dt(sensor, np);
> > if (ret) {
> > dev_err(dev, "DT parsing error: %d\n", ret);
> > return ret;
>
> --
> Kind regards,
>
> Sakari Ailus

2020-06-18 15:53:52

by jacopo mondi

[permalink] [raw]
Subject: Re: [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO.

Hi Roman,

On Tue, May 19, 2020 at 04:16:17AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <[email protected]>
>
> Add support for an optional GPIO connected to PWDN on the sensor. This
> allows the use of hardware standby mode where internal device clock
> and circuit activities are halted.
>
> Please nothe that power is off when PWDN is high.
>
> Signed-off-by: Dave Stevenson <[email protected]>
> Signed-off-by: Roman Kovalivskyi <[email protected]>
> ---
> drivers/media/i2c/ov5647.c | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> index 3e587eb0a30e..796cc80f8ee1 100644
> --- a/drivers/media/i2c/ov5647.c
> +++ b/drivers/media/i2c/ov5647.c
> @@ -21,6 +21,7 @@
>
> #include <linux/clk.h>
> #include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
> #include <linux/i2c.h>
> #include <linux/init.h>
> #include <linux/io.h>
> @@ -35,6 +36,13 @@
>
> #define SENSOR_NAME "ov5647"
>
> +/*
> + * From the datasheet, "20ms after PWDN goes low or 20ms after RESETB goes
> + * high if reset is inserted after PWDN goes high, host can access sensor's
> + * SCCB to initialize sensor."
> + */
> +#define PWDN_ACTIVE_DELAY_MS 20
> +
> #define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5)
> #define MIPI_CTRL00_BUS_IDLE BIT(2)
> #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0)
> @@ -86,6 +94,7 @@ struct ov5647 {
> unsigned int height;
> int power_count;
> struct clk *xclk;
> + struct gpio_desc *pwdn;
> };
>
> static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
> @@ -93,6 +102,11 @@ static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
> return container_of(sd, struct ov5647, sd);
> }
>
> +static inline void msleep_range(unsigned int delay_base)
> +{
> + usleep_range(delay_base * 1000, delay_base * 1000 + 5000);
> +}
> +

I think I mis-lead you with the comment I gave on v1, as I just notice
the designated timeout is 20 msec, so msleep() is fine. Sorry about
this, I thought we were dealing with a shorter interval.

If that's ok with you I'll send a v3 of this series with Sakari's
comments addressed, rebased on top of the yaml version of the sensor
bindings I sent out a few hours ago.

Thanks
j

> static struct regval_list sensor_oe_disable_regs[] = {
> {0x3000, 0x00},
> {0x3001, 0x00},
> @@ -355,6 +369,11 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
> if (on && !ov5647->power_count) {
> dev_dbg(&client->dev, "OV5647 power on\n");
>
> + if (ov5647->pwdn) {
> + gpiod_set_value(ov5647->pwdn, 0);
> + msleep_range(PWDN_ACTIVE_DELAY_MS);
> + }
> +
> ret = clk_prepare_enable(ov5647->xclk);
> if (ret < 0) {
> dev_err(&client->dev, "clk prepare enable failed\n");
> @@ -392,6 +411,8 @@ static int ov5647_sensor_power(struct v4l2_subdev *sd, int on)
> dev_dbg(&client->dev, "soft stby failed\n");
>
> clk_disable_unprepare(ov5647->xclk);
> +
> + gpiod_set_value(ov5647->pwdn, 1);
> }
>
> /* Update the power count. */
> @@ -603,6 +624,10 @@ static int ov5647_probe(struct i2c_client *client)
> return -EINVAL;
> }
>
> + /* Request the power down GPIO asserted */
> + sensor->pwdn = devm_gpiod_get_optional(&client->dev, "pwdn",
> + GPIOD_OUT_HIGH);
> +
> mutex_init(&sensor->lock);
>
> sd = &sensor->sd;
> @@ -616,7 +641,15 @@ static int ov5647_probe(struct i2c_client *client)
> if (ret < 0)
> goto mutex_remove;
>
> + if (sensor->pwdn) {
> + gpiod_set_value(sensor->pwdn, 0);
> + msleep_range(PWDN_ACTIVE_DELAY_MS);
> + }
> +
> ret = ov5647_detect(sd);
> +
> + gpiod_set_value(sensor->pwdn, 1);
> +
> if (ret < 0)
> goto error;
>
> --
> 2.17.1
>

2020-06-22 08:33:57

by jacopo mondi

[permalink] [raw]
Subject: Re: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode

Hi Roman,

On Mon, Jun 22, 2020 at 10:00:46AM +0300, Roman Kovalivskyi wrote:
> Hi Jacopo,
>
> On 18.06.20 13:13, Jacopo Mondi wrote:
> > Hi Roman, Sakari
> >
> > On Tue, May 19, 2020 at 02:57:07PM +0300, Sakari Ailus wrote:
> >> Hi Roman,
> >>
> >> On Tue, May 19, 2020 at 04:16:18AM +0300, Roman Kovalivskyi wrote:
> >>> From: Dave Stevenson <[email protected]>
> >>>
> >>> The driver was only supporting continuous clock mode
> >>> although this was not stated anywhere.
> >>> Non-continuous clock saves a small amount of power and
> >>> on some SoCs is easier to interface with.
> >>>
> > not much to add to what Sakari said, apart for
> >
> >>> Signed-off-by: Dave Stevenson <[email protected]>
> >>> Signed-off-by: Roman Kovalivskyi <[email protected]>
> >>> ---
> >>> drivers/media/i2c/ov5647.c | 25 ++++++++++++++++++++++---
> >>> 1 file changed, 22 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> >>> index 796cc80f8ee1..10f35c637f91 100644
> >>> --- a/drivers/media/i2c/ov5647.c
> >>> +++ b/drivers/media/i2c/ov5647.c
> >>> @@ -44,6 +44,7 @@
> >>> #define PWDN_ACTIVE_DELAY_MS 20
> >>>
> >>> #define MIPI_CTRL00_CLOCK_LANE_GATE BIT(5)
> >>> +#define MIPI_CTRL00_LINE_SYNC_ENABLE BIT(4)
> >>> #define MIPI_CTRL00_BUS_IDLE BIT(2)
> >>> #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0)
> >>>
> >>> @@ -95,6 +96,7 @@ struct ov5647 {
> >>> int power_count;
> >>> struct clk *xclk;
> >>> struct gpio_desc *pwdn;
> >>> + bool is_clock_contiguous;
> > the clock is 'continuous' not contigous :)
> >
> > I plan to upport more ov5647 patches soon, Roman are you planning a
> > resend of this series or should I do so (keeping your signoffs of
> > course)
> >
> > Thanks
> > j
>
> I would be grateful if someone more competent would continue with this
> patch series, so feel free to update it with v3.

I think you did a very good job, I just happen to have a bit more time
to dedicate to this.

I'll make sure I'll cc you and the cc list from your series.

Thanks
j

>
> >>> };
> >>>
> >>> static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
> >>> @@ -274,9 +276,15 @@ static int ov5647_set_virtual_channel(struct v4l2_subdev *sd, int channel)
> >>>
> >>> static int ov5647_stream_on(struct v4l2_subdev *sd)
> >>> {
> >>> + struct ov5647 *ov5647 = to_state(sd);
> >>> + u8 val = MIPI_CTRL00_BUS_IDLE;
> >>> int ret;
> >>>
> >>> - ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, MIPI_CTRL00_BUS_IDLE);
> >>> + if (ov5647->is_clock_contiguous)
> >>> + val |= MIPI_CTRL00_CLOCK_LANE_GATE |
> >>> + MIPI_CTRL00_LINE_SYNC_ENABLE;
> >>> +
> >>> + ret = ov5647_write(sd, OV5647_REG_MIPI_CTRL00, val);
> >>> if (ret < 0)
> >>> return ret;
> >>>
> >>> @@ -573,7 +581,7 @@ static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = {
> >>> .open = ov5647_open,
> >>> };
> >>>
> >>> -static int ov5647_parse_dt(struct device_node *np)
> >>> +static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
> >>> {
> >>> struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
> >>> struct device_node *ep;
> >>> @@ -586,6 +594,17 @@ static int ov5647_parse_dt(struct device_node *np)
> >>>
> >>> ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
> >>>
> >> Extra newline.
> >>
> >>> + if (!ret) {
> >>> + of_node_put(ep);
> >>> + of_node_put(np);
> >> Why to put np as well?
> >>
> >>> + return ret;
> >> Please add a label at the end; it makes error handling easier.
> >>
> >>> + }
> >>> +
> >>> + if (bus_cfg.bus_type == V4L2_MBUS_CSI2_DPHY
> >>> + || bus_cfg.bus_type == V4L2_MBUS_CSI2_CPHY)
> >> I bet this device is D-PHY only.
> >>
> >>> + sensor->is_clock_contiguous = bus_cfg.bus.mipi_csi2.flags
> >>> + & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;
> >> Now that you're making use of bus specific parameters, please set the bus
> >> type first before calling v4l2_fwnode_endpoint_parse().
> >>
> >>> +
> >>> of_node_put(ep);
> >>> return ret;
> >>> }
> >>> @@ -604,7 +623,7 @@ static int ov5647_probe(struct i2c_client *client)
> >>> return -ENOMEM;
> >>>
> >>> if (IS_ENABLED(CONFIG_OF) && np) {
> >>> - ret = ov5647_parse_dt(np);
> >>> + ret = ov5647_parse_dt(sensor, np);
> >>> if (ret) {
> >>> dev_err(dev, "DT parsing error: %d\n", ret);
> >>> return ret;
> >> --
> >> Kind regards,
> >>
> >> Sakari Ailus
>
>
> --
>
> Best regards,
> Roman Kovalivskyi
>