From patchwork Wed Aug 2 19:11:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 130114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp684999vqx; Wed, 2 Aug 2023 12:40:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlELmmniXPRzpoCaxQUSusbyd6vCk2/I6SNHz1HiNGmqop5AND9HvOKlkY1j79MW39vlqAKc X-Received: by 2002:a05:6a21:4882:b0:134:2fd0:73d6 with SMTP id av2-20020a056a21488200b001342fd073d6mr14683500pzc.31.1691005247639; Wed, 02 Aug 2023 12:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691005247; cv=none; d=google.com; s=arc-20160816; b=IQFjZW0zT2Z2AYyao0wvOgJDwW4nOkHtFq/NlmqKzZw0RPCA3NR4wf8KXTZFL/Iwxu tAEzATH34KOhH6b2ZgQbg2jaGUEKVRZ85UOx7MSk3rfORS+MpcghwDcZd6N6odbkLvEh tzeMEO3VOejeCeM5EnCMs/rKQyExLvshxK8DEgYDl2G5Nl1i7J7Fd1BINl52yy+9nxZL yASmwnUlZVgIQIVrWiyWqyYyusvuAKK+8fDZ4fH6EjlFTwnB0O7bVKN5TvqdZI5lP1WO DeV43oWBGsF+F8TYm+KmUQWORts+jy9LyK9agPQiQE9nB43Anp6Jbw4BU1K6Z0fSY7BE Y/AQ== 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=l0fagwpjnO0mCXCu/hb1J7U1QL4bJjiaBDvQnvA0kiY=; fh=FZymoSmdcO0cDPPdWjnPLH+RORnjIOsZUS3qM6HRZPE=; b=o9qWGZI2h1xCQUneeCxelk8/Ubv4ezfQrd3Fr36QxUtBP6BsY+9Mqi3Z2BUzH+6K0t /5PygLY7UCHC5zCDG/YNjS2+WohsIKKPPSsc5YSrzmMdas38Dym1zKxLIMRwhn71Yc3V mWzGzaEVlqC+e/czhvUe8RxxbPRafO9wbZCG/cz11ZHhvoj53TUHbLDkyb3iG4u9LKb5 aaBvk0e73dZStQ8Pfb7usFYcSipFfOB4IqXaxbZPPH1ngTH5JtVIZV2u7+LrQUR6VB1H 1iN0gfb50LHBTdFSfGcO/DZz5g0cuI+JCN/dAHg/VUcE/g7t9FehGQZXlJHQm3ZYOmZl S/vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=ZJHc5KT4; 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 be3-20020a656e43000000b0055c826f2bd4si11238323pgb.77.2023.08.02.12.40.34; Wed, 02 Aug 2023 12:40:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=ZJHc5KT4; 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 S232585AbjHBTMV (ORCPT + 99 others); Wed, 2 Aug 2023 15:12:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjHBTMP (ORCPT ); Wed, 2 Aug 2023 15:12:15 -0400 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74BFC26B2; Wed, 2 Aug 2023 12:12:12 -0700 (PDT) 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=l0fagwpjnO0mCXCu/hb1J7U1QL4bJjiaBDvQnvA0kiY=; b=ZJHc5KT4QuCBR5z+VPN0cY+pvX WORp8NjEOqITE7KRFKUnPYZq88XtaWHbNuuPPJ7/20deZo9pJflnY07ZnqZDJe7UQI3R4Y86bkLd6 hBgQT3V0R7mfT3J0g6YIIE0IgeKl/sj7Z6kAyLcaiRb4kprANGXj3No1FuQQMRWaJpog=; Received: from modemcable061.19-161-184.mc.videotron.ca ([184.161.19.61]:50458 helo=localhost.localdomain) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1qRHGM-0003z2-Ie; Wed, 02 Aug 2023 15:12:03 -0400 From: Hugo Villeneuve To: a.zummo@towertech.it, alexandre.belloni@bootlin.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, bruno.thomsen@gmail.com, Hugo Villeneuve Date: Wed, 2 Aug 2023 15:11:53 -0400 Message-Id: <20230802191153.952667-3-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230802191153.952667-1-hugo@hugovil.com> References: <20230802191153.952667-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 184.161.19.61 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH 2/2] rtc: pcf2127: add support for battery-related DT properties 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: INBOX X-GMAIL-THRID: 1773147518781009581 X-GMAIL-MSGID: 1773147518781009581 From: Hugo Villeneuve Add support for "battery-switch-over-enable" DT property which can be used to enable/disable the battery switch over function. Also add support for "battery-low-detect-enable" DT property which can be used to enable/disable the battery low detection function. If any of these properties is not defined, then no alteration to the PWRMNG field will occur. These properties can be used to change the default power-on values (PWRMNG) for battery-related functions. It is especially useful for the PCF2131 where the default PWRMNG power-on values disable by default the battery-related functions (contrary to the PCF2127). Signed-off-by: Hugo Villeneuve --- drivers/rtc/rtc-pcf2127.c | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 78141bb06ab0..3bb3ad95c67e 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,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) /* Time and date registers */ #define PCF2127_REG_TIME_BASE 0x03 #define PCF2127_BIT_SC_OSF BIT(7) @@ -1080,6 +1082,57 @@ static int pcf2127_enable_ts(struct device *dev, int ts_id) return ret; } +/* + * By default, do not reconfigure or set default power management mode, + * unless explicitly requested via DT properties: + * battery-switch-over + * battery-low-detect + */ +static int pcf2127_configure_power_management(struct device *dev) +{ + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); + int ret; + u8 pwrmng; + u32 bat_sw_over, bat_low_detect; + + /* + * The PWRMNG field is defined in a peculiar way for PCF21XX + * devices: there is no individual bit defined for the + * battery-switch-over or battery-low-detect functions. + * Therefore, we require that both properties must be defined + * to alter the PWRMNG field. + */ + if (device_property_read_u32(dev, "battery-switch-over", &bat_sw_over)) + return 0; + + if (device_property_read_u32(dev, "battery-low-detect", + &bat_low_detect)) + return 0; + + if (!bat_sw_over) { + /* + * If battery-switch-over is disabled, then the + * battery-low-detect function is always disabled. + */ + pwrmng = BIT(2) | BIT(1) | BIT(0); + } else { + if (bat_low_detect) + pwrmng = 0; + else + pwrmng = BIT(0); + } + + ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3, + PCF2127_CTRL3_PWRMNG_MASK, + FIELD_PREP(PCF2127_CTRL3_PWRMNG_MASK, pwrmng)); + if (ret < 0) { + dev_dbg(dev, "PWRMNG config failed\n"); + return ret; + } + + return 0; +} + /* Route all interrupt sources to INT A pin. */ static int pcf2127_configure_interrupt_pins(struct device *dev) { @@ -1163,6 +1216,12 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap, pcf2127->irq_enabled = true; } + ret = pcf2127_configure_power_management(dev); + if (ret) { + dev_err(dev, "failed to configure power management\n"); + return ret; + } + if (alarm_irq > 0 || device_property_read_bool(dev, "wakeup-source")) { device_init_wakeup(dev, true); set_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features);