From patchwork Tue Apr 18 05:20:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keerthy X-Patchwork-Id: 9684955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 025BF602C9 for ; Tue, 18 Apr 2017 05:22:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC8762832D for ; Tue, 18 Apr 2017 05:22:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDBEF28354; Tue, 18 Apr 2017 05:22:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49B0E2832D for ; Tue, 18 Apr 2017 05:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751950AbdDRFWh (ORCPT ); Tue, 18 Apr 2017 01:22:37 -0400 Received: from lelnx193.ext.ti.com ([198.47.27.77]:10460 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751898AbdDRFWg (ORCPT ); Tue, 18 Apr 2017 01:22:36 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id v3I5LPlx028245; Tue, 18 Apr 2017 00:21:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1492492885; bh=gOXgH1aT8asmmSVKRnwPntKQ2UnV79Xvfo07A8fBazs=; h=From:To:CC:Subject:Date; b=R4Be0xreFzk7p7wMa41w9vyrCR0uRx4BnZs0WJoEfNwICAfHwFlW/b9o0HANXs+Ix LydfXzy+p5fXEI7Z9s0424i8HD7yRUPvOyJilA/QFBrSxxSyTa3QVpb+VUQBYb30B2 uj79IJG1FaPzG3HzG8sYFCcFR4FRohq6mz1IATRc= Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3I5LPJZ027268; Tue, 18 Apr 2017 00:21:25 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Tue, 18 Apr 2017 00:21:24 -0500 Received: from ula0393675.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v3I5LILl016695; Tue, 18 Apr 2017 00:21:20 -0500 From: Keerthy To: , CC: , , , , Russ Dill Subject: [PATCH] RTC: Add functionality to read/write rtc scratch registers Date: Tue, 18 Apr 2017 10:50:07 +0530 Message-ID: <1492492807-20316-1-git-send-email-j-keerthy@ti.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Russ Dill Many RTCs provide scratch registers that are maintained so long as the RTC has power. Provide a generic method to access these registers. Signed-off-by: Russ Dill Signed-off-by: Keerthy --- drivers/rtc/interface.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/rtc/rtc-omap.c | 35 ++++++++++++++++++++++++++++++++++ include/linux/rtc.h | 7 +++++++ 3 files changed, 92 insertions(+) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index fc0fa75..facde06 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long offset) mutex_unlock(&rtc->ops_lock); return ret; } + +/* rtc_read_scratch - Read from RTC scratch register + * @ rtc: rtc device to be used + * @ index: index of scratch register + * @ value: returned value read + * + * Kernel interface read from an RTC scratch register + */ +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value) +{ + int err; + + mutex_lock(&rtc->ops_lock); + if (!rtc->ops) + err = -ENODEV; + else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch) + err = -EINVAL; + else + err = rtc->ops->read_scratch(rtc->dev.parent, index, value); + mutex_unlock(&rtc->ops_lock); + return err; +} +EXPORT_SYMBOL_GPL(rtc_read_scratch); + +/* rtc_write_scratch - Write to RTC scratch register + * @ rtc: rtc device to be used + * @ index: index of scratch register + * @ value: value to write + * + * Kernel interface write to an RTC scratch register + */ +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value) +{ + int err; + + mutex_lock(&rtc->ops_lock); + + if (!rtc->ops) + err = -ENODEV; + else if (index >= rtc->ops->scratch_size || + !rtc->ops->write_scratch) + err = -EINVAL; + else + err = rtc->ops->write_scratch(rtc->dev.parent, index, value); + + mutex_unlock(&rtc->ops_lock); + + return err; +} +EXPORT_SYMBOL_GPL(rtc_write_scratch); diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index 13f7cd1..c90d93e 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c @@ -70,6 +70,10 @@ #define OMAP_RTC_COMP_MSB_REG 0x50 #define OMAP_RTC_OSC_REG 0x54 +#define OMAP_RTC_SCRATCH0_REG 0x60 +#define OMAP_RTC_SCRATCH1_REG 0x64 +#define OMAP_RTC_SCRATCH2_REG 0x68 + #define OMAP_RTC_KICK0_REG 0x6c #define OMAP_RTC_KICK1_REG 0x70 @@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) static struct omap_rtc *omap_rtc_power_off_rtc; +static const u32 omap_rtc_scratch_regs[] = { + OMAP_RTC_SCRATCH0_REG, + OMAP_RTC_SCRATCH1_REG, + OMAP_RTC_SCRATCH2_REG, +}; + +static int omap_rtc_read_scratch(struct device *dev, unsigned int index, + u32 *value) +{ + *value = readl(omap_rtc_power_off_rtc->base + + omap_rtc_scratch_regs[index]); + + return 0; +} + +static int omap_rtc_write_scratch(struct device *dev, unsigned int index, + u32 value) +{ + struct omap_rtc *rtc = dev_get_drvdata(dev); + + rtc->type->unlock(rtc); + writel(value, omap_rtc_power_off_rtc->base + + omap_rtc_scratch_regs[index]); + rtc->type->lock(rtc); + + return 0; +} + /* * omap_rtc_poweroff: RTC-controlled power off * @@ -484,6 +516,9 @@ static void omap_rtc_power_off(void) .read_alarm = omap_rtc_read_alarm, .set_alarm = omap_rtc_set_alarm, .alarm_irq_enable = omap_rtc_alarm_irq_enable, + .read_scratch = omap_rtc_read_scratch, + .write_scratch = omap_rtc_write_scratch, + .scratch_size = ARRAY_SIZE(omap_rtc_scratch_regs), }; static const struct omap_rtc_device_type omap_rtc_default_type = { diff --git a/include/linux/rtc.h b/include/linux/rtc.h index b693ada..da5e003 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -91,6 +91,10 @@ struct rtc_class_ops { int (*alarm_irq_enable)(struct device *, unsigned int enabled); int (*read_offset)(struct device *, long *offset); int (*set_offset)(struct device *, long offset); + int (*read_scratch)(struct device *, unsigned int, u32*); + int (*write_scratch)(struct device *, unsigned int, u32); + + unsigned int scratch_size; }; #define RTC_DEVICE_NAME_SIZE 20 @@ -214,6 +218,9 @@ int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer, int rtc_set_offset(struct rtc_device *rtc, long offset); void rtc_timer_do_work(struct work_struct *work); +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value); +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value); + static inline bool is_leap_year(unsigned int year) { return (!(year % 4) && (year % 100)) || !(year % 400);