linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Yu <a0282524688@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: lee@kernel.org, linus.walleij@linaro.org, brgl@bgdev.pl,
	 andi.shyti@kernel.org, mkl@pengutronix.de,
	mailhol.vincent@wanadoo.fr,  andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com,  kuba@kernel.org,
	pabeni@redhat.com, wim@linux-watchdog.org, jdelvare@suse.com,
	 alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org,
	 linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org,
	 linux-can@vger.kernel.org, netdev@vger.kernel.org,
	 linux-watchdog@vger.kernel.org, linux-hwmon@vger.kernel.org,
	 linux-rtc@vger.kernel.org, linux-usb@vger.kernel.org,
	 Ming Yu <tmyu0@nuvoton.com>
Subject: Re: [PATCH v11 5/7] watchdog: Add Nuvoton NCT6694 WDT support
Date: Mon, 26 May 2025 12:09:05 +0800	[thread overview]
Message-ID: <CAOoeyxWoShYNPtBtvOHeYa439cwF-e0ZXRqyOOPGQ+Vqo0HWig@mail.gmail.com> (raw)
In-Reply-To: <4cc7d25b-35de-4303-94cf-7a8e33bdd246@roeck-us.net>

Dear Guenter,

Thank you for reviewing,

Guenter Roeck <linux@roeck-us.net> 於 2025年5月23日 週五 下午6:02寫道:
>
> > +static unsigned int timeout[NCT6694_WDT_MAX_DEVS] = {
> > +     [0 ... (NCT6694_WDT_MAX_DEVS - 1)] = NCT6694_DEFAULT_TIMEOUT
> > +};
> > +module_param_array(timeout, int, NULL, 0644);
> > +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds");
> > +
> > +static unsigned int pretimeout[NCT6694_WDT_MAX_DEVS] = {
> > +     [0 ... (NCT6694_WDT_MAX_DEVS - 1)] = NCT6694_DEFAULT_PRETIMEOUT
> > +};
> > +module_param_array(pretimeout, int, NULL, 0644);
> > +MODULE_PARM_DESC(pretimeout, "Watchdog pre-timeout in seconds");
> > +
>
> How is this supposed to work if there are multiple NCT6694 in the system ?
>

As far as I can tell, they only share the same default timeout and
pretimeout values, which can be overriden using ioctl for individual
devices.

