From patchwork Tue Mar 11 16:54:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 872728 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 AC5C82620E3; Tue, 11 Mar 2025 16:54:34 +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=1741712076; cv=none; b=R4rpumISECZTb96aajtT8mFj4h/83jEEBamGP/9Q2TJMIViE8HNPQa624VtOFcM1JgBDCQfiI03IfHWLQ3zpYqPmSCMixTlfieguXhoaTp6O140xA5p869HxbJsQbDYcU+ROEuU7xpJ1HiZWeC8axP61AKU/BH8flxhyla1tqHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741712076; c=relaxed/simple; bh=VLFa8EV8zFRjutFhpZFmFK/wykFjdgD0m4TeWDJEUe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Djid+/UUz+99zNbzmJrCS0sGQbRuMLe4O/vwTTgsEYuQEs8zisOZVp0gwryevHf+yHiJCWY2NjUWIsA+ajYGKGA/wDD1HENTgdzPtnNNbIB26aDKHMFIyYGM98OOpTOYaOnTmUVGNOv8TtoDQoT2uOdQ14jzXxss8H0s6anYoqQ= 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=4+vzOnkN; 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="4+vzOnkN" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 1DF622E0922D; Tue, 11 Mar 2025 18:54:31 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1741712072; bh=aKRcxZJKN4w8n1EXAOzcnTCprELfbGXy5KJlVyjiz1I=; h=From:To:Subject; b=4+vzOnkN/4M2oCKThN3RntDrTg2hiC7I0nIkpF1M+oRV+2puozEncodn307bKPmKU QyIjY39BsM+ytSzvZlLRw+s1iluEBlVxFxhFbJ+zUHebpiso1XmpNY0cD3PxiWZAgG QVVhWLmiPRonHWpUUIqTjWNQ3tolxP1Wh0lImHUI= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org Cc: linux-hwmon@vger.kernel.org, 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 v4 12/13] platform/x86: oxpec: Adhere to sysfs-class-hwmon and enable pwm on 2 Date: Tue, 11 Mar 2025 17:54:04 +0100 Message-ID: <20250311165406.331046-13-lkml@antheas.dev> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311165406.331046-1-lkml@antheas.dev> References: <20250311165406.331046-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: <174171207237.20184.7101578828806063175@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, the driver does not adhere to the sysfs-class-hwmon specification: 0 is used for auto fan control and 1 is used for manual control. However, it is expected that 0 sets the fan to full speed, 1 sets the fan to manual, and then 2 is used for automatic control. Therefore, change the sysfs API to reflect this and enable pwm on 2. As we are breaking the ABI for this driver, rename oxpec to oxp_ec, reflecting the naming convention used by other drivers, to allow for a smooth migration in current userspace programs. Closes: https://lore.kernel.org/linux-hwmon/20241027174836.8588-1-derekjohn.clark@gmail.com/ Reviewed-by: Derek J. Clark Signed-off-by: Antheas Kapenekakis --- drivers/platform/x86/oxpec.c | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/oxpec.c b/drivers/platform/x86/oxpec.c index 97dc7b7c70c7..273589f8b2fa 100644 --- a/drivers/platform/x86/oxpec.c +++ b/drivers/platform/x86/oxpec.c @@ -938,7 +938,27 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, case hwmon_pwm_input: return oxp_pwm_input_read(val); case hwmon_pwm_enable: - return oxp_pwm_read(val); + ret = oxp_pwm_read(val); + if (ret) + return ret; + + /* Check for auto and return 2 */ + if (!*val) { + *val = 2; + return 0; + } + + /* Return 0 if at full fan speed, 1 otherwise */ + ret = oxp_pwm_fan_speed(val); + if (ret) + return ret; + + if (*val == 255) + *val = 0; + else + *val = 1; + + return 0; default: break; } @@ -952,15 +972,24 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { + int ret; + switch (type) { case hwmon_pwm: switch (attr) { case hwmon_pwm_enable: if (val == 1) return oxp_pwm_enable(); - else if (val == 0) + else if (val == 2) return oxp_pwm_disable(); - return -EINVAL; + else if (val != 0) + return -EINVAL; + + /* Enable PWM and set to max speed */ + ret = oxp_pwm_enable(); + if (ret) + return ret; + return oxp_pwm_input_write(255); case hwmon_pwm_input: return oxp_pwm_input_write(val); default: @@ -1025,7 +1054,7 @@ static int oxp_platform_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device *hwdev; - hwdev = devm_hwmon_device_register_with_info(dev, "oxpec", NULL, + hwdev = devm_hwmon_device_register_with_info(dev, "oxp_ec", NULL, &oxp_ec_chip_info, NULL); if (charge_behaviour_supported())