Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2430164pxb; Sun, 17 Oct 2021 14:53:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+kUdupDFoi43JearcLxxsC/csAonotDQn5T72pv8NuwRzD/UA2e61Nn114l+7ZeCWjs3u X-Received: by 2002:a17:902:8b8b:b0:13d:e91c:a1b9 with SMTP id ay11-20020a1709028b8b00b0013de91ca1b9mr23663616plb.60.1634507599606; Sun, 17 Oct 2021 14:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634507599; cv=none; d=google.com; s=arc-20160816; b=mo2FqwCYJM/qm2Do5KnEUIKtUpANSV/91HOdomzENSoq4REKIfURoIdDo/OKJZWelL CeV/nKn8uNP4PZilrzUS12DabRPeJRZtCFcTANjm/Ivp8yhDJh91nMmHJ4/vQZJuOuVW mC1kIJ3iwWOu182cM3g2v4SdgpVstu5TfZjDl92YhLJioqNeMIJf2t7MeV12KZ3Y+mJI 0haxpHmHTt9oNtRGRWic6DDqkRP2MnSbbbJB7p2eGlw2dTo0VeqTmZ9bha7Qav0DDIkc 3OP/ye24bYJB8mKRLLghRj7N+zpvnNKyFOt4AQ4KaeFxSBLVO0oNUge2xPvrhTaMmGMT pv/A== 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=VClPHTmGyHKEL6l9LeTkdgfk8JQ/KfUvo1rhmkkDATc=; b=j3O/yZKnfQMlNp4QV2SySHPvxy19/7Fv9BNQSSc+L0ltSa0D/nt0zXCZ0RsgjSXSMW /iefl3wHEmqfNfDKzSs7yixghXiREkB/18kgID+uuohA37NX0oBc7pqBQktHbqw6Y1gl Ojh1lzvLoLZe4WH3xgueJIhK3chd8rgSEX/z0+WB8/U1zicUHX2WcfwmweHRzlwfYKrZ BAL0vdIuYSoOcOm4oqOhQW//dg77nrX9LhM0+YhYnP4hkeXzoeLu3Jk0mn8Rt1i9LUK2 Y9b01R4e4X0AueXBisxgXSI/wAkmZRWMKoymkZK5nZ+CusOMvL/pRC5lRo0Wb98cdZdM mQYg== 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 p2si15091292plp.404.2021.10.17.14.53.04; Sun, 17 Oct 2021 14:53:19 -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 S242721AbhJOT26 (ORCPT + 99 others); Fri, 15 Oct 2021 15:28:58 -0400 Received: from mslow1.mail.gandi.net ([217.70.178.240]:59599 "EHLO mslow1.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238322AbhJOT2y (ORCPT ); Fri, 15 Oct 2021 15:28:54 -0400 Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow1.mail.gandi.net (Postfix) with ESMTP id EBA65D6789 for ; Fri, 15 Oct 2021 19:21:48 +0000 (UTC) Received: (Authenticated sender: alexandre.belloni@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 059A6FF807; Fri, 15 Oct 2021 19:21:26 +0000 (UTC) From: Alexandre Belloni To: Alessandro Zummo , Alexandre Belloni Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] rtc: add parameter ioctl Date: Fri, 15 Oct 2021 21:21:15 +0200 Message-Id: <20211015192121.817642-3-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 Add an ioctl allowing to get and set extra parameters for an RTC. For now, only handle getting available features. Signed-off-by: Alexandre Belloni --- drivers/rtc/dev.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/rtc.h | 18 ++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/drivers/rtc/dev.c b/drivers/rtc/dev.c index 5b8ebe86124a..143c097eff0f 100644 --- a/drivers/rtc/dev.c +++ b/drivers/rtc/dev.c @@ -208,6 +208,7 @@ static long rtc_dev_ioctl(struct file *file, const struct rtc_class_ops *ops = rtc->ops; struct rtc_time tm; struct rtc_wkalrm alarm; + struct rtc_param param; void __user *uarg = (void __user *)arg; err = mutex_lock_interruptible(&rtc->ops_lock); @@ -221,6 +222,7 @@ static long rtc_dev_ioctl(struct file *file, switch (cmd) { case RTC_EPOCH_SET: case RTC_SET_TIME: + case RTC_PARAM_SET: if (!capable(CAP_SYS_TIME)) err = -EACCES; break; @@ -382,6 +384,44 @@ static long rtc_dev_ioctl(struct file *file, err = -EFAULT; return err; + case RTC_PARAM_GET: + if (copy_from_user(¶m, uarg, sizeof(param))) { + mutex_unlock(&rtc->ops_lock); + return -EFAULT; + } + + switch(param.param) { + long offset; + case RTC_PARAM_FEATURES: + if (param.index != 0) + err = -EINVAL; + param.uvalue = rtc->features[0]; + break; + + default: + err = -EINVAL; + } + + if (!err) + if (copy_to_user(uarg, ¶m, sizeof(param))) + err = -EFAULT; + + break; + + case RTC_PARAM_SET: + if (copy_from_user(¶m, uarg, sizeof(param))) { + mutex_unlock(&rtc->ops_lock); + return -EFAULT; + } + + switch(param.param) { + case RTC_PARAM_FEATURES: + default: + err = -EINVAL; + } + + break; + default: /* Finally try the driver's ioctl interface */ if (ops->ioctl) { diff --git a/include/uapi/linux/rtc.h b/include/uapi/linux/rtc.h index 60ea711b1843..e4128be7963b 100644 --- a/include/uapi/linux/rtc.h +++ b/include/uapi/linux/rtc.h @@ -14,6 +14,7 @@ #include #include +#include /* * The struct used to pass data via the following ioctl. Similar to the @@ -66,6 +67,17 @@ struct rtc_pll_info { long pll_clock; /* base PLL frequency */ }; +struct rtc_param { + __u64 param; + union { + __u64 uvalue; + __s64 svalue; + __u64 ptr; + }; + __u32 index; + __u32 __pad; +}; + /* * ioctl calls that are permitted to the /dev/rtc interface, if * any of the RTC drivers are enabled. @@ -95,6 +107,9 @@ struct rtc_pll_info { #define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ #define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */ +#define RTC_PARAM_GET _IOW('p', 0x13, struct rtc_param) /* Get parameter */ +#define RTC_PARAM_SET _IOW('p', 0x14, struct rtc_param) /* Set parameter */ + #define RTC_VL_DATA_INVALID _BITUL(0) /* Voltage too low, RTC data is invalid */ #define RTC_VL_BACKUP_LOW _BITUL(1) /* Backup voltage is low */ #define RTC_VL_BACKUP_EMPTY _BITUL(2) /* Backup empty or not present */ @@ -118,6 +133,9 @@ struct rtc_pll_info { #define RTC_FEATURE_NEED_WEEK_DAY 4 #define RTC_FEATURE_CNT 5 +/* parameter list */ +#define RTC_PARAM_FEATURES 0 + #define RTC_MAX_FREQ 8192 -- 2.31.1