From patchwork Mon Mar 28 06:54:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 88554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-pw0-f56.google.com (mail-pw0-f56.google.com [209.85.160.56]) (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 D43BBB6F89 for ; Mon, 28 Mar 2011 17:52:30 +1100 (EST) Received: by pwj9 with SMTP id 9sf557702pwj.11 for ; Sun, 27 Mar 2011 23:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:mime-version:x-beenthere:received-spf :x-virus-scanned:x-authentication-warning:from:to:cc:subject:date :message-id:x-mailer:x-acl-warn:x-antiabuse:x-antiabuse:x-antiabuse :x-antiabuse:x-antiabuse:x-source:x-source-args:x-source-dir :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=hxpnUHNxy1Q4Yl6SdSfrfa9IN6+AeffwEXKJjMh6GvE=; b=Hikw75KPacr6zzYovazSFR9A9rWkHwq/XsxNPsCVzNakvjrQy+6Mq5wTV/4MTl/u4u dNNSYjlOmDjFy49kPJ5lVUjgb8nE2V3jXJ2pRmdE8toWd4W2WNNlcYobUASbRImYbrgR IDVRDNPsmlGz5cvspa1LVpSeP20pkDxbUSVm8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:x-virus-scanned :x-authentication-warning:from:to:cc:subject:date:message-id :x-mailer:x-acl-warn:x-antiabuse:x-source:x-source-args:x-source-dir :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; b=SfYWoLB4JV0mnWL7tBVJ1Q+CDmBQXUinDbupksel7Bunbg2gsSGU8yDW4Eg7qvsbW1 OW3nY0CpaYbC6KubdQjuKUgaZOIWsKNRUBY7+WFWMExLzlbr57DxdOhFrYWjgkEX9JEl 6JHVapFl+75OzRPvgCOE+6iCECsdVdg0dNYsQ= Received: by 10.142.165.20 with SMTP id n20mr260925wfe.36.1301295146527; Sun, 27 Mar 2011 23:52:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.142.97.18 with SMTP id u18ls5065725wfb.2.p; Sun, 27 Mar 2011 23:52:24 -0700 (PDT) Received: by 10.143.133.5 with SMTP id k5mr3471609wfn.9.1301295144864; Sun, 27 Mar 2011 23:52:24 -0700 (PDT) Received: by 10.143.133.5 with SMTP id k5mr3471608wfn.9.1301295144840; Sun, 27 Mar 2011 23:52:24 -0700 (PDT) Received: from compulab.co.il (compulab.co.il [67.18.134.219]) by gmr-mx.google.com with ESMTPS id k41si3940204wfa.7.2011.03.27.23.52.23 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 27 Mar 2011 23:52:23 -0700 (PDT) Received-SPF: pass (google.com: domain of mike@compulab.co.il designates 67.18.134.219 as permitted sender) client-ip=67.18.134.219; Received: from [62.90.235.247] (helo=zimbra-mta.compulab.co.il) by compulab.site5.com with esmtp (Exim 4.69) (envelope-from ) id 1Q46JI-0007gv-RB; Mon, 28 Mar 2011 01:52:21 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 994127E9048; Mon, 28 Mar 2011 08:52:19 +0200 (IST) X-Virus-Scanned: amavisd-new at compulab.co.il Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g028gt0+nQ-W; Mon, 28 Mar 2011 08:52:18 +0200 (IST) Received: from droid.compulab.local (droid.compulab.local [10.1.1.77]) by zimbra-mta.compulab.co.il (Postfix) with ESMTPS id D59887E8B68; Mon, 28 Mar 2011 08:52:18 +0200 (IST) Received: from droid.compulab.local (localhost, droid, droid.compulab.local [127.0.0.1]) by droid.compulab.local (8.14.4/8.14.0) with ESMTP id p2S6sd6K019112; Mon, 28 Mar 2011 08:54:39 +0200 Received: (from mike@localhost) by droid.compulab.local (8.14.4/8.14.0/Submit) id p2S6sbNX019111; Mon, 28 Mar 2011 08:54:37 +0200 X-Authentication-Warning: droid.compulab.local: mike set sender to mike@compulab.co.il using -f From: Mike Rapoport To: rtc-linux@googlegroups.com Cc: Alessandro Zummo , Andrew Morton , linux-kernel@vger.kernel.org, Mike Rapoport Subject: [rtc-linux] [PATCH RESEND] rtc: add EM3027 rtc driver Date: Mon, 28 Mar 2011 08:54:36 +0200 Message-Id: <1301295276-19082-1-git-send-email-mike@compulab.co.il> X-Mailer: git-send-email 1.7.3.1 X-ACL-Warn: { X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - compulab.site5.com X-AntiAbuse: Original Domain - googlegroups.com X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - compulab.co.il X-Source: X-Source-Args: X-Source-Dir: X-Original-Sender: mike@compulab.co.il X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of mike@compulab.co.il designates 67.18.134.219 as permitted sender) smtp.mail=mike@compulab.co.il 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: , Add support for EM Microelectronic EM3027 RTC chip. Signed-off-by: Mike Rapoport --- drivers/rtc/Kconfig | 9 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-em3027.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 0 deletions(-) create mode 100644 drivers/rtc/rtc-em3027.c diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 4941cad..13a6042 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -354,6 +354,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_EM3027 + tristate "EM Microelectronic EM3027" + help + If you say yes here you get support for the EM + Microelectronic EM3027 RTC chips. + + This driver can also be built as a module. If so, the module + will be called rtc-em3027. + endif # I2C comment "SPI RTC drivers" diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 2afdaf3..d29723f 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o obj-$(CONFIG_RTC_DRV_DS3232) += rtc-ds3232.o obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o +obj-$(CONFIG_RTC_DRV_EM3027) += rtc-em3027.o obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c new file mode 100644 index 0000000..d8e1c25 --- /dev/null +++ b/drivers/rtc/rtc-em3027.c @@ -0,0 +1,161 @@ +/* + * An rtc/i2c driver for the EM Microelectronic EM3027 + * Copyright 2011 CompuLab, Ltd. + * + * Author: Mike Rapoport + * + * Based on rtc-ds1672.c by Alessandro Zummo + * + * 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 + * published by the Free Software Foundation. + */ + +#include +#include +#include + +/* Registers */ +#define EM3027_REG_ON_OFF_CTRL 0x00 +#define EM3027_REG_IRQ_CTRL 0x01 +#define EM3027_REG_IRQ_FLAGS 0x02 +#define EM3027_REG_STATUS 0x03 +#define EM3027_REG_RST_CTRL 0x04 + +#define EM3027_REG_WATCH_SEC 0x08 +#define EM3027_REG_WATCH_MIN 0x09 +#define EM3027_REG_WATCH_HOUR 0x0a +#define EM3027_REG_WATCH_DATE 0x0b +#define EM3027_REG_WATCH_DAY 0x0c +#define EM3027_REG_WATCH_MON 0x0d +#define EM3027_REG_WATCH_YEAR 0x0e + +#define EM3027_REG_ALARM_SEC 0x10 +#define EM3027_REG_ALARM_MIN 0x11 +#define EM3027_REG_ALARM_HOUR 0x12 +#define EM3027_REG_ALARM_DATE 0x13 +#define EM3027_REG_ALARM_DAY 0x14 +#define EM3027_REG_ALARM_MON 0x15 +#define EM3027_REG_ALARM_YEAR 0x16 + +static struct i2c_driver em3027_driver; + +static int em3027_get_time(struct device *dev, struct rtc_time *tm) +{ + struct i2c_client *client = to_i2c_client(dev); + + unsigned char addr = EM3027_REG_WATCH_SEC; + unsigned char buf[7]; + + struct i2c_msg msgs[] = { + {client->addr, 0, 1, &addr}, /* setup read addr */ + {client->addr, I2C_M_RD, 7, buf}, /* read time/date */ + }; + + /* read time/date registers */ + if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { + dev_err(&client->dev, "%s: read error\n", __func__); + return -EIO; + } + + tm->tm_sec = bcd2bin(buf[0]); + tm->tm_min = bcd2bin(buf[1]); + tm->tm_hour = bcd2bin(buf[2]); + tm->tm_mday = bcd2bin(buf[3]); + tm->tm_wday = bcd2bin(buf[4]); + tm->tm_mon = bcd2bin(buf[5]); + tm->tm_year = bcd2bin(buf[6]) + 100; + + return 0; +} + +static int em3027_set_time(struct device *dev, struct rtc_time *tm) +{ + struct i2c_client *client = to_i2c_client(dev); + unsigned char buf[8]; + + struct i2c_msg msg = { + client->addr, 0, 8, buf, /* write time/date */ + }; + + buf[0] = EM3027_REG_WATCH_SEC; + buf[1] = bin2bcd(tm->tm_sec); + buf[2] = bin2bcd(tm->tm_min); + buf[3] = bin2bcd(tm->tm_hour); + buf[4] = bin2bcd(tm->tm_mday); + buf[5] = bin2bcd(tm->tm_wday); + buf[6] = bin2bcd(tm->tm_mon); + buf[7] = bin2bcd(tm->tm_year % 100); + + /* write time/date registers */ + if ((i2c_transfer(client->adapter, &msg, 1)) != 1) { + dev_err(&client->dev, "%s: write error\n", __func__); + return -EIO; + } + + return 0; +} + +static const struct rtc_class_ops em3027_rtc_ops = { + .read_time = em3027_get_time, + .set_time = em3027_set_time, +}; + +static int em3027_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct rtc_device *rtc; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + rtc = rtc_device_register(em3027_driver.driver.name, &client->dev, + &em3027_rtc_ops, THIS_MODULE); + if (IS_ERR(rtc)) + return PTR_ERR(rtc); + + i2c_set_clientdata(client, rtc); + + return 0; +} + +static int em3027_remove(struct i2c_client *client) +{ + struct rtc_device *rtc = i2c_get_clientdata(client); + + if (rtc) + rtc_device_unregister(rtc); + + return 0; +} + +static struct i2c_device_id em3027_id[] = { + { "em3027", 0 }, + { } +}; + +static struct i2c_driver em3027_driver = { + .driver = { + .name = "rtc-em3027", + }, + .probe = &em3027_probe, + .remove = &em3027_remove, + .id_table = em3027_id, +}; + +static int __init em3027_init(void) +{ + return i2c_add_driver(&em3027_driver); +} + +static void __exit em3027_exit(void) +{ + i2c_del_driver(&em3027_driver); +} + +MODULE_AUTHOR("Mike Rapoport "); +MODULE_DESCRIPTION("EM Microelectronic EM3027 RTC driver"); +MODULE_LICENSE("GPL"); + +module_init(em3027_init); +module_exit(em3027_exit);