Linux RTC
 help / color / mirror / Atom feed
From: Stefan Kerkmann <s.kerkmann@pengutronix.de>
To: Hugo Villeneuve <hugo@hugovil.com>, alexandre.belloni@bootlin.com
Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
	bruno.thomsen@gmail.com, giampiero@sferalabs.cc,
	p.rosenberger@kunbus.com, antonio@amsobr.com,
	Hugo Villeneuve <hvilleneuve@dimonoff.com>
Subject: Re: [PATCH 2/4] rtc: pcf2127: add pcf2127_pwrmng_get/set
Date: Thu, 6 Aug 2026 14:53:27 +0200	[thread overview]
Message-ID: <4b1effd0-3081-4d37-aaf2-3dad8788faff@pengutronix.de> (raw)
In-Reply-To: <20260311200237.3531981-3-hugo@hugovil.com>



On 3/11/26 21:02, Hugo Villeneuve wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> 
> Add common functions to get/set the pwrmng field in the CTRL3 register,
> used by pcf2127_param_get() and pcf2127_param_set().
> 
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
> ---
> These functions will also be used in the following patch
> to add battery low detection.
> ---
>   drivers/rtc/rtc-pcf2127.c | 42 +++++++++++++++++++++++++++------------
>   1 file changed, 29 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
> index e2e9746027348..0605295026564 100644
> --- a/drivers/rtc/rtc-pcf2127.c
> +++ b/drivers/rtc/rtc-pcf2127.c
> @@ -213,6 +213,30 @@ struct pcf2127 {
>   	bool ts_valid[PCF2127_MAX_TS_SUPPORTED];  /* Timestamp valid indication. */
>   };
>   
> +static int pcf2127_pwrmng_get(struct device *dev, u8 *pwrmng)
> +{
> +	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
> +	u32 value;
> +	int ret;
> +
> +	ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
> +	if (ret < 0)
> +		return ret;
> +
> +	*pwrmng = FIELD_GET(PCF2127_CTRL3_PM, value);
> +
> +	return 0;
> +}
> +
> +static int pcf2127_pwrmng_set(struct device *dev, u8 pwrmng)
> +{
> +	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
> +
> +	return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
> +				  PCF2127_CTRL3_PM,
> +				  FIELD_PREP(PCF2127_CTRL3_PM, pwrmng));
> +}
> +
>   /*
>    * In the routines that deal directly with the pcf2127 hardware, we use
>    * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
> @@ -337,18 +361,15 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
>   
>   static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
>   {
> -	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
> -	u32 value;
> +	u8 value;
>   	int ret;
>   
>   	switch (param->param) {
>   	case RTC_PARAM_BACKUP_SWITCH_MODE:
> -		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
> +		ret = pcf2127_pwrmng_get(dev, &value);
>   		if (ret < 0)
>   			return ret;
>   
> -		value = FIELD_GET(PCF2127_CTRL3_PM, value);
> -
>   		if (value < 0x3)
>   			param->uvalue = RTC_BSM_LEVEL;
>   		else if (value < 0x6)
> @@ -367,19 +388,16 @@ static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
>   
>   static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
>   {
> -	struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
>   	u8 mode = 0;
> -	u32 value;
> +	u8 value;
>   	int ret;
>   
>   	switch (param->param) {
>   	case RTC_PARAM_BACKUP_SWITCH_MODE:
> -		ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
> +		ret = pcf2127_pwrmng_get(dev, &value);
>   		if (ret < 0)
>   			return ret;
>   
> -		value = FIELD_GET(PCF2127_CTRL3_PM, value);
> -
>   		if (value > 5)
>   			value -= 5;
>   		else if (value > 2)
> @@ -400,9 +418,7 @@ static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
>   			return -EINVAL;
>   		}
>   
> -		return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
> -					  PCF2127_CTRL3_PM,
> -					  FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
> +		return pcf2127_pwrmng_set(dev, mode + value);
>   
>   	default:
>   		return -EINVAL;

Reviewed-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>

-- 
Pengutronix e.K.                       | Stefan Kerkmann             |
Steuerwalder Str. 21                   | https://www.pengutronix.de/ |
31137 Hildesheim, Germany              | Phone: +49-5121-206917-128  |
Amtsgericht Hildesheim, HRA 2686       | Fax:   +49-5121-206917-9    |


  reply	other threads:[~2026-08-06 12:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 20:02 [PATCH 0/4] rtc: pcf2127: add support for battery low voltage detection Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 1/4] rtc: pcf2127: remove redundant break statement in switch-case Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 2/4] rtc: pcf2127: add pcf2127_pwrmng_get/set Hugo Villeneuve
2026-08-06 12:53   ` Stefan Kerkmann [this message]
2026-03-11 20:02 ` [PATCH 3/4] rtc: add battery low voltage detection feature Hugo Villeneuve
2026-08-06 12:55   ` Stefan Kerkmann
2026-03-11 20:02 ` [PATCH 4/4] rtc: pcf2127: support battery low voltage detection function Hugo Villeneuve
2026-08-06 12:55   ` Stefan Kerkmann
2026-07-29 15:18 ` [PATCH 0/4] rtc: pcf2127: add support for battery low voltage detection Stefan Kerkmann
2026-08-25 12:59   ` Hugo Villeneuve
2026-08-25  7:31 ` Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b1effd0-3081-4d37-aaf2-3dad8788faff@pengutronix.de \
    --to=s.kerkmann@pengutronix.de \
    --cc=alexandre.belloni@bootlin.com \
    --cc=antonio@amsobr.com \
    --cc=bruno.thomsen@gmail.com \
    --cc=giampiero@sferalabs.cc \
    --cc=hugo@hugovil.com \
    --cc=hvilleneuve@dimonoff.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=p.rosenberger@kunbus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox