From patchwork Sun Sep 25 22:42:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Anders X-Patchwork-Id: 116330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-gx0-f184.google.com (mail-gx0-f184.google.com [209.85.161.184]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 9D7A4B6F6F for ; Mon, 26 Sep 2011 08:42:37 +1000 (EST) Received: by gxk5 with SMTP id 5sf6047321gxk.11 for ; Sun, 25 Sep 2011 15:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=HYSkrF+4XF0ljmO3FHY+vcTslsNqp706CN5bS7rwmxc=; b=Nvr7YE9qrxiFscudW7MyBjS2G4nyqnTbzjG+/xF1Xx2DvByCAkZrKg7VutgZQW0lhe tp/0ipuO/DnIhkpqPjaR3Fcj219YNtbnk1TqXOc5ELPy7Vei3PhxRSdoMe7CugAcrvfm 70CxuAN5nSWx2PIO/B/zTpjhGOntkhDK3WcX8= Received: by 10.236.181.162 with SMTP id l22mr4844361yhm.7.1316990553216; Sun, 25 Sep 2011 15:42:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.101.195.23 with SMTP id x23ls4381291anp.7.gmail; Sun, 25 Sep 2011 15:42:32 -0700 (PDT) Received: by 10.101.90.1 with SMTP id s1mr5275091anl.9.1316990552883; Sun, 25 Sep 2011 15:42:32 -0700 (PDT) Received: by 10.101.90.1 with SMTP id s1mr5275090anl.9.1316990552867; Sun, 25 Sep 2011 15:42:32 -0700 (PDT) Received: from mail-yx0-f171.google.com (mail-yx0-f171.google.com [209.85.213.171]) by gmr-mx.google.com with ESMTPS id g1si19644970anp.1.2011.09.25.15.42.32 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 25 Sep 2011 15:42:32 -0700 (PDT) Received-SPF: pass (google.com: domain of danders.dev@gmail.com designates 209.85.213.171 as permitted sender) client-ip=209.85.213.171; Received: by yxt3 with SMTP id 3so6019936yxt.30 for ; Sun, 25 Sep 2011 15:42:32 -0700 (PDT) Received: by 10.150.178.15 with SMTP id a15mr458007ybf.28.1316990552605; Sun, 25 Sep 2011 15:42:32 -0700 (PDT) Received: from localhost.localdomain (ppp-70-249-146-60.dsl.rcsntx.swbell.net. [70.249.146.60]) by mx.google.com with ESMTPS id 38sm22529977anu.24.2011.09.25.15.42.31 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 25 Sep 2011 15:42:32 -0700 (PDT) From: David Anders To: rtc-linux@googlegroups.com Cc: akpm@linux-foundation.org, a.zummo@towertech.it, x0132446@ti.com, David Anders Subject: [rtc-linux] [PATCH v2] rtc: add initial support for mcp7941x parts Date: Sun, 25 Sep 2011 17:42:13 -0500 Message-Id: <1316990533-14971-1-git-send-email-danders.dev@gmail.com> X-Mailer: git-send-email 1.7.0.4 X-Original-Sender: danders.dev@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of danders.dev@gmail.com designates 209.85.213.171 as permitted sender) smtp.mail=danders.dev@gmail.com; dkim=pass (test mode) header.i=@gmail.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , this patch adds initial support for the microchip mcp7941x series of real time clocks. the mcp7941x series is generally compatible with the ds1307 and ds1337 rtc devices from dallas semiconductor. minor differences include a backup battery enable bit, and the polarity of the oscillator enable bit. Signed-off-by: David Anders Reviewed-by: Wolfram Sang --- drivers/rtc/rtc-ds1307.c | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index b2005b4..62b0763 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -34,6 +34,7 @@ enum ds_type { ds_1388, ds_3231, m41t00, + mcp7941x, rx_8025, // rs5c372 too? different address... }; @@ -43,6 +44,7 @@ enum ds_type { #define DS1307_REG_SECS 0x00 /* 00-59 */ # define DS1307_BIT_CH 0x80 # define DS1340_BIT_nEOSC 0x80 +# define MCP7941X_BIT_ST 0x80 #define DS1307_REG_MIN 0x01 /* 00-59 */ #define DS1307_REG_HOUR 0x02 /* 00-23, or 1-12{am,pm} */ # define DS1307_BIT_12HR 0x40 /* in REG_HOUR */ @@ -50,6 +52,7 @@ enum ds_type { # define DS1340_BIT_CENTURY_EN 0x80 /* in REG_HOUR */ # define DS1340_BIT_CENTURY 0x40 /* in REG_HOUR */ #define DS1307_REG_WDAY 0x03 /* 01-07 */ +# define MCP7941X_BIT_VBATEN 0x08 #define DS1307_REG_MDAY 0x04 /* 01-31 */ #define DS1307_REG_MONTH 0x05 /* 01-12 */ # define DS1337_BIT_CENTURY 0x80 /* in REG_MONTH */ @@ -137,6 +140,8 @@ static const struct chip_desc chips[] = { }, [m41t00] = { }, +[mcp7941x] = { +}, [rx_8025] = { }, }; @@ -149,6 +154,7 @@ static const struct i2c_device_id ds1307_id[] = { { "ds1340", ds_1340 }, { "ds3231", ds_3231 }, { "m41t00", m41t00 }, + { "mcp7941x", mcp7941x }, { "pt7c4338", ds_1307 }, { "rx8025", rx_8025 }, { } @@ -365,6 +371,10 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t) buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY_EN | DS1340_BIT_CENTURY; break; + case mcp7941x: + buf[DS1307_REG_SECS] |= MCP7941X_BIT_ST; + buf[DS1307_REG_WDAY] |= MCP7941X_BIT_VBATEN; + break; default: break; } @@ -809,6 +819,23 @@ read_rtc: dev_warn(&client->dev, "SET TIME!\n"); } break; + case mcp7941x: + /* make sure that the backup battery is enabled */ + if (!(ds1307->regs[DS1307_REG_WDAY] & MCP7941X_BIT_VBATEN)) { + i2c_smbus_write_byte_data(client, DS1307_REG_WDAY, + ds1307->regs[DS1307_REG_WDAY] + | MCP7941X_BIT_VBATEN); + } + + /* clock halted? turn it on, so clock can tick. */ + if (!(tmp & MCP7941X_BIT_ST)) { + i2c_smbus_write_byte_data(client, DS1307_REG_SECS, + MCP7941X_BIT_ST); + dev_warn(&client->dev, "SET TIME!\n"); + goto read_rtc; + } + + break; case rx_8025: case ds_1337: case ds_1339: