Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1925929rbb; Tue, 27 Feb 2024 05:49:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWrFtO/TP0APIoAXgbLwDy+eN0IsHdGxwN9IY8R4JRD5IXHEzLml0pmhcmWiWSSNkDWIEYWH50ISdqZ1o7HiTYG48Ww3vPudfD6Iz0PEQ== X-Google-Smtp-Source: AGHT+IGBWFZlM+LxCU2au9dColZvY0SoyMez2/q6YIg4a8yFFS4iVdNDopkKds22HsIkwt5Dei8C X-Received: by 2002:a05:6a20:9d90:b0:1a0:8897:85f1 with SMTP id mu16-20020a056a209d9000b001a0889785f1mr2722933pzb.6.1709041752926; Tue, 27 Feb 2024 05:49:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709041752; cv=pass; d=google.com; s=arc-20160816; b=hRsu+V3GCiuczsdx2Azfri7+cisDOLZbCz4nBwbXVEwCr+TLfzioTMFrj/REeP8lkp CKK+d1yjFmxffPhYbN68AB5wO9g84ICdF8lBpjQuFdEAMzsMP841nmOE+wdJ1tPcO3SU zcigtB1KBtrDp4/A8PE04VXDNcmtpqXWnFZp6OSQ0bz71ybk9EBq85lhmuAxOx0Nzsxy 5IviSAwxA0+EQDtdDOrsQbYoXGUXeZD9Ect5X47teMxy2ryDd758F7Eo3gDPDH1tnTfR 3uq1zTu5kcJbZCy0hHQtdb7wEJKnmk15NgIXI4K08iW7qVIHJEuaHGp4kwxSOLCjnm7w t/Ow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=gx92jGR/bM3wlQtlpHTsHDgQzGr0Puey6WoEtzn4I0A=; fh=3igxOK/ISV363Xw+kJj82ijTypjWQSd3eD7wwvupeo4=; b=dT0SITUtOLhJAQ5O8j2XUY6b/NrkeBnZ+kKIuuxfq7cj7u5i23KW+cjPRLvMbDCbV9 NplQL+9a3alZu2hZxymN62rvkCpcu3eaYHJ014qFVWQxqV0GgHie/kB9SGLBDikCpUd0 5f8ZUPRGeGW9L7BIJYuDmFhjPSNK++wp7bO+w0m/TB/x3TSwXQnE4nACtYP1Ql/Jg+lE DW2RuCpABCsyAJ4cm+zaOtz+UKDN+WtyzSd5pZvX3hXZhAewOG6bidgy3mgv/gOXYeNw 7/4KYIx/SER2atdioYjMwY8nVZiV+wilC47siEVEKFA9Nvk5BjxvkPHkV4jP+37zo7jX y4+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=eCuzhSel; arc=pass (i=1 spf=pass spfdomain=rts-flowmailer.siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of linux-kernel+bounces-83299-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h9-20020a635749000000b005e2c2fc5125si5460565pgm.249.2024.02.27.05.49.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 05:49:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83299-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=eCuzhSel; arc=pass (i=1 spf=pass spfdomain=rts-flowmailer.siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of linux-kernel+bounces-83299-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B3985B2AEDD for ; Tue, 27 Feb 2024 13:16:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCE6F13B7AE; Tue, 27 Feb 2024 13:15:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=siemens.com header.i=alexander.sverdlin@siemens.com header.b="eCuzhSel" Received: from mta-65-225.siemens.flowmailer.net (mta-65-225.siemens.flowmailer.net [185.136.65.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D82113B7A2 for ; Tue, 27 Feb 2024 13:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.136.65.225 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709039727; cv=none; b=UJsnVMHnlRrO5kMzoVMMyJTsSFYYX3wOnXQyrCJzMRMnIq2s1awuILAcaXoLNTNruP8da5MSd+V35GW0nUjHoC3hCIylJ2Qu42/Jw3hDC9JxK0xDMubZtl2J7lP0dLKbkokQVGKrJpTBn65uqNLBiS6nG1vIq+UzQ2NhiBGkPFg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709039727; c=relaxed/simple; bh=FP6AjnY6lykXcHHYUiN/iTD0OoHVJjRqhJvevTgWu7k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SWkJe0ANlK6AgMosKjlpEk98fJo7NrvlnpQ7kXjUwe+wNeJjlXUVE3weY5XOC0TLGB4/uKxa7COBuoEsHhI8y/0orCr1Z0+Zax20JrVMnsHpRNLLCcqicVAyhMPsjwjKvd4PTvtlvI68EO3Qxo0LtzHsXCeVXZJ+KHlQJ4gH5vw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com; dkim=pass (1024-bit key) header.d=siemens.com header.i=alexander.sverdlin@siemens.com header.b=eCuzhSel; arc=none smtp.client-ip=185.136.65.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=siemens.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rts-flowmailer.siemens.com Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20240227131514b5d18e2db4e7cf0d04 for ; Tue, 27 Feb 2024 14:15:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=alexander.sverdlin@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc; bh=gx92jGR/bM3wlQtlpHTsHDgQzGr0Puey6WoEtzn4I0A=; b=eCuzhSelNHUz20au0aROGtgres048/b9fq80IOQZyW7fUcqgF6IMwNn3u9rMYt3wZ5mvYX ikQhMyy2f1Fwtg8aqH13f1l3tZ1gEB7L+jVatBQhuYMmlQ85+1hm1oZ6WhNtw+bT1OHyy7L+ vNbcsOUwgQcDp4EUro2PIoG60VOgw=; From: "A. Sverdlin" To: linux-rtc@vger.kernel.org Cc: Lukas Stockmann , Alexandre Belloni , linux-kernel@vger.kernel.org, Alexander Sverdlin Subject: [PATCH] rtc: pcf85063: do a SW reset after rtc power fail Date: Tue, 27 Feb 2024 14:14:32 +0100 Message-ID: <20240227131436.3342807-1-alexander.sverdlin@siemens.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-456497:519-21489:flowmailer From: Lukas Stockmann From PCF85063A datasheet, section "Software reset": "There is a low probability that some devices will have corruption of the registers after the automatic power-on reset if the device is powered up with a residual VDD level. It is required that the VDD starts at zero volts at power up or upon power cycling to ensure that there is no corruption of the registers. If this is not possible, a reset must be initiated after power-up (i.e. when power is stable) with the software reset command" Trigger SW reset if a power loss is detected. Link: https://www.nxp.com/docs/en/data-sheet/PCF85063A.pdf Signed-off-by: Lukas Stockmann Signed-off-by: Alexander Sverdlin --- drivers/rtc/rtc-pcf85063.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c index fdbc07f14036..edfd75d18e19 100644 --- a/drivers/rtc/rtc-pcf85063.c +++ b/drivers/rtc/rtc-pcf85063.c @@ -35,6 +35,7 @@ #define PCF85063_REG_CTRL1_CAP_SEL BIT(0) #define PCF85063_REG_CTRL1_STOP BIT(5) #define PCF85063_REG_CTRL1_EXT_TEST BIT(7) +#define PCF85063_REG_CTRL1_SWR 0x58 #define PCF85063_REG_CTRL2 0x01 #define PCF85063_CTRL2_AF BIT(6) @@ -580,7 +581,7 @@ static int pcf85063_probe(struct i2c_client *client) i2c_set_clientdata(client, pcf85063); - err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp); + err = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &tmp); if (err) { dev_err(&client->dev, "RTC chip is not present\n"); return err; @@ -590,6 +591,22 @@ static int pcf85063_probe(struct i2c_client *client) if (IS_ERR(pcf85063->rtc)) return PTR_ERR(pcf85063->rtc); + /* + * If a Power loss is detected, SW reset the device. + * From PCF85063A datasheet: + * There is a low probability that some devices will have corruption + * of the registers after the automatic power-on reset... + */ + if (tmp & PCF85063_REG_SC_OS) { + dev_warn(&client->dev, + "Power loss detected, send a SW reset to the device\n"); + err = regmap_write(pcf85063->regmap, PCF85063_REG_CTRL1, + PCF85063_REG_CTRL1_SWR); + if (err < 0) + dev_err(&client->dev, + "SW reset failed, trying to continue\n"); + } + err = pcf85063_load_capacitance(pcf85063, client->dev.of_node, config->force_cap_7000 ? 7000 : 0); if (err < 0) -- 2.43.2