From patchwork Thu Dec 15 15:02:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421554wrn; Thu, 15 Dec 2022 07:20:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf67GhFV+Jb8tnkx82s39GWIC8TDpJDUfPl/YjX5A2o2acK3GJa/S36908R5ciaJmq3pj6f7 X-Received: by 2002:a17:903:138a:b0:189:5f5c:da1f with SMTP id jx10-20020a170903138a00b001895f5cda1fmr29647003plb.5.1671117615785; Thu, 15 Dec 2022 07:20:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117615; cv=none; d=google.com; s=arc-20160816; b=e6JOEREofciZ36UJXnb3c9LYz79JpwaYUJHYVTaWF98ilJ+fiUZZ5HcYSR7NSBCa67 rpvDwf2+vKI6uKjBTMIbHl+Uswi9L2J7+qXxe2qJrIIpaKbaFOXbY9kZxyse8c0tf162 /GmAuK7lBXLSaH8HQjV4wI0idZrJilgRMd72gPwGiQlw5KMQA5lgNso43g1neLG5oX6W iEBgq+S8l0hczKgajSzi6NK66subcS0Kkvpxt21kt+jvOhqoZA7b5L9S79KzBbfgZcg4 Zke+64yk/Vw20+TqaO356Qu6ahELi63WXLQAY/iG3W+6juE5DT18Z/sFCf9KcUcFKCwF Ao4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=O2eT0UvgGEQnr0ncJDYohPICi1eRFPTbSDswL/HyXgA=; b=GpdBkqX/6w58XjyX8EUNek6oKuiUcQOJ0d21T4GDIqHvrzopl2iRHTDcV1q7eomnJf +2cRFSWCObYYwSh/0PSlPSnBLiVJfjKyIXhxO+AUXljciuDTZU65NJQUtlxBm93dVwnP +OYgIKAVEzb1MoNuYg24wKfbnQ2IWytxfe4IVeJnVBg5kbQNvQK+X9oFeHm/sMjKyjGV ieD5hhYBEnK43i6lRSDeYIazNSnnRTDuiR/wriF/RlN8AFRKFsfMHpQfJgPKyEx42wQW W4pa39dlA/iurXMomp92kddkug8McrdF8KPjzbnWeBH689AxdzC7+A0xdltsBygaQQ3w i7Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=TPHPiwu8; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f11-20020a170902ce8b00b00189274c157bsi6714238plg.518.2022.12.15.07.20.02; Thu, 15 Dec 2022 07:20:15 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=TPHPiwu8; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbiLOPSf (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbiLOPSP (ORCPT ); Thu, 15 Dec 2022 10:18:15 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE28919F; Thu, 15 Dec 2022 07:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=O2eT0UvgGEQnr0ncJDYohPICi1eRFPTbSDswL/HyXgA=; b=TPHPiwu8YYuQMCzrLvN0U40GOM EWEBQxHmI+erGzWQzgQYWaefE+ARnWiCBFwRy2DqgJLSyWXKIPmMyelz28/JW/b5Ubj9ZpkGPeVyP qDj74Gxz5Yau+bJG2sTCRfywe+Vy5jt7WE0tX8VsGysEsCnHt6/hWG4L/1hmG2lAlSBI=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pm8-0000EC-JF; Thu, 15 Dec 2022 10:03:57 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:02 -0500 Message-Id: <20221215150214.1109074-2-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 01/14] rtc: pcf2127: add variant-specific configuration structure X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293825224507015?= X-GMAIL-MSGID: =?utf-8?q?1752293825224507015?= From: Hugo Villeneuve Create variant-specific configuration structures to simplify the implementation of new variants into this driver. It will also avoid to have too many tests for a specific variant, or a list of variants for new devices, inside the code itself. Add configuration options for the support of the NVMEM, bit CD0 in register WD_CTL as well as the maximum number of registers for each variant, instead of hardcoding the variant (PCF2127) inside the i2c_device_id and spi_device_id structures. Also specify a different maximum number of registers (max_register) for the PCF2129. Signed-off-by: Hugo Villeneuve Reviewed-by: Bruno Thomsen --- drivers/rtc/rtc-pcf2127.c | 95 +++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 87f4fc9df68b..b9a5d47a439f 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -101,10 +102,17 @@ PCF2127_BIT_CTRL2_WDTF | \ PCF2127_BIT_CTRL2_TSF2) +struct pcf21xx_config { + int max_register; + unsigned int has_nvmem:1; + unsigned int has_bit_wd_ctl_cd0:1; +}; + struct pcf2127 { struct rtc_device *rtc; struct watchdog_device wdd; struct regmap *regmap; + const struct pcf21xx_config *cfg; time64_t ts; bool ts_valid; bool irq_enabled; @@ -631,8 +639,27 @@ static const struct attribute_group pcf2127_attr_group = { .attrs = pcf2127_attrs, }; +enum pcf21xx_type { + PCF2127, + PCF2129, + PCF21XX_LAST_ID +}; + +static struct pcf21xx_config pcf21xx_cfg[] = { + [PCF2127] = { + .max_register = 0x1d, + .has_nvmem = 1, + .has_bit_wd_ctl_cd0 = 1, + }, + [PCF2129] = { + .max_register = 0x19, + .has_nvmem = 0, + .has_bit_wd_ctl_cd0 = 0, + }, +}; + static int pcf2127_probe(struct device *dev, struct regmap *regmap, - int alarm_irq, const char *name, bool is_pcf2127) + int alarm_irq, const char *name, const struct pcf21xx_config *config) { struct pcf2127 *pcf2127; int ret = 0; @@ -645,6 +672,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, return -ENOMEM; pcf2127->regmap = regmap; + pcf2127->cfg = config; dev_set_drvdata(dev, pcf2127); @@ -688,7 +716,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, set_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features); } - if (is_pcf2127) { + if (pcf2127->cfg->has_nvmem) { struct nvmem_config nvmem_cfg = { .priv = pcf2127, .reg_read = pcf2127_nvmem_read, @@ -734,7 +762,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, PCF2127_BIT_WD_CTL_TF1 | PCF2127_BIT_WD_CTL_TF0, PCF2127_BIT_WD_CTL_CD1 | - (is_pcf2127 ? PCF2127_BIT_WD_CTL_CD0 : 0) | + (pcf2127->cfg->has_bit_wd_ctl_cd0 ? PCF2127_BIT_WD_CTL_CD0 : 0) | PCF2127_BIT_WD_CTL_TF1); if (ret) { dev_err(dev, "%s: watchdog config (wd_ctl) failed\n", __func__); @@ -799,9 +827,9 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, #ifdef CONFIG_OF static const struct of_device_id pcf2127_of_match[] = { - { .compatible = "nxp,pcf2127" }, - { .compatible = "nxp,pcf2129" }, - { .compatible = "nxp,pca2129" }, + { .compatible = "nxp,pcf2127", .data = &pcf21xx_cfg[PCF2127] }, + { .compatible = "nxp,pcf2129", .data = &pcf21xx_cfg[PCF2129] }, + { .compatible = "nxp,pca2129", .data = &pcf21xx_cfg[PCF2129] }, {} }; MODULE_DEVICE_TABLE(of, pcf2127_of_match); @@ -886,26 +914,40 @@ static const struct regmap_bus pcf2127_i2c_regmap = { static struct i2c_driver pcf2127_i2c_driver; static const struct i2c_device_id pcf2127_i2c_id[] = { - { "pcf2127", 1 }, - { "pcf2129", 0 }, - { "pca2129", 0 }, + { "pcf2127", PCF2127 }, + { "pcf2129", PCF2129 }, + { "pca2129", PCF2129 }, { } }; MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id); static int pcf2127_i2c_probe(struct i2c_client *client) { - const struct i2c_device_id *id = i2c_match_id(pcf2127_i2c_id, client); struct regmap *regmap; - static const struct regmap_config config = { + static struct regmap_config config = { .reg_bits = 8, .val_bits = 8, - .max_register = 0x1d, }; + const struct pcf21xx_config *variant; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; + if (client->dev.of_node) { + variant = of_device_get_match_data(&client->dev); + if (!variant) + return -ENODEV; + } else { + enum pcf21xx_type type = + i2c_match_id(pcf2127_i2c_id, client)->driver_data; + + if (type >= PCF21XX_LAST_ID) + return -ENODEV; + variant = &pcf21xx_cfg[type]; + } + + config.max_register = variant->max_register, + regmap = devm_regmap_init(&client->dev, &pcf2127_i2c_regmap, &client->dev, &config); if (IS_ERR(regmap)) { @@ -915,7 +957,7 @@ static int pcf2127_i2c_probe(struct i2c_client *client) } return pcf2127_probe(&client->dev, regmap, client->irq, - pcf2127_i2c_driver.driver.name, id->driver_data); + pcf2127_i2c_driver.driver.name, variant); } static struct i2c_driver pcf2127_i2c_driver = { @@ -953,17 +995,32 @@ static void pcf2127_i2c_unregister_driver(void) #if IS_ENABLED(CONFIG_SPI_MASTER) static struct spi_driver pcf2127_spi_driver; +static const struct spi_device_id pcf2127_spi_id[]; static int pcf2127_spi_probe(struct spi_device *spi) { - static const struct regmap_config config = { + static struct regmap_config config = { .reg_bits = 8, .val_bits = 8, .read_flag_mask = 0xa0, .write_flag_mask = 0x20, - .max_register = 0x1d, }; struct regmap *regmap; + const struct pcf21xx_config *variant; + + if (spi->dev.of_node) { + variant = of_device_get_match_data(&spi->dev); + if (!variant) + return -ENODEV; + } else { + enum pcf21xx_type type = spi_get_device_id(spi)->driver_data; + + if (type >= PCF21XX_LAST_ID) + return -ENODEV; + variant = &pcf21xx_cfg[type]; + } + + config.max_register = variant->max_register, regmap = devm_regmap_init_spi(spi, &config); if (IS_ERR(regmap)) { @@ -974,13 +1031,13 @@ static int pcf2127_spi_probe(struct spi_device *spi) return pcf2127_probe(&spi->dev, regmap, spi->irq, pcf2127_spi_driver.driver.name, - spi_get_device_id(spi)->driver_data); + variant); } static const struct spi_device_id pcf2127_spi_id[] = { - { "pcf2127", 1 }, - { "pcf2129", 0 }, - { "pca2129", 0 }, + { "pcf2127", PCF2127 }, + { "pcf2129", PCF2129 }, + { "pca2129", PCF2129 }, { } }; MODULE_DEVICE_TABLE(spi, pcf2127_spi_id); From patchwork Thu Dec 15 15:02:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33688 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp433533wrn; Thu, 15 Dec 2022 07:40:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf7s7j26ysI4RRDJEjVrtmuygfmh7XQNxJZ/NqxyDnySyk2amdx+ZczyZl2t93lcEEEnhp/h X-Received: by 2002:a05:6a20:9596:b0:aa:ac2:93c7 with SMTP id iu22-20020a056a20959600b000aa0ac293c7mr35501977pzb.54.1671118854859; Thu, 15 Dec 2022 07:40:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671118854; cv=none; d=google.com; s=arc-20160816; b=ISYKY1GvcGz5LiKmFNPQkRfZeR0ivDzrmAsK2K4L6lGaOX1xHB5DRHoX1bXZgzpNVQ gttaCcfcWcC2+/hHWQsRETFwlIntzc+uWpHSeNBYq1qA8FoiDO6J/EB6niO2flUmZgBy ZS3GhQUCR6SOc6kvj/iiBJKzxWbjGQxkEhQStXbB8y7ZU4b9PtqK3ou/pcc7gOiK8oYu UP8MYt+VovCLwRcpOuzARfN3eRuOw2F8Ae4Fos4iL3zrG69sMtpu8hI8Nlp8y9mQdO2I lFBQjg9esAZHQ6gQHOF53UWRr+J071j1Sp54dz01YcqeWaxiaCTDmoKeQv9mgLbOFjwP gF/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=DUk52/OBG9O2b+mwH7NQ1X4tP0YNoZQ+so1GRMEfi1E=; b=FI9cQArEOtwHPkO/gFJDTFbgxz2ckxjYlflxIojvZuorTCxO8C1hjjWtJQZWmROcnR 4/1d78Tr5fF8C/H2HZejB5Obdy7/KxQCPK8SQsAeLDr4pStTBPHIpRARbCtWDalMBsMF MquSH6ZcUUMt/t/qdCbJ//9WKa5Kkgp6PjDqYFTbdCxmGGBygkVzkU5soNml2NkO/AtH tRVtwqX3yYCYtU8kyGhyWevY2WS0YyTgt/fZC0pBd04YP8wqTzJKztBGnljzWKfgrfUe xFdx6hW5Dju3ITtR6TJy0hT1JeAiB5/vIneSnhH0QeV8eAojhmc1RPJrBvc1LoaZikU+ b+KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=qwPJXTaq; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a654cc5000000b00478d5e8c4f5si2818542pgt.383.2022.12.15.07.40.39; Thu, 15 Dec 2022 07:40:54 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=qwPJXTaq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbiLOPUB (ORCPT + 99 others); Thu, 15 Dec 2022 10:20:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230228AbiLOPTZ (ORCPT ); Thu, 15 Dec 2022 10:19:25 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D82CF31DD5; Thu, 15 Dec 2022 07:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=DUk52/OBG9O2b+mwH7NQ1X4tP0YNoZQ+so1GRMEfi1E=; b=qwPJXTaqJTga6gu/CpIuhowGGY UMYkvlM5UKC2M8hqHEbhBzJO6KLw80kIQCtAUTHwNV5bKYjq5yHy5Y9tQC+RbrVhNnbEK1+xMqSXc rvyV8TA22Ac/rVt/XH3qjsJxqDVxR7nakH29tksgitFBWmVl2trxBKa+xnN8qoz/KA48=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pm9-0000EC-QT; Thu, 15 Dec 2022 10:03:58 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:03 -0500 Message-Id: <20221215150214.1109074-3-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 02/14] rtc: pcf2127: adapt for time/date registers at any offset X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752295124440773425?= X-GMAIL-MSGID: =?utf-8?q?1752295124440773425?= From: Hugo Villeneuve This will simplify the implementation of new variants into this driver. Some variants (PCF2131) have a 100th seconds register. This register is currently not supported in this driver. Signed-off-by: Hugo Villeneuve --- drivers/rtc/rtc-pcf2127.c | 68 ++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index b9a5d47a439f..fb0caacaabee 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -44,14 +44,17 @@ #define PCF2127_BIT_CTRL3_BF BIT(3) #define PCF2127_BIT_CTRL3_BTSE BIT(4) /* Time and date registers */ -#define PCF2127_REG_SC 0x03 +#define PCF2127_REG_TIME_DATE_BASE 0x03 +/* Time and date registers offsets (starting from base register) */ +#define PCF2127_OFFSET_TD_SC 0 +#define PCF2127_OFFSET_TD_MN 1 +#define PCF2127_OFFSET_TD_HR 2 +#define PCF2127_OFFSET_TD_DM 3 +#define PCF2127_OFFSET_TD_DW 4 +#define PCF2127_OFFSET_TD_MO 5 +#define PCF2127_OFFSET_TD_YR 6 +/* Time and date registers bits */ #define PCF2127_BIT_SC_OSF BIT(7) -#define PCF2127_REG_MN 0x04 -#define PCF2127_REG_HR 0x05 -#define PCF2127_REG_DM 0x06 -#define PCF2127_REG_DW 0x07 -#define PCF2127_REG_MO 0x08 -#define PCF2127_REG_YR 0x09 /* Alarm registers */ #define PCF2127_REG_ALARM_SC 0x0A #define PCF2127_REG_ALARM_MN 0x0B @@ -106,6 +109,7 @@ struct pcf21xx_config { int max_register; unsigned int has_nvmem:1; unsigned int has_bit_wd_ctl_cd0:1; + u8 regs_td_base; /* Time/data base registers. */ }; struct pcf2127 { @@ -125,27 +129,31 @@ struct pcf2127 { static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev); - unsigned char buf[10]; + unsigned char buf[7]; + unsigned int ctrl3; int ret; /* * Avoid reading CTRL2 register as it causes WD_VAL register * value to reset to 0 which means watchdog is stopped. */ - ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL3, - (buf + PCF2127_REG_CTRL3), - ARRAY_SIZE(buf) - PCF2127_REG_CTRL3); - if (ret) { - dev_err(dev, "%s: read error\n", __func__); + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &ctrl3); + if (ret) return ret; - } - if (buf[PCF2127_REG_CTRL3] & PCF2127_BIT_CTRL3_BLF) + if (ctrl3 & PCF2127_BIT_CTRL3_BLF) dev_info(dev, "low voltage detected, check/replace RTC battery.\n"); + ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->regs_td_base, + buf, sizeof(buf)); + if (ret) { + dev_err(dev, "%s: read error\n", __func__); + return ret; + } + /* Clock integrity is not guaranteed when OSF flag is set. */ - if (buf[PCF2127_REG_SC] & PCF2127_BIT_SC_OSF) { + if (buf[PCF2127_OFFSET_TD_SC] & PCF2127_BIT_SC_OSF) { /* * no need clear the flag here, * it will be cleared once the new date is saved @@ -158,18 +166,18 @@ static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm) dev_dbg(dev, "%s: raw data is cr3=%02x, sec=%02x, min=%02x, hr=%02x, " "mday=%02x, wday=%02x, mon=%02x, year=%02x\n", - __func__, buf[PCF2127_REG_CTRL3], buf[PCF2127_REG_SC], - buf[PCF2127_REG_MN], buf[PCF2127_REG_HR], - buf[PCF2127_REG_DM], buf[PCF2127_REG_DW], - buf[PCF2127_REG_MO], buf[PCF2127_REG_YR]); - - tm->tm_sec = bcd2bin(buf[PCF2127_REG_SC] & 0x7F); - tm->tm_min = bcd2bin(buf[PCF2127_REG_MN] & 0x7F); - tm->tm_hour = bcd2bin(buf[PCF2127_REG_HR] & 0x3F); /* rtc hr 0-23 */ - tm->tm_mday = bcd2bin(buf[PCF2127_REG_DM] & 0x3F); - tm->tm_wday = buf[PCF2127_REG_DW] & 0x07; - tm->tm_mon = bcd2bin(buf[PCF2127_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ - tm->tm_year = bcd2bin(buf[PCF2127_REG_YR]); + __func__, ctrl3, buf[PCF2127_OFFSET_TD_SC], + buf[PCF2127_OFFSET_TD_MN], buf[PCF2127_OFFSET_TD_HR], + buf[PCF2127_OFFSET_TD_DM], buf[PCF2127_OFFSET_TD_DW], + buf[PCF2127_OFFSET_TD_MO], buf[PCF2127_OFFSET_TD_YR]); + + tm->tm_sec = bcd2bin(buf[PCF2127_OFFSET_TD_SC] & 0x7F); + tm->tm_min = bcd2bin(buf[PCF2127_OFFSET_TD_MN] & 0x7F); + tm->tm_hour = bcd2bin(buf[PCF2127_OFFSET_TD_HR] & 0x3F); /* rtc hr 0-23 */ + tm->tm_mday = bcd2bin(buf[PCF2127_OFFSET_TD_DM] & 0x3F); + tm->tm_wday = buf[PCF2127_OFFSET_TD_DW] & 0x07; + tm->tm_mon = bcd2bin(buf[PCF2127_OFFSET_TD_MO] & 0x1F) - 1; /* rtc mn 1-12 */ + tm->tm_year = bcd2bin(buf[PCF2127_OFFSET_TD_YR]); tm->tm_year += 100; dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " @@ -207,7 +215,7 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm) buf[i++] = bin2bcd(tm->tm_year - 100); /* write register's data */ - err = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_SC, buf, i); + err = regmap_bulk_write(pcf2127->regmap, pcf2127->cfg->regs_td_base, buf, i); if (err) { dev_err(dev, "%s: err=%d", __func__, err); @@ -650,11 +658,13 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .max_register = 0x1d, .has_nvmem = 1, .has_bit_wd_ctl_cd0 = 1, + .regs_td_base = PCF2127_REG_TIME_DATE_BASE, }, [PCF2129] = { .max_register = 0x19, .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, + .regs_td_base = PCF2127_REG_TIME_DATE_BASE, }, }; From patchwork Thu Dec 15 15:02:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33683 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421853wrn; Thu, 15 Dec 2022 07:20:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf6G6JK0Ux7yGVaAM4Of0K3rkliSSpN9lBoSbEM6yLMvMWJ9Uv6Gn7YiXlWEXk0hgPZ99zIi X-Received: by 2002:a17:903:130e:b0:189:8ca1:e641 with SMTP id iy14-20020a170903130e00b001898ca1e641mr27766246plb.60.1671117644702; Thu, 15 Dec 2022 07:20:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117644; cv=none; d=google.com; s=arc-20160816; b=Q2Py328b8EoJENzc9QfDEX0tl4Ofv7H0syP5NL0j6jM7Bf0fPbiZMhYMSdTfqQ8M6j 3DvXje66G3G9Se2eJbhuCXRgd+SBy0q9a3tuR9gPjMZ6TUX1VFnzggufSsDyJdoaiYQr 5qYW7iSwVjrelAdmn9JePJqcWbjnvasSX7hQHcEZwg/sCPLVunjikYCHykTd6Olf+3h7 aIxkGgj2eztYGDczxeqsBpGRxDzFw4SR/XcVw9/hQa4XlgmCk5BX8gKzh3UfIhb33ne+ hrXww6D7qWmGyyT5ZDZvTLXpKjDlS5OlYDyJ46l52j9BLUYO0gX6h+iGTbOYx9Bn264b 5XjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=N0+jsxE4w/5gUlTJRZDTHm6syH5Kc3FstshVphEK4g4=; b=oHGeMQLO78GUMAKlsnLhBXYrHDRC/fqkxFgerdkJryGfgor94aBqXdRndgNCoejEBC nlQZ2SueLZ2QBVb0SNnYmvx8V2VMVkOi3dvM+tT15rID2bsDOdNuX4EEZiTyQUCn8AYe 5Ugyx1h5mzp2EzLQp8PxbZj5osZIVEoQcDURhuCZw+Tro+3n0gjsu8gobuFqSFS588oL +vdy4icRRsSBwIXDAvwbZR4X3CPFMLvH1pnel1YpooA+sUCbHLz5Txigcxe2cVb3VHun i6g+/dbZK2KAKvNdWfyv1nggBlLoQ8IbKumR6BdGlb15VmFLzqtduGQZxdu2IGuJQFVm UtLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=gcV9BQdd; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s15-20020a63770f000000b00478701e57c8si2973986pgc.807.2022.12.15.07.20.30; Thu, 15 Dec 2022 07:20:44 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=gcV9BQdd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbiLOPTL (ORCPT + 99 others); Thu, 15 Dec 2022 10:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbiLOPSZ (ORCPT ); Thu, 15 Dec 2022 10:18:25 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EA1AD6A; Thu, 15 Dec 2022 07:18:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=N0+jsxE4w/5gUlTJRZDTHm6syH5Kc3FstshVphEK4g4=; b=gcV9BQddK9XnBQb3xf6TMUWr9j 22P3sI5uGC7WA90TJM5mDlIJCA9xG+t1DK8LZtn1GxoylD+dKPdltLclsdRvkGO+0s3eiHe+zp7Tm RatrK2CEq+IdDWQ9W/EpuADNVbZmp9BeXcIEVS7IYA0j3TWKNUsufAG9U0vjFHQ6GWuw=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmA-0000EC-VB; Thu, 15 Dec 2022 10:03:59 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:04 -0500 Message-Id: <20221215150214.1109074-4-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 03/14] rtc: pcf2127: adapt for alarm registers at any offset X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293855192946112?= X-GMAIL-MSGID: =?utf-8?q?1752293855192946112?= From: Hugo Villeneuve This will simplify the implementation of new variants into this driver. Signed-off-by: Hugo Villeneuve Reviewed-by: Bruno Thomsen --- drivers/rtc/rtc-pcf2127.c | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index fb0caacaabee..db0cb784c0c9 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -56,11 +56,14 @@ /* Time and date registers bits */ #define PCF2127_BIT_SC_OSF BIT(7) /* Alarm registers */ -#define PCF2127_REG_ALARM_SC 0x0A -#define PCF2127_REG_ALARM_MN 0x0B -#define PCF2127_REG_ALARM_HR 0x0C -#define PCF2127_REG_ALARM_DM 0x0D -#define PCF2127_REG_ALARM_DW 0x0E +#define PCF2127_REG_ALARM_BASE 0x0A +/* Alarm registers offsets (starting from base register) */ +#define PCF2127_OFFSET_ALARM_SC 0 +#define PCF2127_OFFSET_ALARM_MN 1 +#define PCF2127_OFFSET_ALARM_HR 2 +#define PCF2127_OFFSET_ALARM_DM 3 +#define PCF2127_OFFSET_ALARM_DW 4 +/* Alarm bits */ #define PCF2127_BIT_ALARM_AE BIT(7) /* CLKOUT control register */ #define PCF2127_REG_CLKOUT 0x0f @@ -110,6 +113,7 @@ struct pcf21xx_config { unsigned int has_nvmem:1; unsigned int has_bit_wd_ctl_cd0:1; u8 regs_td_base; /* Time/data base registers. */ + u8 regs_alarm_base; /* Alarm function base registers. */ }; struct pcf2127 { @@ -402,18 +406,18 @@ static int pcf2127_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) if (ret) return ret; - ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_ALARM_SC, buf, - sizeof(buf)); + ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->regs_alarm_base, + buf, sizeof(buf)); if (ret) return ret; alrm->enabled = ctrl2 & PCF2127_BIT_CTRL2_AIE; alrm->pending = ctrl2 & PCF2127_BIT_CTRL2_AF; - alrm->time.tm_sec = bcd2bin(buf[0] & 0x7F); - alrm->time.tm_min = bcd2bin(buf[1] & 0x7F); - alrm->time.tm_hour = bcd2bin(buf[2] & 0x3F); - alrm->time.tm_mday = bcd2bin(buf[3] & 0x3F); + alrm->time.tm_sec = bcd2bin(buf[PCF2127_OFFSET_ALARM_SC] & 0x7F); + alrm->time.tm_min = bcd2bin(buf[PCF2127_OFFSET_ALARM_MN] & 0x7F); + alrm->time.tm_hour = bcd2bin(buf[PCF2127_OFFSET_ALARM_HR] & 0x3F); + alrm->time.tm_mday = bcd2bin(buf[PCF2127_OFFSET_ALARM_DM] & 0x3F); return 0; } @@ -447,14 +451,14 @@ static int pcf2127_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) if (ret) return ret; - buf[0] = bin2bcd(alrm->time.tm_sec); - buf[1] = bin2bcd(alrm->time.tm_min); - buf[2] = bin2bcd(alrm->time.tm_hour); - buf[3] = bin2bcd(alrm->time.tm_mday); - buf[4] = PCF2127_BIT_ALARM_AE; /* Do not match on week day */ + buf[PCF2127_OFFSET_ALARM_SC] = bin2bcd(alrm->time.tm_sec); + buf[PCF2127_OFFSET_ALARM_MN] = bin2bcd(alrm->time.tm_min); + buf[PCF2127_OFFSET_ALARM_HR] = bin2bcd(alrm->time.tm_hour); + buf[PCF2127_OFFSET_ALARM_DM] = bin2bcd(alrm->time.tm_mday); + buf[PCF2127_OFFSET_ALARM_DW] = PCF2127_BIT_ALARM_AE; /* Do not match on week day */ - ret = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_ALARM_SC, buf, - sizeof(buf)); + ret = regmap_bulk_write(pcf2127->regmap, pcf2127->cfg->regs_alarm_base, + buf, sizeof(buf)); if (ret) return ret; @@ -659,12 +663,14 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .has_nvmem = 1, .has_bit_wd_ctl_cd0 = 1, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, + .regs_alarm_base = PCF2127_REG_ALARM_BASE, }, [PCF2129] = { .max_register = 0x19, .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, + .regs_alarm_base = PCF2127_REG_ALARM_BASE, }, }; From patchwork Thu Dec 15 15:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421702wrn; Thu, 15 Dec 2022 07:20:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf78haVdZ++fGAXA3LJKfJGdHszWFoyPCqjlciBbplojTneOVWjvad4Z/2lzXxcmQHQIMsAi X-Received: by 2002:a17:902:ca14:b0:189:bbd3:a5a7 with SMTP id w20-20020a170902ca1400b00189bbd3a5a7mr24030001pld.51.1671117629592; Thu, 15 Dec 2022 07:20:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117629; cv=none; d=google.com; s=arc-20160816; b=qvKtlPIcBCxzBYlrOniR6rTzeBH1i0QfbY0dWu+q1C8ieKvBtXAubzW+0LraiUnSrp +dotk8gFt+3oGX0gICytWGbeeLspVZ/0dumylb8Pp8lfXSg8E48NC4sOCxMuwsHfl/z1 ZHvsf3SM0daRW1DPS1CK8HE8TWZFN4qW9JCa8Z4LaY9O1iUwz6guFXVAUzNEONQ5jMzs f8j6+xe37TVTHvrSDDwY7dbekmjO4p0Y7t8A7KQ8Ok/9uXmR70yIqMp6GA57l8e1RRay 8mug+nAUyxhGQXd5TmIbD2I4fIUz2Tm/eflclGPhtqKb33wlCaT0Ija1Puwj+Ja2lnVA R4jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=8Q7ceOCImgW1+k459ANYj+kIkkp23Qja0+B2W043r04=; b=I7G5nQBjwGocFvO0D5jwktAmLU3Sw445S0IcFlzwgqN1/6jUVsIbTCpisUlqJ+r8St IpFbGMDAoYgZxDqMo+4XV3jplabgLkPffuxud8ayxpz1+hpCgtfhCX/EG9ezxx4pqoUY yx03f+J+gAo4IcbtwD7OJB+7EGjLk6ZLGlrT/aqAWPWT4V15NUBMBNLjN8a5Oj8EZt05 M45F2LNKJbbws+K9VN3kWry9H24Qxig9E3h09hLbkMv7vPasRp5Lgq2z4fULW1fXAiZH 4EmJmIEmFrxLCh4T+8Z/N5EqXD1GhF5BbhS6ZeqjFQ4naEYwD82AINlIoTwiUSdpDeJZ JnUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=ecaDfEzJ; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a170902cecf00b00189cf69e4cesi6222741plg.525.2022.12.15.07.20.16; Thu, 15 Dec 2022 07:20:29 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=ecaDfEzJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbiLOPSt (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbiLOPST (ORCPT ); Thu, 15 Dec 2022 10:18:19 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22154DD3; Thu, 15 Dec 2022 07:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8Q7ceOCImgW1+k459ANYj+kIkkp23Qja0+B2W043r04=; b=ecaDfEzJgkzaKfq9Kg+aEDBzUC 7mdnunTIzfUga4HHAt25A11reGD8Lq4t/lSD+Zy0PB13spxF6QlhBSJykLuw4y3BG86XLQHkIqkJO MMpAjoOq/zlfEV0QMW4oZ+NIs9/Y4CVXW7+xozMV/3HExeCsWwABy0AMB3lsGnnL6E80=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmC-0000EC-1I; Thu, 15 Dec 2022 10:04:00 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:05 -0500 Message-Id: <20221215150214.1109074-5-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 04/14] rtc: pcf2127: adapt for WD registers at any offset X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293839479807963?= X-GMAIL-MSGID: =?utf-8?q?1752293839479807963?= From: Hugo Villeneuve This will simplify the implementation of new variants into this driver. Signed-off-by: Hugo Villeneuve Reviewed-by: Bruno Thomsen Tested-by: Bruno Thomsen --- drivers/rtc/rtc-pcf2127.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index db0cb784c0c9..5d8c06e32dce 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -114,6 +114,8 @@ struct pcf21xx_config { unsigned int has_bit_wd_ctl_cd0:1; u8 regs_td_base; /* Time/data base registers. */ u8 regs_alarm_base; /* Alarm function base registers. */ + u8 reg_wd_ctl; /* Watchdog control register. */ + u8 reg_wd_val; /* Watchdog value register. */ }; struct pcf2127 { @@ -297,7 +299,7 @@ static int pcf2127_wdt_ping(struct watchdog_device *wdd) { struct pcf2127 *pcf2127 = watchdog_get_drvdata(wdd); - return regmap_write(pcf2127->regmap, PCF2127_REG_WD_VAL, wdd->timeout); + return regmap_write(pcf2127->regmap, pcf2127->cfg->reg_wd_val, wdd->timeout); } /* @@ -331,7 +333,7 @@ static int pcf2127_wdt_stop(struct watchdog_device *wdd) { struct pcf2127 *pcf2127 = watchdog_get_drvdata(wdd); - return regmap_write(pcf2127->regmap, PCF2127_REG_WD_VAL, + return regmap_write(pcf2127->regmap, pcf2127->cfg->reg_wd_val, PCF2127_WD_VAL_STOP); } @@ -380,7 +382,7 @@ static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127) watchdog_set_drvdata(&pcf2127->wdd, pcf2127); /* Test if watchdog timer is started by bootloader */ - ret = regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL, &wdd_timeout); + ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_wd_val, &wdd_timeout); if (ret) return ret; @@ -664,6 +666,8 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .has_bit_wd_ctl_cd0 = 1, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2127_REG_ALARM_BASE, + .reg_wd_ctl = PCF2127_REG_WD_CTL, + .reg_wd_val = PCF2127_REG_WD_VAL, }, [PCF2129] = { .max_register = 0x19, @@ -671,6 +675,8 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .has_bit_wd_ctl_cd0 = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2127_REG_ALARM_BASE, + .reg_wd_ctl = PCF2127_REG_WD_CTL, + .reg_wd_val = PCF2127_REG_WD_VAL, }, }; @@ -772,7 +778,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, * as T. Bits labeled as T must always be written with * logic 0. */ - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_WD_CTL, + ret = regmap_update_bits(pcf2127->regmap, pcf2127->cfg->reg_wd_ctl, PCF2127_BIT_WD_CTL_CD1 | PCF2127_BIT_WD_CTL_CD0 | PCF2127_BIT_WD_CTL_TF1 | From patchwork Thu Dec 15 15:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33675 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421127wrn; Thu, 15 Dec 2022 07:19:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TppuU2S7k3VrxWUTTXb9gYxNCStpZ/tHyag+TGdImPISpQDisebxSaLNH9D1+4c/enmyd X-Received: by 2002:a17:90a:8a18:b0:219:20b4:9a0e with SMTP id w24-20020a17090a8a1800b0021920b49a0emr28539221pjn.24.1671117579767; Thu, 15 Dec 2022 07:19:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117579; cv=none; d=google.com; s=arc-20160816; b=ot4N30Euz++CnLJoh3tlg6Q8OeO+Zgna4cXUe5FQJJdv0KGDdXpf26slgCTTFXbifa 8WiKRPOjW4TFVHJrb2pDYRl9ZhwYQLedbA7fRS3i31uUZhdnpA9BpNI1N1iY1x2BZ1Lx fiAGfN1UtANSvEswgUuuaUe/0yEYmWKu2wP/cfEKGNuBEI9xFFX6u09Nw1KjBpqOmUnq 8DGmCq+K4Buf4Ky5MQF/16wn+OOfRat0b5B3yV8ySpfArd3ywirMpl2PKzkC0Rz2bdda BXgAh5aYriJsZtaCXWtJlzE5JLsyBMybxKyA4NMGPzOTYhxrKYjKdWEsOw43NdTysz0Q KsHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=S8d6dn8OKytIYHpmifekb67q4TLdM6m9YnqemmeSLaQ=; b=pt8jsDGoO8QE3IhzgdkkdzIq9yGNe5hZmBXDsNnj2X1vKzP+7ONth+W2mPxrWaYfV6 tEvl68XcrgEaUEZnuXGR9tmKQSQtLS+n+WE+tMRUgyZg6ZBRSwxzJEe7aKKENyvPSUZB Va5Z8eASFq/TQYRzP1/gIftNZj+7uEQ5aq/j3jjglEwSoLPUqoLJsKKIu1Aq9tyQvb9I WgF9se4Wxm75DC2uEBcT6EPtV/wQggy46HLKAzg0VEM331srZN/OQ2TtxgBEhxIFR2el 2R5ohbY3g0TjO/c69Mutu0ofRdYvl3IuoKIPjgYpgd5bXm744p6HvtX0kW6d0RwTYekw HXeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=c2sQ5iNV; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oe11-20020a17090b394b00b0021984a8bdbesi5026536pjb.47.2022.12.15.07.19.23; Thu, 15 Dec 2022 07:19:39 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=c2sQ5iNV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbiLOPSL (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbiLOPSG (ORCPT ); Thu, 15 Dec 2022 10:18:06 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D58E0; Thu, 15 Dec 2022 07:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=S8d6dn8OKytIYHpmifekb67q4TLdM6m9YnqemmeSLaQ=; b=c2sQ5iNVADjuPd8lr3keKGO5j1 U9La64lwX/gD0ex83K9JpMYq6+FJfByQkhSoN+6pZLcCrHSUn0ElCMdY7dwU5rpWZ7agLHF1SaYVt nIlDCNnDWSfn3sYLKQc2+ObWLxhjrjRmBsa+qQYzun3CicfFUEW/azP0XEp1ZZpZddWE=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmC-0000EC-V6; Thu, 15 Dec 2022 10:04:01 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:06 -0500 Message-Id: <20221215150214.1109074-6-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 05/14] rtc: pcf2127: adapt for CLKOUT register at any offset X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293786942973657?= X-GMAIL-MSGID: =?utf-8?q?1752293786942973657?= From: Hugo Villeneuve This will simplify the implementation of new variants into this driver. Signed-off-by: Hugo Villeneuve Reviewed-by: Bruno Thomsen --- drivers/rtc/rtc-pcf2127.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 5d8c06e32dce..38816ad065eb 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -116,6 +116,7 @@ struct pcf21xx_config { u8 regs_alarm_base; /* Alarm function base registers. */ u8 reg_wd_ctl; /* Watchdog control register. */ u8 reg_wd_val; /* Watchdog value register. */ + u8 reg_clkout; /* Clkout register. */ }; struct pcf2127 { @@ -668,6 +669,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .regs_alarm_base = PCF2127_REG_ALARM_BASE, .reg_wd_ctl = PCF2127_REG_WD_CTL, .reg_wd_val = PCF2127_REG_WD_VAL, + .reg_clkout = PCF2127_REG_CLKOUT, }, [PCF2129] = { .max_register = 0x19, @@ -677,6 +679,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .regs_alarm_base = PCF2127_REG_ALARM_BASE, .reg_wd_ctl = PCF2127_REG_WD_CTL, .reg_wd_val = PCF2127_REG_WD_VAL, + .reg_clkout = PCF2127_REG_CLKOUT, }, }; @@ -756,12 +759,12 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1, PCF2127_BIT_CTRL1_POR_OVRD); - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CLKOUT, &val); + ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val); if (ret < 0) return ret; if (!(val & PCF2127_BIT_CLKOUT_OTPR)) { - ret = regmap_set_bits(pcf2127->regmap, PCF2127_REG_CLKOUT, + ret = regmap_set_bits(pcf2127->regmap, pcf2127->cfg->reg_clkout, PCF2127_BIT_CLKOUT_OTPR); if (ret < 0) return ret; From patchwork Thu Dec 15 15:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33689 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp438516wrn; Thu, 15 Dec 2022 07:50:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5EpK2sPKwrcA6cg0oBaATFgSEPvCrIpbWv6XXsOJ967Bozpzs689T0x5qAyaeh/pKdem8V X-Received: by 2002:a17:906:af0c:b0:7b8:882d:43ef with SMTP id lx12-20020a170906af0c00b007b8882d43efmr9864450ejb.0.1671119435185; Thu, 15 Dec 2022 07:50:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671119435; cv=none; d=google.com; s=arc-20160816; b=AD5PU8xHK1M5EzRdgfRROBbkaFIDohhWYk6OB4+hbeGPQ15KQS9fkUr9cPuWNGdq0r fg4cmCLXQR7g0yNqX3XxX+7tBEoT9ScQrhqhj/95jP/zHMBsQzjeS0oceHRk98ELDBDM K/GPZqp3ixxOo8i7+FNXW0S82blGQ01XOICWlkyUYv9bvxPLhc3pcC3caKsZT34tb4Xw tM1usS5rxUV6mgCFc8NMDCyh+qmYTyFvEtgf97qv7LSgn8e2krlItr2S1Wvg09FcKr2l FlSSYKM5RBJuW2XMyOxotki+fMfxhg5uUxeh21VZ6IE/XXe/nRM9MfYLC1NMTKkD6sRL WhEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=3/hHFIu9SnBKamnAdB3ZQ8g9PZ0HEAjP2IbxnYhiE10=; b=teYpthGdlR5j80Pf/bM8ie1uObsm/1gNBWqCTTkZU8i9zfMGT9eguxYEb9TnQsBaTe zTXg5qdJJevff6Hisa0MXYQzfj/h3ealKBdfvStsDRL3dqM6E1fsmOE7cax+bDO786VH Pk5EZhCNzWaVg/tECQD1twABZA775ZChXIab4/ROCwXaSuR5e7bq3oVBdIs90h0BRNGf W0KmsICaPTdcpeJMq1XX2ISHfym6Wj2N40IRDGYuvacdmpxNTAbd173QtS3XOUc+lpy8 AaziMS2JAoLCirrxFrraKmxHDq6K24NkAbHMzCbB1Imk7W+LAzK3AtpVdQRg8RQ0V3L4 ZAMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=lV7ulN+d; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh16-20020a1709076e9000b007af041e40b4si15568990ejc.129.2022.12.15.07.50.11; Thu, 15 Dec 2022 07:50:35 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=lV7ulN+d; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbiLOPUQ (ORCPT + 99 others); Thu, 15 Dec 2022 10:20:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbiLOPT3 (ORCPT ); Thu, 15 Dec 2022 10:19:29 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6D5F31EDE; Thu, 15 Dec 2022 07:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=3/hHFIu9SnBKamnAdB3ZQ8g9PZ0HEAjP2IbxnYhiE10=; b=lV7ulN+dKm/SBhTFCJMMX8L67j ESIkngHePN4zgGZhBpV1Qav5bkBo6WWLyua17OcHCazwP4AMfbYs/0fQOwUCmt7aVajuvEEf9fprJ OID55IP1uQIvT1ra8I8Q/OiplV20AuKmgtwyUDNE5zezVeS59BWY9JmV99JM8nlqM5RM=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmE-0000EC-1p; Thu, 15 Dec 2022 10:04:04 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:07 -0500 Message-Id: <20221215150214.1109074-7-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 06/14] rtc: pcf2127: add support for multiple TS functions X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752295732910778644?= X-GMAIL-MSGID: =?utf-8?q?1752295732910778644?= From: Hugo Villeneuve This will simplify the implementation of new variants into this driver. Signed-off-by: Hugo Villeneuve --- drivers/rtc/rtc-pcf2127.c | 303 +++++++++++++++++++++++++++----------- 1 file changed, 215 insertions(+), 88 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 38816ad065eb..3265878edc48 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -75,16 +75,19 @@ #define PCF2127_BIT_WD_CTL_CD0 BIT(6) #define PCF2127_BIT_WD_CTL_CD1 BIT(7) #define PCF2127_REG_WD_VAL 0x11 -/* Tamper timestamp registers */ -#define PCF2127_REG_TS_CTRL 0x12 +/* Tamper timestamp1 registers */ +#define PCF2127_REG_TS1_BASE 0x12 +/* Tamper timestamp registers common offsets (starting from base register) */ +#define PCF2127_OFFSET_TS_CTL 0 +#define PCF2127_OFFSET_TS_SC 1 +#define PCF2127_OFFSET_TS_MN 2 +#define PCF2127_OFFSET_TS_HR 3 +#define PCF2127_OFFSET_TS_DM 4 +#define PCF2127_OFFSET_TS_MO 5 +#define PCF2127_OFFSET_TS_YR 6 +/* Tamper timestamp registers common bits */ #define PCF2127_BIT_TS_CTRL_TSOFF BIT(6) #define PCF2127_BIT_TS_CTRL_TSM BIT(7) -#define PCF2127_REG_TS_SC 0x13 -#define PCF2127_REG_TS_MN 0x14 -#define PCF2127_REG_TS_HR 0x15 -#define PCF2127_REG_TS_DM 0x16 -#define PCF2127_REG_TS_MO 0x17 -#define PCF2127_REG_TS_YR 0x18 /* * RAM registers * PCF2127 has 512 bytes general-purpose static RAM (SRAM) that is @@ -108,6 +111,20 @@ PCF2127_BIT_CTRL2_WDTF | \ PCF2127_BIT_CTRL2_TSF2) +struct pcf21xx_ts_config { + u8 regs_base; /* Base register to read timestamp values. */ + /* TS input pin driven to GND detection (supported by all variants): */ + u8 low_reg; /* Interrupt control register. */ + u8 low_bit; /* Interrupt flag in low_reg control register. */ + /* TS input pin driven to intermediate level between GND and supply + * detection (optional feature depending on variant): + */ + u8 inter_reg; /* Interrupt control register. */ + u8 inter_bit; /* Interrupt flag in inter_reg control register. */ + u8 ie_reg; /* Interrupt enable control register. */ + u8 ie_bit; /* Interrupt enable bit. */ +}; + struct pcf21xx_config { int max_register; unsigned int has_nvmem:1; @@ -117,6 +134,9 @@ struct pcf21xx_config { u8 reg_wd_ctl; /* Watchdog control register. */ u8 reg_wd_val; /* Watchdog value register. */ u8 reg_clkout; /* Clkout register. */ + unsigned int ts_count; + struct pcf21xx_ts_config ts[4]; + struct attribute_group attribute_group; }; struct pcf2127 { @@ -124,9 +144,9 @@ struct pcf2127 { struct watchdog_device wdd; struct regmap *regmap; const struct pcf21xx_config *cfg; - time64_t ts; - bool ts_valid; bool irq_enabled; + time64_t ts[4]; /* Timestamp values. */ + bool ts_valid[4]; /* Timestamp valid indication. */ }; /* @@ -469,38 +489,39 @@ static int pcf2127_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) } /* - * This function reads ctrl2 register, caller is responsible for calling - * pcf2127_wdt_active_ping() + * This function reads one timestamp function data, caller is responsible for + * calling pcf2127_wdt_active_ping() */ -static int pcf2127_rtc_ts_read(struct device *dev, time64_t *ts) +static int pcf2127_rtc_ts_read(struct device *dev, time64_t *ts, + int ts_id) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev); struct rtc_time tm; int ret; - unsigned char data[25]; + unsigned char data[7]; /* To store result of reading 7 consecutive + * timestamp registers. + */ - ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL1, data, - sizeof(data)); + ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->ts[ts_id].regs_base, + data, sizeof(data)); if (ret) { - dev_err(dev, "%s: read error ret=%d\n", __func__, ret); + dev_err(dev, "%s: bulk read error ret=%d\n", __func__, ret); return ret; } dev_dbg(dev, - "%s: raw data is cr1=%02x, cr2=%02x, cr3=%02x, ts_sc=%02x, ts_mn=%02x, ts_hr=%02x, ts_dm=%02x, ts_mo=%02x, ts_yr=%02x\n", - __func__, data[PCF2127_REG_CTRL1], data[PCF2127_REG_CTRL2], - data[PCF2127_REG_CTRL3], data[PCF2127_REG_TS_SC], - data[PCF2127_REG_TS_MN], data[PCF2127_REG_TS_HR], - data[PCF2127_REG_TS_DM], data[PCF2127_REG_TS_MO], - data[PCF2127_REG_TS_YR]); - - tm.tm_sec = bcd2bin(data[PCF2127_REG_TS_SC] & 0x7F); - tm.tm_min = bcd2bin(data[PCF2127_REG_TS_MN] & 0x7F); - tm.tm_hour = bcd2bin(data[PCF2127_REG_TS_HR] & 0x3F); - tm.tm_mday = bcd2bin(data[PCF2127_REG_TS_DM] & 0x3F); + "%s: raw data is ts_sc=%02x, ts_mn=%02x, ts_hr=%02x, ts_dm=%02x, ts_mo=%02x, ts_yr=%02x\n", + __func__, data[PCF2127_OFFSET_TS_SC], data[PCF2127_OFFSET_TS_MN], + data[PCF2127_OFFSET_TS_HR], data[PCF2127_OFFSET_TS_DM], + data[PCF2127_OFFSET_TS_MO], data[PCF2127_OFFSET_TS_YR]); + + tm.tm_sec = bcd2bin(data[PCF2127_OFFSET_TS_SC] & 0x7F); + tm.tm_min = bcd2bin(data[PCF2127_OFFSET_TS_MN] & 0x7F); + tm.tm_hour = bcd2bin(data[PCF2127_OFFSET_TS_HR] & 0x3F); + tm.tm_mday = bcd2bin(data[PCF2127_OFFSET_TS_DM] & 0x3F); /* TS_MO register (month) value range: 1-12 */ - tm.tm_mon = bcd2bin(data[PCF2127_REG_TS_MO] & 0x1F) - 1; - tm.tm_year = bcd2bin(data[PCF2127_REG_TS_YR]); + tm.tm_mon = bcd2bin(data[PCF2127_OFFSET_TS_MO] & 0x1F) - 1; + tm.tm_year = bcd2bin(data[PCF2127_OFFSET_TS_YR]); if (tm.tm_year < 70) tm.tm_year += 100; /* assume we are in 1970...2069 */ @@ -514,18 +535,21 @@ static int pcf2127_rtc_ts_read(struct device *dev, time64_t *ts) return 0; }; -static void pcf2127_rtc_ts_snapshot(struct device *dev) +static void pcf2127_rtc_ts_snapshot(struct device *dev, int ts_id) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev); int ret; + if (ts_id >= pcf2127->cfg->ts_count) + return; + /* Let userspace read the first timestamp */ - if (pcf2127->ts_valid) + if (pcf2127->ts_valid[ts_id]) return; - ret = pcf2127_rtc_ts_read(dev, &pcf2127->ts); + ret = pcf2127_rtc_ts_read(dev, &pcf2127->ts[ts_id], ts_id); if (!ret) - pcf2127->ts_valid = true; + pcf2127->ts_valid[ts_id] = true; } static irqreturn_t pcf2127_rtc_irq(int irq, void *dev) @@ -546,7 +570,7 @@ static irqreturn_t pcf2127_rtc_irq(int irq, void *dev) return IRQ_NONE; if (ctrl1 & PCF2127_BIT_CTRL1_TSF1 || ctrl2 & PCF2127_BIT_CTRL2_TSF2) - pcf2127_rtc_ts_snapshot(dev); + pcf2127_rtc_ts_snapshot(dev, 0); if (ctrl1 & PCF2127_CTRL1_IRQ_MASK) regmap_write(pcf2127->regmap, PCF2127_REG_CTRL1, @@ -575,28 +599,40 @@ static const struct rtc_class_ops pcf2127_rtc_ops = { /* sysfs interface */ -static ssize_t timestamp0_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t timestamp_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count, int ts_id) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); int ret; + if (ts_id >= pcf2127->cfg->ts_count) + return 0; + if (pcf2127->irq_enabled) { - pcf2127->ts_valid = false; + pcf2127->ts_valid[ts_id] = false; } else { - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, - PCF2127_BIT_CTRL1_TSF1, 0); + /* Always clear LOW interrupt bit. */ + ret = regmap_update_bits(pcf2127->regmap, + pcf2127->cfg->ts[ts_id].low_reg, + pcf2127->cfg->ts[ts_id].low_bit, + 0); + if (ret) { - dev_err(dev, "%s: update ctrl1 ret=%d\n", __func__, ret); + dev_err(dev, "%s: update TS low ret=%d\n", __func__, ret); return ret; } - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL2, - PCF2127_BIT_CTRL2_TSF2, 0); - if (ret) { - dev_err(dev, "%s: update ctrl2 ret=%d\n", __func__, ret); - return ret; + if (pcf2127->cfg->ts[ts_id].inter_bit) { + /* Clear INTERMEDIATE interrupt bit if supported. */ + ret = regmap_update_bits(pcf2127->regmap, + pcf2127->cfg->ts[ts_id].inter_reg, + pcf2127->cfg->ts[ts_id].inter_bit, + 0); + if (ret) { + dev_err(dev, "%s: update TS intermediate ret=%d\n", __func__, ret); + return ret; + } } ret = pcf2127_wdt_active_ping(&pcf2127->wdd); @@ -605,34 +641,63 @@ static ssize_t timestamp0_store(struct device *dev, } return count; +} + +static ssize_t timestamp0_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + return timestamp_store(dev, attr, buf, count, 0); }; -static ssize_t timestamp0_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t timestamp_show(struct device *dev, + struct device_attribute *attr, char *buf, + int ts_id) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); - unsigned int ctrl1, ctrl2; int ret; time64_t ts; + if (ts_id >= pcf2127->cfg->ts_count) + return 0; + if (pcf2127->irq_enabled) { - if (!pcf2127->ts_valid) + if (!pcf2127->ts_valid[ts_id]) return 0; - ts = pcf2127->ts; + ts = pcf2127->ts[ts_id]; } else { - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); - if (ret) - return 0; + u8 valid_low = 0; + u8 valid_inter = 0; + unsigned int ctrl; - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2); + /* Check if TS input pin is driven to GND, supported by all + * variants. + */ + ret = regmap_read(pcf2127->regmap, + pcf2127->cfg->ts[ts_id].low_reg, + &ctrl); if (ret) return 0; - if (!(ctrl1 & PCF2127_BIT_CTRL1_TSF1) && - !(ctrl2 & PCF2127_BIT_CTRL2_TSF2)) + valid_low = ctrl & pcf2127->cfg->ts[ts_id].low_bit; + + if (pcf2127->cfg->ts[ts_id].inter_bit) { + /* Check if TS input pin is driven to intermediate level + * between GND and supply, if supported by variant. + */ + ret = regmap_read(pcf2127->regmap, + pcf2127->cfg->ts[ts_id].inter_reg, + &ctrl); + if (ret) + return 0; + + valid_inter = ctrl & pcf2127->cfg->ts[ts_id].inter_bit; + } + + if (!valid_low && !valid_inter) return 0; - ret = pcf2127_rtc_ts_read(dev->parent, &ts); + ret = pcf2127_rtc_ts_read(dev->parent, &ts, ts_id); if (ret) return 0; @@ -641,6 +706,12 @@ static ssize_t timestamp0_show(struct device *dev, return ret; } return sprintf(buf, "%llu\n", (unsigned long long)ts); +} + +static ssize_t timestamp0_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return timestamp_show(dev, attr, buf, 0); }; static DEVICE_ATTR_RW(timestamp0); @@ -650,10 +721,6 @@ static struct attribute *pcf2127_attrs[] = { NULL }; -static const struct attribute_group pcf2127_attr_group = { - .attrs = pcf2127_attrs, -}; - enum pcf21xx_type { PCF2127, PCF2129, @@ -670,6 +737,19 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .reg_wd_ctl = PCF2127_REG_WD_CTL, .reg_wd_val = PCF2127_REG_WD_VAL, .reg_clkout = PCF2127_REG_CLKOUT, + .ts_count = 1, + .ts[0] = { + .regs_base = PCF2127_REG_TS1_BASE, + .low_reg = PCF2127_REG_CTRL1, + .low_bit = PCF2127_BIT_CTRL1_TSF1, + .inter_reg = PCF2127_REG_CTRL2, + .inter_bit = PCF2127_BIT_CTRL2_TSF2, + .ie_reg = PCF2127_REG_CTRL2, + .ie_bit = PCF2127_BIT_CTRL2_TSIE, + }, + .attribute_group = { + .attrs = pcf2127_attrs, + }, }, [PCF2129] = { .max_register = 0x19, @@ -680,15 +760,81 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .reg_wd_ctl = PCF2127_REG_WD_CTL, .reg_wd_val = PCF2127_REG_WD_VAL, .reg_clkout = PCF2127_REG_CLKOUT, + .ts_count = 1, + .ts[0] = { + .regs_base = PCF2127_REG_TS1_BASE, + .low_reg = PCF2127_REG_CTRL1, + .low_bit = PCF2127_BIT_CTRL1_TSF1, + .inter_reg = PCF2127_REG_CTRL2, + .inter_bit = PCF2127_BIT_CTRL2_TSF2, + .ie_reg = PCF2127_REG_CTRL2, + .ie_bit = PCF2127_BIT_CTRL2_TSIE, + }, + .attribute_group = { + .attrs = pcf2127_attrs, + }, }, }; +/* + * Enable timestamp function and corresponding interrupt(s). + */ +static int pcf2127_enable_ts(struct device *dev, int ts_id) +{ + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); + int ret; + + if (ts_id >= pcf2127->cfg->ts_count) { + dev_err(dev, "%s: invalid tamper detection ID (%d)\n", + __func__, ts_id); + return -EINVAL; + } + + /* Enable timestamp function. */ + ret = regmap_update_bits(pcf2127->regmap, + pcf2127->cfg->ts[ts_id].regs_base, + PCF2127_BIT_TS_CTRL_TSOFF | + PCF2127_BIT_TS_CTRL_TSM, + PCF2127_BIT_TS_CTRL_TSM); + if (ret) { + dev_err(dev, "%s: tamper detection config (ts%d_ctrl) failed\n", + __func__, ts_id); + return ret; + } + + /* TS input pin driven to GND detection is supported by all variants. + * Make sure that low_bit is defined. + */ + if (pcf2127->cfg->ts[ts_id].low_bit == 0) { + dev_err(dev, "%s: tamper detection LOW configuration invalid\n", + __func__); + return ret; + } + + /* + * Enable interrupt generation when TSF timestamp flag is set. + * Interrupt signals are open-drain outputs and can be left floating if + * unused. + */ + ret = regmap_update_bits(pcf2127->regmap, pcf2127->cfg->ts[ts_id].ie_reg, + pcf2127->cfg->ts[ts_id].ie_bit, + pcf2127->cfg->ts[ts_id].ie_bit); + if (ret) { + dev_err(dev, "%s: tamper detection TSIE%d config failed\n", + __func__, ts_id); + return ret; + } + + return ret; +} + static int pcf2127_probe(struct device *dev, struct regmap *regmap, int alarm_irq, const char *name, const struct pcf21xx_config *config) { struct pcf2127 *pcf2127; int ret = 0; unsigned int val; + int i; dev_dbg(dev, "%s\n", __func__); @@ -813,34 +959,15 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, } /* - * Enable timestamp function and store timestamp of first trigger - * event until TSF1 and TSF2 interrupt flags are cleared. + * Enable timestamp functions 1 to 4. */ - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_TS_CTRL, - PCF2127_BIT_TS_CTRL_TSOFF | - PCF2127_BIT_TS_CTRL_TSM, - PCF2127_BIT_TS_CTRL_TSM); - if (ret) { - dev_err(dev, "%s: tamper detection config (ts_ctrl) failed\n", - __func__); - return ret; - } - - /* - * Enable interrupt generation when TSF1 or TSF2 timestamp flags - * are set. Interrupt signal is an open-drain output and can be - * left floating if unused. - */ - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL2, - PCF2127_BIT_CTRL2_TSIE, - PCF2127_BIT_CTRL2_TSIE); - if (ret) { - dev_err(dev, "%s: tamper detection config (ctrl2) failed\n", - __func__); - return ret; + for (i = 0; i < pcf2127->cfg->ts_count; i++) { + ret = pcf2127_enable_ts(dev, i); + if (ret) + return ret; } - ret = rtc_add_group(pcf2127->rtc, &pcf2127_attr_group); + ret = rtc_add_group(pcf2127->rtc, &pcf2127->cfg->attribute_group); if (ret) { dev_err(dev, "%s: tamper sysfs registering failed\n", __func__); From patchwork Thu Dec 15 15:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421896wrn; Thu, 15 Dec 2022 07:20:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf492cNxNxjtyBt4KF83Qyo28F+XCOHcAJC7PIXzc3QyS0DDvq9xmADU3ZSLfbE2sx7CBhq+ X-Received: by 2002:a17:902:b907:b0:186:c958:663 with SMTP id bf7-20020a170902b90700b00186c9580663mr32083279plb.31.1671117648315; Thu, 15 Dec 2022 07:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117648; cv=none; d=google.com; s=arc-20160816; b=0jhNQU6V6GjA/2dfirWPgrqOJRW0SGea9bhzbWMQYnzluWs9bdod9xcbQhLp9SDYTT /OzW/eME/wHUrqplDp0stcKU3A3HTzN/JJLOtOLGPPB3RHlyEzTrwc6dyvabfQCZ0g84 ccBDF/qWmpoGPmCbeUrjJpBcrFF8Ok8nnOCiTo3ZnZyNjiw7+s+2f8NyqhzbgXkL4dMN 2hPeQLJJ1wDkYypJwVM2vGMq7L3lXtJkTgDHWcyxIkpAkNjmFNeuKHvnzGxBO7lZ4ViH WfGS+ZWX55TNdb43woQTQxeA2UCxil1/mw92b4n4BnB11uprVnScfAuEY2Fx7vYyhTBv Jtkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=6czPPNkduKKltpClkSQ8PeW3l4k73V2Ne2Gq2XzHjSY=; b=QIJ9QqOKZssB9xti3hhNPPG6KTPLvXkL+dlxBY1haRHwmZKrQmfc1xB5+Qvf3lVhLA ZoRXLIA2phgzi39x2g96iBUqh5Dqw4p+8rStEQ6zRC5O08EOEl6s02tgEhhLLuSGtHIM OQdfMcUkig/BJoAHhve/ar35MfCtLNg/QzsC9u0HUOcZOA9oGoO/LouM9r/1fp4CZpGm unq1VzSGENczvEXzs4sFB7G61FjLuUZLahQHoY9iCwiaPnuzCLfDGiyoC2fsadEkcgY6 +RteRayy+BFGQRO+bDeDGnV82ZGWNfpcl8ErfLWKYPLhRMcSI5v2TWMzCooW7kSNDj7Y MrYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=Lpkuztn5; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw2-20020a170903044200b001869de3edcasi5666663plb.466.2022.12.15.07.20.34; Thu, 15 Dec 2022 07:20:48 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=Lpkuztn5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbiLOPT3 (ORCPT + 99 others); Thu, 15 Dec 2022 10:19:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230076AbiLOPTB (ORCPT ); Thu, 15 Dec 2022 10:19:01 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 602637646; Thu, 15 Dec 2022 07:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6czPPNkduKKltpClkSQ8PeW3l4k73V2Ne2Gq2XzHjSY=; b=Lpkuztn566PrPDFa+ZQ0xljdeS ClTLcWgtpfACPQOsvwuip0RZ5ald4psFaWznHnPmpyvDKmP0qQME5AUh63YBv8pEOQ5Jdrbl7m4kb GI67p8Dbcjhuu74mIeKb8rQTPy3HeN0Pw33VNdPekhmuVL59gpdkuvsHt7yQsQ0GEkZU=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmG-0000EC-Uq; Thu, 15 Dec 2022 10:04:06 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:08 -0500 Message-Id: <20221215150214.1109074-8-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 07/14] rtc: pcf2127: add support for PCF2131 RTC X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293859079677260?= X-GMAIL-MSGID: =?utf-8?q?1752293859079677260?= From: Hugo Villeneuve This RTC is very similar in functionality to the PCF2127/29. Basically it: -supports two new control registers at offsets 4 and 5 -supports a new reset register (not implemented in this driver) -supports 4 tamper detection functions instead of 1 -has no nvmem (like the PCF2129) -has two output interrupt pins Because of that, most of the register addresses are very different, although they still follow the same layout. For example, the tamper registers have a different base address, but the offsets are all the same. Signed-off-by: Hugo Villeneuve --- drivers/rtc/Kconfig | 4 +- drivers/rtc/rtc-pcf2127.c | 234 ++++++++++++++++++++++++++++++++++---- 2 files changed, 215 insertions(+), 23 deletions(-) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 2bb640d1521d..3d4043ce0057 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -910,9 +910,9 @@ config RTC_DRV_PCF2127 select REGMAP_SPI if SPI_MASTER select WATCHDOG_CORE if WATCHDOG help - If you say yes here you get support for the NXP PCF2127/29 RTC + If you say yes here you get support for the NXP PCF2127/29/31 RTC chips with integrated quartz crystal for industrial applications. - Both chips also have watchdog timer and tamper switch detection + These chips also have watchdog timer and tamper switch detection features. PCF2127 has an additional feature of 512 bytes battery backed diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 3265878edc48..4148e135f935 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -1,16 +1,26 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * An I2C and SPI driver for the NXP PCF2127/29 RTC + * An I2C and SPI driver for the NXP PCF2127/29/31 RTC * Copyright 2013 Til-Technologies + * Copyright 2021 DimOnOff * * Author: Renaud Cerrato * * Watchdog and tamper functions * Author: Bruno Thomsen * + * PCF2131 support + * Author: Hugo Villeneuve + * * based on the other drivers in this same directory. * - * Datasheet: https://www.nxp.com/docs/en/data-sheet/PCF2127.pdf + * Datasheets: https://www.nxp.com/docs/en/data-sheet/PCF2127.pdf + * https://www.nxp.com/docs/en/data-sheet/PCF2131DS.pdf + */ + +/* + * The following features are not yet implemented for the PCF2131: + * - support for 1/100th seconds */ #include @@ -43,8 +53,30 @@ #define PCF2127_BIT_CTRL3_BLF BIT(2) #define PCF2127_BIT_CTRL3_BF BIT(3) #define PCF2127_BIT_CTRL3_BTSE BIT(4) +/* Control register 4 */ +#define PCF2131_REG_CTRL4 0x03 +#define PCF2131_BIT_CTRL4_TSF4 BIT(4) +#define PCF2131_BIT_CTRL4_TSF3 BIT(5) +#define PCF2131_BIT_CTRL4_TSF2 BIT(6) +#define PCF2131_BIT_CTRL4_TSF1 BIT(7) +/* Control register 5 */ +#define PCF2131_REG_CTRL5 0x04 +#define PCF2131_BIT_CTRL5_TSIE4 BIT(4) +#define PCF2131_BIT_CTRL5_TSIE3 BIT(5) +#define PCF2131_BIT_CTRL5_TSIE2 BIT(6) +#define PCF2131_BIT_CTRL5_TSIE1 BIT(7) +/* Software reset register */ +#define PCF2131_REG_SR_RESET 0x05 +#define PCF2131_SR_RESET_READ_PATTERN 0b00100100 /* Fixed pattern. */ +#define PCF2131_SR_RESET_RESET_CMD 0x2C /* SR is bit 3. */ /* Time and date registers */ #define PCF2127_REG_TIME_DATE_BASE 0x03 +#define PCF2131_REG_TIME_DATE_BASE 0x07 /* Register 0x06 is 100th seconds, + * but we do not support it. By + * using offset 0x07, we can be + * compatible with existing + * time/date functions. + */ /* Time and date registers offsets (starting from base register) */ #define PCF2127_OFFSET_TD_SC 0 #define PCF2127_OFFSET_TD_MN 1 @@ -57,6 +89,7 @@ #define PCF2127_BIT_SC_OSF BIT(7) /* Alarm registers */ #define PCF2127_REG_ALARM_BASE 0x0A +#define PCF2131_REG_ALARM_BASE 0x0E /* Alarm registers offsets (starting from base register) */ #define PCF2127_OFFSET_ALARM_SC 0 #define PCF2127_OFFSET_ALARM_MN 1 @@ -67,16 +100,26 @@ #define PCF2127_BIT_ALARM_AE BIT(7) /* CLKOUT control register */ #define PCF2127_REG_CLKOUT 0x0f +#define PCF2131_REG_CLKOUT 0x13 #define PCF2127_BIT_CLKOUT_OTPR BIT(5) /* Watchdog registers */ #define PCF2127_REG_WD_CTL 0x10 +#define PCF2131_REG_WD_CTL 0x35 #define PCF2127_BIT_WD_CTL_TF0 BIT(0) #define PCF2127_BIT_WD_CTL_TF1 BIT(1) #define PCF2127_BIT_WD_CTL_CD0 BIT(6) #define PCF2127_BIT_WD_CTL_CD1 BIT(7) #define PCF2127_REG_WD_VAL 0x11 +#define PCF2131_REG_WD_VAL 0x36 /* Tamper timestamp1 registers */ #define PCF2127_REG_TS1_BASE 0x12 +#define PCF2131_REG_TS1_BASE 0x14 +/* Tamper timestamp2 registers */ +#define PCF2131_REG_TS2_BASE 0x1B +/* Tamper timestamp3 registers */ +#define PCF2131_REG_TS3_BASE 0x22 +/* Tamper timestamp4 registers */ +#define PCF2131_REG_TS4_BASE 0x29 /* Tamper timestamp registers common offsets (starting from base register) */ #define PCF2127_OFFSET_TS_CTL 0 #define PCF2127_OFFSET_TS_SC 1 @@ -92,11 +135,22 @@ * RAM registers * PCF2127 has 512 bytes general-purpose static RAM (SRAM) that is * battery backed and can survive a power outage. - * PCF2129 doesn't have this feature. + * PCF2129/31 doesn't have this feature. */ #define PCF2127_REG_RAM_ADDR_MSB 0x1A #define PCF2127_REG_RAM_WRT_CMD 0x1C #define PCF2127_REG_RAM_RD_CMD 0x1D +/* Interrupt mask registers */ +#define PCF2131_REG_INT_A_MASK1 0x31 +#define PCF2131_REG_INT_A_MASK2 0x32 +#define PCF2131_REG_INT_B_MASK1 0x33 +#define PCF2131_REG_INT_B_MASK2 0x34 +#define PCF2131_BIT_INT_BLIE BIT(0) +#define PCF2131_BIT_INT_BIE BIT(1) +#define PCF2131_BIT_INT_AIE BIT(2) +#define PCF2131_BIT_INT_WD_CD BIT(3) +#define PCF2131_BIT_INT_SI BIT(4) +#define PCF2131_BIT_INT_MI BIT(5) /* Watchdog timer value constants */ #define PCF2127_WD_VAL_STOP 0 @@ -110,6 +164,14 @@ PCF2127_BIT_CTRL2_AF | \ PCF2127_BIT_CTRL2_WDTF | \ PCF2127_BIT_CTRL2_TSF2) +#define PCF2131_CTRL2_IRQ_MASK ( \ + PCF2127_BIT_CTRL2_AF | \ + PCF2127_BIT_CTRL2_WDTF) +#define PCF2131_CTRL4_IRQ_MASK ( \ + PCF2131_BIT_CTRL4_TSF4 | \ + PCF2131_BIT_CTRL4_TSF3 | \ + PCF2131_BIT_CTRL4_TSF2 | \ + PCF2131_BIT_CTRL4_TSF1) struct pcf21xx_ts_config { u8 regs_base; /* Base register to read timestamp values. */ @@ -370,7 +432,7 @@ static int pcf2127_wdt_set_timeout(struct watchdog_device *wdd, } static const struct watchdog_info pcf2127_wdt_info = { - .identity = "NXP PCF2127/PCF2129 Watchdog", + .identity = "NXP PCF2127/29/31 Watchdog", .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT, }; @@ -555,30 +617,64 @@ static void pcf2127_rtc_ts_snapshot(struct device *dev, int ts_id) static irqreturn_t pcf2127_rtc_irq(int irq, void *dev) { struct pcf2127 *pcf2127 = dev_get_drvdata(dev); - unsigned int ctrl1, ctrl2; + unsigned int ctrl2; int ret = 0; - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); - if (ret) - return IRQ_NONE; - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2); if (ret) return IRQ_NONE; - if (!(ctrl1 & PCF2127_CTRL1_IRQ_MASK || ctrl2 & PCF2127_CTRL2_IRQ_MASK)) - return IRQ_NONE; + if (pcf2127->cfg->ts_count == 1) { + /* PCF2127/29 */ + unsigned int ctrl1; + + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); + if (ret) + return IRQ_NONE; + + if (!(ctrl1 & PCF2127_CTRL1_IRQ_MASK || ctrl2 & PCF2127_CTRL2_IRQ_MASK)) + return IRQ_NONE; - if (ctrl1 & PCF2127_BIT_CTRL1_TSF1 || ctrl2 & PCF2127_BIT_CTRL2_TSF2) - pcf2127_rtc_ts_snapshot(dev, 0); + if (ctrl1 & PCF2127_BIT_CTRL1_TSF1 || ctrl2 & PCF2127_BIT_CTRL2_TSF2) + pcf2127_rtc_ts_snapshot(dev, 0); - if (ctrl1 & PCF2127_CTRL1_IRQ_MASK) - regmap_write(pcf2127->regmap, PCF2127_REG_CTRL1, - ctrl1 & ~PCF2127_CTRL1_IRQ_MASK); + if (ctrl1 & PCF2127_CTRL1_IRQ_MASK) + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL1, + ctrl1 & ~PCF2127_CTRL1_IRQ_MASK); + + if (ctrl2 & PCF2127_CTRL2_IRQ_MASK) + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, + ctrl2 & ~PCF2127_CTRL2_IRQ_MASK); + } else { + /* PCF2131. */ + unsigned int ctrl4; + + ret = regmap_read(pcf2127->regmap, PCF2131_REG_CTRL4, &ctrl4); + if (ret) + return IRQ_NONE; - if (ctrl2 & PCF2127_CTRL2_IRQ_MASK) - regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, - ctrl2 & ~PCF2127_CTRL2_IRQ_MASK); + if (!(ctrl4 & PCF2131_CTRL4_IRQ_MASK || ctrl2 & PCF2131_CTRL2_IRQ_MASK)) + return IRQ_NONE; + + if (ctrl4 & PCF2131_CTRL4_IRQ_MASK) { + int i; + int tsf_bit = PCF2131_BIT_CTRL4_TSF1; /* Start at bit 7. */ + + for (i = 0; i < pcf2127->cfg->ts_count; i++) { + if (ctrl4 & tsf_bit) + pcf2127_rtc_ts_snapshot(dev, i); + + tsf_bit = tsf_bit >> 1; + } + + regmap_write(pcf2127->regmap, PCF2131_REG_CTRL4, + ctrl4 & ~PCF2131_CTRL4_IRQ_MASK); + } + + if (ctrl2 & PCF2131_CTRL2_IRQ_MASK) + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, + ctrl2 & ~PCF2131_CTRL2_IRQ_MASK); + } if (ctrl2 & PCF2127_BIT_CTRL2_AF) rtc_update_irq(pcf2127->rtc, 1, RTC_IRQF | RTC_AF); @@ -650,6 +746,27 @@ static ssize_t timestamp0_store(struct device *dev, return timestamp_store(dev, attr, buf, count, 0); }; +static ssize_t timestamp1_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + return timestamp_store(dev, attr, buf, count, 1); +}; + +static ssize_t timestamp2_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + return timestamp_store(dev, attr, buf, count, 2); +}; + +static ssize_t timestamp3_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + return timestamp_store(dev, attr, buf, count, 3); +}; + static ssize_t timestamp_show(struct device *dev, struct device_attribute *attr, char *buf, int ts_id) @@ -714,16 +831,46 @@ static ssize_t timestamp0_show(struct device *dev, return timestamp_show(dev, attr, buf, 0); }; +static ssize_t timestamp1_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return timestamp_show(dev, attr, buf, 1); +}; + +static ssize_t timestamp2_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return timestamp_show(dev, attr, buf, 2); +}; + +static ssize_t timestamp3_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return timestamp_show(dev, attr, buf, 3); +}; + static DEVICE_ATTR_RW(timestamp0); +static DEVICE_ATTR_RW(timestamp1); +static DEVICE_ATTR_RW(timestamp2); +static DEVICE_ATTR_RW(timestamp3); static struct attribute *pcf2127_attrs[] = { &dev_attr_timestamp0.attr, NULL }; +static struct attribute *pcf2131_attrs[] = { + &dev_attr_timestamp0.attr, + &dev_attr_timestamp1.attr, + &dev_attr_timestamp2.attr, + &dev_attr_timestamp3.attr, + NULL +}; + enum pcf21xx_type { PCF2127, PCF2129, + PCF2131, PCF21XX_LAST_ID }; @@ -774,6 +921,48 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .attrs = pcf2127_attrs, }, }, + [PCF2131] = { + .max_register = 0x36, + .has_nvmem = 0, + .has_bit_wd_ctl_cd0 = 0, + .regs_td_base = PCF2131_REG_TIME_DATE_BASE, + .regs_alarm_base = PCF2131_REG_ALARM_BASE, + .reg_wd_ctl = PCF2131_REG_WD_CTL, + .reg_wd_val = PCF2131_REG_WD_VAL, + .reg_clkout = PCF2131_REG_CLKOUT, + .ts_count = 4, + .ts[0] = { + .regs_base = PCF2131_REG_TS1_BASE, + .low_reg = PCF2131_REG_CTRL4, + .low_bit = PCF2131_BIT_CTRL4_TSF1, + .ie_reg = PCF2131_REG_CTRL5, + .ie_bit = PCF2131_BIT_CTRL5_TSIE1, + }, + .ts[1] = { + .regs_base = PCF2131_REG_TS2_BASE, + .low_reg = PCF2131_REG_CTRL4, + .low_bit = PCF2131_BIT_CTRL4_TSF2, + .ie_reg = PCF2131_REG_CTRL5, + .ie_bit = PCF2131_BIT_CTRL5_TSIE2, + }, + .ts[2] = { + .regs_base = PCF2131_REG_TS3_BASE, + .low_reg = PCF2131_REG_CTRL4, + .low_bit = PCF2131_BIT_CTRL4_TSF3, + .ie_reg = PCF2131_REG_CTRL5, + .ie_bit = PCF2131_BIT_CTRL5_TSIE3, + }, + .ts[3] = { + .regs_base = PCF2131_REG_TS4_BASE, + .low_reg = PCF2131_REG_CTRL4, + .low_bit = PCF2131_BIT_CTRL4_TSF4, + .ie_reg = PCF2131_REG_CTRL5, + .ie_bit = PCF2131_BIT_CTRL5_TSIE4, + }, + .attribute_group = { + .attrs = pcf2131_attrs, + }, + }, }; /* @@ -922,7 +1111,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, * Watchdog timer enabled and reset pin /RST activated when timed out. * Select 1Hz clock source for watchdog timer. * Note: Countdown timer disabled and not available. - * For pca2129, pcf2129, only bit[7] is for Symbol WD_CD + * For pca2129, pcf2129 and pcf2131, only bit[7] is for Symbol WD_CD * of register watchdg_tim_ctl. The bit[6] is labeled * as T. Bits labeled as T must always be written with * logic 0. @@ -982,6 +1171,7 @@ static const struct of_device_id pcf2127_of_match[] = { { .compatible = "nxp,pcf2127", .data = &pcf21xx_cfg[PCF2127] }, { .compatible = "nxp,pcf2129", .data = &pcf21xx_cfg[PCF2129] }, { .compatible = "nxp,pca2129", .data = &pcf21xx_cfg[PCF2129] }, + { .compatible = "nxp,pcf2131", .data = &pcf21xx_cfg[PCF2131] }, {} }; MODULE_DEVICE_TABLE(of, pcf2127_of_match); @@ -1069,6 +1259,7 @@ static const struct i2c_device_id pcf2127_i2c_id[] = { { "pcf2127", PCF2127 }, { "pcf2129", PCF2129 }, { "pca2129", PCF2129 }, + { "pcf2131", PCF2131 }, { } }; MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id); @@ -1190,6 +1381,7 @@ static const struct spi_device_id pcf2127_spi_id[] = { { "pcf2127", PCF2127 }, { "pcf2129", PCF2129 }, { "pca2129", PCF2129 }, + { "pcf2131", PCF2131 }, { } }; MODULE_DEVICE_TABLE(spi, pcf2127_spi_id); @@ -1254,5 +1446,5 @@ static void __exit pcf2127_exit(void) module_exit(pcf2127_exit) MODULE_AUTHOR("Renaud Cerrato "); -MODULE_DESCRIPTION("NXP PCF2127/29 RTC driver"); +MODULE_DESCRIPTION("NXP PCF2127/29/31 RTC driver"); MODULE_LICENSE("GPL v2"); From patchwork Thu Dec 15 15:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421916wrn; Thu, 15 Dec 2022 07:20:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4RCTxYeQTGtL6S4MiXzq97sJdm6BzBKoTtj6KYK4Apoqmd44tb5RhBU3eUrXkMwZBJ1dc0 X-Received: by 2002:a17:902:bb98:b0:186:a43b:ac with SMTP id m24-20020a170902bb9800b00186a43b00acmr27778319pls.35.1671117650788; Thu, 15 Dec 2022 07:20:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117650; cv=none; d=google.com; s=arc-20160816; b=qACYlkMsqrydId9UgThAnZeRlnVEl/6iJbyqe44nGiDS0tx+p3Udgd69Ue+v1cLBFg OGW+8IV3jeEa70N7iBjUBCXWQKoeagYuVY83wch0PEsXlik4V4TRd+rH7llXHWd7tjHt nFb7o1fUhVOrJpj6CZp/kCOqnX5tywjNl2Szy9dHvP5tEpGv224Nr7sEQ2r/s+UFKHSb ZrMXMlGo+xdlfBRfS1hIVd46upAOpOkb+1doJ/0WbDHKhD2IFxZXkwDgRBmVWEFBriBy mHT1tB0VPCpzqZTqxh8QRQrHjR2bOIh+jGg0OhFVAbW5ykqwgs751sqrNsYok0oJPwve Ed0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=93BpRoQca1NquGcy51NScGuvojh7/iuZ0TUbanDmc/E=; b=nFw8HTNGNAWMmT8i0DQ+4+lXRyrS3bk14pk8R3bRobpkRED+GLFdvYvG3VRJexpFZj tQCbpwUOn073Q3IxFu5h2OEQTtU/CpUaVmEnJlgsEreoIn6yTP/TzXABViAy5yB30hyS 2AhLHInq7bh+c9IokbQZHk02axjlaesYzoEOZDGF+3IBJ+rCJKzeLCMpHuqYGWCeJIzO 8LQapU4yfhue+OpdiVdEoY4RQEZ2V51qzzfCPxJrvRBGzUDhzH51mT8R9BUCQjzM0glA /uRMsbaBc5AsCF6mLOzTjIFwS9hkqzc5ODa4xhJWIb8CjmSt+udjAwJwkyamw7ulHDiE R+Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=YLMnlpqQ; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj19-20020a170903049300b001868277386dsi5377046plb.192.2022.12.15.07.20.31; Thu, 15 Dec 2022 07:20:50 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=YLMnlpqQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbiLOPTE (ORCPT + 99 others); Thu, 15 Dec 2022 10:19:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbiLOPSV (ORCPT ); Thu, 15 Dec 2022 10:18:21 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D56AC70; Thu, 15 Dec 2022 07:18:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=93BpRoQca1NquGcy51NScGuvojh7/iuZ0TUbanDmc/E=; b=YLMnlpqQYsCMooD65o0qavlFV0 Mr/Zc+DEXDLagiHezge4uw47CPPxCbCgvOG1Lmj1HQhnvvc2LB2ktR0ORuJ9yyOCDmUG+UFcpGgIb p1jQECwB9fjzsYg1LQuQONsqH1V1nwztOKDmWyr2lCbltoNAjz+TeZC7ZldTS1qnkISw=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmJ-0000EC-9e; Thu, 15 Dec 2022 10:04:07 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:09 -0500 Message-Id: <20221215150214.1109074-9-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 08/14] rtc: pcf2127: add support for PCF2131 interrupts on output INT_A X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293861517584209?= X-GMAIL-MSGID: =?utf-8?q?1752293861517584209?= From: Hugo Villeneuve The PCF2127 and PCF2129 have one output interrupt pin. The PCF2131 has two, named INT_A and INT_B. The hardware support that any interrupt source can be routed to either one or both of them. Force all interrupt sources to go to the INT A pin. Support to route any interrupt source to INT A/B pins is not supported by this driver at the moment. Signed-off-by: Hugo Villeneuve Reviewed-by: Bruno Thomsen --- drivers/rtc/rtc-pcf2127.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 4148e135f935..68af4d0438b8 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -191,6 +191,7 @@ struct pcf21xx_config { int max_register; unsigned int has_nvmem:1; unsigned int has_bit_wd_ctl_cd0:1; + unsigned int has_int_a_b:1; /* PCF2131 supports two interrupt outputs. */ u8 regs_td_base; /* Time/data base registers. */ u8 regs_alarm_base; /* Alarm function base registers. */ u8 reg_wd_ctl; /* Watchdog control register. */ @@ -879,6 +880,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .max_register = 0x1d, .has_nvmem = 1, .has_bit_wd_ctl_cd0 = 1, + .has_int_a_b = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2127_REG_ALARM_BASE, .reg_wd_ctl = PCF2127_REG_WD_CTL, @@ -902,6 +904,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .max_register = 0x19, .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, + .has_int_a_b = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2127_REG_ALARM_BASE, .reg_wd_ctl = PCF2127_REG_WD_CTL, @@ -925,6 +928,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .max_register = 0x36, .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, + .has_int_a_b = 1, .regs_td_base = PCF2131_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2131_REG_ALARM_BASE, .reg_wd_ctl = PCF2131_REG_WD_CTL, @@ -1017,6 +1021,28 @@ static int pcf2127_enable_ts(struct device *dev, int ts_id) return ret; } +/* Route all interrupt sources to INT A pin. */ +static int pcf2127_configure_interrupt_pins(struct device *dev) +{ + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); + int ret; + + /* Mask bits need to be cleared to enable corresponding + * interrupt source. + */ + ret = regmap_write(pcf2127->regmap, + PCF2131_REG_INT_A_MASK1, 0); + if (ret) + return ret; + + ret = regmap_write(pcf2127->regmap, + PCF2131_REG_INT_A_MASK2, 0); + if (ret) + return ret; + + return ret; +} + static int pcf2127_probe(struct device *dev, struct regmap *regmap, int alarm_irq, const char *name, const struct pcf21xx_config *config) { @@ -1076,6 +1102,15 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, set_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features); } + if (pcf2127->cfg->has_int_a_b) { + /* Configure int A/B pins, independently of alarm_irq. */ + ret = pcf2127_configure_interrupt_pins(dev); + if (ret) { + dev_err(dev, "failed to configure interrupt pins\n"); + return ret; + } + } + if (pcf2127->cfg->has_nvmem) { struct nvmem_config nvmem_cfg = { .priv = pcf2127, From patchwork Thu Dec 15 15:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421130wrn; Thu, 15 Dec 2022 07:19:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf6sIJJrdKfyqsII2T5OcS0SHPH4Kw5DYdZbD/N/lyMnNsPDaxJ1I9bPg7oiV+mqDnrHr1Em X-Received: by 2002:a17:90a:ce16:b0:218:a672:bcab with SMTP id f22-20020a17090ace1600b00218a672bcabmr28894152pju.14.1671117579744; Thu, 15 Dec 2022 07:19:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117579; cv=none; d=google.com; s=arc-20160816; b=cjNfvxbVwfCrpR+VhQY6I+tYvNB2tOIUKyx/eRxe6F/k4EjbeazWcEnUomYHFslN/e T3SqCNAA6wmPqm679FNy2qMZn6zBdU8HAO7mAnru558JGClJT06ThIDjyJLfIcOY59cP hqvwpj6zdfqNZ74eApLzYpaZg5xPxlDaqEROAxv2NREDaVYm4wu3Yk9gfHcQGaxvBxSV yw+ZNEAR9l9P0vVCMVbv7QxuDootym2IMGXtMkf3xNyE0hURGBwR89VQj8SpOv6Yvcey a0sWGjiUn9lYnWN0LnhmwwS4MeG0gBSEB9wOPlt8QFpw+w3WCp4JsnI7FGK8HUjvxuio PgbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=z+IHwHSu5unAUaaw4EDPAX6GeAr53Ixz/aN3zTKz0e8=; b=ICONoYPRqiz6RYGIbBCLTOVKP7TxPXU/XFAXXRJ7Ifoehh7WFa+HtsBB/UQsOi2d5m /WLndhxocofcmvi04Tq+BOMfJ4pI5+0hhpW+EtO7YdwpmIMsCuVB16KyI841WdpNgJhB RsTLt7afp4qC8GUYmgLQBLEXR7GoIOqhSQjgi9GMuQM2fYS/uC2vSnRhEJw3zBHPI5OR 7eGaC8M9gN86OV4jD/5pBp4oaXEYisi4CA5Qo+Rx42TSozpexw2d4g6Qi8WknNqSuQBP /Wm8aAu1vdbPCK5LZgYtVJqy2akjtEJ/sqMtOtAsOzzc0DsOs/tBC2aWHIB5FfUQrV3B o+lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=Qku3p+XT; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pf4-20020a17090b1d8400b00218ceebbcafsi5868224pjb.130.2022.12.15.07.19.25; Thu, 15 Dec 2022 07:19:39 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=Qku3p+XT; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbiLOPSH (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbiLOPSE (ORCPT ); Thu, 15 Dec 2022 10:18:04 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80E6C19F; Thu, 15 Dec 2022 07:18:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=z+IHwHSu5unAUaaw4EDPAX6GeAr53Ixz/aN3zTKz0e8=; b=Qku3p+XT555mojQSydWem3v8Yu 4EdXOoOaYhhR0PqwTE6//CqdXVbuZuAbLuh8SRYy5VeN4VYAgHOZPvqUTP11SIA7rfdhX2b5iH0SU m+KitC3I3DikYQdv+e+pNipccXr3B7J44CYgxgYo7KsucDRgjAERvYj0/NpMlJIsiZQg=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmK-0000EC-D5; Thu, 15 Dec 2022 10:04:09 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:10 -0500 Message-Id: <20221215150214.1109074-10-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 09/14] rtc: pcf2127: set PWRMNG value for PCF2131 X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293787002185328?= X-GMAIL-MSGID: =?utf-8?q?1752293787002185328?= From: Hugo Villeneuve Default PWRMNG[2:0] bits are set to 000b for PCF2127/29, but to 111b for PCF2131. Set these bits to 000b to select same mode as PCF2127/29. Signed-off-by: Hugo Villeneuve Reviewed-by: Bruno Thomsen --- drivers/rtc/rtc-pcf2127.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 68af4d0438b8..241189ee4a05 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -53,6 +53,7 @@ #define PCF2127_BIT_CTRL3_BLF BIT(2) #define PCF2127_BIT_CTRL3_BF BIT(3) #define PCF2127_BIT_CTRL3_BTSE BIT(4) +#define PCF2127_CTRL3_PWRMNG_MASK GENMASK(7, 5) /* Control register 4 */ #define PCF2131_REG_CTRL4 0x03 #define PCF2131_BIT_CTRL4_TSF4 BIT(4) @@ -1129,6 +1130,20 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1, PCF2127_BIT_CTRL1_POR_OVRD); + /* Make sure PWRMNG[2:0] is set to 000b. This is the default for + * PCF2127/29, but not for PCF2131 (default of 111b). + * + * PWRMNG[2:0] = 000b: + * battery switch-over function is enabled in standard mode; + * battery low detection function is enabled + */ + ret = regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL3, + PCF2127_CTRL3_PWRMNG_MASK); + if (ret < 0) { + dev_err(dev, "PWRMNG config failed\n"); + return ret; + } + ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val); if (ret < 0) return ret; From patchwork Thu Dec 15 15:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33686 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421933wrn; Thu, 15 Dec 2022 07:20:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf64Z5syliarpNS8wrjZY30nm2FYJlLGqsj7uU6gjgRMTD3FW2STuq41Sbt5tUb30kddE8+A X-Received: by 2002:a17:90b:80f:b0:219:3d3a:6c51 with SMTP id bk15-20020a17090b080f00b002193d3a6c51mr29074836pjb.40.1671117652433; Thu, 15 Dec 2022 07:20:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117652; cv=none; d=google.com; s=arc-20160816; b=g3WgYdygkPnfwurOw9RixGtPbYkd3VzW254rEIiYRQIIdCzCJuYfAvJgd19WJo+Zt3 +HfmbxChs2dO/DBVWHdk3L4QexOp6QJIu0d9V4se5sN/Wl2OFUco+YyxDH54u51kpAdG kIq0Kw/qA2kgSQ2/yke1AAe1cu5qT3tJ8kQbo4RpEwiDKm7CH5Q20inDdk7NDifrNIeE 3181a2O4rqiAb6DcnJvVCPvge4R+ULivdOEY8e+h4plmmhqtySITRFg6ypiOATLhv5uO KVLOtfVRaOYqUj5DqQw0Bj3E0pSAqhVImSrNcJSOH/8xYLqqMlQNhhr7NYPXwHjf1cJQ HnxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=oPy9P9+yLezoffi1X44DtaGZG/5UdTf4Vmd7bRb4d7g=; b=X9MVd4NpzWVesqzwf/oN4ZEdButX+ahZ01pGnOdm2BYd/Ocpi/6v7H5z1nAqsWCStM 0xsT5zD8dlMsdi9YjJaHz72vm9TshctEV+B8fUp6NnVPlvJq6ZEGNiFaWIqAjrpF05rn TJnkAfRu8tTRAMpr/bz2zPTjcBfyFHNuGmoaxJ/vVJxjuFa8T8f2Ca9gZC+MycHoi2UZ GCYSqlpWjx0uP5OGK40ARh2IH3rIQkXJKM01jJW8Ol7VXkjUVkjvMMkqb70jauB8PPyg 4knOd8OJY0CGxDqj9aEI529CkUQasSiFh0dLsAi+JFvn6f6+/JdBh3ralZ7hQLGmvkNI pVQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=sFVlt4J3; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l72-20020a63914b000000b004785d1e2b7bsi3189419pge.514.2022.12.15.07.20.39; Thu, 15 Dec 2022 07:20:52 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=sFVlt4J3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230247AbiLOPTl (ORCPT + 99 others); Thu, 15 Dec 2022 10:19:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiLOPTM (ORCPT ); Thu, 15 Dec 2022 10:19:12 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60A2FDB8; Thu, 15 Dec 2022 07:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=oPy9P9+yLezoffi1X44DtaGZG/5UdTf4Vmd7bRb4d7g=; b=sFVlt4J3F/BcSFruC+6l4cnuP+ vqcPUtaFrAAyNdhMdAKF74KdXDl+F8hr+7sUj1xd7GtE89Yz6HxraC85PVfHdYSGr2wolba/m3MTv Kujmw/2ovzw7Y+RWfhZssNQgGrdLd2CUZFWfn8XAxiwsDs3ks7mp5XzDrhn074EKFhaU=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmL-0000EC-IL; Thu, 15 Dec 2022 10:04:10 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:11 -0500 Message-Id: <20221215150214.1109074-11-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 10/14] rtc: pcf2127: read and validate PCF2131 device signature X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293863051353283?= X-GMAIL-MSGID: =?utf-8?q?1752293863051353283?= From: Hugo Villeneuve Make sure the device we are probing is really the device we are interested in. Signed-off-by: Hugo Villeneuve --- drivers/rtc/rtc-pcf2127.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 241189ee4a05..e4b78b9c03f9 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -193,11 +193,13 @@ struct pcf21xx_config { unsigned int has_nvmem:1; unsigned int has_bit_wd_ctl_cd0:1; unsigned int has_int_a_b:1; /* PCF2131 supports two interrupt outputs. */ + unsigned int has_reset_reg:1; /* If variant has a reset register. */ u8 regs_td_base; /* Time/data base registers. */ u8 regs_alarm_base; /* Alarm function base registers. */ u8 reg_wd_ctl; /* Watchdog control register. */ u8 reg_wd_val; /* Watchdog value register. */ u8 reg_clkout; /* Clkout register. */ + u8 reg_reset; /* Reset register if available. */ unsigned int ts_count; struct pcf21xx_ts_config ts[4]; struct attribute_group attribute_group; @@ -882,6 +884,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .has_nvmem = 1, .has_bit_wd_ctl_cd0 = 1, .has_int_a_b = 0, + .has_reset_reg = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2127_REG_ALARM_BASE, .reg_wd_ctl = PCF2127_REG_WD_CTL, @@ -906,6 +909,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, .has_int_a_b = 0, + .has_reset_reg = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2127_REG_ALARM_BASE, .reg_wd_ctl = PCF2127_REG_WD_CTL, @@ -930,11 +934,13 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, .has_int_a_b = 1, + .has_reset_reg = 1, .regs_td_base = PCF2131_REG_TIME_DATE_BASE, .regs_alarm_base = PCF2131_REG_ALARM_BASE, .reg_wd_ctl = PCF2131_REG_WD_CTL, .reg_wd_val = PCF2131_REG_WD_VAL, .reg_clkout = PCF2131_REG_CLKOUT, + .reg_reset = PCF2131_REG_SR_RESET, .ts_count = 4, .ts[0] = { .regs_base = PCF2131_REG_TS1_BASE, @@ -1075,6 +1081,20 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf2127->rtc->features); clear_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features); + /* Read device signature if available. */ + if (pcf2127->cfg->has_reset_reg) { + ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_reset, &val); + if (ret < 0) { + dev_err(dev, "reading RESET register failed\n"); + return ret; + } + + if (val != PCF2131_SR_RESET_READ_PATTERN) { + dev_err(dev, "invalid device signature: $%02X\n", (u8)val); + return -ENODEV; + } + } + if (alarm_irq > 0) { unsigned long flags; From patchwork Thu Dec 15 15:02:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421177wrn; Thu, 15 Dec 2022 07:19:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ZoDxOBT4I0zwHEMgWmm+jGiqiRJTVBdvwMFU9Y5bEff6f0Uk+fW8qJ+/LIr8k8OxIqufp X-Received: by 2002:a05:6a20:930f:b0:a7:866d:40b5 with SMTP id r15-20020a056a20930f00b000a7866d40b5mr25172042pzh.6.1671117583868; Thu, 15 Dec 2022 07:19:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117583; cv=none; d=google.com; s=arc-20160816; b=rNx4s+BWQsS3Afw4swdp3RCBY+3EAAYKpOPiAHl11jqc5EiA1CW9i5AGlxqDNxebwc CDvXfH4Bj4FCrceJc5lEwiIIcGI/s7sm7rceZOKGHjXNjfj6rC8qNYD0ZmgO4IZDqcgZ qjHn0laKz/R3tXH7jlDYoJX4jaTiV+k/3et584IG0LOxqCeyP/dck8DLxcMjN9AzLMoQ eAofJ+ymwOimAGgmwfIX1e1wSl/j91F6lxKj19imU8K+Y38rrfIaRUYGWjMdj5agAbwV 9j3IEGQOnYsJ+tKZ6pb0wr4/HWG41/TmLZoaXmnWIs8kSxU6P7f0g44Vv9J0sRfG0DxI 9rUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=cCTf1P1Ro/N5X79I1I290rP6Jh7qh0U4wx0QBzSmYMQ=; b=0+sIeARTHL+OCV+7tc7/Avmtymwf+6Pm2R3hL4Ok+lSNrpqIrZKKdMSz0v1ExhsC0D rAZI5ldGy71WhSRQGh87t8gpwO4XQxMQIpSQN+0L2xk9CBUxA35s9pWBE2jAJ9vSbrDL KytYKe1Or+fUsXs4VV7H2kTUcqVg8LRKvcVODZCNK3tLrAojcvcvJg1f1X2lIiiKC5HY IS2sz4CrDcxCFGWTRs6i1Ht1xQhJ4Q2ZdnuNmZhr/t5rFXoyoQ73c6AOZdNKKGL8bOrI wO5qwKik+OY/sinaNI9GpM+YLEblI/weab+fRQkYzU6oNbyriB6Tp4ECjnW/UBu6SBr6 gbng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=FJAEF2V4; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m22-20020a635816000000b00479079b77a6si3027108pgb.105.2022.12.15.07.19.30; Thu, 15 Dec 2022 07:19:43 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=FJAEF2V4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbiLOPSP (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiLOPSH (ORCPT ); Thu, 15 Dec 2022 10:18:07 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC7FF19F; Thu, 15 Dec 2022 07:18:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=cCTf1P1Ro/N5X79I1I290rP6Jh7qh0U4wx0QBzSmYMQ=; b=FJAEF2V4u9/V8aWleuoaeHIMnh YiumC9kpOionkUuDn3/3wSBvR3+mOIl91bpx291TIvTjg0RMth2l7ZmG4uh0HH3w4LSL8AQVWvdJ9 K2qkLCtmbSfqkOKFE7vFtsiJU85o56xjKD+/etsOa2nYYH0fOkr3i4/abN/otikFaI3Q=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmN-0000EC-1u; Thu, 15 Dec 2022 10:04:11 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:12 -0500 Message-Id: <20221215150214.1109074-12-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 11/14] rtc: pcf2127: adapt time/date registers write sequence for PCF2131 X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293791196414261?= X-GMAIL-MSGID: =?utf-8?q?1752293791196414261?= From: Hugo Villeneuve The sequence for updating the time/date registers is slightly different between PCF2127/29 and PCF2131. For PCF2127/29, during write operations, the time counting circuits (memory locations 03h through 09h) are automatically blocked. For PCF2131, time/date registers write access requires setting the STOP bit and sending the clear prescaler instruction (CPR). STOP then needs to be released once write operation is completed. Signed-off-by: Hugo Villeneuve --- drivers/rtc/rtc-pcf2127.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index e4b78b9c03f9..11fbdab6bf01 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -39,6 +39,7 @@ #define PCF2127_REG_CTRL1 0x00 #define PCF2127_BIT_CTRL1_POR_OVRD BIT(3) #define PCF2127_BIT_CTRL1_TSF1 BIT(4) +#define PCF2127_BIT_CTRL1_STOP BIT(5) /* Control register 2 */ #define PCF2127_REG_CTRL2 0x01 #define PCF2127_BIT_CTRL2_AIE BIT(1) @@ -70,6 +71,7 @@ #define PCF2131_REG_SR_RESET 0x05 #define PCF2131_SR_RESET_READ_PATTERN 0b00100100 /* Fixed pattern. */ #define PCF2131_SR_RESET_RESET_CMD 0x2C /* SR is bit 3. */ +#define PCF2131_SR_RESET_CPR_CMD 0xA4 /* CPR is bit 7. */ /* Time and date registers */ #define PCF2127_REG_TIME_DATE_BASE 0x03 #define PCF2131_REG_TIME_DATE_BASE 0x07 /* Register 0x06 is 100th seconds, @@ -307,7 +309,31 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm) /* year */ buf[i++] = bin2bcd(tm->tm_year - 100); - /* write register's data */ + /* Write access to time registers: + * PCF2127/29: no special action required. + * PCF2131: requires setting the STOP bit. STOP bit needs to + * be cleared after time registers are updated. + * It is also recommended to set CPR bit, although + * write access will work without it. + */ + if (pcf2127->cfg->has_reset_reg) { + err = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, + PCF2127_BIT_CTRL1_STOP, + PCF2127_BIT_CTRL1_STOP); + if (err) { + dev_err(dev, "setting STOP bit failed\n"); + return err; + } + + err = regmap_write(pcf2127->regmap, pcf2127->cfg->reg_reset, + PCF2131_SR_RESET_CPR_CMD); + if (err) { + dev_err(dev, "sending CPR cmd failed\n"); + return err; + } + } + + /* write time register's data */ err = regmap_bulk_write(pcf2127->regmap, pcf2127->cfg->regs_td_base, buf, i); if (err) { dev_err(dev, @@ -315,6 +341,16 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm) return err; } + if (pcf2127->cfg->has_reset_reg) { + /* Clear STOP bit (PCF2131 only) after write is completed. */ + err = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, + PCF2127_BIT_CTRL1_STOP, 0); + if (err) { + dev_err(dev, "clearing STOP bit failed\n"); + return err; + } + } + return 0; } From patchwork Thu Dec 15 15:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421369wrn; Thu, 15 Dec 2022 07:20:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf44fVVWz/LXxVaCAVG9EtRS/F1VIwAIT/7wle/eE9GlxhYdRAE0iJFu/dG1ybpfb8RUuNSM X-Received: by 2002:a17:903:3316:b0:189:7819:e5c with SMTP id jk22-20020a170903331600b0018978190e5cmr27791054plb.6.1671117599762; Thu, 15 Dec 2022 07:19:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117599; cv=none; d=google.com; s=arc-20160816; b=AdKFszQHMfEtobRgSjvCSFPK1qWfPZlVyUcffv/Q/oqn7pj1EuXU9FzKi71A8MCevL 7sCEoHA4Z3O13+Twqn7ZJaUZ0ak/uwtZI5uFpe6IfxMpQWtmVrLT1R94XV7HUqEbu/39 JLzeoS3zz9p6uKP8WPqeK2vYGJslLO/g52OVW4dUG5dcaTDH7kXk7bWpEUEtxRVcOYfB c94FM3kjEAc5RD9EodVMpe955m/Oen0DxEmgQQ3YzJbQ4mBl+kf0hM7GlDEyWRQcIMhz QIz54P5rbOMWiPguaRyZi5rqxUj1sJRMbnU+uGL8p9c4BXFyuT6ItooKvi01Y69JZdtj MO8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=AKT7vMuFa4zuixGZfWOqdH1QYl+ynLT/9uMz3IdzAig=; b=sX5XVqQfNJexIID3KuAjk3/qisu7Ebsl5HVbCPq7tdRfKwj16vnhJYxvjPgQw+3ovT 5gUePT/UgZ88vXwqINnkVKYPiixzQjYGG5ddLw+ywlU32naYUf1Me2+jQiWeB26qXwc2 2LLtbknr9sKR9+E4c4HZxb5EYR+ylGAimVd/JgEEWSklsICcVdq+Yy1TlunI/yjeqNoY R9BXMI4H0TYmb3RY5QZImjYir3bPD4+ESsFJbYV9D7lb3IE6eWSSk9phVLbP3ZzVDQs4 FwxBSDJw7yTaGLNgXiLmwPx2G49MqRwKsDKUwoHuGSsot4tcj6OmoveXb6077iYb5bmp hvnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=E3KhdBp2; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x13-20020a170902ec8d00b0018909c67720si6616977plg.281.2022.12.15.07.19.44; Thu, 15 Dec 2022 07:19:59 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b=E3KhdBp2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbiLOPSZ (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiLOPSN (ORCPT ); Thu, 15 Dec 2022 10:18:13 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0CEABDD; Thu, 15 Dec 2022 07:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=AKT7vMuFa4zuixGZfWOqdH1QYl+ynLT/9uMz3IdzAig=; b=E3KhdBp2dJQM6xxnqzweZErHl8 ueeMXliyhTb61Zp7AZNtIzLIHAzeu2okuHmhHcJ8QMhAbvvA59DvdTZBLJabHJeJODyTQy9Ba4VhU ZornaZnXS+FnniZUkQnOP+d1ijQFvFTe+X1m9k2NmjiIn6AdrR2bI8ruMp+b7SUVcnQ4=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmO-0000EC-FM; Thu, 15 Dec 2022 10:04:13 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:13 -0500 Message-Id: <20221215150214.1109074-13-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 12/14] rtc: pcf2127: support generic watchdog timing configuration X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293807907196080?= X-GMAIL-MSGID: =?utf-8?q?1752293807907196080?= From: Hugo Villeneuve Introduce in the configuration structure two new values to hold the watchdog clock source and the min_hw_heartbeat_ms value. The minimum and maximum timeout values are automatically computed from the watchdog clock source value for each variant. The PCF2131 has no 1Hz watchdog clock source, as is the case for PCF2127/29. The next best choice is using a 1/4Hz clock, giving a watchdog timeout range between 4 and 1016s. By using the same register configuration as for the PCF2127/29, the 1/4Hz clock source is selected. Note: the PCF2127 datasheet gives a min/max range between 1 and 255s, but it should be between 2 and 254s, because the watchdog is triggered when the timer value reaches 1, not 0. Signed-off-by: Hugo Villeneuve --- drivers/rtc/rtc-pcf2127.c | 56 +++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 11fbdab6bf01..3fd2fee4978b 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -157,9 +157,29 @@ /* Watchdog timer value constants */ #define PCF2127_WD_VAL_STOP 0 -#define PCF2127_WD_VAL_MIN 2 -#define PCF2127_WD_VAL_MAX 255 -#define PCF2127_WD_VAL_DEFAULT 60 +#define PCF2127_WD_VAL_DEFAULT 60 /* In seconds. */ +/* PCF2127/29 watchdog timer value constants */ +#define PCF2127_WD_CLOCK_HZ_X1000 1000 /* 1Hz */ +#define PCF2127_WD_MIN_HW_HEARTBEAT_MS 500 +/* PCF2131 watchdog timer value constants */ +#define PCF2131_WD_CLOCK_HZ_X1000 250 /* 1/4Hz */ +#define PCF2131_WD_MIN_HW_HEARTBEAT_MS 4000 +/* + * Compute watchdog period, t, in seconds, from the WATCHDG_TIM_VAL register + * value, n, and the clock frequency, f, in Hz. + * + * The PCF2127/29 datasheet gives t as: + * t = n / f + * The PCF2131 datasheet gives t as: + * t = (n - 1) / f + * For both variants, the watchdog is triggered when the WATCHDG_TIM_VAL reaches + * the value 1, and not zero. Consequently, the equation from the PCF2131 + * datasheet seems to be the correct one for both variants. + */ +#define WD_PERIOD_S(_n_, _f1000_) ((1000 * ((_n_) - 1)) / (_f1000_)) + +/* Compute value of WATCHDG_TIM_VAL to obtain period t, in seconds. */ +#define WD_COUNTER(_t_, _f1000_) ((((_t_) * (_f1000_)) / 1000) + 1) /* Mask for currently enabled interrupts */ #define PCF2127_CTRL1_IRQ_MASK (PCF2127_BIT_CTRL1_TSF1) @@ -202,6 +222,11 @@ struct pcf21xx_config { u8 reg_wd_val; /* Watchdog value register. */ u8 reg_clkout; /* Clkout register. */ u8 reg_reset; /* Reset register if available. */ + + /* Watchdog configuration. */ + int wdd_clock_hz_x1000; /* Value in Hz multiplicated by 1000 */ + int wdd_min_hw_heartbeat_ms; + unsigned int ts_count; struct pcf21xx_ts_config ts[4]; struct attribute_group attribute_group; @@ -496,10 +521,19 @@ static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127) pcf2127->wdd.parent = dev; pcf2127->wdd.info = &pcf2127_wdt_info; pcf2127->wdd.ops = &pcf2127_watchdog_ops; - pcf2127->wdd.min_timeout = PCF2127_WD_VAL_MIN; - pcf2127->wdd.max_timeout = PCF2127_WD_VAL_MAX; - pcf2127->wdd.timeout = PCF2127_WD_VAL_DEFAULT; - pcf2127->wdd.min_hw_heartbeat_ms = 500; + + pcf2127->wdd.min_timeout = + WD_PERIOD_S(2, pcf2127->cfg->wdd_clock_hz_x1000); + pcf2127->wdd.max_timeout = + WD_PERIOD_S(255, pcf2127->cfg->wdd_clock_hz_x1000); + pcf2127->wdd.timeout = WD_COUNTER(PCF2127_WD_VAL_DEFAULT, + pcf2127->cfg->wdd_clock_hz_x1000); + + dev_dbg(dev, "%s min = %ds\n", __func__, pcf2127->wdd.min_timeout); + dev_dbg(dev, "%s max = %ds\n", __func__, pcf2127->wdd.max_timeout); + dev_dbg(dev, "%s def = %d\n", __func__, pcf2127->wdd.timeout); + + pcf2127->wdd.min_hw_heartbeat_ms = pcf2127->cfg->wdd_min_hw_heartbeat_ms; pcf2127->wdd.status = WATCHDOG_NOWAYOUT_INIT_STATUS; watchdog_set_drvdata(&pcf2127->wdd, pcf2127); @@ -926,6 +960,8 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .reg_wd_ctl = PCF2127_REG_WD_CTL, .reg_wd_val = PCF2127_REG_WD_VAL, .reg_clkout = PCF2127_REG_CLKOUT, + .wdd_clock_hz_x1000 = PCF2127_WD_CLOCK_HZ_X1000, + .wdd_min_hw_heartbeat_ms = PCF2127_WD_MIN_HW_HEARTBEAT_MS, .ts_count = 1, .ts[0] = { .regs_base = PCF2127_REG_TS1_BASE, @@ -951,6 +987,8 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .reg_wd_ctl = PCF2127_REG_WD_CTL, .reg_wd_val = PCF2127_REG_WD_VAL, .reg_clkout = PCF2127_REG_CLKOUT, + .wdd_clock_hz_x1000 = PCF2127_WD_CLOCK_HZ_X1000, + .wdd_min_hw_heartbeat_ms = PCF2127_WD_MIN_HW_HEARTBEAT_MS, .ts_count = 1, .ts[0] = { .regs_base = PCF2127_REG_TS1_BASE, @@ -977,6 +1015,8 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .reg_wd_val = PCF2131_REG_WD_VAL, .reg_clkout = PCF2131_REG_CLKOUT, .reg_reset = PCF2131_REG_SR_RESET, + .wdd_clock_hz_x1000 = PCF2131_WD_CLOCK_HZ_X1000, + .wdd_min_hw_heartbeat_ms = PCF2131_WD_MIN_HW_HEARTBEAT_MS, .ts_count = 4, .ts[0] = { .regs_base = PCF2131_REG_TS1_BASE, @@ -1215,7 +1255,7 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, /* * Watchdog timer enabled and reset pin /RST activated when timed out. - * Select 1Hz clock source for watchdog timer. + * Select 1Hz clock source for watchdog timer (1/4Hz for PCF2131). * Note: Countdown timer disabled and not available. * For pca2129, pcf2129 and pcf2131, only bit[7] is for Symbol WD_CD * of register watchdg_tim_ctl. The bit[6] is labeled From patchwork Thu Dec 15 15:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421371wrn; Thu, 15 Dec 2022 07:20:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf4qo/mdk292TpTJy4eyRSAKQ275iqk84jzPLtZ/G6fLvpKED9lEpe1bgthLkmuFpOx387LC X-Received: by 2002:a17:90a:ebc6:b0:212:f14b:9c3f with SMTP id cf6-20020a17090aebc600b00212f14b9c3fmr29202152pjb.25.1671117599851; Thu, 15 Dec 2022 07:19:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117599; cv=none; d=google.com; s=arc-20160816; b=fwRbu63BN7cFmsmGc1Zq4f3Mxu/Vs3xz/kIymxNAHb6dy01orwjsikgkWu+fRgyPMG KTQZVu1K/sgf+XRjlljpYyrdJX6YGbAuJGzRKgCRP3pjn2cgfZBo2++QoRKJpuCzKjQ8 /Ptlk0TdW1hH9odeWAZHdVatsCW67Wxdup6qa8Whhjwhf4Ht4JuxFnXLysbBfp5mBbuc stKOThE7lRSvZV/xhcZFflwM4qwpDRI+9zNTvHojbK1qCa9Y6e1jYHIhPG04krsg4Hzp 7jWK9PJPwTAEY/h/EzCrP7gCQ3vIUJEhiyCqRULxnWqyY3wYo2iRI40MqIavr7niFxPF tSNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=2TpvNPjJv8dDj4S0AWy3RhL4BnpJx4K5ru1eHBA0knE=; b=CBNm6Zp+Vv88GapO3RFCMmBQA34dMiIiUI0BtOVhOpf/nIBaWcGoCqepmfK2xAzPbD PK+ECXnVxoRW1ViY8cEZeQCyIwxp5AnxU1jl1GZF4v4G+YMf5c8ebxeZ9djKKrnKBpYI nzORqEpiYe/XB+9lNIZYL8n3p8VEtdaklZum0qsXunIip/+lBA2DXAu26hH5bfo5W2/z Mf1HAK3KI7u0pnEJwC+94XNMw+vLDMmVwYzG/xhL14fZdgCRBORueWBF/7V9XTVf3bLU iO/betCmH2FRDO41AopWlsfZut/Q7KkpyC6D/K3r/Hlg9ltPJM5C2b64qn/HJJpHG5Zm VQoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b="nZX7/Wto"; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n19-20020a63ee53000000b004788ec9cfdasi3112495pgk.71.2022.12.15.07.19.42; Thu, 15 Dec 2022 07:19:59 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b="nZX7/Wto"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230030AbiLOPST (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbiLOPSJ (ORCPT ); Thu, 15 Dec 2022 10:18:09 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78DDCC41; Thu, 15 Dec 2022 07:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2TpvNPjJv8dDj4S0AWy3RhL4BnpJx4K5ru1eHBA0knE=; b=nZX7/WtofBUQQYU1kqwXQ6pVSe MY0Eo2yc67aJ00XNJu439CNUbx5xEs5iRsubdpJMEu6APpfIFv06RYNDpczor9MaQeV7DvrpRg9CK Lp788Li4ccE5ErB7xKkvXaPqS5k9BJUXgKpm2eTxZzH9GLqSEDohqTJaENE4m/5tG/aY=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmQ-0000EC-3I; Thu, 15 Dec 2022 10:04:14 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:14 -0500 Message-Id: <20221215150214.1109074-14-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 13/14] rtc: pcf2127: add flag for watchdog register value read support X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293808400506177?= X-GMAIL-MSGID: =?utf-8?q?1752293808400506177?= From: Hugo Villeneuve The watchdog value register cannot be read on the PCF2131 after being set. Add a new flag to identify which variant has read access to this register, and use this flag to selectively test if watchdog timer was started by bootloader. Signed-off-by: Hugo Villeneuve Reviewed-by: Bruno Thomsen --- drivers/rtc/rtc-pcf2127.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 3fd2fee4978b..1d2b5c9e6757 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -214,6 +214,7 @@ struct pcf21xx_config { int max_register; unsigned int has_nvmem:1; unsigned int has_bit_wd_ctl_cd0:1; + unsigned int wd_val_reg_readable:1; /* If watchdog value register can be read. */ unsigned int has_int_a_b:1; /* PCF2131 supports two interrupt outputs. */ unsigned int has_reset_reg:1; /* If variant has a reset register. */ u8 regs_td_base; /* Time/data base registers. */ @@ -511,7 +512,6 @@ static const struct watchdog_ops pcf2127_watchdog_ops = { static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127) { - u32 wdd_timeout; int ret; if (!IS_ENABLED(CONFIG_WATCHDOG) || @@ -539,12 +539,17 @@ static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127) watchdog_set_drvdata(&pcf2127->wdd, pcf2127); /* Test if watchdog timer is started by bootloader */ - ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_wd_val, &wdd_timeout); - if (ret) - return ret; + if (pcf2127->cfg->wd_val_reg_readable) { + u32 wdd_timeout; + + ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_wd_val, + &wdd_timeout); + if (ret) + return ret; - if (wdd_timeout) - set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); + if (wdd_timeout) + set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); + } return devm_watchdog_register_device(dev, &pcf2127->wdd); } @@ -953,6 +958,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .max_register = 0x1d, .has_nvmem = 1, .has_bit_wd_ctl_cd0 = 1, + .wd_val_reg_readable = 1, .has_int_a_b = 0, .has_reset_reg = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, @@ -980,6 +986,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .max_register = 0x19, .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, + .wd_val_reg_readable = 1, .has_int_a_b = 0, .has_reset_reg = 0, .regs_td_base = PCF2127_REG_TIME_DATE_BASE, @@ -1007,6 +1014,7 @@ static struct pcf21xx_config pcf21xx_cfg[] = { .max_register = 0x36, .has_nvmem = 0, .has_bit_wd_ctl_cd0 = 0, + .wd_val_reg_readable = 0, .has_int_a_b = 1, .has_reset_reg = 1, .regs_td_base = PCF2131_REG_TIME_DATE_BASE, From patchwork Thu Dec 15 15:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 33681 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp421681wrn; Thu, 15 Dec 2022 07:20:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf62kzNyHTKPmeORhL/vfGxosQrW8XmbIZXJeWwNjji3zNAe827WnE6rnBWBvs6o5SNqb9sE X-Received: by 2002:a05:6a00:4147:b0:577:213e:8cab with SMTP id bv7-20020a056a00414700b00577213e8cabmr29819107pfb.16.1671117627473; Thu, 15 Dec 2022 07:20:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671117627; cv=none; d=google.com; s=arc-20160816; b=uI86nLct68cRVvNdI/Z+igYUkyUEzR83/70trfjMuO+HMx9Nsc71YfhyGnNN3Ia5PC Li0Uzz8UjAT7q55csPlRy9kmjNqRGEAWUCVHhtFCEe/uZOjCfA7/u4YPy6qI1yvovNF0 i/dAejt2RGZhw/KNM8hDO/FSz/lDM/I76hQEcSvW7M5nPbUc5nQd4VylLrXujMdQ3LbU KzLBYOv88CAHr81BKT9XGFjju6OopdieZ7EXrWNQv++9x7VXbC/8S7RUu5bXKoCIxh76 g4O3FLpPCdW9liSbLsUDjZjAkAffATNC8pD7QkvXriOlSp/RlBFlwJVohFaERamYFbS1 +7rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=FmeBIF+FZ8aMPXIhZOnlL5pUaTxaQWAPZ9wO0WSH7RY=; b=sO2l0RvGcqdhflFHi58Z+QmWyf/BtishwtgMcudazrj3PI8iLKqXDZLB7kOYP2pTRi JwcCcib4ttXLxmCTngmt+Baid+ixNXg2WGwa+saZ9j1R/K4ZGVi24BxgiG1a0kpChpdh o3Aw7qcAtzPa65gl8dU7Ty2wlh1qHNuxvI5p8B9qAYoWrulLaqmyyMOhzOKcMj0jLhDJ nYJFsmevHBSC/DAAp9LS1sND8lrnyMLKBYA60fBFBfY2fKcUweBSkNogqGT2fWBrIq3f z3HDaBnVguozP7k/rZRqDqpkxQa0/+ieS8CXZNRXoH3UjIhyhfd0rj1eV4wTGNpNoksU hNLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b="HUvzc/dP"; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020a056a0023c300b0056cb4662b9csi3370124pfc.16.2022.12.15.07.20.13; Thu, 15 Dec 2022 07:20:27 -0800 (PST) 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=fail header.i=@hugovil.com header.s=x header.b="HUvzc/dP"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbiLOPSa (ORCPT + 99 others); Thu, 15 Dec 2022 10:18:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbiLOPSM (ORCPT ); Thu, 15 Dec 2022 10:18:12 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D915FC70; Thu, 15 Dec 2022 07:18:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FmeBIF+FZ8aMPXIhZOnlL5pUaTxaQWAPZ9wO0WSH7RY=; b=HUvzc/dPPLcisxf7kMgULfAZH6 uy8pq3/SGqwHDoGTzyihXMY+Lta7r4uDIz1J74c7oOnqNXJT32HSkmmf4e3cySY6enNE30SsMjLIT F70H3PWzuK4QOCMWYFwzoIkt0ar37GMLm2FYK8bi7vq4Z9i7t8WWbldFqPIVtOytsP14=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:48102 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1p5pmR-0000EC-CL; Thu, 15 Dec 2022 10:04:15 -0500 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Thu, 15 Dec 2022 10:02:15 -0500 Message-Id: <20221215150214.1109074-15-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221215150214.1109074-1-hugo@hugovil.com> References: <20221215150214.1109074-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 14/14] dt-bindings: rtc: pcf2127: add PCF2131 X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) 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?1752293837345230884?= X-GMAIL-MSGID: =?utf-8?q?1752293837345230884?= From: Hugo Villeneuve Add support for new NXP RTC PCF2131. Signed-off-by: Hugo Villeneuve Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml b/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml index cde7b1675ead..a8f8c23da4d8 100644 --- a/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml +++ b/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml @@ -14,7 +14,9 @@ maintainers: properties: compatible: - const: nxp,pcf2127 + enum: + - nxp,pcf2127 + - nxp,pcf2131 reg: maxItems: 1