From patchwork Fri Jun 9 21:04:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 105817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1192452vqr; Fri, 9 Jun 2023 14:26:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HRw8gb5e4L7eNISFHwkae/W104qKx969Z9XZ4FvKQxpXRsWAcfHi6EWN4MHi5l76SP92h X-Received: by 2002:a05:6a00:2193:b0:649:93a7:571b with SMTP id h19-20020a056a00219300b0064993a7571bmr2917429pfi.13.1686345972551; Fri, 09 Jun 2023 14:26:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686345972; cv=pass; d=google.com; s=arc-20160816; b=Wj6XKU0sj1I4YwYftjEZJLWGU+hXSCN5NmlR6gBmCfZsAibIO1dgD6AJtiS+f6FH4G W8PG+DJcIzmAmDmgHdOcBh0Ej10ln77eKvYTRSOF83c+nYWlQ40Rrg//5kXqunFfK3Om BTngffrel7rYOdQH+FYAdtXPJoxaDtxLJbblUdR9r64Z4QNC5b7khgBLPuvUbU5Zzwwh i0hKFedN25T11WBi7+5I+mX0MBDrlxOxXzVeenU5PNMeiDgDKxlKlJ9WG+vwFv20g9Ko gnGOcHrsA7V5/ZLCWwnYiq1/nB2+Xg5Nn4lWEAAHy2up/gjouuKW010jAAcfSh6Aza2g geBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding:cc:to :content-language:subject:from:user-agent:date:message-id :dkim-signature; bh=H2jdjcuNyFUKWFm4EMWdqKR6ASTe7qlr2IBFsbHVWNA=; b=Z0JKOMkT69b6skf2wjMiRtjKYENqH293voh7oFaYM+64mDoZ8RX9ubP21l2VM33NZz 33X5/8NOWtwSGjDnBcSGFob0lG7vcvoKttvkV9BqPxHEzsM3F00ec5IRts7nYMCj7Mg5 yvD9DINKeEXonjriJnVH7HLJoqKWiT8nMlH45TNyIoOrlI0oQQ8S9kCV45n7nqoiqCRx O/I2QuIeO21eAyQyn4FJncjZQqy6eDrf3J2nIyIe+nFxkidHVA0rVfOelgnmNN+OwPIv Ck9Qz6HIbjSUDay4r+PUGP6N9nVe4TePAMnzJYOHfj4AbIys3kHeex6lPympW2RwI9ds yd2g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=Ehe+RFt5; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h19-20020aa796d3000000b0064f3917aedesi3030024pfq.176.2023.06.09.14.25.59; Fri, 09 Jun 2023 14:26:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=Ehe+RFt5; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbjFIVEW (ORCPT + 99 others); Fri, 9 Jun 2023 17:04:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbjFIVEV (ORCPT ); Fri, 9 Jun 2023 17:04:21 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2064.outbound.protection.outlook.com [40.107.241.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC5FC358E; Fri, 9 Jun 2023 14:04:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eqpBynF0JNtS3v/KconJ6zXao/hyfjPoi6+bx3YgzZ9lYSw1U6pk82c9/5IIriWYYxFXuLJTjwmdjuO5Acc4TAE3I08iqanIfJoZnhAV/Fu/rR8xnGAp+IAnYVSo7Gd7EivyVO2QycqsiXu+pJm0Stn0HxkuIfap6Am9S+f3XCq7uI32qPW2UtcKcIMtyzdTswRIR4Bf1XvmzBjTBmFdUshWbrIyTkIDondcluED/2Q8QRPzy+9taKnf0NnJeuEEsnbxU1dUeLvnSxcD3T+Nq3VO8eRxQDjUWqM2LEMjavlJueMPqzikkaipl+1m5mErBjxTW9ReJxiOJLsi1C8QFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H2jdjcuNyFUKWFm4EMWdqKR6ASTe7qlr2IBFsbHVWNA=; b=jsD01sSYE5hp5CJYGV4vnIeA3txFM0V1Wx6/0d30b4pKD1vhNKmQkb4o6/TrObolq/McOV4tosY/0KRhF7gYgGlRrCHnikpeCYvYZ0FXbzhSzvUNXa2RBgIiWdAXaTPwIBxikY4TUaEA+aMvFMc0fVx690PQDbbduLOkGPKISCgZLRYrrWKbl8rhgg+LefIWS9/V/hKOihzwCN+JBuP5ePRT2P4ZPBzDxco1xUGmUXZBuzgrQVn0HLtHJQ7AcDiZ/bTfM++qWIRI47+iUgrzn9OxdLVaDluop5TcQSPJkTQNZatzPqqe8sKOQCRASx9gF2kHINRW0JGMDpuOSGV6Pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=siemens.com; dmarc=pass action=none header.from=siemens.com; dkim=pass header.d=siemens.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=siemens.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H2jdjcuNyFUKWFm4EMWdqKR6ASTe7qlr2IBFsbHVWNA=; b=Ehe+RFt5baxR7VejwxWu3D6dHVpaDcjqBMGK1tJc5czr6PnG18S1C8fnVsgChj+OBrkNyIXsQFUVLY82HmKybdj8mQTlperFG6ZmZJPbVBmOq8z8DsoDw6JG3uKrNBLGDTdjKT03UZKCyzE3MwC3tAC0HPQpC2qe8t2n0dQu/QHJ7NA50tg8UEkFD/QPIW9q8YgEcahXj4su5JStjr+94csAoO3+epSN+4iskuzTsiAJwcXDaexHevOI0OdQ6zBiGGO05aeIH/r+cE5bU2oGX7RI1k//ZvHclKzTcqMbm1AhOoLU59kmFbjmcrnxxj1UXrxdEAAN0j5hhi+2riuW1g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=siemens.com; Received: from AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:588::19) by AS8PR10MB7428.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.19; Fri, 9 Jun 2023 21:04:16 +0000 Received: from AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM ([fe80::53c2:174a:8b13:ce94]) by AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM ([fe80::53c2:174a:8b13:ce94%3]) with mapi id 15.20.6455.037; Fri, 9 Jun 2023 21:04:16 +0000 Message-ID: Date: Fri, 9 Jun 2023 23:04:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 From: Jan Kiszka Subject: [PATCH] rtc: pcf-8563: Report previously detected low-voltage via RTC_VL_BACKUP_LOW Content-Language: en-US To: Alessandro Zummo , Alexandre Belloni , linux-rtc@vger.kernel.org Cc: Linux Kernel Mailing List X-ClientProxiedBy: FR0P281CA0250.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:af::20) To AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:588::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS4PR10MB6181:EE_|AS8PR10MB7428:EE_ X-MS-Office365-Filtering-Correlation-Id: 615d9b18-8006-4f68-34d6-08db692d15db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aVJMD+guSdgVHVNSrowqlUfxZ9gaYHSbrF/Py/Tr5zCqHxnPRWGzLT3lp5LJMsOLh5NTJA5tCJg5ocRNZCoheEUIJvH+B7Of64oV19efHkkMSobxo00BtXdbLYRG+QAX4HrZu5SXM6t+euQo7Hyzr47ZdxahrRl6ejP10igRH0STdlaMKxCnX+14iHePcXkkut1lPH2j3Mi/zoeiT9+McBFn1oF33k9PhwXronT+uwtnhRIlCtH84SFIFmu4JV3WvOuKhRn/Nr6QMziA+0jkQQkmBHzESmTqAkmLfEYM+kwf2EeZqxPpgqTkz14OYOi9G2BLNZlru7Svk0Eyz1XMClZxE/UZf+V20dzftNeu/rd8eD6JgRah42Z9/QujTDY1+o7TBjmwAKoGbocIF3yoIhhyPoZcOUWOoYjWEVT9bnIBHAM15PqOV+ixMcEZ5aQXWZOxy+r1b/AJrD3ixvNakK6qSNVFlljiPB/4D+lnBNMasLfwzZ2WTZ/EcfgytFQQb9BkC1qiGqQalytihpc9ApCTDOwB675qE8EqFEzWA8O3XkzDpOrS6iy/SoMx26x6q7DM4VuYIrAXwM0oy3QSGM1REXKbqrTm/gGMuuKzqYkK6+gE3awc096wXke4fNqcY6T9fjMs+8sLZBvRVJPr2Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(396003)(366004)(346002)(376002)(451199021)(44832011)(5660300002)(38100700002)(82960400001)(186003)(26005)(83380400001)(6506007)(2616005)(6512007)(478600001)(110136005)(2906002)(86362001)(6486002)(31696002)(36756003)(66946007)(66556008)(8676002)(4326008)(31686004)(66476007)(8936002)(6666004)(41300700001)(316002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?i3YEfDykJmCiRTo+8KzJJpsixJFU?= =?utf-8?q?CgwlVG8Rwl+dsyRG48QSZ+vjpdnctD4uns7/ckV6VikMaFF0B4Az97RPcOEvTHse+?= =?utf-8?q?rmU5NXavNlEvCTy5/Zyk5gs+JrdC8FdkjXvPuEiJVNgZ7Xp5cYnkv8stn5KZHlSo3?= =?utf-8?q?bT0bIaXolvfnfFO5uKtjYZFexCTIxSxoVxtwpbJFQFgROgQgYP2BFa9wxndTiCKAz?= =?utf-8?q?TKAhKkKl3aIvSfTnJ4XVUlWejAWrLf+joD19ImDhz7/3wxO6DItjkcpZLKvBPBUNZ?= =?utf-8?q?BOrWPArTq+YaC6O2GyOfDOxbxMAdW31amjNCqmtovL7aNp/ags1cbFAS8AOjNU3hg?= =?utf-8?q?MvM6d+gkxMNnKDU1GDT1fkx+W2jZ4MSc6B3h7XLHsYRMQcTKSjBCTd/e3ciq3pWHm?= =?ut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?q?BfXvLsH05ReAn2AsN1nKUz3RC78BvhjAK4u62uFkN8ZY9D2Fg6OQJ1/Rkfp4IyYqn?= =?utf-8?q?nr8zujQmqkUWQhCxNhG7RckURZ0FmzEeuTKrQotnbhMN5gogiEdFi/F7/InX91EZa?= =?utf-8?q?W6GjwTv1Y906KTmX03ebtV9Bj+G/dZoksKNZhB6IFSIoO4bCeDw9MmGrGOXFxXsd8?= =?utf-8?q?ww8ryyAvsv4ssBzwayiHGxoQCWOyotq13rLQ9O/x9AqA/aFCZpMdLyho9xdpn9VXq?= =?utf-8?q?KQrBAIIczzD7oDhIgaq/AB6otlU+MRlQGQ=3D=3D?= X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-Network-Message-Id: 615d9b18-8006-4f68-34d6-08db692d15db X-MS-Exchange-CrossTenant-AuthSource: AS4PR10MB6181.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2023 21:04:16.5681 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jkg4RELARfWSW2V/vvynImkJOQP8noe9zxoouFJA+2ZLclEDibtIRsgHUKyxaiDNkvCF5m3uFz0l+6x7uNJ+Qw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR10MB7428 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768261914334786174?= X-GMAIL-MSGID: =?utf-8?q?1768261914334786174?= From: Jan Kiszka The VL bit in the seconds register remains set only until seconds are written under main power. As this often happens during boot-up after picking up a network time, make sure to preserve the low battery state across this, caching it and returning it via the RTC_VL_BACKUP_LOW bit. To permit userspace clearing this state during runtime, also implement RTC_VL_CLR that works against the cached state. This is emulating RTCs which have a battery voltage check that works under main power as well. Signed-off-by: Jan Kiszka --- drivers/rtc/rtc-pcf8563.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index 7e720472213c..f8c6cdb9a39d 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c @@ -81,6 +81,7 @@ struct pcf8563 { #ifdef CONFIG_COMMON_CLK struct clk_hw clkout_hw; #endif + bool low_bat; }; static int pcf8563_read_block_data(struct i2c_client *client, unsigned char reg, @@ -207,6 +208,7 @@ static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) return err; if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) { + pcf8563->low_bat = true; dev_err(&client->dev, "low voltage detected, date/time is not reliable.\n"); return -EINVAL; @@ -277,6 +279,8 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm) static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) { struct i2c_client *client = to_i2c_client(dev); + struct pcf8563 *pcf8563 = i2c_get_clientdata(client); + unsigned int state = 0; int ret; switch (cmd) { @@ -284,9 +288,16 @@ static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long ret = i2c_smbus_read_byte_data(client, PCF8563_REG_SC); if (ret < 0) return ret; - - return put_user(ret & PCF8563_SC_LV ? RTC_VL_DATA_INVALID : 0, - (unsigned int __user *)arg); + if (ret & PCF8563_SC_LV) { + state |= RTC_VL_DATA_INVALID; + pcf8563->low_bat = true; + } + if (pcf8563->low_bat) + state |= RTC_VL_BACKUP_LOW; + return put_user(state, (unsigned int __user *)arg); + case RTC_VL_CLR: + pcf8563->low_bat = false; + return 0; default: return -ENOIOCTLCMD; }