diff options
| author | Shih-Yuan Lee <fourdollars@debian.org> | 2026-07-11 17:33:21 +0800 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2026-08-10 08:59:41 -0700 |
| commit | d33baed3fea26756ef3b077347b8da0de3f492f1 (patch) | |
| tree | 64d617a9ecd221e569de4b648b6c7659df5fcedc | |
| parent | 26db273640887276a24ca2546b06e334508871f8 (diff) | |
| download | linux-d33baed3fea26756ef3b077347b8da0de3f492f1.tar.gz linux-d33baed3fea26756ef3b077347b8da0de3f492f1.zip | |
hwmon: (applesmc) Cache fan positions during register initialization
To support the read_string callback for fan labels in the modern HWMON
API, load and cache the fan position names in smcreg.fan_positions
during register initialization.
Pre-pad fallback labels with four spaces to match the "+ 4" pointer
arithmetic offset used by all fan labels in the read_string callback.
Signed-off-by: Shih-Yuan Lee <fourdollars@debian.org>
Link: https://lore.kernel.org/r/20260711093323.14529-2-fourdollars@debian.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
| -rw-r--r-- | drivers/hwmon/applesmc.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index 90a14a7f2c4c..9b2d9ecb20c0 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c @@ -133,6 +133,7 @@ static struct applesmc_registers { bool init_complete; /* true when fully initialized */ struct applesmc_entry *cache; /* cached key entries */ const char **index; /* temperature key index */ + char fan_positions[10][17]; /* cached fan position labels */ } smcreg = { .mutex = __MUTEX_INITIALIZER(smcreg.mutex), }; @@ -566,7 +567,7 @@ static int applesmc_init_smcreg_try(void) { struct applesmc_registers *s = &smcreg; bool left_light_sensor = false, right_light_sensor = false; - unsigned int count; + unsigned int count, i; u8 tmp[1]; int ret; @@ -597,6 +598,16 @@ static int applesmc_init_smcreg_try(void) if (s->fan_count > 10) s->fan_count = 10; + for (i = 0; i < s->fan_count; i++) { + char newkey[5]; + + scnprintf(newkey, sizeof(newkey), FAN_ID_FMT, i); + ret = applesmc_read_key(newkey, s->fan_positions[i], 16); + s->fan_positions[i][16] = 0; + if (ret) + scnprintf(s->fan_positions[i], 17, " Fan %d", i); + } + ret = applesmc_get_lower_bound(&s->temp_begin, "T"); if (ret) return ret; |
