Created
March 22, 2024 03:58
-
-
Save justinweiss/2b23e1e53884acc68838efffcbb27bc4 to your computer and use it in GitHub Desktop.
0001-oxp-sensors-hwmon-Add-GPD-Win-Mini.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 48433f6b5b56fdee0f3c8172e7edba331235d999 Mon Sep 17 00:00:00 2001 | |
From: Justin Weiss <[email protected]> | |
Date: Thu, 21 Mar 2024 20:50:56 -0700 | |
Subject: [PATCH] oxp-sensors: hwmon: Add GPD Win Mini | |
Adds the GPD Win Mini handheld to PWM fan control. The Win Mini | |
has a register for reading fan speed and a register for reading and | |
writing the PWM. It does not have a separate enable register, but | |
treats writing 0 to the PWM as fan auto mode. Values from 1-244 set a | |
manual fan speed, and 245-255 have undetermined behavior. | |
To keep compatibility with existing tools, it will treat setting | |
pwm_enable to 0 as auto mode, 1 will set manual mode at a speed of | |
around 70%. pwm1 will scale internal values 1-244 to 0-255. | |
--- | |
drivers/hwmon/oxp-sensors.c | 41 +++++++++++++++++++++++++++++++++++++ | |
1 file changed, 41 insertions(+) | |
diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c | |
index 3496e514192d..c3a1b10d5772 100644 | |
--- a/drivers/hwmon/oxp-sensors.c | |
+++ b/drivers/hwmon/oxp-sensors.c | |
@@ -46,6 +46,7 @@ enum oxp_board { | |
aya_neo_air_plus_mendo, | |
aya_neo_air_pro, | |
aya_neo_geek, | |
+ gpd_win_mini, | |
orange_pi_neo_01, | |
oxp_mini_amd, | |
oxp_mini_amd_a07, | |
@@ -67,6 +68,16 @@ static enum oxp_board board; | |
#define ORANGEPI_SENSOR_AUTO 0x00 /* Value for fan auto mode */ | |
#define ORANGEPI_SENSOR_MANUAL 0xAA /* Value for fan auto mode */ | |
+/* GPD Win Mini doesn't have a separate enable register for the | |
+ * fan. For the PWM register, 0 is auto, 1-244 is a manual value, and | |
+ * 245-255 are undefined. This driver will scale to 0-255, and treat | |
+ * PWM enable without a value as "set to manual, 70%." | |
+ */ | |
+#define GPD_WIN_MINI_SENSOR_FAN_REG 0x78 /* Fan reading is 2 registers long */ | |
+#define GPD_WIN_MINI_SENSOR_PWM_REG 0x7A /* PWM reading is 1 register long */ | |
+#define GPD_WIN_MINI_SENSOR_AUTO 0x00 /* Value for fan auto mode */ | |
+#define GPD_WIN_MINI_SENSOR_MANUAL 0xAA /* Value for fan manual mode -- 70% */ | |
+ | |
/* Turbo button takeover function | |
* Older boards have different values and EC registers | |
* for the same function | |
@@ -129,6 +140,13 @@ static const struct dmi_system_id dmi_table[] = { | |
}, | |
.driver_data = (void *)aya_neo_geek, | |
}, | |
+ { | |
+ .matches = { | |
+ DMI_MATCH(DMI_BOARD_VENDOR, "GPD"), | |
+ DMI_EXACT_MATCH(DMI_BOARD_NAME, "G1617-01"), | |
+ }, | |
+ .driver_data = (void *)gpd_win_mini, | |
+ }, | |
{ | |
.matches = { | |
DMI_MATCH(DMI_BOARD_VENDOR, "OrangePi"), | |
@@ -314,6 +332,11 @@ static int oxp_pwm_enable(void) | |
switch (board) { | |
case orange_pi_neo_01: | |
return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, ORANGEPI_SENSOR_MANUAL); | |
+ case gpd_win_mini: | |
+ /* GPD Win Mini has no separate enable register. | |
+ * Instead, set the fan to a medium speed | |
+ */ | |
+ return write_to_ec(GPD_WIN_MINI_SENSOR_PWM_REG, GPD_WIN_MINI_SENSOR_MANUAL); | |
case aya_neo_2: | |
case aya_neo_air: | |
case aya_neo_air_plus_mendo: | |
@@ -335,6 +358,8 @@ static int oxp_pwm_disable(void) | |
switch (board) { | |
case orange_pi_neo_01: | |
return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, ORANGEPI_SENSOR_AUTO); | |
+ case gpd_win_mini: | |
+ return write_to_ec(GPD_WIN_MINI_SENSOR_PWM_REG, GPD_WIN_MINI_SENSOR_AUTO); | |
case aya_neo_2: | |
case aya_neo_air: | |
case aya_neo_air_plus_mendo: | |
@@ -376,6 +401,8 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, | |
switch (board) { | |
case orange_pi_neo_01: | |
return read_from_ec(ORANGEPI_SENSOR_FAN_REG, 2, val); | |
+ case gpd_win_mini: | |
+ return read_from_ec(GPD_WIN_MINI_SENSOR_FAN_REG, 2, val); | |
case aya_neo_2: | |
case aya_neo_air: | |
case aya_neo_air_plus_mendo: | |
@@ -403,6 +430,13 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, | |
if (ret) | |
return ret; | |
break; | |
+ case gpd_win_mini: | |
+ ret = read_from_ec(GPD_WIN_MINI_SENSOR_PWM_REG, 1, val); | |
+ if (ret) | |
+ return ret; | |
+ if (*val != GPD_WIN_MINI_SENSOR_AUTO) | |
+ *val = ((*val - 1) * 255) / 243; | |
+ break; | |
case aya_neo_2: | |
case aya_neo_air: | |
case aya_neo_air_plus_mendo: | |
@@ -430,6 +464,10 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type, | |
ret = read_from_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, 1, val); | |
*val = (*val == ORANGEPI_SENSOR_MANUAL); | |
return ret; | |
+ case gpd_win_mini: | |
+ ret = read_from_ec(GPD_WIN_MINI_SENSOR_PWM_REG, 1, val); | |
+ *val = (*val != GPD_WIN_MINI_SENSOR_AUTO); | |
+ return ret; | |
case aok_zoe_a1: | |
case aya_neo_2: | |
case aya_neo_air: | |
@@ -472,6 +510,9 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type, | |
switch (board) { | |
case orange_pi_neo_01: | |
return write_to_ec(ORANGEPI_SENSOR_PWM_REG, val); | |
+ case gpd_win_mini: | |
+ val = (val * 243) / 255 + 1; | |
+ return write_to_ec(GPD_WIN_MINI_SENSOR_PWM_REG, val); | |
case aya_neo_2: | |
case aya_neo_air: | |
case aya_neo_air_plus_mendo: | |
-- | |
2.44.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment