Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1350999 > unrolled thread

[PATCH 1/5] rtc: rtc-jz4740: Add support for the RTC in the jz4780 SoC

Started byPaul Cercueil <paul@crapouillou.net>
First post2016-03-05 23:50 +0100
Last post2016-03-17 13:10 +0100
Articles 6 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/5] rtc: rtc-jz4740: Add support for the RTC in the jz4780 SoC Paul Cercueil <paul@crapouillou.net> - 2016-03-05 23:50 +0100
    [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver Paul Cercueil <paul@crapouillou.net> - 2016-03-05 23:50 +0100
      Re: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc  driver Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-03-06 13:20 +0100
      Re: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc  driver Rob Herring <robh@kernel.org> - 2016-03-17 13:00 +0100
      Re: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc  driver Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2016-03-17 13:10 +0100
    Re: [PATCH 1/5] rtc: rtc-jz4740: Add support for the RTC in the  jz4780 SoC Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2016-03-17 13:10 +0100

#1350999 — [PATCH 1/5] rtc: rtc-jz4740: Add support for the RTC in the jz4780 SoC

FromPaul Cercueil <paul@crapouillou.net>
Date2016-03-05 23:50 +0100
Subject[PATCH 1/5] rtc: rtc-jz4740: Add support for the RTC in the jz4780 SoC
Message-ID<r9tbk-4pS-3@gated-at.bofh.it>
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 drivers/rtc/Kconfig      |  6 +++---
 drivers/rtc/rtc-jz4740.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e593c55..b322f08 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1494,10 +1494,10 @@ config RTC_DRV_MPC5121
 
 config RTC_DRV_JZ4740
 	tristate "Ingenic JZ4740 SoC"
-	depends on MACH_JZ4740 || COMPILE_TEST
+	depends on MACH_INGENIC || COMPILE_TEST
 	help
-	  If you say yes here you get support for the Ingenic JZ4740 SoC RTC
-	  controller.
+	  If you say yes here you get support for the Ingenic JZ47xx SoCs RTC
+	  controllers.
 
 	  This driver can also be buillt as a module. If so, the module
 	  will be called rtc-jz4740.
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index b2bcfc0..47617bd 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -29,6 +29,10 @@
 #define JZ_REG_RTC_HIBERNATE	0x20
 #define JZ_REG_RTC_SCRATCHPAD	0x34
 
+/* The following are present on the jz4780 */
+#define JZ_REG_RTC_WENR	0x3C
+#define JZ_RTC_WENR_WEN	BIT(31)
+
 #define JZ_RTC_CTRL_WRDY	BIT(7)
 #define JZ_RTC_CTRL_1HZ		BIT(6)
 #define JZ_RTC_CTRL_1HZ_IRQ	BIT(5)
@@ -37,8 +41,17 @@
 #define JZ_RTC_CTRL_AE		BIT(2)
 #define JZ_RTC_CTRL_ENABLE	BIT(0)
 
+/* Magic value to enable writes on jz4780 */
+#define JZ_RTC_WENR_MAGIC	0xA55A
+
+enum jz4740_rtc_type {
+	ID_JZ4740,
+	ID_JZ4780,
+};
+
 struct jz4740_rtc {
 	void __iomem *base;
+	enum jz4740_rtc_type type;
 
 	struct rtc_device *rtc;
 
@@ -64,11 +77,33 @@ static int jz4740_rtc_wait_write_ready(struct jz4740_rtc *rtc)
 	return timeout ? 0 : -EIO;
 }
 
+static inline int jz4780_rtc_enable_write(struct jz4740_rtc *rtc)
+{
+	uint32_t ctrl;
+	int ret, timeout = 1000;
+
+	ret = jz4740_rtc_wait_write_ready(rtc);
+	if (ret != 0)
+		return ret;
+
+	writel(JZ_RTC_WENR_MAGIC, rtc->base + JZ_REG_RTC_WENR);
+
+	do {
+		ctrl = readl(rtc->base + JZ_REG_RTC_WENR);
+	} while (!(ctrl & JZ_RTC_WENR_WEN) && --timeout);
+
+	return timeout ? 0 : -EIO;
+}
+
 static inline int jz4740_rtc_reg_write(struct jz4740_rtc *rtc, size_t reg,
 	uint32_t val)
 {
-	int ret;
-	ret = jz4740_rtc_wait_write_ready(rtc);
+	int ret = 0;
+
+	if (rtc->type >= ID_JZ4780)
+		ret = jz4780_rtc_enable_write(rtc);
+	if (ret == 0)
+		ret = jz4740_rtc_wait_write_ready(rtc);
 	if (ret == 0)
 		writel(val, rtc->base + reg);
 
@@ -216,11 +251,14 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
 	struct jz4740_rtc *rtc;
 	uint32_t scratchpad;
 	struct resource *mem;
+	const struct platform_device_id *id = platform_get_device_id(pdev);
 
 	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
 	if (!rtc)
 		return -ENOMEM;
 
+	rtc->type = id->driver_data;
+
 	rtc->irq = platform_get_irq(pdev, 0);
 	if (rtc->irq < 0) {
 		dev_err(&pdev->dev, "Failed to get platform irq\n");
@@ -295,12 +333,20 @@ static const struct dev_pm_ops jz4740_pm_ops = {
 #define JZ4740_RTC_PM_OPS NULL
 #endif  /* CONFIG_PM */
 
+static const struct platform_device_id jz4740_rtc_ids[] = {
+	{"jz4740-rtc", ID_JZ4740},
+	{"jz4780-rtc", ID_JZ4780},
+	{}
+};
+MODULE_DEVICE_TABLE(platform, jz4740_rtc_ids);
+
 static struct platform_driver jz4740_rtc_driver = {
 	.probe	 = jz4740_rtc_probe,
 	.driver	 = {
 		.name  = "jz4740-rtc",
 		.pm    = JZ4740_RTC_PM_OPS,
 	},
+	.id_table = jz4740_rtc_ids,
 };
 
 module_platform_driver(jz4740_rtc_driver);
-- 
2.7.0

[toc] | [next] | [standalone]


#1351002 — [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver

FromPaul Cercueil <paul@crapouillou.net>
Date2016-03-05 23:50 +0100
Subject[PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver
Message-ID<r9tbl-4pS-33@gated-at.bofh.it>
In reply to#1350999
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 .../devicetree/bindings/rtc/ingenic,jz4740-rtc.txt | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt

diff --git a/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
new file mode 100644
index 0000000..71e4ad0
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
@@ -0,0 +1,38 @@
+JZ4740 and similar SoCs real-time clock driver
+
+Required properties:
+
+- compatible: One of:
+  - "ingenic,jz4740-rtc" - for use with the JZ4740 SoC
+  - "ingenic,jz4780-rtc" - for use with the JZ4780 SoC
+- reg: Address range of rtc register set
+- interrupts: IRQ number for the alarm interrupt
+- interrupt-parent: phandle of the interrupt controller
+- clocks: phandle to the "rtc" clock
+- clock-names: must be "rtc"
+
+Optional properties:
+- system-power-controller: To use this component as the
+  system power controller
+- reset-pin-assert-time: Reset pin low-level assertion time
+  after wakeup (default 60ms; range 0-125ms if RTC clock at 
+  32 kHz)
+- min-wakeup-pin-assert-time: Minimum wakeup pin assertion time
+  (default 100ms; range 0-2s if RTC clock at 32 kHz)
+
+Example:
+
+rtc@10003000 {
+	compatible = "ingenic,jz4740-rtc";
+	reg = <0x10003000 0x3F>;
+
+	interrupt-parent = <&intc>;
+	interrupts = <32>;
+
+	clocks = <&rtc_clock>;
+	clock-names = "rtc";
+
+	system-power-controller;
+	reset-pin-assert-time = <60>;
+	min-wakeup-pin-assert-time = <100>;
+};
-- 
2.7.0

[toc] | [prev] | [next] | [standalone]


#1351106 — Re: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver

FromSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Date2016-03-06 13:20 +0100
SubjectRe: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver
Message-ID<r9FPc-4Sg-21@gated-at.bofh.it>
In reply to#1351002
Hello.

On 3/6/2016 1:38 AM, Paul Cercueil wrote:

> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>   .../devicetree/bindings/rtc/ingenic,jz4740-rtc.txt | 38 ++++++++++++++++++++++
>   1 file changed, 38 insertions(+)
>   create mode 100644 Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
>
> diff --git a/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> new file mode 100644
> index 0000000..71e4ad0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> @@ -0,0 +1,38 @@
> +JZ4740 and similar SoCs real-time clock driver
> +
> +Required properties:
> +
> +- compatible: One of:
> +  - "ingenic,jz4740-rtc" - for use with the JZ4740 SoC
> +  - "ingenic,jz4780-rtc" - for use with the JZ4780 SoC
> +- reg: Address range of rtc register set
> +- interrupts: IRQ number for the alarm interrupt
> +- interrupt-parent: phandle of the interrupt controller

    This is never a required property, it can be inherited from the parent node.

[...]

MBR, Sergei

[toc] | [prev] | [next] | [standalone]


#1359772 — Re: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver

FromRob Herring <robh@kernel.org>
Date2016-03-17 13:00 +0100
SubjectRe: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver
Message-ID<rdEKS-6X2-15@gated-at.bofh.it>
In reply to#1351002
On Sat, Mar 05, 2016 at 11:38:48PM +0100, Paul Cercueil wrote:
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  .../devicetree/bindings/rtc/ingenic,jz4740-rtc.txt | 38 ++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> 
> diff --git a/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> new file mode 100644
> index 0000000..71e4ad0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> @@ -0,0 +1,38 @@
> +JZ4740 and similar SoCs real-time clock driver
> +
> +Required properties:
> +
> +- compatible: One of:
> +  - "ingenic,jz4740-rtc" - for use with the JZ4740 SoC
> +  - "ingenic,jz4780-rtc" - for use with the JZ4780 SoC
> +- reg: Address range of rtc register set
> +- interrupts: IRQ number for the alarm interrupt
> +- interrupt-parent: phandle of the interrupt controller
> +- clocks: phandle to the "rtc" clock
> +- clock-names: must be "rtc"
> +
> +Optional properties:
> +- system-power-controller: To use this component as the
> +  system power controller

> +- reset-pin-assert-time: Reset pin low-level assertion time
> +  after wakeup (default 60ms; range 0-125ms if RTC clock at 
> +  32 kHz)
> +- min-wakeup-pin-assert-time: Minimum wakeup pin assertion time
> +  (default 100ms; range 0-2s if RTC clock at 32 kHz)

Please append units on these (-msec).

> +
> +Example:
> +
> +rtc@10003000 {
> +	compatible = "ingenic,jz4740-rtc";
> +	reg = <0x10003000 0x3F>;
> +
> +	interrupt-parent = <&intc>;
> +	interrupts = <32>;
> +
> +	clocks = <&rtc_clock>;
> +	clock-names = "rtc";
> +
> +	system-power-controller;
> +	reset-pin-assert-time = <60>;
> +	min-wakeup-pin-assert-time = <100>;
> +};
> -- 
> 2.7.0
> 

[toc] | [prev] | [next] | [standalone]


#1359790 — Re: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver

FromAlexandre Belloni <alexandre.belloni@free-electrons.com>
Date2016-03-17 13:10 +0100
SubjectRe: [PATCH 2/5] Documentation: dt: Add binding info for jz4740-rtc driver
Message-ID<rdEUz-7h0-27@gated-at.bofh.it>
In reply to#1351002
On 05/03/2016 at 23:38:48 +0100, Paul Cercueil wrote :
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  .../devicetree/bindings/rtc/ingenic,jz4740-rtc.txt | 38 ++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> 
> diff --git a/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> new file mode 100644
> index 0000000..71e4ad0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
> @@ -0,0 +1,38 @@
> +JZ4740 and similar SoCs real-time clock driver
> +
> +Required properties:
> +
> +- compatible: One of:
> +  - "ingenic,jz4740-rtc" - for use with the JZ4740 SoC
> +  - "ingenic,jz4780-rtc" - for use with the JZ4780 SoC
> +- reg: Address range of rtc register set
> +- interrupts: IRQ number for the alarm interrupt
> +- interrupt-parent: phandle of the interrupt controller
> +- clocks: phandle to the "rtc" clock
> +- clock-names: must be "rtc"
> +
> +Optional properties:
> +- system-power-controller: To use this component as the
> +  system power controller
> +- reset-pin-assert-time: Reset pin low-level assertion time
> +  after wakeup (default 60ms; range 0-125ms if RTC clock at 

Trailing whitespace on that line.


-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[toc] | [prev] | [next] | [standalone]


#1359783 — Re: [PATCH 1/5] rtc: rtc-jz4740: Add support for the RTC in the jz4780 SoC

FromAlexandre Belloni <alexandre.belloni@free-electrons.com>
Date2016-03-17 13:10 +0100
SubjectRe: [PATCH 1/5] rtc: rtc-jz4740: Add support for the RTC in the jz4780 SoC
Message-ID<rdEUy-7h0-7@gated-at.bofh.it>
In reply to#1350999
Please, always include a commit message, even if it is short.

On 05/03/2016 at 23:38:47 +0100, Paul Cercueil wrote :
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  drivers/rtc/Kconfig      |  6 +++---
>  drivers/rtc/rtc-jz4740.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++--
>  2 files changed, 51 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index e593c55..b322f08 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -1494,10 +1494,10 @@ config RTC_DRV_MPC5121
>  
>  config RTC_DRV_JZ4740
>  	tristate "Ingenic JZ4740 SoC"
> -	depends on MACH_JZ4740 || COMPILE_TEST
> +	depends on MACH_INGENIC || COMPILE_TEST
>  	help
> -	  If you say yes here you get support for the Ingenic JZ4740 SoC RTC
> -	  controller.
> +	  If you say yes here you get support for the Ingenic JZ47xx SoCs RTC
> +	  controllers.
>  
>  	  This driver can also be buillt as a module. If so, the module
>  	  will be called rtc-jz4740.
> diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
> index b2bcfc0..47617bd 100644
> --- a/drivers/rtc/rtc-jz4740.c
> +++ b/drivers/rtc/rtc-jz4740.c
> @@ -29,6 +29,10 @@
>  #define JZ_REG_RTC_HIBERNATE	0x20
>  #define JZ_REG_RTC_SCRATCHPAD	0x34
>  
> +/* The following are present on the jz4780 */
> +#define JZ_REG_RTC_WENR	0x3C
> +#define JZ_RTC_WENR_WEN	BIT(31)
> +
>  #define JZ_RTC_CTRL_WRDY	BIT(7)
>  #define JZ_RTC_CTRL_1HZ		BIT(6)
>  #define JZ_RTC_CTRL_1HZ_IRQ	BIT(5)
> @@ -37,8 +41,17 @@
>  #define JZ_RTC_CTRL_AE		BIT(2)
>  #define JZ_RTC_CTRL_ENABLE	BIT(0)
>  
> +/* Magic value to enable writes on jz4780 */
> +#define JZ_RTC_WENR_MAGIC	0xA55A
> +
> +enum jz4740_rtc_type {
> +	ID_JZ4740,
> +	ID_JZ4780,
> +};
> +
>  struct jz4740_rtc {
>  	void __iomem *base;
> +	enum jz4740_rtc_type type;
>  
>  	struct rtc_device *rtc;
>  
> @@ -64,11 +77,33 @@ static int jz4740_rtc_wait_write_ready(struct jz4740_rtc *rtc)
>  	return timeout ? 0 : -EIO;
>  }
>  
> +static inline int jz4780_rtc_enable_write(struct jz4740_rtc *rtc)
> +{
> +	uint32_t ctrl;
> +	int ret, timeout = 1000;
> +
> +	ret = jz4740_rtc_wait_write_ready(rtc);
> +	if (ret != 0)
> +		return ret;
> +
> +	writel(JZ_RTC_WENR_MAGIC, rtc->base + JZ_REG_RTC_WENR);
> +
> +	do {
> +		ctrl = readl(rtc->base + JZ_REG_RTC_WENR);
> +	} while (!(ctrl & JZ_RTC_WENR_WEN) && --timeout);
> +
> +	return timeout ? 0 : -EIO;
> +}
> +
>  static inline int jz4740_rtc_reg_write(struct jz4740_rtc *rtc, size_t reg,
>  	uint32_t val)
>  {
> -	int ret;
> -	ret = jz4740_rtc_wait_write_ready(rtc);
> +	int ret = 0;
> +
> +	if (rtc->type >= ID_JZ4780)
> +		ret = jz4780_rtc_enable_write(rtc);
> +	if (ret == 0)
> +		ret = jz4740_rtc_wait_write_ready(rtc);
>  	if (ret == 0)
>  		writel(val, rtc->base + reg);
>  
> @@ -216,11 +251,14 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
>  	struct jz4740_rtc *rtc;
>  	uint32_t scratchpad;
>  	struct resource *mem;
> +	const struct platform_device_id *id = platform_get_device_id(pdev);
>  
>  	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
>  	if (!rtc)
>  		return -ENOMEM;
>  
> +	rtc->type = id->driver_data;
> +
>  	rtc->irq = platform_get_irq(pdev, 0);
>  	if (rtc->irq < 0) {
>  		dev_err(&pdev->dev, "Failed to get platform irq\n");
> @@ -295,12 +333,20 @@ static const struct dev_pm_ops jz4740_pm_ops = {
>  #define JZ4740_RTC_PM_OPS NULL
>  #endif  /* CONFIG_PM */
>  
> +static const struct platform_device_id jz4740_rtc_ids[] = {
> +	{"jz4740-rtc", ID_JZ4740},
> +	{"jz4780-rtc", ID_JZ4780},
> +	{}
> +};
> +MODULE_DEVICE_TABLE(platform, jz4740_rtc_ids);
> +
>  static struct platform_driver jz4740_rtc_driver = {
>  	.probe	 = jz4740_rtc_probe,
>  	.driver	 = {
>  		.name  = "jz4740-rtc",
>  		.pm    = JZ4740_RTC_PM_OPS,
>  	},
> +	.id_table = jz4740_rtc_ids,
>  };
>  
>  module_platform_driver(jz4740_rtc_driver);
> -- 
> 2.7.0
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web