Zephyr API Documentation 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
11
12#ifndef ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PPC_H_
13#define ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PPC_H_
14
21
22#include <zephyr/types.h>
23#include <zephyr/device.h>
24#include <errno.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
56
57typedef void (*usbc_ppc_event_cb_t)(const struct device *dev, void *data, enum usbc_ppc_event ev);
58
64
68__subsystem struct usbc_ppc_driver_api {
70 int (*is_dead_battery_mode)(const struct device *dev);
72 int (*exit_dead_battery_mode)(const struct device *dev);
74 int (*is_vbus_source)(const struct device *dev);
76 int (*is_vbus_sink)(const struct device *dev);
78 int (*set_snk_ctrl)(const struct device *dev, bool enable);
80 int (*set_src_ctrl)(const struct device *dev, bool enable);
82 int (*set_vbus_discharge)(const struct device *dev, bool enable);
84 int (*is_vbus_present)(const struct device *dev);
86 int (*set_event_handler)(const struct device *dev, usbc_ppc_event_cb_t handler, void *data);
88 int (*dump_regs)(const struct device *dev);
89};
90
92
93/*
94 * API functions
95 */
96
106static inline int ppc_is_dead_battery_mode(const struct device *dev)
107{
108 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
109
110 if (api->is_dead_battery_mode == NULL) {
111 return -ENOSYS;
112 }
113
114 return api->is_dead_battery_mode(dev);
115}
116
129static inline int ppc_exit_dead_battery_mode(const struct device *dev)
130{
131 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
132
133 if (api->exit_dead_battery_mode == NULL) {
134 return -ENOSYS;
135 }
136
137 return api->exit_dead_battery_mode(dev);
138}
139
149static inline int ppc_is_vbus_source(const struct device *dev)
150{
151 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
152
153 if (api->is_vbus_source == NULL) {
154 return -ENOSYS;
155 }
156
157 return api->is_vbus_source(dev);
158}
159
169static inline int ppc_is_vbus_sink(const struct device *dev)
170{
171 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
172
173 if (api->is_vbus_sink == NULL) {
174 return -ENOSYS;
175 }
176
177 return api->is_vbus_sink(dev);
178}
179
189static inline int ppc_set_snk_ctrl(const struct device *dev, bool enable)
190{
191 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
192
193 if (api->set_snk_ctrl == NULL) {
194 return -ENOSYS;
195 }
196
197 return api->set_snk_ctrl(dev, enable);
198}
199
209static inline int ppc_set_src_ctrl(const struct device *dev, bool enable)
210{
211 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
212
213 if (api->set_src_ctrl == NULL) {
214 return -ENOSYS;
215 }
216
217 return api->set_src_ctrl(dev, enable);
218}
219
229static inline int ppc_set_vbus_discharge(const struct device *dev, bool enable)
230{
231 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
232
233 if (api->set_vbus_discharge == NULL) {
234 return -ENOSYS;
235 }
236
237 return api->set_vbus_discharge(dev, enable);
238}
239
249static inline int ppc_is_vbus_present(const struct device *dev)
250{
251 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
252
253 if (api->is_vbus_present == NULL) {
254 return -ENOSYS;
255 }
256
257 return api->is_vbus_present(dev);
258}
259
269static inline int ppc_set_event_handler(const struct device *dev,
270 usbc_ppc_event_cb_t handler, void *data)
271{
272 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
273
274 if (api->set_event_handler == NULL) {
275 return -ENOSYS;
276 }
277
278 return api->set_event_handler(dev, handler, data);
279}
280
289static inline int ppc_dump_regs(const struct device *dev)
290{
291 const struct usbc_ppc_driver_api *api = DEVICE_API_GET(usbc_ppc, dev);
292
293 if (api->dump_regs == NULL) {
294 return -ENOSYS;
295 }
296
297 return api->dump_regs(dev);
298}
299
300#ifdef __cplusplus
301}
302#endif
303
307
308#endif /* ZEPHYR_INCLUDE_DRIVERS_USBC_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:1425
System error numbers.
#define ENOSYS
Function not implemented.
Definition errno.h:82
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:269
usbc_ppc_event
Type of event being notified by Power Path Controller.
Definition usbc_ppc.h:31
static int ppc_is_dead_battery_mode(const struct device *dev)
Check if PPC is in the dead battery mode.
Definition usbc_ppc.h:106
void(* usbc_ppc_event_cb_t)(const struct device *dev, void *data, enum usbc_ppc_event ev)
Definition usbc_ppc.h:57
static int ppc_is_vbus_source(const struct device *dev)
Check if the PPC is sourcing the VBUS.
Definition usbc_ppc.h:149
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:129
static int ppc_is_vbus_present(const struct device *dev)
Check if VBUS is present.
Definition usbc_ppc.h:249
static int ppc_set_src_ctrl(const struct device *dev, bool enable)
Set the state of VBUS sourcing.
Definition usbc_ppc.h:209
static int ppc_set_snk_ctrl(const struct device *dev, bool enable)
Set the state of VBUS sinking.
Definition usbc_ppc.h:189
static int ppc_set_vbus_discharge(const struct device *dev, bool enable)
Set the state of VBUS discharging.
Definition usbc_ppc.h:229
static int ppc_dump_regs(const struct device *dev)
Print the values or PPC registers.
Definition usbc_ppc.h:289
static int ppc_is_vbus_sink(const struct device *dev)
Check if the PPC is sinking the VBUS.
Definition usbc_ppc.h:169
@ USBC_PPC_EVENT_SRC_REVERSE_CURRENT
Reverse current detected while being in a source role.
Definition usbc_ppc.h:38
@ USBC_PPC_EVENT_SRC_OVERCURRENT
Overcurrent detected while being in a source role.
Definition usbc_ppc.h:40
@ USBC_PPC_EVENT_SRC_OVERVOLTAGE
Overvoltage detected while being in a source role.
Definition usbc_ppc.h:36
@ USBC_PPC_EVENT_SNK_REVERSE_CURRENT
Reverse current detected while being in a sink role.
Definition usbc_ppc.h:50
@ USBC_PPC_EVENT_SNK_OVERVOLTAGE
Overvoltage detected while being in a sink role.
Definition usbc_ppc.h:54
@ USBC_PPC_EVENT_DEAD_BATTERY_ERROR
Exit from dead-battery mode failed.
Definition usbc_ppc.h:33
@ USBC_PPC_EVENT_SNK_SHORT
VBUS short detected while being in a sink role.
Definition usbc_ppc.h:52
@ USBC_PPC_EVENT_BOTH_SNKSRC_ENABLED
Sink and source paths enabled simultaneously.
Definition usbc_ppc.h:47
@ USBC_PPC_EVENT_OVER_TEMPERATURE
Chip over temperature detected.
Definition usbc_ppc.h:45
@ USBC_PPC_EVENT_SRC_SHORT
VBUS short detected while being in a source role.
Definition usbc_ppc.h:42
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
<span class="mlabel">Driver Operations</span> USB Type-C Power Path Controller driver operations
Definition usbc_ppc.h:68
int(* set_vbus_discharge)(const struct device *dev, bool enable)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:82
int(* set_src_ctrl)(const struct device *dev, bool enable)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:80
int(* exit_dead_battery_mode)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:72
int(* is_dead_battery_mode)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:70
int(* is_vbus_present)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:84
int(* set_event_handler)(const struct device *dev, usbc_ppc_event_cb_t handler, void *data)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:86
int(* is_vbus_sink)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:76
int(* is_vbus_source)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:74
int(* dump_regs)(const struct device *dev)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:88
int(* set_snk_ctrl)(const struct device *dev, bool enable)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition usbc_ppc.h:78