1 /*
2  * Copyright 2018 - 2022 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __USB_DEVICE_CONFIG_H__
8 #define __USB_DEVICE_CONFIG_H__
9 
10 #include <zephyr/devicetree.h>
11 #include "usb.h"
12 
13 /******************************************************************************
14  * Definitions
15  *****************************************************************************/
16 #ifdef CONFIG_USB_DEVICE_DRIVER
17 /* EHCI instance count */
18 #ifdef CONFIG_USB_DC_NXP_EHCI
19 #define USB_DEVICE_CONFIG_EHCI (1U)
20 /* How many the DTD are supported. */
21 #define USB_DEVICE_CONFIG_EHCI_MAX_DTD (16U)
22 #endif /* CONFIG_USB_DC_NXP_EHCI */
23 
24 #ifdef CONFIG_USB_DC_NXP_LPCIP3511
25 
26 #ifdef USBHSD_BASE_ADDRS
27 #define USB_DEVICE_CONFIG_LPCIP3511HS (1U)
28 #else
29 #define USB_DEVICE_CONFIG_LPCIP3511HS (0U)
30 #endif
31 
32 #ifdef USB_BASE_ADDRS
33 #define USB_DEVICE_CONFIG_LPCIP3511FS (1U)
34 #else
35 #define USB_DEVICE_CONFIG_LPCIP3511FS (0U)
36 #endif
37 
38 #endif /* CONFIG_USB_DC_NXP_LPCIP3511 */
39 
40 /* Whether device is self power. 1U supported, 0U not supported */
41 #define USB_DEVICE_CONFIG_SELF_POWER (1U)
42 
43 #define NUM_INSTS DT_NUM_INST_STATUS_OKAY(nxp_ehci) + DT_NUM_INST_STATUS_OKAY(nxp_lpcip3511)
44 BUILD_ASSERT(NUM_INSTS <= 1, "Only one USB device supported");
45 #if DT_HAS_COMPAT_STATUS_OKAY(nxp_lpcip3511)
46 #undef DT_DRV_COMPAT
47 #define DT_DRV_COMPAT nxp_lpcip3511
48 #elif DT_HAS_COMPAT_STATUS_OKAY(nxp_ehci)
49 #undef DT_DRV_COMPAT
50 #define DT_DRV_COMPAT nxp_ehci
51 #endif
52 
53 /* Number of endpoints supported */
54 #define USB_DEVICE_CONFIG_ENDPOINTS (DT_INST_PROP(0, num_bidir_endpoints))
55 #else
56 
57 #ifdef CONFIG_UDC_NXP_EHCI
58 #define USB_DEVICE_CONFIG_EHCI (DT_NUM_INST_STATUS_OKAY(nxp_ehci))
59 #endif
60 
61 #ifdef CONFIG_UDC_NXP_IP3511
62 
63 #if defined(USBHSD_BASE_ADDRS) && defined(USB_BASE_ADDRS)
64 #define USB_DEVICE_CONFIG_LPCIP3511HS (1U)
65 #define USB_DEVICE_CONFIG_LPCIP3511FS (1U)
66 
67 #else
68 
69 #ifdef USBHSD_BASE_ADDRS
70 #define USB_DEVICE_CONFIG_LPCIP3511HS (DT_NUM_INST_STATUS_OKAY(nxp_lpcip3511))
71 #else
72 #define USB_DEVICE_CONFIG_LPCIP3511HS (0U)
73 #endif
74 
75 #ifdef USB_BASE_ADDRS
76 #define USB_DEVICE_CONFIG_LPCIP3511FS (DT_NUM_INST_STATUS_OKAY(nxp_lpcip3511))
77 #else
78 #define USB_DEVICE_CONFIG_LPCIP3511FS (0U)
79 #endif
80 
81 #endif
82 #endif
83 
84 /* calculte the num of endponts.
85  * mcux ip3511 driver doesn't use USB_DEVICE_CONFIG_ENDPOINTS,
86  * so use ehci endpoint number if ehci is enabled.
87  */
88 #if DT_HAS_COMPAT_STATUS_OKAY(nxp_ehci)
89 #undef DT_DRV_COMPAT
90 #define DT_DRV_COMPAT nxp_ehci
91 #elif DT_HAS_COMPAT_STATUS_OKAY(nxp_lpcip3511)
92 #undef DT_DRV_COMPAT
93 #define DT_DRV_COMPAT nxp_lpcip3511
94 #endif
95 
96 /* Number of endpoints supported */
97 #define USB_DEVICE_CONFIG_ENDPOINTS (DT_INST_PROP(0, num_bidir_endpoints))
98 
99 #define USB_DEVICE_CONFIG_SELF_POWER (1U)
100 
101 #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U))
102 /*! @brief How many the DTD are supported. */
103 #define USB_DEVICE_CONFIG_EHCI_MAX_DTD (16U)
104 #endif
105 
106 #endif
107 
108 #endif /* __USB_DEVICE_CONFIG_H__ */
109