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: "J, KEERTHY" X-Patchwork-Id: 751650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-io0-x23a.google.com (mail-io0-x23a.google.com [IPv6:2607:f8b0:4001:c06::23a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w6YQN1xw3z9s65 for ; Tue, 18 Apr 2017 15:21:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="AhEbcqCG"; dkim-atps=neutral Received: by mail-io0-x23a.google.com with SMTP id h41sf12648448ioi.0 for ; Mon, 17 Apr 2017 22:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=O2AcK7hqKBL8BBPP80dhAsSFnI9alLTZjlvM4q/WebE=; b=AhEbcqCG4gd5++konR76tJVGZVHZxvIso5e5COOZH8cJBJpAUrQdX3HIRH+YFVxnRo bkwyhsIxLQYdNFaZ8VYHX8w8DBIASXP+sq9FlBZOihF5t5YTaJV3yE5S8EsPJ31ZGP8O FBXO9ol80OzdGBC6OriUHwP+zcw8xRn/McxIBrK6gFBq12l8w4Nai+nXXR88WDhkt2u+ MWMmEhds9nkmyTgTkJxu9b/AxCwPBsQLXkRG0RPyDo5503lhuxRLT1W/E9BrlZzc7ZVZ 1nA9JPgoBHGk43GcbNdoStasnjtoDyYb3mXx6k8EAoupKoD+RzU3GH0ITscw7qr3SET2 HAPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=O2AcK7hqKBL8BBPP80dhAsSFnI9alLTZjlvM4q/WebE=; b=KJlIA8UTm6y0bMuYkKUPMXztnv1s8FF6/aLgEDgSD70YWPYv9vLcl7uEL20RVLcWGE 6o9UOLiJJioi94BMD54V5D6O4lyx9LV1ceUb/GhggQWKKkFNYLuTKMIDwm5DvTEBonfM 84cOPwFDgA8ahwcTIiZKnxNgM2OeTaRxk+Lu+ognm+yUhW1f6zkROAQBw3qInxBTOMR1 k2podo6m77TYtii0enmMfLs1to1Xe9yi296VnaJM0X+Suifsl07Pw59RKRB4DoimjFmz AySK/v0gJMbiGBxpow2PHrxAP43gX/dwdGx45NSKPIHsqb7rXN3ir9n5dbUdegoJAASK OJ6Q== Sender: rtc-linux@googlegroups.com X-Gm-Message-State: AN3rC/4ZBhIGQRii2d3KsohhIVHKvZCqzoXZ9ZLMVpySG0WgI/h8ubpp IGWVxsZ1Sk4aHQ== X-Received: by 10.157.26.98 with SMTP id u31mr294027otu.0.1492492888106; Mon, 17 Apr 2017 22:21:28 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.157.51.155 with SMTP id u27ls173200otc.34.gmail; Mon, 17 Apr 2017 22:21:27 -0700 (PDT) X-Received: by 10.31.164.75 with SMTP id n72mr8841178vke.39.1492492887864; Mon, 17 Apr 2017 22:21:27 -0700 (PDT) Received: from lelnx193.ext.ti.com (lelnx193.ext.ti.com. [198.47.27.77]) by gmr-mx.google.com with ESMTPS id n22si834024itg.2.2017.04.17.22.21.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Apr 2017 22:21:27 -0700 (PDT) Received-SPF: pass (google.com: domain of j-keerthy@ti.com designates 198.47.27.77 as permitted sender) client-ip=198.47.27.77; 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 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: [rtc-linux] [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 X-Original-Sender: j-keerthy@ti.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@ti.com; spf=pass (google.com: domain of j-keerthy@ti.com designates 198.47.27.77 as permitted sender) smtp.mailfrom=j-keerthy@ti.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ti.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-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , 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);