From patchwork Wed Oct 25 16:21:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 1855171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=wolfvision.net header.i=@wolfvision.net header.a=rsa-sha256 header.s=selector2 header.b=SGAobYfq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=permerror (SPF Permanent Error: More than 10 MX records returned) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-rtc+bounces-125-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SFvMl6wtSz23jp for ; Thu, 26 Oct 2023 03:22:11 +1100 (AEDT) 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8713D281CA9 for ; Wed, 25 Oct 2023 16:22:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC40E2E65C; Wed, 25 Oct 2023 16:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="SGAobYfq" X-Original-To: linux-rtc@vger.kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 C0E3D2E620; Wed, 25 Oct 2023 16:22:04 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2063.outbound.protection.outlook.com [40.107.21.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31BE691; Wed, 25 Oct 2023 09:22:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mK8zV6UM7/b0uD/de1z9Q9Ol3fuyQam44pj4vNTsl4OD7bo8tpbNHB2oBeTFrLSnajPLK56hJnpgUQvTYyfHIQxjmWjEMU6LWJGcDtBGnDi2mO5GhwAc4jHFv12fXJ8GRBYBfuotuuiPiSPD9+diqHi/N2X/67lcsuJUuDgc/53jUtFepqlA+MeOuxBmdnXQ5BjmIKtlagK9ptP6RZTqSBdQSMcHNxpM3CaGa8g/4cSd06LTdmIFke+xIvORucLvc7N2zD+pAju6iaHP+fapSHPOcyGdv20rPc6BbSj9Wgplw7gYS2anDUPR3ovFKces/dazk8ccOBGVe0f0OeByEw== 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=IhnIsREnNliGjRhfvQxTajFTEWoDQVcts8ho7zL724g=; b=jAWD+7fF5lzc0GlqhKOcJJA+hTgCwLhNizr36XMjpdsy3aNPpc2J9zJcGVayNqamrKF+F+kWf2SOArIbyUxs9JRhO2Fz+Vug6JatQuJffP8hbS/rfmheJKpu3A62/NJJqvdCX6bz0uX3ONzZATrjoUOgPQzm4/nzYDihalqwjAHhxxXmX4bcMYyITp3ZHhYv/m1IB/gMbiXg9pEayfA6K8uWRIqFxOHAFNcwmSK7E7qvLRxPC1R7fSFj2kj5W30oE77h6RDDHm6Pbx2WuXon3yVbTHrYApY92156lx2pkI9FlU2vysY5QTEHQQsvicqSuY9A6XcuSaTAW61GQJ0P/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wolfvision.net; dmarc=pass action=none header.from=wolfvision.net; dkim=pass header.d=wolfvision.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfvision.net; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IhnIsREnNliGjRhfvQxTajFTEWoDQVcts8ho7zL724g=; b=SGAobYfq1kMFWIOD30ZM3Y3SWc3T+sYwjN1nHboWkZRTQ0CQAz5UDNr5FW1U1Pc/NQK9twAdBezqTFzp4Jo5OjDNtUKDTABg4LY3aPjqdaKnRuYOhJBnC1YWVIxrXgoaITgfzGKC+Dwu7oPen+TWm8GnON8ZK9fjAaD6CQij+c8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) by VI1PR08MB5376.eurprd08.prod.outlook.com (2603:10a6:803:13e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Wed, 25 Oct 2023 16:21:59 +0000 Received: from VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::a309:1d65:f5fb:436b]) by VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::a309:1d65:f5fb:436b%6]) with mapi id 15.20.6933.019; Wed, 25 Oct 2023 16:21:59 +0000 From: Javier Carrasco Date: Wed, 25 Oct 2023 18:21:54 +0200 Subject: [PATCH 1/2] rtc: pcf85363: add support for high-impedance output Message-Id: <20231024-topic-pcf85363_hiz_output-v1-1-50908aff0e52@wolfvision.net> References: <20231024-topic-pcf85363_hiz_output-v1-0-50908aff0e52@wolfvision.net> In-Reply-To: <20231024-topic-pcf85363_hiz_output-v1-0-50908aff0e52@wolfvision.net> To: Alessandro Zummo , Alexandre Belloni , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1698250918; l=4421; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=FF2xr2kA4qsEIO3Vzgxe9YV6LCFr1AZBTHkk4R/7HSw=; b=NL8dEBmMmFEa4v289RMS3qED08d9Bi/PNAHgRlAgMm560xhjgannG3JAEDYQksbycB7EpeQ8j hlUnaI2kB/ECNODS+DQ7m8sHctxJ4H4LsRTmEYmU7SFc0YocF86r7+Z X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1PR0102CA0040.eurprd01.prod.exchangelabs.com (2603:10a6:803::17) To VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) Precedence: bulk X-Mailing-List: linux-rtc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4974:EE_|VI1PR08MB5376:EE_ X-MS-Office365-Filtering-Correlation-Id: 0639ebf5-d03f-4861-eb3e-08dbd576835c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZNPU7U4Qokf4T1lG2mY4jY88P9ro8Kb0SVymhKYqMnTG0QG5vR406H6Za0eCFFYJSRaVRwGT/SoVDv40l/hanWuvVMFctjgTJocZlFVWj3B+KlaN+RXsJRSg1Pwcsuzj+4R2FE4w1rKob9jQjj+mE3x0MZJwgTCUkZF8Mk7zqSk4q9nrtIXe+2dDRsg0qiXGeHIcFn2loZAeRS6RnbLAo3AL1xIq86NMXdB8CsHuJr+03DRSpjGa7m/XEW9HaLcI98I/VsMOeWfRsOTTIjDHIr717WV+0BoRCFAxzUy2qV9BMjJgQ23FsWBWXJxMLDiIPlgaTmvoek8esbyY2/ULla50MsBOMMbrcy3DRXlTFACBre95oVfe9mVZpfwFx0+y0+mQ3RZ5q2xbOEyaHPD7MwxK8D3d1uP9eGPV6/2ePa6J4OOnCGeohid0BuX53ATcfs+VCpVOMDwRm59kfHHPwgH+DPme1VN9CmN4B5hpfI+SaopOPh2RkMtc4x+Z4GbmMVq8RMk/naGuLFm6FGHKO1rCzBReITGNRcVW95CyLfLagEvvhYyC9bRgzTAHrY/yZqNtphA8LEvV5rIwr+GvsdeuWt5yiEc/vjH68XNztwwc1TgrbPzYs8xIiPsv40U8 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR08MB4974.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39840400004)(396003)(376002)(136003)(366004)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(4326008)(2906002)(8676002)(8936002)(44832011)(83380400001)(6486002)(107886003)(52116002)(5660300002)(41300700001)(6512007)(6506007)(86362001)(316002)(110136005)(26005)(478600001)(6666004)(2616005)(36756003)(38100700002)(66946007)(66556008)(66476007)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ZusoKFoGUYGodQoq+7pW2IYjPNpb?= =?utf-8?q?O9K53QGxZkSnvq7hN4gQOzvdrF9SFz/0OAHOhTCeoCydw0sdsS16C/138+9Rk/4cJ?= =?utf-8?q?3dMBR68JgsAnNBW71hTL3PeIWSrJekAZ1Sakmgizn8iEpEBgUI5LpBW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= =?utf-8?q?0YzRDDiYxab1FGCkXjPVBKcXlwdiCXfp5y/t+1PG3+ZJFjAnh0T+TYBU9TCDtAWWU?= =?utf-8?q?irQvYbKNqAyfzaEXPtnmJoQ5YyXQ1l3yXb+fQEEEeV1Ae7eTrcRF3SJfB/nHar94N?= =?utf-8?q?nRopfWsz75+gvuEsWGpZaBIGfgK/lhTJrz91jDK4gFWbgpSrmGyAWRopX8vSCVb/c?= =?utf-8?q?tBewYKNmccqjoKoQGcLGIhcVarmXAlVc01ZOCskaYfnUhWT39tGL1pGPBv8stNYal?= =?utf-8?q?DoQgKQaaJfJhScuLI0JD4XrOD55GMc/JbZy660YFANrqLYTsnEKz6wyMAUjZnVBCP?= =?utf-8?q?1P/2RgIRXIxCAkXR/Rzjh97oJrBIyVaNaga3tBiTVgFn9DywmRsfjyOZHXqCJa/Lw?= =?utf-8?q?YHW2/bTRNo3lKtu3lZX2Pi4izppXWfPrr7I685dudknbru2/IGW1vP0EC/hhqv20K?= =?utf-8?q?PkFist8iJFhM2GfGdAKvWqstaF4DizuOBPCTJJ9Jnx9AtpLvVPjnGuyO5cuJsN9VS?= =?utf-8?q?Iq81FhVo3UM6sJp1F/0Knzc61rkHiQ5qZDWIDpBbj2xaJSSgUoDtMgM=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 0639ebf5-d03f-4861-eb3e-08dbd576835c X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4974.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 16:21:59.0785 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e94ec9da-9183-471e-83b3-51baa8eb804f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5qdMebzrFqtiDZjmdTNRqaaZ86wT+56JpaeffBw2ebfgfIF/3t0LP7JD82dKN10IWGa6Mb7pxkTaLDHngqZs1WYnfpI4QOe1fbeKmpJUc/g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5376 The pcf85363 provides a high-impedance (hi-Z) mode for its output. This mode can be used to reduce power consumption in applications where the RTC output is only required as a clock/interrupt source when the system runs in low-power mode (i.e. serving as a clock source for a PMU when the system is down). If the output is not needed, it can also be completely disabled. This implementation adds support for a hi-Z output and also uses simple pm operations (suspend and resume) to switch the output mode from hi-Z in normal operation to the required operation mode in sleep mode (currently either clock or interrupt) if the "sleep" value for the hiz-output was set. In order to make use of the hi-Z output modeling via device tree, check if the new "hiz-output" property is defined and set the hi-Z mode accordingly. Signed-off-by: Javier Carrasco --- drivers/rtc/rtc-pcf85363.c | 62 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c index 540042b9eec8..82eaf8de8b33 100644 --- a/drivers/rtc/rtc-pcf85363.c +++ b/drivers/rtc/rtc-pcf85363.c @@ -110,9 +110,17 @@ #define NVRAM_SIZE 0x40 +enum pcf85363_hiz_output_t { + PCF85363_HIZ_OFF, + PCF85363_HIZ_ON, + PCF85363_HIZ_SLEEP, +}; + struct pcf85363 { struct rtc_device *rtc; struct regmap *regmap; + + enum pcf85363_hiz_output_t hiz_output; }; struct pcf85x63_config { @@ -403,6 +411,7 @@ static int pcf85363_probe(struct i2c_client *client) }; int ret, i, err; bool wakeup_source; + const char *hiz_output = NULL; if (data) config = data; @@ -433,9 +442,32 @@ static int pcf85363_probe(struct i2c_client *client) pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099; + if (device_property_present(&client->dev, "hiz-output")) { + ret = device_property_read_string(&client->dev, "hiz-output", + &hiz_output); + if (ret) + return ret; + + if (!strcmp(hiz_output, "enabled")) { + pcf85363->hiz_output = PCF85363_HIZ_ON; + } else if (!strcmp(hiz_output, "sleep")) { + pcf85363->hiz_output = PCF85363_HIZ_SLEEP; + } else if (!strcmp(hiz_output, "disabled")) { + pcf85363->hiz_output = PCF85363_HIZ_OFF; + } else { + dev_warn(&client->dev, "Unknown hiz-output: %s. Assuming disabled", + hiz_output); + pcf85363->hiz_output = PCF85363_HIZ_OFF; + } + } else { + pcf85363->hiz_output = PCF85363_HIZ_OFF; + } wakeup_source = device_property_read_bool(&client->dev, "wakeup-source"); - if (client->irq > 0 || wakeup_source) { + if (pcf85363->hiz_output != PCF85363_HIZ_OFF) { + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, + PIN_IO_INTAPM, PIN_IO_INTA_HIZ); + } else if (client->irq > 0 || wakeup_source) { regmap_write(pcf85363->regmap, CTRL_FLAGS, 0); regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, PIN_IO_INTAPM, PIN_IO_INTA_OUT); @@ -474,6 +506,31 @@ static int pcf85363_probe(struct i2c_client *client) return ret; } +#ifdef CONFIG_PM_SLEEP +static int pcf85363_suspend(struct device *dev) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + + if (pcf85363->hiz_output == PCF85363_HIZ_SLEEP) + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, PIN_IO_INTAPM, + device_may_wakeup(dev) ? PIN_IO_INTA_OUT : + PIN_IO_INTA_CLK); + + return 0; +} + +static int pcf85363_resume(struct device *dev) +{ + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); + + if (pcf85363->hiz_output == PCF85363_HIZ_SLEEP) + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, + PIN_IO_INTAPM, PIN_IO_INTA_HIZ); + + return 0; +} +#endif + static const __maybe_unused struct of_device_id dev_ids[] = { { .compatible = "nxp,pcf85263", .data = &pcf_85263_config }, { .compatible = "nxp,pcf85363", .data = &pcf_85363_config }, @@ -481,9 +538,12 @@ static const __maybe_unused struct of_device_id dev_ids[] = { }; MODULE_DEVICE_TABLE(of, dev_ids); +static SIMPLE_DEV_PM_OPS(pcf85363_pm_ops, pcf85363_suspend, pcf85363_resume); + static struct i2c_driver pcf85363_driver = { .driver = { .name = "pcf85363", + .pm = &pcf85363_pm_ops, .of_match_table = of_match_ptr(dev_ids), }, .probe = pcf85363_probe,