diff options
56 files changed, 644 insertions, 290 deletions
diff --git a/baseboard/ite_evb/build.mk b/baseboard/ite_evb/build.mk index 77352145ee..507222e6b3 100644 --- a/baseboard/ite_evb/build.mk +++ b/baseboard/ite_evb/build.mk @@ -7,4 +7,4 @@ # baseboard-y=baseboard.o -baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o diff --git a/baseboard/ite_evb/usb_pd_pdo.c b/baseboard/ite_evb/usb_pd_pdo.c new file mode 100644 index 0000000000..24cbc8b996 --- /dev/null +++ b/baseboard/ite_evb/usb_pd_pdo.c @@ -0,0 +1,23 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ + PDO_FIXED_UNCONSTRAINED | PDO_FIXED_COMM_CAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_BATT(4500, 14000, 10000), + PDO_VAR(4500, 14000, 3000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/baseboard/ite_evb/usb_pd_pdo.h b/baseboard/ite_evb/usb_pd_pdo.h new file mode 100644 index 0000000000..ce3300cc7d --- /dev/null +++ b/baseboard/ite_evb/usb_pd_pdo.h @@ -0,0 +1,20 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BASEBOARD_ITE_EVB_USB_PD_PDO_H +#define __CROS_EC_BASEBOARD_ITE_EVB_USB_PD_PDO_H + +#include "config.h" +#include "stdint.h" + +/* Threshold voltage of VBUS provided (mV) */ +#define PD_VBUS_PROVIDED_THRESHOLD 3900 + +extern const uint32_t pd_src_pdo[1]; +extern const int pd_src_pdo_cnt; +extern const uint32_t pd_snk_pdo[3]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BASEBOARD_ITE_EVB_USB_PD_PDO_H */ diff --git a/baseboard/ite_evb/usb_pd_policy.c b/baseboard/ite_evb/usb_pd_policy.c index 59f3da13f5..b5462bd1e2 100644 --- a/baseboard/ite_evb/usb_pd_policy.c +++ b/baseboard/ite_evb/usb_pd_policy.c @@ -18,31 +18,11 @@ #include "timer.h" #include "util.h" #include "usb_mux.h" +#include "usb_pd_pdo.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -/* ---------------- Power Data Objects (PDOs) ----------------- */ -#ifdef CONFIG_USB_PD_CUSTOM_PDO -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_UNCONSTRAINED | PDO_FIXED_COMM_CAP) - -/* Threshold voltage of VBUS provided (mV) */ -#define PD_VBUS_PROVIDED_THRESHOLD 3900 - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_BATT(4500, 14000, 10000), - PDO_VAR(4500, 14000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); -#endif - int pd_is_max_request_allowed(void) { /* Max voltage request allowed */ diff --git a/baseboard/kalista/build.mk b/baseboard/kalista/build.mk index e64b6a2d71..85270d4bd4 100644 --- a/baseboard/kalista/build.mk +++ b/baseboard/kalista/build.mk @@ -8,4 +8,4 @@ baseboard-y=baseboard.o baseboard-y+=led.o -baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
\ No newline at end of file +baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o
\ No newline at end of file diff --git a/baseboard/kalista/usb_pd_pdo.c b/baseboard/kalista/usb_pd_pdo.c new file mode 100644 index 0000000000..0addbcc51c --- /dev/null +++ b/baseboard/kalista/usb_pd_pdo.c @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS (PDO_FIXED_UNCONSTRAINED | \ + PDO_FIXED_DATA_SWAP | \ + PDO_FIXED_COMM_CAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); diff --git a/baseboard/kalista/usb_pd_pdo.h b/baseboard/kalista/usb_pd_pdo.h new file mode 100644 index 0000000000..1dad035d3d --- /dev/null +++ b/baseboard/kalista/usb_pd_pdo.h @@ -0,0 +1,15 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BASEBOARD_KALISTA_USB_PD_PDO_H +#define __CROS_EC_BASEBOARD_KALISTA_USB_PD_PDO_H + +#include "config.h" +#include "stdint.h" + +extern const uint32_t pd_src_pdo[1]; +extern const int pd_src_pdo_cnt; + +#endif /* __CROS_EC_BASEBOARD_KALISTA_USB_PD_PDO_H */ diff --git a/baseboard/kalista/usb_pd_policy.c b/baseboard/kalista/usb_pd_policy.c index 89af4b50fb..85b26aac76 100644 --- a/baseboard/kalista/usb_pd_policy.c +++ b/baseboard/kalista/usb_pd_policy.c @@ -20,20 +20,12 @@ #include "util.h" #include "usb_mux.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #include "usb_pd_tcpm.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define PDO_FIXED_FLAGS (PDO_FIXED_UNCONSTRAINED | \ - PDO_FIXED_DATA_SWAP | \ - PDO_FIXED_COMM_CAP) - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - int board_vbus_source_enabled(int port) { if (port != 0) diff --git a/board/coffeecake/build.mk b/board/coffeecake/build.mk index fb5a6fccdb..59ca88486b 100644 --- a/board/coffeecake/build.mk +++ b/board/coffeecake/build.mk @@ -14,4 +14,4 @@ CHIP_VARIANT:=stm32f07x test-list-y= board-y=board.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o diff --git a/board/coffeecake/usb_pd_pdo.c b/board/coffeecake/usb_pd_pdo.c new file mode 100644 index 0000000000..a766d7dbe5 --- /dev/null +++ b/board/coffeecake/usb_pd_pdo.c @@ -0,0 +1,26 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS_EXT (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ + PDO_FIXED_COMM_CAP | PDO_FIXED_UNCONSTRAINED) + +#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ + PDO_FIXED_COMM_CAP) + +const uint32_t pd_src_pdo[] = { + [PDO_IDX_5V] = PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS_EXT), + [PDO_IDX_9V] = PDO_FIXED(9000, 2500, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); +BUILD_ASSERT(ARRAY_SIZE(pd_src_pdo) == PDO_IDX_COUNT); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/board/coffeecake/usb_pd_pdo.h b/board/coffeecake/usb_pd_pdo.h new file mode 100644 index 0000000000..f695defddb --- /dev/null +++ b/board/coffeecake/usb_pd_pdo.h @@ -0,0 +1,25 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_COFFEECAKE_USB_PD_PDO_H +#define __CROS_EC_BOARD_COFFEECAKE_USB_PD_PDO_H + +#include "stdint.h" + +/* Voltage indexes for the PDOs */ +enum volt_idx { + PDO_IDX_5V = 0, + PDO_IDX_9V = 1, + /* TODO: add PPS support */ + PDO_IDX_COUNT +}; + +extern const uint32_t pd_src_pdo[2]; +extern const int pd_src_pdo_cnt; + +extern const uint32_t pd_snk_pdo[1]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BOARD_COFFEECAKE_USB_PD_PDO_H */ diff --git a/board/coffeecake/usb_pd_policy.c b/board/coffeecake/usb_pd_policy.c index dc19207a0e..c8c74688a8 100644 --- a/board/coffeecake/usb_pd_policy.c +++ b/board/coffeecake/usb_pd_policy.c @@ -18,40 +18,13 @@ #include "usb_api.h" #include "usb_bb.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #include "usb_pd_tcpm.h" #include "util.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define PDO_FIXED_FLAGS_EXT (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP | PDO_FIXED_UNCONSTRAINED) - -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - - -/* Voltage indexes for the PDOs */ -enum volt_idx { - PDO_IDX_5V = 0, - PDO_IDX_9V = 1, - /* TODO: add PPS support */ - PDO_IDX_COUNT -}; - -/* PDOs */ -const uint32_t pd_src_pdo[] = { - [PDO_IDX_5V] = PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS_EXT), - [PDO_IDX_9V] = PDO_FIXED(9000, 2500, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); -BUILD_ASSERT(ARRAY_SIZE(pd_src_pdo) == PDO_IDX_COUNT); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - /* Holds valid object position (opos) for entered mode */ static int alt_mode[PD_AMODE_COUNT]; diff --git a/board/dingdong/build.mk b/board/dingdong/build.mk index 18799c3b9f..71cea3f845 100644 --- a/board/dingdong/build.mk +++ b/board/dingdong/build.mk @@ -11,4 +11,4 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x board-y=board.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o diff --git a/board/dingdong/usb_pd_pdo.c b/board/dingdong/usb_pd_pdo.c new file mode 100644 index 0000000000..990c2de5ab --- /dev/null +++ b/board/dingdong/usb_pd_pdo.c @@ -0,0 +1,20 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS PDO_FIXED_COMM_CAP + +/* Source PDOs */ +const uint32_t pd_src_pdo[] = {}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +/* Fake PDOs : we just want our pre-defined voltages */ +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/board/dingdong/usb_pd_pdo.h b/board/dingdong/usb_pd_pdo.h new file mode 100644 index 0000000000..66bb713ee8 --- /dev/null +++ b/board/dingdong/usb_pd_pdo.h @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_DINGDONG_USB_PD_PDO_H +#define __CROS_EC_BOARD_DINGDONG_USB_PD_PDO_H + +#include "stdint.h" + +extern const uint32_t pd_src_pdo[0]; +extern const int pd_src_pdo_cnt; + +extern const uint32_t pd_snk_pdo[1]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BOARD_DINGDONG_USB_PD_PDO_H */ diff --git a/board/dingdong/usb_pd_policy.c b/board/dingdong/usb_pd_policy.c index 50700f8a62..9bcc7f806f 100644 --- a/board/dingdong/usb_pd_policy.c +++ b/board/dingdong/usb_pd_policy.c @@ -23,18 +23,6 @@ #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define PDO_FIXED_FLAGS PDO_FIXED_COMM_CAP - -/* Source PDOs */ -const uint32_t pd_src_pdo[] = {}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - -/* Fake PDOs : we just want our pre-defined voltages */ -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - /* Holds valid object position (opos) for entered mode */ static int alt_mode[PD_AMODE_COUNT]; diff --git a/board/fizz/build.mk b/board/fizz/build.mk index 74094ac834..febbb7fac2 100644 --- a/board/fizz/build.mk +++ b/board/fizz/build.mk @@ -10,5 +10,5 @@ CHIP:=npcx CHIP_VARIANT:=npcx5m6g board-y=board.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o board-y+=led.o diff --git a/board/fizz/usb_pd_pdo.c b/board/fizz/usb_pd_pdo.c new file mode 100644 index 0000000000..bb612affef --- /dev/null +++ b/board/fizz/usb_pd_pdo.c @@ -0,0 +1,23 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ + PDO_FIXED_COMM_CAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_BATT(4750, 21000, 50000), + PDO_VAR(4750, 21000, 3000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/board/fizz/usb_pd_pdo.h b/board/fizz/usb_pd_pdo.h new file mode 100644 index 0000000000..de4f8f9474 --- /dev/null +++ b/board/fizz/usb_pd_pdo.h @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_FIZZ_USB_PD_PDO_H +#define __CROS_EC_BOARD_FIZZ_USB_PD_PDO_H + +#include "stdint.h" + +extern const uint32_t pd_src_pdo[1]; +extern const int pd_src_pdo_cnt; + +extern const uint32_t pd_snk_pdo[3]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BOARD_FIZZ_USB_PD_PDO_H */ diff --git a/board/fizz/usb_pd_policy.c b/board/fizz/usb_pd_policy.c index 5de57f3c9b..5fc495417f 100644 --- a/board/fizz/usb_pd_policy.c +++ b/board/fizz/usb_pd_policy.c @@ -20,26 +20,12 @@ #include "util.h" #include "usb_mux.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #include "usb_pd_tcpm.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_BATT(4750, 21000, 50000), - PDO_VAR(4750, 21000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - int board_vbus_source_enabled(int port) { if (port != 0) diff --git a/board/hoho/build.mk b/board/hoho/build.mk index 18799c3b9f..71cea3f845 100644 --- a/board/hoho/build.mk +++ b/board/hoho/build.mk @@ -11,4 +11,4 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x board-y=board.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o diff --git a/board/hoho/usb_pd_pdo.c b/board/hoho/usb_pd_pdo.c new file mode 100644 index 0000000000..19b5d127a5 --- /dev/null +++ b/board/hoho/usb_pd_pdo.c @@ -0,0 +1,18 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +/* Source PDOs */ +const uint32_t pd_src_pdo[] = {}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +/* Fake PDOs : we just want our pre-defined voltages */ +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_COMM_CAP), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/board/hoho/usb_pd_pdo.h b/board/hoho/usb_pd_pdo.h new file mode 100644 index 0000000000..8a43db795e --- /dev/null +++ b/board/hoho/usb_pd_pdo.h @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_HOHO_USB_PD_PDO_H +#define __CROS_EC_BOARD_HOHO_USB_PD_PDO_H + +#include "stdint.h" + +extern const uint32_t pd_src_pdo[0]; +extern const int pd_src_pdo_cnt; + +extern const uint32_t pd_snk_pdo[1]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BOARD_HOHO_USB_PD_PDO_H */ diff --git a/board/hoho/usb_pd_policy.c b/board/hoho/usb_pd_policy.c index 2ee83d32aa..73f3fca16e 100644 --- a/board/hoho/usb_pd_policy.c +++ b/board/hoho/usb_pd_policy.c @@ -17,22 +17,13 @@ #include "usb_api.h" #include "usb_bb.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #include "usb_pd_tcpm.h" #include "util.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -/* Source PDOs */ -const uint32_t pd_src_pdo[] = {}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - -/* Fake PDOs : we just want our pre-defined voltages */ -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_COMM_CAP), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - /* Holds valid object position (opos) for entered mode */ static int alt_mode[PD_AMODE_COUNT]; diff --git a/board/host/build.mk b/board/host/build.mk index 241f197342..17927528c2 100644 --- a/board/host/build.mk +++ b/board/host/build.mk @@ -12,4 +12,4 @@ board-y=board.o board-$(HAS_TASK_CHIPSET)+=chipset.o board-$(CONFIG_BATTERY_MOCK)+=battery.o charger.o board-$(CONFIG_FANS)+=fan.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_config.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_config.o usb_pd_pdo.o diff --git a/board/host/usb_pd_pdo.c b/board/host/usb_pd_pdo.c new file mode 100644 index 0000000000..a84b03f75f --- /dev/null +++ b/board/host/usb_pd_pdo.c @@ -0,0 +1,23 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 900, PDO_FIXED_FLAGS), + PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_BATT(4750, 21000, 15000), + PDO_VAR(4750, 21000, 3000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/board/host/usb_pd_pdo.h b/board/host/usb_pd_pdo.h new file mode 100644 index 0000000000..64d73c7a15 --- /dev/null +++ b/board/host/usb_pd_pdo.h @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_HOST_USB_PD_PDO_H +#define __CROS_EC_BOARD_HOST_USB_PD_PDO_H + +#include "stdint.h" + +extern const uint32_t pd_src_pdo[2]; +extern const int pd_src_pdo_cnt; + +extern const uint32_t pd_snk_pdo[3]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BOARD_HOST_USB_PD_PDO_H */ diff --git a/board/host/usb_pd_policy.c b/board/host/usb_pd_policy.c index 23285f4838..b02891ee29 100644 --- a/board/host/usb_pd_policy.c +++ b/board/host/usb_pd_policy.c @@ -6,26 +6,12 @@ #include "common.h" #include "console.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #include "util.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP) - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 900, PDO_FIXED_FLAGS), - PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_BATT(4750, 21000, 15000), - PDO_VAR(4750, 21000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - test_mockable int pd_set_power_supply_ready(int port) { /* Not implemented */ diff --git a/board/pdeval-stm32f072/build.mk b/board/pdeval-stm32f072/build.mk index ef1346d534..30d5bf8ac8 100644 --- a/board/pdeval-stm32f072/build.mk +++ b/board/pdeval-stm32f072/build.mk @@ -10,4 +10,4 @@ CHIP:=stm32 CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x -board-y=board.o usb_pd_policy.o +board-y=board.o usb_pd_policy.o usb_pd_pdo.o diff --git a/board/pdeval-stm32f072/usb_pd_pdo.c b/board/pdeval-stm32f072/usb_pd_pdo.c new file mode 100644 index 0000000000..442e708923 --- /dev/null +++ b/board/pdeval-stm32f072/usb_pd_pdo.c @@ -0,0 +1,21 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 900, PDO_FIXED_FLAGS), + PDO_BATT(5000, 21000, 30000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/board/pdeval-stm32f072/usb_pd_pdo.h b/board/pdeval-stm32f072/usb_pd_pdo.h new file mode 100644 index 0000000000..58fd1f153c --- /dev/null +++ b/board/pdeval-stm32f072/usb_pd_pdo.h @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_PDEVAL_STM32F072_USB_PD_PDO_H +#define __CROS_EC_BOARD_PDEVAL_STM32F072_USB_PD_PDO_H + +#include "stdint.h" + +extern const uint32_t pd_src_pdo[1]; +extern const int pd_src_pdo_cnt; + +extern const uint32_t pd_snk_pdo[2]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BOARD_PDEVAL_STM32F072_USB_PD_PDO_H */ diff --git a/board/pdeval-stm32f072/usb_pd_policy.c b/board/pdeval-stm32f072/usb_pd_policy.c index 2f7941321b..6fdb894eed 100644 --- a/board/pdeval-stm32f072/usb_pd_policy.c +++ b/board/pdeval-stm32f072/usb_pd_policy.c @@ -15,25 +15,14 @@ #include "util.h" #include "usb_mux.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP) - /* Used to fake VBUS presence since no GPIO is available to read VBUS */ static int vbus_present; -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 900, PDO_FIXED_FLAGS), - PDO_BATT(5000, 21000, 30000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); #if defined(CONFIG_USB_PD_TCPM_MUX) && defined(CONFIG_USB_PD_TCPM_ANX7447) const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { diff --git a/board/plankton/build.mk b/board/plankton/build.mk index 89a01e629b..662be139c7 100644 --- a/board/plankton/build.mk +++ b/board/plankton/build.mk @@ -11,4 +11,4 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x board-y=board.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o diff --git a/board/plankton/usb_pd_pdo.c b/board/plankton/usb_pd_pdo.c new file mode 100644 index 0000000000..f51a40abdc --- /dev/null +++ b/board/plankton/usb_pd_pdo.c @@ -0,0 +1,45 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS (PDO_FIXED_DATA_SWAP | PDO_FIXED_UNCONSTRAINED |\ + PDO_FIXED_COMM_CAP) + +/* Source PDOs */ +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(20000, 3000, PDO_FIXED_FLAGS), +}; + +/* Fake PDOs : we just want our pre-defined voltages */ +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_FIXED(12000, 500, PDO_FIXED_FLAGS), + PDO_FIXED(20000, 500, PDO_FIXED_FLAGS), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + +static const int pd_src_pdo_cnts[] = { + [SRC_CAP_5V] = 1, + [SRC_CAP_12V] = 2, + [SRC_CAP_20V] = 3, +}; + +static int pd_src_pdo_idx; + +void board_set_source_cap(enum board_src_cap cap) +{ + pd_src_pdo_idx = cap; +} + +int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port) +{ + *src_pdo = pd_src_pdo; + return pd_src_pdo_cnts[pd_src_pdo_idx]; +} diff --git a/board/plankton/usb_pd_pdo.h b/board/plankton/usb_pd_pdo.h new file mode 100644 index 0000000000..20e8976348 --- /dev/null +++ b/board/plankton/usb_pd_pdo.h @@ -0,0 +1,19 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_PLANKTON_USB_PD_PDO_H +#define __CROS_EC_BOARD_PLANKTON_USB_PD_PDO_H + +#include "stdint.h" + +extern const uint32_t pd_src_pdo[3]; + +extern const uint32_t pd_snk_pdo[3]; +extern const int pd_snk_pdo_cnt; + +void board_set_source_cap(enum board_src_cap cap); +int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port); + +#endif /* __CROS_EC_BOARD_PLANKTON_USB_PD_PDO_H */ diff --git a/board/plankton/usb_pd_policy.c b/board/plankton/usb_pd_policy.c index 8cb24372a0..238f2297f5 100644 --- a/board/plankton/usb_pd_policy.c +++ b/board/plankton/usb_pd_policy.c @@ -15,6 +15,7 @@ #include "timer.h" #include "util.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #include "usb_pd_tcpm.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) @@ -23,44 +24,9 @@ /* Acceptable margin between requested VBUS and measured value */ #define MARGIN_MV 400 /* mV */ -#define PDO_FIXED_FLAGS (PDO_FIXED_DATA_SWAP | PDO_FIXED_UNCONSTRAINED |\ - PDO_FIXED_COMM_CAP) - -/* Source PDOs */ -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), - PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), - PDO_FIXED(20000, 3000, PDO_FIXED_FLAGS), -}; -static const int pd_src_pdo_cnts[] = { - [SRC_CAP_5V] = 1, - [SRC_CAP_12V] = 2, - [SRC_CAP_20V] = 3, -}; - -static int pd_src_pdo_idx; - -/* Fake PDOs : we just want our pre-defined voltages */ -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_FIXED(12000, 500, PDO_FIXED_FLAGS), - PDO_FIXED(20000, 500, PDO_FIXED_FLAGS), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - /* Whether alternate mode has been entered or not */ static int alt_mode; -void board_set_source_cap(enum board_src_cap cap) -{ - pd_src_pdo_idx = cap; -} - -int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port) -{ - *src_pdo = pd_src_pdo; - return pd_src_pdo_cnts[pd_src_pdo_idx]; -} void pd_set_input_current_limit(int port, uint32_t max_ma, uint32_t supply_voltage) diff --git a/board/servo_v4/build.mk b/board/servo_v4/build.mk index 6336bbfab6..6c39be0475 100644 --- a/board/servo_v4/build.mk +++ b/board/servo_v4/build.mk @@ -14,6 +14,6 @@ CHIP_VARIANT:=stm32f07x test-list-y= board-y=board.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o all_deps=$(patsubst ro,,$(def_all_deps)) diff --git a/board/servo_v4/usb_pd_pdo.c b/board/servo_v4/usb_pd_pdo.c new file mode 100644 index 0000000000..8df0eac2c2 --- /dev/null +++ b/board/servo_v4/usb_pd_pdo.c @@ -0,0 +1,56 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "charge_manager.h" +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_config.h" +#include "usb_pd_pdo.h" + +#define CHG_PDO_FIXED_FLAGS (PDO_FIXED_DATA_SWAP) + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, CHG_PDO_FIXED_FLAGS), + PDO_BATT(4750, 21000, 15000), + PDO_VAR(4750, 21000, 3000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + +/* + * Dynamic PDO that reflects capabilities present on the CHG port. Allow for + * multiple entries so that we can offer greater than 5V charging. The 1st + * entry will be fixed 5V, but its current value may change based on the CHG + * port vbus info. Subsequent entries are used for when offering vbus greater + * than 5V. + */ +const uint16_t pd_src_voltages_mv[] = { + 5000, 9000, 10000, 12000, 15000, 20000, +}; +uint32_t pd_src_chg_pdo[ARRAY_SIZE(pd_src_voltages_mv)]; +uint8_t chg_pdo_cnt; + +int active_charge_port = CHARGE_PORT_NONE; +struct vbus_prop vbus[CONFIG_USB_PD_PORT_MAX_COUNT]; + +int charge_port_is_active(void) +{ + return active_charge_port == CHG && vbus[CHG].mv > 0; +} + +int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port) +{ + int pdo_cnt = 0; + + /* + * If CHG is providing VBUS, then advertise what's available on the CHG + * port, otherwise we provide no power. + */ + if (charge_port_is_active()) { + *src_pdo = pd_src_chg_pdo; + pdo_cnt = chg_pdo_cnt; + } + + return pdo_cnt; +} diff --git a/board/servo_v4/usb_pd_pdo.h b/board/servo_v4/usb_pd_pdo.h new file mode 100644 index 0000000000..bb9d8adca6 --- /dev/null +++ b/board/servo_v4/usb_pd_pdo.h @@ -0,0 +1,30 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_SERVO_V4_USB_PD_PDO_H +#define __CROS_EC_BOARD_SERVO_V4_USB_PD_PDO_H + +#include "compile_time_macros.h" +#include "stdint.h" + +extern const uint32_t pd_snk_pdo[3]; +extern const int pd_snk_pdo_cnt; + +extern const uint16_t pd_src_voltages_mv[6]; +extern uint32_t pd_src_chg_pdo[ARRAY_SIZE(pd_src_voltages_mv)]; +extern uint8_t chg_pdo_cnt; + +extern int active_charge_port; + +struct vbus_prop { + int mv; + int ma; +}; +extern struct vbus_prop vbus[CONFIG_USB_PD_PORT_MAX_COUNT]; + +int charge_port_is_active(void); +int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port); + +#endif /* __CROS_EC_BOARD_SERVO_V4_USB_PD_PDO_H */ diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c index 00eaa1e628..61931cda8b 100644 --- a/board/servo_v4/usb_pd_policy.c +++ b/board/servo_v4/usb_pd_policy.c @@ -25,6 +25,7 @@ #include "usb_mux.h" #include "usb_pd.h" #include "usb_pd_config.h" +#include "usb_pd_pdo.h" #include "usb_pd_tcpm.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) @@ -33,8 +34,6 @@ #define DUT_PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ PDO_FIXED_COMM_CAP) -#define CHG_PDO_FIXED_FLAGS (PDO_FIXED_DATA_SWAP) - #define VBUS_UNCHANGED(curr, pend, new) (curr == new && pend == new) /* Macros to config the PD role */ @@ -88,32 +87,6 @@ #define DUT_BOTH_CC_PD(r) DUT_BOTH_CC_SET(r, GPIO_OUT_LOW) #define DUT_BOTH_CC_OPEN(r) DUT_BOTH_CC_SET(r, GPIO_INPUT) -/* - * Dynamic PDO that reflects capabilities present on the CHG port. Allow for - * multiple entries so that we can offer greater than 5V charging. The 1st - * entry will be fixed 5V, but its current value may change based on the CHG - * port vbus info. Subsequent entries are used for when offering vbus greater - * than 5V. - */ -static const uint16_t pd_src_voltages_mv[] = { - 5000, 9000, 10000, 12000, 15000, 20000, -}; -static uint32_t pd_src_chg_pdo[ARRAY_SIZE(pd_src_voltages_mv)]; -static uint8_t chg_pdo_cnt; - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, CHG_PDO_FIXED_FLAGS), - PDO_BATT(4750, 21000, 15000), - PDO_VAR(4750, 21000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - -struct vbus_prop { - int mv; - int ma; -}; -static struct vbus_prop vbus[CONFIG_USB_PD_PORT_MAX_COUNT]; -static int active_charge_port = CHARGE_PORT_NONE; static enum charge_supplier active_charge_supplier; static uint8_t vbus_rp = TYPEC_RP_RESERVED; @@ -172,11 +145,6 @@ static uint32_t max_supported_voltage(void) user_limited_max_mv; } -static int charge_port_is_active(void) -{ - return active_charge_port == CHG && vbus[CHG].mv > 0; -} - static int is_charge_through_allowed(void) { return charge_port_is_active() && cc_config & CC_ALLOW_SRC; @@ -606,22 +574,6 @@ int board_select_rp_value(int port, int rp) return EC_SUCCESS; } -int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port) -{ - int pdo_cnt = 0; - - /* - * If CHG is providing VBUS, then advertise what's available on the CHG - * port, otherwise we provide no power. - */ - if (charge_port_is_active()) { - *src_pdo = pd_src_chg_pdo; - pdo_cnt = chg_pdo_cnt; - } - - return pdo_cnt; -} - __override void pd_transition_voltage(int idx) { timestamp_t deadline; diff --git a/board/twinkie/build.mk b/board/twinkie/build.mk index 6fc2067d8f..3ced5f2966 100644 --- a/board/twinkie/build.mk +++ b/board/twinkie/build.mk @@ -10,5 +10,5 @@ CHIP:=stm32 CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x -board-y=board.o usb_pd_policy.o injector.o simpletrace.o +board-y=board.o usb_pd_policy.o injector.o simpletrace.o usb_pd_pdo.o board-$(HAS_TASK_SNIFFER)+=sniffer.o diff --git a/board/twinkie/usb_pd_pdo.c b/board/twinkie/usb_pd_pdo.c new file mode 100644 index 0000000000..120c13125b --- /dev/null +++ b/board/twinkie/usb_pd_pdo.c @@ -0,0 +1,24 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +#define PDO_FIXED_FLAGS (PDO_FIXED_UNCONSTRAINED | PDO_FIXED_DATA_SWAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(20000, 3000, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_BATT(4750, 21000, 15000), + PDO_VAR(4750, 21000, 3000), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); diff --git a/board/twinkie/usb_pd_pdo.h b/board/twinkie/usb_pd_pdo.h new file mode 100644 index 0000000000..377ccce1b5 --- /dev/null +++ b/board/twinkie/usb_pd_pdo.h @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_TWINKIE_USB_PD_PDO_H +#define __CROS_EC_BOARD_TWINKIE_USB_PD_PDO_H + +#include "stdint.h" + +extern const uint32_t pd_src_pdo[3]; +extern const int pd_src_pdo_cnt; + +extern const uint32_t pd_snk_pdo[3]; +extern const int pd_snk_pdo_cnt; + +#endif /* __CROS_EC_BOARD_TWINKIE_USB_PD_PDO_H */ diff --git a/board/twinkie/usb_pd_policy.c b/board/twinkie/usb_pd_policy.c index 62ecd6e0db..a8f76b40e5 100644 --- a/board/twinkie/usb_pd_policy.c +++ b/board/twinkie/usb_pd_policy.c @@ -13,26 +13,11 @@ #include "timer.h" #include "util.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -#define PDO_FIXED_FLAGS (PDO_FIXED_UNCONSTRAINED | PDO_FIXED_DATA_SWAP) - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), - PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), - PDO_FIXED(20000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_BATT(4750, 21000, 15000), - PDO_VAR(4750, 21000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - void pd_set_input_current_limit(int port, uint32_t max_ma, uint32_t supply_voltage) { diff --git a/board/zinger/build.mk b/board/zinger/build.mk index 566cf34ce0..c85eb9df4b 100644 --- a/board/zinger/build.mk +++ b/board/zinger/build.mk @@ -10,4 +10,4 @@ CHIP:=stm32 CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f03x -board-y=board.o hardware.o runtime.o usb_pd_policy.o +board-y=board.o hardware.o runtime.o usb_pd_policy.o usb_pd_pdo.o diff --git a/board/zinger/usb_pd_pdo.c b/board/zinger/usb_pd_pdo.c new file mode 100644 index 0000000000..13f8407d6d --- /dev/null +++ b/board/zinger/usb_pd_pdo.c @@ -0,0 +1,17 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "compile_time_macros.h" +#include "usb_pd.h" +#include "usb_pd_pdo.h" + +/* Power Delivery Objects */ +const uint32_t pd_src_pdo[] = { + [PDO_IDX_5V] = PDO_FIXED(5000, RATED_CURRENT, PDO_FIXED_FLAGS), + [PDO_IDX_12V] = PDO_FIXED(12000, RATED_CURRENT, PDO_FIXED_FLAGS), + [PDO_IDX_20V] = PDO_FIXED(20000, RATED_CURRENT, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); +BUILD_ASSERT(ARRAY_SIZE(pd_src_pdo) == PDO_IDX_COUNT); diff --git a/board/zinger/usb_pd_pdo.h b/board/zinger/usb_pd_pdo.h new file mode 100644 index 0000000000..07b7129202 --- /dev/null +++ b/board/zinger/usb_pd_pdo.h @@ -0,0 +1,30 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_BOARD_ZINGER_USB_PD_PDO_H +#define __CROS_EC_BOARD_ZINGER_USB_PD_PDO_H + +/* Max current */ +#if defined(BOARD_ZINGER) +#define RATED_CURRENT 3000 +#elif defined(BOARD_MINIMUFFIN) +#define RATED_CURRENT 2250 +#endif + +/* Voltage indexes for the PDOs */ +enum volt_idx { + PDO_IDX_5V = 0, + PDO_IDX_12V = 1, + PDO_IDX_20V = 2, + + PDO_IDX_COUNT +}; + +#define PDO_FIXED_FLAGS (PDO_FIXED_UNCONSTRAINED | PDO_FIXED_DATA_SWAP) + +extern const uint32_t pd_src_pdo[3]; +extern const int pd_src_pdo_cnt; + +#endif /* __CROS_EC_BOARD_ZINGER_USB_PD_PDO_H */ diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c index f47789e063..098bb13c0f 100644 --- a/board/zinger/usb_pd_policy.c +++ b/board/zinger/usb_pd_policy.c @@ -15,6 +15,7 @@ #include "timer.h" #include "util.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" /* ------------------------- Power supply control ------------------------ */ @@ -88,13 +89,6 @@ static timestamp_t fault_deadline; /* convert raw ADC value to mV */ #define ADC_TO_VOLT_MV(vbus) ((vbus)*VOLT_DIV*VDDA_MV/ADC_SCALE) -/* Max current */ -#if defined(BOARD_ZINGER) -#define RATED_CURRENT 3000 -#elif defined(BOARD_MINIMUFFIN) -#define RATED_CURRENT 2250 -#endif - /* Max current : 20% over rated current */ #define MAX_CURRENT VBUS_MA(RATED_CURRENT * 6/5) /* Fast short circuit protection : 50% over rated current */ @@ -154,26 +148,6 @@ static void discharge_voltage(int target_volt) /* ----------------------- USB Power delivery policy ---------------------- */ -#define PDO_FIXED_FLAGS (PDO_FIXED_UNCONSTRAINED | PDO_FIXED_DATA_SWAP) - -/* Voltage indexes for the PDOs */ -enum volt_idx { - PDO_IDX_5V = 0, - PDO_IDX_12V = 1, - PDO_IDX_20V = 2, - - PDO_IDX_COUNT -}; - -/* Power Delivery Objects */ -const uint32_t pd_src_pdo[] = { - [PDO_IDX_5V] = PDO_FIXED(5000, RATED_CURRENT, PDO_FIXED_FLAGS), - [PDO_IDX_12V] = PDO_FIXED(12000, RATED_CURRENT, PDO_FIXED_FLAGS), - [PDO_IDX_20V] = PDO_FIXED(20000, RATED_CURRENT, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); -BUILD_ASSERT(ARRAY_SIZE(pd_src_pdo) == PDO_IDX_COUNT); - /* PDO voltages (should match the table above) */ static const struct { enum volt select; /* GPIO configuration to select the voltage */ diff --git a/common/build.mk b/common/build.mk index 3405a34a2b..901d0d3c9d 100644 --- a/common/build.mk +++ b/common/build.mk @@ -168,9 +168,10 @@ common-$(CONFIG_USB_PORT_POWER_DUMB)+=usb_port_power_dumb.o common-$(CONFIG_USB_PORT_POWER_SMART)+=usb_port_power_smart.o common-$(CONFIG_HAS_TASK_PD_INT)+=usbc_intr_task.o ifneq ($(CONFIG_USB_POWER_DELIVERY),) -common-$(CONFIG_USB_POWER_DELIVERY)+=usb_common.o +common-$(CONFIG_USB_POWER_DELIVERY)+=usb_common.o usb_pd_pdo.o ifneq ($(CONFIG_USB_PD_TCPMV1),) -common-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_protocol.o usb_pd_policy.o +common-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_protocol.o usb_pd_policy.o \ + usb_pd_pdo.o endif common-$(CONFIG_USB_PD_DUAL_ROLE)+=usb_pd_dual_role.o common-$(CONFIG_USB_PD_HOST_CMD)+=usb_pd_host_cmd.o diff --git a/common/usb_common.c b/common/usb_common.c index 6c51da3358..02344fa3f5 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -698,30 +698,6 @@ __overridable void typec_set_source_current_limit(int p, enum tcpc_rp_value rp) ppc_set_vbus_source_current_limit(p, rp); } -/* ---------------- Power Data Objects (PDOs) ----------------- */ -#ifndef CONFIG_USB_PD_CUSTOM_PDO -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); -const uint32_t pd_src_pdo_max[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, - GENERIC_MIN((PD_OPERATING_POWER_MW / 5), PD_MAX_CURRENT_MA), - PDO_FIXED_FLAGS), - PDO_BATT(4750, PD_MAX_VOLTAGE_MV, PD_OPERATING_POWER_MW), - PDO_VAR(4750, PD_MAX_VOLTAGE_MV, PD_MAX_CURRENT_MA), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); -#endif /* CONFIG_USB_PD_CUSTOM_PDO */ - /* ----------------- Vendor Defined Messages ------------------ */ #if defined(CONFIG_USB_PE_SM) && !defined(CONFIG_USB_VPD) && \ !defined(CONFIG_USB_CTVPD) diff --git a/common/usb_pd_pdo.c b/common/usb_pd_pdo.c new file mode 100644 index 0000000000..cfa355bf0e --- /dev/null +++ b/common/usb_pd_pdo.c @@ -0,0 +1,33 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "usb_pd.h" +#include "util.h" +#include "usb_pd_pdo.h" + +#ifndef CONFIG_USB_PD_CUSTOM_PDO + +#define PDO_FIXED_FLAGS \ + (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP | PDO_FIXED_COMM_CAP) + +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); +const uint32_t pd_src_pdo_max[] = { + PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), +}; +const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max); + +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, + GENERIC_MIN((PD_OPERATING_POWER_MW / 5), PD_MAX_CURRENT_MA), + PDO_FIXED_FLAGS), + PDO_BATT(4750, PD_MAX_VOLTAGE_MV, PD_OPERATING_POWER_MW), + PDO_VAR(4750, PD_MAX_VOLTAGE_MV, PD_MAX_CURRENT_MA), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + +#endif /* CONFIG_USB_PD_CUSTOM_PDO */ diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c index eb2dfc52c0..e3a392d5dc 100644 --- a/common/usbc/usb_pd_dpm.c +++ b/common/usbc/usb_pd_dpm.c @@ -21,6 +21,7 @@ #include "usb_pd.h" #include "usb_pd_dpm.h" #include "usb_pd_tcpm.h" +#include "usb_pd_pdo.h" #include "usb_tbt_alt_mode.h" #ifdef CONFIG_COMMON_RUNTIME diff --git a/include/usb_pd_pdo.h b/include/usb_pd_pdo.h new file mode 100644 index 0000000000..4219c05183 --- /dev/null +++ b/include/usb_pd_pdo.h @@ -0,0 +1,19 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_COMMON_USB_PD_PDO_H +#define __CROS_EC_COMMON_USB_PD_PDO_H + +/* ---------------- Power Data Objects (PDOs) ----------------- */ +#ifndef CONFIG_USB_PD_CUSTOM_PDO +extern const uint32_t pd_src_pdo[1]; +extern const int pd_src_pdo_cnt; +extern const uint32_t pd_src_pdo_max[1]; +extern const int pd_src_pdo_max_cnt; +extern const uint32_t pd_snk_pdo[3]; +extern const int pd_snk_pdo_cnt; +#endif /* CONFIG_USB_PD_CUSTOM_PDO */ + +#endif /* __CROS_EC_COMMON_USB_PD_PDO_H */ diff --git a/util/build.mk b/util/build.mk index 3c8ce256e0..e8ed2c8204 100644 --- a/util/build.mk +++ b/util/build.mk @@ -47,10 +47,10 @@ build-util-bin-y+=genvif build-util-art-y+=$(BOARD)_vif.xml # usb_pd_policy.c can be in baseboard, or board, or both. -genvif-pd-srcs=$(sort $(wildcard $(BASEDIR)/usb_pd_policy.c \ - board/$(BOARD)/usb_pd_policy.c)) +genvif-pd-srcs=$(sort $(wildcard $(BASEDIR)/usb_pd_pdo.c \ + board/$(BOARD)/usb_pd_pdo.c)) genvif-pd-objs=$(genvif-pd-srcs:%.c=$(out)/util/%.o) -genvif-pd-objs += $(out)/common/usb_common.o +genvif-pd-objs += $(out)/common/usb_common.o $(out)/common/usb_pd_pdo.o deps-$(CONFIG_USB_POWER_DELIVERY) += $(genvif-pd-objs:%.o=%.o.d) $(out)/util/genvif: $(genvif-pd-objs) util/genvif.h board/$(BOARD)/board.h \ @@ -63,9 +63,15 @@ STANDALONE_FLAGS=-ffreestanding -fno-builtin -nostdinc \ $(out)/util/%/usb_pd_policy.o: %/usb_pd_policy.c -@ mkdir -p $(@D) $(call quiet,c_to_vif,BUILDCC) +$(out)/util/%/usb_pd_pdo.o: %/usb_pd_pdo.c + -@ mkdir -p $(@D) + $(call quiet,c_to_vif,BUILDCC) $(out)/common/usb_common.o: common/usb_common.c -@ mkdir -p $(@D) $(call quiet,c_to_vif,BUILDCC) +$(out)/common/usb_pd_pdo.o: common/usb_pd_pdo.c + -@ mkdir -p $(@D) + $(call quiet,c_to_vif,BUILDCC) endif # CONFIG_USB_POWER_DELIVERY ifneq ($(CONFIG_BOOTBLOCK),) diff --git a/util/genvif.c b/util/genvif.c index ca2b63d9e5..3c9ec3bb89 100644 --- a/util/genvif.c +++ b/util/genvif.c @@ -19,6 +19,7 @@ #include "config.h" #include "usb_pd.h" +#include "usb_pd_pdo.h" #include "usb_pd_tcpm.h" #include "charge_manager.h" diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 4a3b56a856..0ff7f890be 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -311,6 +311,7 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USB_PORT_POWER_DUMB zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USB_POWER_DELIVERY "${PLATFORM_EC}/common/usb_common.c" + "${PLATFORM_EC}/common/usb_pd_pdo.c" "${PLATFORM_EC}/common/usbc/usbc_task.c" "${PLATFORM_EC}/common/usbc/usb_pd_timer.c" "${PLATFORM_EC}/common/usbc/usb_sm.c" |