linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ALOK TIWARI <alok.a.tiwari@oracle.com>
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>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 1/4] platform/x86: (ayn-ec) Add PWM Fan HWMON Interface
Date: Fri, 25 Jul 2025 20:38:42 +0530	[thread overview]
Message-ID: <e3ab1337-2409-4828-aea7-4c71f8e9197d@oracle.com> (raw)
In-Reply-To: <20250725004533.63537-1-derekjohn.clark@gmail.com>


> +/*
> + * Platform driver for Ayn x86 Handhelds.
> + *
> + * Implements multiple attributes provided by the EC. Fan reading and control,
> + * as well as temperature sensor readings are exposed via hwmon sysfs. EC RGB
> + * control is exposed via an led-class-multicolor interface.
> + *
> + * Fan control is provided via a pwm interface in the range [0-255]. Ayn use
> + * [0-128] as the range in the EC, the written value is scaled to accommodate.
> + * The EC also provides a configurable fan curve with five set points that
> + * associate a temperature in Celcius [0-100] with a fan speed [0-128]. The
> + * auto_point fan speeds are also scaled from the range [0-255]. Temperature
> + * readings are scaled from degrees to millidegrees when read.
> + *
> + * RGB control is provided using 4 registers. One each for the colors red,
> + * green, and blue are [0-255]. There is also a effect register that takes
> + * switches between an EC controlled breathing that cycles through all colors
> + * and fades in/out, and manual, which enables setting a user defined color.
> + *
> + * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> + */
> +
[clip]
> +		if (val < 0 || val > 255)
> +			return -EINVAL;
> +		val = val >> 1; /* Max EC value is 128, scale from 255 */
> +		break;
> +	case 5:
> +	case 6:
> +	case 7:
> +	case 8:
> +	case 9:
> +		if (val < 0 || val > 100)
> +			return -EINVAL;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	ret = write_to_ec(reg, val);
> +	if (ret)
> +		return ret;
> +	return count;
> +}
> +
> +/**
> + * pwm_curve_show() - Read a fan curve speed or temperature value.
> + *
> + * @dev: The attribute's parent device.
> + * @attr: The attribute to read.
> + * @buf: Buffer to read to.

"to read to" is awkward
Output buffer.

> + *
> + * Return: Number of bytes read, or an error.
> + */
> +static ssize_t pwm_curve_show(struct device *dev, struct device_attribute *attr,
> +			      char *buf)
> +{
> +	int i, ret;
> +	long val;
> +	u8 reg;
> +
> +	i = to_sensor_dev_attr(attr)->index;
> +	switch (i) {
> +	case 0:
> +		reg = AYN_SENSOR_PWM_FAN_SPEED_1_REG;
> +		break;
> +	case 1:
> +		reg = AYN_SENSOR_PWM_FAN_SPEED_2_REG;
> +		break;
> +	case 2:
> +		reg = AYN_SENSOR_PWM_FAN_SPEED_3_REG;
> +		break;
> +	case 3:
> +		reg = AYN_SENSOR_PWM_FAN_SPEED_4_REG;
> +		break;
> +	case 4:
> +		reg = AYN_SENSOR_PWM_FAN_SPEED_5_REG;
> +		break;
> +	case 5:
> +		reg = AYN_SENSOR_PWM_FAN_TEMP_1_REG;
> +		break;
> +	case 6:
> +		reg = AYN_SENSOR_PWM_FAN_TEMP_2_REG;
> +		break;
> +	case 7:
> +		reg = AYN_SENSOR_PWM_FAN_TEMP_3_REG;
> +		break;
> +	case 8:
> +		reg = AYN_SENSOR_PWM_FAN_TEMP_4_REG;
> +		break;
> +	case 9:
> +		reg = AYN_SENSOR_PWM_FAN_TEMP_5_REG;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	ret = read_from_ec(reg, 1, &val);
> +	if (ret)
> +		return ret;
> +
> +	switch (i) {
> +	case 0:
> +	case 1:
> +	case 2:
> +	case 3:
> +	case 4:
> +		val = val << 1; /* Max EC value is 128, scale to 255 */
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	return sysfs_emit(buf, "%ld\n", val);
> +}
> +
> +/* Fan curve attributes */
> +static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point1_pwm, pwm_curve, 0);
> +static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_pwm, pwm_curve, 1);
> +static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point3_pwm, pwm_curve, 2);
> +static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point4_pwm, pwm_curve, 3);
> +static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point5_pwm, pwm_curve, 4);
> +static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point1_temp, pwm_curve, 5);
> +static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_temp, pwm_curve, 6);
> +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);
> +
> +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,
> +	&sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
> +	&sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
> +	&sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
> +	&sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
> +	&sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
> +	&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,
> +	NULL,
> +};
> +
> +ATTRIBUTE_GROUPS(ayn_sensors);
> +
> +static int ayn_ec_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct device *hwdev;
> +	int ret;

ret is unused.

> +
> +	hwdev = devm_hwmon_device_register_with_info(dev, "aynec", NULL,
> +						     &ayn_ec_chip_info,
> +						     ayn_sensors_groups);
> +	return PTR_ERR_OR_ZERO(hwdev);
> +}
> +
> +static struct platform_driver ayn_ec_driver = {
> +	.driver = {
> +		.name = "ayn-ec",
> +	},
> +	.probe = ayn_ec_probe,
> +};

Thanks,
Alok

  parent reply	other threads:[~2025-07-25 15:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-25  0:45 [PATCH 1/4] platform/x86: (ayn-ec) Add PWM Fan HWMON Interface Derek J. Clark
2025-07-25  0:45 ` [PATCH 2/4] platform/x86: (ayn-ec) Add Temperature Sensors Derek J. Clark
2025-07-25 15:29   ` ALOK TIWARI
2025-07-26 15:50   ` David Box
2025-07-26 17:52     ` Derek John Clark
2025-07-25  0:45 ` [PATCH 3/4] platform/x86: (ayn-ec) Add RGB Interface Derek J. Clark
2025-07-25  0:45 ` [PATCH 4/4] platform/x86: (ayn-ec) Add Ayn EC Platform Documentation Derek J. Clark
2025-07-25 15:08 ` ALOK TIWARI [this message]
2025-07-26  2:48   ` [PATCH 1/4] platform/x86: (ayn-ec) Add PWM Fan HWMON Interface Derek J. Clark
2025-07-26 10:57 ` kernel test robot
2025-07-26 11:43 ` kernel test robot
2025-07-26 12:06 ` kernel test robot
2025-07-26 13:20 ` kernel test robot
2025-07-26 15:34 ` kernel test robot
2025-07-26 15:47 ` David Box
2025-07-26 17:51   ` Derek John Clark
2025-07-26 17:21 ` kernel test robot

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=e3ab1337-2409-4828-aea7-4c71f8e9197d@oracle.com \
    --to=alok.a.tiwari@oracle.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jdelvare@suse.com \
    --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;
as well as URLs for NNTP newsgroup(s).