* [PATCH 1/2] rtc: armada38x: drop redundant initialization
@ 2018-06-21 17:40 Baruch Siach
2018-06-21 17:40 ` [PATCH 2/2] rtc: armada38x: reset after rtc power loss Baruch Siach
2018-06-21 17:59 ` [PATCH 1/2] rtc: armada38x: drop redundant initialization Alexandre Belloni
0 siblings, 2 replies; 6+ messages in thread
From: Baruch Siach @ 2018-06-21 17:40 UTC (permalink / raw)
To: Jason Cooper, Andrew Lunn, Gregory Clement, Sebastian Hesselbarth
Cc: Russell King, Jon Nettleton, Alessandro Zummo, Alexandre Belloni,
linux-rtc, linux-arm-kernel, Baruch Siach
The 'ret' variable in these functions is set unconditionally below.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
drivers/rtc/rtc-armada38x.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
index 1e4978c96ffd..4d62a54fd5d6 100644
--- a/drivers/rtc/rtc-armada38x.c
+++ b/drivers/rtc/rtc-armada38x.c
@@ -229,7 +229,7 @@ static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct armada38x_rtc *rtc = dev_get_drvdata(dev);
- int ret = 0;
+ int ret;
unsigned long time, flags;
ret = rtc_tm_to_time(tm, &time);
@@ -272,7 +272,7 @@ static int armada38x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
u32 reg = ALARM_REG(RTC_ALARM1, rtc->data->alarm);
u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm);
unsigned long time, flags;
- int ret = 0;
+ int ret;
ret = rtc_tm_to_time(&alrm->time, &time);
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] rtc: armada38x: reset after rtc power loss
2018-06-21 17:40 [PATCH 1/2] rtc: armada38x: drop redundant initialization Baruch Siach
@ 2018-06-21 17:40 ` Baruch Siach
2018-06-28 13:56 ` Gregory CLEMENT
2018-07-12 18:36 ` Alexandre Belloni
2018-06-21 17:59 ` [PATCH 1/2] rtc: armada38x: drop redundant initialization Alexandre Belloni
1 sibling, 2 replies; 6+ messages in thread
From: Baruch Siach @ 2018-06-21 17:40 UTC (permalink / raw)
To: Jason Cooper, Andrew Lunn, Gregory Clement, Sebastian Hesselbarth
Cc: Russell King, Jon Nettleton, Alessandro Zummo, Alexandre Belloni,
linux-rtc, linux-arm-kernel, Baruch Siach
When the RTC block looses power it needs a reset sequence to make it
usable again. Otherwise, writes to the time register have no effect.
This reset sequence combines information from the mvebu_rtc driver in
the Marvell provided U-Boot, and the SolidRun provided U-Boot repo.
Tested on the Armada 388 based SolidRun Clearfog Base.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
drivers/rtc/rtc-armada38x.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
index 4d62a54fd5d6..0b50276dce6d 100644
--- a/drivers/rtc/rtc-armada38x.c
+++ b/drivers/rtc/rtc-armada38x.c
@@ -30,6 +30,8 @@
#define RTC_IRQ_FREQ_1HZ BIT(2)
#define RTC_CCR 0x18
#define RTC_CCR_MODE BIT(15)
+#define RTC_CONF_TEST 0x1C
+#define RTC_NOMINAL_TIMING BIT(13)
#define RTC_TIME 0xC
#define RTC_ALARM1 0x10
@@ -75,6 +77,7 @@ struct armada38x_rtc {
void __iomem *regs_soc;
spinlock_t lock;
int irq;
+ bool initialized;
struct value_to_freq *val_to_freq;
struct armada38x_rtc_data *data;
};
@@ -226,6 +229,23 @@ static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
return 0;
}
+static void armada38x_rtc_reset(struct armada38x_rtc *rtc)
+{
+ u32 reg;
+
+ reg = rtc->data->read_rtc_reg(rtc, RTC_CONF_TEST);
+ /* If bits [7:0] are non-zero, assume RTC was uninitialized */
+ if (reg & 0xff) {
+ rtc_delayed_write(0, rtc, RTC_CONF_TEST);
+ msleep(500); /* Oscillator startup time */
+ rtc_delayed_write(0, rtc, RTC_TIME);
+ rtc_delayed_write(SOC_RTC_ALARM1 | SOC_RTC_ALARM2, rtc,
+ RTC_STATUS);
+ rtc_delayed_write(RTC_NOMINAL_TIMING, rtc, RTC_CCR);
+ }
+ rtc->initialized = true;
+}
+
static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct armada38x_rtc *rtc = dev_get_drvdata(dev);
@@ -237,6 +257,9 @@ static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
if (ret)
goto out;
+ if (!rtc->initialized)
+ armada38x_rtc_reset(rtc);
+
spin_lock_irqsave(&rtc->lock, flags);
rtc_delayed_write(time, rtc, RTC_TIME);
spin_unlock_irqrestore(&rtc->lock, flags);
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] rtc: armada38x: drop redundant initialization
2018-06-21 17:40 [PATCH 1/2] rtc: armada38x: drop redundant initialization Baruch Siach
2018-06-21 17:40 ` [PATCH 2/2] rtc: armada38x: reset after rtc power loss Baruch Siach
@ 2018-06-21 17:59 ` Alexandre Belloni
2018-06-21 18:11 ` Baruch Siach
1 sibling, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2018-06-21 17:59 UTC (permalink / raw)
To: Baruch Siach
Cc: Jason Cooper, Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
Russell King, Jon Nettleton, Alessandro Zummo, linux-rtc,
linux-arm-kernel
On 21/06/2018 20:40:22+0300, Baruch Siach wrote:
> The 'ret' variable in these functions is set unconditionally below.
>
Hum, what is the actual benefit of this patch?
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
> drivers/rtc/rtc-armada38x.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
> index 1e4978c96ffd..4d62a54fd5d6 100644
> --- a/drivers/rtc/rtc-armada38x.c
> +++ b/drivers/rtc/rtc-armada38x.c
> @@ -229,7 +229,7 @@ static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
> static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
> {
> struct armada38x_rtc *rtc = dev_get_drvdata(dev);
> - int ret = 0;
> + int ret;
> unsigned long time, flags;
>
> ret = rtc_tm_to_time(tm, &time);
> @@ -272,7 +272,7 @@ static int armada38x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> u32 reg = ALARM_REG(RTC_ALARM1, rtc->data->alarm);
> u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm);
> unsigned long time, flags;
> - int ret = 0;
> + int ret;
>
> ret = rtc_tm_to_time(&alrm->time, &time);
>
> --
> 2.17.1
>
--
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] rtc: armada38x: drop redundant initialization
2018-06-21 17:59 ` [PATCH 1/2] rtc: armada38x: drop redundant initialization Alexandre Belloni
@ 2018-06-21 18:11 ` Baruch Siach
0 siblings, 0 replies; 6+ messages in thread
From: Baruch Siach @ 2018-06-21 18:11 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Jason Cooper, Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
Russell King, Jon Nettleton, Alessandro Zummo, linux-rtc,
linux-arm-kernel
Hi Alexandre,
On Thu, Jun 21, 2018 at 07:59:39PM +0200, Alexandre Belloni wrote:
> On 21/06/2018 20:40:22+0300, Baruch Siach wrote:
> > The 'ret' variable in these functions is set unconditionally below.
>
> Hum, what is the actual benefit of this patch?
It is just a small cleanup to reduces somewhat the strain on the reader of the
code. ret is not different from other variables in the same functions that are
only initialized when needed.
baruch
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> > ---
> > drivers/rtc/rtc-armada38x.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
> > index 1e4978c96ffd..4d62a54fd5d6 100644
> > --- a/drivers/rtc/rtc-armada38x.c
> > +++ b/drivers/rtc/rtc-armada38x.c
> > @@ -229,7 +229,7 @@ static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
> > static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
> > {
> > struct armada38x_rtc *rtc = dev_get_drvdata(dev);
> > - int ret = 0;
> > + int ret;
> > unsigned long time, flags;
> >
> > ret = rtc_tm_to_time(tm, &time);
> > @@ -272,7 +272,7 @@ static int armada38x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> > u32 reg = ALARM_REG(RTC_ALARM1, rtc->data->alarm);
> > u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm);
> > unsigned long time, flags;
> > - int ret = 0;
> > + int ret;
> >
> > ret = rtc_tm_to_time(&alrm->time, &time);
> >
> > --
> > 2.17.1
--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] rtc: armada38x: reset after rtc power loss
2018-06-21 17:40 ` [PATCH 2/2] rtc: armada38x: reset after rtc power loss Baruch Siach
@ 2018-06-28 13:56 ` Gregory CLEMENT
2018-07-12 18:36 ` Alexandre Belloni
1 sibling, 0 replies; 6+ messages in thread
From: Gregory CLEMENT @ 2018-06-28 13:56 UTC (permalink / raw)
To: Baruch Siach
Cc: Jason Cooper, Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
Russell King, Jon Nettleton, Alessandro Zummo, Alexandre Belloni,
linux-rtc, linux-arm-kernel
Hi Baruch,
On jeu., juin 21 2018, Baruch Siach <baruch@tkos.co.il> wrote:
> When the RTC block looses power it needs a reset sequence to make it
> usable again. Otherwise, writes to the time register have no effect.
>
> This reset sequence combines information from the mvebu_rtc driver in
> the Marvell provided U-Boot, and the SolidRun provided U-Boot repo.
>
> Tested on the Armada 388 based SolidRun Clearfog Base.
It also matches my notes to reset the RTC on Armada 8K:
devmem2 0xf428401c w 0
devmem2 0xf4284018 w 0x2000
Acked-by: Gregory CLEMENT <gregory.clement@bootlin.com>
Thanks,
Gregory
>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
> drivers/rtc/rtc-armada38x.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/drivers/rtc/rtc-armada38x.c b/drivers/rtc/rtc-armada38x.c
> index 4d62a54fd5d6..0b50276dce6d 100644
> --- a/drivers/rtc/rtc-armada38x.c
> +++ b/drivers/rtc/rtc-armada38x.c
> @@ -30,6 +30,8 @@
> #define RTC_IRQ_FREQ_1HZ BIT(2)
> #define RTC_CCR 0x18
> #define RTC_CCR_MODE BIT(15)
> +#define RTC_CONF_TEST 0x1C
> +#define RTC_NOMINAL_TIMING BIT(13)
>
> #define RTC_TIME 0xC
> #define RTC_ALARM1 0x10
> @@ -75,6 +77,7 @@ struct armada38x_rtc {
> void __iomem *regs_soc;
> spinlock_t lock;
> int irq;
> + bool initialized;
> struct value_to_freq *val_to_freq;
> struct armada38x_rtc_data *data;
> };
> @@ -226,6 +229,23 @@ static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
> return 0;
> }
>
> +static void armada38x_rtc_reset(struct armada38x_rtc *rtc)
> +{
> + u32 reg;
> +
> + reg = rtc->data->read_rtc_reg(rtc, RTC_CONF_TEST);
> + /* If bits [7:0] are non-zero, assume RTC was uninitialized */
> + if (reg & 0xff) {
> + rtc_delayed_write(0, rtc, RTC_CONF_TEST);
> + msleep(500); /* Oscillator startup time */
> + rtc_delayed_write(0, rtc, RTC_TIME);
> + rtc_delayed_write(SOC_RTC_ALARM1 | SOC_RTC_ALARM2, rtc,
> + RTC_STATUS);
> + rtc_delayed_write(RTC_NOMINAL_TIMING, rtc, RTC_CCR);
> + }
> + rtc->initialized = true;
> +}
> +
> static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
> {
> struct armada38x_rtc *rtc = dev_get_drvdata(dev);
> @@ -237,6 +257,9 @@ static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
> if (ret)
> goto out;
>
> + if (!rtc->initialized)
> + armada38x_rtc_reset(rtc);
> +
> spin_lock_irqsave(&rtc->lock, flags);
> rtc_delayed_write(time, rtc, RTC_TIME);
> spin_unlock_irqrestore(&rtc->lock, flags);
> --
> 2.17.1
>
--
Gregory Clement, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] rtc: armada38x: reset after rtc power loss
2018-06-21 17:40 ` [PATCH 2/2] rtc: armada38x: reset after rtc power loss Baruch Siach
2018-06-28 13:56 ` Gregory CLEMENT
@ 2018-07-12 18:36 ` Alexandre Belloni
1 sibling, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2018-07-12 18:36 UTC (permalink / raw)
To: Baruch Siach
Cc: Jason Cooper, Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
Russell King, Jon Nettleton, Alessandro Zummo, linux-rtc,
linux-arm-kernel
On 21/06/2018 20:40:23+0300, Baruch Siach wrote:
> When the RTC block looses power it needs a reset sequence to make it
> usable again. Otherwise, writes to the time register have no effect.
>
> This reset sequence combines information from the mvebu_rtc driver in
> the Marvell provided U-Boot, and the SolidRun provided U-Boot repo.
>
> Tested on the Armada 388 based SolidRun Clearfog Base.
>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
> drivers/rtc/rtc-armada38x.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
Applied, thanks.
--
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-07-12 18:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-21 17:40 [PATCH 1/2] rtc: armada38x: drop redundant initialization Baruch Siach
2018-06-21 17:40 ` [PATCH 2/2] rtc: armada38x: reset after rtc power loss Baruch Siach
2018-06-28 13:56 ` Gregory CLEMENT
2018-07-12 18:36 ` Alexandre Belloni
2018-06-21 17:59 ` [PATCH 1/2] rtc: armada38x: drop redundant initialization Alexandre Belloni
2018-06-21 18:11 ` Baruch Siach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).