Skip to content

Commit 551c765

Browse files
barnas-michalcarlescufi
authored andcommitted
usbc: integrate the PPC with the USB-C stack
Add calls to the PPC API that enables and disables the sink and source paths in the appropriate USB-C stack states. Signed-off-by: Michał Barnaś <[email protected]>
1 parent 6bd26a0 commit 551c765

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

dts/bindings/usb-c/usb-c-connector.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ properties:
5454
description: |
5555
VBUS measurement and control for this port.
5656
57+
ppc:
58+
type: phandle
59+
description: |
60+
Power path controller for this port
61+
5762
power-role:
5863
type: string
5964
required: true

subsys/usb/usb_c/usbc_stack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ static ALWAYS_INLINE void usbc_handler(void *port_dev)
8080
.prl_hr = &prl_hr_##inst, \
8181
.tcpc = DEVICE_DT_GET(DT_INST_PROP(inst, tcpc)), \
8282
.vbus = DEVICE_DT_GET(DT_INST_PROP(inst, vbus)), \
83+
.ppc = COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, ppc), \
84+
(DEVICE_DT_GET(DT_INST_PROP(inst, ppc))), (NULL)), \
8385
}; \
8486
\
8587
static const struct usbc_port_config usbc_port_config_##inst = { \

subsys/usb/usb_c/usbc_stack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ struct usbc_port_data {
101101
const struct device *tcpc;
102102
/** VBUS Measurement and control device on this port */
103103
const struct device *vbus;
104+
/** Power Path Controller device on this port */
105+
const struct device *ppc;
104106

105107
/** Device Policy Manager Request FIFO */
106108
struct k_fifo request_fifo;

subsys/usb/usb_c/usbc_tc_common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LOG_MODULE_DECLARE(usbc_stack, CONFIG_USBC_STACK_LOG_LEVEL);
1111
#include "usbc_tc_snk_states_internal.h"
1212
#include "usbc_tc_src_states_internal.h"
1313
#include "usbc_tc_common_internal.h"
14+
#include <zephyr/drivers/usb_c/usbc_ppc.h>
1415

1516
static const struct smf_state tc_states[TC_STATE_COUNT];
1617
static int tc_init(const struct device *dev);
@@ -152,6 +153,11 @@ static int tc_init(const struct device *dev)
152153
return ret;
153154
}
154155

156+
/* Disable VBUS sourcing by the PPC */
157+
if (data->ppc != NULL) {
158+
ppc_set_src_ctrl(data->ppc, false);
159+
}
160+
155161
/* Stop sourcing VCONN */
156162
ret = tcpc_set_vconn(tcpc, false);
157163
if (ret != 0 && ret != -ENOTSUP) {

subsys/usb/usb_c/usbc_tc_snk_states.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LOG_MODULE_DECLARE(usbc_stack, CONFIG_USBC_STACK_LOG_LEVEL);
1010
#include "usbc_stack.h"
1111
#include "usbc_tc_snk_states_internal.h"
1212
#include "usbc_tc_common_internal.h"
13+
#include <zephyr/drivers/usb_c/usbc_ppc.h>
1314

1415
/**
1516
* @brief Sink power sub states. Only called if a PD contract is not in place
@@ -214,6 +215,14 @@ void tc_attached_snk_entry(void *obj)
214215

215216
/* Enable PD */
216217
tc_pd_enable(dev, true);
218+
219+
/* Enable sink path for the PPC */
220+
if (data->ppc != NULL) {
221+
ret = ppc_set_snk_ctrl(data->ppc, true);
222+
if (ret != 0 && ret != -ENOTSUP) {
223+
LOG_ERR("Couldn't enable PPC sink path: %d", ret);
224+
}
225+
}
217226
}
218227

219228
/**
@@ -245,9 +254,19 @@ void tc_attached_snk_exit(void *obj)
245254
{
246255
struct tc_sm_t *tc = (struct tc_sm_t *)obj;
247256
const struct device *dev = tc->dev;
257+
struct usbc_port_data *data = dev->data;
258+
int ret;
248259

249260
/* Disable PD */
250261
tc_pd_enable(dev, false);
262+
263+
/* Disable sink path for the PPC */
264+
if (data->ppc != NULL) {
265+
ret = ppc_set_snk_ctrl(data->ppc, false);
266+
if (ret != 0 && ret != -ENOTSUP) {
267+
LOG_ERR("Couldn't disable PPC sink path: %d", ret);
268+
}
269+
}
251270
}
252271

253272
/**

subsys/usb/usb_c/usbc_tc_src_states.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LOG_MODULE_DECLARE(usbc_stack, CONFIG_USBC_STACK_LOG_LEVEL);
99

1010
#include "usbc_stack.h"
1111
#include "usbc_tc_src_states_internal.h"
12+
#include <zephyr/drivers/usb_c/usbc_ppc.h>
1213

1314
/**
1415
* @brief Spec. Release 1.3, section 4.5.2.2.7 Unattached.SRC State
@@ -253,6 +254,16 @@ void tc_attached_src_entry(void *obj)
253254

254255
/* Enable PD */
255256
tc_pd_enable(dev, true);
257+
258+
/* Enable the VBUS sourcing by the PPC */
259+
if (data->ppc != NULL) {
260+
int ret;
261+
262+
ret = ppc_set_src_ctrl(data->ppc, true);
263+
if (ret < 0 && ret != -ENOSYS) {
264+
LOG_ERR("Couldn't disable PPC source");
265+
}
266+
}
256267
}
257268

258269
void tc_attached_src_run(void *obj)
@@ -304,6 +315,16 @@ void tc_attached_src_exit(void *obj)
304315
/* Stop sourcing VBUS */
305316
data->policy_cb_src_en(dev, false);
306317

318+
/* Disable the VBUS sourcing by the PPC */
319+
if (data->ppc != NULL) {
320+
int ret;
321+
322+
ret = ppc_set_src_ctrl(data->ppc, false);
323+
if (ret < 0 && ret != -ENOSYS) {
324+
LOG_ERR("Couldn't disable PPC source");
325+
}
326+
}
327+
307328
/* Stop sourcing VCONN */
308329
ret = tcpc_set_vconn(tcpc, false);
309330
if (ret != 0 && ret != -ENOSYS) {

0 commit comments

Comments
 (0)