1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Huawei Matebook E Go Embedded Controller 4 * 5 * Copyright (C) 2024-2025 Pengyu Luo <[email protected]> 6 */ 7 8 #ifndef __HUAWEI_GAOKUN_EC_H__ 9 #define __HUAWEI_GAOKUN_EC_H__ 10 11 #define GAOKUN_UCSI_CCI_SIZE 4 12 #define GAOKUN_UCSI_MSGI_SIZE 16 13 #define GAOKUN_UCSI_READ_SIZE (GAOKUN_UCSI_CCI_SIZE + GAOKUN_UCSI_MSGI_SIZE) 14 #define GAOKUN_UCSI_WRITE_SIZE 24 /* 8B CTRL, 16B MSGO */ 15 16 #define GAOKUN_UCSI_NO_PORT_UPDATE (-1) 17 18 #define GAOKUN_SMART_CHARGE_DATA_SIZE 4 /* mode, delay, start, end */ 19 20 /* -------------------------------------------------------------------------- */ 21 22 struct gaokun_ec; 23 struct gaokun_ucsi_reg; 24 struct notifier_block; 25 26 #define GAOKUN_MOD_NAME "huawei_gaokun_ec" 27 #define GAOKUN_DEV_PSY "psy" 28 #define GAOKUN_DEV_UCSI "ucsi" 29 30 /* -------------------------------------------------------------------------- */ 31 /* Common API */ 32 33 int gaokun_ec_register_notify(struct gaokun_ec *ec, 34 struct notifier_block *nb); 35 void gaokun_ec_unregister_notify(struct gaokun_ec *ec, 36 struct notifier_block *nb); 37 38 int gaokun_ec_read(struct gaokun_ec *ec, const u8 *req, 39 size_t resp_len, u8 *resp); 40 int gaokun_ec_write(struct gaokun_ec *ec, const u8 *req); 41 int gaokun_ec_read_byte(struct gaokun_ec *ec, const u8 *req, u8 *byte); 42 43 /* -------------------------------------------------------------------------- */ 44 /* API for PSY */ 45 46 int gaokun_ec_psy_multi_read(struct gaokun_ec *ec, u8 reg, 47 size_t resp_len, u8 *resp); 48 49 static inline int gaokun_ec_psy_read_byte(struct gaokun_ec *ec, 50 u8 reg, u8 *byte) 51 { 52 return gaokun_ec_psy_multi_read(ec, reg, sizeof(*byte), byte); 53 } 54 55 static inline int gaokun_ec_psy_read_word(struct gaokun_ec *ec, 56 u8 reg, u16 *word) 57 { 58 return gaokun_ec_psy_multi_read(ec, reg, sizeof(*word), (u8 *)word); 59 } 60 61 int gaokun_ec_psy_get_smart_charge(struct gaokun_ec *ec, 62 u8 resp[GAOKUN_SMART_CHARGE_DATA_SIZE]); 63 int gaokun_ec_psy_set_smart_charge(struct gaokun_ec *ec, 64 const u8 req[GAOKUN_SMART_CHARGE_DATA_SIZE]); 65 66 int gaokun_ec_psy_get_smart_charge_enable(struct gaokun_ec *ec, bool *on); 67 int gaokun_ec_psy_set_smart_charge_enable(struct gaokun_ec *ec, bool on); 68 69 /* -------------------------------------------------------------------------- */ 70 /* API for UCSI */ 71 72 int gaokun_ec_ucsi_read(struct gaokun_ec *ec, u8 resp[GAOKUN_UCSI_READ_SIZE]); 73 int gaokun_ec_ucsi_write(struct gaokun_ec *ec, 74 const u8 req[GAOKUN_UCSI_WRITE_SIZE]); 75 76 int gaokun_ec_ucsi_get_reg(struct gaokun_ec *ec, struct gaokun_ucsi_reg *ureg); 77 int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id); 78 79 #endif /* __HUAWEI_GAOKUN_EC_H__ */ 80