Skip to contentSkip to conversation

atmel-isi: Add DT support for Atmel ISI driver

PATCH Superseded Josh Wu 3 participants 13 messages Mar 25, 2014 – Jul 18, 2014

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Josh Wu

author
#0 lore raw

v2 cover atmel-isi: Add DT support for Atmel ISI driver

This patch series add DT support for atmel ISI driver. It can support the common v4l2 DT interfaces.

v1 --> v2:
modified the device tree binding document to remove the a optional property.

Josh Wu (3):
[media] atmel-isi: add v4l2 async probe support [media] atmel-isi: convert the pdata from pointer to structure [media] atmel-isi: add primary DT support

 .../devicetree/bindings/media/atmel-isi.txt        |   50 +++++++++++++++++
 drivers/media/platform/soc_camera/atmel-isi.c      |   56 +++++++++++++++-----
 include/media/atmel-isi.h                          |    4 ++
 3 files changed, 98 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isi.txt
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v2 1/3 atmel-isi: add v4l2 async probe support

---
v1 --> v2:
no change.

 drivers/media/platform/soc_camera/atmel-isi.c |    5 +++++
 include/media/atmel-isi.h                     |    4 ++++
 2 files changed, 9 insertions(+)
drivers/media/platform/soc_camera/atmel-isi.c +5 -0
index a1a95fe..9d977c5 100644
@@ -989,6 +989,11 @@ static int atmel_isi_probe(struct platform_device *pdev)
 	soc_host->v4l2_dev.dev	= &pdev->dev;
 	soc_host->nr		= pdev->id;
 
