From: Greg KH <gregkh@suse.de>
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>,
Chuck Ebbert <cebbert@redhat.com>,
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 003/101] rtc-pcf8563: detect polarity of century bit automatically
Date: Wed, 07 Mar 2007 09:10:38 -0800 [thread overview]
Message-ID: <20070307171126.233352635@mini.kroah.org> (raw)
In-Reply-To: <20070307171035.150802805@mini.kroah.org>
[-- Attachment #1: rtc-pcf8563-detect-polarity-of-century-bit-automatically.patch --]
[-- Type: text/plain, Size: 4808 bytes --]
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.20.1.orig/drivers/rtc/rtc-pcf8563.c
+++ linux-2.6.20.1/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;
}
--
next prev parent reply other threads:[~2007-03-07 18:00 UTC|newest]
Thread overview: 112+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-07 17:10 [patch 000/101] 2.6.20-stable review Greg KH
2007-03-07 17:10 ` [patch 001/101] ocfs2: ocfs2_link() journal credits update Greg KH
2007-03-07 17:10 ` [patch 002/101] x86_64: fix 2.6.18 regression - PTRACE_OLDSETOPTIONS should be accepted Greg KH
2007-03-07 17:10 ` Greg KH [this message]
2007-03-07 17:10 ` [patch 004/101] prism54: correct assignment of DOT1XENABLE in WE-19 codepaths Greg KH
2007-03-07 17:10 ` [patch 005/101] pata_amd: fix an obvious bug in cable detection Greg KH
2007-03-07 17:10 ` [patch 006/101] knfsd: Fix a race in closing NFSd connections Greg KH
2007-03-07 17:10 ` [patch 007/101] Keys: Fix key serial number collision handling Greg KH
2007-03-07 17:10 ` [patch 008/101] ide: fix drive side 80c cable check Greg KH
2007-03-07 17:10 ` [patch 009/101] bcm43xx: Fix for oops on resume Greg KH
2007-03-07 17:10 ` [patch 010/101] bcm43xx: Fix for oops on ampdu status Greg KH
2007-03-07 17:10 ` [patch 011/101] AGP: intel-agp bugfix Greg KH
2007-03-07 17:10 ` [patch 012/101] Missing critical phys_to_virt in lib/swiotlb.c Greg KH
2007-03-07 17:10 ` [patch 013/101] USB: fix concurrent buffer access in the hub driver Greg KH
2007-03-07 17:10 ` [patch 014/101] USB audio fixes 1 Greg KH
2007-03-07 17:10 ` [patch 015/101] USB audio fixes 2 Greg KH
2007-03-07 17:10 ` [patch 016/101] hda-intel - Dont try to probe invalid codecs Greg KH
2007-03-07 17:10 ` [patch 017/101] Fix various bugs with aligned reads in RAID5 Greg KH
2007-03-07 17:10 ` [patch 018/101] Fix ATM initcall ordering Greg KH
2007-03-07 17:10 ` [patch 019/101] Fix TCP FIN handling Greg KH
2007-03-07 17:10 ` [patch 020/101] Fix allocation failure handling in multicast Greg KH
2007-03-07 17:10 ` [patch 021/101] md: Avoid possible BUG_ON in md bitmap handling Greg KH
2007-03-07 17:10 ` [patch 022/101] Fix compile error for e500 core based processors Greg KH
2007-03-07 17:10 ` [patch 023/101] ieee1394: video1394: DMA fix Greg KH
2007-03-07 17:10 ` [patch 024/101] ieee1394: fix host device registering when nodemgr disabled Greg KH
2007-03-07 17:11 ` [patch 025/101] Fix null pointer dereference in appledisplay driver Greg KH
2007-03-07 17:11 ` [patch 026/101] USB HID: Fix USB vendor and product IDs endianness for USB HID devices Greg KH
2007-03-07 17:11 ` [patch 027/101] Kconfig: FAULT_INJECTION can be selected only if LOCKDEP is enabled Greg KH
2007-03-08 12:17 ` Blaisorblade
2007-03-07 17:11 ` [patch 028/101] MTD: Fatal regression in drivers/mtd/redboot.c in 2.6.20 Greg KH
2007-03-07 17:11 ` [patch 029/101] IPV6: HASHTABLES: Use appropriate seed for caluculating ehash index Greg KH
2007-03-07 17:11 ` [patch 030/101] EHCI: turn off remote wakeup during shutdown Greg KH
2007-03-07 17:11 ` [patch 031/101] Avoid using nfsd process pools on SMP machines Greg KH
2007-03-07 17:11 ` [patch 032/101] Fix recently introduced problem with shutting down a busy NFS server Greg KH
2007-03-07 17:11 ` [patch 033/101] UHCI: fix port resume problem Greg KH
2007-03-07 17:11 ` [patch 034/101] Fix atmarp.h for userspace Greg KH
2007-03-07 17:11 ` [patch 035/101] Clear TCP segmentation offload state in ipt_REJECT Greg KH
2007-03-07 17:11 ` [patch 036/101] Fix IPX module unload Greg KH
2007-03-07 17:11 ` [patch 037/101] : Prevent pseudo garbage in SYNs advertized window Greg KH
2007-03-07 17:11 ` [patch 038/101] Fix oops in xfrm_audit_log() Greg KH
2007-03-07 17:11 ` [patch 039/101] sky2: dont flush good pause frames Greg KH
2007-03-07 17:11 ` [patch 040/101] sky2: transmit timeout deadlock Greg KH
2007-03-07 17:11 ` [patch 041/101] x86_64: Fix wrong gcc check in bitops.h Greg KH
2007-03-07 17:11 ` [patch 042/101] x86: Dont require the vDSO for handling a.out signals Greg KH
2007-03-07 17:11 ` [patch 043/101] i386: Fix broken CONFIG_COMPAT_VDSO on i386 Greg KH
2007-03-07 17:11 ` [patch 044/101] bcm43xx: fix for 4309 Greg KH
2007-03-07 17:11 ` [patch 045/101] md: Fix raid10 recovery problem Greg KH
2007-03-07 17:11 ` [patch 046/101] dvbdev: fix illegal re-usage of fileoperations struct Greg KH
2007-03-07 17:11 ` [patch 047/101] V4L: pvrusb2: Fix video corruption on stream start Greg KH
2007-03-07 17:11 ` [patch 048/101] V4L: pvrusb2: Handle larger cx2341x firmware images Greg KH
2007-03-07 17:11 ` [patch 049/101] DVB: cxusb: fix firmware patch for big endian systems Greg KH
2007-03-07 17:11 ` [patch 050/101] DVB: digitv: open nxt6000 i2c_gate for TDED4 tuner handling Greg KH
2007-03-07 17:11 ` [patch 051/101] V4L: fix cx25840 firmware loading Greg KH
2007-03-07 17:11 ` [patch 052/101] V4L: cx88-blackbird: allow usage of 376836 and 262144 sized firmware images Greg KH
2007-03-07 17:11 ` [patch 053/101] Fix posix-cpu-timer breakage caused by stale p->last_ran value Greg KH
2007-03-07 17:11 ` [patch 054/101] swsusp: Fix possible oops in userland interface Greg KH
2007-03-07 17:11 ` [patch 055/101] sata_sil: ignore and clear spurious IRQs while executing commands by polling Greg KH
2007-03-07 17:11 ` [patch 056/101] fix umask when noACL kernel meets extN tuned for ACLs Greg KH
2007-03-07 17:11 ` [patch 057/101] UML - Fix 2.6.20 hang Greg KH
2007-03-07 17:11 ` [patch 058/101] mmc: Power quirk for ENE controllers Greg KH
2007-03-07 17:11 ` [patch 059/101] bcm43xx: Fix assertion failures in interrupt handler Greg KH
2007-03-07 17:11 ` [patch 060/101] libata: add missing PM callbacks Greg KH
2007-03-07 17:11 ` [patch 061/101] libata: add missing CONFIG_PM in LLDs Greg KH
2007-03-07 17:11 ` [patch 062/101] POWERPC: Fix performance monitor exception Greg KH
2007-03-07 17:11 ` [patch 063/101] HID: fix possible double-free on error path in hid parser Greg KH
2007-03-07 17:11 ` [patch 064/101] Fix interrupt probing on E450 sparc64 systems Greg KH
2007-03-07 17:11 ` [patch 065/101] Fix xfrm_add_sa_expire() return value Greg KH
2007-03-07 17:11 ` [patch 066/101] Fix skb data reallocation handling in IPSEC Greg KH
2007-03-07 17:11 ` [patch 067/101] Fix %100 cpu spinning on sparc64 Greg KH
2007-03-07 17:11 ` [patch 068/101] Fix TCP MD5 locking Greg KH
2007-03-07 17:11 ` [patch 069/101] Dont add anycast reference to device multiple times Greg KH
2007-03-07 17:11 ` [patch 070/101] Fix anycast procfs device leak Greg KH
2007-03-07 17:11 ` [patch 071/101] Fix reference counting (memory leak) problem in __nfulnl_send() and callers related to packet queueing Greg KH
2007-03-07 17:11 ` [patch 072/101] export blk_recount_segments Greg KH
2007-03-07 17:11 ` [patch 073/101] forcedeth: disable msix Greg KH
2007-03-07 17:11 ` [patch 074/101] tty_io: fix race in master pty close/slave pty close path Greg KH
2007-03-07 17:11 ` [patch 075/101] sched: fix SMT scheduler bug Greg KH
2007-03-07 17:11 ` [patch 076/101] USB: usbnet driver bugfix Greg KH
2007-03-07 17:11 ` [patch 077/101] Backport of psmouse suspend/shutdown cleanups Greg KH
2007-03-07 17:11 ` [patch 078/101] Revert "LOG2: Alter get_order() so that it can make use of ilog2() on a constant" Greg KH
2007-03-07 17:11 ` [patch 079/101] RPM: fix double free in portmapper code Greg KH
2007-03-07 17:11 ` [patch 080/101] NLM: Fix double free in __nlm_async_call Greg KH
2007-03-07 17:11 ` [patch 081/101] kexec: Fix CONFIG_SMP=n compilation V2 (ia64) Greg KH
2007-03-07 17:11 ` [patch 082/101] Fix MTRR compat ioctl Greg KH
2007-03-07 17:11 ` [patch 083/101] ufs: restore back support of openstep Greg KH
2007-03-07 17:11 ` [patch 084/101] v9fs_vfs_mkdir(): fix a double free Greg KH
2007-03-07 17:12 ` [patch 085/101] enable mouse button 2+3 emulation for x86 macs Greg KH
2007-03-07 17:12 ` [patch 086/101] hugetlb: preserve hugetlb pte dirty state Greg KH
2007-03-07 17:12 ` [patch 087/101] m32r: build fix for processors without ISA_DSP_LEVEL2 Greg KH
2007-03-07 17:12 ` [patch 088/101] kernel/time/clocksource.c needs struct task_struct on m68k Greg KH
2007-03-07 17:12 ` [patch 089/101] buffer: memorder fix Greg KH
2007-03-07 17:12 ` [patch 090/101] Char: specialix, isr have 2 params Greg KH
2007-03-07 17:12 ` [patch 091/101] lockdep: forward declare struct task_struct Greg KH
2007-03-07 17:12 ` [patch 092/101] kvm: Fix asm constraint for lldt instruction Greg KH
2007-03-07 17:12 ` [patch 093/101] ueagle-atm.c needs sched.h Greg KH
2007-03-07 17:12 ` [patch 094/101] fix section mismatch warning in lockdep Greg KH
2007-03-07 17:12 ` [patch 095/101] throttle_vm_writeout(): dont loop on GFP_NOFS and GFP_NOIO allocations Greg KH
2007-03-07 17:12 ` [patch 096/101] bug in gdth.c crashing machine Greg KH
2007-03-07 17:12 ` [patch 097/101] revert "drivers/net/tulip/dmfe: support basic carrier detection" Greg KH
2007-03-07 18:14 ` Stephen Hemminger
2007-03-08 2:41 ` Dan Williams
2007-03-08 3:06 ` Linus Torvalds
2007-03-07 17:12 ` [patch 098/101] video/aty/mach64_ct.c: fix bogus delay loop Greg KH
2007-03-07 17:12 ` [patch 099/101] pktcdvd: Correctly set cmd_len field in pkt_generic_packet Greg KH
2007-03-07 17:12 ` [patch 100/101] ATA: convert GSI to irq on ia64 Greg KH
2007-03-07 17:12 ` [patch 101/101] gfs2: fix locking mistake Greg KH
2007-03-07 17:34 ` [stable] [patch 000/101] 2.6.20-stable review Greg KH
2007-03-07 23:12 ` [patch 102/101] TCP: Fix minisock tcp_create_openreq_child() typo Chris Wright
2007-03-07 23:12 ` [patch 103/101] Fix buffer overflow in Omnikey CardMan 4040 driver (CVE-2007-0005) Chris Wright
2007-03-07 23:13 ` [patch 104/101] x86-64: survive having no irq mapping for a vector Chris Wright
2007-03-07 18:41 ` [patch 000/101] 2.6.20-stable review Chuck Ebbert
2007-03-07 21:05 ` [stable] " Chris Wright
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=20070307171126.233352635@mini.kroah.org \
--to=gregkh@suse.de \
--cc=a.zummo@towertech.it \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=anemo@mba.ocn.ne.jp \
--cc=cebbert@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome