Skip to content

Commit 172aa36

Browse files
mathieuchopstmfabiobaltieri
authored andcommitted
drivers: usb: udc: stm32: use direct function calls for clock on/off
To enable/disable clocks, the UDC driver used function pointers stored in the instance private data(!), which *could* be NULL... but in practice, they were always initialized. Furthermore, the clock configuration is done through Clock Control API calls so the code can be shared by all instances. Replace indirect calls through function pointers with direct calls to the "priv_clock_(dis|en)able" function, which are renamed to "udc_stm32_..." for consistency with the rest of the driver. The now-unused function pointers are also removed from the instance data structure. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent e5fdd46 commit 172aa36

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/usb/udc/udc_stm32.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ struct udc_stm32_data {
158158
uint32_t occupied_mem;
159159
/* wLength of SETUP packet for s-out-status */
160160
uint32_t ep0_out_wlength;
161-
int (*clk_enable)(void);
162-
int (*clk_disable)(void);
163161
struct k_thread thread_data;
164162
struct k_msgq msgq_data;
165163
};
@@ -193,6 +191,9 @@ struct udc_stm32_msg {
193191
uint16_t rx_count;
194192
};
195193

194+
static int udc_stm32_clock_enable(void);
195+
static int udc_stm32_clock_disable(void);
196+
196197
static void udc_stm32_lock(const struct device *dev)
197198
{
198199
udc_lock_internal(dev, K_FOREVER);
@@ -696,7 +697,7 @@ int udc_stm32_init(const struct device *dev)
696697
const struct udc_stm32_config *cfg = dev->config;
697698
HAL_StatusTypeDef status;
698699

699-
if (priv->clk_enable != NULL && priv->clk_enable() != 0) {
700+
if (udc_stm32_clock_enable() < 0) {
700701
LOG_ERR("Error enabling clock(s)");
701702
return -EIO;
702703
}
@@ -928,7 +929,7 @@ static int udc_stm32_shutdown(const struct device *dev)
928929
/* continue anyway */
929930
}
930931

931-
if (priv->clk_disable != NULL && priv->clk_disable() != 0) {
932+
if (udc_stm32_clock_disable() < 0) {
932933
LOG_ERR("Error disabling clock(s)");
933934
/* continue anyway */
934935
}
@@ -1239,7 +1240,7 @@ static const struct udc_stm32_config udc0_cfg = {
12391240

12401241
static struct stm32_pclken pclken[] = STM32_DT_INST_CLOCKS(0);
12411242

1242-
static int priv_clock_enable(void)
1243+
static int udc_stm32_clock_enable(void)
12431244
{
12441245
const struct device *const clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
12451246

@@ -1449,7 +1450,7 @@ static int priv_clock_enable(void)
14491450
return 0;
14501451
}
14511452

1452-
static int priv_clock_disable(void)
1453+
static int udc_stm32_clock_disable(void)
14531454
{
14541455
const struct device *clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
14551456

@@ -1538,8 +1539,6 @@ static int udc_stm32_driver_init0(const struct device *dev)
15381539
}
15391540

15401541
priv->dev = dev;
1541-
priv->clk_enable = priv_clock_enable;
1542-
priv->clk_disable = priv_clock_disable;
15431542

15441543
k_msgq_init(&priv->msgq_data, udc_msgq_buf_0, sizeof(struct udc_stm32_msg),
15451544
CONFIG_UDC_STM32_MAX_QMESSAGES);

0 commit comments

Comments
 (0)