[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <cf3ef6ff-632e-4fcf-9c13-1425e444a0e5@roeck-us.net>
Date: Thu, 26 Dec 2024 13:04:07 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: tjakobi@...h.uni-bielefeld.de
Cc: Derek John Clark <derekjohn.clark@...il.com>,
Joaquín Ignacio Aramendía <samsagax@...il.com>,
Jean Delvare <jdelvare@...e.com>, linux-hwmon@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/4] hwmon: (oxp-sensors) Separate logic from
device-specific data
On Thu, Dec 26, 2024 at 06:00:16PM +0100, tjakobi@...h.uni-bielefeld.de wrote:
> From: Tobias Jakobi <tjakobi@...h.uni-bielefeld.de>
>
> We currently have large switch-statements in all functions that
> write to EC registers, even though the bulk of the supported
> devices functions more or less the same.
>
> Factor the device-specific data out into a struct oxp_config. This
> only leaves logic in the corresponding functions and should make
> adding future devices much easier and less error-prone.
>
> Also introduce struct oxp_data which is going to be used in a
> later commit to cache device state.
>
> Signed-off-by: Tobias Jakobi <tjakobi@...h.uni-bielefeld.de>
> ---
> drivers/hwmon/oxp-sensors.c | 517 +++++++++++++++---------------------
> 1 file changed, 215 insertions(+), 302 deletions(-)
>
>
...
> -static int oxp_pwm_disable(void)
> +static int oxp_pwm_disable(const struct oxp_config *config)
> {
> - switch (board) {
> - case orange_pi_neo:
> - return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
> - case aok_zoe_a1:
> - case aya_neo_2:
> - case aya_neo_air:
> - case aya_neo_air_1s:
> - case aya_neo_air_plus_mendo:
> - case aya_neo_air_pro:
> - case aya_neo_flip:
> - case aya_neo_geek:
> - case aya_neo_kun:
> - case oxp_2:
> - case oxp_fly:
> - case oxp_mini_amd:
> - case oxp_mini_amd_a07:
> - case oxp_mini_amd_pro:
> - case oxp_x1:
> - return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
> - default:
> - return -EINVAL;
> - }
> + if (test_bit(OXP_FEATURE_PWM, &config->features))
> + return write_to_ec(config->sensor_pwm_enable_reg, PWM_MODE_AUTO);
> +
This and all the other feature checks are completely wrong.
Those checks whould happen once in the is_visible functions,
and there should not be any such runtime checks. If a feature
is not available, the associated attributes should not be created
in the first place.
If such checks happen in the current code, that should be fixed
in the is_visible functions. Any existing runtime feature checks
should be removed.
Guenter
Powered by blists - more mailing lists