From nobody Wed Sep 3 02:36:06 2025 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F9031E9B0D; Sat, 26 Jul 2025 03:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501129; cv=none; b=ZG+pm0jdQzXp5FBq5dgwoh2u+C6YgHzmVJyF0PXZQnY7gLQmAjSO0vyPbueBbj08otiZxtAYxsa9b/2BMMAbzrvC83W03rIbTP2MtGWMfmOZtwvGi8yHw2418C1nt3EIi08DvjpOULCuwxrGcya0Fk4SHgyofIijkgnD7EnooSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501129; c=relaxed/simple; bh=Xiv6ulUL+wETM/GSd0EfxCFtD+ZMMN/wtuGNPPUAPYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jQl3pHXXruil61oXyAFJ3JHAlqW3FWsB0GvVwLztOlapvlehUfHgGgrmhISJ+GHHHn5T8AZydupqjfLod1k/J8ToTleDSdKbFG769kkSz+LRXD9yOxu1xuaaq32aqTGXO3kHQpfmoHhozTOyN4srcKJt7BgL9u0kA5xg/8tDklI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lAWv77Nu; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lAWv77Nu" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-313eeb77b1fso2202378a91.1; Fri, 25 Jul 2025 20:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753501127; x=1754105927; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zO2HRpChM2ITtXpfU5czPOOrSwfJcbAtUNJW3j2u5a4=; b=lAWv77Nuv53xLE2Pk8urRXaaHvD9jYZDLOF3bffAuAwdvIwPRA5lbppyqLj087wdNr TWZ0aJ+R/qNsXFT5sDnQI9r7Gje+vezv3PwK3/r2Y4Z7c8MXb8uAbfmphttCiHvHA8yx KvYway386v3q/qGYa42SO807cIN/JQSN4qiav9mfbGtZ8e7J+DTzIzrEJMToQrU4TJPX bUvS6MpN55IiOl1Wnx7fRJsAzSTTlGzmik99Yf1qnuNuiuwFOV4UJNesz9vRuy/Eu8tm g6iTVMqJxiUHnZHHjjZ15sghQGZVNjadxokzt06BfRshw4bIL6mptIfwUtp8kxrVEjNa giRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753501127; x=1754105927; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zO2HRpChM2ITtXpfU5czPOOrSwfJcbAtUNJW3j2u5a4=; b=SDQdbClvjSUwSD4jxZ0pB0489Po7CPtLgUeCDI/fZR78YWeLu/R0E5ffOakjncrS5b 82GJjEGULf7uWIlg6xs2BVtJkoZdI4s6wuRmTk4MZhKIy/u9p8jK7cvR47muvOe1Jdfs WBmiUMrowkahD7ylstUOr6PTAeoX/mBk9KcIVDARQByAIpiInQUEJOIcDqoW0wu+6fT0 fdM7bJ9ZYk4JzaoPfZ6eNJCb5kDk4iv8afI0y/YsEouyMQWpcctMhXL/sF5ThjDUpdKm J777QnyhvelQgXOR3Dlqdi6RMl2ZUYT9SeLI0rOoYmlKniP5qvGelvR2W8soW2XTPAkd JVYg== X-Forwarded-Encrypted: i=1; AJvYcCWGK6DRxzdXyllqSRQIKBV5PLVA4jpmJduPY4XJBBd/WKD+R/ftC1Qz6nWoZcg0OwLt2cQu5A7TJyHo9tw=@vger.kernel.org, AJvYcCXWZGAvPHjchOftQ7CAHvUh+EpnuzxNVIx9LCb7MB4Msb9QtXAD42YLXVTT2egRMdS97b5Fx8aZXkc=@vger.kernel.org, AJvYcCXo3p0e9UtL2Nc6NWY/7vD6IY1Zc+ymssCgZVzEW8Evac0t40Q4T9Nh6Tmy0jeKRWKA72VbTb0I1CR8YOcM8j1gxlvefA==@vger.kernel.org, AJvYcCXro+0AldIDkVHuJ87d7sLkLb8OXS+xW/aFpHe81UeOOQvVusG0VjDSNPRjA5v2sP2j4Drq1QBWC7Ht11xS@vger.kernel.org X-Gm-Message-State: AOJu0Yz80ndZHimlYA6k57juq9UjsrSK3WaFIhPweZZkBUgqBYu3F3DB BtzFr3VfwNWo3qDVpFxJc4nujQom7dAlU4nNBH+JUfZntCFGJeoNWKFg X-Gm-Gg: ASbGnctdQY25TlZzCx18fWLWHFMsrf9+28/ldUqWWzTmQD/qxQSXD7i3nqgyKH4oXBY wJHeK5944incHD1uYN8BPDKHQV8KoCinKT+x74WHw39crbWMZWLn73ybCnnMULPT1LzXRsQkhVe ZzP4utu0Mh3SFcNAsp74eFIJQmW968OJfX36CzJT4KQ2c1X3r9BW7Ah+c03x47pRPUHySnnkwh7 vhXhxWiZBRaJjgtUPhECi9dZ+htKbFGR+Tt5hzAqw8ZYBVrPhKA/LsrEskt9A0gVGf7hM2hdn89 GXrvsDaonSSec8KC1Fp2GgdPcgN5Di6OsE7oHRAKqC7V8RXgwKF4VmVRiPzHOLK4ms9zMSNCSeL F7/pPoX/KrFdnlCfeZUtIQKLjUYmGWZuHO7r7lY+JqolOiGx1otxnHtOst5ymjUzRptU+m08Or1 veLKB/m855CKYC X-Google-Smtp-Source: AGHT+IFJHI091hcpTs6IEWs+qkqq69j8qSMEgyM2XBDTu2anE+RdOAweuuAOgWOpu0iEsWPFARqDQQ== X-Received: by 2002:a17:90a:d40e:b0:313:1e9d:404b with SMTP id 98e67ed59e1d1-31e7783b3c0mr6923733a91.2.1753501126399; Fri, 25 Jul 2025 20:38:46 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31e832f8942sm779204a91.4.2025.07.25.20.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jul 2025 20:38:46 -0700 (PDT) From: "Derek J. Clark" To: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Jean Delvare , Guenter Roeck , Alok Tiwari , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 1/4] platform/x86: (ayn-ec) Add PWM Fan HWMON Interface Date: Fri, 25 Jul 2025 20:38:38 -0700 Message-ID: <20250726033841.7474-2-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250726033841.7474-1-derekjohn.clark@gmail.com> References: <20250726033841.7474-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds platform driver for Ayn Loki and Tactoy Zeenix lines of handheld devices. This patch implements a hwmon interface for EC provided manual PWM fan control and user defined fan curves. A global ACPI lock is used when reading or writing from the EC. There are 4 fan modes implemented in this patch. Modes 0-3 act in accordance with the standard hwmon logic where 0 is 100% fan speed, 1 is manual control, and 2 is automatic control. As the EC only provides 3 modes by default, mode 0 is implemented by setting the device to manual and then setting fan speed to 100% directly. In mode 1 the PWM duty cycle is set in sysfs with values [0-255], which are then scaled to the EC max of 128. Mode 4 is an automatic mode where the fan curve is user defined. There are 5 total set points and each set point takes a temperature in Celsius [0-100] and a PWM duty cycle [0-255]. When the CPU temperature reaches a given set point, the corresponding duty cycle is automatically set by the EC. Signed-off-by: Derek J. Clark --- MAINTAINERS | 6 + drivers/platform/x86/Kconfig | 14 + drivers/platform/x86/Makefile | 3 + drivers/platform/x86/ayn-ec.c | 595 ++++++++++++++++++++++++++++++++++ 4 files changed, 618 insertions(+) create mode 100644 drivers/platform/x86/ayn-ec.c diff --git a/MAINTAINERS b/MAINTAINERS index d61b004005fd..5b816883fe7d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4035,6 +4035,12 @@ W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/pwm/adi,axi-pwmgen.yaml F: drivers/pwm/pwm-axi-pwmgen.c =20 +AYN PLATFORM EC DRIVER +M: Derek J. Clark +L: platform-driver-x86@vger.kernel.org +S: Maintained +F: drivers/platform/x86/ayn-ec.c + AZ6007 DVB DRIVER M: Mauro Carvalho Chehab L: linux-media@vger.kernel.org diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 6d238e120dce..61391be65a7b 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -304,6 +304,20 @@ config ASUS_TF103C_DOCK If you have an Asus TF103C tablet say Y or M here, for a generic x86 distro config say M here. =20 +config AYN_EC + tristate "Ayn x86 devices EC platform control" + depends on ACPI + depends on HWMON + select LEDS_CLASS + select LEDS_CLASS_MULTICOLOR + help + This is a driver for Ayn and Tactoy x86 handheld devices. It provides + temperature monitoring, manual fan speed control, fan curve control, + and chassis RGB settings. + + If you have an x86 Ayn or Tactoy handheld device say M here. The module + will be called ayn-platform. + config MERAKI_MX100 tristate "Cisco Meraki MX100 Platform Driver" depends on GPIOLIB diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index a0c5848513e3..d32504b89365 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -38,6 +38,9 @@ obj-$(CONFIG_ASUS_TF103C_DOCK) +=3D asus-tf103c-dock.o obj-$(CONFIG_EEEPC_LAPTOP) +=3D eeepc-laptop.o obj-$(CONFIG_EEEPC_WMI) +=3D eeepc-wmi.o =20 +# Ayn +obj-$(CONFIG_AYN_EC) +=3D ayn-ec.o + # Cisco/Meraki obj-$(CONFIG_MERAKI_MX100) +=3D meraki-mx100.o =20 diff --git a/drivers/platform/x86/ayn-ec.c b/drivers/platform/x86/ayn-ec.c new file mode 100644 index 000000000000..7e2187eba9a8 --- /dev/null +++ b/drivers/platform/x86/ayn-ec.c @@ -0,0 +1,595 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Platform driver for Ayn x86 Handhelds. + * + * Implements multiple attributes provided by the EC. Fan reading and cont= rol, + * 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 u= se + * [0-128] as the range in the EC, the written value is scaled to accommod= ate. + * 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]. Temperatu= re + * 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 col= ors + * and fades in/out, and manual, which enables setting a user defined colo= r. + * + * Copyright (C) 2025 Derek J. Clark + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Fan reading and PWM */ +#define AYN_SENSOR_PWM_FAN_ENABLE_REG 0x10 /* PWM operating mode */ +#define AYN_SENSOR_PWM_FAN_SET_REG 0x11 /* PWM duty cycle */ +#define AYN_SENSOR_PWM_FAN_SPEED_REG 0x20 /* Fan speed */ + +/* EC controlled fan curve registers */ +#define AYN_SENSOR_PWM_FAN_SPEED_1_REG 0x12 +#define AYN_SENSOR_PWM_FAN_SPEED_2_REG 0x14 +#define AYN_SENSOR_PWM_FAN_SPEED_3_REG 0x16 +#define AYN_SENSOR_PWM_FAN_SPEED_4_REG 0x18 +#define AYN_SENSOR_PWM_FAN_SPEED_5_REG 0x1A +#define AYN_SENSOR_PWM_FAN_TEMP_1_REG 0x13 +#define AYN_SENSOR_PWM_FAN_TEMP_2_REG 0x15 +#define AYN_SENSOR_PWM_FAN_TEMP_3_REG 0x17 +#define AYN_SENSOR_PWM_FAN_TEMP_4_REG 0x19 +#define AYN_SENSOR_PWM_FAN_TEMP_5_REG 0x1B + +/* Handle ACPI lock mechanism */ +#define ACPI_LOCK_DELAY_MS 500 +enum ayn_model { + ayn_loki_max =3D 1, + ayn_loki_minipro, + ayn_loki_zero, + tactoy_zeenix_lite, +}; + +struct ayn_device { + u32 ayn_lock; /* ACPI EC Lock */ +} drvdata; + +/* Handle ACPI lock mechanism */ +#define ACPI_LOCK_DELAY_MS 500 + +static bool lock_global_acpi_lock(void) +{ + return ACPI_SUCCESS(acpi_acquire_global_lock(ACPI_LOCK_DELAY_MS, + &drvdata.ayn_lock)); +} + +static bool unlock_global_acpi_lock(void) +{ + return ACPI_SUCCESS(acpi_release_global_lock(drvdata.ayn_lock)); +} + +/** + * read_from_ec() - Reads a value from the embedded controller. + * + * @reg: The register to start the read from. + * @size: The number of sequential registers the data is contained in. + * @val: Pointer to return the data with. + * + * Return: 0, or an error. + */ +static int read_from_ec(u8 reg, int size, long *val) +{ + int ret, i; + u8 buf; + + if (!lock_global_acpi_lock()) + return -EBUSY; + + *val =3D 0; + for (i =3D 0; i < size; i++) { + ret =3D ec_read(reg + i, &buf); + if (ret) + return ret; + *val <<=3D i * 8; + *val +=3D buf; + } + + if (!unlock_global_acpi_lock()) + return -EBUSY; + + return 0; +} + +/** + * write_to_ec() - Writes a value to the embedded controller. + * + * @reg: The register to write to. + * @val: Value to write + * + * Return: 0, or an error. + */ +static int write_to_ec(u8 reg, u8 val) +{ + int ret; + + if (!lock_global_acpi_lock()) + return -EBUSY; + + pr_info("Writing EC value %d to register %u\n", val, reg); + ret =3D ec_write(reg, val); + + if (!unlock_global_acpi_lock()) + return -EBUSY; + + return ret; +} + +/** + * ayn_pwm_manual() - Enable manual control of the fan. + */ +static int ayn_pwm_manual(void) +{ + return write_to_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 0x00); +} + +/** + * ayn_pwm_full() - Set fan to 100% speed. + */ +static int ayn_pwm_full(void) +{ + int ret; + + ret =3D write_to_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 0x00); + if (ret) + return ret; + + return write_to_ec(AYN_SENSOR_PWM_FAN_SET_REG, 128); +} + +/** + * ayn_pwm_auto() - Enable automatic EC control of the fan. + */ +static int ayn_pwm_auto(void) +{ + return write_to_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 0x01); +} + +/** + * ayn_pwm_auto() - Enable manually setting the fan curve for automatic + * EC control of the fan. + */ +static int ayn_pwm_user(void) +{ + return write_to_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 0x02); +} + +/** + * ayn_ec_hwmon_is_visible() - Determines RO or RW for hwmon attribute sys= fs. + * + * @drvdata: Unused void pointer to context data. + * @type: The hwmon_sensor_types type. + * @attr: The attribute to set RO/RW on. + * @channel: HWMON subsystem usage flags for the attribute. + * + * Return: Permission level. + */ +static umode_t ayn_ec_hwmon_is_visible(const void *drvdata, + enum hwmon_sensor_types type, u32 attr, + int channel) +{ + switch (type) { + case hwmon_fan: + return 0444; + case hwmon_pwm: + return 0644; + default: + return 0; + } +} + +/** + * ayn_pwm_fan_read() - Read from a hwmon pwm or fan attribute. + * + * @dev: parent device of the given attribute. + * @type: The hwmon_sensor_types type. + * @attr: The attribute to read from. + * @channel: HWMON subsystem usage flags for the attribute. + * @val: Pointer to return the read value from. + * + * Return: 0, or an error. + */ +static int ayn_pwm_fan_read(struct device *dev, enum hwmon_sensor_types ty= pe, + u32 attr, int channel, long *val) +{ + int ret; + + switch (type) { + case hwmon_fan: + switch (attr) { + case hwmon_fan_input: + return read_from_ec(AYN_SENSOR_PWM_FAN_SPEED_REG, 2, + val); + default: + break; + } + break; + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_enable: + ret =3D read_from_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 1, + val); + if (ret) + return ret; + + /* EC uses 0 for manual, 1 for automatic, 2 for user + * fan curve. Reflect hwmon usage instead. + */ + if (*val =3D=3D 1) { + *val =3D 2; + return 0; + } + + if (*val =3D=3D 2) { + *val =3D 3; + return 0; + } + + /* Return 0 when fan at max, otherwise 1 for manual. */ + ret =3D read_from_ec(AYN_SENSOR_PWM_FAN_SET_REG, 1, val); + if (ret) + return ret; + + if (*val =3D=3D 128) + *val =3D 0; + else + *val =3D 1; + + return ret; + case hwmon_pwm_input: + ret =3D read_from_ec(AYN_SENSOR_PWM_FAN_SET_REG, 1, val); + if (ret) + return ret; + + *val =3D *val << 1; /* Max value is 128, scale to 255 */ + + return 0; + default: + break; + } + break; + default: + break; + } + return -EOPNOTSUPP; +} + +/** + * ayn_pwm_fan_write() - Write to a hwmon pwm attribute. + * + * @dev: parent device of the given attribute. + * @type: The hwmon_sensor_types type. + * @attr: The attribute to write to. + * @channel: HWMON subsystem usage flags for the attribute. + * @val: Value to write. + * + * Return: 0, or an error. + */ +static int ayn_pwm_fan_write(struct device *dev, enum hwmon_sensor_types t= ype, + u32 attr, int channel, long val) +{ + switch (type) { + case hwmon_pwm: + switch (attr) { + case hwmon_pwm_enable: + switch (val) { + case 0: + return ayn_pwm_full(); + case 1: + return ayn_pwm_manual(); + case 2: + return ayn_pwm_auto(); + case 3: + return ayn_pwm_user(); + default: + return -EINVAL; + } + case hwmon_pwm_input: + if (val < 0 || val > 255) + return -EINVAL; + + val =3D val >> 1; /* Max value is 128, scale from 255 */ + + return write_to_ec(AYN_SENSOR_PWM_FAN_SET_REG, val); + default: + break; + } + break; + default: + break; + } + return -EOPNOTSUPP; +} + +static const struct hwmon_channel_info *ayn_ec_sensors[] =3D { + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT), + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE), + NULL, +}; + +static const struct hwmon_ops ayn_ec_hwmon_ops =3D { + .is_visible =3D ayn_ec_hwmon_is_visible, + .read =3D ayn_pwm_fan_read, + .write =3D ayn_pwm_fan_write, +}; + +static const struct hwmon_chip_info ayn_ec_chip_info =3D { + .ops =3D &ayn_ec_hwmon_ops, + .info =3D ayn_ec_sensors, +}; + +/** + * pwm_curve_store() - Write a fan curve speed or temperature value. + * + * @dev: The attribute's parent device. + * @attr: The attribute to read. + * @buf: Input value string from sysfs write. + * + * Return: Number of bytes read, or an error. + */ +static ssize_t pwm_curve_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + int ret, i, val; + u8 reg; + + ret =3D kstrtoint(buf, 0, &val); + if (ret) + return ret; + + i =3D to_sensor_dev_attr(attr)->index; + switch (i) { + case 0: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_1_REG; + break; + case 1: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_2_REG; + break; + case 2: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_3_REG; + break; + case 3: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_4_REG; + break; + case 4: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_5_REG; + break; + case 5: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_1_REG; + break; + case 6: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_2_REG; + break; + case 7: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_3_REG; + break; + case 8: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_4_REG; + break; + case 9: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_5_REG; + break; + default: + return -EINVAL; + } + + switch (i) { + case 0: + case 1: + case 2: + case 3: + case 4: + if (val < 0 || val > 255) + return -EINVAL; + val =3D 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 =3D 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: 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 =3D to_sensor_dev_attr(attr)->index; + switch (i) { + case 0: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_1_REG; + break; + case 1: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_2_REG; + break; + case 2: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_3_REG; + break; + case 3: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_4_REG; + break; + case 4: + reg =3D AYN_SENSOR_PWM_FAN_SPEED_5_REG; + break; + case 5: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_1_REG; + break; + case 6: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_2_REG; + break; + case 7: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_3_REG; + break; + case 8: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_4_REG; + break; + case 9: + reg =3D AYN_SENSOR_PWM_FAN_TEMP_5_REG; + break; + default: + return -EINVAL; + } + + ret =3D read_from_ec(reg, 1, &val); + if (ret) + return ret; + + switch (i) { + case 0: + case 1: + case 2: + case 3: + case 4: + val =3D 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[] =3D { + &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 =3D &pdev->dev; + struct device *hwdev; + + hwdev =3D 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 =3D { + .driver =3D { + .name =3D "ayn-ec", + }, + .probe =3D ayn_ec_probe, +}; + +static struct platform_device *ayn_ec_device; + +static int __init ayn_ec_init(void) +{ + ayn_ec_device =3D platform_create_bundle(&ayn_ec_driver, ayn_ec_probe, + NULL, 0, NULL, 0); + + return PTR_ERR_OR_ZERO(ayn_ec_device); +} + +static void __exit ayn_ec_exit(void) +{ + platform_device_unregister(ayn_ec_device); + platform_driver_unregister(&ayn_ec_driver); +} + +static const struct dmi_system_id ayn_dmi_table[] =3D { + { + .matches =3D { + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "ayn"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "Loki Max"), + }, + .driver_data =3D (void *)ayn_loki_max, + }, + { + .matches =3D { + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "ayn"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "Loki MiniPro"), + }, + .driver_data =3D (void *)ayn_loki_minipro, + }, + { + .matches =3D { + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "ayn"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "Loki Zero"), + }, + .driver_data =3D (void *)ayn_loki_zero, + }, + { + .matches =3D { + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Tectoy"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "Zeenix Lite"), + }, + .driver_data =3D (void *)tactoy_zeenix_lite, + }, + {}, +}; + +MODULE_DEVICE_TABLE(dmi, ayn_dmi_table); + +module_init(ayn_ec_init); +module_exit(ayn_ec_exit); + +MODULE_AUTHOR("Derek J. Clark "); +MODULE_DESCRIPTION("Platform driver that handles EC sensors of Ayn x86 dev= ices"); +MODULE_LICENSE("GPL"); --=20 2.50.1 From nobody Wed Sep 3 02:36:06 2025 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52B891EFFB7; Sat, 26 Jul 2025 03:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501129; cv=none; b=Msci1rA9dp/7T3FeU7MjWH9XlSvynBi3DkeEHvZUh2UfAG+LzTZcjec96G4LnTT5Tfq/Dl8M5NTGlnzylcNLUsdpM8iiQ53wAJvAfgPfA64YWTq/X7x2HGnoa6JFYOrq9a8JzSLUKLYBGZhaXr9ySocKpcsdoKnH3yd34FkShb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501129; c=relaxed/simple; bh=qqR1ftzVitkRvIjjA3vechrl+NjZRajDJ13MWpI4Hqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CbfBrck8wDH1jrdQIpGTjzmY3An9vxo30B4zYP/2nndacKHA9X/o9Q4OIiuJ4jxp6Z6TRtPf8SKbuWRItWJcsYPJ1IGA72AFQz6RRcKAx0tne4FjLlA+maZmfKzaw8IZwPFQl9Zw5fR9DGyTaD8SKgHtx4KRdAdIV18hCUbF08c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=huy1Cihi; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="huy1Cihi" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-313bb9b2f5bso2473060a91.3; Fri, 25 Jul 2025 20:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753501128; x=1754105928; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6F0Nx/x4Au56cIxfa0QJMWeiLDdvbcrTmp+T/eyT3+w=; b=huy1Cihi9rbKsE6Nc07jeKbD/zVOFiPNCG/6uV8M688eOybIACaYZuD6lqGSJ1XTu8 sr1EJYXchhHjQ+lgnpzEQ91+ZUziPLlrdz5cE6JYOPp2fmCkW3pIpb17w3+2FGPM/Wsc 9S5fxJM7Pt6gRwnhVWFCjvNwoBhcIrmLFFnSeoLj5wI9OQjnLxu0BluHmTpGrvKJwEuM QrQa36KijVo8smjHXWfDNeTy7U0AHGQ/UQKSCTIWckdgiE8lR9px4cdlo+H78tOvaN6N 2/HVHUtY9uqikDNDLL231Va/RokA/VD7v/T1XIWIKILwjiiTLhF4S3ixgoNV19t8/d25 nGuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753501128; x=1754105928; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6F0Nx/x4Au56cIxfa0QJMWeiLDdvbcrTmp+T/eyT3+w=; b=wxZPUGYf5kTgTPNFi9zlVa1Qt8rGM98hfZy4pokAQ0Vu8w4W5KZy1+xeOjRUYj+ebJ vWVS0A62oqisni2gA6qOhJmeeXwvNFcjyXlki8Ax6chUmuaX1o8SYgc4Tn9a5i5f8+Zh MXLtvlhc1KFoLfttZZM6L36PU1QtRyBIdLI3cHRR/Tu/A6vjlO08fR+iJAioO4pYPSPm /ueU6uFhSdr9fEEhfV2RUf0l9nHlThv+yRpxTZTRemkjF9roFS4B6sr00MU9f1TMfKfh s3V/nWzdDVH4vNmt1CzUtmm7fSRQJcy1Xo3QqTjZu4+yrYZsqHqwSF08IorMKBhcVHI6 IOZg== X-Forwarded-Encrypted: i=1; AJvYcCWCXwj1r50qipxOadEvIRYKdjEKP5/20jByx+Jt57owB6+q3l2FVW4oPU6kunbPc1+e6goK2yufZMC4HY8aThTfJcq2iA==@vger.kernel.org, AJvYcCWJ1yqeRC6/Glwwye5agCARxxEdmHx1cFWMKvFcUSCP/Wy/FKiZPJbmYBzi7ahjKS690DIRR+dHZYL/OTI=@vger.kernel.org, AJvYcCWmdC1/SU9kAdm74bG9gX7ZoMg1adDCrO7QITuOdrAhH5IaWZiKbkV9W0Z4n2FsS0XdkSGXXZvufT0=@vger.kernel.org, AJvYcCXXPV/Dny+z3fczfDWhh5n/EedtRgY/eQKWn8kF3QxV2qyJbyhrSzcxNYBOaTKXSWdRXcQES5lUWjOyYFt3@vger.kernel.org X-Gm-Message-State: AOJu0Yy/YtNAv5F50H8naDFhx3rr3exPZZXOsVemeItNkMFTCclRYM1M lQNSrVHGsO28Rq+0Ws0H9gZyAOlzgqrvojnH06jYIRalWnoZTkirvX0A X-Gm-Gg: ASbGncvPSWMx2jr+c0ZrELI32NxdjE2StM1Gz0Lg3Osk6aV4V6dK7Zv6g2DlZ7HEWaY /51lDuA9APQ87fbqZ3bA2BFwky2L4haBG+wti21o3hGZyc/NIGh6ELf8/T6LXYM+wJCho4Yv+sD gGNeVMGwChUD9zz0v8EvgIs7b8WsxpI0SnJ2+sPVltGaCI/KVIn+WLYkVC+B2hoeZ2nbCDKFbf2 0Bmn/JOHjLjJPyDPEu8P5kIVz0oz2k9r8J+DKouFbYe3gJh2ZjXHF8tXwW/HEk+11NCKazxeQxy FWtglJoFu7co/7pKHdNnEYo6b9mfOcAe3jGBZU0ItdcVXAR4YE4KpkOidaIpbHP7QuUnOtDbbW9 ePN0yXXWfskbNTvYKB1W54/bfeWoq4Hetajy6HTw5653WIT3aZO+ZnF102Y4c1JM4eY+SjLlElC Hb7eqQ/tmJo6iu X-Google-Smtp-Source: AGHT+IFGJT/KJS3r8dIQVOtFr4U6pTDgI6xExedT2Hw9UAWDmL3kJ2XZNy8CsLT5ROcH2OKRguFOQw== X-Received: by 2002:a17:90b:3bc4:b0:308:7270:d6ea with SMTP id 98e67ed59e1d1-31e77a2483fmr5757918a91.30.1753501127469; Fri, 25 Jul 2025 20:38:47 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31e832f8942sm779204a91.4.2025.07.25.20.38.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jul 2025 20:38:47 -0700 (PDT) From: "Derek J. Clark" To: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Jean Delvare , Guenter Roeck , Alok Tiwari , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 2/4] platform/x86: (ayn-ec) Add Temperature Sensors Date: Fri, 25 Jul 2025 20:38:39 -0700 Message-ID: <20250726033841.7474-3-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250726033841.7474-1-derekjohn.clark@gmail.com> References: <20250726033841.7474-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C2=B0C Motherboard: +30.0=C2=B0C Charger IC: +30.0=C2=B0C vCore: +36.0=C2=B0C CPU Core: +48.0=C2=B0C Signed-off-by: Derek J. Clark --- drivers/platform/x86/ayn-ec.c | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/drivers/platform/x86/ayn-ec.c b/drivers/platform/x86/ayn-ec.c index 7e2187eba9a8..3b4daa7603ee 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 =20 +/* 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 */ + /* Handle ACPI lock mechanism */ #define ACPI_LOCK_DELAY_MS 500 + enum ayn_model { ayn_loki_max =3D 1, ayn_loki_minipro, @@ -63,6 +71,20 @@ struct ayn_device { u32 ayn_lock; /* ACPI EC Lock */ } drvdata; =20 +struct thermal_sensor { + char *name; + int reg; +}; + +static struct thermal_sensor thermal_sensors[] =3D { + { "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 }, + {} +}; + /* Handle ACPI lock mechanism */ #define ACPI_LOCK_DELAY_MS 500 =20 @@ -503,6 +525,61 @@ static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point3_temp, pw= m_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); =20 +/** + * 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 =3D to_sensor_dev_attr(attr)->index; + + ret =3D read_from_ec(thermal_sensors[i].reg, 1, &val); + if (ret) + return ret; + + val =3D 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 =3D 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[] =3D { &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, @@ -514,6 +591,16 @@ static struct attribute *ayn_sensors_attrs[] =3D { &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, }; =20 --=20 2.50.1 From nobody Wed Sep 3 02:36:06 2025 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CDEE1F17EB; Sat, 26 Jul 2025 03:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501131; cv=none; b=fEg9JDSwPFHfIlG9k/BJa/+EnfWNkp8NyqGb3nGujLAEdJSA1d2Q88B+rzWuCRcntv05nlufhC1He1QKDMT/WI7b+CJjcrzBheExU3znZ5nqMO3yH98NKLVVxNqZTevMlbV1KQssgXc97MOIk2Ik50ptxSANgOmlV3CsZtBRvOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501131; c=relaxed/simple; bh=qMccuERQ2VERfK2KQwVm7Eq1mAauLj8r33/cRrV624I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cWP+Zpkt99A2psKVMmVQOqHel5pW1iyIMZvYJOcZ0Uuz6tB/vGRBl1LXmDJs6HhRgTbzUi20zwCwJQpBy9tUxuznTosgGOwvQFZvOd81JCAbw8BnWaiDNfVnEgOyji/8cOo8C5ojsAeGoL+BwCbrOinJl3c2UjA0zd1jPZQjzZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ReHpKknc; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ReHpKknc" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-b3220c39cffso2901432a12.0; Fri, 25 Jul 2025 20:38:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753501129; x=1754105929; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YM1d0/lGL1+75gVv7USWsP7dD2kt+Rmlur8V9H1htiE=; b=ReHpKkncIU0ZzHK/JLchScDdAc80hzdgIUzqNPudSLz6NtUwNAQjRZwhJkdIqrIQHL rxTVB7gaYNd492Qlvxw+FdfOT1FzTsBM7mnubOUadwxeOAPo/YZsWteFsT4xSQWrD2sU 5QibrQXwH7Wte3rAJOnQjCknK+ALp6eTCMH2gUbCBMtsW+niz47A+5ILgU04fDMf8asw 7jqPlwzgo/HAuy5dTVgcKodNOsWM7tVnO97e5SOR6oBc2ptgIyTdro/osyvRsd8QfQPQ LqxN5673W94flFtmD1eXzzCJk60GWZQTL4ri8Ecysj9NZ/oSm6K/okp/5er5XD+rYTPu d9XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753501129; x=1754105929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YM1d0/lGL1+75gVv7USWsP7dD2kt+Rmlur8V9H1htiE=; b=EIOvMTgrl1vC5RHjBhETyBlrV/SbLHObQxmxLDFTFO0nKyjIsPKRerhq+sdCF8mN55 gFOQEttOH6c9OBOPquQawgz5tJCLiLjB3yR6zxL5lW+zSpPB+qaTqGKntQ0Hfd3MG0+w 8fKlS7nCQJkCd/5SMK8IldkEIvIaEuU2qajEWE3TeE6DPSS3GCDic7qexvwZSYPaURwo vObcwSmt4C66TB3molFERG1dTNwmzNhfAuIGstiWqobTGnr/idCZS15nWlaQ2Xamvdn2 hd/Seiqnnbo2BQ0xQlD1ZL6b1LFltwbh0pkQD1pAcQ0g87E2F2FEDhb+z1sCy0y/aonh 5NRw== X-Forwarded-Encrypted: i=1; AJvYcCUb6le83+cZwH4dIA0CQBdeivp0TCZKze5Y6MnEfYhmaRuRwRHNKpLQlkJhrLFiXkIW2GkjVI2CWmjjdZCLrfYjwvo1Mg==@vger.kernel.org, AJvYcCWcwfHHikSFbQ/U7tjNsw9UWR9GedW3ub7b9Z4dNDuuq2edmG8phWjKKHi9lVVDxpvR7L03B8kT8WJl8lcB@vger.kernel.org, AJvYcCXCvldZus8/4DLAKmzl/vFQbs96DtFZJ95SUREFWHebP7rox57uUlMuqvAIPUo7+duoUzrMzSDJVvh3VvM=@vger.kernel.org, AJvYcCXjhGjnF2Sn1Y6+0bFNrKny+2jICCRayZ07DwM8hPMpYqKuts7h+7FJimJviiRbenFrNq76YVwInYg=@vger.kernel.org X-Gm-Message-State: AOJu0YzuICIK0JgzYXYHBQq8BcUymEu2agkbDmWawz6mzxn+MBW/mjlL j/Zh4lrexpOoiv0VpPbCFK+Q9YzMfsVZxe12eEialPb/wcdusnaUB3JYQU0OSg== X-Gm-Gg: ASbGncvuFo0iMeoS9IdX0f4pCMtR0dfZIvKY0Q9/nX3suk/hSX+b64UzMKiLZzoU2sa 9Jc+tmm/xx9vD/qk4wC5Hze2aXgWhxx8Wi+r9QWK8KKrE/bq5zO9Ft2IW5GMPlqdM1DJt2gTibS nnUTCJBnchPbZZHa5o+9hpZ5/wkCQ/xoI4pAz6iiV6ay94dZD/qpEf/Xx1tju3NQzYDkI7XIH09 YcTAqjpLXCiPQAPYvVxKOZsQ8v/QC0Gu/UQ5sRIUxNWdIamyGOQmkUE/WNwJvxlYMryDhOqAsHb cPLN4Ka+PW5OcJ7GYC/DlTqVGpDj0TKqjjfSlFXxQkwU9c5p3d0FalD6IDsvinBxD9y025OwLgb aSsGUm60KwhUlS+YpD6ISZ7/ZTZac0WTtZXeR8EPSoGHwaW16HHeYA6G2cVxXMRxBOurdCQAYb8 c+fwtGc82WpP6w X-Google-Smtp-Source: AGHT+IEOv3C4wSNmSjsRBU2Egsl0G/lGSmF/VtbOk5540yQjUw6S+QEtrrTP16UZ1SgsM3ftK9kjiw== X-Received: by 2002:a05:6a20:3ca5:b0:232:57c8:1bf4 with SMTP id adf61e73a8af0-23d700164ebmr6365956637.9.1753501128714; Fri, 25 Jul 2025 20:38:48 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31e832f8942sm779204a91.4.2025.07.25.20.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jul 2025 20:38:48 -0700 (PDT) From: "Derek J. Clark" To: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Jean Delvare , Guenter Roeck , Alok Tiwari , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 3/4] platform/x86: (ayn-ec) Add RGB Interface Date: Fri, 25 Jul 2025 20:38:40 -0700 Message-ID: <20250726033841.7474-4-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250726033841.7474-1-derekjohn.clark@gmail.com> References: <20250726033841.7474-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds an EC controlled LED Multicolor Class Device for controlling the RGB rings around the joysticks. The EC provides a single register for each of the colors red, green, and blue, as well as a mode switching register. The EC accepts values [0-255] for all colors. There are two available effects: breathe, which is the default when the device is started, and monocolor. When resuming from sleep the user selected effect will be overwritten by the EC, so the driver retains the last setting and resets on resume. When setting a color, each color register is set before a final "write" code is sent to the device. The EC may briefly reflect the "write" code when writing, but quickly changes to the "monocolor" value once complete. The driver interprets both of these values as "monocolor" in _show to simplify the sysfs exposed to the user. Two custom attributes are added to the standard LED parent device: effect, a RW file descriptor used to set the effect, and effect_index, which enumerates the available valid options. Signed-off-by: Derek J. Clark --- drivers/platform/x86/ayn-ec.c | 283 ++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) diff --git a/drivers/platform/x86/ayn-ec.c b/drivers/platform/x86/ayn-ec.c index 3b4daa7603ee..3bede03a60fe 100644 --- a/drivers/platform/x86/ayn-ec.c +++ b/drivers/platform/x86/ayn-ec.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include #include @@ -57,6 +59,17 @@ #define AYN_SENSOR_PROC_TEMP_REG 0x09 /* CPU Core */ #define AYN_SENSOR_VCORE_TEMP_REG 0x08 /* vCore */ =20 +/* EC Controlled RGB registers */ +#define AYN_LED_MC_RED_REG 0xB0 /* Range 0x00-0xFF */ +#define AYN_LED_MC_GREEN_REG 0xB1 /* Range 0x00-0xFF */ +#define AYN_LED_MC_BLUE_REG 0xB2 /* Range 0x00-0xFF */ +#define AYN_RGB_EFFECT_REG 0xB3 + +/* RGB effect modes */ +#define AYN_RGB_EFFECT_BREATHE 0x00 +#define AYN_RGB_EFFECT_MONOCOLOR 0x55 +#define AYN_RGB_EFFECT_WRITE 0xAA + /* Handle ACPI lock mechanism */ #define ACPI_LOCK_DELAY_MS 500 =20 @@ -68,7 +81,9 @@ enum ayn_model { }; =20 struct ayn_device { + struct led_classdev *led_cdev; u32 ayn_lock; /* ACPI EC Lock */ + u8 rgb_effect; } drvdata; =20 struct thermal_sensor { @@ -85,6 +100,30 @@ static struct thermal_sensor thermal_sensors[] =3D { {} }; =20 +/* RGB effect values */ +enum RGB_EFFECT_OPTION { + BREATHE, + MONOCOLOR, +}; + +static const char *const RGB_EFFECT_TEXT[] =3D { + [BREATHE] =3D "breathe", + [MONOCOLOR] =3D "monocolor", +}; + +#define DEVICE_ATTR_RW_NAMED(_name, _attrname) \ + struct device_attribute dev_attr_##_name =3D { \ + .attr =3D { .name =3D _attrname, .mode =3D 0644 }, \ + .show =3D _name##_show, \ + .store =3D _name##_store, \ + } + +#define DEVICE_ATTR_RO_NAMED(_name, _attrname) \ + struct device_attribute dev_attr_##_name =3D { \ + .attr =3D { .name =3D _attrname, .mode =3D 0444 }, \ + .show =3D _name##_show, \ + } + /* Handle ACPI lock mechanism */ #define ACPI_LOCK_DELAY_MS 500 =20 @@ -606,10 +645,253 @@ static struct attribute *ayn_sensors_attrs[] =3D { =20 ATTRIBUTE_GROUPS(ayn_sensors); =20 +/** + * rgb_effect_write() - Set the RGB effect stored in drvdata.rgb_effect. + */ +static int rgb_effect_write(void) +{ + return write_to_ec(AYN_RGB_EFFECT_REG, drvdata.rgb_effect); +}; + +/** + * rgb_effect_read() - Read the RGB effect and store it in drvdata.rgb_eff= ect. + */ +static int rgb_effect_read(void) +{ + int ret; + long effect; + + ret =3D read_from_ec(AYN_RGB_EFFECT_REG, 1, &effect); + if (ret) + return ret; + + switch (effect) { + case AYN_RGB_EFFECT_WRITE: + case AYN_RGB_EFFECT_MONOCOLOR: + drvdata.rgb_effect =3D AYN_RGB_EFFECT_WRITE; + break; + default: + drvdata.rgb_effect =3D AYN_RGB_EFFECT_BREATHE; + } + + return 0; +} + +/** + * rgb_effect_store() - Store the given RGB effect and set it. + * + * @dev: parent device of the given attribute. + * @attr: The attribute to write to. + * @buf: Input value string from sysfs write. + * @count: The number of bytes written. + * + * Return: The number of bytes written, or an error. + */ +static ssize_t rgb_effect_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + int ret; + + ret =3D sysfs_match_string(RGB_EFFECT_TEXT, buf); + if (ret < 0) + return ret; + + if (ret) + drvdata.rgb_effect =3D AYN_RGB_EFFECT_WRITE; + else + drvdata.rgb_effect =3D AYN_RGB_EFFECT_BREATHE; + + ret =3D rgb_effect_write(); + if (ret) + return ret; + + return count; +}; + +/** + * rgb_effect_show() - Read the current RGB effect. + * + * @dev: parent device of the given attribute. + * @attr: The attribute to read. + * @buf: Buffer to read to. + * + * Return: The number of bytes read, or an error. + */ +static ssize_t rgb_effect_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret, i; + + ret =3D rgb_effect_read(); + if (ret) + return ret; + + switch (drvdata.rgb_effect) { + case AYN_RGB_EFFECT_WRITE: + case AYN_RGB_EFFECT_MONOCOLOR: + i =3D MONOCOLOR; + break; + default: + i =3D BREATHE; + break; + } + + return sysfs_emit(buf, "%s\n", RGB_EFFECT_TEXT[i]); +}; + +static DEVICE_ATTR_RW_NAMED(rgb_effect, "effect"); + +/** + * rgb_effect_show() - Display the RGB effects available. + * + * @dev: parent device of the given attribute. + * @attr: The attribute to read. + * @buf: Buffer to read to. + * + * Return: The number of bytes read, or an error. + */ +static ssize_t rgb_effect_index_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + size_t count =3D 0; + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(RGB_EFFECT_TEXT); i++) + count +=3D sysfs_emit_at(buf, count, "%s ", RGB_EFFECT_TEXT[i]); + + buf[count - 1] =3D '\n'; + + return count; +} + +static DEVICE_ATTR_RO_NAMED(rgb_effect_index, "effect_index"); + +/** + * ayn_led_mc_brightness_set() - Write the brightness for the RGB LED. + * + * @led_cdev: Parent LED device for the led_classdev_mc. + * @brightness: Brightness value to write [0-255]. + */ +static void ayn_led_mc_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct led_classdev_mc *led_cdev_mc =3D lcdev_to_mccdev(led_cdev); + struct mc_subled s_led; + int i, ret, val; + + switch (drvdata.rgb_effect) { + case AYN_RGB_EFFECT_WRITE: + case AYN_RGB_EFFECT_MONOCOLOR: + break; + case AYN_RGB_EFFECT_BREATHE: + return; + } + + led_cdev->brightness =3D brightness; + for (i =3D 0; i < led_cdev_mc->num_colors; i++) { + s_led =3D led_cdev_mc->subled_info[i]; + val =3D brightness * s_led.intensity / led_cdev->max_brightness; + ret =3D write_to_ec(s_led.channel, val); + if (ret) { + dev_err(led_cdev->dev, + "Error setting brightness: %d\n", ret); + return; + } + } + + /* Must write mode again to change to set color */ + write_to_ec(AYN_RGB_EFFECT_REG, AYN_RGB_EFFECT_WRITE); +}; + +/** + * ayn_led_mc_brightness_get() - Get the brightness for the RGB LED. + * + * @led_cdev: Parent LED device for the led_classdev_mc. + * + * Return: Current brightness. + */ +static enum led_brightness ayn_led_mc_brightness_get(struct led_classdev *= led_cdev) +{ + return led_cdev->brightness; +}; + +static struct attribute *ayn_led_mc_attrs[] =3D { + &dev_attr_rgb_effect.attr, + &dev_attr_rgb_effect_index.attr, + NULL, +}; + +static struct attribute_group ayn_led_mc_group =3D { + .attrs =3D ayn_led_mc_attrs, +}; + +struct mc_subled ayn_led_mc_subled_info[] =3D { + { + .color_index =3D LED_COLOR_ID_RED, + .brightness =3D 0, + .intensity =3D 0, + .channel =3D AYN_LED_MC_RED_REG, + }, + { + .color_index =3D LED_COLOR_ID_GREEN, + .brightness =3D 0, + .intensity =3D 0, + .channel =3D AYN_LED_MC_GREEN_REG, + }, + { + .color_index =3D LED_COLOR_ID_BLUE, + .brightness =3D 0, + .intensity =3D 0, + .channel =3D AYN_LED_MC_BLUE_REG, + }, +}; + +struct led_classdev_mc ayn_led_mc =3D { + .led_cdev =3D { + .name =3D "ayn:rgb:joystick_rings", + .brightness =3D 0, + .max_brightness =3D 255, + .brightness_set =3D ayn_led_mc_brightness_set, + .brightness_get =3D ayn_led_mc_brightness_get, + .color =3D LED_COLOR_ID_RGB, + }, + .num_colors =3D ARRAY_SIZE(ayn_led_mc_subled_info), + .subled_info =3D ayn_led_mc_subled_info, +}; + +static int ayn_ec_resume(struct platform_device *pdev) +{ + struct led_classdev *led_cdev =3D drvdata.led_cdev; + int ret; + + ret =3D rgb_effect_write(); + if (ret) + return ret; + + ayn_led_mc_brightness_set(led_cdev, led_cdev->brightness); + + return 0; +} + static int ayn_ec_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; struct device *hwdev; + int ret; + + ret =3D devm_led_classdev_multicolor_register(dev, &ayn_led_mc); + if (ret) + return ret; + + ret =3D devm_device_add_group(ayn_led_mc.led_cdev.dev, &ayn_led_mc_group); + if (ret) + return ret; + + drvdata.led_cdev =3D &ayn_led_mc.led_cdev; + ret =3D rgb_effect_read(); + if (ret) + return ret; =20 hwdev =3D devm_hwmon_device_register_with_info(dev, "aynec", NULL, &ayn_ec_chip_info, @@ -622,6 +904,7 @@ static struct platform_driver ayn_ec_driver =3D { .name =3D "ayn-ec", }, .probe =3D ayn_ec_probe, + .resume =3D ayn_ec_resume, }; =20 static struct platform_device *ayn_ec_device; --=20 2.50.1 From nobody Wed Sep 3 02:36:06 2025 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C47A1F8677; Sat, 26 Jul 2025 03:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501132; cv=none; b=p4ZcX4dS0SchWc/e/xxJKY+b2NZM2Xdbqe9Dx0Au3Ak1HhENERqMkouZ/RBf583nWWuNpSOUYYRMLX/ddNI2qE/rWgb7vF2jHR4K09iwyUUAoC4B4OtRZV9JRmmKjIBnyZJ0yWrnvPCVtpCUkPf6Cje2I3dspjE6+Q4lwwY+5cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753501132; c=relaxed/simple; bh=gBtYcIpRgannJPNmx2mAehywLv3BkRKGhJDDbTI0CHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ssh93N0Bje1VqNtJhYxwWEpVU06LmDgxFbcuA/9aZOx2AGWB6joGFLuOdnlyiqdpviC4SgLZh8am3lDPwpkjmZaltwj8qNmdXtLQudouNaono1kwRQWOdSx/9dy1Fbww0KcTbub/A7aaFP8Vk2oYqeJr9tpRNILXopB9wY/j4YA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=O23NiokP; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O23NiokP" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-748feca4a61so1740971b3a.3; Fri, 25 Jul 2025 20:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753501130; x=1754105930; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yhAfEUFpjFMraUwyhkD2ehWMmDnT/QkqkKRyhC8aN2s=; b=O23NiokPh0BXbpbtO+xZKtry82Dde3kcG9xu3QLiMohwGLHt1fccBNXzi3S4uel96Z 8VWbTj6SEM214BYd+Ct83hB0AsrR6ta+dH88u0Wr/PKYXTCv8EEN0OaAAjwkcYgSbaXP eAmuOZWKG264SsQVSxShcebmQZlsvq1K++hbFS4M3KT26qYC7Ke1OWdi8qVJ6jdpRAeL j4ci5R571CTUG5L44z8+2Vh9dr2b7m72mMtUCuFTlA1FzLlI8gHRU7eKYxH6/KzFmyZK b/uTBLaLhBtp0rqXfekeNWEbuV5LfMNg5/3DNGWIYHzL8Ogw5udWM/ws5lxEZF7lr86Q pYOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753501130; x=1754105930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yhAfEUFpjFMraUwyhkD2ehWMmDnT/QkqkKRyhC8aN2s=; b=Axtkgv6Y3NpnFxMb1ezTbNHd4My4+YPZmJAOg2J07r70HoOW5DW1lc/8OnKczwesZg 6w83z64571obN5FJFwy5cPuS4p4AnWXWwoQvXUmza+azyW052vBfFKsEE4kK4JbFAUYm Oho0bxjy2swEQlckuOgMJ6CxrVXt4OYuz/+er7WMZc96ckWyd9YEl1A5hZ24EYCPjwDV HjScSa0CmereexgjZhQfzNtBo1ouGVR96PtdQOOSvonGtQLJbmG4G0YY0pyCxMyaa9T3 cPokluQsn0nrUXfU2PPFKeRLKL2jHnblRJEHJ4egzcQhrhNLWbS2lOoDk5BW4aUD10FM r+RA== X-Forwarded-Encrypted: i=1; AJvYcCUhormHRQnpuz6fDbKNl22g777Htp4Sglrn007RHzzVSFoZM23hokYAxrFKdggRWy7Oh92dFI3S8Fc/MsM=@vger.kernel.org, AJvYcCX5AcKS5KuN7ciZ7Eb9dsri2C59ICYm9IglJAS3fTQdDWef444vOMmQPtok9gL0DWjaMtPmWUG8SVA=@vger.kernel.org, AJvYcCXM3u7oyUvZWR/el/1fvzIFFGlGtZSJHSJWABKVa6/YT4y28dAxM148+HrWAbzeyGWip2vb2PxeszTDcg96xOAbP3IH4Q==@vger.kernel.org, AJvYcCXRoXbh8iXoxRNf3yC3cfikpqV7RB+uWxdcUhdTMwTN0SkEUqsb49c0TWhkXxfkDZWfya5JX8pMMd4iitn3@vger.kernel.org X-Gm-Message-State: AOJu0Yzj5hF0mAkdNd9jaaYfVA/5rgag1v09y7GWdMIHxaybOJo3zAxm xrWuQ/aZhhzAarRS4oSy6YvXTm9ksfI5bLLB9dZxxivwMxM5TcnAlSlF X-Gm-Gg: ASbGnctMEkozAdcFMvH2XwWDEnrzzQsC1y2uZREYrjNIn6dYJ+qa9Rg+QkgMFDx2vlT EBiUCCf5cOcfLuQye4XJUp1ovHB/AtinC1hb0qsFkgx4aTw7MBxoZXtCpF4nnx+5AfHr62U87vG GjZ/9P3uQciUyEAYHRRz7qvHCMjVAJEU6WtvSH+kJdLNJKzjWtLCxR7yemIqsiZoaj6uiDydGuJ OA1+/YH/Oq1aiRYMcJJyiZ7B6/HTZZSB12b54MR10Mj0UZYWnPDC94f9G8MCcdi0fDjGBk6SYE2 Uey4dgnEaUABMnXdlsCIIDCCm4EKuBVq6wLMYGQQ6dyFnm4z1yfxy4z4yXQnj+FfBMDrbnTwbye J+a6TOYaLM7ExcjtvHgYqZkzWeZ1qq4fXEFSCW+ekn1bjQw5yw1OGkdj9dNy5zMcpg4c+kgbHKG nNEA== X-Google-Smtp-Source: AGHT+IEOI7ZTSmj8OclQ2OLzg1WH0d8Hd+3i7+/AURRay8pA5DXbxcWgY34GMcmdo6ZKTuBheOpKfg== X-Received: by 2002:a05:6a21:62c9:b0:23d:781f:1516 with SMTP id adf61e73a8af0-23d781f2791mr4979045637.22.1753501129715; Fri, 25 Jul 2025 20:38:49 -0700 (PDT) Received: from bliptop (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31e832f8942sm779204a91.4.2025.07.25.20.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jul 2025 20:38:49 -0700 (PDT) From: "Derek J. Clark" To: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Jean Delvare , Guenter Roeck , Alok Tiwari , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 4/4] platform/x86: (ayn-ec) Add Ayn EC Platform Documentation Date: Fri, 25 Jul 2025 20:38:41 -0700 Message-ID: <20250726033841.7474-5-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250726033841.7474-1-derekjohn.clark@gmail.com> References: <20250726033841.7474-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds ABI documentation for the ayn-ec platform driver Signed-off-by: Derek J. Clark --- .../ABI/testing/sysfs-platform-ayn-ec | 59 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 60 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-ayn-ec diff --git a/Documentation/ABI/testing/sysfs-platform-ayn-ec b/Documentatio= n/ABI/testing/sysfs-platform-ayn-ec new file mode 100644 index 000000000000..cba68b0870ea --- /dev/null +++ b/Documentation/ABI/testing/sysfs-platform-ayn-ec @@ -0,0 +1,59 @@ +What: /sys/class/hwmon/hwmon[0-9]/pwm1_enable +Date: July 2025 +KernelVersion: 6.17 +Contact: "Derek J. Clark" +Description: + This sets the PWM fan mode of operation. Valid values are [0-3]. + Values [0-2] conform with standard hwmon operating modes. Value 3 + enables user defined fan curve settings. + + Applies to Ayn Loki and Toctoy Zeenix lines of handheld devices. + +What: /sys/class/hwmon/hwmon[0-9]/pwm1_auto_point[1-5]_pwm +Date: July 2025 +KernelVersion: 6.17 +Contact: "Derek J. Clark" +Description: + This sets the PWM fan duty cycle for the given index of the fan curve. + When the temperature reaches the corresponding pwm1_auto_point[1-5]_te= mp, + the EC will automatically increase the fan duty cycle to the given val= ue. + + Values are [0-255] + + Applies to Ayn Loki and Toctoy Zeenix lines of handheld devices. + +What: /sys/class/hwmon/hwmon[0-9]/pwm1_auto_point[1-5]_temp +Date: July 2025 +KernelVersion: 6.17 +Contact: "Derek J. Clark" +Description: + This sets the activation temperature for the given index of the fan curv= e. + When the temperature reaches the given value, the EC will automatically + increase the fan duty cycle to the corresponding pwm1_auto_point[1-5]_= pwm + value. + + Values are [0-100] + + Applies to Ayn Loki and Toctoy Zeenix lines of handheld devices. + +What: /sys/class/leds/ayn:rgb:joystick_rings/effect +Date: July 2025 +KernelVersion: 6.17 +Contact: "Derek J. Clark" +Description: + This controls the display effect of the RGB interface. + + Values are monocolor or breathe. + + Applies to Ayn Loki and Toctoy Zeenix lines of handheld devices. + +What: /sys/class/leds/ayn:rgb:joystick_rings/effect_index +Date: July 2025 +KernelVersion: 6.17 +Contact: "Derek J. Clark" +Description: + This displays the available options for the effect attribute. + + Values are monocolor or breathe. + + Applies to Ayn Loki and Toctoy Zeenix lines of handheld devices. diff --git a/MAINTAINERS b/MAINTAINERS index 5b816883fe7d..199bebbffa0d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4039,6 +4039,7 @@ AYN PLATFORM EC DRIVER M: Derek J. Clark L: platform-driver-x86@vger.kernel.org S: Maintained +F: Documentation/ABI/testing/sysfs-platform-ayn-ec F: drivers/platform/x86/ayn-ec.c =20 AZ6007 DVB DRIVER --=20 2.50.1