[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z9jTDJqkaID75OU-@google.com>
Date: Tue, 18 Mar 2025 09:57:32 +0800
From: "Sung-Chi, Li" <lschyi@...omium.org>
To: Thomas Weißschuh <thomas@...ssschuh.net>
Cc: Jean Delvare <jdelvare@...e.com>, Guenter Roeck <linux@...ck-us.net>,
Benson Leung <bleung@...omium.org>,
Guenter Roeck <groeck@...omium.org>,
chrome-platform@...ts.linux.dev, linux-hwmon@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] hwmon: (cros_ec) Add set and get target fan RPM
function
On Mon, Mar 17, 2025 at 06:46:32PM +0100, Thomas Weißschuh wrote:
> On 2025-03-17 14:40:26+0800, Sung-Chi Li wrote:
> > The ChromeOS embedded controller (EC) supports closed loop fan speed
> > control, so add the fan target attribute under hwmon framework, such
> > that kernel can expose reading and specifying the desired fan RPM for
> > fans connected to the EC.
> >
> > When probing the cros_ec hwmon module, we also check the supported
> > command version of setting target fan RPM. This commit implements the
> > version 0 of getting the target fan RPM, which can only read the target
> > RPM of the first fan. This commit also implements the version 0 and 1 of
> > setting the target fan RPM, where the version 0 only supports setting
> > all fan to the same RPM, while version 1 supports setting different RPM
> > to each fan respectively.
>
> Can you explain why this set of command compatibility was chosen?
> I would have expected to fully support the v1 commands and completely
> skip v0.
>
I thought it would be better to support all current existing functionality.
Currently, there are v0 and v1 for setting, and only v0 for getting. However, I
think we will only care about v1 for setting (there is only v0 for getting), so
combine with another comment for the importance of v0, I think I'll only support
setting for v1.
> > Signed-off-by: Sung-Chi Li <lschyi@...omium.org>
> > ---
> > ChromeOS embedded controller (EC) supports closed-loop fan control. We
> > anticipate to have the fan related control from the kernel side, so this
> > series register the HWMON_F_TARGET attribute, and implement the read and
> > write function for setting/reading the target fan RPM from the EC side.
> > ---
> > Changes in v2:
> >
> > - Squash the read, write, and register of fan target attribute to 1
> > commit, as they are the same topic.
> > - Probe the supported command version from EC for setting the target fan
> > RPM, and perform the set fan target RPM based on the supported
> > version.
> > - Update the used variable type to kernel types (i.e., u32).
> > - Link to v1: https://lore.kernel.org/r/20250313-extend_ec_hwmon_fan-v1-0-5c566776f2c4@chromium.org
> > ---
> > drivers/hwmon/cros_ec_hwmon.c | 130 ++++++++++++++++++++++++++++++++++++++++--
> > 1 file changed, 125 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
> > index 9991c3fa020ac859cbbff29dfb669e53248df885..b118a355f67d7238a6f596cf01a49d5b621b31d6 100644
> > --- a/drivers/hwmon/cros_ec_hwmon.c
> > +++ b/drivers/hwmon/cros_ec_hwmon.c
> > @@ -21,6 +21,12 @@ struct cros_ec_hwmon_priv {
> > struct cros_ec_device *cros_ec;
> > const char *temp_sensor_names[EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES];
> > u8 usable_fans;
> > + int set_fan_target_rpm_version;
> > +};
> > +
> > +union ec_params_pwm_set_fan_target_rpm {
> > + struct ec_params_pwm_set_fan_target_rpm_v0 v0;
> > + struct ec_params_pwm_set_fan_target_rpm_v1 v1;
> > };
>
> No need to give this union a name. It is only used once.
> It doesn't even have to be a union but can be two dedicated on-stack
> variables.
>
Only v1 is supported, so I'll remove this union, and there will only be 1
variable on-stack variable.
> >
> > static int cros_ec_hwmon_read_fan_speed(struct cros_ec_device *cros_ec, u8 index, u16 *speed)
> > @@ -36,6 +42,25 @@ static int cros_ec_hwmon_read_fan_speed(struct cros_ec_device *cros_ec, u8 index
> > return 0;
> > }
> >
> > +static int cros_ec_hwmon_read_fan_target(struct cros_ec_device *cros_ec,
> > + u8 index, u32 *speed)
> > +{
> > + struct ec_response_pwm_get_fan_rpm r;
> > + int ret;
> > +
> > + // Currently only supports reading the first fan.
> > + if (index > 0)
> > + return -EOPNOTSUPP;
>
> This needs to be checked in is_visible(), not here.
> (Or only support v1 and not have the restriction)
>
Thank you, I was not sure about whether to do it in `is_visible` or the read
function. Please note that there is no v1 for getting the specific fan target
RPM value.
> > + return 0;
> > +}
> > +
> > static int cros_ec_hwmon_read_temp(struct cros_ec_device *cros_ec, u8 index, u8 *temp)
> > {
> > unsigned int offset;
> > @@ -52,6 +77,49 @@ static int cros_ec_hwmon_read_temp(struct cros_ec_device *cros_ec, u8 index, u8
> > return 0;
> > }
> >
> > +static int cros_ec_hwmon_set_fan_rpm(struct cros_ec_device *cros_ec,
> > + int version, u8 index, u16 val)
> > +{
> > + union ec_params_pwm_set_fan_target_rpm req;
> > + int req_size;
> > + int ret;
> > +
> > + if (version == 0) {
> > + if (index != 0)
> > + dev_warn(
> > + cros_ec->dev,
> > + "v0 only supports setting all fan to same RPM (cannot just set idx %d), set all to %d\n",
> > + index, val);
>
> How important is v0 in general?
>
I think v1 covers all functionality for v0, and the intention for having this
functionality is to have more control on each fan, so v0 is not that importatn.
Along with the comments above, I can drop the support for v0.
> > + if (ret < 0) {
> > + dev_err(priv->cros_ec->dev,
> > + "error getting target fan RPM set command version: %d\n", ret);
> > + return ret;
> > + }
>
> If neither v0 nor v1 are supported, this will completely prevent the
> driver from being probed. Is this intentional?
>
Supposedly one of the version should be supported. However, with your reminder,
I think missing this functionality should not block this module. As such, I will
only log an warning here.
Powered by blists - more mailing lists