Re: [PATCH] hwmon: gpd-fan: replace custom EC I/O with kernel ec_read/ec_write

From: Cryolitia PukNgae

Date: Thu Feb 26 2026 - 22:03:45 EST


Morduan Zang <zhangdandan@xxxxxxxxxxxxx> 于2026年2月27日周五 10:50写道:
>
> Replace the custom gpd_ecram_read() and gpd_ecram_write() functions that
> use direct I/O port access (inb/outb) with the kernel's standard ec_read()
> and ec_write() functions. This provides better abstraction, improves code
> maintainability, and ensures compatibility across different kernel
> versions.
>
> Signed-off-by: Morduan Zang <zhangdandan@xxxxxxxxxxxxx>
> ---
> drivers/hwmon/gpd-fan.c | 37 +++----------------------------------
> 1 file changed, 3 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/hwmon/gpd-fan.c b/drivers/hwmon/gpd-fan.c
> index 1729729b135f..c44957b7fd91 100644
> --- a/drivers/hwmon/gpd-fan.c
> +++ b/drivers/hwmon/gpd-fan.c
> @@ -19,6 +19,7 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> +#include <linux/acpi.h>
>
> #define DRIVER_NAME "gpdfan"
> #define GPD_PWM_CTR_OFFSET 0x1841
> @@ -243,44 +244,12 @@ static const struct gpd_fan_drvdata *gpd_module_drvdata[] = {
> // Helper functions to handle EC read/write
> static void gpd_ecram_read(u16 offset, u8 *val)
> {
> - u16 addr_port = gpd_driver_priv.drvdata->addr_port;
> - u16 data_port = gpd_driver_priv.drvdata->data_port;
> -
> - outb(0x2E, addr_port);
> - outb(0x11, data_port);
> - outb(0x2F, addr_port);
> - outb((u8)((offset >> 8) & 0xFF), data_port);
> -
> - outb(0x2E, addr_port);
> - outb(0x10, data_port);
> - outb(0x2F, addr_port);
> - outb((u8)(offset & 0xFF), data_port);
> -
> - outb(0x2E, addr_port);
> - outb(0x12, data_port);
> - outb(0x2F, addr_port);
> - *val = inb(data_port);
> + *val = ec_read(offset, val);
> }
>
> static void gpd_ecram_write(u16 offset, u8 value)
> {
> - u16 addr_port = gpd_driver_priv.drvdata->addr_port;
> - u16 data_port = gpd_driver_priv.drvdata->data_port;
> -
> - outb(0x2E, addr_port);
> - outb(0x11, data_port);
> - outb(0x2F, addr_port);
> - outb((u8)((offset >> 8) & 0xFF), data_port);
> -
> - outb(0x2E, addr_port);
> - outb(0x10, data_port);
> - outb(0x2F, addr_port);
> - outb((u8)(offset & 0xFF), data_port);
> -
> - outb(0x2E, addr_port);
> - outb(0x12, data_port);
> - outb(0x2F, addr_port);
> - outb(value, data_port);
> + ec_write(offset, value);
> }
>
> static int gpd_generic_read_rpm(void)
> --
> 2.50.1
>

Why do you send it to my gmail, using uniontech.com which is in the
MAINTAINERS file please.
Have you tested it on a GPD device?

thanks,
Cryolitia PukNgae