Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
tcpm.h
1/* Copyright 2015 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6/* USB Power delivery port management - common header for TCPM drivers */
7
8#ifndef __CROS_EC_USB_PD_TCPM_TCPM_H
9#define __CROS_EC_USB_PD_TCPM_TCPM_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include "../drivers/tcpm_driver.h"
16#include "usb_pd_tcpm.h"
17
18#include "../config.h"
19
20#if defined(CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE) && !defined(CONFIG_USB_PD_DUAL_ROLE)
21#error "DRP auto toggle requires board to have DRP support"
22#error "Please upgrade your board configuration"
23#endif
24
25#ifndef CONFIG_USB_PD_TCPC
26 extern const struct tcpc_config_t tcpc_config;
27
28 /* I2C wrapper functions - get I2C port / slave addr from config struct. */
29 int tcpc_write(int reg, int val);
30 int tcpc_read(int reg, int* val);
31 int tcpc_xfer(const uint8_t* out, int out_size, uint8_t* in, int in_size, int flags);
32 int tcpc_xfer_unlocked(const uint8_t* out, int out_size, uint8_t* in, int in_size, int flags);
33 void tcpc_lock(int lock);
34
35 /* TCPM driver wrapper function */
36 static inline int tcpm_init()
37 {
38 int rv;
39
40 rv = tcpc_config.drv->init();
41 if (rv)
42 return rv;
43
44 /* Board specific post TCPC init */
45 if (board_tcpc_post_init)
46 rv = board_tcpc_post_init();
47
48 return rv;
49 }
50
51 static inline int tcpm_release() { return tcpc_config.drv->release(); }
52
53 static inline int tcpm_get_cc(enum tcpc_cc_voltage_status* cc1, enum tcpc_cc_voltage_status* cc2)
54 {
55 return tcpc_config.drv->get_cc(cc1, cc2);
56 }
57
58 static inline int tcpm_get_vbus_level(enum vbus_level level)
59 {
60 if (tcpc_config.drv->get_vbus_level)
61 return tcpc_config.drv->get_vbus_level(level);
62 // return 0 instead of a ptentially confusing error
63 return 0;
64 }
65
66 static inline int tcpm_get_vbus_voltage()
67 {
68 // TODO: check returned error
69 int vbus = 0;
70 if (tcpc_config.drv->get_vbus_voltage)
71 {
72 tcpc_config.drv->get_vbus_voltage(&vbus);
73 }
74 return vbus;
75 }
76
77 static inline int tcpm_select_rp_value(int rp) { return tcpc_config.drv->select_rp_value(rp); }
78
79 static inline int tcpm_set_cc(int pull) { return tcpc_config.drv->set_cc(pull); }
80
81 static inline int tcpm_set_polarity(enum tcpc_cc_polarity polarity)
82 {
83 return tcpc_config.drv->set_polarity(polarity);
84 }
85
86 static inline int tcpm_set_vconn(int enable) { return tcpc_config.drv->set_vconn(enable); }
87
88 static inline int tcpm_set_msg_header(int power_role, int data_role)
89 {
90 return tcpc_config.drv->set_msg_header(power_role, data_role);
91 }
92
93 static inline int tcpm_set_rx_enable(int enable) { return tcpc_config.drv->set_rx_enable(enable); }
94
95 static inline void tcpm_enable_auto_discharge_disconnect(int enable)
96 {
97 const struct tcpm_drv* tcpc = tcpc_config.drv;
98
101 }
102
103 static inline int tcpm_get_message(uint32_t* payload, uint32_t* head)
104 {
105 return tcpc_config.drv->get_message(payload, head);
106 }
107
108 static inline int tcpm_transmit(enum tcpm_transmit_type type, uint16_t header, const uint32_t* data)
109 {
110 return tcpc_config.drv->transmit(type, header, data);
111 }
112
113 static inline void tcpc_alert() { tcpc_config.drv->tcpc_alert(); }
114
115 static inline void tcpc_discharge_vbus(int enable) { tcpc_config.drv->tcpc_discharge_vbus(enable); }
116
117#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
118 static inline int tcpm_auto_toggle_supported() { return !!tcpc_config.drv->drp_toggle; }
119
120 static inline int tcpm_enable_drp_toggle() { return tcpc_config.drv->drp_toggle(); }
121#endif
122
123#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
124 static inline int tcpm_enter_low_power_mode() { return tcpc_config.drv->enter_low_power_mode(); }
125#else
126 int tcpm_enter_low_power_mode();
127#endif
128
129#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
130 static inline int tcpc_i2c_read(const const int addr, const int reg, int* data) { return tcpc_read(reg, data); }
131
132 static inline int tcpc_i2c_write(const const int addr, const int reg, int data) { return tcpc_write(reg, data); }
133#endif
134
135 static inline int tcpm_get_chip_info(int renew, struct ec_response_pd_chip_info** info)
136 {
137 if (tcpc_config.drv->get_chip_info)
138 return tcpc_config.drv->get_chip_info(renew, info);
139 return EC_ERROR_UNIMPLEMENTED;
140 }
141
142#else
143
151int tcpm_init();
152
162int tcpm_get_cc(int* cc1, int* cc2);
163
171int tcpm_get_vbus_level(enum vbus_level level);
172
181int tcpm_select_rp_value(int rp);
182
191int tcpm_set_cc(int pull);
192
201int tcpm_set_polarity(int polarity);
202
211int tcpm_set_vconn(int enable);
212
222int tcpm_set_msg_header(int power_role, int data_role);
223
232int tcpm_set_rx_enable(int enable);
233
243int tcpm_get_message(uint32_t* payload, int* head);
244
256int tcpm_transmit(enum tcpm_transmit_type type, uint16_t header, const uint32_t* data);
257
263void tcpc_alert();
264
265#endif
266
267#ifdef __cplusplus
268}
269#endif
270
271#endif
Definition: usb_pd_tcpm.h:87
Definition: usb_pd_tcpm.h:548
Definition: usb_pd_tcpm.h:268
int(* select_rp_value)(int rp)
Definition: usb_pd_tcpm.h:322
int(* get_chip_info)(int live, struct ec_response_pd_chip_info **info)
Definition: usb_pd_tcpm.h:457
int(* set_vconn)(int enable)
Definition: usb_pd_tcpm.h:363
int(* set_rx_enable)(int enable)
Definition: usb_pd_tcpm.h:380
int(* get_vbus_level)(enum vbus_level level)
Definition: usb_pd_tcpm.h:303
int(* set_msg_header)(int power_role, int data_role)
Definition: usb_pd_tcpm.h:373
int(* init)()
Definition: usb_pd_tcpm.h:276
int(* transmit)(enum tcpm_transmit_type type, uint16_t header, const uint32_t *data)
Definition: usb_pd_tcpm.h:403
void(* tcpc_enable_auto_discharge_disconnect)(int enable)
Definition: usb_pd_tcpm.h:423
void(* tcpc_alert)()
Definition: usb_pd_tcpm.h:409
void(* tcpc_discharge_vbus)(int enable)
Definition: usb_pd_tcpm.h:416
int(* get_cc)(enum tcpc_cc_voltage_status *cc1, enum tcpc_cc_voltage_status *cc2)
Definition: usb_pd_tcpm.h:294
int(* enter_low_power_mode)()
Definition: usb_pd_tcpm.h:509
int(* get_vbus_voltage)(int *vbus)
Definition: usb_pd_tcpm.h:313
int(* release)()
Definition: usb_pd_tcpm.h:284
int(* get_message)(uint32_t *payload, uint32_t *head)
Definition: usb_pd_tcpm.h:391
int(* set_cc)(int pull)
Definition: usb_pd_tcpm.h:331
int(* set_polarity)(enum tcpc_cc_polarity polarity)
Definition: usb_pd_tcpm.h:340
int(* drp_toggle)()
Definition: usb_pd_tcpm.h:446