From patchwork Mon Nov 22 03:54:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jain Priyanka-B32167 X-Patchwork-Id: 72498 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]) by ozlabs.org (Postfix) with ESMTP id BDC35B70EA for ; Mon, 22 Nov 2010 14:54:06 +1100 (EST) Received: by wye20 with SMTP id 20sf3752756wye.11 for ; Sun, 21 Nov 2010 19:54:04 -0800 (PST) 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:received:x-spamscore:x-bigfish :x-spam-tcs-scl:x-forefront-antispam-report:x-fb-ss:received :received:received:received:received:received:received:mime-version :x-mimeole:received:x-originalarrivaltime:accept-language :acceptlanguage:x-ms-has-attach:subject:date:message-id :x-ms-tnef-correlator:thread-topic:thread-index:from:to:cc :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 :content-language:content-class; bh=ySJ9SdxxZt55X93ZjrLiNphH4taraLg1DxXj3TcrMok=; b=lR3jrMGv8PE3a8lv4QEG21XcAd16uW1uJdraionX4M2KdBzL67IQFDy3XERnezIYYH NORjYrUxH9pv9cfpDU7QBEw1OsWK01f+iDErmpc22QNt8uzau9guIx2JKZq7F7BWAtkh YTo86/bLrOg/7Zq83YA6UuNVSP64Kt9dwfjk4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:x-spamscore:x-bigfish:x-spam-tcs-scl :x-forefront-antispam-report:x-fb-ss:mime-version:x-mimeole :x-originalarrivaltime:accept-language:acceptlanguage :x-ms-has-attach:subject:date:message-id:x-ms-tnef-correlator :thread-topic:thread-index:from:to:cc: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 :content-language:content-class; b=gwJS6kExF7c1dx2MddffmKTMfM1cVnF9FmQraMin9ch6cYEKoR+GgDfCHtXnUQeOTH Zv1lUA8oAdaNXQKT0iuKQkO43IXt5D2SE+1IeXqtWdcb9MqZSz68c5fAAvDcVz5OLceA Xfw7PgY47pNoT2Cr26DdtLNvrn1VbkQn5uoKY= Received: by 10.216.4.72 with SMTP id 50mr225939wei.1.1290398042949; Sun, 21 Nov 2010 19:54:02 -0800 (PST) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.216.79.7 with SMTP id h7ls1888441wee.1.p; Sun, 21 Nov 2010 19:54:02 -0800 (PST) Received: by 10.216.154.196 with SMTP id h46mr156127wek.9.1290398041946; Sun, 21 Nov 2010 19:54:01 -0800 (PST) Received: by 10.216.154.196 with SMTP id h46mr156126wek.9.1290398041880; Sun, 21 Nov 2010 19:54:01 -0800 (PST) Received: from DB3EHSOBE004.bigfish.com (db3ehsobe004.messaging.microsoft.com [213.199.154.142]) by gmr-mx.google.com with ESMTP id x80si459471weq.4.2010.11.21.19.54.01; Sun, 21 Nov 2010 19:54:01 -0800 (PST) Received-SPF: neutral (google.com: 213.199.154.142 is neither permitted nor denied by best guess record for domain of B32167@freescale.com) client-ip=213.199.154.142; Received: from mail34-db3-R.bigfish.com (10.3.81.246) by DB3EHSOBE004.bigfish.com (10.3.84.24) with Microsoft SMTP Server id 14.1.225.8; Mon, 22 Nov 2010 03:54:01 +0000 Received: from mail34-db3 (localhost.localdomain [127.0.0.1]) by mail34-db3-R.bigfish.com (Postfix) with ESMTP id 532C13C8177 for ; Mon, 22 Nov 2010 03:54:01 +0000 (UTC) X-SpamScore: -10 X-BigFish: VS-10(zz542N9371Pc8kbd0dizz1202hzz8275bh8275dhz2dh2a8h668h67dh685h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:de01egw01.freescale.net; RD:de01egw01.freescale.net; EFVD:NLI X-FB-SS: 0, Received: from mail34-db3 (localhost.localdomain [127.0.0.1]) by mail34-db3 (MessageSwitch) id 129039803484025_27046; Mon, 22 Nov 2010 03:53:54 +0000 (UTC) Received: from DB3EHSMHS007.bigfish.com (unknown [10.3.81.248]) by mail34-db3.bigfish.com (Postfix) with ESMTP id 1562A1B48074 for ; Mon, 22 Nov 2010 03:53:28 +0000 (UTC) Received: from de01egw01.freescale.net (192.88.165.102) by DB3EHSMHS007.bigfish.com (10.3.87.107) with Microsoft SMTP Server (TLS) id 14.1.225.8; Mon, 22 Nov 2010 03:53:16 +0000 Received: from az33smr01.freescale.net (az33smr01.freescale.net [10.64.34.199]) by de01egw01.freescale.net (8.14.3/8.14.3) with ESMTP id oAM3srEQ001827 for ; Sun, 21 Nov 2010 20:54:53 -0700 (MST) Received: from az33exm21.fsl.freescale.net (az33exm21.am.freescale.net [10.64.32.7]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id oAM3rEcH026385 for ; Sun, 21 Nov 2010 21:53:14 -0600 (CST) Received: from az33exm23.fsl.freescale.net ([10.64.32.8]) by az33exm21.fsl.freescale.net with Microsoft SMTPSVC(6.0.3790.4675); Sun, 21 Nov 2010 20:54:22 -0700 Received: from mail.freescale.net ([10.84.1.13]) by az33exm23.fsl.freescale.net with Microsoft SMTPSVC(6.0.3790.4675); Sun, 21 Nov 2010 20:54:21 -0700 MIME-Version: 1.0 X-MimeOLE: Produced By Microsoft Exchange V6.5 Received: from 039-SN1MPN1-001.039d.mgd.msft.net ([169.254.1.218]) by 039-SN1MMR1-001.039d.mgd.msft.net ([10.84.1.13]) with mapi; Sun, 21 Nov 2010 21:53:14 -0600 X-OriginalArrivalTime: 22 Nov 2010 03:54:21.0016 (UTC) FILETIME=[F1B38580:01CB89F8] Accept-Language: en-US acceptlanguage: en-US X-MS-Has-Attach: Subject: [rtc-linux] FW: [PATCH][v1] RTC driver(Linux) for PT7C4338 chip. Date: Sun, 21 Nov 2010 20:54:17 -0700 Message-ID: <470DB7CE2CD0944E9436E7ADEFC02FE3039A67@039-SN1MPN1-001.039d.mgd.msft.net> X-MS-TNEF-Correlator: Thread-Topic: [PATCH][v1] RTC driver(Linux) for PT7C4338 chip. Thread-Index: Act08hFS6XSnRx01Rx+f9lEQCRfyrwMYw2OAAijmK/A= From: Jain Priyanka-B32167 To: Alessandro Zummo CC: X-OriginatorOrg: freescale.com X-Original-Sender: b32167@freescale.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 213.199.154.142 is neither permitted nor denied by best guess record for domain of B32167@freescale.com) smtp.mail=B32167@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: , Content-Language: en-US Content-Class: urn:content-classes:message Hi, Please review and acknowledge this patch. Thanks and Regards Priyanka -----Original Message----- From: Jain Priyanka-B32167 Sent: Thursday, November 11, 2010 9:36 AM To: Jain Priyanka-B32167; rtc-linux@googlegroups.com; linuxppc-dev@lists.ozlabs.org Subject: RE: [PATCH][v1] RTC driver(Linux) for PT7C4338 chip. Hi, I am waiting for review comments and acknowledgement that this patch will be pick up for open source. Please acknowledge. Regards Priyanka Jain -----Original Message----- From: Jain Priyanka-B32167 Sent: Tuesday, October 26, 2010 3:12 PM To: rtc-linux@googlegroups.com; linuxppc-dev@lists.ozlabs.org Cc: Jain Priyanka-B32167 Subject: [PATCH][v1] RTC driver(Linux) for PT7C4338 chip. PT7C4338 chip is being manufactured by Pericom Technology Inc. It is a serial real-time clock which provides: 1)Low-power clock/calendar. 2)Programmable square-wave output. It has 56 bytes of nonvolatile RAM. Signed-off-by: Priyanka Jain --- PT7C4338 RTC driver is verified on Freescale P1010RDB. Changes for v1: Incoperated Kumar Gala's review comments -Removing board name from commit messages. drivers/rtc/Kconfig | 9 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-pt7c4338.c | 215 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-pt7c4338.c +MODULE_AUTHOR("Priyanka Jain "); +MODULE_DESCRIPTION("pericom Technology Inc. PT7C4338 RTC Driver"); +MODULE_LICENSE("GPL"); -- 1.6.5.6 diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 10ba12c..6ff0901 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -324,6 +324,15 @@ config RTC_DRV_RX8025 This driver can also be built as a module. If so, the module will be called rtc-rx8025. +config RTC_DRV_PT7C4338 + tristate "Pericom Technology Inc. PT7C4338 RTC" + help + If you say yes here you get support for the Pericom Technology + Inc. PT7C4338 RTC chip. + + This driver can also be built as a module. If so, the module + will be called rtc-pt7c4338. + endif # I2C comment "SPI RTC drivers" diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 5adbba7..4014607 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -70,6 +70,7 @@ obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o +obj-$(CONFIG_RTC_DRV_PT7C4338) += rtc-pt7c4338.o obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o obj-$(CONFIG_RTC_DRV_RP5C01) += rtc-rp5c01.o diff --git a/drivers/rtc/rtc-pt7c4338.c b/drivers/rtc/rtc-pt7c4338.c new file mode 100644 index 0000000..fca52cd --- /dev/null +++ b/drivers/rtc/rtc-pt7c4338.c @@ -0,0 +1,215 @@ +/* + * Copyright 2010 Freescale Semiconductor, Inc. + * + * Author: Priyanka Jain + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +/* + * This file provides Date & Time support (no alarms) for PT7C4338 chip. + * + * This file is based on drivers/rtc/rtc-ds1307.c + * + * PT7C4338 chip is manufactured by Pericom Technology Inc. + * It is a serial real-time clock which provides + * 1)Low-power clock/calendar. + * 2)Programmable square-wave output. + * It has 56 bytes of nonvolatile RAM. + */ + +#include +#include +#include +#include +#include + +/* RTC register addresses */ +#define PT7C4338_REG_SECONDS 0x00 +#define PT7C4338_REG_MINUTES 0x01 +#define PT7C4338_REG_HOURS 0x02 +#define PT7C4338_REG_AMPM 0x02 +#define PT7C4338_REG_DAY 0x03 +#define PT7C4338_REG_DATE 0x04 +#define PT7C4338_REG_MONTH 0x05 +#define PT7C4338_REG_YEAR 0x06 +#define PT7C4338_REG_CTRL_STAT 0x07 + +/* RTC second register address bit */ +#define PT7C4338_SEC_BIT_CH 0x80 /*Clock Halt (in Register 0)*/ + +/* RTC control and status register bits */ +#define PT7C4338_CTRL_STAT_BIT_RS0 0x1 /*Rate select 0*/ +#define PT7C4338_CTRL_STAT_BIT_RS1 0x2 /*Rate select 1*/ +#define PT7C4338_CTRL_STAT_BIT_SQWE 0x10 /*Square Wave Enable*/ +#define PT7C4338_CTRL_STAT_BIT_OSF 0x20 /*Oscillator Stop Flag*/ +#define PT7C4338_CTRL_STAT_BIT_OUT 0x80 /*Output Level Control*/ + +static const struct i2c_device_id pt7c4338_id[] = { + { "pt7c4338", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, pt7c4338_id); + +struct pt7c4338{ + struct i2c_client *client; + struct rtc_device *rtc; +}; + +static int pt7c4338_read_time(struct device *dev, struct rtc_time +*time) { + struct i2c_client *client = to_i2c_client(dev); + int ret; + u8 buf[7]; + u8 year, month, day, hour, minute, second; + u8 week, twelve_hr, am_pm; + + ret = i2c_smbus_read_i2c_block_data(client, + PT7C4338_REG_SECONDS, 7, buf); + if (ret < 0) + return ret; + if (ret < 7) + return -EIO; + + second = buf[0]; + minute = buf[1]; + hour = buf[2]; + week = buf[3]; + day = buf[4]; + month = buf[5]; + year = buf[6]; + + /* Extract additional information for AM/PM */ + twelve_hr = hour & 0x40; + am_pm = hour & 0x20; + + /* Write to rtc_time structure */ + time->tm_sec = bcd2bin(second & 0x7f); + time->tm_min = bcd2bin(minute & 0x7f); + if (twelve_hr) { + /* Convert to 24 hr */ + if (am_pm) + time->tm_hour = bcd2bin(hour & 0x10) + 12; + else + time->tm_hour = bcd2bin(hour & 0xBF); + } else { + time->tm_hour = bcd2bin(hour); + } + + time->tm_wday = bcd2bin(week & 0x07) - 1; + time->tm_mday = bcd2bin(day & 0x3f); + time->tm_mon = bcd2bin(month & 0x1F) - 1; + /* assume 20YY not 19YY */ + time->tm_year = bcd2bin(year) + 100; + + return 0; +} + +static int pt7c4338_set_time(struct device *dev, struct rtc_time *time) +{ + struct i2c_client *client = to_i2c_client(dev); + u8 buf[7]; + + /* Extract time from rtc_time and load into pt7c4338*/ + buf[0] = bin2bcd(time->tm_sec); + buf[1] = bin2bcd(time->tm_min); + buf[2] = bin2bcd(time->tm_hour); + buf[3] = bin2bcd(time->tm_wday + 1); /* Day of the week */ + buf[4] = bin2bcd(time->tm_mday); /* Date */ + buf[5] = bin2bcd(time->tm_mon + 1); + + /* assume 20YY not 19YY */ + if (time->tm_year >= 100) + buf[6] = bin2bcd(time->tm_year - 100); + else + buf[6] = bin2bcd(time->tm_year); + + return i2c_smbus_write_i2c_block_data(client, + PT7C4338_REG_SECONDS, 7, buf); +} + +static const struct rtc_class_ops pt7c4338_rtc_ops = { + .read_time = pt7c4338_read_time, + .set_time = pt7c4338_set_time, +}; + +static int pt7c4338_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pt7c4338 *pt7c4338; + struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); + int ret; + + pt7c4338 = kzalloc(sizeof(struct pt7c4338), GFP_KERNEL); + if (!pt7c4338) + return -ENOMEM; + + pt7c4338->client = client; + i2c_set_clientdata(client, pt7c4338); + pt7c4338->rtc = rtc_device_register(client->name, &client->dev, + &pt7c4338_rtc_ops, THIS_MODULE); + if (IS_ERR(pt7c4338->rtc)) { + ret = PTR_ERR(pt7c4338->rtc); + dev_err(&client->dev, "unable to register the class device\n"); + goto out_free; + } + + return 0; +out_free: + i2c_set_clientdata(client, NULL); + kfree(pt7c4338); + return ret; +} + +static int __devexit pt7c4338_remove(struct i2c_client *client) { + struct pt7c4338 *pt7c4338 = i2c_get_clientdata(client); + + rtc_device_unregister(pt7c4338->rtc); + i2c_set_clientdata(client, NULL); + kfree(pt7c4338); + return 0; +} + +static struct i2c_driver pt7c4338_driver = { + .driver = { + .name = "rtc-pt7c4338", + .owner = THIS_MODULE, + }, + .probe = pt7c4338_probe, + .remove = __devexit_p(pt7c4338_remove), + .id_table = pt7c4338_id, +}; + +static int __init pt7c4338_init(void) +{ + return i2c_add_driver(&pt7c4338_driver); } + +static void __exit pt7c4338_exit(void) +{ + i2c_del_driver(&pt7c4338_driver); +} + +module_init(pt7c4338_init); +module_exit(pt7c4338_exit); +