From patchwork Tue Jan 25 04:53:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varun Wadekar X-Patchwork-Id: 80314 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-pv0-f184.google.com (mail-pv0-f184.google.com [74.125.83.184]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id BA6241007D1 for ; Tue, 25 Jan 2011 15:53:13 +1100 (EST) Received: by pvg11 with SMTP id 11sf1673015pvg.11 for ; Mon, 24 Jan 2011 20:53:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:x-beenthere:received-spf:x-pgp-universal :message-id:date:from:organization:user-agent:mime-version:to:cc :subject: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; bh=ApAsWq33Lta4sUl6TFCPRRFr0vw7ZaclhDi94bFL0VI=; b=e9AQBRMBjXOm/cbW60SpbPHuXNMxTrwcGHd8H1N+08MLHwYUT2tgGwyoajFluLnkLi O8q8mxoDtFU91yYL8B8Q0J/dEaepd8anyAxhj/p6Isp9AvNBCQX0fPePalBzUa3z6f+i Pii9RmMvVyFJRX1xGsvYuzdt9rW0m50HIn0t4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:x-pgp-universal:message-id:date:from :organization:user-agent:mime-version:to:cc:subject :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; b=EhGDWuyPXXc5d82D4yvVRmkpDYgMfGZ2G0nFFbxIL8VenckFzG2ZFoDBNyF8drM+R1 +IkYf+OuW06f+e/5BQf3kGz6Xcvr/oqt2iXpsrnO3VnqAl0iO/mmelx6dxsOdccw3Eoe bLyusx4KuzXHv9irtW3Jq7wQYV6nqy81aqOQs= Received: by 10.142.126.13 with SMTP id y13mr266926wfc.56.1295931190791; Mon, 24 Jan 2011 20:53:10 -0800 (PST) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.142.2.41 with SMTP id 41ls143883wfb.0.p; Mon, 24 Jan 2011 20:53:10 -0800 (PST) Received: by 10.142.132.7 with SMTP id f7mr1013274wfd.19.1295931190187; Mon, 24 Jan 2011 20:53:10 -0800 (PST) Received: by 10.142.132.7 with SMTP id f7mr1013273wfd.19.1295931190146; Mon, 24 Jan 2011 20:53:10 -0800 (PST) Received: from hqemgate03.nvidia.com (hqemgate03.nvidia.com [216.228.121.140]) by gmr-mx.google.com with ESMTPS id f13si15173360wfo.4.2011.01.24.20.53.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 24 Jan 2011 20:53:10 -0800 (PST) Received-SPF: pass (google.com: domain of vwadekar@nvidia.com designates 216.228.121.140 as permitted sender) client-ip=216.228.121.140; Received: from hqnvupgp05.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com id ; Mon, 24 Jan 2011 20:59:51 -0800 Received: from hqemhub01.nvidia.com ([172.17.108.22]) by hqnvupgp05.nvidia.com (PGP Universal service); Mon, 24 Jan 2011 20:42:02 -0800 X-PGP-Universal: processed; by hqnvupgp05.nvidia.com on Mon, 24 Jan 2011 20:42:02 -0800 Received: from [10.24.109.4] (172.20.144.16) by hqemhub01.nvidia.com (172.17.98.26) with Microsoft SMTP Server id 8.2.254.0; Mon, 24 Jan 2011 20:53:08 -0800 Message-ID: <4D3E5731.4000809@nvidia.com> Date: Tue, 25 Jan 2011 10:23:05 +0530 From: Varun Wadekar Organization: NVIDIA Corporation User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: CC: Alessandro Zummo , "linux-tegra@vger.kernel.org" , Andy Ritger , Stephen Warren , Bharat Nihalani , Varun Wadekar Subject: [rtc-linux] [PATCH 0/2] rtc: tps6586x: add RTC driver for TI TPS6586x X-Original-Sender: vwadekar@nvidia.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of vwadekar@nvidia.com designates 216.228.121.140 as permitted sender) smtp.mail=vwadekar@nvidia.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: , ---- rtc: tps6586x: add RTC driver for TI TPS6586x Signed-off-by: Gary King +MODULE_AUTHOR("NVIDIA Corporation"); +MODULE_LICENSE("GPL"); nvpublic diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 48ca713..241c7f7 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -286,6 +286,13 @@ config RTC_DRV_DM355EVM help Supports the RTC firmware in the MSP430 on the DM355 EVM. +config RTC_DRV_TPS6586X + tristate "TI TPS6586X RTC" + depends on I2C + select MFD_TPS6586X + help + This driver supports TPS6586X RTC + config RTC_DRV_TWL92330 boolean "TI TWL92330/Menelaus" depends on MENELAUS diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 0f207b3..acd8426 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -91,6 +91,7 @@ obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o obj-$(CONFIG_RTC_DRV_STMP) += rtc-stmp3xxx.o obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o +obj-$(CONFIG_RTC_DRV_TPS6586X) += rtc-tps6586x.o obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c new file mode 100644 index 0000000..f898f40 --- /dev/null +++ b/drivers/rtc/rtc-tps6586x.c @@ -0,0 +1,203 @@ +/* + * drivers/rtc/rtc-tps6586x.c + * + * RTC driver for TI TPS6586x + * + * Copyright (c) 2010, NVIDIA Corporation. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define TPS_EPOCH 2009 + +#define RTC_CTRL 0xc0 +#define RTC_ENABLE (1 << 5) /* enables tick updates */ +#define RTC_HIRES (1 << 4) /* 1Khz or 32Khz updates */ +#define RTC_ALARM1_HI 0xc1 +#define RTC_COUNT4 0xc6 + +struct tps6586x_rtc { + unsigned long epoch_start; + struct rtc_device *rtc; +}; + +static inline struct device *to_tps6586x_dev(struct device *dev) +{ + return dev->parent; +} + +static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct tps6586x_rtc *rtc = dev_get_drvdata(dev); + struct device *tps_dev = to_tps6586x_dev(dev); + unsigned long long ticks = 0; + unsigned long seconds; + u8 buff[5]; + int err; + int i; + + err = tps6586x_reads(tps_dev, RTC_COUNT4, sizeof(buff), buff); + if (err < 0) { + dev_err(dev, "failed to read counter\n"); + return err; + } + + for (i = 0; i < sizeof(buff); i++) { + ticks <<= 8; + ticks |= buff[i]; + } + + seconds = ticks >> 10; + + seconds += rtc->epoch_start; + rtc_time_to_tm(seconds, tm); + return rtc_valid_tm(tm); +} + +static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct tps6586x_rtc *rtc = dev_get_drvdata(dev); + struct device *tps_dev = to_tps6586x_dev(dev); + unsigned long long ticks; + unsigned long seconds; + u8 buff[5]; + int err; + + rtc_tm_to_time(tm, &seconds); + + if (WARN_ON(seconds < rtc->epoch_start)) { + dev_err(dev, "requested time unsupported\n"); + return -EINVAL; + } + + seconds -= rtc->epoch_start; + + ticks = seconds << 10; + buff[0] = (ticks >> 32) & 0xff; + buff[1] = (ticks >> 24) & 0xff; + buff[2] = (ticks >> 16) & 0xff; + buff[3] = (ticks >> 8) & 0xff; + buff[4] = ticks & 0xff; + + dev_info(dev, "setting time to %lu seconds (%llu ticks)\n", + seconds, ticks); + + + err = tps6586x_clr_bits(tps_dev, RTC_CTRL, RTC_ENABLE); + if (err < 0) { + dev_err(dev, "failed to clear RTC_ENABLE\n"); + return err; + } + + err = tps6586x_writes(tps_dev, RTC_COUNT4, sizeof(buff), buff); + if (err < 0) { + dev_err(dev, "failed to program new time\n"); + return err; + } + + err = tps6586x_set_bits(tps_dev, RTC_CTRL, RTC_ENABLE); + if (err < 0) { + dev_err(dev, "failed to set RTC_ENABLE\n"); + return err; + } + + return 0; +} + +static const struct rtc_class_ops tps6586x_rtc_ops = { + .read_time = tps6586x_rtc_read_time, + .set_time = tps6586x_rtc_set_time, +}; + +static int __devinit tps6586x_rtc_probe(struct platform_device *pdev) +{ + struct device *tps_dev = to_tps6586x_dev(&pdev->dev); + struct tps6586x_rtc *rtc; + int err; + + rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); + + if (!rtc) + return -ENOMEM; + + rtc->epoch_start = mktime(TPS_EPOCH, 1, 1, 0, 0, 0); + rtc->rtc = rtc_device_register("tps6586x-rtc", &pdev->dev, + &tps6586x_rtc_ops, THIS_MODULE); + + if (IS_ERR(rtc->rtc)) { + err = PTR_ERR(rtc->rtc); + goto fail; + } + + /* disable high-res mode, enable tick counting */ + err = tps6586x_update(tps_dev, RTC_CTRL, + (RTC_ENABLE | RTC_HIRES), RTC_ENABLE); + if (err < 0) { + dev_err(&pdev->dev, "unable to start counter\n"); + goto fail; + } + + dev_set_drvdata(&pdev->dev, rtc); + return 0; + +fail: + if (!IS_ERR_OR_NULL(rtc->rtc)) + rtc_device_unregister(rtc->rtc); + kfree(rtc); + return err; +} + +static int __devexit tps6586x_rtc_remove(struct platform_device *pdev) +{ + struct tps6586x_rtc *rtc = dev_get_drvdata(&pdev->dev); + + rtc_device_unregister(rtc->rtc); + kfree(rtc); + return 0; +} + +static struct platform_driver tps6586x_rtc_driver = { + .driver = { + .name = "tps6586x-rtc", + .owner = THIS_MODULE, + }, + .probe = tps6586x_rtc_probe, + .remove = __devexit_p(tps6586x_rtc_remove), +}; + +static int __init tps6586x_rtc_init(void) +{ + return platform_driver_register(&tps6586x_rtc_driver); +} +module_init(tps6586x_rtc_init); + +static void __exit tps6586x_rtc_exit(void) +{ + platform_driver_unregister(&tps6586x_rtc_driver); +} +module_exit(tps6586x_rtc_exit); + +MODULE_DESCRIPTION("TI TPS6586x RTC driver");