/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright 2020 Google, LLC * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #ifndef __GOOGLE_DC_PPS_H_ #define __GOOGLE_DC_PPS_H_ #include #include #include #define PD_T_PPS_TIMEOUT 9000 /* Maximum of 10 seconds */ #define PD_T_PPS_DEADLINE_S 7 #define PPS_KEEP_ALIVE_MAX 3 #define PPS_ERROR_RETRY_MS 1000 #define CHG_PPS_VOTER "pps_chg" /* * There is a similar one in tcpm.c * NOTE: we don't really need to replicate the values in tcpm.c in the * internal state, we just need to know to set 2 to the TCPM power supply * to enable PPS. */ enum pps_psy_online_states { PPS_PSY_OFFLINE = 0, PPS_PSY_FIXED_ONLINE, PPS_PSY_PROG_ONLINE, }; enum pd_pps_stage { PPS_NOTSUPP = -1, /* tried and failed or disconnected */ PPS_DISABLED = 0, /* default state, never tried */ PPS_NONE, /* try to enable */ PPS_AVAILABLE, PPS_ACTIVE, }; enum pd_nr_pdo { PDO_FIXED_5V = 1, PDO_FIXED_HIGH_VOLTAGE, PDO_PPS, PDO_MAX_SUPP = PDO_PPS, PDO_MAX = PDO_MAX_OBJECTS, /* 7 */ }; struct pd_pps_data { struct power_supply *pps_psy; void *port_data; struct wakeup_source *pps_ws; bool stay_awake; int nr_src_cap; u32 *src_caps; u32 snk_pdo[PDO_MAX_OBJECTS]; unsigned int nr_snk_pdo; u32 default_pps_pdo; int pd_online; enum pd_pps_stage stage; unsigned int keep_alive_cnt; ktime_t last_update; /* from TA */ int min_uv; int max_uv; int max_ua; /* to TA */ int out_uv; int op_ua; /* logging client */ struct logbuffer *log; }; /* TODO: device dependent */ #define PD_SNK_MAX_MV 9000 /* TODO: device dependent */ #define PD_SNK_MIN_MV 5000 struct tcpm_port; struct tcpm_port *chg_get_tcpm_port(struct power_supply *tcpm_psy); /* */ #define pps_is_disabled(x) (((x) == PPS_NOTSUPP) || ((x) == PPS_DISABLED)) #define pps_name(pps_psy) \ ((pps_psy) && (pps_psy)->desc && (pps_psy)->desc->name ? \ (pps_psy)->desc->name : "<>") struct dentry; int pps_init(struct pd_pps_data *pps_data, struct device *dev, struct power_supply *pps_psy, const char *pps_ws_name); int pps_init_fs(struct pd_pps_data *pps_data, struct dentry *de); /* reset state and leave in DISABLED */ void pps_init_state(struct pd_pps_data *pps_data); /* free resources */ void pps_free(struct pd_pps_data *pps_data); /* Run the PPS state machine */ int pps_work(struct pd_pps_data *pps, struct power_supply *tcpm_psy); /* rougly equivalent */ int pps_ping(struct pd_pps_data *pps, struct power_supply *tcpm_psy); int pps_keep_alive(struct pd_pps_data *pps, struct power_supply *tcpm_psy); /* update the PPS adapter */ int pps_update_adapter(struct pd_pps_data *pps_data, int pending_uv, int pending_ua, struct power_supply *tcpm_psy); int pps_check_adapter(struct pd_pps_data *pps, int pending_uv, int pending_ua, struct power_supply *tcpm_psy); /* */ int pps_prog_offline(struct pd_pps_data *pps, struct power_supply *tcpm_psy); void pps_adjust_volt(struct pd_pps_data *pps, int mod); int chg_switch_profile(struct pd_pps_data *pps, struct power_supply *tcpm_psy, bool more_pwr); int pps_get_apdo_max_power(struct pd_pps_data *pps, unsigned int *ta_idx, unsigned int *ta_max_vol, unsigned int *ta_max_cur, unsigned long *ta_max_pwr); bool pps_check_prog_online(struct pd_pps_data *pps_data); bool pps_prog_check_online(struct pd_pps_data *pps_data, struct power_supply *tcpm_psy); int pps_get_src_cap(struct pd_pps_data *pps, struct power_supply *tcpm_psy); void pps_set_logbuffer(struct pd_pps_data *pps_data, struct logbuffer *log); void pps_log(struct pd_pps_data *pps, const char *fmt, ...); /* probe */ struct power_supply *pps_get_tcpm_psy(struct device_node *node, size_t size); int pps_request_pdo(struct pd_pps_data *pps_data, unsigned int ta_idx, unsigned int ta_max_vol, unsigned int ta_max_cur); #endif /* __GOOGLE_DC_PPS_H_ */