+	if (isi->pdata.asd_sizes) {
+		soc_host->asd = isi->pdata.asd;
+		soc_host->asd_sizes = isi->pdata.asd_sizes;
+	}
+
 	ret = soc_camera_host_register(soc_host);
 	if (ret) {
 		dev_err(&pdev->dev, "Unable to register soc camera host\n");
include/media/atmel-isi.h +4 -0
index 2b02347..c2e5703 100644
@@ -106,6 +106,8 @@
 #define ISI_DATAWIDTH_8				0x01
 #define ISI_DATAWIDTH_10			0x02
 
+struct v4l2_async_subdev;
+
 struct isi_platform_data {
 	u8 has_emb_sync;
 	u8 emb_crc_sync;
@@ -118,6 +120,8 @@ struct isi_platform_data {
 	u32 frate;
 	/* Using for ISI_MCK */
 	u32 mck_hz;
+	struct v4l2_async_subdev **asd;	/* Flat array, arranged in groups */
+	int *asd_sizes;		/* 0-terminated array of asd group sizes */
 };
 
 #endif /* __ATMEL_ISI_H__ */
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v2 2/3 atmel-isi: convert the pdata from pointer to structure

In reply to Josh Wu

Now the platform data is initialized by allocation of isi structure. In the future, we use pdata to store the dt parameters.

---
v1 --> v2:
no change.

 drivers/media/platform/soc_camera/atmel-isi.c |   22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/media/platform/soc_camera/atmel-isi.c +11 -11
index 9d977c5..f4add0a 100644
@@ -84,7 +84,7 @@ struct atmel_isi {
 	struct clk			*mck;
 	unsigned int			irq;
 
-	struct isi_platform_data	*pdata;
+	struct isi_platform_data	pdata;
 	u16				width_flags;	/* max 12 bits */
 
 	struct list_head		video_buffer_list;
@@ -350,7 +350,7 @@ static void start_dma(struct atmel_isi *isi, struct frame_buffer *buffer)
 
 	cfg1 &= ~ISI_CFG1_FRATE_DIV_MASK;
 	/* Enable linked list */
-	cfg1 |= isi->pdata->frate | ISI_CFG1_DISCR;
+	cfg1 |= isi->pdata.frate | ISI_CFG1_DISCR;
 
 	/* Enable codec path and ISI */
 	ctrl = ISI_CTRL_CDC | ISI_CTRL_EN;
@@ -797,7 +797,7 @@ static int isi_camera_set_bus_param(struct soc_camera_device *icd)
 	/* Make choises, based on platform preferences */
 	if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
 	    (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
-		if (isi->pdata->hsync_act_low)
+		if (isi->pdata.hsync_act_low)
 			common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
 		else
 			common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
@@ -805,7 +805,7 @@ static int isi_camera_set_bus_param(struct soc_camera_device *icd)
 
 	if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
 	    (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
-		if (isi->pdata->vsync_act_low)
+		if (isi->pdata.vsync_act_low)
 			common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
 		else
 			common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
@@ -813,7 +813,7 @@ static int isi_camera_set_bus_param(struct soc_camera_device *icd)
 
 	if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
 	    (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
-		if (isi->pdata->pclk_act_falling)
+		if (isi->pdata.pclk_act_falling)
 			common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
 		else
 			common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
@@ -835,9 +835,9 @@ static int isi_camera_set_bus_param(struct soc_camera_device *icd)
 	if (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
 		cfg1 |= ISI_CFG1_PIXCLK_POL_ACTIVE_FALLING;
 
-	if (isi->pdata->has_emb_sync)
+	if (isi->pdata.has_emb_sync)
 		cfg1 |= ISI_CFG1_EMB_SYNC;
-	if (isi->pdata->full_mode)
+	if (isi->pdata.full_mode)
 		cfg1 |= ISI_CFG1_FULL_MODE;
 
 	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
@@ -912,7 +912,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
 	if (IS_ERR(isi->pclk))
 		return PTR_ERR(isi->pclk);
 
-	isi->pdata = pdata;
+	memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
 	isi->active = NULL;
 	spin_lock_init(&isi->lock);
 	INIT_LIST_HEAD(&isi->video_buffer_list);
@@ -928,7 +928,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
 		/* Set ISI_MCK's frequency, it should be faster than pixel
 		 * clock.
 		 */
-		ret = clk_set_rate(isi->mck, pdata->mck_hz);
+		ret = clk_set_rate(isi->mck, isi->pdata.mck_hz);
 		if (ret < 0)
 			return ret;
 	}
@@ -962,9 +962,9 @@ static int atmel_isi_probe(struct platform_device *pdev)
 		goto err_ioremap;
 	}
 
-	if (pdata->data_width_flags & ISI_DATAWIDTH_8)
+	if (isi->pdata.data_width_flags & ISI_DATAWIDTH_8)
 		isi->width_flags = 1 << 7;
-	if (pdata->data_width_flags & ISI_DATAWIDTH_10)
+	if (isi->pdata.data_width_flags & ISI_DATAWIDTH_10)
 		isi->width_flags |= 1 << 9;
 
 	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v2 2/3 atmel-isi: convert the pdata from pointer to structure

Hi Josh,

I'm still waiting for an update of Ben's patches to then also apply yours, but I decided to have a look at yours now to see if I find anything, that might be worth changing. A small note to this one below.

Quoted 15 lines · Josh Wu

Now the platform data is initialized by allocation of isi structure. In the future, we use pdata to store the dt parameters.

---
v1 --> v2:
no change.

 drivers/media/platform/soc_camera/atmel-isi.c |   22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/media/platform/soc_camera/atmel-isi.c +0 -0
index 9d977c5..f4add0a 100644

[snip]

drivers/media/platform/soc_camera/atmel-isi.c static int atmel_isi_probe(struct platform_device *pdev) · line 915

Quoted 6 lines
drivers/media/platform/soc_camera/atmel-isi.c +1 -1
@@ -912,7 +912,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
 	if (IS_ERR(isi->pclk))
 		return PTR_ERR(isi->pclk);
 
-	isi->pdata = pdata;
+	memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));

I think it'd be better to use

+ memcpy(&isi->pdata, pdata, sizeof(isi->pdata));

This way if the type of the pdata changes at any time in the future this line will not have to be changed. If you don't mind I can make this change myself, so you don't have to make a new version just for this.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

author
#4 lore raw

PATCH v2 2/3 atmel-isi: convert the pdata from pointer to structure

Hi, Guennadi

Quoted 35 lines · Guennadi Liakhovetski

Hi Josh,

I'm still waiting for an update of Ben's patches to then also apply yours, but I decided to have a look at yours now to see if I find anything, that might be worth changing. A small note to this one below.

Quoted 15 lines · Josh Wu

Now the platform data is initialized by allocation of isi structure. In the future, we use pdata to store the dt parameters.

---
v1 --> v2:
no change.

  drivers/media/platform/soc_camera/atmel-isi.c |   22 +++++++++++-----------
  1 file changed, 11 insertions(+), 11 deletions(-)
drivers/media/platform/soc_camera/atmel-isi.c +0 -0
index 9d977c5..f4add0a 100644

[snip]

drivers/media/platform/soc_camera/atmel-isi.c static int atmel_isi_probe(struct platform_device *pdev) · line 915

Quoted 6 lines
drivers/media/platform/soc_camera/atmel-isi.c +1 -1
@@ -912,7 +912,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
  	if (IS_ERR(isi->pclk))
  		return PTR_ERR(isi->pclk);
 
-	isi->pdata = pdata;
+	memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));

I think it'd be better to use

(quoted diff) +1 -0
+	memcpy(&isi->pdata, pdata, sizeof(isi->pdata));
Quoted 3 lines

This way if the type of the pdata changes at any time in the future this line will not have to be changed. If you don't mind I can make this change myself, so you don't have to make a new version just for this.

Thanks for pointing it out. I think I will sent out a new version of patch (include bus-width parsing) then I will included with this fix.

Best Regards,
Josh Wu

Quoted 7 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

author
#5 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

In reply to Josh Wu

This patch add the DT support for Atmel ISI driver.
It use the same v4l2 DT interface that defined in video-interfaces.txt.

Cc devicetree at vger.kernel.org

---
v1 --> v2:
refine the binding document.
add port node description.
removed the optional property.

 .../devicetree/bindings/media/atmel-isi.txt        |   50 ++++++++++++++++++++
 drivers/media/platform/soc_camera/atmel-isi.c      |   31 +++++++++++-
 2 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isi.txt
Documentation/devicetree/bindings/media/atmel-isi.txt new file +50 -0
new file mode 100644
index 0000000..11c98ee
@@ -0,0 +1,50 @@
+Atmel Image Sensor Interface (ISI) SoC Camera Subsystem
+----------------------------------------------
+
+Required properties:
+- compatible: must be "atmel,at91sam9g45-isi"
+- reg: physical base address and length of the registers set for the device;
+- interrupts: should contain IRQ line for the ISI;
+- clocks: list of clock specifiers, corresponding to entries in
+          the clock-names property;
+- clock-names: must contain "isi_clk", which is the isi peripherial clock.
+
+ISI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+	isi: isi at f0034000 {
+		compatible = "atmel,at91sam9g45-isi";
+		reg = <0xf0034000 0x4000>;
+		interrupts = <37 IRQ_TYPE_LEVEL_HIGH 5>;
+
+		clocks = <&isi_clk>;
+		clock-names = "isi_clk";
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_isi>;
+
+		port {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			isi_0: endpoint {
+				remote-endpoint = <&ov2640_0>;
+			};
+		};
+	};
+
+	i2c1: i2c at f0018000 {
+		ov2640: camera at 0x30 {
+			compatible = "omnivision,ov2640";
+			reg = <0x30>;
+
+			port {
+				ov2640_0: endpoint {
+					remote-endpoint = <&isi_0>;
+					bus-width = <8>;
+				};
+			};
+		};
+	};
drivers/media/platform/soc_camera/atmel-isi.c +29 -2
index f4add0a..d6a1f7b 100644
@@ -19,6 +19,7 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
@@ -33,6 +34,7 @@
 #define VID_LIMIT_BYTES			(16 * 1024 * 1024)
 #define MIN_FRAME_RATE			15
 #define FRAME_INTERVAL_MILLI_SEC	(1000 / MIN_FRAME_RATE)
+#define ISI_DEFAULT_MCLK_FREQ		25000000
 
 /* Frame buffer descriptor */
 struct fbd {
@@ -885,6 +887,20 @@ static int atmel_isi_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int atmel_isi_probe_dt(struct atmel_isi *isi,
+			struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+
+	/* Default settings for ISI */
+	isi->pdata.full_mode = 1;
+	isi->pdata.mck_hz = ISI_DEFAULT_MCLK_FREQ;
+	isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL;
+	isi->pdata.data_width_flags = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10;
+
+	return 0;
+}
+
 static int atmel_isi_probe(struct platform_device *pdev)
 {
 	unsigned int irq;
@@ -896,7 +912,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
 	struct isi_platform_data *pdata;
 
 	pdata = dev->platform_data;
-	if (!pdata || !pdata->data_width_flags) {
+	if ((!pdata || !pdata->data_width_flags) && !pdev->dev.of_node) {
 		dev_err(&pdev->dev,
 			"No config available for Atmel ISI\n");
 		return -EINVAL;
@@ -912,7 +928,11 @@ static int atmel_isi_probe(struct platform_device *pdev)
 	if (IS_ERR(isi->pclk))
 		return PTR_ERR(isi->pclk);
 
-	memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	if (pdata)
+		memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	else	/* dt probe */
+		atmel_isi_probe_dt(isi, pdev);
+
 	isi->active = NULL;
 	spin_lock_init(&isi->lock);
 	INIT_LIST_HEAD(&isi->video_buffer_list);
@@ -1014,11 +1034,18 @@ err_alloc_ctx:
 	return ret;
 }
 
+static const struct of_device_id atmel_isi_of_match[] = {
+	{ .compatible = "atmel,at91sam9g45-isi" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, atmel_isi_of_match);
+
 static struct platform_driver atmel_isi_driver = {
 	.remove		= atmel_isi_remove,
 	.driver		= {
 		.name = "atmel_isi",
 		.owner = THIS_MODULE,
+		.of_match_table = atmel_isi_of_match,
 	},
 };
 
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

Hi Josh,

Thank you for the patch.

Quoted 5 lines · On Tuesday 25 March 2014 18:45:20 Josh Wu wrote:

This patch add the DT support for Atmel ISI driver.
It use the same v4l2 DT interface that defined in video-interfaces.txt.

Quoted 151 lines

---
v1 --> v2:
refine the binding document.
add port node description.
removed the optional property.

 .../devicetree/bindings/media/atmel-isi.txt        |   50 +++++++++++++++++
 drivers/media/platform/soc_camera/atmel-isi.c      |   31 +++++++++++-
 2 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isi.txt
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/media/atmel-isi.txt new file mode 100644
index 0000000..11c98ee

Documentation/devicetree/bindings/media/atmel-isi.txt new file +6 -0
@@ -0,0 +1,50 @@
+Atmel Image Sensor Interface (ISI) SoC Camera Subsystem
+----------------------------------------------
+
+Required properties:
+- compatible: must be "atmel,at91sam9g45-isi"
+- reg: physical base address and length of the registers set for the

device;

+- interrupts: should contain IRQ line for the ISI;
+- clocks: list of clock specifiers, corresponding to entries in
Documentation/devicetree/bindings/media/atmel-isi.txt new file +42 -0
+          the clock-names property;
+- clock-names: must contain "isi_clk", which is the isi peripherial clock.
+
+ISI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+	isi: isi@f0034000 {
+		compatible = "atmel,at91sam9g45-isi";
+		reg = <0xf0034000 0x4000>;
+		interrupts = <37 IRQ_TYPE_LEVEL_HIGH 5>;
+
+		clocks = <&isi_clk>;
+		clock-names = "isi_clk";
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_isi>;
+
+		port {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			isi_0: endpoint {
+				remote-endpoint = <&ov2640_0>;
+			};
+		};
+	};
+
+	i2c1: i2c@f0018000 {
+		ov2640: camera@0x30 {
+			compatible = "omnivision,ov2640";
+			reg = <0x30>;
+
+			port {
+				ov2640_0: endpoint {
+					remote-endpoint = <&isi_0>;
+					bus-width = <8>;
+				};
+			};
+		};
+	};
(quoted diff) +0 -0

b/drivers/media/platform/soc_camera/atmel-isi.c index f4add0a..d6a1f7b 100644

drivers/media/platform/soc_camera/atmel-isi.c +29 -2
@@ -19,6 +19,7 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
@@ -33,6 +34,7 @@
 #define VID_LIMIT_BYTES			(16 * 1024 * 1024)
 #define MIN_FRAME_RATE			15
 #define FRAME_INTERVAL_MILLI_SEC	(1000 / MIN_FRAME_RATE)
+#define ISI_DEFAULT_MCLK_FREQ		25000000
 
 /* Frame buffer descriptor */
 struct fbd {
@@ -885,6 +887,20 @@ static int atmel_isi_remove(struct platform_device
 *pdev) return 0;
 }
 
+static int atmel_isi_probe_dt(struct atmel_isi *isi,
+			struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+
+	/* Default settings for ISI */
+	isi->pdata.full_mode = 1;
+	isi->pdata.mck_hz = ISI_DEFAULT_MCLK_FREQ;
+	isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL;
+	isi->pdata.data_width_flags = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10;
+
+	return 0;
+}
+
 static int atmel_isi_probe(struct platform_device *pdev)
 {
 	unsigned int irq;
@@ -896,7 +912,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
 struct isi_platform_data *pdata;
 
 	pdata = dev->platform_data;
-	if (!pdata || !pdata->data_width_flags) {
+	if ((!pdata || !pdata->data_width_flags) && !pdev->dev.of_node) {
 		dev_err(&pdev->dev,
 			"No config available for Atmel ISI\n");
 		return -EINVAL;
@@ -912,7 +928,11 @@ static int atmel_isi_probe(struct platform_device
 *pdev) if (IS_ERR(isi->pclk))
 		return PTR_ERR(isi->pclk);
 
-	memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	if (pdata)
+		memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	else	/* dt probe */
+		atmel_isi_probe_dt(isi, pdev);
+
 	isi->active = NULL;
 	spin_lock_init(&isi->lock);
 	INIT_LIST_HEAD(&isi->video_buffer_list);
@@ -1014,11 +1034,18 @@ err_alloc_ctx:
 	return ret;
 }
 
+static const struct of_device_id atmel_isi_of_match[] = {
+	{ .compatible = "atmel,at91sam9g45-isi" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, atmel_isi_of_match);
+
 static struct platform_driver atmel_isi_driver = {
 	.remove		= atmel_isi_remove,
 	.driver		= {
 		.name = "atmel_isi",
 		.owner = THIS_MODULE,
+		.of_match_table = atmel_isi_of_match,
 	},
 };
Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

In reply to Josh Wu

Hi Josh,

Please correct me if I'm wrong, but I don't see how this is going to work without the central part - building asynchronous V4L2 data structures from the DT, something that your earlier patch "media: soc-camera: OF cameras" was doing, but which you stopped developing after a discussion with Ben (added to Cc).

Thanks
Guennadi

Quoted 157 lines · Josh Wu

This patch add the DT support for Atmel ISI driver.
It use the same v4l2 DT interface that defined in video-interfaces.txt.

Cc devicetree at vger.kernel.org

---
v1 --> v2:
refine the binding document.
add port node description.
removed the optional property.

 .../devicetree/bindings/media/atmel-isi.txt        |   50 ++++++++++++++++++++
 drivers/media/platform/soc_camera/atmel-isi.c      |   31 +++++++++++-
 2 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isi.txt
Documentation/devicetree/bindings/media/atmel-isi.txt new file +50 -0
new file mode 100644
index 0000000..11c98ee
@@ -0,0 +1,50 @@
+Atmel Image Sensor Interface (ISI) SoC Camera Subsystem
+----------------------------------------------
+
+Required properties:
+- compatible: must be "atmel,at91sam9g45-isi"
+- reg: physical base address and length of the registers set for the device;
+- interrupts: should contain IRQ line for the ISI;
+- clocks: list of clock specifiers, corresponding to entries in
+          the clock-names property;
+- clock-names: must contain "isi_clk", which is the isi peripherial clock.
+
+ISI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+	isi: isi at f0034000 {
+		compatible = "atmel,at91sam9g45-isi";
+		reg = <0xf0034000 0x4000>;
+		interrupts = <37 IRQ_TYPE_LEVEL_HIGH 5>;
+
+		clocks = <&isi_clk>;
+		clock-names = "isi_clk";
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_isi>;
+
+		port {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			isi_0: endpoint {
+				remote-endpoint = <&ov2640_0>;
+			};
+		};
+	};
+
+	i2c1: i2c at f0018000 {
+		ov2640: camera at 0x30 {
+			compatible = "omnivision,ov2640";
+			reg = <0x30>;
+
+			port {
+				ov2640_0: endpoint {
+					remote-endpoint = <&isi_0>;
+					bus-width = <8>;
+				};
+			};
+		};
+	};
drivers/media/platform/soc_camera/atmel-isi.c +29 -2
index f4add0a..d6a1f7b 100644
@@ -19,6 +19,7 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
@@ -33,6 +34,7 @@
 #define VID_LIMIT_BYTES			(16 * 1024 * 1024)
 #define MIN_FRAME_RATE			15
 #define FRAME_INTERVAL_MILLI_SEC	(1000 / MIN_FRAME_RATE)
+#define ISI_DEFAULT_MCLK_FREQ		25000000
 
 /* Frame buffer descriptor */
 struct fbd {
@@ -885,6 +887,20 @@ static int atmel_isi_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int atmel_isi_probe_dt(struct atmel_isi *isi,
+			struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+
+	/* Default settings for ISI */
+	isi->pdata.full_mode = 1;
+	isi->pdata.mck_hz = ISI_DEFAULT_MCLK_FREQ;
+	isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL;
+	isi->pdata.data_width_flags = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10;
+
+	return 0;
+}
+
 static int atmel_isi_probe(struct platform_device *pdev)
 {
 	unsigned int irq;
@@ -896,7 +912,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
 	struct isi_platform_data *pdata;
 
 	pdata = dev->platform_data;
-	if (!pdata || !pdata->data_width_flags) {
+	if ((!pdata || !pdata->data_width_flags) && !pdev->dev.of_node) {
 		dev_err(&pdev->dev,
 			"No config available for Atmel ISI\n");
 		return -EINVAL;
@@ -912,7 +928,11 @@ static int atmel_isi_probe(struct platform_device *pdev)
 	if (IS_ERR(isi->pclk))
 		return PTR_ERR(isi->pclk);
 
-	memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	if (pdata)
+		memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	else	/* dt probe */
+		atmel_isi_probe_dt(isi, pdev);
+
 	isi->active = NULL;
 	spin_lock_init(&isi->lock);
 	INIT_LIST_HEAD(&isi->video_buffer_list);
@@ -1014,11 +1034,18 @@ err_alloc_ctx:
 	return ret;
 }
 
+static const struct of_device_id atmel_isi_of_match[] = {
+	{ .compatible = "atmel,at91sam9g45-isi" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, atmel_isi_of_match);
+
 static struct platform_driver atmel_isi_driver = {
 	.remove		= atmel_isi_remove,
 	.driver		= {
 		.name = "atmel_isi",
 		.owner = THIS_MODULE,
+		.of_match_table = atmel_isi_of_match,
 	},
 };
 
Signature · 1 line
1.7.9.5

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

author
#8 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

Dear Guennadi

Quoted 5 lines · Guennadi Liakhovetski

Hi Josh,

Please correct me if I'm wrong, but I don't see how this is going to work without the central part - building asynchronous V4L2 data structures from the DT, something that your earlier patch

Here you mean Bryan Wu not me, right? ;-)
Bryan write the patch "[v2] media: soc-camera: OF cameras" in:
https://patchwork.linuxtv.org/patch/22288/.
And I saw Ben Dooks already sent out his patch to support soc-camera OF now (https://patchwork.linuxtv.org/patch/23304/) which is simpler than Bryan's.

Quoted 3 lines

"media: soc-camera: OF cameras"
was doing, but which you stopped developing after a discussion with Ben (added to Cc).

And yes, atmel-isi dt patch should not work without above SoC-Camera of support patch.
But as the atmel-isi dt binding document and port node can be finalized. So I think this patch is ready for the mainline.

BTW: I will test Ben's patch with atmel-isi.

thanks and best regards,
Josh Wu

Quoted 167 lines

Thanks
Guennadi

Quoted 157 lines · Josh Wu

This patch add the DT support for Atmel ISI driver.
It use the same v4l2 DT interface that defined in video-interfaces.txt.

Cc devicetree at vger.kernel.org

---
v1 --> v2:
refine the binding document.
add port node description.
removed the optional property.

  .../devicetree/bindings/media/atmel-isi.txt        |   50 ++++++++++++++++++++
  drivers/media/platform/soc_camera/atmel-isi.c      |   31 +++++++++++-
  2 files changed, 79 insertions(+), 2 deletions(-)

create mode 100644 Documentation/devicetree/bindings/media/atmel-isi.txt

Documentation/devicetree/bindings/media/atmel-isi.txt new file +50 -0
new file mode 100644
index 0000000..11c98ee
@@ -0,0 +1,50 @@
+Atmel Image Sensor Interface (ISI) SoC Camera Subsystem
+----------------------------------------------
+
+Required properties:
+- compatible: must be "atmel,at91sam9g45-isi"
+- reg: physical base address and length of the registers set for the device;
+- interrupts: should contain IRQ line for the ISI;
+- clocks: list of clock specifiers, corresponding to entries in
+          the clock-names property;
+- clock-names: must contain "isi_clk", which is the isi peripherial clock.
+
+ISI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+	isi: isi at f0034000 {
+		compatible = "atmel,at91sam9g45-isi";
+		reg = <0xf0034000 0x4000>;
+		interrupts = <37 IRQ_TYPE_LEVEL_HIGH 5>;
+
+		clocks = <&isi_clk>;
+		clock-names = "isi_clk";
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_isi>;
+
+		port {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			isi_0: endpoint {
+				remote-endpoint = <&ov2640_0>;
+			};
+		};
+	};
+
+	i2c1: i2c at f0018000 {
+		ov2640: camera at 0x30 {
+			compatible = "omnivision,ov2640";
+			reg = <0x30>;
+
+			port {
+				ov2640_0: endpoint {
+					remote-endpoint = <&isi_0>;
+					bus-width = <8>;
+				};
+			};
+		};
+	};
drivers/media/platform/soc_camera/atmel-isi.c +29 -2
index f4add0a..d6a1f7b 100644
@@ -19,6 +19,7 @@
  #include <linux/interrupt.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
+#include <linux/of.h>
  #include <linux/platform_device.h>
  #include <linux/slab.h>
 
@@ -33,6 +34,7 @@
  #define VID_LIMIT_BYTES			(16 * 1024 * 1024)
  #define MIN_FRAME_RATE			15
  #define FRAME_INTERVAL_MILLI_SEC	(1000 / MIN_FRAME_RATE)
+#define ISI_DEFAULT_MCLK_FREQ		25000000
 
  /* Frame buffer descriptor */
  struct fbd {
@@ -885,6 +887,20 @@ static int atmel_isi_remove(struct platform_device *pdev)
  	return 0;
  }
 
+static int atmel_isi_probe_dt(struct atmel_isi *isi,
+			struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+
+	/* Default settings for ISI */
+	isi->pdata.full_mode = 1;
+	isi->pdata.mck_hz = ISI_DEFAULT_MCLK_FREQ;
+	isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL;
+	isi->pdata.data_width_flags = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10;
+
+	return 0;
+}
+
  static int atmel_isi_probe(struct platform_device *pdev)
  {
  	unsigned int irq;
@@ -896,7 +912,7 @@ static int atmel_isi_probe(struct platform_device *pdev)
  	struct isi_platform_data *pdata;
 
  	pdata = dev->platform_data;
-	if (!pdata || !pdata->data_width_flags) {
+	if ((!pdata || !pdata->data_width_flags) && !pdev->dev.of_node) {
  		dev_err(&pdev->dev,
  			"No config available for Atmel ISI\n");
  		return -EINVAL;
@@ -912,7 +928,11 @@ static int atmel_isi_probe(struct platform_device *pdev)
  	if (IS_ERR(isi->pclk))
  		return PTR_ERR(isi->pclk);
 
-	memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	if (pdata)
+		memcpy(&isi->pdata, pdata, sizeof(struct isi_platform_data));
+	else	/* dt probe */
+		atmel_isi_probe_dt(isi, pdev);
+
  	isi->active = NULL;
  	spin_lock_init(&isi->lock);
  	INIT_LIST_HEAD(&isi->video_buffer_list);
@@ -1014,11 +1034,18 @@ err_alloc_ctx:
  	return ret;
  }
 
+static const struct of_device_id atmel_isi_of_match[] = {
+	{ .compatible = "atmel,at91sam9g45-isi" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, atmel_isi_of_match);
+
  static struct platform_driver atmel_isi_driver = {
  	.remove		= atmel_isi_remove,
  	.driver		= {
  		.name = "atmel_isi",
  		.owner = THIS_MODULE,
+		.of_match_table = atmel_isi_of_match,
  	},
  };
 
Signature · 1 line
1.7.9.5

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#9 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

Hi Josh,

What's the status of this patch set ? Do you plan to rebase and resubmit it ?

Quoted 26 lines · On Monday 31 March 2014 17:05:13 Josh Wu wrote:

Dear Guennadi

Quoted 5 lines · Guennadi Liakhovetski

Hi Josh,

Please correct me if I'm wrong, but I don't see how this is going to work without the central part - building asynchronous V4L2 data structures from the DT, something that your earlier patch

Here you mean Bryan Wu not me, right? ;-)
Bryan write the patch "[v2] media: soc-camera: OF cameras" in:
https://patchwork.linuxtv.org/patch/22288/.
And I saw Ben Dooks already sent out his patch to support soc-camera OF now (https://patchwork.linuxtv.org/patch/23304/) which is simpler than Bryan's.

Quoted 3 lines

"media: soc-camera: OF cameras"
was doing, but which you stopped developing after a discussion with Ben (added to Cc).

And yes, atmel-isi dt patch should not work without above SoC-Camera of support patch.
But as the atmel-isi dt binding document and port node can be finalized. So I think this patch is ready for the mainline.

BTW: I will test Ben's patch with atmel-isi.

Signature · 3 lines
Regards,

Laurent Pinchart
author
#10 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

Dear Laurent

Quoted 3 lines · Laurent Pinchart

Hi Josh,

What's the status of this patch set ? Do you plan to rebase and resubmit it ?

Thanks for the reminding.
yes, I will rebase it and resubmit the new version for this patch set with the data bus width support.
Thanks.

Best Regards,
Josh Wu

Quoted 26 lines · On Monday 31 March 2014 17:05:13 Josh Wu wrote:
Quoted 24 lines

Dear Guennadi

Quoted 5 lines · Guennadi Liakhovetski

Hi Josh,

Please correct me if I'm wrong, but I don't see how this is going to work without the central part - building asynchronous V4L2 data structures from the DT, something that your earlier patch

Here you mean Bryan Wu not me, right? ;-)
Bryan write the patch "[v2] media: soc-camera: OF cameras" in:
https://patchwork.linuxtv.org/patch/22288/.
And I saw Ben Dooks already sent out his patch to support soc-camera OF now (https://patchwork.linuxtv.org/patch/23304/) which is simpler than Bryan's.

Quoted 3 lines

"media: soc-camera: OF cameras"
was doing, but which you stopped developing after a discussion with Ben (added to Cc).

And yes, atmel-isi dt patch should not work without above SoC-Camera of support patch.
But as the atmel-isi dt binding document and port node can be finalized. So I think this patch is ready for the mainline.

BTW: I will test Ben's patch with atmel-isi.

#11 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

In reply to Josh Wu
Quoted 15 lines · Josh Wu

This patch add the DT support for Atmel ISI driver.
It use the same v4l2 DT interface that defined in video-interfaces.txt.

Cc devicetree at vger.kernel.org

---
v1 --> v2:
refine the binding document.
add port node description.
removed the optional property.

 .../devicetree/bindings/media/atmel-isi.txt        |   50 ++++++++++++++++++++
 drivers/media/platform/soc_camera/atmel-isi.c      |   31 +++++++++++-
 2 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isi.txt

[snip]

Quoted 4 lines
drivers/media/platform/soc_camera/atmel-isi.c +0 -0
index f4add0a..d6a1f7b 100644

[snip]

drivers/media/platform/soc_camera/atmel-isi.c static int atmel_isi_remove(struct platform_device *pdev) · line 898

Quoted 13 lines
drivers/media/platform/soc_camera/atmel-isi.c +9 -0
@@ -885,6 +887,20 @@ static int atmel_isi_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int atmel_isi_probe_dt(struct atmel_isi *isi,
+			struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+
+	/* Default settings for ISI */
+	isi->pdata.full_mode = 1;
+	isi->pdata.mck_hz = ISI_DEFAULT_MCLK_FREQ;
+	isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL;

The above flags eventually should probably partially be added as new driver-specific DT properties, partially derived from DT clock bindings. But I'm ok to have them fixed like this in the initial version.

drivers/media/platform/soc_camera/atmel-isi.c static int atmel_isi_remove(struct platform_device *pdev) · line 899

Quoted 1 line
drivers/media/platform/soc_camera/atmel-isi.c +1 -0
+	isi->pdata.data_width_flags = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10;

Whereas these flags, I think, should already now be derived from the bus-width standard property? v4l2_of_parse_parallel_bus() will extract them for you and I just asked Ben to add a call to v4l2_of_parse_endpoint() to his patch. Consequently you'll have to rearrange bus-width interpretation in isi_camera_try_bus_param() a bit and use OF parsing results there directly if available? Or maybe you find a better way. It would certainly be better to extend your probing code and just use OF results to initialise isi->width_flags, but that might be impossible, because OF parsing would be performed inside soc_camera_host_register() and your isi_camera_try_bus_param() can also be called immediately from it if all required I2C devices are already available? If your I2C subdevice drivers defer probing until the host has probed, then you could initialise .width_flags after soc_camera_host_register(), but you cannot rely on that.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

author
#12 lore raw

PATCH v2 3/3 atmel-isi: add primary DT support

Hi, Guennadi

Quoted 42 lines · Guennadi Liakhovetski
Quoted 15 lines · Josh Wu

This patch add the DT support for Atmel ISI driver.
It use the same v4l2 DT interface that defined in video-interfaces.txt.

Cc devicetree at vger.kernel.org

---
v1 --> v2:
refine the binding document.
add port node description.
removed the optional property.

  .../devicetree/bindings/media/atmel-isi.txt        |   50 ++++++++++++++++++++
  drivers/media/platform/soc_camera/atmel-isi.c      |   31 +++++++++++-
  2 files changed, 79 insertions(+), 2 deletions(-)

create mode 100644 Documentation/devicetree/bindings/media/atmel-isi.txt

[snip]

Quoted 4 lines
drivers/media/platform/soc_camera/atmel-isi.c +0 -0
index f4add0a..d6a1f7b 100644

[snip]

drivers/media/platform/soc_camera/atmel-isi.c static int atmel_isi_remove(struct platform_device *pdev) · line 898

Quoted 13 lines
drivers/media/platform/soc_camera/atmel-isi.c +9 -0
@@ -885,6 +887,20 @@ static int atmel_isi_remove(struct platform_device *pdev)
  	return 0;
  }
 
+static int atmel_isi_probe_dt(struct atmel_isi *isi,
+			struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+
+	/* Default settings for ISI */
+	isi->pdata.full_mode = 1;
+	isi->pdata.mck_hz = ISI_DEFAULT_MCLK_FREQ;
+	isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL;

The above flags eventually should probably partially be added as new driver-specific DT properties, partially derived from DT clock bindings. But I'm ok to have them fixed like this in the initial version.

Quoted 3 lines

drivers/media/platform/soc_camera/atmel-isi.c static int atmel_isi_remove(struct platform_device *pdev) · line 899

Quoted 1 line
drivers/media/platform/soc_camera/atmel-isi.c +1 -0
+	isi->pdata.data_width_flags = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10;

Whereas these flags, I think, should already now be derived from the bus-width standard property?

yes. I agree.

Quoted 3 lines

v4l2_of_parse_parallel_bus() will extract them for you and I just asked Ben to add a call to v4l2_of_parse_endpoint() to his patch.

Is it better to call v4l2_of_parse_endpoint() in the atmel-isi driver? I think the dt parsing stuff should be done by host driver and sensor driver itself. No need to call v4l2_of_parse_endpoint() in soc-camera.c.

Quoted 9 lines

Consequently you'll have to
rearrange bus-width interpretation in isi_camera_try_bus_param() a bit and use OF parsing results there directly if available? Or maybe you find a better way. It would certainly be better to extend your probing code and just use OF results to initialise isi->width_flags, but that might be impossible, because OF parsing would be performed inside soc_camera_host_register() and your isi_camera_try_bus_param() can also be called immediately from it if all required I2C devices are already available?

I am little bit confuse here. I don't see any issue in above case. Since atmel_isi_probe_dt() will always be called earlier then soc_camera_host_register().
That means when soc_camera_host_register() called isi_camera_try_bus_param(), the isi->width_flags are already initialized in a valid value by atmel_isi_probe_dt().
Am I missing anything here?

Quoted 3 lines

If your I2C subdevice drivers defer probing until the host has probed, then you could initialise .width_flags after soc_camera_host_register(), but you cannot rely on that.

I tested these two cases without any issue:
1. In dtb, the i2c sensor dt node probe earlier than atmel-isi dt node. i2c sensor will do a defer probe here as mclk is not found until
atmel-isi driver probed and call soc_camera_host_register().
2. In dtb, the atmel-isi dt node is probed earlier than i2c sensor.

Best Regards,
Josh Wu

Quoted 11 lines

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html