Skip to content

Commit c55a8e2

Browse files
Cryolitiagroeck
authored andcommitted
hwmon: (gpd-fan) initialize EC on driver load for Win 4
The original implement will re-init the EC when it reports a zero value, and it's a workaround for the black box buggy firmware. Now a contributer test and report that, the bug is that, the firmware won't initialize the EC on boot, so the EC ramains in unusable status. And it won't need to re-init it during runtime. The original implement is not perfect, any write command will be ignored until we first read it. Just re-init it unconditionally when the driver load could work. Fixes: 0ab88e2 ("hwmon: add GPD devices sensor driver") Co-developed-by: kylon <[email protected]> Signed-off-by: kylon <[email protected]> Link: Cryolitia/gpd-fan-driver#20 Signed-off-by: Cryolitia PukNgae <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 9efb297 commit c55a8e2

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

drivers/hwmon/gpd-fan.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -276,31 +276,6 @@ static int gpd_generic_read_rpm(void)
276276
return (u16)high << 8 | low;
277277
}
278278

279-
static void gpd_win4_init_ec(void)
280-
{
281-
u8 chip_id, chip_ver;
282-
283-
gpd_ecram_read(0x2000, &chip_id);
284-
285-
if (chip_id == 0x55) {
286-
gpd_ecram_read(0x1060, &chip_ver);
287-
gpd_ecram_write(0x1060, chip_ver | 0x80);
288-
}
289-
}
290-
291-
static int gpd_win4_read_rpm(void)
292-
{
293-
int ret;
294-
295-
ret = gpd_generic_read_rpm();
296-
297-
if (ret == 0)
298-
// Re-init EC when speed is 0
299-
gpd_win4_init_ec();
300-
301-
return ret;
302-
}
303-
304279
static int gpd_wm2_read_rpm(void)
305280
{
306281
for (u16 pwm_ctr_offset = GPD_PWM_CTR_OFFSET;
@@ -320,11 +295,10 @@ static int gpd_wm2_read_rpm(void)
320295
static int gpd_read_rpm(void)
321296
{
322297
switch (gpd_driver_priv.drvdata->board) {
298+
case win4_6800u:
323299
case win_mini:
324300
case duo:
325301
return gpd_generic_read_rpm();
326-
case win4_6800u:
327-
return gpd_win4_read_rpm();
328302
case win_max_2:
329303
return gpd_wm2_read_rpm();
330304
}
@@ -607,6 +581,28 @@ static struct hwmon_chip_info gpd_fan_chip_info = {
607581
.info = gpd_fan_hwmon_channel_info
608582
};
609583

584+
static void gpd_win4_init_ec(void)
585+
{
586+
u8 chip_id, chip_ver;
587+
588+
gpd_ecram_read(0x2000, &chip_id);
589+
590+
if (chip_id == 0x55) {
591+
gpd_ecram_read(0x1060, &chip_ver);
592+
gpd_ecram_write(0x1060, chip_ver | 0x80);
593+
}
594+
}
595+
596+
static void gpd_init_ec(void)
597+
{
598+
// The buggy firmware won't initialize EC properly on boot.
599+
// Before its initialization, reading RPM will always return 0,
600+
// and writing PWM will have no effect.
601+
// Initialize it manually on driver load.
602+
if (gpd_driver_priv.drvdata->board == win4_6800u)
603+
gpd_win4_init_ec();
604+
}
605+
610606
static int gpd_fan_probe(struct platform_device *pdev)
611607
{
612608
struct device *dev = &pdev->dev;
@@ -634,6 +630,8 @@ static int gpd_fan_probe(struct platform_device *pdev)
634630
return dev_err_probe(dev, PTR_ERR(hwdev),
635631
"Failed to register hwmon device\n");
636632

633+
gpd_init_ec();
634+
637635
return 0;
638636
}
639637

0 commit comments

Comments
 (0)