From patchwork Thu Dec 26 11:27:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 853793 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (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 31F121D318F; Thu, 26 Dec 2024 11:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212480; cv=none; b=doxfYgi0DJtcEvt8hynZZIK5Qa+btAu690nEOyhFWNrF9S2GpLEwtvnyRzIU5u4D5ziaf0+nz9jjTzgy8UuXvKY9Ax1ZwQvNjheU4pInPvOo7ltGHmDWaprMQSGprWSZ0Ktevyh8gZOtBDhRi9C7ZYi4SbgSKpST/NUtEXQ4Sdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735212480; c=relaxed/simple; bh=keObh7z3hbPSSGQepUH+MprYhQhX645L9LmRefnzxqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r2h+jp6piTCRLS1HsK1+FsJNwbccKBWJ+vqDuJ686B+kKkGvDFyIGPbIBe9az5/5fgcH5N3qchYgTuAqREF6as7a4q6CxOTRV4EFll4AMGTKE+iWsJCjtr0x85V2zsj7wXFhl7c7jvFS8352clK/js6bF4U5fJxP6CgzAnv7VtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=0scUV1if; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="0scUV1if" Received: from localhost.localdomain (unknown [IPv6:2a02:2149:8b14:7c00:7f68:a54:8871:387f]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 812A22E00D18; Thu, 26 Dec 2024 13:27:50 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1735212471; bh=nkq3TmKJP5/w+xBCL2mMJoQYmA07vG9AluzBr/2uTKA=; h=From:To:Subject; b=0scUV1ifxC3YgbjfTcN/b/Jv88QRnhBHTiEbE5qr396+gdGlZbVAzOSzg5t5WS1tw PoWQok2LaGii+Jjq/DQ9aG+Z06oW4BJVKJZ7Gk8HczWw1SYW9gjVQbl16WVkAcmY0M MNxLEBYN982ebQP3raujw/Sdg3Ry8hiUfSdl/kro= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a02:2149:8b14:7c00:7f68:a54:8871:387f) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-hwmon@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-pm@vger.kernel.org, Guenter Roeck , Jean Delvare , Jonathan Corbet , Joaquin Ignacio Aramendia , Derek J Clark , Kevin Greenberg , Joshua Tam , Parth Menon , Eileen , Antheas Kapenekakis Subject: [PATCH 06/10] hwmon: (oxp-sensors) Add turbo led support to X1 devices Date: Thu, 26 Dec 2024 12:27:36 +0100 Message-ID: <20241226112740.340804-7-lkml@antheas.dev> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241226112740.340804-1-lkml@antheas.dev> References: <20241226112740.340804-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <173521247118.11073.16534949646201267439@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean The X1 and X1 mini lineups feature an LED nested within their turbo button. When turbo takeover is not enabled, the turbo button allows the device to switch from 18W to 25W TDP. When the device is in the 25W TDP mode, the LED is turned on. However, when we engage turbo takeover, the turbo led remains on its last state, which might be illuminated and cannot be currently controlled. Therefore, add the register that controls it under sysfs, to allow userspace to turn it off once engaging turbo takeover and then control it as they wish. As part of researching this topic, I verified that other OneXPlayer devices do not have a turbo led, which makes this feature only applicable to X1 and X1 mini devices. Signed-off-by: Antheas Kapenekakis --- drivers/hwmon/oxp-sensors.c | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c index 30b7020ea836..850e8d72be1f 100644 --- a/drivers/hwmon/oxp-sensors.c +++ b/drivers/hwmon/oxp-sensors.c @@ -101,6 +101,12 @@ static enum oxp_board board; */ #define OXP_X1_CHARGE_BYPASS_MASK_S3S5 0x02 +/* X1 Turbo LED */ +#define OXP_X1_TURBO_LED_REG 0x57 + +#define OXP_X1_TURBO_LED_OFF 0x01 +#define OXP_X1_TURBO_LED_ON 0x02 + enum charge_type_value_index { CT_OFF, CT_S0, @@ -459,6 +465,73 @@ static ssize_t tt_toggle_show(struct device *dev, static DEVICE_ATTR_RW(tt_toggle); +/* Callbacks for turbo toggle attribute */ +static umode_t tt_led_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + switch (board) { + case oxp_x1: + return attr->mode; + default: + break; + } + return 0; +} + +static ssize_t tt_led_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + u8 reg, val; + int rval; + bool value; + + rval = kstrtobool(buf, &value); + if (rval) + return rval; + + switch (board) { + case oxp_x1: + reg = OXP_X1_TURBO_LED_REG; + val = value ? OXP_X1_TURBO_LED_ON : OXP_X1_TURBO_LED_OFF; + break; + default: + return -EINVAL; + } + rval = write_to_ec(reg, val); + + if (rval) + return rval; + + return count; +} + +static ssize_t tt_led_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int retval; + u8 reg; + long enval; + long val; + + switch (board) { + case oxp_x1: + reg = OXP_2_TURBO_SWITCH_REG; + enval = OXP_X1_TURBO_LED_ON; + break; + default: + return -EINVAL; + } + + retval = read_from_ec(reg, 1, &val); + if (retval) + return retval; + + return sysfs_emit(buf, "%d\n", val == enval); +} + +static DEVICE_ATTR_RW(tt_led); + /* Callbacks for turbo toggle attribute */ static bool charge_control_supported(void) { @@ -887,8 +960,19 @@ static struct attribute_group oxp_tt_toggle_attribute_group = { .attrs = oxp_tt_toggle_attrs, }; +static struct attribute *oxp_tt_led_attrs[] = { + &dev_attr_tt_led.attr, + NULL +}; + +static struct attribute_group oxp_tt_led_attribute_group = { + .is_visible = tt_led_is_visible, + .attrs = oxp_tt_led_attrs, +}; + static const struct attribute_group *oxp_ec_groups[] = { &oxp_tt_toggle_attribute_group, + &oxp_tt_led_attribute_group, NULL };