From patchwork Fri Jan 2 21:32:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Fuchs X-Patchwork-Id: 16346 X-Patchwork-Delegate: azummo-patchwork@towertech.it Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from yw-out-2122.google.com (yw-out-2122.google.com [74.125.46.26]) by ozlabs.org (Postfix) with ESMTP id DCA63DE0F1 for ; Sat, 3 Jan 2009 08:33:01 +1100 (EST) Received: by yw-out-2122.google.com with SMTP id 7so1859443ywi.11 for ; Fri, 02 Jan 2009 13:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received-spf:authentication-results:received :received:received:received:from:to:subject:date:user-agent :organization:mime-version:content-type:message-id:x-virus-scanned :x-virus-status:reply-to:sender:precedence:x-google-loop :mailing-list:list-id:list-post:list-help:list-unsubscribe :x-beenthere-env:x-beenthere; bh=rRCjUom+mi5gTtqqKc5lh4g2ELp5CgMfp3j0AG6LEjs=; b=glI5jB0wqiEgtv6Wb4Vxfv6+nSYxGXMDRsbHN64+zCH9XF05h0vtvjRrnXRyyH87fk ZM6dzoGMgOHiifgTcCgdsWGFXzNtrxFvt7tN6o/WVCKl9Go5LNcNsljhnni/kNP5PHsH LJggqsLxjzkWUCvDeLMIRnZAGaKRWl731g6mY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results:from :to:subject:date:user-agent:organization:mime-version:content-type :message-id:x-virus-scanned:x-virus-status:reply-to:sender :precedence:x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; b=Qo2j06hMYT4BtpzOdzwBO4vsW47iuWCkgrsw/seGpshsgdklK7NbVEoC5tO80lxiaf moDMk+cQTk5EIZ72oP4720mansF1S/48vcyLlUcRZVs3Uue/C3vF6RyBibvelX9BxG8o ORygsBVwSFm+rHqNFwngiBdEFhMNN3MAXFM90= Received: by 10.90.115.17 with SMTP id n17mr1890445agc.21.1230931977478; Fri, 02 Jan 2009 13:32:57 -0800 (PST) Received: by 10.176.226.7 with SMTP id y7gr1754yqg.0; Fri, 02 Jan 2009 13:32:57 -0800 (PST) X-Sender: matthias.fuchs@esd-electronics.com X-Apparently-To: rtc-linux@googlegroups.com Received: by 10.90.100.17 with SMTP id x17mr6084543agb.18.1230931971475; Fri, 02 Jan 2009 13:32:51 -0800 (PST) Received: from mail-in-10.arcor-online.net (mail-in-10.arcor-online.net [151.189.21.50]) by mx.google.com with ESMTP id 22si9894686yxr.16.2009.01.02.13.32.50; Fri, 02 Jan 2009 13:32:51 -0800 (PST) Received-SPF: neutral (google.com: 151.189.21.50 is neither permitted nor denied by best guess record for domain of matthias.fuchs@esd-electronics.com) client-ip=151.189.21.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 151.189.21.50 is neither permitted nor denied by best guess record for domain of matthias.fuchs@esd-electronics.com) smtp.mail=matthias.fuchs@esd-electronics.com Received: from mail-in-13-z2.arcor-online.net (mail-in-13-z2.arcor-online.net [151.189.8.30]) by mail-in-10.arcor-online.net (Postfix) with ESMTP id 3B7BA1F517B for ; Fri, 2 Jan 2009 22:32:50 +0100 (CET) Received: from mail-in-06.arcor-online.net (mail-in-06.arcor-online.net [151.189.21.46]) by mail-in-13-z2.arcor-online.net (Postfix) with ESMTP id 1CB681B8E45 for ; Fri, 2 Jan 2009 22:32:50 +0100 (CET) Received: from bunny.home (dslb-088-070-064-025.pools.arcor-ip.net [88.70.64.25]) by mail-in-06.arcor-online.net (Postfix) with ESMTP id D04B435E6A5 for ; Fri, 2 Jan 2009 22:32:49 +0100 (CET) Received: from fox.localnet (fox.home [192.168.2.13]) by bunny.home (Postfix) with ESMTPS id EBE4B25107F3 for ; Fri, 2 Jan 2009 22:32:51 +0100 (CET) From: Matthias Fuchs To: rtc-linux@googlegroups.com Subject: [rtc-linux] [PATCH] rtc: Add EPSON RX8025 support to DS1307 RTC driver Date: Fri, 2 Jan 2009 22:32:48 +0100 User-Agent: KMail/1.10.3 (Linux/2.6.27-9-generic; KDE/4.1.3; i686; ; ) Organization: esd gmbh Mime-Version: 1.0 Message-Id: <200901022232.48593.matthias.fuchs@esd-electronics.com> X-Virus-Scanned: ClamAV 0.94.1/8830/Fri Jan 2 17:01:42 2009 on mail-in-06.arcor-online.net X-Virus-Status: Clean Reply-To: rtc-linux@googlegroups.com Sender: rtc-linux@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rtc-linux@googlegroups.com; contact rtc-linux+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rtc-linux@googlegroups.com X-BeenThere: rtc-linux@googlegroups.com This patch adds support for the EPSON RX8025 RTC. The date/time registers of this chip are compatible to the DS1307. Signed-off-by: Matthias Fuchs --- drivers/rtc/Kconfig | 7 ++-- drivers/rtc/rtc-ds1307.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 123092d..00492d2 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -125,13 +125,14 @@ comment "I2C RTC drivers" if I2C config RTC_DRV_DS1307 - tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00" + tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025" help If you say yes here you get support for various compatible RTC chips (often with battery backup) connected with I2C. This driver should handle DS1307, DS1337, DS1338, DS1339, DS1340, ST M41T00, - and probably other chips. In some cases the RTC must already - have been initialized (by manufacturing or a bootloader). + EPSON RX-8025 and probably other chips. In some cases the RTC + must already have been initialized (by manufacturing or a + bootloader). The first seven registers on these chips hold an RTC, and other registers may add features such as NVRAM, a trickle charger for diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 162330b..a181272 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -3,6 +3,7 @@ * * Copyright (C) 2005 James Chapman (ds1337 core) * Copyright (C) 2006 David Brownell + * Copyright (C) 2009 Matthias Fuchs (rx8025 support) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -31,6 +32,7 @@ enum ds_type { ds_1339, ds_1340, m41t00, + rx_8025, // rs5c372 too? different address... }; @@ -83,6 +85,12 @@ enum ds_type { #define DS1339_REG_ALARM1_SECS 0x07 #define DS1339_REG_TRICKLE 0x10 +#define RX8025_REG_CTRL1 0x0e +# define RX8025_BIT_2412 0x20 +#define RX8025_REG_CTRL2 0x0f +# define RX8025_BIT_PON 0x10 +# define RX8025_BIT_VDET 0x40 +# define RX8025_BIT_XST 0x20 struct ds1307 { @@ -119,6 +127,8 @@ static const struct chip_desc chips[] = { [ds_1340] = { }, [m41t00] = { +}, +[rx_8025] = { }, }; static const struct i2c_device_id ds1307_id[] = { @@ -128,6 +138,7 @@ static const struct i2c_device_id ds1307_id[] = { { "ds1339", ds_1339 }, { "ds1340", ds_1340 }, { "m41t00", m41t00 }, + { "rx8025", rx_8025 }, { } }; MODULE_DEVICE_TABLE(i2c, ds1307_id); @@ -641,6 +652,77 @@ static int __devinit ds1307_probe(struct i2c_client *client, dev_warn(&client->dev, "SET TIME!\n"); } break; + + case rx_8025: + ds1307->reg_addr = RX8025_REG_CTRL1 << 4 | 0x08; + ds1307->msg[1].len = 2; + + tmp = i2c_transfer(adapter, ds1307->msg, 2); + if (tmp != 2) { + pr_debug("read error %d\n", tmp); + err = -EIO; + goto exit_free; + } + + ds1307->reg_addr = 0; + ds1307->msg[1].len = sizeof(ds1307->regs); + + /* oscillator off? turn it on, so clock can tick. */ + if (!(ds1307->regs[1] & RX8025_BIT_XST)) { + ds1307->regs[1] |= RX8025_BIT_XST; + i2c_smbus_write_byte_data(client, + RX8025_REG_CTRL2 << 4 | 0x08, + ds1307->regs[1]); + dev_warn(&client->dev, + "oscillator stop detected - SET TIME!\n"); + } + + if (ds1307->regs[1] & RX8025_BIT_PON) { + ds1307->regs[1] &= ~RX8025_BIT_PON; + i2c_smbus_write_byte_data(client, + RX8025_REG_CTRL2 << 4 | 0x08, + ds1307->regs[1]); + dev_warn(&client->dev, "power-on detected\n"); + } + + if (ds1307->regs[1] & RX8025_BIT_VDET) { + ds1307->regs[1] &= ~RX8025_BIT_VDET; + i2c_smbus_write_byte_data(client, + RX8025_REG_CTRL2 << 4 | 0x08, + ds1307->regs[1]); + dev_warn(&client->dev, "voltage drop detected\n"); + } + + /* make sure we are running in 24hour mode */ + if (!(ds1307->regs[0] & RX8025_BIT_2412)) { + u8 hour; + + /* switch to 24 hour mode */ + i2c_smbus_write_byte_data(client, + RX8025_REG_CTRL1 << 4 | 0x08, + ds1307->regs[0] | + RX8025_BIT_2412); + + tmp = i2c_transfer(adapter, ds1307->msg, 2); + if (tmp != 2) { + pr_debug("read error %d\n", tmp); + err = -EIO; + goto exit_free; + } + + /* correct hour */ + hour = bcd2bin(ds1307->regs[DS1307_REG_HOUR]); + if (hour == 12) + hour = 0; + if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) + hour += 12; + + i2c_smbus_write_byte_data(client, + DS1307_REG_HOUR << 4 | 0x08, + hour); + } + + break; default: break; } @@ -702,6 +784,7 @@ read_rtc: dev_warn(&client->dev, "SET TIME!\n"); } break; + case rx_8025: case ds_1337: case ds_1339: break; @@ -731,6 +814,8 @@ read_rtc: * systems that will run through year 2100. */ break; + case rx_8025: + break; default: if (!(tmp & DS1307_BIT_12HR)) break;