[RFC 0/5] add rtc support

Antony Pavlov antonynpavlov at gmail.com
Fri Jul 11 04:27:35 PDT 2014


On Fri, 11 Jul 2014 10:12:36 +0400
Antony Pavlov <antonynpavlov at gmail.com> wrote:

> On Fri, 11 Jul 2014 07:37:38 +0200
> Sascha Hauer <s.hauer at pengutronix.de> wrote:
> 
> > On Thu, Jul 10, 2014 at 12:33:14PM +0400, Antony Pavlov wrote:
> > > This patchseries imports RTC support from linux-3.15.
> > > 
> > > User can use 'hwclock' command to see realtime clock readout.
> > > 
> > > Tested with DS1307.
> > > 
> > > TODOs:
> > > 
> > >  * rtc_set_time() is not realized;
> > >  * ds1307_set_time() is not tested;
> > >  * bcd lib is compiled in even if rtc support is disabled (as linux does);
> > >    we can make it optional;
> > 
...
> I have an idea to put epoch offset (number of years into AD to which a zero year value
> in the Hardware Clock refers) into "global.epoch" variable and add corresponding
> Kconfig option for default epoch value.

I was wrong.

Hmm hwclock receives time value in the 'struct tm'
(e.g. see linux.git/include/linux/time.h)

/*
 * Similar to the struct tm in userspace <time.h>, but it needs to be here so
 * that the kernel source is self contained.
 */
struct tm {
	/*
	 * the number of seconds after the minute, normally in the range
	 * 0 to 59, but can be up to 60 to allow for leap seconds
	 */
	int tm_sec;
	/* the number of minutes after the hour, in the range 0 to 59*/
	int tm_min;
	/* the number of hours past midnight, in the range 0 to 23 */
	int tm_hour;
	/* the day of the month, in the range 1 to 31 */
	int tm_mday;
	/* the number of months since January, in the range 0 to 11 */
	int tm_mon;
	/* the number of years since 1900 */
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

	long tm_year;
	/* the number of days since Sunday, in the range 0 to 6 */
	int tm_wday;
	/* the number of days since January 1, in the range 0 to 365 */
	int tm_yday;
};

Here is a quote from read_hardware_clock()
(see util-linux-2.20.1/hwclock/hwclock.c)

         printf(_
             ("Hw clock time : %4d/%.2d/%.2d %.2d:%.2d:%.2d = "
             "%ld seconds since 1969\n"), tm.tm_year + 1900,
             tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
             tm.tm_sec, (long)*systime_p);

So in linux hardware clock epoch is always "1900".

-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list