|
12 | 12 | #include <zephyr/logging/log.h>
|
13 | 13 | #include <soc.h>
|
14 | 14 | #include <zephyr/drivers/pinctrl.h>
|
| 15 | +#include <zephyr/drivers/clock_control.h> |
15 | 16 |
|
16 | 17 | /* ESP32 includes */
|
17 | 18 | #include <esp_clk_tree.h>
|
@@ -51,6 +52,8 @@ struct sdhc_esp32_config {
|
51 | 52 |
|
52 | 53 | int slot;
|
53 | 54 | const sdmmc_dev_t *sdio_hw;
|
| 55 | + const struct device *clock_dev; |
| 56 | + const clock_control_subsys_t clock_subsys; |
54 | 57 | const struct pinctrl_dev_config *pcfg;
|
55 | 58 | const struct gpio_dt_spec pwr_gpio;
|
56 | 59 | /*
|
@@ -1320,9 +1323,16 @@ static int sdhc_esp32_init(const struct device *dev)
|
1320 | 1323 | return -EINVAL;
|
1321 | 1324 | }
|
1322 | 1325 |
|
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 | + } |
1326 | 1336 |
|
1327 | 1337 | /* Enable clock to peripheral. Use smallest divider first */
|
1328 | 1338 | 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,
|
1406 | 1416 | \
|
1407 | 1417 | static const struct sdhc_esp32_config sdhc_esp32_##n##_config = { \
|
1408 | 1418 | .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), \ |
1409 | 1421 | .irq_source = DT_IRQN(DT_INST_PARENT(n)), \
|
1410 | 1422 | .slot = DT_REG_ADDR(DT_DRV_INST(n)), \
|
1411 | 1423 | .bus_width_cfg = DT_INST_PROP(n, bus_width), \
|
|
0 commit comments