Skip to content

Commit d770690

Browse files
fanwang-ambiqjhedberg
authored andcommitted
drivers: sdhc:Updated sdhc driver for apollo510&apollo510L
Deleted PM device macro definition Updated SDIO base for apollo510 and apollo510L Signed-off-by: Fan Wang <[email protected]>
1 parent 2290b95 commit d770690

File tree

1 file changed

+9
-35
lines changed

1 file changed

+9
-35
lines changed

drivers/sdhc/sdhc_ambiq.c

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
LOG_MODULE_REGISTER(ambiq_sdio, CONFIG_SDHC_LOG_LEVEL);
2323

2424
#define CACHABLE_START_ADDR SSRAM_BASEADDR
25+
#if defined(CONFIG_SOC_SERIES_APOLLO4X)
26+
#define SDIO_BASE_ADDR SDIO_BASE
27+
#define SDIO_ADDR_INTERVAL 1
28+
#else
29+
#define SDIO_BASE_ADDR SDIO0_BASE
30+
#define SDIO_ADDR_INTERVAL (SDIO1_BASE - SDIO0_BASE)
31+
#endif
2532

2633
struct ambiq_sdio_config {
2734
SDIO_Type *pSDHC;
@@ -119,13 +126,11 @@ static int ambiq_sdio_reset(const struct device *dev)
119126
uint32_t ui32Status = 0;
120127
int ret = 0;
121128

122-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
123129
ret = pm_device_runtime_get(dev);
124130

125131
if (ret < 0) {
126132
LOG_ERR("pm_device_runtime_get failed: %d", ret);
127133
}
128-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
129134

130135
LOG_DBG("SDHC Software Reset");
131136
ui32Status = am_hal_sdhc_software_reset(config->pSDHC, AM_HAL_SDHC_SW_RESET_ALL);
@@ -134,7 +139,6 @@ static int ambiq_sdio_reset(const struct device *dev)
134139
ret = -EIO;
135140
}
136141

137-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
138142
/* Use async put to avoid useless device suspension/resumption
139143
* when doing consecutive transmission.
140144
*/
@@ -143,7 +147,6 @@ static int ambiq_sdio_reset(const struct device *dev)
143147
if (ret < 0) {
144148
LOG_ERR("pm_device_runtime_put failed: %d", ret);
145149
}
146-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
147150

148151
return ret;
149152
}
@@ -238,22 +241,18 @@ static int ambiq_sdio_set_io(const struct device *dev, struct sdhc_io *ios)
238241
return -ENOTSUP;
239242
}
240243

241-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
242244
ret = pm_device_runtime_get(dev);
243245

244246
if (ret < 0) {
245247
LOG_ERR("pm_device_runtime_get failed: %d", ret);
246248
}
247-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
248249

249250
/* Change SDIO Host Bus Voltage */
250251
if (eBusVoltage != data->card.cfg.eIoVoltage) {
251252
data->card.cfg.eIoVoltage = eBusVoltage;
252253
ui32Status = data->host->ops->set_bus_voltage(data->host->pHandle, eBusVoltage);
253254
if (ui32Status != AM_HAL_STATUS_SUCCESS) {
254-
#ifdef CONFIG_PM_DEVICE_RUNTIME
255255
pm_device_runtime_put(dev);
256-
#endif
257256
return -ENOTSUP;
258257
}
259258
}
@@ -263,29 +262,23 @@ static int ambiq_sdio_set_io(const struct device *dev, struct sdhc_io *ios)
263262
data->card.cfg.eBusWidth = eBusWidth;
264263
ui32Status = data->host->ops->set_bus_width(data->host->pHandle, eBusWidth);
265264
if (ui32Status != AM_HAL_STATUS_SUCCESS) {
266-
#ifdef CONFIG_PM_DEVICE_RUNTIME
267265
pm_device_runtime_put(dev);
268-
#endif
269266
return -ENOTSUP;
270267
}
271268
}
272269

273270
/* Change SDIO Host Clock Speed */
274271
ui32Status = data->host->ops->set_bus_clock(data->host->pHandle, data->card.cfg.ui32Clock);
275272
if (ui32Status != AM_HAL_STATUS_SUCCESS) {
276-
#ifdef CONFIG_PM_DEVICE_RUNTIME
277273
pm_device_runtime_put(dev);
278-
#endif
279274
return -ENOTSUP;
280275
}
281276

282277
if (ios->timing == SDHC_TIMING_DDR52) {
283278
LOG_DBG("MMC Card DDR50 Mode");
284279
/* DDR50 mode must be 4bit or 8bit width according to EMMC Spec */
285280
if (eBusWidth == AM_HAL_HOST_BUS_WIDTH_1) {
286-
#ifdef CONFIG_PM_DEVICE_RUNTIME
287281
pm_device_runtime_put(dev);
288-
#endif
289282
return -ENOTSUP;
290283
}
291284
eUHSMode = AM_HAL_HOST_UHS_DDR50;
@@ -296,14 +289,11 @@ static int ambiq_sdio_set_io(const struct device *dev, struct sdhc_io *ios)
296289
data->card.cfg.eUHSMode = eUHSMode;
297290
ui32Status = data->host->ops->set_uhs_mode(data->host->pHandle, eUHSMode);
298291
if (ui32Status != AM_HAL_STATUS_SUCCESS) {
299-
#ifdef CONFIG_PM_DEVICE_RUNTIME
300292
pm_device_runtime_put(dev);
301-
#endif
302293
return -ENOTSUP;
303294
}
304295
}
305296

