diff mbox

[2/2] rtc: mxc: add support of device tree

Message ID 1431729330-7625-3-git-send-email-tremyfr@gmail.com
State Superseded
Headers show

Commit Message

Philippe Reynes May 15, 2015, 10:35 p.m. UTC
Signed-off-by: Philippe Reynes <tremyfr@gmail.com>
---
 Documentation/devicetree/bindings/rtc/rtc-mxc.txt |   27 +++++++++++++++++++++
 drivers/rtc/rtc-mxc.c                             |   22 ++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mxc.txt

Comments

Alexandre Belloni May 28, 2015, 12:06 p.m. UTC | #1
Hi,

On 16/05/2015 at 00:35:30 +0200, Philippe Reynes wrote :
> 

Please always include a commit message.

> Signed-off-by: Philippe Reynes <tremyfr@gmail.com>
> ---
>  Documentation/devicetree/bindings/rtc/rtc-mxc.txt |   27 +++++++++++++++++++++
>  drivers/rtc/rtc-mxc.c                             |   22 ++++++++++++++++-
>  2 files changed, 48 insertions(+), 1 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mxc.txt
> 
> diff --git a/Documentation/devicetree/bindings/rtc/rtc-mxc.txt b/Documentation/devicetree/bindings/rtc/rtc-mxc.txt
> new file mode 100644
> index 0000000..5505493
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/rtc-mxc.txt
> @@ -0,0 +1,27 @@
> +* Real Time Clock of the i.MX SoCs
> +
> +RTC controller for the i.MX SoCs
> +
> +Required properties:
> +- compatible: Should be "fsl,imx1-rtc" or "fsl,imx21-rtc".
> +- reg: physical base address of the controller and length of memory mapped
> +  region.
> +- interrupts: IRQ line for the RTC.
> +- clocks: should contain two entries:
> +  * one for the input reference
> +  * one for the the SoC RTC
> +- clock-names: should contain:
> +  * "rtc" for the input reference clock
> +  * "ipg" for the SoC RTC clock
> +
> +Example:
> +
> +rtc@10007000 {
> +	compatible = "fsl,imx21-rtc";
> +	reg = <0x10007000 0x1000>;
> +	interrupts = <22>;
> +	clocks = <&clks IMX27_CLK_CKIL>,
> +	       	 <&clks IMX27_CLK_RTC_IPG_GATE>;
> +	clock-names = "rtc, "ipg";
> +	status = "disabled";
> +};
> diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
> index e916a91..df6483d 100644
> --- a/drivers/rtc/rtc-mxc.c
> +++ b/drivers/rtc/rtc-mxc.c
> @@ -16,6 +16,8 @@
>  #include <linux/interrupt.h>
>  #include <linux/platform_device.h>
>  #include <linux/clk.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
>  
>  #define RTC_INPUT_CLK_32768HZ	(0x00 << 5)
>  #define RTC_INPUT_CLK_32000HZ	(0x01 << 5)
> @@ -98,6 +100,15 @@ static struct platform_device_id imx_rtc_devtype[] = {
>  };
>  MODULE_DEVICE_TABLE(platform, imx_rtc_devtype);
>  
> +#ifdef CONFIG_OF
> +static const struct of_device_id imx_rtc_dt_ids[] = {
> +	{ .compatible = "fsl,imx1-rtc", .data = &imx_rtc_devtype[IMX1_RTC] },
> +	{ .compatible = "fsl,imx21-rtc", .data = &imx_rtc_devtype[IMX21_RTC] },

Maybe you can use directly IMX1_RTC and IMX21_RTC which...


>  
> -	pdata->devtype = pdev->id_entry->driver_data;
> +	of_id = of_match_device(imx_rtc_dt_ids, &pdev->dev);
> +	if (of_id) {
> +		struct platform_device_id *id_entry;
> +
> +		id_entry = (struct platform_device_id *)of_id->data;
> +		pdata->devtype = id_entry->driver_data;

... also simplifies that part.

> +	} else
> +		pdata->devtype = pdev->id_entry->driver_data;
>
Philippe Reynes June 4, 2015, 9:26 p.m. UTC | #2
Hi Alexandre,


On 28/05/15 14:06, Alexandre Belloni wrote:
> Hi,
>
> On 16/05/2015 at 00:35:30 +0200, Philippe Reynes wrote :
>>
>
> Please always include a commit message.

Oh yes, sorry about that.

>> Signed-off-by: Philippe Reynes<tremyfr@gmail.com>
>> ---
>>   Documentation/devicetree/bindings/rtc/rtc-mxc.txt |   27 +++++++++++++++++++++
>>   drivers/rtc/rtc-mxc.c                             |   22 ++++++++++++++++-
>>   2 files changed, 48 insertions(+), 1 deletions(-)
>>   create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mxc.txt
>>
>> diff --git a/Documentation/devicetree/bindings/rtc/rtc-mxc.txt b/Documentation/devicetree/bindings/rtc/rtc-mxc.txt
>> new file mode 100644
>> index 0000000..5505493
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/rtc/rtc-mxc.txt
>> @@ -0,0 +1,27 @@
>> +* Real Time Clock of the i.MX SoCs
>> +
>> +RTC controller for the i.MX SoCs
>> +
>> +Required properties:
>> +- compatible: Should be "fsl,imx1-rtc" or "fsl,imx21-rtc".
>> +- reg: physical base address of the controller and length of memory mapped
>> +  region.
>> +- interrupts: IRQ line for the RTC.
>> +- clocks: should contain two entries:
>> +  * one for the input reference
>> +  * one for the the SoC RTC
>> +- clock-names: should contain:
>> +  * "rtc" for the input reference clock
>> +  * "ipg" for the SoC RTC clock
>> +
>> +Example:
>> +
>> +rtc@10007000 {
>> +	compatible = "fsl,imx21-rtc";
>> +	reg =<0x10007000 0x1000>;
>> +	interrupts =<22>;
>> +	clocks =<&clks IMX27_CLK_CKIL>,
>> +	       	<&clks IMX27_CLK_RTC_IPG_GATE>;
>> +	clock-names = "rtc, "ipg";
>> +	status = "disabled";
>> +};
>> diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
>> index e916a91..df6483d 100644
>> --- a/drivers/rtc/rtc-mxc.c
>> +++ b/drivers/rtc/rtc-mxc.c
>> @@ -16,6 +16,8 @@
>>   #include<linux/interrupt.h>
>>   #include<linux/platform_device.h>
>>   #include<linux/clk.h>
>> +#include<linux/of.h>
>> +#include<linux/of_device.h>
>>
>>   #define RTC_INPUT_CLK_32768HZ	(0x00<<  5)
>>   #define RTC_INPUT_CLK_32000HZ	(0x01<<  5)
>> @@ -98,6 +100,15 @@ static struct platform_device_id imx_rtc_devtype[] = {
>>   };
>>   MODULE_DEVICE_TABLE(platform, imx_rtc_devtype);
>>
>> +#ifdef CONFIG_OF
>> +static const struct of_device_id imx_rtc_dt_ids[] = {
>> +	{ .compatible = "fsl,imx1-rtc", .data =&imx_rtc_devtype[IMX1_RTC] },
>> +	{ .compatible = "fsl,imx21-rtc", .data =&imx_rtc_devtype[IMX21_RTC] },
>
> Maybe you can use directly IMX1_RTC and IMX21_RTC which...

I've seen both "style" on the code. I may change the code to simply use IMX1_RTC
and IMX21_RTC.

>>
>> -	pdata->devtype = pdev->id_entry->driver_data;
>> +	of_id = of_match_device(imx_rtc_dt_ids,&pdev->dev);
>> +	if (of_id) {
>> +		struct platform_device_id *id_entry;
>> +
>> +		id_entry = (struct platform_device_id *)of_id->data;
>> +		pdata->devtype = id_entry->driver_data;
>
> ... also simplifies that part.

I'll do it in the next version of this patch.
  
>> +	} else
>> +		pdata->devtype = pdev->id_entry->driver_data;
>>
>

Do you prefer that I wait the clock driver has move to drivers/clk/imx
(as requested by Shawn) before sending a v2 ?

Regards,
Philippe
Alexandre Belloni June 4, 2015, 10:22 p.m. UTC | #3
On 04/06/2015 at 23:26:05 +0200, Philippe Reynes wrote :
> I'll do it in the next version of this patch.
> >>+	} else
> >>+		pdata->devtype = pdev->id_entry->driver_data;
> >>
> >
> 
> Do you prefer that I wait the clock driver has move to drivers/clk/imx
> (as requested by Shawn) before sending a v2 ?
> 

It would have been good to get the clock change in 4.2 but it is already
late in the cycle now so I'm not sure it can go in. That would have
removed the dependency.

The other solution is to merge everything through Shawn's tree.

Anyway, you can send the patches, we'll handle that part :)
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/rtc/rtc-mxc.txt b/Documentation/devicetree/bindings/rtc/rtc-mxc.txt
new file mode 100644
index 0000000..5505493
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-mxc.txt
@@ -0,0 +1,27 @@ 
+* Real Time Clock of the i.MX SoCs
+
+RTC controller for the i.MX SoCs
+
+Required properties:
+- compatible: Should be "fsl,imx1-rtc" or "fsl,imx21-rtc".
+- reg: physical base address of the controller and length of memory mapped
+  region.
+- interrupts: IRQ line for the RTC.
+- clocks: should contain two entries:
+  * one for the input reference
+  * one for the the SoC RTC
+- clock-names: should contain:
+  * "rtc" for the input reference clock
+  * "ipg" for the SoC RTC clock
+
+Example:
+
+rtc@10007000 {
+	compatible = "fsl,imx21-rtc";
+	reg = <0x10007000 0x1000>;
+	interrupts = <22>;
+	clocks = <&clks IMX27_CLK_CKIL>,
+	       	 <&clks IMX27_CLK_RTC_IPG_GATE>;
+	clock-names = "rtc, "ipg";
+	status = "disabled";
+};
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index e916a91..df6483d 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -16,6 +16,8 @@ 
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 
 #define RTC_INPUT_CLK_32768HZ	(0x00 << 5)
 #define RTC_INPUT_CLK_32000HZ	(0x01 << 5)
@@ -98,6 +100,15 @@  static struct platform_device_id imx_rtc_devtype[] = {
 };
 MODULE_DEVICE_TABLE(platform, imx_rtc_devtype);
 
+#ifdef CONFIG_OF
+static const struct of_device_id imx_rtc_dt_ids[] = {
+	{ .compatible = "fsl,imx1-rtc", .data = &imx_rtc_devtype[IMX1_RTC] },
+	{ .compatible = "fsl,imx21-rtc", .data = &imx_rtc_devtype[IMX21_RTC] },
+	{}
+};
+MODULE_DEVICE_TABLE(of, imx_rtc_dt_ids);
+#endif
+
 static inline int is_imx1_rtc(struct rtc_plat_data *data)
 {
 	return data->devtype == IMX1_RTC;
@@ -362,12 +373,20 @@  static int mxc_rtc_probe(struct platform_device *pdev)
 	u32 reg;
 	unsigned long rate;
 	int ret;
+	const struct of_device_id *of_id;
 
 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return -ENOMEM;
 
-	pdata->devtype = pdev->id_entry->driver_data;
+	of_id = of_match_device(imx_rtc_dt_ids, &pdev->dev);
+	if (of_id) {
+		struct platform_device_id *id_entry;
+
+		id_entry = (struct platform_device_id *)of_id->data;
+		pdata->devtype = id_entry->driver_data;
+	} else
+		pdata->devtype = pdev->id_entry->driver_data;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
@@ -481,6 +500,7 @@  static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
 static struct platform_driver mxc_rtc_driver = {
 	.driver = {
 		   .name	= "mxc_rtc",
+		   .of_match_table = of_match_ptr(imx_rtc_dt_ids),
 		   .pm		= &mxc_rtc_pm_ops,
 	},
 	.id_table = imx_rtc_devtype,