All of lore.kernel.org
 help / color / mirror / Atom feed
* Armada RTC power up reset
@ 2017-11-30  9:40 Baruch Siach
  2017-12-01 17:10 ` Gregory CLEMENT
  0 siblings, 1 reply; 6+ messages in thread
From: Baruch Siach @ 2017-11-30  9:40 UTC (permalink / raw)
  To: Thomas Petazzoni
  Cc: Gregory Clement, Alexandre Belloni, linux-rtc, Rabeeh Khoury

Hi Thomas,

As you know, the Armada 38x/8k RTC needs a reset sequence to be operational 
when first powered up. This reset code is currently in the vendor provided 
U-Boot RTC driver. But having to run 'date reset' from the U-Boot prompt every 
first boot (happens quite a lot when dealing with SOMs) is not nice. An 
automatic reset in the kernel driver would be much better.

Rabeeh has mentioned to me that you had an idea how to detect at run time that 
the RTC is in first power up state. Do you recall the details?

Thanks,
baruch

-- 
     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: Armada RTC power up reset
  2017-11-30  9:40 Armada RTC power up reset Baruch Siach
@ 2017-12-01 17:10 ` Gregory CLEMENT
  2017-12-11 12:46   ` Rabeeh Khoury
  0 siblings, 1 reply; 6+ messages in thread
From: Gregory CLEMENT @ 2017-12-01 17:10 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Thomas Petazzoni, Alexandre Belloni, linux-rtc, Rabeeh Khoury

Hi Baruch,
 
 On jeu., nov. 30 2017, Baruch Siach <baruch@tkos.co.il> wrote:

> Hi Thomas,
>
> As you know, the Armada 38x/8k RTC needs a reset sequence to be operational 
> when first powered up. This reset code is currently in the vendor provided 
> U-Boot RTC driver. But having to run 'date reset' from the U-Boot prompt every 
> first boot (happens quite a lot when dealing with SOMs) is not nice. An 
> automatic reset in the kernel driver would be much better.
>
> Rabeeh has mentioned to me that you had an idea how to detect at run time that 
> the RTC is in first power up state. Do you recall the details?

Actually it was me who worked on the RTC but I didn't remember having a
way to detect that the RTC is in first power up state. I dig in the
datasheet, errata sheet and alos on varisou branches of the vendor tree
and didn't find anything.

Maybe a solution could be to reset the RTC when we set the time.

Gregory


>
> Thanks,
> baruch
>
> -- 
>      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 -

-- 
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Armada RTC power up reset
  2017-12-01 17:10 ` Gregory CLEMENT
@ 2017-12-11 12:46   ` Rabeeh Khoury
  2017-12-11 16:08     ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Rabeeh Khoury @ 2017-12-11 12:46 UTC (permalink / raw)
  To: Gregory CLEMENT
  Cc: Baruch Siach, Thomas Petazzoni, Alexandre Belloni, linux-rtc, nadavh

[-- Attachment #1: Type: text/plain, Size: 1932 bytes --]

Hi Gregory,

On Fri, Dec 1, 2017 at 7:10 PM, Gregory CLEMENT <
gregory.clement@free-electrons.com> wrote:

> Hi Baruch,
>
>  On jeu., nov. 30 2017, Baruch Siach <baruch@tkos.co.il> wrote:
>
> > Hi Thomas,
> >
> > As you know, the Armada 38x/8k RTC needs a reset sequence to be
> operational
> > when first powered up. This reset code is currently in the vendor
> provided
> > U-Boot RTC driver. But having to run 'date reset' from the U-Boot prompt
> every
> > first boot (happens quite a lot when dealing with SOMs) is not nice. An
> > automatic reset in the kernel driver would be much better.
> >
> > Rabeeh has mentioned to me that you had an idea how to detect at run
> time that
> > the RTC is in first power up state. Do you recall the details?
>
> Actually it was me who worked on the RTC but I didn't remember having a
> way to detect that the RTC is in first power up state. I dig in the
> datasheet, errata sheet and alos on varisou branches of the vendor tree
> and didn't find anything.
>
> Maybe a solution could be to reset the RTC when we set the time.
>


This is one way to do it; but then on first boot you might get real awkward
time; like year 2035 which can seriously confuse the boot process.
Detecting an uninitialized RTC and forcing it to tick with time = 0 (i.e.
1970) is better way since boot failures can be reproduced in an orderly
manner (and the developer would know what was really wrong).

Now for the point; I was reviewing all the bits in the RTC unit when it's
stuck; there are few bits that can indicate an uninitialized state; for
instance - RTC test configuration register (0xa381c).
I'm getting random values in bits [7:0] where it should be 0x0; we can this
as an indication; but the tip I got from Nadavh (CCed) is that Thomas (and
probably you) have found a bit that we can rely on to detect a stuck state
that can trigger a reset of the RTC on device probe.

Any ideas?

Regards,
Rabeeh

[-- Attachment #2: Type: text/html, Size: 2588 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Armada RTC power up reset
  2017-12-11 12:46   ` Rabeeh Khoury
