Skip to content

Commit 1857197

Browse files
Raffael Rostagnonashif
authored andcommitted
sdhc: esp32: Clock control setting from DTS
Enable SDIO clock using clock control subsystem instead of low level functions. Signed-off-by: Raffael Rostagno <[email protected]>
1 parent 0e3d9cc commit 1857197

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/sdhc/sdhc_esp32.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/logging/log.h>
1313
#include <soc.h>
1414
#include <zephyr/drivers/pinctrl.h>
15+
#include <zephyr/drivers/clock_control.h>
1516

1617
/* ESP32 includes */
1718
#include <esp_clk_tree.h>
@@ -51,6 +52,8 @@ struct sdhc_esp32_config {
5152

5253
int slot;
5354
const sdmmc_dev_t *sdio_hw;
55+
const struct device *clock_dev;
56+
const clock_control_subsys_t clock_subsys;
5457
const struct pinctrl_dev_config *pcfg;
5558
const struct gpio_dt_spec pwr_gpio;
5659
/*
@@ -1320,9 +1323,16 @@ static int sdhc_esp32_init(const struct device *dev)
13201323
return -EINVAL;
13211324
}
13221325

1323-
/* enable bus clock for registers */
1324-
sdmmc_ll_enable_bus_clock(sdio_hw, true);
1325-
sdmmc_ll_reset_register(sdio_hw);
1326+
if (!device_is_ready(cfg->clock_dev)) {
1327+
return -ENODEV;
1328+
}
1329+
1330+
ret = clock_control_on(cfg->clock_dev, cfg->clock_subsys);
1331+
1332+
if (ret != 0) {
1333+
LOG_ERR("Error enabling SDHC clock");
1334+
return ret;
1335+
}
13261336

13271337
/* Enable clock to peripheral. Use smallest divider first */
13281338
ret = sdmmc_host_set_clk_div(sdio_hw, 2);
@@ -1406,6 +1416,8 @@ static const struct sdhc_driver_api sdhc_api = {.reset = sdhc_esp32_reset,
14061416
\
14071417
static const struct sdhc_esp32_config sdhc_esp32_##n##_config = { \
14081418
.sdio_hw = (const sdmmc_dev_t *)DT_REG_ADDR(DT_INST_PARENT(n)), \
1419+
.clock_dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(DT_INST_PARENT(n))), \
1420+
.clock_subsys = (clock_control_subsys_t)DT_CLOCKS_CELL(DT_INST_PARENT(n), offset), \
14091421
.irq_source = DT_IRQN(DT_INST_PARENT(n)), \
14101422
.slot = DT_REG_ADDR(DT_DRV_INST(n)), \
14111423
.bus_width_cfg = DT_INST_PROP(n, bus_width), \

0 commit comments

Comments
 (0)