mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Armin Wolf <W_Armin@gmx.de>
To: "Derek J. Clark" <derekjohn.clark@gmail.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Hans de Goede" <hansg@kernel.org>
Cc: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Alok Tiwari <alok.a.tiwari@oracle.com>,
	David Box <david.e.box@linux.intel.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH v3 2/4] platform/x86: (ayn-ec) Add Temperature Sensors
Date: Sun, 27 Jul 2025 01:37:16 +0200	[thread overview]
Message-ID: <edc7d119-ee64-489b-ab1d-9577f007e918@gmx.de> (raw)
In-Reply-To: <20250726204041.516440-3-derekjohn.clark@gmail.com>

Am 26.07.25 um 22:40 schrieb Derek J. Clark:

> 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@gmail.com>
> ---
>   drivers/platform/x86/ayn-ec.c | 88 ++++++++++++++++++++++++++++++++++-
>   1 file changed, 86 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/ayn-ec.c b/drivers/platform/x86/ayn-ec.c
> index 8bd3ed1c69eb..466cc33adcb0 100644
> --- a/drivers/platform/x86/ayn-ec.c
> +++ b/drivers/platform/x86/ayn-ec.c
> @@ -61,6 +61,14 @@
>   #define HWMON_PWM_FAN_MODE_AUTO	0x02
>   #define HWMON_PWM_FAN_MODE_EC_CURVE	0x03
>   
> +/* EC Temperature 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 */
> +
> +

Please avoid multiple blank lines.

>   /* Handle ACPI lock mechanism */
>   #define ACPI_LOCK_DELAY_MS 500
>   
> @@ -81,8 +89,19 @@ struct ayn_device {
>   	u32 ayn_lock; /* ACPI EC Lock */
>   } drvdata;
>   
> -/* Handle ACPI lock mechanism */
> -#define ACPI_LOCK_DELAY_MS 500
> +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 },
> +	{}
> +};

Please declare this array as const.

>   
>   static bool lock_global_acpi_lock(void)
>   {
> @@ -428,6 +447,61 @@ 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 write the result into.
> + *
> + * 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;

Please use MILLIDEGREE_PER_DEGREE from linux/units.h here.

> +
> +	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 = 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,
> @@ -439,6 +513,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,

Please use the standard hwmon API for exposing those temperature sensors.

Thanks,
Armin Wolf

>   	NULL,
>   };
>   

  reply	other threads:[~2025-07-26 23:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-26 20:40 [PATCH v3 0/4] Add AYN EC Platform Driver Derek J. Clark
2025-07-26 20:40 ` [PATCH v3 1/4] platform/x86: (ayn-ec) Add PWM Fan HWMON Interface Derek J. Clark
2025-07-26 23:32   ` Armin Wolf
2025-07-29  2:58     ` Derek John Clark
2025-07-29  4:09       ` Armin Wolf
2025-08-10 22:27         ` Derek John Clark
2025-08-11  8:38           ` Armin Wolf
2025-07-28 16:31   ` kernel test robot
2025-07-29  3:39     ` Randy Dunlap
2025-07-28 21:34   ` kernel test robot
2025-07-26 20:40 ` [PATCH v3 2/4] platform/x86: (ayn-ec) Add Temperature Sensors Derek J. Clark
2025-07-26 23:37   ` Armin Wolf [this message]
2025-07-29  3:02     ` Derek John Clark
2025-07-26 20:40 ` [PATCH v3 3/4] platform/x86: (ayn-ec) Add RGB Interface Derek J. Clark
2025-07-26 23:58   ` Armin Wolf
2025-07-29  3:25     ` Derek John Clark
2025-07-29  4:18       ` Armin Wolf
2025-07-28 23:36   ` kernel test robot
2025-07-26 20:40 ` [PATCH v3 4/4] platform/x86: (ayn-ec) Add AYN EC Platform Documentation Derek J. Clark
2025-07-27  0:03   ` Armin Wolf
2025-07-29  3:26     ` Derek John Clark

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=edc7d119-ee64-489b-ab1d-9577f007e918@gmx.de \
    --to=w_armin@gmx.de \
    --cc=alok.a.tiwari@oracle.com \
    --cc=david.e.box@linux.intel.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jdelvare@suse.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=platform-driver-x86@vger.kernel.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

all inboxes | Powered by JetHome®