@ 2017-12-11 16:08     ` Alexandre Belloni
  2017-12-11 18:14       ` Rabeeh Khoury
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2017-12-11 16:08 UTC (permalink / raw)
  To: Rabeeh Khoury
  Cc: Gregory CLEMENT, Baruch Siach, Thomas Petazzoni, linux-rtc, nadavh

On 11/12/2017 at 14:46:41 +0200, Rabeeh Khoury wrote:
> On Fri, Dec 1, 2017 at 7:10 PM, Gregory CLEMENT <
> gregory.clement@free-electrons.com> wrote:
> 
> > Hi Baruch,
> >
> >  On jeu., nov. 30 2017, Baruch Siach <baruch@tkos.co.il> wrote:
> >
> > > Hi Thomas,
> > >
> > > As you know, the Armada 38x/8k RTC needs a reset sequence to be
> > operational
> > > when first powered up. This reset code is currently in the vendor
> > provided
> > > U-Boot RTC driver. But having to run 'date reset' from the U-Boot prompt
> > every
> > > first boot (happens quite a lot when dealing with SOMs) is not nice. An
> > > automatic reset in the kernel driver would be much better.
> > >
> > > Rabeeh has mentioned to me that you had an idea how to detect at run
> > time that
> > > the RTC is in first power up state. Do you recall the details?
> >
> > Actually it was me who worked on the RTC but I didn't remember having a
> > way to detect that the RTC is in first power up state. I dig in the
> > datasheet, errata sheet and alos on varisou branches of the vendor tree
> > and didn't find anything.
> >
> > Maybe a solution could be to reset the RTC when we set the time.
> >
> 
> 
> This is one way to do it; but then on first boot you might get real awkward
> time; like year 2035 which can seriously confuse the boot process.
> Detecting an uninitialized RTC and forcing it to tick with time = 0 (i.e.
> 1970) is better way since boot failures can be reproduced in an orderly
> manner (and the developer would know what was really wrong).

Certainly not. If you know the time is invalid, then just return an
error. Else, userspace has no way to know whether it can rely on the
time from the RTC and act accordingly.


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Armada RTC power up reset
  2017-12-11 16:08     ` Alexandre Belloni
@ 2017-12-11 18:14       ` Rabeeh Khoury
  2017-12-20 17:02         ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Rabeeh Khoury @ 2017-12-11 18:14 UTC (permalink / raw)
  To: Alexandre Belloni, Gregory CLEMENT, Thomas Petazzoni
  Cc: Baruch Siach, linux-rtc, nadavh

