[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6f7lr653uffhzenm5fgl5cghrsscvqpcpoxyu6qmq6xzlia3h4@fa4ucvpnqwdg>
Date: Sat, 26 Jul 2025 08:50:24 -0700
From: David Box <david.e.box@...ux.intel.com>
To: "Derek J. Clark" <derekjohn.clark@...il.com>
Cc: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Hans de Goede <hansg@...nel.org>, Jean Delvare <jdelvare@...e.com>,
Guenter Roeck <linux@...ck-us.net>, platform-driver-x86@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-hwmon@...r.kernel.org
Subject: Re: [PATCH 2/4] platform/x86: (ayn-ec) Add Temperature Sensors
On Thu, Jul 24, 2025 at 05:45:31PM -0700, Derek J. Clark wrote:
> Adds temperature sensors to the ayn-ec hwmon interface. These read-only
> values include Battery, Motherboard, Charger IC, vCore, and CPU Core, as
> well as labels for each entry. The temperature values provided by the EC
> are whole numbers in degrees Celsius. As hwmon expects millidegrees, we
> scale the raw value up.
>
> `sensors` output after this patch is applied:
> aynec-isa-0000
> Adapter: ISA adapter
> fan1: 1876 RPM
> Battery: +29.0°C
> Motherboard: +30.0°C
> Charger IC: +30.0°C
> vCore: +36.0°C
> CPU Core: +48.0°C
>
> Signed-off-by: Derek J. Clark <derekjohn.clark@...il.com>
> ---
> drivers/platform/x86/ayn-ec.c | 89 +++++++++++++++++++++++++++++++++++
> 1 file changed, 89 insertions(+)
>
> diff --git a/drivers/platform/x86/ayn-ec.c b/drivers/platform/x86/ayn-ec.c
> index 06f232bd10fa..b2054dc2358a 100644
> --- a/drivers/platform/x86/ayn-ec.c
> +++ b/drivers/platform/x86/ayn-ec.c
> @@ -50,8 +50,16 @@
> #define AYN_SENSOR_PWM_FAN_TEMP_4_REG 0x19
> #define AYN_SENSOR_PWM_FAN_TEMP_5_REG 0x1B
>
> +/* EC Teperature Sensors */
> +#define AYN_SENSOR_BAT_TEMP_REG 0x04 /* Battery */
> +#define AYN_SENSOR_CHARGE_TEMP_REG 0x07 /* Charger IC */
> +#define AYN_SENSOR_MB_TEMP_REG 0x05 /* Motherboard */
> +#define AYN_SENSOR_PROC_TEMP_REG 0x09 /* CPU Core */
> +#define AYN_SENSOR_VCORE_TEMP_REG 0x08 /* vCore */
> +
> /* Handle ACPI lock mechanism */
> #define ACPI_LOCK_DELAY_MS 500
> +
> enum ayn_model {
> ayn_loki_max = 1,
> ayn_loki_minipro,
> @@ -63,6 +71,20 @@ struct ayn_device {
> u32 ayn_lock; /* ACPI EC Lock */
> } drvdata;
>
> +struct thermal_sensor {
> + char *name;
> + int reg;
> +};
> +
> +static struct thermal_sensor thermal_sensors[] = {
> + { "Battery", AYN_SENSOR_BAT_TEMP_REG },
> + { "Motherboard", AYN_SENSOR_MB_TEMP_REG },
> + { "Charger IC", AYN_SENSOR_CHARGE_TEMP_REG },
> + { "vCore", AYN_SENSOR_VCORE_TEMP_REG },
> + { "CPU Core", AYN_SENSOR_PROC_TEMP_REG },
> + {}
> +};
Use tabs to align the constants for better readability.
David
> +
> /* Handle ACPI lock mechanism */
> #define ACPI_LOCK_DELAY_MS 500
>
> @@ -503,6 +525,63 @@ static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point3_temp, pwm_curve, 7);
> static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point4_temp, pwm_curve, 8);
> static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point5_temp, pwm_curve, 9);
>
> +/**
> + * thermal_sensor_show() - Read a thermal sensor attribute value.
> + *
> + * @dev: The attribute's parent device.
> + * @attr: The attribute to read.
> + * @buf: Buffer to read to.
> + *
> + * Return: Number of bytes read, or an error.
> + */
> +static ssize_t thermal_sensor_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + long ret, val;
> + int i;
> +
> + i = to_sensor_dev_attr(attr)->index;
> +
> + ret = read_from_ec(thermal_sensors[i].reg, 1, &val);
> + if (ret)
> + return ret;
> +
> + val = val * 1000L;
> +
> + return sysfs_emit(buf, "%ld\n", val);
> +}
> +
> +/**
> + * thermal_sensor_label_show() - Read a thermal sensor attribute label.
> + *
> + * @dev: The attribute's parent device.
> + * @attr: The attribute to read.
> + * @buf: Buffer to read to.
> + *
> + * Return: Number of bytes read, or an error.
> + */
> +static ssize_t thermal_sensor_label_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + int i;
> +
> + i = to_sensor_dev_attr(attr)->index;
> +
> + return sysfs_emit(buf, "%s\n", thermal_sensors[i].name);
> +}
> +
> +static SENSOR_DEVICE_ATTR_RO(temp1_input, thermal_sensor, 0);
> +static SENSOR_DEVICE_ATTR_RO(temp2_input, thermal_sensor, 1);
> +static SENSOR_DEVICE_ATTR_RO(temp3_input, thermal_sensor, 2);
> +static SENSOR_DEVICE_ATTR_RO(temp4_input, thermal_sensor, 3);
> +static SENSOR_DEVICE_ATTR_RO(temp5_input, thermal_sensor, 4);
> +static SENSOR_DEVICE_ATTR_RO(temp1_label, thermal_sensor_label, 0);
> +static SENSOR_DEVICE_ATTR_RO(temp2_label, thermal_sensor_label, 1);
> +static SENSOR_DEVICE_ATTR_RO(temp3_label, thermal_sensor_label, 2);
> +static SENSOR_DEVICE_ATTR_RO(temp4_label, thermal_sensor_label, 3);
> +static SENSOR_DEVICE_ATTR_RO(temp5_label, thermal_sensor_label, 4);
> +
> static struct attribute *ayn_sensors_attrs[] = {
> &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
> &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
> @@ -514,6 +593,16 @@ static struct attribute *ayn_sensors_attrs[] = {
> &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
> &sensor_dev_attr_pwm1_auto_point5_pwm.dev_attr.attr,
> &sensor_dev_attr_pwm1_auto_point5_temp.dev_attr.attr,
> + &sensor_dev_attr_temp1_input.dev_attr.attr,
> + &sensor_dev_attr_temp1_label.dev_attr.attr,
> + &sensor_dev_attr_temp2_input.dev_attr.attr,
> + &sensor_dev_attr_temp2_label.dev_attr.attr,
> + &sensor_dev_attr_temp3_input.dev_attr.attr,
> + &sensor_dev_attr_temp3_label.dev_attr.attr,
> + &sensor_dev_attr_temp4_input.dev_attr.attr,
> + &sensor_dev_attr_temp4_label.dev_attr.attr,
> + &sensor_dev_attr_temp5_input.dev_attr.attr,
> + &sensor_dev_attr_temp5_label.dev_attr.attr,
> NULL,
> };
>
> --
> 2.50.0
>
>
Powered by blists - more mailing lists