Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3108529pxb; Mon, 18 Oct 2021 08:22:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/7QN1CdFxS7fWXWJ677RszP3I8CIM29YdYi9noNgaGtcKhh7/0HZFg+Begi6bqOpi7S9D X-Received: by 2002:a17:906:6c83:: with SMTP id s3mr31371316ejr.13.1634570562081; Mon, 18 Oct 2021 08:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634570562; cv=none; d=google.com; s=arc-20160816; b=S5luZc1DypsWvVdYEJHU7PogAJdB0x6tFd6GqIKYpgDnjIM3iKeSt03ZSIwp38i3yZ pATSmruJFbepesJPOmWkZOGo+/Jg5YwJbAj25E0RuSi48Eiq88MsVaebSS7NzScqcrix Kc9HUdlStl0CmqWAJkNeA1mBqdAhG8xF/C1ekk8PDWpKi4VRKLdmVQq+zkibJMrDBCPU tYZIw1r07XXS8N/nJyKUm6ewy9d/CHmzsaGNikzlrma/57IucGFFesvH0u0T7U3HDBpR Xkw5/u44lOCtCqOGWvhIRLamavaY4bQMjevznyp62GA6xFIR8exzqiFrazxe1k9ao0P2 SV2g== 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=8kSAgKDUpPUFRCSn0p3mdZfx3eKT8Xd4yaSwvlpOMq4=; b=xDOuyODdbSemk63DIe/mIN7TwiddMBofZ/184n8notesrdMobGCTNpkR4ZoghbbjFq CaCkSFGaY0beSjNVRGdtfvGlkcD9fUjxSw5TeXejmlqejvtIHBSDsc1mYJI5/1+Sv1gj yT9HUtn7m2Hbm1ovBnaqtipNbR0nMcdWhGtjIck47LWVVKgWZ3cSm6pYzt/RigdZ/Hh3 evCGNyDYTcnwWecYy2oXAk5ifG36edIq3E4bb/rhMs3ctrODPJBQ8kQioxzr7xLZv78u pO7zXgj//l0fYj19UTNd8XvAErMGAxX03cAb4vNHEkh635bENI2xQ3uvYxQiZPOwVvnU NI9w== 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 qw32si29870076ejc.421.2021.10.18.08.22.18; Mon, 18 Oct 2021 08:22:42 -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 S233642AbhJRPWH (ORCPT + 99 others); Mon, 18 Oct 2021 11:22:07 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:53463 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233395AbhJRPV6 (ORCPT ); Mon, 18 Oct 2021 11:21:58 -0400 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id E334024000C; Mon, 18 Oct 2021 15:19:44 +0000 (UTC) From: Alexandre Belloni To: Alessandro Zummo , Alexandre Belloni Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] rtc: rv3032: allow setting BSM Date: Mon, 18 Oct 2021 17:19:33 +0200 Message-Id: <20211018151933.76865-8-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018151933.76865-1-alexandre.belloni@bootlin.com> References: <20211018151933.76865-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 is currently set properly when the trickle charger is enabled. However, in the case of a non-rechargeable battery, it is necessary to be able to enable it, only allow that when the trickle charger is disabled. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-rv3032.c | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drivers/rtc/rtc-rv3032.c b/drivers/rtc/rtc-rv3032.c index 1b62ed2f1459..a3c73179ecb1 100644 --- a/drivers/rtc/rtc-rv3032.c +++ b/drivers/rtc/rtc-rv3032.c @@ -106,6 +106,7 @@ struct rv3032_data { struct regmap *regmap; struct rtc_device *rtc; + bool trickle_charger_set; #ifdef CONFIG_COMMON_CLK struct clk_hw clkout_hw; #endif @@ -402,6 +403,75 @@ static int rv3032_set_offset(struct device *dev, long offset) FIELD_PREP(RV3032_OFFSET_MSK, offset)); } +static int rv3032_param_get(struct device *dev, struct rtc_param *param) +{ + struct rv3032_data *rv3032 = dev_get_drvdata(dev); + int ret; + + switch(param->param) { + u32 value; + + case RTC_PARAM_BACKUP_SWITCH_MODE: + ret = regmap_read(rv3032->regmap, RV3032_PMU, &value); + if (ret < 0) + return ret; + + value = FIELD_GET(RV3032_PMU_BSM, value); + + switch(value) { + case RV3032_PMU_BSM_DSM: + param->uvalue = RTC_BSM_DIRECT; + break; + case RV3032_PMU_BSM_LSM: + param->uvalue = RTC_BSM_LEVEL; + break; + default: + param->uvalue = RTC_BSM_DISABLED; + } + + break; + + default: + return -EINVAL; + } + + return 0; +} + +static int rv3032_param_set(struct device *dev, struct rtc_param *param) +{ + struct rv3032_data *rv3032 = dev_get_drvdata(dev); + + switch(param->param) { + u8 mode; + case RTC_PARAM_BACKUP_SWITCH_MODE: + if (rv3032->trickle_charger_set) + return -EINVAL; + + switch (param->uvalue) { + case RTC_BSM_DISABLED: + mode = 0; + break; + case RTC_BSM_DIRECT: + mode = RV3032_PMU_BSM_DSM; + break; + case RTC_BSM_LEVEL: + mode = RV3032_PMU_BSM_LSM; + break; + default: + return -EINVAL; + } + + return rv3032_update_cfg(rv3032, RV3032_PMU, RV3032_PMU_BSM, + FIELD_PREP(RV3032_PMU_BSM, mode)); + + default: + return -EINVAL; + } + + return 0; +} + static int rv3032_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) { struct rv3032_data *rv3032 = dev_get_drvdata(dev); @@ -541,6 +611,8 @@ static int rv3032_trickle_charger_setup(struct device *dev, struct rv3032_data * return 0; } + rv3032->trickle_charger_set = true; + return rv3032_update_cfg(rv3032, RV3032_PMU, RV3032_PMU_TCR | RV3032_PMU_TCM | RV3032_PMU_BSM, val | FIELD_PREP(RV3032_PMU_TCR, i)); @@ -813,6 +885,8 @@ static const struct rtc_class_ops rv3032_rtc_ops = { .read_alarm = rv3032_get_alarm, .set_alarm = rv3032_set_alarm, .alarm_irq_enable = rv3032_alarm_irq_enable, + .param_get = rv3032_param_get, + .param_set = rv3032_param_set, }; static const struct regmap_config regmap_config = { @@ -883,6 +957,8 @@ static int rv3032_probe(struct i2c_client *client) rv3032_trickle_charger_setup(&client->dev, rv3032); + set_bit(RTC_FEATURE_BACKUP_SWITCH_MODE, rv3032->rtc->features); + rv3032->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; rv3032->rtc->range_max = RTC_TIMESTAMP_END_2099; rv3032->rtc->ops = &rv3032_rtc_ops; -- 2.31.1