linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: kevin diggs <diggskevin38@gmail.com>
Cc: Linux PPC Development <linuxppc-dev@ozlabs.org>
Subject: Re: RTC on 2.6.36 for PowerMac 8600
Date: Sun, 29 Jan 2012 09:29:59 +0100	[thread overview]
Message-ID: <m2obtmhpx4.fsf@linux-m68k.org> (raw)
In-Reply-To: <CAKTLLVQTt8aRFb2QpXkUUikTJshnV_ytTWJ778MZ1ACyoD8aOw__43210.997261531$1327806577$gmane$org@mail.gmail.com> (kevin diggs's message of "Sat, 28 Jan 2012 21:08:56 -0600")

kevin diggs <diggskevin38@gmail.com> writes:

> [root@PowerMac8600B root]# hwclock --debug
> hwclock from util-linux-2.12pre
> Using /dev/rtc interface to clock.
> Last drift adjustment done at 1317444443 seconds after 1969
> Last calibration done at 1317444443 seconds after 1969
> Hardware clock is on local time
> Assuming hardware clock is kept in local time.
> Waiting for clock tick...
> /dev/rtc does not have interrupt functions. Waiting in loop for time
> from /dev/rtc to change
> RTC_RD_TIME: Invalid argument

Perhaps the RTC was reset due to battery running out?  That would set
the year to 1900, but the kernel RTC interface cannot represent dates
before 1970.  Unfortunately hwclock insists on reading the RTC even when
you just want to write to it, so you cannot fix that with hwclock -w.
When the battery of my iBook has run out I'm using the following to
reset RTC to current time so that it is usable again.

Andreas.

#include <time.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/rtc.h>

int
main (void)
{
  time_t now;
  struct tm gmt;
  struct rtc_time rtc;
  int fd;

  now = time (0);
  gmt = *gmtime (&now);
  rtc.tm_sec = gmt.tm_sec;
  rtc.tm_min = gmt.tm_min;
  rtc.tm_hour = gmt.tm_hour;
  rtc.tm_mday = gmt.tm_mday;
  rtc.tm_mon = gmt.tm_mon;
  rtc.tm_year = gmt.tm_year;
  rtc.tm_wday = gmt.tm_wday;
  rtc.tm_yday = gmt.tm_yday;
  rtc.tm_isdst = gmt.tm_isdst;
  fd = open ("/dev/rtc", O_RDONLY);
  if (fd < 0)
    fd = open ("/dev/rtc0", O_RDONLY);
  if (fd < 0)
    {
      perror ("/dev/rtc");
      return 1;
    }
  if (ioctl (fd, RTC_SET_TIME, &rtc) < 0)
    {
      perror ("RTC_SET_TIME");
      return 1;
    }
  return 0;
}

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

       reply	other threads:[~2012-01-29  8:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAKTLLVQTt8aRFb2QpXkUUikTJshnV_ytTWJ778MZ1ACyoD8aOw__43210.997261531$1327806577$gmane$org@mail.gmail.com>
2012-01-29  8:29 ` Andreas Schwab [this message]
2012-01-31 19:31   ` RTC on 2.6.36 for PowerMac 8600 kevin diggs
2012-01-29  3:08 kevin diggs
2012-01-31  9:06 ` Benjamin Herrenschmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2obtmhpx4.fsf@linux-m68k.org \
    --to=schwab@linux-m68k.org \
    --cc=diggskevin38@gmail.com \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).