linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Heiko Stübner" <heiko@sntech.de>
To: lee@kernel.org, jdelvare@suse.com, dmitry.torokhov@gmail.com,
	pavel@ucw.cz, Guenter Roeck <linux@roeck-us.net>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	ukleinek@debian.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-hwmon@vger.kernel.org,
	linux-input@vger.kernel.org, linux-leds@vger.kernel.org
Subject: Re: [PATCH v4 5/7] hwmon: add driver for the hwmon parts of qnap-mcu devices
Date: Tue, 13 Aug 2024 22:39:38 +0200	[thread overview]
Message-ID: <7628765.mr9Zh2SJbS@diego> (raw)
In-Reply-To: <fd1db8a4-9ea5-49b2-9316-65bf3753a7fa@roeck-us.net>

Hi Guenter,

Am Dienstag, 13. August 2024, 18:03:57 CEST schrieb Guenter Roeck:
> On 8/10/24 11:47, Heiko Stuebner wrote:

> > +static int qnap_mcu_hwmon_set_pwm(struct qnap_mcu_hwmon *hwm, u8 pwm)
> > +{
> > +	const u8 cmd[] = {
> > +		[0] = 0x40, /* @ */
> > +		[1] = 0x46, /* F */
> > +		[2] = 0x57, /* W */
> > +		[3] = 0x30, /* 0 ... fan-id? */
> > +		[4] = pwm
> > +	};
> > +
> > +	/* set the fan pwm */
> > +	return qnap_mcu_exec_with_ack(hwm->mcu, cmd, sizeof(cmd));
> > +}

> > +static int qnap_mcu_hwmon_get_cooling_data(struct device *dev, struct qnap_mcu_hwmon *hwm)
> > +{
> > +	struct fwnode_handle *fwnode;
> > +	int num, i, ret;
> > +
> > +	fwnode = device_get_named_child_node(dev->parent, "fan-0");
> 
> Is the dummy "-0" index mandated somewhere ?

I don't think it is. The node should just begin with "fan" I think.

I've added the -0 because from everything I've seen of the qnap software-
side, the mcu firmware can address multiple fans.

In the original firmware, everything is done in userspace wrt. the MCU,
and the fan commands in their abstraction layer allow for multiple fans.

Also there is that suspicious "0" in the command sequence when
getting/setting the fan pwm. And in the original device config this is
labeled as the first fan.

From everything I've seen, the MCU is not limited to the Rockchip-line
of devices and I do hope others will find this useful in the future,
so adding the "-0" was a better safe than sorry choice.

Because that way adding that theoretical 2nd fan in the future won't
cause too much trouble in the dt-binding.


> I don't care either way, it just seems odd. Either case,
> 
> Acked-by: Guenter Roeck <linux@roeck-us.net>
> 
> > +	if (!fwnode)
> > +		return 0;
> > +
> > +	/* if we found the fan-node, we're keeping it until device-unbind */
> > +	hwm->fan_node = fwnode;
> > +	ret = devm_add_action_or_reset(dev, devm_fan_node_release, hwm);
> > +	if (ret)
> > +		return ret;
> > +
> > +	if (!fwnode_property_present(fwnode, "cooling-levels"))
> > +		return 0;
> > +
> 
> Side note: One could argue that a sub-node with no content does not really
> make sense and should be invalid.

I remember thinking about that, but didn't come to a real decision on my
own, hence left it as it was. So will follow your suggestion :-)


> > +	ret = fwnode_property_count_u32(fwnode, "cooling-levels");
> > +	if (ret <= 0) {
> > +		dev_err(dev, "Failed to count elements in 'cooling-levels'\n");
> > +		return ret ? : -EINVAL;
> > +	}
> > +
> > +	num = ret;
> 
> Another side note: Using ret here isn't necessary. I'd just have used
> 'num' directly.

will do

> 
> > +	hwm->fan_cooling_levels = devm_kcalloc(dev, num, sizeof(u32),
> > +					       GFP_KERNEL);
> > +	if (!hwm->fan_cooling_levels)
> > +		return -ENOMEM;
> > +
> > +	ret = fwnode_property_read_u32_array(fwnode, "cooling-levels",
> > +					     hwm->fan_cooling_levels, num);
> > +	if (ret) {
> > +		dev_err(dev, "Failed to read 'cooling-levels'\n");
> > +		return ret;
> > +	}
> > +
> > +	for (i = 0; i < num; i++) {
> > +		if (hwm->fan_cooling_levels[i] > hwm->pwm_max) {
> > +			dev_err(dev, "fan state[%d]:%d > %d\n", i,
> > +				hwm->fan_cooling_levels[i], hwm->pwm_max);
> > +			return -EINVAL;
> 
> In case you send another version, you might want to consider using dev_err_probe().

ok will do.

I was probably way overthinking if I should not use dev_err_probe in a
function that is not a probe function (though of course part of the probe
process).


Thanks a lot for looking over the code once again
Heiko



  reply	other threads:[~2024-08-13 20:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-10 18:47 [PATCH v4 0/7] Drivers to support the MCU on QNAP NAS devices Heiko Stuebner
2024-08-10 18:47 ` [PATCH v4 1/7] dt-bindings: mfd: add binding for qnap,ts433-mcu devices Heiko Stuebner
2024-08-12 16:11   ` Conor Dooley
2024-08-10 18:47 ` [PATCH v4 2/7] mfd: add base driver for qnap-mcu devices Heiko Stuebner
2024-08-16 17:13   ` Lee Jones
2024-08-18 21:15     ` Heiko Stübner
2024-08-22 10:10       ` Lee Jones
2024-08-10 18:47 ` [PATCH v4 3/7] leds: add driver for LEDs from " Heiko Stuebner
2024-08-10 18:47 ` [PATCH v4 4/7] Input: add driver for the input part of " Heiko Stuebner
2024-08-10 18:47 ` [PATCH v4 5/7] hwmon: add driver for the hwmon parts " Heiko Stuebner
2024-08-13 16:03   ` Guenter Roeck
2024-08-13 20:39     ` Heiko Stübner [this message]
2024-08-10 18:47 ` [PATCH v4 6/7] arm64: dts: rockchip: hook up the MCU on the QNAP TS433 Heiko Stuebner
2024-08-10 18:47 ` [PATCH v4 7/7] arm64: dts: rockchip: set hdd led labels on qnap-ts433 Heiko Stuebner

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=7628765.mr9Zh2SJbS@diego \
    --to=heiko@sntech.de \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux@roeck-us.net \
    --cc=pavel@ucw.cz \
    --cc=robh@kernel.org \
    --cc=ukleinek@debian.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).