Zephyr Project API 3.7.0
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#ifndef ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PPC_H_
13#define ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PPC_H_
14
15#include <zephyr/types.h>
16#include <zephyr/device.h>
17#include <errno.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
49
50typedef void (*usbc_ppc_event_cb_t)(const struct device *dev, void *data, enum usbc_ppc_event ev);
51
53__subsystem struct usbc_ppc_driver_api {
54 int (*is_dead_battery_mode)(const struct device *dev);
55 int (*exit_dead_battery_mode)(const struct device *dev);
56 int (*is_vbus_source)(const struct device *dev);
57 int (*is_vbus_sink)(const struct device *dev);
58 int (*set_snk_ctrl)(const struct device *dev, bool enable);
59 int (*set_src_ctrl)(const struct device *dev, bool enable);
60 int (*set_vbus_discharge)(const struct device *dev, bool enable);
61 int (*is_vbus_present)(const struct device *dev);
62 int (*set_event_handler)(const struct device *dev, usbc_ppc_event_cb_t handler, void *data);
63 int (*dump_regs)(const struct device *dev);
64};
65
66/*
67 * API functions
68 */
69
79static inline int ppc_is_dead_battery_mode(const struct device *dev)
80{
81 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
82
83 if (api->is_dead_battery_mode == NULL) {
84 return -ENOSYS;
85 }
86
87 return api->is_dead_battery_mode(dev);
88}
89
102static inline int ppc_exit_dead_battery_mode(const struct device *dev)
103{
104 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
105
106 if (api->exit_dead_battery_mode == NULL) {
107 return -ENOSYS;
108 }
109
110 return api->exit_dead_battery_mode(dev);
111}
112
122static inline int ppc_is_vbus_source(const struct device *dev)
123{
124 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
125
126 if (api->is_vbus_source == NULL) {
127 return -ENOSYS;
128 }
129
130 return api->is_vbus_source(dev);
131}
132
142static inline int ppc_is_vbus_sink(const struct device *dev)
143{
144 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
145
146 if (api->is_vbus_sink == NULL) {
147 return -ENOSYS;
148 }
149
150 return api->is_vbus_sink(dev);
151}
152
162static inline int ppc_set_snk_ctrl(const struct device *dev, bool enable)
163{
164 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
165
166 if (api->set_snk_ctrl == NULL) {
167 return -ENOSYS;
168 }
169
170 return api->set_snk_ctrl(dev, enable);
171}
172
182static inline int ppc_set_src_ctrl(const struct device *dev, bool enable)
183{
184 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
185
186 if (api->set_src_ctrl == NULL) {
187 return -ENOSYS;
188 }
189
190 return api->set_src_ctrl(dev, enable);
191}
192
202static inline int ppc_set_vbus_discharge(const struct device *dev, bool enable)
203{
204 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
205
206 if (api->set_vbus_discharge == NULL) {
207 return -ENOSYS;
208 }
209
210 return api->set_vbus_discharge(dev, enable);
211}
212
222static inline int ppc_is_vbus_present(const struct device *dev)
223{
224 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
225
226 if (api->is_vbus_present == NULL) {
227 return -ENOSYS;
228 }
229
230 return api->is_vbus_present(dev);
231}
232
242static inline int ppc_set_event_handler(const struct device *dev,
244{
245 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
246
247 if (api->set_event_handler == NULL) {
248 return -ENOSYS;
249 }
250
251 return api->set_event_handler(dev, handler, data);
252}
253
262static inline int ppc_dump_regs(const struct device *dev)
263{
264 const struct usbc_ppc_driver_api *api = (const struct usbc_ppc_driver_api *)dev->api;
265
266 if (api->dump_regs == NULL) {
267 return -ENOSYS;
268 }
269
270 return api->dump_regs(dev);
271}
272
273#ifdef __cplusplus
274}
275#endif
276
277#endif /* ZEPHYR_INCLUDE_DRIVERS_USBC_USBC_PPC_H_ */
System error numbers.
#define ENOSYS
Function not implemented.
Definition errno.h:82
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
Structure with pointers to the functions implemented by driver.
Definition usbc_ppc.h:53
int(* set_vbus_discharge)(const struct device *dev, bool enable)
Definition usbc_ppc.h:60
int(* set_src_ctrl)(const struct device *dev, bool enable)
Definition usbc_ppc.h:59
int(* exit_dead_battery_mode)(const struct device *dev)
Definition usbc_ppc.h:55
int(* is_dead_battery_mode)(const struct device *dev)
Definition usbc_ppc.h:54
int(* is_vbus_present)(const struct device *dev)
Definition usbc_ppc.h:61
int(* set_event_handler)(const struct device *dev, usbc_ppc_event_cb_t handler, void *data)
Definition usbc_ppc.h:62
int(* is_vbus_sink)(const struct device *dev)
Definition usbc_ppc.h:57
int(* is_vbus_source)(const struct device *dev)
Definition usbc_ppc.h:56
int(* dump_regs)(const struct device *dev)
Definition usbc_ppc.h:63
int(* set_snk_ctrl)(const struct device *dev, bool enable)
Definition usbc_ppc.h:58
static fdata_t data[2]
Definition test_fifo_contexts.c:15
static void handler(struct k_timer *timer)
Definition main.c:19
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:242
usbc_ppc_event
Type of event being notified by Power Path Controller.
Definition usbc_ppc.h:24
@ USBC_PPC_EVENT_SRC_REVERSE_CURRENT
Reverse current detected while being in a source role.
Definition usbc_ppc.h:31
@ USBC_PPC_EVENT_SRC_OVERCURRENT
Overcurrent detected while being in a source role.
Definition usbc_ppc.h:33
@ USBC_PPC_EVENT_SRC_OVERVOLTAGE
Overvoltage detected while being in a source role.
Definition usbc_ppc.h:29
@ USBC_PPC_EVENT_SNK_REVERSE_CURRENT
Reverse current detected while being in a sink role.
Definition usbc_ppc.h:43
@ USBC_PPC_EVENT_SNK_OVERVOLTAGE
Overvoltage detected while being in a sink role.
Definition usbc_ppc.h:47
@ USBC_PPC_EVENT_DEAD_BATTERY_ERROR
Exit from dead-battery mode failed.
Definition usbc_ppc.h:26
@ USBC_PPC_EVENT_SNK_SHORT
VBUS short detected while being in a sink role.
Definition usbc_ppc.h:45
@ USBC_PPC_EVENT_BOTH_SNKSRC_ENABLED
Sink and source paths enabled simultaneously.
Definition usbc_ppc.h:40
@ USBC_PPC_EVENT_OVER_TEMPERATURE
Chip over temperature detected
Definition usbc_ppc.h:38
@ USBC_PPC_EVENT_SRC_SHORT
VBUS short detected while being in a source role.
Definition usbc_ppc.h:35
static int ppc_is_dead_battery_mode(const struct device *dev)
Check if PPC is in the dead battery mode.
Definition usbc_ppc.h:79
void(* usbc_ppc_event_cb_t)(const struct device *dev, void *data, enum usbc_ppc_event ev)
Definition usbc_ppc.h:50
static int ppc_is_vbus_source(const struct device *dev)
Check if the PPC is sourcing the VBUS.
Definition usbc_ppc.h:122
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:102
static int ppc_is_vbus_present(const struct device *dev)
Check if VBUS is present.
Definition usbc_ppc.h:222
static int ppc_set_src_ctrl(const struct device *dev, bool enable)
Set the state of VBUS sourcing.
Definition usbc_ppc.h:182
static int ppc_set_snk_ctrl(const struct device *dev, bool enable)
Set the state of VBUS sinking.
Definition usbc_ppc.h:162
static int ppc_set_vbus_discharge(const struct device *dev, bool enable)
Set the state of VBUS discharging.
Definition usbc_ppc.h:202
static int ppc_dump_regs(const struct device *dev)
Print the values or PPC registers.
Definition usbc_ppc.h:262
static int ppc_is_vbus_sink(const struct device *dev)
Check if the PPC is sinking the VBUS.
Definition usbc_ppc.h:142