Linux Watchdog driver development
 help / color / mirror / Atom feed
From: Rustam Adilov <adilov@disroot.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Sander Vanheule <sander@svanheule.net>,
	Wim Van Sebroeck <wim@linux-watchdog.org>,
	linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] watchdog: realtek-otto: Change to use regmap API
Date: Tue, 26 May 2026 20:23:53 +0000	[thread overview]
Message-ID: <b4b09be5ff456a23d15a5af3237b9b46@disroot.org> (raw)
In-Reply-To: <1d5091ff-e497-4b5a-a906-7cc02c31c4c0@roeck-us.net>

On 2026-05-19 19:25, Guenter Roeck wrote:
> On 5/19/26 12:00, Sander Vanheule wrote:
>> Hi Rustam,
>> 
>> On Tue, 2026-05-19 at 23:23 +0500, Rustam Adilov wrote:
>> [...]
>>> @@ -74,24 +75,17 @@ struct otto_wdt_ctrl {
>>>   static int otto_wdt_start(struct watchdog_device *wdev)
>>>   {
>>>   	struct otto_wdt_ctrl *ctrl = watchdog_get_drvdata(wdev);
>>> -	u32 v;
>>> -
>>> -	v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
>>> -	v |= OTTO_WDT_CTRL_ENABLE;
>>> -	iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
>>>   +	regmap_set_bits(ctrl->regmap, OTTO_WDT_REG_CTRL,
>>> OTTO_WDT_CTRL_ENABLE);
>>>   	return 0;
>> 
>> iowrite32() doesn't return anything, but regmap_set_bits() does.
>> 
>> You can turn this into
>>      return regmap_set_bits(...);
>> 
>>>   }
>>>     static int otto_wdt_stop(struct watchdog_device *wdev)
>>>   {
>>>   	struct otto_wdt_ctrl *ctrl = watchdog_get_drvdata(wdev);
>>> -	u32 v;
>>> -
>>> -	v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
>>> -	v &= ~OTTO_WDT_CTRL_ENABLE;
>>> -	iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
>>>   +	regmap_clear_bits(ctrl->regmap, OTTO_WDT_REG_CTRL,
>>> +			  OTTO_WDT_CTRL_ENABLE);
>>>   	return 0;
>> 
>> Same as above.
>> This is probably short enough to keep is on one line? (< 100 characters)
>> 
>>>   }
>>>   @@ -99,8 +93,7 @@ static int otto_wdt_ping(struct watchdog_device *wdev)
>>>   {
>>>   	struct otto_wdt_ctrl *ctrl = watchdog_get_drvdata(wdev);
>>>   -	iowrite32(OTTO_WDT_CNTR_PING, ctrl->base + OTTO_WDT_REG_CNTR);
>>> -
>>> +	regmap_write(ctrl->regmap, OTTO_WDT_REG_CNTR, OTTO_WDT_CNTR_PING);
>>>   	return 0;
>> 
>> Same as above.
>> 
>>>   }
>>>   @@ -126,7 +119,7 @@ static int otto_wdt_determine_timeouts(struct
>>> watchdog_device *wdev, unsigned in
>>>   	unsigned int total_ticks;
>>>   	unsigned int prescale;
>>>   	unsigned int tick_ms;
>>> -	u32 v;
>>> +	u32 mask, val;
>>>     	do {
>>>   		prescale = prescale_next;
>>> @@ -142,14 +135,11 @@ static int otto_wdt_determine_timeouts(struct
>>> watchdog_device *wdev, unsigned in
>>>   	} while (phase1_ticks > OTTO_WDT_PHASE_TICKS_MAX
>>>   		|| phase2_ticks > OTTO_WDT_PHASE_TICKS_MAX);
>>>   -	v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
>>> -
>>> -	v &= ~(OTTO_WDT_CTRL_PRESCALE | OTTO_WDT_CTRL_PHASE1 |
>>> OTTO_WDT_CTRL_PHASE2);
>>> -	v |= FIELD_PREP(OTTO_WDT_CTRL_PHASE1, phase1_ticks - 1);
>>> -	v |= FIELD_PREP(OTTO_WDT_CTRL_PHASE2, phase2_ticks - 1);
>>> -	v |= FIELD_PREP(OTTO_WDT_CTRL_PRESCALE, prescale);
>>> -
>>> -	iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
>>> +	mask = OTTO_WDT_CTRL_PRESCALE | OTTO_WDT_CTRL_PHASE1 |
>>> OTTO_WDT_CTRL_PHASE2;
>>> +	val = FIELD_PREP(OTTO_WDT_CTRL_PHASE1, phase1_ticks - 1);
>>> +	val |= FIELD_PREP(OTTO_WDT_CTRL_PHASE2, phase2_ticks - 1);
>>> +	val |= FIELD_PREP(OTTO_WDT_CTRL_PRESCALE, prescale);
>>> +	regmap_update_bits(ctrl->regmap, OTTO_WDT_REG_CTRL, mask, val);
>> 
>> To be consistent, you would also need to propagate the result of
>> regmap_update_bits() if it's an error. Same for the other regmap_*() calls.
>> 
> 
> I am now inclined to reject this patch. regmap mmio never returns errors
> unless it is associated with clocks, and now useless error handling is
> requested. That defeats the idea of simplifying the code. Instead, its
> complexity is increased by adding unnecessary error handling.
> 
> So this is now a NACK if unnecessary error handling is indeed added,
> unless someone convinces me that this would add some benefits that I
> am unable to see.
> 
> Guenter

Hello,
Sorry for taking so long to reply.

Just to be clear, i didn't have a chance to do anything about the requested
error handling. Looking at the existing watchdog drivers that use regmap, some
implement the error handling and some don't and that's a bit confusing to me.
I would like to see if Sander has something more to say here.

While i am here, this whole patch is not specifically for simplifying the code.
It is also about fixing an issue where the CONFIG_SWAP_IO_SPACE is enabled. It
makes it so that ioread32 and iowrite32 perform byte swap and since this driver
expects them not to byte swap, things break. RTL9607C is expected to have it for
USB support.
Alternatively i could have used __raw_readl and __raw_writel instead of regmap but
i felt like regmap would be more accepted.

Best,
Rustam

      reply	other threads:[~2026-05-26 20:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 18:23 [PATCH v2 0/1] watchdog: realtek-otto: Make use of regmap API Rustam Adilov
2026-05-19 18:23 ` [PATCH v2 1/1] watchdog: realtek-otto: Change to use " Rustam Adilov
2026-05-19 18:56   ` sashiko-bot
2026-05-19 19:00   ` Sander Vanheule
2026-05-19 19:25     ` Guenter Roeck
2026-05-26 20:23       ` Rustam Adilov [this message]

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=b4b09be5ff456a23d15a5af3237b9b46@disroot.org \
    --to=adilov@disroot.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=sander@svanheule.net \
    --cc=wim@linux-watchdog.org \
    /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