Linux-Renesas-SoC Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 0/6] ov5647 driver improvement
@ 2020-05-19  1:16 Roman Kovalivskyi
       [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
  0 siblings, 1 reply; 12+ messages in thread
From: Roman Kovalivskyi @ 2020-05-19  1:16 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, Jacopo Mondi,
	Michael Rodin, Mauro Carvalho Chehab, Sakari Ailus,
	Hugues Fruchet, Maxime Ripard, Adam Ford, Todor Tomov,
	Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca, Dave Stevenson,
	Roman Kovalivskyi

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.
       [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
@ 2020-05-19  1:16   ` Roman Kovalivskyi
  2020-05-19 11:24     ` Sakari Ailus
  2020-05-19  1:16   ` [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO Roman Kovalivskyi
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Roman Kovalivskyi @ 2020-05-19  1:16 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, Jacopo Mondi,
	Michael Rodin, Mauro Carvalho Chehab, Sakari Ailus,
	Hugues Fruchet, Maxime Ripard, Adam Ford, Todor Tomov,
	Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca, Dave Stevenson,
	Roman Kovalivskyi

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

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 <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
---
 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO.
       [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
  2020-05-19  1:16   ` [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
@ 2020-05-19  1:16   ` Roman Kovalivskyi
  2020-05-19  1:16   ` [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Roman Kovalivskyi @ 2020-05-19  1:16 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, Jacopo Mondi,
	Michael Rodin, Mauro Carvalho Chehab, Sakari Ailus,
	Hugues Fruchet, Maxime Ripard, Adam Ford, Todor Tomov,
	Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca, Dave Stevenson,
	Roman Kovalivskyi

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

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 <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode
       [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
  2020-05-19  1:16   ` [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
  2020-05-19  1:16   ` [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO Roman Kovalivskyi
@ 2020-05-19  1:16   ` Roman Kovalivskyi
  2020-05-19 11:57     ` Sakari Ailus
  2020-05-19  1:16   ` [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
                     ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Roman Kovalivskyi @ 2020-05-19  1:16 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, Jacopo Mondi,
	Michael Rodin, Mauro Carvalho Chehab, Sakari Ailus,
	Hugues Fruchet, Maxime Ripard, Adam Ford, Todor Tomov,
	Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca, Dave Stevenson,
	Roman Kovalivskyi

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

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 <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep
       [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
                     ` (2 preceding siblings ...)
  2020-05-19  1:16   ` [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
@ 2020-05-19  1:16   ` Roman Kovalivskyi
  2020-05-19 11:57     ` Sakari Ailus
  2020-05-19  1:16   ` [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control Roman Kovalivskyi
  2020-05-19  1:16   ` [PATCH v2 6/6] media: dt-bindings: ov5647: Add property for non-continuous clock Roman Kovalivskyi
  5 siblings, 1 reply; 12+ messages in thread
From: Roman Kovalivskyi @ 2020-05-19  1:16 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, Jacopo Mondi,
	Michael Rodin, Mauro Carvalho Chehab, Sakari Ailus,
	Hugues Fruchet, Maxime Ripard, Adam Ford, Todor Tomov,
	Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca, Dave Stevenson,
	Roman Kovalivskyi

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

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 <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control
       [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
                     ` (3 preceding siblings ...)
  2020-05-19  1:16   ` [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
@ 2020-05-19  1:16   ` Roman Kovalivskyi
  2020-05-19 11:51     ` Sakari Ailus
  2020-05-19  1:16   ` [PATCH v2 6/6] media: dt-bindings: ov5647: Add property for non-continuous clock Roman Kovalivskyi
  5 siblings, 1 reply; 12+ messages in thread
From: Roman Kovalivskyi @ 2020-05-19  1:16 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, Jacopo Mondi,
	Michael Rodin, Mauro Carvalho Chehab, Sakari Ailus,
	Hugues Fruchet, Maxime Ripard, Adam Ford, Todor Tomov,
	Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca, Dave Stevenson,
	Roman Kovalivskyi

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

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

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 6/6] media: dt-bindings: ov5647: Add property for non-continuous clock
       [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
                     ` (4 preceding siblings ...)
  2020-05-19  1:16   ` [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control Roman Kovalivskyi
@ 2020-05-19  1:16   ` Roman Kovalivskyi
  5 siblings, 0 replies; 12+ messages in thread
From: Roman Kovalivskyi @ 2020-05-19  1:16 UTC (permalink / raw)
  To: linux-kernel, linux-media, linux-renesas-soc
  Cc: Luis Oliveira, Niklas Söderlund, Jacopo Mondi,
	Michael Rodin, Mauro Carvalho Chehab, Sakari Ailus,
	Hugues Fruchet, Maxime Ripard, Adam Ford, Todor Tomov,
	Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca, Dave Stevenson,
	Roman Kovalivskyi

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

Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
---
 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.
  2020-05-19  1:16   ` [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
@ 2020-05-19 11:24     ` Sakari Ailus
  2020-05-19 11:51       ` Sakari Ailus
  0 siblings, 1 reply; 12+ messages in thread
From: Sakari Ailus @ 2020-05-19 11:24 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Jacopo Mondi, Michael Rodin,
	Mauro Carvalho Chehab, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hi Dave,

Thanks for the patchset.

On Tue, May 19, 2020 at 04:16:16AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
> 
> 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 <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control
  2020-05-19  1:16   ` [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control Roman Kovalivskyi
@ 2020-05-19 11:51     ` Sakari Ailus
  0 siblings, 0 replies; 12+ messages in thread
From: Sakari Ailus @ 2020-05-19 11:51 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Jacopo Mondi, Michael Rodin,
	Mauro Carvalho Chehab, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hi Roman,

On Tue, May 19, 2020 at 04:16:20AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
> 
> Add optional GPIO pwdn to connect to the PWDN line on the sensor.
> 
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>

This patch should precede the corresponding driver patch.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls.
  2020-05-19 11:24     ` Sakari Ailus
@ 2020-05-19 11:51       ` Sakari Ailus
  0 siblings, 0 replies; 12+ messages in thread
From: Sakari Ailus @ 2020-05-19 11:51 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Jacopo Mondi, Michael Rodin,
	Mauro Carvalho Chehab, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

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

I meant to say "Hi Roman".

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode
  2020-05-19  1:16   ` [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
@ 2020-05-19 11:57     ` Sakari Ailus
  0 siblings, 0 replies; 12+ messages in thread
From: Sakari Ailus @ 2020-05-19 11:57 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Jacopo Mondi, Michael Rodin,
	Mauro Carvalho Chehab, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

Hi Roman,

On Tue, May 19, 2020 at 04:16:18AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
> 
> 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 <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep
  2020-05-19  1:16   ` [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
@ 2020-05-19 11:57     ` Sakari Ailus
  0 siblings, 0 replies; 12+ messages in thread
From: Sakari Ailus @ 2020-05-19 11:57 UTC (permalink / raw)
  To: Roman Kovalivskyi
  Cc: linux-kernel, linux-media, linux-renesas-soc, Luis Oliveira,
	Niklas Söderlund, Jacopo Mondi, Michael Rodin,
	Mauro Carvalho Chehab, Hugues Fruchet, Maxime Ripard, Adam Ford,
	Todor Tomov, Suresh Udipi, Andrew Gabbasov, Eugeniu Rosca,
	Dave Stevenson

On Tue, May 19, 2020 at 04:16:19AM +0300, Roman Kovalivskyi wrote:
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
> 
> 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 <dave.stevenson@raspberrypi.org>
> Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>

This needs to be merged with the 2nd patch.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, back to index

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19  1:16 [PATCH v2 0/6] ov5647 driver improvement Roman Kovalivskyi
     [not found] ` <cover.1589850165.git.roman.kovalivskyi@globallogic.com>
2020-05-19  1:16   ` [PATCH v2 1/6] media: ov5647: Add set_fmt and get_fmt calls Roman Kovalivskyi
2020-05-19 11:24     ` Sakari Ailus
2020-05-19 11:51       ` Sakari Ailus
2020-05-19  1:16   ` [PATCH v2 2/6] media: ov5647: Add support for PWDN GPIO Roman Kovalivskyi
2020-05-19  1:16   ` [PATCH v2 3/6] media: ov5647: Add support for non-continuous clock mode Roman Kovalivskyi
2020-05-19 11:57     ` Sakari Ailus
2020-05-19  1:16   ` [PATCH v2 4/6] media: ov5647: Use gpiod_set_value_cansleep Roman Kovalivskyi
2020-05-19 11:57     ` Sakari Ailus
2020-05-19  1:16   ` [PATCH v2 5/6] media: dt-bindings: ov5647: Add property for PWDN control Roman Kovalivskyi
2020-05-19 11:51     ` Sakari Ailus
2020-05-19  1:16   ` [PATCH v2 6/6] media: dt-bindings: ov5647: Add property for non-continuous clock Roman Kovalivskyi

Linux-Renesas-SoC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-renesas-soc/0 linux-renesas-soc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-renesas-soc linux-renesas-soc/ https://lore.kernel.org/linux-renesas-soc \
		linux-renesas-soc@vger.kernel.org
	public-inbox-index linux-renesas-soc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-renesas-soc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git