306-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
307297
/* Use async put to avoid useless device suspension/resumption
308298
* when doing consecutive transmission.
309299
*/
@@ -312,7 +302,6 @@ static int ambiq_sdio_set_io(const struct device *dev, struct sdhc_io *ios)
312302
if (ret < 0) {
313303
LOG_ERR("pm_device_runtime_put failed: %d", ret);
314304
}
315-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
316305

317306
return ret;
318307
}
@@ -399,17 +388,14 @@ static int ambiq_sdio_execute_tuning(const struct device *dev)
399388

400389
/* Timing delay is disabled if both TX and RX delay are set into 0 */
401390
if (ui8TxRxDelays[0] != 0 || ui8TxRxDelays[1] != 0) {
402-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
403391
ret = pm_device_runtime_get(dev);
404392

405393
if (ret < 0) {
406394
LOG_ERR("pm_device_runtime_get failed: %d", ret);
407395
}
408-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
409396

410397
am_hal_card_host_set_txrx_delay(data->host, ui8TxRxDelays);
411398

412-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
413399
/* Use async put to avoid useless device suspension/resumption
414400
* when doing consecutive transmission.
415401
*/
@@ -418,7 +404,6 @@ static int ambiq_sdio_execute_tuning(const struct device *dev)
418404
if (ret < 0) {
419405
LOG_ERR("pm_device_runtime_put failed: %d", ret);
420406
}
421-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
422407
}
423408

424409
return ret;
@@ -431,18 +416,15 @@ static int ambiq_sdio_get_card_present(const struct device *dev)
431416
{
432417
struct ambiq_sdio_data *data = dev->data;
433418
int status = 0;
434-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
435419
int ret = 0;
436420

437421
ret = pm_device_runtime_get(dev);
438422

439423
if (ret < 0) {
440424
LOG_ERR("pm_device_runtime_get failed: %d", ret);
441425
}
442-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
443426
LOG_DBG("Get card present status");
444427
status = data->host->ops->get_cd(data->host->pHandle);
445-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
446428
/* Use async put to avoid useless device suspension/resumption
447429
* when doing consecutive transmission.
448430
*/
@@ -451,7 +433,6 @@ static int ambiq_sdio_get_card_present(const struct device *dev)
451433
if (ret < 0) {
452434
LOG_ERR("pm_device_runtime_put failed: %d", ret);
453435
}
454-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
455436
return status;
456437
}
457438

@@ -462,18 +443,15 @@ static int ambiq_sdio_card_busy(const struct device *dev)
462443
{
463444
struct ambiq_sdio_data *data = dev->data;
464445
uint32_t ui32Status;
465-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
466446
int ret = 0;
467447

468448
ret = pm_device_runtime_get(dev);
469449

470450
if (ret < 0) {
471451
LOG_ERR("pm_device_runtime_get failed: %d", ret);
472452
}
473-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
474453
ui32Status = data->host->ops->card_busy(data->host->pHandle, DEFAULT_GET_STATUS_TIMEOUT_MS);
475454
LOG_DBG("Check card busy status");
476-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
477455
/* Use async put to avoid useless device suspension/resumption
478456
* when doing consecutive transmission.
479457
*/
@@ -482,7 +460,7 @@ static int ambiq_sdio_card_busy(const struct device *dev)
482460
if (ret < 0) {
483461
LOG_ERR("pm_device_runtime_put failed: %d", ret);
484462
}
485-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
463+
486464

487465
return (ui32Status != AM_HAL_STATUS_SUCCESS) ? 1 : 0;
488466
}
@@ -566,13 +544,11 @@ static int ambiq_sdio_request(const struct device *dev, struct sdhc_command *cmd
566544
return -EBUSY;
567545
}
568546

569-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
570547
ret = pm_device_runtime_get(dev);
571548

572549
if (ret < 0) {
573550
LOG_ERR("pm_device_runtime_get failed: %d", ret);
574551
}
575-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
576552

577553
if (data) {
578554
#if defined(CONFIG_CACHE_MANAGEMENT) && defined(CONFIG_DCACHE)
@@ -630,7 +606,6 @@ static int ambiq_sdio_request(const struct device *dev, struct sdhc_command *cmd
630606
data->bytes_xfered = (ui32Status >> 16) & 0xFFFF;
631607
}
632608

633-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
634609
/* Use async put to avoid useless device suspension/resumption
635610
* when doing consecutive transmission.
636611
*/
@@ -639,7 +614,6 @@ static int ambiq_sdio_request(const struct device *dev, struct sdhc_command *cmd
639614
if (ret < 0) {
640615
LOG_ERR("pm_device_runtime_put failed: %d", ret);
641616
}
642-
#endif /* CONFIG_PM_DEVICE_RUNTIME */
643617

644618
return ret;
645619
}
@@ -811,7 +785,7 @@ static int ambiq_sdio_pm_action(const struct device *dev, enum pm_device_action
811785
.pSDHC = (SDIO_Type *)DT_INST_REG_ADDR(n), \
812786
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
813787
.irq_config_func = sdio_##n##_irq_config_func, \
814-
.inst = n, \
788+
.inst = (DT_INST_REG_ADDR(n) - SDIO_BASE_ADDR) / SDIO_ADDR_INTERVAL, \
815789
.tx_delay = DT_INST_PROP(n, txdelay), \
816790
.rx_delay = DT_INST_PROP(n, rxdelay), \
817791
.max_bus_freq = DT_INST_PROP(n, max_bus_freq), \

0 commit comments

Comments
 (0)