From patchwork Wed Jun 15 05:30:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J, KEERTHY" X-Patchwork-Id: 635690 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-io0-x23e.google.com (mail-io0-x23e.google.com [IPv6:2607:f8b0:4001:c06::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rTw9m2S2gz9s0M for ; Wed, 15 Jun 2016 15:31:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=Ggg32HKC; dkim-atps=neutral Received: by mail-io0-x23e.google.com with SMTP id l5sf5066852ioa.1 for ; Tue, 14 Jun 2016 22:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; 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=NIiLXD282jkBglsdrLnkMdo+JmtxFl2o4x+bulFkF7M=; b=Ggg32HKCxUmbFCSSNLM6RzVOpFI4ccUNEigYK9j5t2dnrTXf0YxkVw3g6JW7Kxip39 Bd0wgZPLWT4Cl0KJgTA6GJoi3TixRa547ftNBWCXMH856POsfwY8OE/+vsgWP2IDVQZN LVWJ1u9jZI8NOEaLqzdTbaoL4ELP/1Exg51pPXW3GHtUZgyz3jZ84ZqPh/W2SiPNm82F ROSDKBOLK+RHwVXRX4PtpcF2uHepBjPYqvPC2Crv5XfwJHJ45SHL60u4+Ot3Fgq2tefA YlBSAzvgSAnUccnlblkDVianFJH6LhqlQsNuFMt8xacnBxQb/KowRJehhYaoHY62qruC /yLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; 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=NIiLXD282jkBglsdrLnkMdo+JmtxFl2o4x+bulFkF7M=; b=T4v0gHGceIsM3kqTwDf7zj2ojoIXctLuy7FgQa54BgpuPUrFPAzS6lNOZHjXi/wjFW nJpEp0UutnctYqJX6ayl1B+MFtTQIMVp6JkwNgvxwXGu4eQ99C+0uGqbIJfkOMNms6Wr lKPU0F2SicVfMbwoSxO/JdpcN+/zsanEzpwwPymgz1kUqZpZ/DvY8/XEkghjgpDWp/kN eo5j4f5iwQrxsn6GUi2oUYOubVMXXUrlOsVncNNrYDDFSBeHl3Hf42N3PsE/m5q8sytu dg6k9F1r1n9sUr2qjei2vUlGa7dRb7LZNNgebMa2H4Pn5yepeD2QMQi+/2OJebVGWoN8 anwg== Sender: rtc-linux@googlegroups.com X-Gm-Message-State: ALyK8tL93yU3MT1G7cGcKTRFMddawXIGvfeTCvTuIJN4Lqn8oe1ldbdPnfkZ7/co69dMkg== X-Received: by 10.36.20.206 with SMTP id 197mr541160itg.3.1465968698013; Tue, 14 Jun 2016 22:31:38 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.36.36.16 with SMTP id f16ls174166ita.11.gmail; Tue, 14 Jun 2016 22:31:37 -0700 (PDT) X-Received: by 10.67.14.106 with SMTP id ff10mr19316867pad.25.1465968697559; Tue, 14 Jun 2016 22:31:37 -0700 (PDT) Received: from devils.ext.ti.com (devils.ext.ti.com. [198.47.26.153]) by gmr-mx.google.com with ESMTPS id d127si480030ite.1.2016.06.14.22.31.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 Jun 2016 22:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of j-keerthy@ti.com designates 198.47.26.153 as permitted sender) client-ip=198.47.26.153; Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id u5F5V8Jj024068; Wed, 15 Jun 2016 00:31:08 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5F5VYQ6000680; Wed, 15 Jun 2016 00:31:34 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Wed, 15 Jun 2016 00:31:34 -0500 Received: from ula0393675.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5F5VV25022384; Wed, 15 Jun 2016 00:31:32 -0500 From: Keerthy To: , CC: , , , , Subject: [rtc-linux] [PATCH] RTC: Add functionality to read/write rtc scratch registers Date: Wed, 15 Jun 2016 11:00:41 +0530 Message-ID: <1465968641-8080-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; spf=pass (google.com: domain of j-keerthy@ti.com designates 198.47.26.153 as permitted sender) smtp.mailfrom=j-keerthy@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 7cafd4d..d5a7ee2 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -1018,3 +1018,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 ec2e9c5..d00ca11 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c @@ -66,6 +66,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 @@ -405,6 +409,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 * @@ -475,6 +507,9 @@ static struct rtc_class_ops omap_rtc_ops = { .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_read_offset(struct rtc_device *rtc, long *offset); 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);