Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3107609pxb; Mon, 18 Oct 2021 08:21:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNVkbb8doHfGwf9AUfsOfRNzPwyk/7ucjcgicOyPmU0zWJXjpscC0ws3hnArXV2ye8lbBi X-Received: by 2002:a62:79d7:0:b0:44c:a583:e5d7 with SMTP id u206-20020a6279d7000000b0044ca583e5d7mr28951646pfc.2.1634570505801; Mon, 18 Oct 2021 08:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634570505; cv=none; d=google.com; s=arc-20160816; b=wb9xMQrknbDswqA5oFm6lXRo2pC0rtoR+QjPkr3efrpAK9SkHwedZ3KgZa8H8vnVhX rNiZboqWALgoki4BqZ4udjQffe5jhKXkWPNvqHbf8ta2mJaUmM9HXkajzQfxlzgm9/Hl Q2v13gTC5/bEKvSIttdQ2p1HEz3re9fIWt5yGy2HQVVCeW+AqNOf0/jT2/Tzrwmd3KTm Jd/oMiYvs8B/+J/AFUuezqqzqUQHaZUmAx5ykQevEIySmI797hHpksyX3TsLf10HLj9U sHkLa9n84fQRcyjJG+1CB6J/QA5N06zFIbPeRBeccBB/ruNhDc/HG+9Y6ZSBRyCFSeES bA5w== 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=zr25xy/gRb+NbthkH3OIDF9jto19Cw/P7y+GkCmLAQA=; b=DyHpyuOK0QuRoNB4mAjb4QHrPF94onD+eCejAwgeKkstPVG95wSgvJCPSeUIDijoiL d/qoz7320vPFRdKR3tq4y4vBV27U4h4YNGCY3tAZFUtYuY2L94BcqkFo24MUbvslswmW 1DgOzz5VJXvmHWzmRjnNOSgMsJZkXJP+kX7jTnVY/DiDPpAUTteP9vRs9FSV4hFfAjGy l6NFheD7Lc5M0K8DhCac5e6qwxWk8e0wJYxI+8aFOiNFQ0xft2F2bTYbQwjZIlz262fR XIr26Us6D2Mfu6MWLfvmUQzRFkI/BIjkZE0EONt9YE8tYEhpfDzqVud3vy/vFv8CoMkV ccsA== 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 n2si17989385pjh.91.2021.10.18.08.21.28; Mon, 18 Oct 2021 08:21:45 -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 S233360AbhJRPWB (ORCPT + 99 others); Mon, 18 Oct 2021 11:22:01 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:44167 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233304AbhJRPVz (ORCPT ); Mon, 18 Oct 2021 11:21:55 -0400 Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id F0570240015; Mon, 18 Oct 2021 15:19:42 +0000 (UTC) From: Alexandre Belloni To: Alessandro Zummo , Alexandre Belloni Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] rtc: add BSM parameter Date: Mon, 18 Oct 2021 17:19:31 +0200 Message-Id: <20211018151933.76865-6-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 BSM or Backup Switch Mode is a common feature on RTCs, allowing to select how the RTC will decide when to switch from its primary power supply to the backup power supply. It is necessary to be able to set it from userspace as there are uses cases where it has to be done dynamically. Supported values are: RTC_BSM_DISABLED: disabled RTC_BSM_DIRECT: switching will happen as soon as Vbackup > Vdd RTC_BSM_LEVEL: switching will happen around a threshold, usually with an hysteresis RTC_BSM_STANDBY: switching will not happen until Vdd > Vbackup, this is useful to ensure the RTC doesn't draw any power until the device is first powered on. Signed-off-by: Alexandre Belloni --- drivers/rtc/dev.c | 10 ++++++++-- include/linux/rtc.h | 2 ++ include/uapi/linux/rtc.h | 9 ++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/dev.c b/drivers/rtc/dev.c index abee1fc4705e..e104972a28fd 100644 --- a/drivers/rtc/dev.c +++ b/drivers/rtc/dev.c @@ -409,7 +409,10 @@ static long rtc_dev_ioctl(struct file *file, break; default: - err = -EINVAL; + if (rtc->ops->param_get) + err = rtc->ops->param_get(rtc->dev.parent, ¶m); + else + err = -EINVAL; } if (!err) @@ -436,7 +439,10 @@ static long rtc_dev_ioctl(struct file *file, return rtc_set_offset(rtc, param.svalue); default: - err = -EINVAL; + if (rtc->ops->param_set) + err = rtc->ops->param_set(rtc->dev.parent, ¶m); + else + err = -EINVAL; } break; diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 354e0843ab17..47fd1c2d3a57 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -66,6 +66,8 @@ 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 (*param_get)(struct device *, struct rtc_param *param); + int (*param_set)(struct device *, struct rtc_param *param); }; struct rtc_device; diff --git a/include/uapi/linux/rtc.h b/include/uapi/linux/rtc.h index 5debe82439c2..03e5b776e597 100644 --- a/include/uapi/linux/rtc.h +++ b/include/uapi/linux/rtc.h @@ -132,11 +132,18 @@ struct rtc_param { #define RTC_FEATURE_ALARM_RES_2S 3 #define RTC_FEATURE_UPDATE_INTERRUPT 4 #define RTC_FEATURE_CORRECTION 5 -#define RTC_FEATURE_CNT 6 +#define RTC_FEATURE_BACKUP_SWITCH_MODE 6 +#define RTC_FEATURE_CNT 7 /* parameter list */ #define RTC_PARAM_FEATURES 0 #define RTC_PARAM_CORRECTION 1 +#define RTC_PARAM_BACKUP_SWITCH_MODE 2 + +#define RTC_BSM_DISABLED 0 +#define RTC_BSM_DIRECT 1 +#define RTC_BSM_LEVEL 2 +#define RTC_BSM_STANDBY 3 #define RTC_MAX_FREQ 8192 -- 2.31.1