Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2408723pxb; Sun, 17 Oct 2021 14:08:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9S6iufgBiF87FsHpY0SDKSlDnsCUfU3XWrTX6WolZnkAu1OES3yO9+STPFrES8yybCrO+ X-Received: by 2002:a17:90b:4b89:: with SMTP id lr9mr28967123pjb.11.1634504892734; Sun, 17 Oct 2021 14:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634504892; cv=none; d=google.com; s=arc-20160816; b=FXXPx6cTvCP7KzpyCrJ0z2h3Y0wli+UXhWRSsfHbzNVsu8EQUCW9T/jSnn5VTSWH9+ S0TOftkU62dfhK6eS/F+BQLej9ivkHe2RyqTSiwdljttm+kT8Ggz6b55r4z5g7kWUUvj FI6WsHOSKkI7JrNwXWMZkXHdrlPB+nulJJQn/NM9SZJJZOmgg7U/4aKglG9hH9pqYFfg H/iNcI6QspqfFsdutYjg0m7qK6A+AflA1cjvWC3/pJE/lR3J5KzzRJ8oaxPNkrxMN1YI +PIg3W52Eri6Gj8EEI3RHau2S3JT0f2NcZp3v3dc6OWqBxOPwal0jkTG8BHcEh447Q0I bCRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=s5KgyOSttHo+2CO1EuRSHjE+ZdqqTeVsSJdrtfn0LI4=; b=FSxihIur5yCu09Os8E7+orxCQ347l1YhV+9NL3Y2Ac+G5tFYJWzmzkhS7EI0kICX4Y u/vtRGWv2yxoDroHtumZlDlbBqYRcne0b8WvsxkXvHw4B1Uqwn9OwIRNeCjvl8BiUIsf Ltw+1xpeedwtl3IhwaUWvSrjNuRalcAZM86Z5HA49Fd+6rr2317joMOtfEqlA+k6tSeI ErazR23LN8fZv09lpNmkFv5jbhNgQtp5LVjAeywanmhW/ARt9njXK1dD0hBy6ARCShMm 3ULaL7HgNcn/3kZyQVaivW9wSLlfiDol9YT/CO0iz5FkhKmr/cnGhpQ0A7GjRLfpa9tE CDqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si29493659pjq.2.2021.10.17.14.08.00; Sun, 17 Oct 2021 14:08:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242687AbhJOTXk (ORCPT + 99 others); Fri, 15 Oct 2021 15:23:40 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:47937 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242673AbhJOTXi (ORCPT ); Fri, 15 Oct 2021 15:23:38 -0400 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 71EC620008; Fri, 15 Oct 2021 19:21:30 +0000 (UTC) From: Alexandre Belloni To: Alessandro Zummo , Alexandre Belloni Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] rtc: rv3028: add BSM support Date: Fri, 15 Oct 2021 21:21:19 +0200 Message-Id: <20211015192121.817642-7-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211015192121.817642-1-alexandre.belloni@bootlin.com> References: <20211015192121.817642-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Backup Switch Mode controls how the RTC decides when to switch to the backup power supply. As it is disabled by default, provide a way to enable and configure it. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-rv3028.c | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/rtc/rtc-rv3028.c b/drivers/rtc/rtc-rv3028.c index 12c807306893..45c82e59d68f 100644 --- a/drivers/rtc/rtc-rv3028.c +++ b/drivers/rtc/rtc-rv3028.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -80,6 +81,10 @@ #define RV3028_BACKUP_TCE BIT(5) #define RV3028_BACKUP_TCR_MASK GENMASK(1,0) +#define RV3028_BACKUP_BSM GENMASK(3,2) + +#define RV3028_BACKUP_BSM_DSM 0x1 +#define RV3028_BACKUP_BSM_LSM 0x3 #define OFFSET_STEP_PPT 953674 @@ -512,6 +517,72 @@ static int rv3028_set_offset(struct device *dev, long offset) } +static int rv3028_param_get(struct device *dev, struct rtc_param *param) +{ + struct rv3028_data *rv3028 = dev_get_drvdata(dev); + int ret; + + switch(param->param) { + u32 value; + + case RTC_PARAM_BACKUP_SWITCH_MODE: + ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &value); + if (ret < 0) + return ret; + + value = FIELD_GET(RV3028_BACKUP_BSM, value); + + switch(value) { + case RV3028_BACKUP_BSM_DSM: + param->uvalue = RTC_BSM_DIRECT; + break; + case RV3028_BACKUP_BSM_LSM: + param->uvalue = RTC_BSM_LEVEL; + break; + default: + param->uvalue = RTC_BSM_DISABLED; + } + break; + + default: + return -EINVAL; + } + + return 0; +} + +static int rv3028_param_set(struct device *dev, struct rtc_param *param) +{ + struct rv3028_data *rv3028 = dev_get_drvdata(dev); + + switch(param->param) { + u8 mode; + case RTC_PARAM_BACKUP_SWITCH_MODE: + switch (param->uvalue) { + case RTC_BSM_DISABLED: + mode = 0; + break; + case RTC_BSM_DIRECT: + mode = RV3028_BACKUP_BSM_DSM; + break; + case RTC_BSM_LEVEL: + mode = RV3028_BACKUP_BSM_LSM; + break; + default: + return -EINVAL; + } + + rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_BSM, + FIELD_PREP(RV3028_BACKUP_BSM, mode)); + break; + + default: + return -EINVAL; + } + + return 0; +} + static int rv3028_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) { struct rv3028_data *rv3028 = dev_get_drvdata(dev); @@ -776,6 +847,8 @@ static const struct rtc_class_ops rv3028_rtc_ops = { .read_offset = rv3028_read_offset, .set_offset = rv3028_set_offset, .ioctl = rv3028_ioctl, + .param_get = rv3028_param_get, + .param_set = rv3028_param_set, }; static const struct regmap_config regmap_config = { -- 2.31.1