> > +static bool nowayout = WATCHDOG_NOWAYOUT;
> > +module_param(nowayout, bool, 0);
> > +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
> > +                        __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
...
> > +static int nct6694_wdt_setting(struct watchdog_device *wdev,
> > +                            u32 timeout_val, u8 timeout_act,
> > +                            u32 pretimeout_val, u8 pretimeout_act)
> > +{
> > +     struct nct6694_wdt_data *data = watchdog_get_drvdata(wdev);
> > +     struct nct6694_wdt_setup *setup = &data->msg->setup;
> > +     const struct nct6694_cmd_header cmd_hd = {
> > +             .mod = NCT6694_WDT_MOD,
> > +             .cmd = NCT6694_WDT_SETUP,
> > +             .sel = NCT6694_WDT_SETUP_SEL(data->wdev_idx),
> > +             .len = cpu_to_le16(sizeof(*setup))
> > +     };
> > +     unsigned int timeout_fmt, pretimeout_fmt;
> > +
> > +     guard(mutex)(&data->lock);
> > +
>
> Watchdog drivers are already mutex protected in the watchdog core.
>

Okay, I will remove the mutex in v12.

> > +     if (pretimeout_val == 0)
> > +             pretimeout_act = NCT6694_ACTION_NONE;
> > +
> > +     timeout_fmt = (timeout_val * 1000) | (timeout_act << 24);
> > +     pretimeout_fmt = (pretimeout_val * 1000) | (pretimeout_act << 24);
> > +
> > +     memset(setup, 0, sizeof(*setup));
> > +     setup->timeout = cpu_to_le32(timeout_fmt);
> > +     setup->pretimeout = cpu_to_le32(pretimeout_fmt);
> > +
> > +     return nct6694_write_msg(data->nct6694, &cmd_hd, setup);
> > +}
...
> > +static int nct6694_wdt_probe(struct platform_device *pdev)
> > +{
> > +     struct device *dev = &pdev->dev;
> > +     struct nct6694 *nct6694 = dev_get_drvdata(pdev->dev.parent);
> > +     struct nct6694_wdt_data *data;
> > +     struct watchdog_device *wdev;
> > +     int ret, wdev_idx;
> > +
> > +     data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > +     if (!data)
> > +             return -ENOMEM;
> > +
> > +     data->msg = devm_kzalloc(dev, sizeof(union nct6694_wdt_msg),
> > +                              GFP_KERNEL);
> > +     if (!data->msg)
> > +             return -ENOMEM;
> > +
> > +     wdev_idx = ida_alloc(&nct6694_wdt_ida, GFP_KERNEL);
> > +     if (wdev_idx < 0)
> > +             return wdev_idx;
> > +
>
> Sorry, I fail to understand why this is needed or even makes sense.
> That ID is global, so if there is more than one chip they all get more or
> less random IDs assigned. Why would that be valuable or necessary ?
> If it is just necessary to give the watchdog different IDs, and the
> values don't matter, why not just use pdev->id ?
> I guess that won't work either because it is used as array index below.
> You'll have to find a different means to identify which of the two watchdogs
> is handled by this instance of the driver.
>
> This warrants a detailed explanation why there need to be globally unique IDs
> across multiple chips.
>

I will update the code to use pdev->id as assigned by the MFD in the next patch.

> > +     ret = devm_add_action_or_reset(dev, nct6694_wdt_ida_remove, data);
> > +     if (ret)
> > +             return ret;
> > +
> > +     data->dev = dev;
> > +     data->nct6694 = nct6694;
> > +     data->wdev_idx = wdev_idx;
> > +
> > +     wdev = &data->wdev;
> > +     wdev->info = &nct6694_wdt_info;
> > +     wdev->ops = &nct6694_wdt_ops;
> > +     wdev->timeout = timeout[wdev_idx];
> > +     wdev->pretimeout = pretimeout[wdev_idx];
> > +     if (timeout[wdev_idx] < pretimeout[wdev_idx]) {
>
> Maybe I am missing it, but I don't see where wdev_idx is bound to [0,1].
> It is global. There could be a dozen of those chips connected through
> USB.
>
> > +             dev_warn(data->dev, "pretimeout < timeout. Setting to zero\n");
> > +             wdev->pretimeout = 0;
> > +     }
> > +


Best regards,
Ming

  reply	other threads:[~2025-05-26  4:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-20  2:03 [PATCH v11 0/7] Add Nuvoton NCT6694 MFD drivers a0282524688
2025-05-20  2:03 ` [PATCH v11 1/7] mfd: Add core driver for Nuvoton NCT6694 a0282524688
2025-05-23  9:02   ` Lee Jones
2025-05-26  3:56     ` Ming Yu
2025-05-20  2:03 ` [PATCH v11 2/7] gpio: Add Nuvoton NCT6694 GPIO support a0282524688
2025-05-20  2:03 ` [PATCH v11 3/7] i2c: Add Nuvoton NCT6694 I2C support a0282524688
2025-05-20  2:03 ` [PATCH v11 4/7] can: Add Nuvoton NCT6694 CANFD support a0282524688
2025-05-20  2:03 ` [PATCH v11 5/7] watchdog: Add Nuvoton NCT6694 WDT support a0282524688
2025-05-23 10:02   ` Guenter Roeck
2025-05-26  4:09     ` Ming Yu [this message]
2025-05-20  2:03 ` [PATCH v11 6/7] hwmon: Add Nuvoton NCT6694 HWMON support a0282524688
2025-05-20 21:32   ` kernel test robot
2025-05-23  9:00     ` Lee Jones
2025-05-23  9:44       ` Guenter Roeck
2025-05-20  2:03 ` [PATCH v11 7/7] rtc: Add Nuvoton NCT6694 RTC support a0282524688

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=CAOoeyxWoShYNPtBtvOHeYa439cwF-e0ZXRqyOOPGQ+Vqo0HWig@mail.gmail.com \
    --to=a0282524688@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andi.shyti@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=brgl@bgdev.pl \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jdelvare@suse.com \
    --cc=kuba@kernel.org \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tmyu0@nuvoton.com \
    --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;
as well as URLs for NNTP newsgroup(s).