linux-loongson/include/linux/platform_data/huawei-gaokun-ec.h
Pengyu Luo 7636f090d0
platform: arm64: add Huawei Matebook E Go EC driver
There are three variants of which Huawei released the first two
simultaneously.

Huawei Matebook E Go LTE(sc8180x), codename seems to be gaokun2.
Huawei Matebook E Go(sc8280xp@3.0GHz), codename must be gaokun3. (see [1])
Huawei Matebook E Go 2023(sc8280xp@2.69GHz), codename should be also gaokun3.

Adding support for the latter two variants for now, this driver should
also work for the sc8180x variant according to acpi table files, but I
don't have the device to test yet.

Different from other Qualcomm Snapdragon sc8280xp based machines, the
Huawei Matebook E Go uses an embedded controller while others use
a system called PMIC GLink. This embedded controller can be used to
perform a set of various functions, including, but not limited to:

- Battery and charger monitoring;
- Charge control and smart charge;
- Fn_lock settings;
- Tablet lid status;
- Temperature sensors;
- USB Type-C notifications (ports orientation,  DP alt mode HPD);
- USB Type-C PD (according to observation, up to 48w).

Add a driver for the EC which creates devices for UCSI and power supply
devices.

This driver is inspired by the following drivers:
        drivers/platform/arm64/acer-aspire1-ec.c
        drivers/platform/arm64/lenovo-yoga-c630.c
        drivers/platform/x86/huawei-wmi.c

Also thanks for reviewers' working. They have made this patch improve
a lot.

[1] https://bugzilla.kernel.org/show_bug.cgi?id=219645

Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20250214180656.28599-3-mitltlatltl@gmail.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
2025-03-03 10:55:36 +02:00

80 lines
2.6 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Huawei Matebook E Go Embedded Controller
*
* Copyright (C) 2024-2025 Pengyu Luo <mitltlatltl@gmail.com>
*/
#ifndef __HUAWEI_GAOKUN_EC_H__
#define __HUAWEI_GAOKUN_EC_H__
#define GAOKUN_UCSI_CCI_SIZE 4
#define GAOKUN_UCSI_MSGI_SIZE 16
#define GAOKUN_UCSI_READ_SIZE (GAOKUN_UCSI_CCI_SIZE + GAOKUN_UCSI_MSGI_SIZE)
#define GAOKUN_UCSI_WRITE_SIZE 24 /* 8B CTRL, 16B MSGO */
#define GAOKUN_UCSI_NO_PORT_UPDATE (-1)
#define GAOKUN_SMART_CHARGE_DATA_SIZE 4 /* mode, delay, start, end */
/* -------------------------------------------------------------------------- */
struct gaokun_ec;
struct gaokun_ucsi_reg;
struct notifier_block;
#define GAOKUN_MOD_NAME "huawei_gaokun_ec"
#define GAOKUN_DEV_PSY "psy"
#define GAOKUN_DEV_UCSI "ucsi"
/* -------------------------------------------------------------------------- */
/* Common API */
int gaokun_ec_register_notify(struct gaokun_ec *ec,
struct notifier_block *nb);
void gaokun_ec_unregister_notify(struct gaokun_ec *ec,
struct notifier_block *nb);
int gaokun_ec_read(struct gaokun_ec *ec, const u8 *req,
size_t resp_len, u8 *resp);
int gaokun_ec_write(struct gaokun_ec *ec, const u8 *req);
int gaokun_ec_read_byte(struct gaokun_ec *ec, const u8 *req, u8 *byte);
/* -------------------------------------------------------------------------- */
/* API for PSY */
int gaokun_ec_psy_multi_read(struct gaokun_ec *ec, u8 reg,
size_t resp_len, u8 *resp);
static inline int gaokun_ec_psy_read_byte(struct gaokun_ec *ec,
u8 reg, u8 *byte)
{
return gaokun_ec_psy_multi_read(ec, reg, sizeof(*byte), byte);
}
static inline int gaokun_ec_psy_read_word(struct gaokun_ec *ec,
u8 reg, u16 *word)
{
return gaokun_ec_psy_multi_read(ec, reg, sizeof(*word), (u8 *)word);
}
int gaokun_ec_psy_get_smart_charge(struct gaokun_ec *ec,
u8 resp[GAOKUN_SMART_CHARGE_DATA_SIZE]);
int gaokun_ec_psy_set_smart_charge(struct gaokun_ec *ec,
const u8 req[GAOKUN_SMART_CHARGE_DATA_SIZE]);
int gaokun_ec_psy_get_smart_charge_enable(struct gaokun_ec *ec, bool *on);
int gaokun_ec_psy_set_smart_charge_enable(struct gaokun_ec *ec, bool on);
/* -------------------------------------------------------------------------- */
/* API for UCSI */
int gaokun_ec_ucsi_read(struct gaokun_ec *ec, u8 resp[GAOKUN_UCSI_READ_SIZE]);
int gaokun_ec_ucsi_write(struct gaokun_ec *ec,
const u8 req[GAOKUN_UCSI_WRITE_SIZE]);
int gaokun_ec_ucsi_get_reg(struct gaokun_ec *ec, struct gaokun_ucsi_reg *ureg);
int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id);
#endif /* __HUAWEI_GAOKUN_EC_H__ */