[-- Attachment #1: Type: text/plain, Size: 2513 bytes --]

On Mon, Dec 11, 2017 at 6:08 PM, Alexandre Belloni <
alexandre.belloni@free-electrons.com> wrote:

> On 11/12/2017 at 14:46:41 +0200, Rabeeh Khoury wrote:
> > On Fri, Dec 1, 2017 at 7:10 PM, Gregory CLEMENT <
> > gregory.clement@free-electrons.com> wrote:
> >
> > > Hi Baruch,
> > >
> > >  On jeu., nov. 30 2017, Baruch Siach <baruch@tkos.co.il> wrote:
> > >
> > > > Hi Thomas,
> > > >
> > > > As you know, the Armada 38x/8k RTC needs a reset sequence to be
> > > operational
> > > > when first powered up. This reset code is currently in the vendor
> > > provided
> > > > U-Boot RTC driver. But having to run 'date reset' from the U-Boot
> prompt
> > > every
> > > > first boot (happens quite a lot when dealing with SOMs) is not nice.
> An
> > > > automatic reset in the kernel driver would be much better.
> > > >
> > > > Rabeeh has mentioned to me that you had an idea how to detect at run
> > > time that
> > > > the RTC is in first power up state. Do you recall the details?
> > >
> > > Actually it was me who worked on the RTC but I didn't remember having a
> > > way to detect that the RTC is in first power up state. I dig in the
> > > datasheet, errata sheet and alos on varisou branches of the vendor tree
> > > and didn't find anything.
> > >
> > > Maybe a solution could be to reset the RTC when we set the time.
> > >
> >
> >
> > This is one way to do it; but then on first boot you might get real
> awkward
> > time; like year 2035 which can seriously confuse the boot process.
> > Detecting an uninitialized RTC and forcing it to tick with time = 0 (i.e.
> > 1970) is better way since boot failures can be reproduced in an orderly
> > manner (and the developer would know what was really wrong).
>
> Certainly not. If you know the time is invalid, then just return an
> error. Else, userspace has no way to know whether it can rely on the
> time from the RTC and act accordingly.
>
Part of the problem is that you don't know if the time is valid or not; you
can look at some bits and try to guess.
For instance the test conf register gets random values on it's low [7:0]
value which can be used to tell if the RTC is in a initialized condition or
not.

Please look at the following two options -

The first; sets the values to a know good state (including time=0) on it's
probe() -
https://pastebin.com/ubqwEBBM

Second return -EPERM on an uninitialized RTC until first write resets it's
values to a known condition on first write (as Gregory suggest) -
https://pastebin.com/r7sydF8G

Suggestion?

[-- Attachment #2: Type: text/html, Size: 3652 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Armada RTC power up reset
  2017-12-11 18:14       ` Rabeeh Khoury
@ 2017-12-20 17:02         ` Alexandre Belloni
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2017-12-20 17:02 UTC (permalink / raw)
  To: Rabeeh Khoury
  Cc: Gregory CLEMENT, Thomas Petazzoni, Baruch Siach, linux-rtc, nadavh

On 11/12/2017 at 20:14:00 +0200, Rabeeh Khoury wrote:
> The first; sets the values to a know good state (including time=0) on it's
> probe() -
> https://pastebin.com/ubqwEBBM
> 

No, as explained that would be bad for userspace as it will have now way
to know whether the time is correct or not (you may as well not have any
RTC at all).

> Second return -EPERM on an uninitialized RTC until first write resets it's
> values to a known condition on first write (as Gregory suggest) -
> https://pastebin.com/r7sydF8G
> 

-EINVAL is the proper error code for an uninitialized RTC but yes, that
would be the idea.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-20 17:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-30  9:40 Armada RTC power up reset Baruch Siach
2017-12-01 17:10 ` Gregory CLEMENT
2017-12-11 12:46   ` Rabeeh Khoury
2017-12-11 16:08     ` Alexandre Belloni
2017-12-11 18:14       ` Rabeeh Khoury
2017-12-20 17:02         ` Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.