Skip to content

Commit 46b11f1

Browse files
tmon-nordickartben
authored andcommitted
drivers: udc_dwc2: Inline vendor quirks if possible
Constify vendor quirks structure to not keep it in RAM. Use constified vendor quirks structure directly if there is only one snps,dwc2 instance to allow compiler inlining quirk implementation. Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no> Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
1 parent 957f10c commit 46b11f1

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

drivers/usb/udc/udc_dwc2.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#define DT_DRV_COMPAT snps_dwc2
8+
79
#include "udc_common.h"
810
#include "udc_dwc2.h"
911

@@ -22,7 +24,6 @@
2224

2325
#include <zephyr/logging/log.h>
2426
LOG_MODULE_REGISTER(udc_dwc2, CONFIG_UDC_DRIVER_LOG_LEVEL);
25-
#include "udc_dwc2_vendor_quirks.h"
2627

2728
enum dwc2_drv_event_type {
2829
/* USB connection speed determined after bus reset */
@@ -3200,13 +3201,6 @@ static const struct udc_api udc_dwc2_api = {
32003201
.ep_dequeue = udc_dwc2_ep_dequeue,
32013202
};
32023203

3203-
#define DT_DRV_COMPAT snps_dwc2
3204-
3205-
#define UDC_DWC2_VENDOR_QUIRK_GET(n) \
3206-
COND_CODE_1(DT_NODE_VENDOR_HAS_IDX(DT_DRV_INST(n), 1), \
3207-
(&dwc2_vendor_quirks_##n), \
3208-
(NULL))
3209-
32103204
#define UDC_DWC2_DT_INST_REG_ADDR(n) \
32113205
COND_CODE_1(DT_NUM_REGS(DT_DRV_INST(n)), (DT_INST_REG_ADDR(n)), \
32123206
(DT_INST_REG_ADDR_BY_NAME(n, core)))

drivers/usb/udc/udc_dwc2.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct udc_dwc2_config {
4646
/* Pointer to pin control configuration or NULL */
4747
struct pinctrl_dev_config *const pcfg;
4848
/* Pointer to vendor quirks or NULL */
49-
struct dwc2_vendor_quirks *const quirks;
49+
const struct dwc2_vendor_quirks *const quirks;
5050
void (*make_thread)(const struct device *dev);
5151
void (*irq_enable_func)(const struct device *dev);
5252
void (*irq_disable_func)(const struct device *dev);
@@ -55,13 +55,23 @@ struct udc_dwc2_config {
5555
uint32_t ghwcfg4;
5656
};
5757

58+
#include "udc_dwc2_vendor_quirks.h"
59+
60+
#define UDC_DWC2_VENDOR_QUIRK_GET(n) \
61+
COND_CODE_1(DT_NODE_VENDOR_HAS_IDX(DT_DRV_INST(n), 1), \
62+
(&dwc2_vendor_quirks_##n), \
63+
(NULL))
64+
5865
#define DWC2_QUIRK_FUNC_DEFINE(fname) \
5966
static inline int dwc2_quirk_##fname(const struct device *dev) \
6067
{ \
6168
const struct udc_dwc2_config *const config = dev->config; \
62-
struct dwc2_vendor_quirks *quirks = config->quirks; \
69+
const struct dwc2_vendor_quirks *const quirks = \
70+
COND_CODE_1(IS_EQ(DT_NUM_INST_STATUS_OKAY(snps_dwc2), 1), \
71+
(UDC_DWC2_VENDOR_QUIRK_GET(0); ARG_UNUSED(config);), \
72+
(config->quirks;)) \
6373
\
64-
if (quirks != NULL && config->quirks->fname != NULL) { \
74+
if (quirks != NULL && quirks->fname != NULL) { \
6575
return quirks->fname(dev); \
6676
} \
6777
\

drivers/usb/udc/udc_dwc2_vendor_quirks.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ struct usb_dw_stm32_clk {
2525
size_t pclken_len;
2626
};
2727

28-
#define DT_DRV_COMPAT snps_dwc2
29-
3028
static inline int stm32f4_fsotg_enable_clk(const struct usb_dw_stm32_clk *const clk)
3129
{
3230
int ret;
@@ -94,7 +92,7 @@ static inline int stm32f4_fsotg_disable_phy(const struct device *dev)
9492
return stm32f4_fsotg_enable_clk(&stm32f4_clk_##n); \
9593
} \
9694
\
97-
struct dwc2_vendor_quirks dwc2_vendor_quirks_##n = { \
95+
const struct dwc2_vendor_quirks dwc2_vendor_quirks_##n = { \
9896
.pre_enable = stm32f4_fsotg_enable_clk_##n, \
9997
.post_enable = stm32f4_fsotg_enable_phy, \
10098
.disable = stm32f4_fsotg_disable_phy, \
@@ -104,14 +102,11 @@ static inline int stm32f4_fsotg_disable_phy(const struct device *dev)
104102

105103
DT_INST_FOREACH_STATUS_OKAY(QUIRK_STM32F4_FSOTG_DEFINE)
106104

107-
#undef DT_DRV_COMPAT
108-
109105
#endif /*DT_HAS_COMPAT_STATUS_OKAY(st_stm32f4_fsotg) */
110106

111107
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_usbhs)
112108

113-
#define DT_DRV_COMPAT snps_dwc2
114-
109+
#include <zephyr/logging/log.h>
115110
#include <nrfs_backend_ipc_service.h>
116111
#include <nrfs_usb.h>
117112

@@ -129,6 +124,7 @@ static K_EVENT_DEFINE(usbhs_events);
129124

130125
static void usbhs_vbus_handler(nrfs_usb_evt_t const *p_evt, void *const context)
131126
{
127+
LOG_MODULE_DECLARE(udc_dwc2, CONFIG_UDC_DRIVER_LOG_LEVEL);
132128
const struct device *dev = context;
133129

134130
switch (p_evt->type) {
@@ -156,6 +152,7 @@ static void usbhs_vbus_handler(nrfs_usb_evt_t const *p_evt, void *const context)
156152

157153
static inline int usbhs_enable_nrfs_service(const struct device *dev)
158154
{
155+
LOG_MODULE_DECLARE(udc_dwc2, CONFIG_UDC_DRIVER_LOG_LEVEL);
159156
nrfs_err_t nrfs_err;
160157
int err;
161158

@@ -182,6 +179,7 @@ static inline int usbhs_enable_nrfs_service(const struct device *dev)
182179

183180
static inline int usbhs_enable_core(const struct device *dev)
184181
{
182+
LOG_MODULE_DECLARE(udc_dwc2, CONFIG_UDC_DRIVER_LOG_LEVEL);
185183
NRF_USBHS_Type *wrapper = USBHS_DT_WRAPPER_REG_ADDR(0);
186184
k_timeout_t timeout = K_FOREVER;
187185

@@ -229,6 +227,7 @@ static inline int usbhs_disable_core(const struct device *dev)
229227

230228
static inline int usbhs_disable_nrfs_service(const struct device *dev)
231229
{
230+
LOG_MODULE_DECLARE(udc_dwc2, CONFIG_UDC_DRIVER_LOG_LEVEL);
232231
nrfs_err_t nrfs_err;
233232

234233
nrfs_err = nrfs_usb_disable_request((void *)dev);
@@ -297,7 +296,7 @@ static inline int usbhs_pre_hibernation_exit(const struct device *dev)
297296
}
298297

299298
#define QUIRK_NRF_USBHS_DEFINE(n) \
300-
struct dwc2_vendor_quirks dwc2_vendor_quirks_##n = { \
299+
const struct dwc2_vendor_quirks dwc2_vendor_quirks_##n = { \
301300
.init = usbhs_enable_nrfs_service, \
302301
.pre_enable = usbhs_enable_core, \
303302
.disable = usbhs_disable_core, \
@@ -311,8 +310,6 @@ static inline int usbhs_pre_hibernation_exit(const struct device *dev)
311310

312311
DT_INST_FOREACH_STATUS_OKAY(QUIRK_NRF_USBHS_DEFINE)
313312

314-
#undef DT_DRV_COMPAT
315-
316313
#endif /*DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_usbhs) */
317314

318315
/* Add next vendor quirks definition above this line */

0 commit comments

Comments
 (0)