All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, stable@kernel.org,
	akpm@linux-foundation.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	Michael Krufky <mkrufky@linuxtv.org>,
	torvalds@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	jean-baptiste.maneyrol@teamlog.com, a.zummo@towertech.it,
	dbrownell@users.sourceforge.net,
	Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Subject: [patch 07/21] rtc-pcf8563: detect polarity of century bit automatically
Date: Tue, 20 Feb 2007 17:37:17 -0800	[thread overview]
Message-ID: <20070221013717.GH30227@kroah.com> (raw)
In-Reply-To: <20070221013619.GA30227@kroah.com>

[-- Attachment #1: rtc-pcf8563-detect-polarity-of-century-bit-automatically.patch --]
[-- Type: text/plain, Size: 4901 bytes --]

-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

The usage of the century bit was inverted on 2.6.19 following to PCF8563's
description, but it was not match to usage suggested by RTC8564's
datasheet.  Anyway what MO_C=1 means can vary on each platform.  This patch
is to detect its polarity in get_datetime routine.  The default value of
c_polarity is 0 (MO_C=1 means 19xx) so that this patch does not change
current behavior even if get_datetime was not called before set_datetime.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@teamlog.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/rtc/rtc-pcf8563.c |   40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

--- linux-2.6.19.4.orig/drivers/rtc/rtc-pcf8563.c
+++ linux-2.6.19.4/drivers/rtc/rtc-pcf8563.c
@@ -53,6 +53,25 @@ I2C_CLIENT_INSMOD;
 #define PCF8563_SC_LV		0x80 /* low voltage */
 #define PCF8563_MO_C		0x80 /* century */
 
+struct pcf8563 {
+	struct i2c_client client;
+	/*
+	 * The meaning of MO_C bit varies by the chip type.
+	 * From PCF8563 datasheet: this bit is toggled when the years
+	 * register overflows from 99 to 00
+	 *   0 indicates the century is 20xx
+	 *   1 indicates the century is 19xx
+	 * From RTC8564 datasheet: this bit indicates change of
+	 * century. When the year digit data overflows from 99 to 00,
+	 * this bit is set. By presetting it to 0 while still in the
+	 * 20th century, it will be set in year 2000, ...
+	 * There seems no reliable way to know how the system use this
+	 * bit.  So let's do it heuristically, assuming we are live in
+	 * 1970...2069.
+	 */
+	int c_polarity;	/* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
+};
+
 static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
 static int pcf8563_detach(struct i2c_client *client);
 
@@ -62,6 +81,7 @@ static int pcf8563_detach(struct i2c_cli
  */
 static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 {
+	struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
 	unsigned char buf[13] = { PCF8563_REG_ST1 };
 
 	struct i2c_msg msgs[] = {
@@ -94,8 +114,12 @@ static int pcf8563_get_datetime(struct i
 	tm->tm_mday = BCD2BIN(buf[PCF8563_REG_DM] & 0x3F);
 	tm->tm_wday = buf[PCF8563_REG_DW] & 0x07;
 	tm->tm_mon = BCD2BIN(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
-	tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR])
-		+ (buf[PCF8563_REG_MO] & PCF8563_MO_C ? 0 : 100);
+	tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR]);
+	if (tm->tm_year < 70)
+		tm->tm_year += 100;	/* assume we are in 1970...2069 */
+	/* detect the polarity heuristically. see note above. */
+	pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ?
+		(tm->tm_year >= 100) : (tm->tm_year < 100);
 
 	dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
 		"mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -114,6 +138,7 @@ static int pcf8563_get_datetime(struct i
 
 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 {
+	struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
 	int i, err;
 	unsigned char buf[9];
 
@@ -135,7 +160,7 @@ static int pcf8563_set_datetime(struct i
 
 	/* year and century */
 	buf[PCF8563_REG_YR] = BIN2BCD(tm->tm_year % 100);
-	if (tm->tm_year < 100)
+	if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100))
 		buf[PCF8563_REG_MO] |= PCF8563_MO_C;
 
 	buf[PCF8563_REG_DW] = tm->tm_wday & 0x07;
@@ -248,6 +273,7 @@ static struct i2c_driver pcf8563_driver 
 
 static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
 {
+	struct pcf8563 *pcf8563;
 	struct i2c_client *client;
 	struct rtc_device *rtc;
 
@@ -260,11 +286,12 @@ static int pcf8563_probe(struct i2c_adap
 		goto exit;
 	}
 
-	if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
+	if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) {
 		err = -ENOMEM;
 		goto exit;
 	}
 
+	client = &pcf8563->client;
 	client->addr = address;
 	client->driver = &pcf8563_driver;
 	client->adapter	= adapter;
@@ -301,7 +328,7 @@ exit_detach:
 	i2c_detach_client(client);
 
 exit_kfree:
-	kfree(client);
+	kfree(pcf8563);
 
 exit:
 	return err;
@@ -309,6 +336,7 @@ exit:
 
 static int pcf8563_detach(struct i2c_client *client)
 {
+	struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
 	int err;
 	struct rtc_device *rtc = i2c_get_clientdata(client);
 
@@ -318,7 +346,7 @@ static int pcf8563_detach(struct i2c_cli
 	if ((err = i2c_detach_client(client)))
 		return err;
 
-	kfree(client);
+	kfree(pcf8563);
 
 	return 0;
 }

--

  parent reply	other threads:[~2007-02-21  1:47 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070221012758.925122216@mini.kroah.org>
2007-02-21  1:36 ` [patch 00/21] 2.6.19-stable review Greg KH
2007-02-21  1:36   ` [patch 01/21] V4L: cx88: Fix lockup on suspend Greg KH
2007-02-22  1:00     ` Chuck Ebbert
2007-02-22  1:14       ` Michael Krufky
2007-02-21  1:36   ` [patch 02/21] V4L: Fix quickcam communicator driver for big endian architectures Greg KH
2007-02-21  1:36   ` [patch 03/21] V4L: fix ks0127 status flags Greg KH
2007-02-21  1:36   ` [patch 04/21] V4L: tveeprom: autodetect LG TAPC G701D as tuner type 37 Greg KH
2007-02-21  1:37   ` [patch 05/21] V4L: buf_qbuf: fix videobuf_queue->stream corruption and lockup Greg KH
2007-02-21  1:37   ` [patch 06/21] net/smc911x: match up spin lock/unlock Greg KH
2007-02-21  1:37   ` Greg KH [this message]
2007-02-21  1:37   ` [patch 08/21] aio: fix buggy put_ioctx call in aio_complete - v2 Greg KH
2007-02-21  1:37   ` [uml-devel] [patch 09/21] x86_64: fix 2.6.18 regression - PTRACE_OLDSETOPTIONS should be accepted Greg KH
2007-02-21  1:37     ` Greg KH
2007-02-21  1:37   ` [patch 10/21] ide: fix drive side 80c cable check Greg KH
2007-02-21  1:37   ` [patch 11/21] pata_amd: fix an obvious bug in cable detection Greg KH
2007-02-21  1:37   ` [patch 12/21] bcm43xx: Fix for oops on resume Greg KH
2007-02-21  1:38   ` [patch 13/21] bcm43xx: Fix for oops on ampdu status Greg KH
2007-02-21  1:38   ` [patch 14/21] usb-audio: work around wrong frequency in CM6501 descriptors Greg KH
2007-02-21  1:38   ` [patch 15/21] usbaudio - Fix Oops with broken usb descriptors Greg KH
2007-02-21  1:38   ` [patch 16/21] usbaudio - Fix Oops with unconventional sample rates Greg KH
2007-02-21  1:38   ` [patch 17/21] Use different constraint for gcc < 4.1 in bitops Greg KH
2007-02-21  1:38   ` [patch 18/21] prism54: correct assignment of DOT1XENABLE in WE-19 codepaths Greg KH
2007-02-21  1:38   ` [patch 19/21] net, 8139too.c: fix netpoll deadlock Greg KH
2007-02-21  1:38   ` [patch 20/21] Keys: Fix key serial number collision handling Greg KH
2007-02-21  1:39   ` [patch 21/21] knfsd: Fix a race in closing NFSd connections Greg KH
2007-02-21  1:39     ` Greg KH
2007-02-21 13:36   ` [patch 00/21] 2.6.19-stable review Stefan Richter
2007-02-21 13:37     ` Stefan Richter
2007-03-09  5:35     ` Adrian Bunk
2007-02-21 16:38   ` Chuck Ebbert
2007-02-21 16:50   ` Chuck Ebbert
2007-02-21 19:31   ` Chuck Ebbert
2007-02-21 19:47     ` Andrew Morton
2007-02-21 20:09       ` Linus Torvalds
2007-02-21 22:45         ` Eric W. Biederman
2007-02-28  6:37         ` Eric W. Biederman
2007-02-28  8:51           ` Zwane Mwaikambo
2007-02-28 12:28             ` Eric W. Biederman
2007-02-28 19:52               ` [stable] " Greg KH
2007-02-28 23:25                 ` Eric W. Biederman
2007-02-21 20:13       ` Eric W. Biederman
2007-02-21 20:21         ` Chuck Ebbert
2007-02-21 22:19         ` Andi Kleen
2007-02-21 22:20       ` Andi Kleen
2007-02-21 22:39         ` Chuck Ebbert
2007-02-22  1:19           ` Andi Kleen
2007-02-21 20:39     ` Greg KH
2007-02-21 20:44       ` Chuck Ebbert
2007-02-21 22:33   ` Chuck Ebbert
2007-02-21 22:35     ` Chuck Ebbert
2007-02-21 22:43   ` Chuck Ebbert
2007-02-22 16:09   ` Chuck Ebbert

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=20070221013717.GH30227@kroah.com \
    --to=greg@kroah.com \
    --cc=a.zummo@towertech.it \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=anemo@mba.ocn.ne.jp \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=jean-baptiste.maneyrol@teamlog.com \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkrufky@linuxtv.org \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /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 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.