Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
usbc_ppc.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_USB_C_USBC_PPC_H_
14#define ZEPHYR_INCLUDE_DRIVERS_USB_C_USBC_PPC_H_
15
22
23#include <zephyr/types.h>
24#include <zephyr/device.h>
25#include <errno.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
57
67typedef void (*usbc_ppc_event_cb_t)(const struct device *dev, void *data, enum usbc_ppc_event ev);
68
74
78__subsystem struct usbc_ppc_driver_api {
80 int (*is_dead_battery_mode)(const struct device *dev);
82 int (*exit_dead_battery_mode)(const struct device *dev);
84 int (*is_vbus_source)(const struct device *dev);
86 int (*is_vbus_sink)(const struct device *dev);
88 int (*set_snk_ctrl)(const struct device *dev, bool enable);
90 int (*set_src_ctrl)(const struct device *dev, bool enable);
92 int (*set_vbus_discharge)(const struct device *dev, bool enable);
94 int (*is_vbus_present)(const struct device *dev);
96 int (*set_event_handler)(const struct device *dev, usbc_ppc_event_cb_t handler, void *data);
98 int (*dump_regs)(const struct device *dev);
99};
100
102
103/*
104 * API functions
105 */
106
116static inline int ppc_is_dead_battery_mode(const struct device *dev)
117{
118 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
119
120 if (api->is_dead_battery_mode == NULL) {
121 return -ENOSYS;
122 }
123
124 return api->is_dead_battery_mode(dev);
125}
126
139static inline int ppc_exit_dead_battery_mode(const struct device *dev)
140{
141 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
142
143 if (api->exit_dead_battery_mode == NULL) {
144 return -ENOSYS;
145 }
146
147 return api->exit_dead_battery_mode(dev);
148}
149
159static inline int ppc_is_vbus_source(const struct device *dev)
160{
161 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
162
163 if (api->is_vbus_source == NULL) {
164 return -ENOSYS;
165 }
166
167 return api->is_vbus_source(dev);
168}
169
179static inline int ppc_is_vbus_sink(const struct device *dev)
180{
181 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
182
183 if (api->is_vbus_sink == NULL) {
184 return -ENOSYS;
185 }
186
187 return api->is_vbus_sink(dev);
188}
189
199static inline int ppc_set_snk_ctrl(const struct device *dev, bool enable)
200{
201 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
202
203 if (api->set_snk_ctrl == NULL) {
204 return -ENOSYS;
205 }
206
207 return api->set_snk_ctrl(dev, enable);
208}
209
219static inline int ppc_set_src_ctrl(const struct device *dev, bool enable)
220{
221 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
222
223 if (api->set_src_ctrl == NULL) {
224 return -ENOSYS;
225 }
226
227 return api->set_src_ctrl(dev, enable);
228}
229
239static inline int ppc_set_vbus_discharge(const struct device *dev, bool enable)
240{
241 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
242
243 if (api->set_vbus_discharge == NULL) {
244 return -ENOSYS;
245 }
246
247 return api->set_vbus_discharge(dev, enable);
248}
249
259static inline int ppc_is_vbus_present(const struct device *dev)
260{
261 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
262
263 if (api->is_vbus_present == NULL) {
264 return -ENOSYS;
265 }
266
267 return api->is_vbus_present(dev);
268}
269
279static inline int ppc_set_event_handler(const struct device *dev,
280 usbc_ppc_event_cb_t handler, void *data)
281{
282 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
283
284 if (api->set_event_handler == NULL) {
285 return -ENOSYS;
286 }
287
288 return api->set_event_handler(dev, handler, data);
289}
290
299static inline int ppc_dump_regs(const struct device *dev)
300{
301 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
302
303 if (api->dump_regs == NULL) {
304 return -ENOSYS;
305 }
306
307 return api->dump_regs(dev);
308}
309
310#ifdef __cplusplus
311}
312#endif
313
317
318#endif /* ZEPHYR_INCLUDE_DRIVERS_USB_C_USBC_PPC_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
System error numbers.
#define ENOSYS
Function not implemented.
Definition errno.h:83
static int ppc_set_event_handler(const struct device *dev, usbc_ppc_event_cb_t handler, void *data)
Set the callback used to notify about PPC events.
Definition usbc_ppc.h:279
usbc_ppc_event
Type of event being notified by Power Path Controller.
Definition usbc_ppc.h:32
static int ppc_is_dead_battery_mode(const struct device *dev)
Check if PPC is in the dead battery mode.
Definition usbc_ppc.h:116
void(* usbc_ppc_event_cb_t)(const struct device *dev, void *data, enum usbc_ppc_event ev)
Callback used to notify about PPC events.
Definition usbc_ppc.h:67
static int ppc_is_vbus_source(const struct device *dev)
Check if the PPC is sourcing the VBUS.
Definition usbc_ppc.h:159
static int ppc_exit_dead_battery_mode(const struct device *dev)
Request the PPC to exit from the dead battery mode Return from this call doesn't mean that the PPC is...
Definition usbc_ppc.h:139
static int ppc_is_vbus_present(const struct device *dev)
Check if VBUS is present.
Definition usbc_ppc.h:259
static int ppc_set_src_ctrl(const struct device *dev, bool enable)
Set the state of VBUS sourcing.
Definition usbc_ppc.h:219
static int ppc_set_snk_ctrl(const struct device *dev, bool enable)
Set the state of VBUS sinking.
Definition usbc_ppc.h:199
static int ppc_set_vbus_discharge(const struct device *dev, bool enable)
Set the state of VBUS discharging.
Definition usbc_ppc.h:239
static int ppc_dump_regs(const struct device *dev)
Print the values or PPC registers.
Definition usbc_ppc.h:299
static int ppc_is_vbus_sink(const struct device *dev)
Check if the PPC is sinking the VBUS.
Definition usbc_ppc.h:179
@ USBC_PPC_EVENT_SRC_REVERSE_CURRENT
Reverse current detected while being in a source role.
Definition usbc_ppc.h:39
@ USBC_PPC_EVENT_SRC_OVERCURRENT
Overcurrent detected while being in a source role.
Definition usbc_ppc.h:41
@ USBC_PPC_EVENT_SRC_OVERVOLTAGE
Overvoltage detected while being in a source role.
Definition usbc_ppc.h:37
@ USBC_PPC_EVENT_SNK_REVERSE_CURRENT
Reverse current detected while being in a sink role.
Definition usbc_ppc.h:51
@ USBC_PPC_EVENT_SNK_OVERVOLTAGE
Overvoltage detected while being in a sink role.
Definition usbc_ppc.h:55
@ USBC_PPC_EVENT_DEAD_BATTERY_ERROR
Exit from dead-battery mode failed.
Definition usbc_ppc.h:34
@ USBC_PPC_EVENT_SNK_SHORT
VBUS short detected while being in a sink role.
Definition usbc_ppc.h:53
@ USBC_PPC_EVENT_BOTH_SNKSRC_ENABLED
Sink and source paths enabled simultaneously.
Definition usbc_ppc.h:48
@ USBC_PPC_EVENT_OVER_TEMPERATURE
Chip over temperature detected.
Definition usbc_ppc.h:46
@ USBC_PPC_EVENT_SRC_SHORT
VBUS short detected while being in a source role.
Definition usbc_ppc.h:43
#define NULL
Definition iar_missing_defs.h:20
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
@def_driverbackendgroup{USB Type-C Power Path Controller,usb_type_c_power_path_controller}
Definition usbc_ppc.h:78
int(* set_vbus_discharge)(const struct device *dev, bool enable)
@driver_ops_optional Set the state of VBUS discharging.
Definition usbc_ppc.h:92
int(* set_src_ctrl)(const struct device *dev, bool enable)
@driver_ops_optional Set the state of VBUS sourcing.
Definition usbc_ppc.h:90
int(* exit_dead_battery_mode)(const struct device *dev)
@driver_ops_optional Request the PPC to exit from the dead battery mode Return from this call doesn...
Definition usbc_ppc.h:82
int(* is_dead_battery_mode)(const struct device *dev)
@driver_ops_optional Check if PPC is in the dead battery mode.
Definition usbc_ppc.h:80
int(* is_vbus_present)(const struct device *dev)
@driver_ops_optional Check if VBUS is present.
Definition usbc_ppc.h:94
int(* set_event_handler)(const struct device *dev, usbc_ppc_event_cb_t handler, void *data)
@driver_ops_optional Set the callback used to notify about PPC events.
Definition usbc_ppc.h:96
int(* is_vbus_sink)(const struct device *dev)
@driver_ops_optional Check if the PPC is sinking the VBUS.
Definition usbc_ppc.h:86
int(* is_vbus_source)(const struct device *dev)
@driver_ops_optional Check if the PPC is sourcing the VBUS.
Definition usbc_ppc.h:84
int(* dump_regs)(const struct device *dev)
@driver_ops_optional Print the values or PPC registers.
Definition usbc_ppc.h:98
int(* set_snk_ctrl)(const struct device *dev, bool enable)
@driver_ops_optional Set the state of VBUS sinking.
Definition usbc_ppc.h:88