1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <zephyr/devicetree.h>
#include <zephyr/sys/util_macro.h>
#include "usb_mux.h"
#include "usbc/usb_muxes.h"
/**
* @brief Macro that can be used in USB_MUX_FOREACH_USBC_PORT as filter
* argument. It allows to evaluate to "1 ||" for each named USBC port
* that has usb-muxes property.
*/
#define USB_MUX_PORT_HAS_MUX(unused1, unused2) 1 ||
/**
* Check if there is any named USBC port with usb-muxes property. It evaluates
* to "1 || 1 || ... 1 || 0" when there are multiple named USBC ports with
* usb-muxes property and to "0" when any named USBC port has usb-muxes
* property.
*
* This prevents creating struct usb_mux usb_muxes[] for platforms that didn't
* migrate USB mux configuration to DTS yet.
*/
#if USB_MUX_FOREACH_USBC_PORT(USB_MUX_PORT_HAS_MUX, _) 0
/**
* Forward declarations for board_init and board_set callbacks. e.g.
* int c0_mux0_board_init(const struct usb_mux *);
* int c1_mux0_board_set(const struct usb_mux *, mux_state_t);
*/
USB_MUX_FOREACH_USBC_PORT(USB_MUX_HAS_CB_BOARD_INIT,
USB_MUX_CB_BOARD_INIT_DECLARE)
USB_MUX_FOREACH_USBC_PORT(USB_MUX_HAS_CB_BOARD_SET,
USB_MUX_CB_BOARD_SET_DECLARE)
/**
* Define root of each USB muxes chain e.g.
* [0] = {
* .usb_port = 0,
* .next_mux = &USB_MUX_NODE_DT_N_S_usbc_S_port0_0_S_it5205_mux_0,
* .board_init = &board_init,
* .board_set = NULL,
* .flags = 0,
* .driver = &virtual_usb_mux_driver,
* .hpd_update = &virtual_hpd_update,
* },
* [1] = { ... },
*/
MAYBE_CONST struct usb_mux usb_muxes[] = { USB_MUX_FOREACH_USBC_PORT(
USB_MUX_FIRST, USB_MUX_ARRAY) };
/**
* Define all USB muxes except roots e.g.
* MAYBE_CONST struct usb_mux USB_MUX_NODE_DT_N_S_usbc_S_port0_0_S_mux_0 = {
* .usb_port = 0,
* .next_mux = NULL,
* .board_init = NULL,
* .board_set = NULL,
* .flags = 0,
* .driver = &virtual_usb_mux_driver,
* .hpd_update = &virtual_hpd_update,
* };
* MAYBE_CONST struct usb_mux USB_MUX_NODE_<node_id> = { ... };
*/
USB_MUX_FOREACH_USBC_PORT(USB_MUX_NO_FIRST, USB_MUX_DEFINE)
/* Create bb_controls only if BB or HB retimer driver is enabled */
#if defined(CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB) || \
defined(CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_HB)
/**
* @brief bb_controls array should be constant only if configuration cannot
* change in runtime
*/
#define BB_CONTROLS_CONST \
COND_CODE_1(CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB_RUNTIME_CONFIG, \
(), (const))
/**
* Define bb_controls for BB retimers in USB muxes chain e.g.
* [0] = {
* .retimer_rst_gpio = IOEX_USB_C0_BB_RETIMER_RST,
* .usb_ls_en_gpio = IOEX_USB_C0_BB_RETIMER_LS_EN,
* },
* [1] = { ... },
*/
BB_CONTROLS_CONST struct bb_usb_control bb_controls[] = {
USB_MUX_FOREACH_USBC_PORT(USB_MUX_BB_RETIMERS, USB_MUX_ARRAY)
};
#endif /* CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB/HB */
#endif /* #if USB_MUX_FOREACH_USBC_PORT(USB_MUX_PORT_HAS_MUX, _) */
|