Re: [PATCH v2 03/22] rtc: pm8xxx: use regmap_update_bits()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/2/23 07:54, Johan Hovold wrote:
> Switch to using regmap_update_bits() instead of open coding
> read-modify-write accesses.
> 
> Signed-off-by: Johan Hovold <johan+linaro@xxxxxxxxxx>
> ---
>  drivers/rtc/rtc-pm8xxx.c | 87 ++++++++++------------------------------
>  1 file changed, 22 insertions(+), 65 deletions(-)

Reviewed-by: David Collins <quic_collinsd@xxxxxxxxxxx>


> diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c
> index f49bda999e02..8c2847ac64f4 100644
> --- a/drivers/rtc/rtc-pm8xxx.c
> +++ b/drivers/rtc/rtc-pm8xxx.c
> @@ -78,10 +78,10 @@ static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  {
>  	int rc, i;
>  	unsigned long secs, irq_flags;
> -	u8 value[NUM_8_BIT_RTC_REGS], alarm_enabled = 0, rtc_disabled = 0;
> -	unsigned int ctrl_reg, rtc_ctrl_reg;
>  	struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
>  	const struct pm8xxx_rtc_regs *regs = rtc_dd->regs;
> +	u8 value[NUM_8_BIT_RTC_REGS];
> +	bool alarm_enabled;
>  
>  	if (!rtc_dd->allow_set_time)
>  		return -ENODEV;
> @@ -97,31 +97,16 @@ static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
>  
>  	spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
>  
> -	rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg);
> +	rc = regmap_update_bits_check(rtc_dd->regmap, regs->alarm_ctrl,
> +				      regs->alarm_en, 0, &alarm_enabled);
>  	if (rc)
>  		goto rtc_rw_fail;
>  
> -	if (ctrl_reg & regs->alarm_en) {
> -		alarm_enabled = 1;
> -		ctrl_reg &= ~regs->alarm_en;
> -		rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg);
> -		if (rc)
> -			goto rtc_rw_fail;
> -	}
> -

I like this usage of regmap_update_bits_check().  It is a great helper
to use in this situation.  It really helps to simplify the logic.

Take care,
David




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux