From patchwork Fri Apr 16 09:19:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Patard X-Patchwork-Id: 50315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-yw0-f166.google.com (mail-yw0-f166.google.com [209.85.211.166]) by ozlabs.org (Postfix) with ESMTP id 02103B7D40 for ; Fri, 16 Apr 2010 19:19:42 +1000 (EST) Received: by ywh38 with SMTP id 38sf1287770ywh.29 for ; Fri, 16 Apr 2010 02:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:x-spam-virus:x-spam-checker-version :x-spam-level:x-spam-status:received:received:received:from:to:cc :subject:organization:date:message-id:mime-version :x-original-authentication-results:x-original-sender:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type; bh=lLdRyWmGEF/iaVs85PIqtlp7rvFcieqlBlioq1+5kmc=; b=UOUQ5fw43SyJZo7fal5wnG7ZEQgyzOj+Wh7KffN4sQpbLqDwGd6l9i4xGw+GZaby7O dDNeCbgKTHGB36et5yYIg9mvPyCEDGWt6+/Qm1Rd5iPhbdLGrk3yN2s3ZpN89LcOGVVW pYvR+GnafW+hbY8FoGg8CtPWAtutGf3b+l5nw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:x-spam-virus:x-spam-checker-version :x-spam-level:x-spam-status:from:to:cc:subject:organization:date :message-id:mime-version:x-original-authentication-results :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; b=yiom7B1MmkQhkUBJrb4QFSpjuJA0moc0SgQXLVjimkDo77WoP2+ls9tkT8rzxtgyWg 1p5+e58KPwfYWYeXyvTHp3MhiXYGCGeQt66zvMBOylyD++JhHu7bmx1C8TCXHlQESXq/ J/T/OMAzXgsMB4+UowPcOi5pO1S8zBLImKrkk= Received: by 10.91.91.6 with SMTP id t6mr366116agl.14.1271409580200; Fri, 16 Apr 2010 02:19:40 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.216.198.222 with SMTP id v72ls369869wen.3.p; Fri, 16 Apr 2010 02:19:39 -0700 (PDT) Received: by 10.216.153.146 with SMTP id f18mr118934wek.1.1271409578905; Fri, 16 Apr 2010 02:19:38 -0700 (PDT) Received: by 10.216.153.146 with SMTP id f18mr118933wek.1.1271409578878; Fri, 16 Apr 2010 02:19:38 -0700 (PDT) Received: from mx1.mandriva.com (mx1.moondrake.net [212.85.150.166]) by gmr-mx.google.com with ESMTP id p33si2982469wba.7.2010.04.16.02.19.38; Fri, 16 Apr 2010 02:19:38 -0700 (PDT) Received-SPF: neutral (google.com: 212.85.150.166 is neither permitted nor denied by best guess record for domain of arnaud.patard@mandriva.com) client-ip=212.85.150.166; Received: by mx1.mandriva.com (Postfix, from userid 501) id D54FA274029; Fri, 16 Apr 2010 11:19:37 +0200 (CEST) X-Spam-Virus: No X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mx1.mandriva.com X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 Received: from office-abk.mandriva.com (unknown [195.7.104.248]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.mandriva.com (Postfix) with ESMTP id 8190C274014; Fri, 16 Apr 2010 11:19:36 +0200 (CEST) Received: from anduin.mandriva.com (fw2.mandriva.com [192.168.2.3]) by office-abk.mandriva.com (Postfix) with ESMTP id 301F884EF4; Fri, 16 Apr 2010 11:36:40 +0200 (CEST) Received: from anduin.mandriva.com (localhost [127.0.0.1]) by anduin.mandriva.com (Postfix) with ESMTP id 54117FF855; Fri, 16 Apr 2010 11:19:52 +0200 (CEST) From: Arnaud Patard To: linux-mips@linux-mips.org, rtc-linux@googlegroups.com Cc: david-b@pacbell.net, a.zummo@towertech.it, ralf@linux-mips.org Subject: [rtc-linux] [PATCH] rtc-cmos: Fix binary mode support Organization: Mandriva Date: Fri, 16 Apr 2010 11:19:51 +0200 Message-ID: MIME-Version: 1.0 X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.85.150.166 is neither permitted nor denied by best guess record for domain of arnaud.patard@mandriva.com) smtp.mail=arnaud.patard@mandriva.com X-Original-Sender: apatard@mandriva.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: , As a follow-up to the thread about rtc support for some loongson 2e/2f boards, this patch tries to address the "REVISIT"/"FIXME" comments about rtc binary mode handling and allow rtc to work with rtc in binary mode. I've also raised the message about 24-h mode not supported to warning otherwise, one may end up with no rtc without any message in the kernel log. Signed-off-by: Arnaud Patard diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index e9aa814..9d99408 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -238,31 +238,32 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t) rtc_control = CMOS_READ(RTC_CONTROL); spin_unlock_irq(&rtc_lock); - /* REVISIT this assumes PC style usage: always BCD */ - - if (((unsigned)t->time.tm_sec) < 0x60) - t->time.tm_sec = bcd2bin(t->time.tm_sec); - else - t->time.tm_sec = -1; - if (((unsigned)t->time.tm_min) < 0x60) - t->time.tm_min = bcd2bin(t->time.tm_min); - else - t->time.tm_min = -1; - if (((unsigned)t->time.tm_hour) < 0x24) - t->time.tm_hour = bcd2bin(t->time.tm_hour); - else - t->time.tm_hour = -1; - - if (cmos->day_alrm) { - if (((unsigned)t->time.tm_mday) <= 0x31) - t->time.tm_mday = bcd2bin(t->time.tm_mday); + if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { + if (((unsigned)t->time.tm_sec) < 0x60) + t->time.tm_sec = bcd2bin(t->time.tm_sec); else - t->time.tm_mday = -1; - if (cmos->mon_alrm) { - if (((unsigned)t->time.tm_mon) <= 0x12) - t->time.tm_mon = bcd2bin(t->time.tm_mon) - 1; + t->time.tm_sec = -1; + if (((unsigned)t->time.tm_min) < 0x60) + t->time.tm_min = bcd2bin(t->time.tm_min); + else + t->time.tm_min = -1; + if (((unsigned)t->time.tm_hour) < 0x24) + t->time.tm_hour = bcd2bin(t->time.tm_hour); + else + t->time.tm_hour = -1; + + if (cmos->day_alrm) { + if (((unsigned)t->time.tm_mday) <= 0x31) + t->time.tm_mday = bcd2bin(t->time.tm_mday); else - t->time.tm_mon = -1; + t->time.tm_mday = -1; + + if (cmos->mon_alrm) { + if (((unsigned)t->time.tm_mon) <= 0x12) + t->time.tm_mon = bcd2bin(t->time.tm_mon)-1; + else + t->time.tm_mon = -1; + } } } t->time.tm_year = -1; @@ -322,29 +323,26 @@ static void cmos_irq_disable(struct cmos_rtc *cmos, unsigned char mask) static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) { struct cmos_rtc *cmos = dev_get_drvdata(dev); - unsigned char mon, mday, hrs, min, sec; + unsigned char mon, mday, hrs, min, sec, rtc_control; if (!is_valid_irq(cmos->irq)) return -EIO; - /* REVISIT this assumes PC style usage: always BCD */ - - /* Writing 0xff means "don't care" or "match all". */ - mon = t->time.tm_mon + 1; - mon = (mon <= 12) ? bin2bcd(mon) : 0xff; - mday = t->time.tm_mday; - mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff; - hrs = t->time.tm_hour; - hrs = (hrs < 24) ? bin2bcd(hrs) : 0xff; - min = t->time.tm_min; - min = (min < 60) ? bin2bcd(min) : 0xff; - sec = t->time.tm_sec; - sec = (sec < 60) ? bin2bcd(sec) : 0xff; + + rtc_control = CMOS_READ(RTC_CONTROL); + if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { + /* Writing 0xff means "don't care" or "match all". */ + mon = (mon <= 12) ? bin2bcd(mon) : 0xff; + mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff; + hrs = (hrs < 24) ? bin2bcd(hrs) : 0xff; + min = (min < 60) ? bin2bcd(min) : 0xff; + sec = (sec < 60) ? bin2bcd(sec) : 0xff; + } spin_lock_irq(&rtc_lock); @@ -478,7 +476,7 @@ static int cmos_procfs(struct device *dev, struct seq_file *seq) "update_IRQ\t: %s\n" "HPET_emulated\t: %s\n" // "square_wave\t: %s\n" - // "BCD\t\t: %s\n" + "BCD\t\t: %s\n" "DST_enable\t: %s\n" "periodic_freq\t: %d\n" "batt_status\t: %s\n", @@ -486,7 +484,7 @@ static int cmos_procfs(struct device *dev, struct seq_file *seq) (rtc_control & RTC_UIE) ? "yes" : "no", is_hpet_enabled() ? "yes" : "no", // (rtc_control & RTC_SQWE) ? "yes" : "no", - // (rtc_control & RTC_DM_BINARY) ? "no" : "yes", + (rtc_control & RTC_DM_BINARY) ? "no" : "yes", (rtc_control & RTC_DST_EN) ? "yes" : "no", cmos->rtc->irq_freq, (valid & RTC_VRT) ? "okay" : "dead"); @@ -749,12 +747,11 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) spin_unlock_irq(&rtc_lock); - /* FIXME teach the alarm code how to handle binary mode; + /* FIXME: * doesn't know 12-hour mode either. */ - if (is_valid_irq(rtc_irq) && - (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY)))) { - dev_dbg(dev, "only 24-hr BCD mode supported\n"); + if (is_valid_irq(rtc_irq) && !(rtc_control & RTC_24H)) { + dev_warn(dev, "only 24-hr supported\n") retval = -ENXIO; goto cleanup1; }