Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
pd.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 The Chromium OS Authors
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * This is based on Linux, documentation:
6 * https://github.com/torvalds/linux/blob/v5.19/include/dt-bindings/usb/pd.h
7 */
8#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_USBC_PD_H_
9#define ZEPHYR_INCLUDE_DT_BINDINGS_USBC_PD_H_
10
16
34
36
37/* Power Delivery Power Data Object type field */
38#define PDO_TYPE_FIXED 0
39#define PDO_TYPE_BATT 1
40#define PDO_TYPE_VAR 2
41#define PDO_TYPE_APDO 3
42
43#define PDO_TYPE_SHIFT 30
44#define PDO_TYPE_MASK 0x3
45
46#define PDO_TYPE(t) ((t) << PDO_TYPE_SHIFT)
47
48#define PDO_VOLT_MASK 0x3ff
49#define PDO_CURR_MASK 0x3ff
50#define PDO_PWR_MASK 0x3ff
51
53
58#define PDO_FIXED_DUAL_ROLE (1 << 29)
59#define PDO_FIXED_SUSPEND (1 << 28)
60#define PDO_FIXED_HIGHER_CAP (1 << 28)
61#define PDO_FIXED_EXTPOWER (1 << 27)
62#define PDO_FIXED_USB_COMM (1 << 26)
63#define PDO_FIXED_DATA_SWAP (1 << 25)
65
67#define PDO_FIXED_VOLT_SHIFT 10 /* 50mV units */
68#define PDO_FIXED_CURR_SHIFT 0 /* 10mA units */
69
70#define PDO_FIXED_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_FIXED_VOLT_SHIFT)
71#define PDO_FIXED_CURR(ma) ((((ma) / 10) & PDO_CURR_MASK) << PDO_FIXED_CURR_SHIFT)
73
82#define PDO_FIXED(mv, ma, flags) \
83 (PDO_TYPE(PDO_TYPE_FIXED) | (flags) | \
84 PDO_FIXED_VOLT(mv) | PDO_FIXED_CURR(ma))
85
87#define VSAFE5V 5000
88
90#define PDO_BATT_MAX_VOLT_SHIFT 20 /* 50mV units */
91#define PDO_BATT_MIN_VOLT_SHIFT 10 /* 50mV units */
92#define PDO_BATT_MAX_PWR_SHIFT 0 /* 250mW units */
93
94#define PDO_BATT_MIN_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_BATT_MIN_VOLT_SHIFT)
95#define PDO_BATT_MAX_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_BATT_MAX_VOLT_SHIFT)
96#define PDO_BATT_MAX_POWER(mw) ((((mw) / 250) & PDO_PWR_MASK) << PDO_BATT_MAX_PWR_SHIFT)
98
107#define PDO_BATT(min_mv, max_mv, max_mw) \
108 (PDO_TYPE(PDO_TYPE_BATT) | PDO_BATT_MIN_VOLT(min_mv) | \
109 PDO_BATT_MAX_VOLT(max_mv) | PDO_BATT_MAX_POWER(max_mw))
110
112#define PDO_VAR_MAX_VOLT_SHIFT 20 /* 50mV units */
113#define PDO_VAR_MIN_VOLT_SHIFT 10 /* 50mV units */
114#define PDO_VAR_MAX_CURR_SHIFT 0 /* 10mA units */
115
116#define PDO_VAR_MIN_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_VAR_MIN_VOLT_SHIFT)
117#define PDO_VAR_MAX_VOLT(mv) ((((mv) / 50) & PDO_VOLT_MASK) << PDO_VAR_MAX_VOLT_SHIFT)
118#define PDO_VAR_MAX_CURR(ma) ((((ma) / 10) & PDO_CURR_MASK) << PDO_VAR_MAX_CURR_SHIFT)
120
129#define PDO_VAR(min_mv, max_mv, max_ma) \
130 (PDO_TYPE(PDO_TYPE_VAR) | PDO_VAR_MIN_VOLT(min_mv) | \
131 PDO_VAR_MAX_VOLT(max_mv) | PDO_VAR_MAX_CURR(max_ma))
132
134#define APDO_TYPE_PPS 0
135
136#define PDO_APDO_TYPE_SHIFT 28 /* Only valid value currently is 0x0 - PPS */
137#define PDO_APDO_TYPE_MASK 0x3
138
139#define PDO_APDO_TYPE(t) ((t) << PDO_APDO_TYPE_SHIFT)
140
141#define PDO_PPS_APDO_MAX_VOLT_SHIFT 17 /* 100mV units */
142#define PDO_PPS_APDO_MIN_VOLT_SHIFT 8 /* 100mV units */
143#define PDO_PPS_APDO_MAX_CURR_SHIFT 0 /* 50mA units */
144
145#define PDO_PPS_APDO_VOLT_MASK 0xff
146#define PDO_PPS_APDO_CURR_MASK 0x7f
147
148#define PDO_PPS_APDO_MIN_VOLT(mv) \
149 ((((mv) / 100) & PDO_PPS_APDO_VOLT_MASK) << PDO_PPS_APDO_MIN_VOLT_SHIFT)
150#define PDO_PPS_APDO_MAX_VOLT(mv) \
151 ((((mv) / 100) & PDO_PPS_APDO_VOLT_MASK) << PDO_PPS_APDO_MAX_VOLT_SHIFT)
152#define PDO_PPS_APDO_MAX_CURR(ma) \
153 ((((ma) / 50) & PDO_PPS_APDO_CURR_MASK) << PDO_PPS_APDO_MAX_CURR_SHIFT)
155
164#define PDO_PPS_APDO(min_mv, max_mv, max_ma) \
165 (PDO_TYPE(PDO_TYPE_APDO) | PDO_APDO_TYPE(APDO_TYPE_PPS) | \
166 PDO_PPS_APDO_MIN_VOLT(min_mv) | PDO_PPS_APDO_MAX_VOLT(max_mv) | \
167 PDO_PPS_APDO_MAX_CURR(max_ma))
168
172
173#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_USBC_PD_H_ */