Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp490884pxh; Wed, 10 Nov 2021 05:07:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJymqeujJr1XNE3BCpW6xPSd1xqgR0tNHmSEoWQjI678LEciCiAQBIu1NIDz6bfZilRLH0Hk X-Received: by 2002:a05:6402:405:: with SMTP id q5mr20934396edv.62.1636549661856; Wed, 10 Nov 2021 05:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636549661; cv=none; d=google.com; s=arc-20160816; b=ohfKzSnH8vzudSdMHv6PIwW8TVnLrZvvHe0twcbjUSsMu8Cvd3tR7uUT2LtgzQxvlF Ml4DvBnU1gNxFF104W1tybHVTCYhDqSvc51v3UIqsHROe+XRIu8YMZ6zw7SdALspWi68 dOb0RiKqq/fQtPhO5n8kz63/MSTBM6lZl0RB2O+TVmtBtHogVB8jWxA0sXZ9ApaNBz6f z3tMcWkBYUmaVqH4B7PHeWmEps7jJMj2VYM+Ul7jjAZ7Gfrs1qFXEGxe/eTMuatQU2RF tspPV+z0cRW8HyQJw0OKMwdl5iGLMo4uzHtT65sVjV0Ni7Apg/CpH7Yd7tcAAQIkS13i PD2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=nU3nv8rOCy8pYPsaPbC1Tl2lc1EFo7HiiaRCokA64wI=; b=FOjrOPdWGMahKvlCOuu61PLTnoPmNif5deh9CUoE4eSAsmsmoOznj6Pt3HP6mXoPUg YxvWH8VFS5tOEE9aanRXUZrhDVB2O4tqGF2ri6szk0etv+QNHB9modNmiOfGxX9ZgBoS aRBnPRjKfNretfqVDZe+2xBK6JHIHdmUWzo5zF/KbdugRZC6gQSiOIX4muzzqazFhWTv 2WY7sv7BX/U8pvUZk9WTAHT/VvrsCCE3lacD6Iv5+VvATBjG4vqyJm/zJ11TaRasYr+y oYAQU36AxoFhhQZPbjNqn2v45FT/J19702Ui22J87cgh0ow8R5TB02gxF48LQ1fiRasg 1GGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=Rdt5pyaq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si36799085edt.61.2021.11.10.05.07.13; Wed, 10 Nov 2021 05:07:41 -0800 (PST) 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; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=Rdt5pyaq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231849AbhKJNHE (ORCPT + 99 others); Wed, 10 Nov 2021 08:07:04 -0500 Received: from smtp1.axis.com ([195.60.68.17]:43568 "EHLO smtp1.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231679AbhKJNHD (ORCPT ); Wed, 10 Nov 2021 08:07:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1636549457; x=1668085457; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=nU3nv8rOCy8pYPsaPbC1Tl2lc1EFo7HiiaRCokA64wI=; b=Rdt5pyaqRK6HVwsW5YRRhVi8Elb8G6TFpgZHGrLzGLCQtoyVGTpeh2M+ 3RZtmIJqxxshDoK+Lgvpy+12UmCMRUimxpmEWxLOpsakTkYeJwq5f603a RVZllvsMDf00gNJ9gWDRmp5y0JgCbVPF6SYwS2rj2HVoRD9JPQ5hyAZGo IVVOA3Yd9PMW/weWNAdVIGmfRmMdqGNRz297wvID81w5bcpYWRk+O/q1t ZJqZVRdmOB04I7vTTwyQjYeaWXJxAipoCsr5d5/B0b4xwlnCZghLZLNhh C9bsjnLJxd6RirpxwpqFegZGRTysc7JkJZmXC2Lg5MmNhO6pKGl3sOxRy A==; Subject: Re: [PATCH] rtc: rs5c372: Add support of RTC_VL_READ ioctl To: Pavel Modilaynen , , CC: , , , Pavel Modilaynen References: <20211105004049.5486-1-pavel.modilaynen@axis.com> From: Camel Guo Message-ID: Date: Wed, 10 Nov 2021 14:03:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20211105004049.5486-1-pavel.modilaynen@axis.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.0.5.60] X-ClientProxiedBy: se-mail02w.axis.com (10.20.40.8) To se-mail03w.axis.com (10.20.40.9) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, After discussion internally on this patch, we would like to abandon this patch and purpose this one https://lore.kernel.org/linux-rtc/20211110115455.18699-1-camel.guo@axis.com/T/#u instead. Sorry for the inconvenience and please review that patch instead. Best Regards Camel Guo On 11/5/21 1:40 AM, Pavel Modilaynen wrote: > From: Pavel Modilaynen > > Read, cache and expose with RTC_VL_READ ioctl low voltage > detection flag. It is supported on all devices except RS5C372A/B, > for which osciallation halt detection bit is interpreted > as low voltage condition. > Add RTC_VL_CLEAR ioctl to clear the cached value. > > Signed-off-by: Pavel Modilaynen > --- > drivers/rtc/rtc-rs5c372.c | 46 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c > index 80980414890c..68d2ed9670c4 100644 > --- a/drivers/rtc/rtc-rs5c372.c > +++ b/drivers/rtc/rtc-rs5c372.c > @@ -126,6 +126,7 @@ struct rs5c372 { > unsigned smbus:1; > char buf[17]; > char *regs; > + int voltage_low; > }; > > static int rs5c_get_regs(struct rs5c372 *rs5c) > @@ -216,22 +217,40 @@ static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm) > if (status < 0) > return status; > > + /* check the warning bits */ > switch (rs5c->type) { > case rtc_r2025sd: > case rtc_r2221tl: > if ((rs5c->type == rtc_r2025sd && !(ctrl2 & R2x2x_CTRL2_XSTP)) || > (rs5c->type == rtc_r2221tl && (ctrl2 & R2x2x_CTRL2_XSTP))) { > dev_warn(&client->dev, "rtc oscillator interruption detected. Please reset the rtc clock.\n"); > + /* keep it as indicator of low/dead battery */ > + rs5c->voltage_low = 1; > return -EINVAL; > } > break; > default: > if (ctrl2 & RS5C_CTRL2_XSTP) { > dev_warn(&client->dev, "rtc oscillator interruption detected. Please reset the rtc clock.\n"); > + /* keep it as indicator of low/dead battery */ > + rs5c->voltage_low = 1; > return -EINVAL; > } > } > > + > + switch (rs5c->type) { > + case rtc_rs5c372a: > + case rtc_rs5c372b: > + break; > + default: > + if (ctrl2 & R2x2x_CTRL2_VDET) { > + rs5c->voltage_low = 1; > + dev_warn(&client->dev, "low voltage detected\n"); > + } > + break; > + } > + > tm->tm_sec = bcd2bin(rs5c->regs[RS5C372_REG_SECS] & 0x7f); > tm->tm_min = bcd2bin(rs5c->regs[RS5C372_REG_MINS] & 0x7f); > tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]); > @@ -485,6 +504,32 @@ static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq) > #define rs5c372_rtc_proc NULL > #endif > > +#ifdef CONFIG_RTC_INTF_DEV > +static int rs5c372_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) > +{ > + struct rs5c372 *rs5c = i2c_get_clientdata(to_i2c_client(dev)); > + > + dev_dbg(dev, "%s: cmd=%x\n", __func__, cmd); > + > + switch (cmd) { > + case RTC_VL_READ: > + if (rs5c->voltage_low) > + dev_info(dev, "low voltage detected, date/time is not reliable.\n"); > + > + return put_user(rs5c->voltage_low, (unsigned int __user *)arg); > + case RTC_VL_CLR: > + /* Clear the cached value. */ > + rs5c->voltage_low = 0; > + return 0; > + default: > + return -ENOIOCTLCMD; > + } > + return 0; > +} > +#else > +#define rs5c372_ioctl NULL > +#endif > + > static const struct rtc_class_ops rs5c372_rtc_ops = { > .proc = rs5c372_rtc_proc, > .read_time = rs5c372_rtc_read_time, > @@ -492,6 +537,7 @@ static const struct rtc_class_ops rs5c372_rtc_ops = { > .read_alarm = rs5c_read_alarm, > .set_alarm = rs5c_set_alarm, > .alarm_irq_enable = rs5c_rtc_alarm_irq_enable, > + .ioctl = rs5c372_ioctl, > }; > > #if IS_ENABLED(CONFIG_RTC_INTF_SYSFS) >