From patchwork Fri Jan 28 06:19:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xulei X-Patchwork-Id: 80772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wy0-f184.google.com (mail-wy0-f184.google.com [74.125.82.184]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 3D074B710D for ; Fri, 28 Jan 2011 17:16:28 +1100 (EST) Received: by wyb39 with SMTP id 39sf3107926wyb.11 for ; Thu, 27 Jan 2011 22:16:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:x-beenthere:received-spf:x-spamscore:x-bigfish :x-forefront-antispam-report:x-fb-ss:from:to:cc:subject:date :message-id:x-mailer:mime-version:x-originatororg:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; bh=LOpMlm/edSv6mVi4xlhPnoiVVfVi54jIGJhw99XE348=; b=eZtPE/3/bZVxKFwIKFUkHwehAWegOaZR/OgBBm3523Tr0zIdRf94dKTL/P1YOgS4a7 pBtNrkOWiOgxOtXqRol8H/CRipEFLNu0+RVBHmfUSYR8PY2MryUmM2EzwCGc/IrYcfWU 5cOzOdpWCaTHULUlKlxh3rkjSMsjhRwZjHhSQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:x-spamscore:x-bigfish :x-forefront-antispam-report:x-fb-ss:from:to:cc:subject:date :message-id:x-mailer:mime-version:x-originatororg:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; b=J7yguePzAkVImH/BHE6JZ60/6XNc+2dyvRa96EbMFEkXUlf0nq2Vcdw0t10GWtd6Bo bWyUygRxuBWDcIYT4KaeZBu6OluTRqLTQDDyOK24iaObe3OIYQBJkPlMPDNB79+fMYEU U50JNneDdGqYKFGSDEf8r3yzk9uZM1cp+9H4c= Received: by 10.216.183.148 with SMTP id q20mr593411wem.20.1296195383121; Thu, 27 Jan 2011 22:16:23 -0800 (PST) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.216.15.136 with SMTP id f8ls1201460wef.3.p; Thu, 27 Jan 2011 22:16:22 -0800 (PST) Received: by 10.216.165.15 with SMTP id d15mr183435wel.2.1296195382422; Thu, 27 Jan 2011 22:16:22 -0800 (PST) Received: by 10.216.165.15 with SMTP id d15mr183434wel.2.1296195382408; Thu, 27 Jan 2011 22:16:22 -0800 (PST) Received: from DB3EHSOBE002.bigfish.com (db3ehsobe002.messaging.microsoft.com [213.199.154.140]) by gmr-mx.google.com with ESMTPS id i31si1587710wej.9.2011.01.27.22.16.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 27 Jan 2011 22:16:22 -0800 (PST) Received-SPF: neutral (google.com: 213.199.154.140 is neither permitted nor denied by best guess record for domain of B33228@freescale.com) client-ip=213.199.154.140; Received: from mail89-db3-R.bigfish.com (10.3.81.243) by DB3EHSOBE002.bigfish.com (10.3.84.22) with Microsoft SMTP Server id 14.1.225.8; Fri, 28 Jan 2011 06:16:21 +0000 Received: from mail89-db3 (localhost.localdomain [127.0.0.1]) by mail89-db3-R.bigfish.com (Postfix) with ESMTP id ABB2EA5006F; Fri, 28 Jan 2011 06:16:21 +0000 (UTC) X-SpamScore: 3 X-BigFish: VS3(zzc8kzz1202hzz8275bhz2dh2a8h668h) X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:az33egw02.freescale.net; RD:az33egw02.freescale.net; EFVD:NLI X-FB-SS: 13, Received: from mail89-db3 (localhost.localdomain [127.0.0.1]) by mail89-db3 (MessageSwitch) id 1296195381432608_16727; Fri, 28 Jan 2011 06:16:21 +0000 (UTC) Received: from DB3EHSMHS004.bigfish.com (unknown [10.3.81.243]) by mail89-db3.bigfish.com (Postfix) with ESMTP id 5BE5AC9804C; Fri, 28 Jan 2011 06:16:21 +0000 (UTC) Received: from az33egw02.freescale.net (192.88.158.103) by DB3EHSMHS004.bigfish.com (10.3.87.104) with Microsoft SMTP Server (TLS) id 14.1.225.8; Fri, 28 Jan 2011 06:16:20 +0000 Received: from az33smr02.freescale.net (az33smr02.freescale.net [10.64.34.200]) by az33egw02.freescale.net (8.14.3/8.14.3) with ESMTP id p0S6GIPM013684; Thu, 27 Jan 2011 23:16:18 -0700 (MST) Received: from localhost.localdomain (xulei-desktop.ap.freescale.net [10.193.20.28]) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id p0S6GFZa011307; Fri, 28 Jan 2011 00:16:15 -0600 (CST) From: Lei Xu To: CC: , Lei Xu Subject: [rtc-linux] [PATCH] RTC: Fix time range difference between linux and RTC chip Date: Fri, 28 Jan 2011 14:19:19 +0800 Message-ID: <1296195559-5439-1-git-send-email-B33228@freescale.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-Original-Sender: b33228@freescale.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 213.199.154.140 is neither permitted nor denied by best guess record for domain of B33228@freescale.com) smtp.mail=B33228@freescale.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , In linux rtc_time struct, tm_mon range is 0~11, tm_wday range is 0~6, while in RTC HW REG, month range is 1~12, day of the week range is 1~7, this patch adjusts difference of them. Signed-off-by: Lei Xu --- drivers/rtc/rtc-ds3232.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c index 23a9ee1..9507354 100644 --- a/drivers/rtc/rtc-ds3232.c +++ b/drivers/rtc/rtc-ds3232.c @@ -1,7 +1,7 @@ /* * RTC client/driver for the Maxim/Dallas DS3232 Real-Time Clock over I2C * - * Copyright (C) 2009-2010 Freescale Semiconductor. + * Copyright (C) 2009-2011 Freescale Semiconductor. * Author: Jack Lan * * This program is free software; you can redistribute it and/or modify it @@ -141,9 +141,11 @@ static int ds3232_read_time(struct device *dev, struct rtc_time *time) time->tm_hour = bcd2bin(hour); } - time->tm_wday = bcd2bin(week); + /* Day of the week in linux range is 0~6 while 1~7 in RTC chip */ + time->tm_wday = bcd2bin(week) - 1; time->tm_mday = bcd2bin(day); - time->tm_mon = bcd2bin(month & 0x7F); + /* linux tm_mon range:0~11, while month range is 1~12 in RTC chip */ + time->tm_mon = bcd2bin(month & 0x7F) - 1; if (century) add_century = 100; @@ -162,9 +164,11 @@ static int ds3232_set_time(struct device *dev, struct rtc_time *time) buf[0] = bin2bcd(time->tm_sec); buf[1] = bin2bcd(time->tm_min); buf[2] = bin2bcd(time->tm_hour); - buf[3] = bin2bcd(time->tm_wday); /* Day of the week */ + /* Day of the week in linux range is 0~6 while 1~7 in RTC chip */ + buf[3] = bin2bcd(time->tm_wday + 1); buf[4] = bin2bcd(time->tm_mday); /* Date */ - buf[5] = bin2bcd(time->tm_mon); + /* linux tm_mon range:0~11, while month range is 1~12 in RTC chip */ + buf[5] = bin2bcd(time->tm_mon + 1); if (time->tm_year >= 100) { buf[5] |= 0x80; buf[6] = bin2bcd(time->tm_year - 100);