[v2,3/3,media] atmel-isi: add primary DT support

Message ID 1395744320-15025-1-git-send-email-josh.wu@atmel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Josh Wu March 25, 2014, 10:45 a.m. UTC
  This patch add the DT support for Atmel ISI driver.
It use the same v4l2 DT interface that defined in video-interfaces.txt.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Cc: devicetree@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
  

Comments

Laurent Pinchart March 26, 2014, 4:12 p.m. UTC | #1
Hi Josh,

Thank you for the patch.

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.
> 
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
> Cc: devicetree@vger.kernel.org

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> 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
> 
> diff --git a/Documentation/devicetree/bindings/media/atmel-isi.txt
> b/Documentation/devicetree/bindings/media/atmel-isi.txt new file mode
> 100644
> index 0000000..11c98ee
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/atmel-isi.txt
> @@ -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@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>;
> +				};
> +			};
> +		};
> +	};
> diff --git a/drivers/media/platform/soc_camera/atmel-isi.c
> b/drivers/media/platform/soc_camera/atmel-isi.c index f4add0a..d6a1f7b
> 100644
> --- a/drivers/media/platform/soc_camera/atmel-isi.c
> +++ b/drivers/media/platform/soc_camera/atmel-isi.c
> @@ -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,
>  	},
>  };
  
Guennadi Liakhovetski March 30, 2014, 9:20 p.m. UTC | #2
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

On Tue, 25 Mar 2014, 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.
> 
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
> Cc: devicetree@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
> 
> diff --git a/Documentation/devicetree/bindings/media/atmel-isi.txt b/Documentation/devicetree/bindings/media/atmel-isi.txt
> new file mode 100644
> index 0000000..11c98ee
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/atmel-isi.txt
> @@ -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@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>;
> +				};
> +			};
> +		};
> +	};
> diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
> index f4add0a..d6a1f7b 100644
> --- a/drivers/media/platform/soc_camera/atmel-isi.c
> +++ b/drivers/media/platform/soc_camera/atmel-isi.c
> @@ -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,
>  	},
>  };
>  
> -- 
> 1.7.9.5
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  
Josh Wu March 31, 2014, 9:05 a.m. UTC | #3
Dear Guennadi

On 3/31/2014 5:20 AM, Guennadi Liakhovetski wrote:
> 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.

> "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

>
> Thanks
> Guennadi
>
> On Tue, 25 Mar 2014, 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.
>>
>> Signed-off-by: Josh Wu <josh.wu@atmel.com>
>> Cc: devicetree@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
>>
>> diff --git a/Documentation/devicetree/bindings/media/atmel-isi.txt b/Documentation/devicetree/bindings/media/atmel-isi.txt
>> new file mode 100644
>> index 0000000..11c98ee
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/media/atmel-isi.txt
>> @@ -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@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>;
>> +				};
>> +			};
>> +		};
>> +	};
>> diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
>> index f4add0a..d6a1f7b 100644
>> --- a/drivers/media/platform/soc_camera/atmel-isi.c
>> +++ b/drivers/media/platform/soc_camera/atmel-isi.c
>> @@ -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,
>>   	},
>>   };
>>   
>> -- 
>> 1.7.9.5
>>
> ---
> Guennadi Liakhovetski, Ph.D.
> Freelance Open-Source Software Developer
> http://www.open-technology.de/

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  
Guennadi Liakhovetski May 18, 2014, 9:51 p.m. UTC | #4
On Tue, 25 Mar 2014, 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.
> 
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
> Cc: devicetree@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]

> diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
> index f4add0a..d6a1f7b 100644
> --- a/drivers/media/platform/soc_camera/atmel-isi.c
> +++ b/drivers/media/platform/soc_camera/atmel-isi.c

[snip]

> @@ -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.

> +	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/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  
Josh Wu May 23, 2014, 3:12 a.m. UTC | #5
Hi, Guennadi

On 5/19/2014 5:51 AM, Guennadi Liakhovetski wrote:
> On Tue, 25 Mar 2014, 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.
>>
>> Signed-off-by: Josh Wu <josh.wu@atmel.com>
>> Cc: devicetree@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]
>
>> diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
>> index f4add0a..d6a1f7b 100644
>> --- a/drivers/media/platform/soc_camera/atmel-isi.c
>> +++ b/drivers/media/platform/soc_camera/atmel-isi.c
> [snip]
>
>> @@ -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.
>
>> +	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.

> 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.

> 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?

> 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

>
> 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@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  
Laurent Pinchart July 17, 2014, 11 a.m. UTC | #6
Hi Josh,

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

On Monday 31 March 2014 17:05:13 Josh Wu wrote:
> Dear Guennadi
> 
> On 3/31/2014 5:20 AM, Guennadi Liakhovetski wrote:
> > 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.
> 
> > "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.
  
Josh Wu July 18, 2014, 3:15 a.m. UTC | #7
Dear Laurent

On 7/17/2014 7:00 PM, Laurent Pinchart wrote:
> 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
>
> On Monday 31 March 2014 17:05:13 Josh Wu wrote:
>> Dear Guennadi
>>
>> On 3/31/2014 5:20 AM, Guennadi Liakhovetski wrote:
>>> 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.
>>
>>> "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.

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Patch

diff --git a/Documentation/devicetree/bindings/media/atmel-isi.txt b/Documentation/devicetree/bindings/media/atmel-isi.txt
new file mode 100644
index 0000000..11c98ee
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/atmel-isi.txt
@@ -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@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>;
+				};
+			};
+		};
+	};
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index f4add0a..d6a1f7b 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -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,
 	},
 };