drv_sdio.c 16.4 KB
Newer Older
G
greedyhao 已提交
1
/*
G
greedyhao 已提交
2
 * Copyright (c) 2020-2021, Bluetrum Development Team
mysterywolf's avatar
mysterywolf 已提交
3
 *
G
greedyhao 已提交
4 5 6 7
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author            Notes
G
greedyhao 已提交
8
 * 2020-11-30     greedyhao         first version
G
greedyhao 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
 */

#include "drv_sdio.h"
#include "interrupt.h"
#include <rthw.h>

#ifdef BSP_USING_SDIO

// #define DRV_DEBUG
#define LOG_TAG             "drv.sdio"
#include <drv_log.h>

#define SDIO_USING_1_BIT

static struct ab32_sdio_config sdio_config[] =
{
    {.instance = SDMMC0_BASE,
    },
};
static struct rt_mmcsd_host *host = RT_NULL;

#define RTHW_SDIO_LOCK(_sdio)   rt_mutex_take(&(_sdio)->mutex, RT_WAITING_FOREVER)
#define RTHW_SDIO_UNLOCK(_sdio) rt_mutex_release(&(_sdio)->mutex);

struct sdio_pkg
{
    struct rt_mmcsd_cmd *cmd;
    void *buff;
    rt_uint32_t flag;
    rt_uint32_t xfer_blks;
};

struct rthw_sdio
{
    struct rt_mmcsd_host *host;
    struct ab32_sdio_des sdio_des;
    struct rt_event event;
    struct rt_mutex mutex;
    struct sdio_pkg *pkg;
};

ALIGN(SDIO_ALIGN_LEN)
static rt_uint8_t cache_buf[SDIO_BUFF_SIZE];

53
static rt_uint8_t sd_baud = 119;
G
greedyhao 已提交
54

55
rt_uint8_t sysclk_update_baud(rt_uint8_t baud);
G
greedyhao 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151

static rt_uint32_t ab32_sdio_clk_get(hal_sfr_t hw_sdio)
{
    return (get_sysclk_nhz() / (sd_baud+1));
}

/**
  * @brief  This function get order from sdio.
  * @param  data
  * @retval sdio  order
  */
static int get_order(rt_uint32_t data)
{
    int order = 0;

    switch (data)
    {
    case 1:
        order = 0;
        break;
    case 2:
        order = 1;
        break;
    case 4:
        order = 2;
        break;
    case 8:
        order = 3;
        break;
    case 16:
        order = 4;
        break;
    case 32:
        order = 5;
        break;
    case 64:
        order = 6;
        break;
    case 128:
        order = 7;
        break;
    case 256:
        order = 8;
        break;
    case 512:
        order = 9;
        break;
    case 1024:
        order = 10;
        break;
    case 2048:
        order = 11;
        break;
    case 4096:
        order = 12;
        break;
    case 8192:
        order = 13;
        break;
    case 16384:
        order = 14;
        break;
    default :
        order = 0;
        break;
    }

    return order;
}

/**
  * @brief  This function wait sdio completed.
  * @param  sdio  rthw_sdio
  * @retval None
  */
static void rthw_sdio_wait_completed(struct rthw_sdio *sdio)
{
    rt_uint32_t status = 0;
    struct rt_mmcsd_cmd *cmd = sdio->pkg->cmd;
    struct rt_mmcsd_data *data = cmd->data;
    hal_sfr_t hw_sdio = sdio->sdio_des.hw_sdio;
    rt_err_t tx_finish = -RT_ERROR;

    if (rt_event_recv(&sdio->event, 0xFFFFFFFF & ~HW_SDIO_CON_DFLAG, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
                        rt_tick_from_millisecond(5000), &status) != RT_EOK)
    {
        LOG_E("wait completed timeout");
        cmd->err = -RT_ETIMEOUT;
        return;
    }

    if (sdio->pkg == RT_NULL)
    {
        return;
    }

152 153 154 155
    cmd->resp[0] = hw_sdio[SDxARG3];
    cmd->resp[1] = hw_sdio[SDxARG2];
    cmd->resp[2] = hw_sdio[SDxARG1];
    cmd->resp[3] = hw_sdio[SDxARG0];
G
greedyhao 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291

    if (!(status & HW_SDIO_CON_NRPS)) {
        cmd->err = RT_EOK;
        LOG_D("sta:0x%08X [%08X %08X %08X %08X]", status, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
    } else {
        cmd->err = -RT_ERROR;
    }
}

/**
  * @brief  This function transfer data by dma.
  * @param  sdio  rthw_sdio
  * @param  pkg   sdio package
  * @retval None
  */
static void rthw_sdio_transfer_by_dma(struct rthw_sdio *sdio, struct sdio_pkg *pkg)
{
    struct rt_mmcsd_data *data;
    int size;
    void *buff;
    hal_sfr_t hw_sdio = sdio->sdio_des.hw_sdio;

    if ((RT_NULL == pkg) || (RT_NULL == sdio))
    {
        LOG_E("rthw_sdio_transfer_by_dma invalid args");
        return;
    }

    data = pkg->cmd->data;
    if (RT_NULL == data)
    {
        LOG_E("rthw_sdio_transfer_by_dma invalid args");
        return;
    }

    buff = pkg->buff;
    if (RT_NULL == buff)
    {
        LOG_E("rthw_sdio_transfer_by_dma invalid args");
        return;
    }
    hw_sdio = sdio->sdio_des.hw_sdio;
    size = data->blks * data->blksize;

    if (data->flags & DATA_DIR_WRITE)
    {
        LOG_D("DATA_DIR_WRITE %d", pkg->xfer_blks);
        sdio->sdio_des.txconfig((rt_uint32_t *)((rt_uint8_t *)buff + (pkg->xfer_blks * data->blksize)), 512);
    }
    else if (data->flags & DATA_DIR_READ)
    {
        LOG_D("DATA_DIR_WRITE %d", pkg->xfer_blks);
        sdio->sdio_des.rxconfig((rt_uint32_t *)((rt_uint8_t *)buff + (pkg->xfer_blks * data->blksize)), data->blksize);
    }
}

/**
  * @brief  This function send command.
  * @param  sdio  rthw_sdio
  * @param  pkg   sdio package
  * @retval None
  */
static void rthw_sdio_send_command(struct rthw_sdio *sdio, struct sdio_pkg *pkg)
{
    struct rt_mmcsd_cmd *cmd = pkg->cmd;
    struct rt_mmcsd_data *data = cmd->data;
    hal_sfr_t hw_sdio = sdio->sdio_des.hw_sdio;
    rt_uint32_t reg_cmd = 0;
    rt_uint32_t data_flag = 0;

    /* save pkg */
    sdio->pkg = pkg;

    #define CK8E            BIT(11)             //在命令/数据包后加上8CLK
    #define CBUSY           BIT(10)             //Busy Check
    #define CLRSP           BIT(9)              //17Byte Long Rsp
    #define CRSP            BIT(8)              //Need Rsp

    /* config cmd reg */
    if (cmd->cmd_code != 18) {
        reg_cmd = cmd->cmd_code | 0x40 | CK8E;
    } else {
        reg_cmd = cmd->cmd_code | 0x40;
    }

    switch (resp_type(cmd))
    {
    case RESP_R1B:
        reg_cmd |= CBUSY | CRSP;
        break;
    case RESP_R2:
        reg_cmd |= CLRSP | CRSP;
        break;
    default:
        reg_cmd |= CRSP;
        break;
    }

    LOG_D("CMD:%d 0x%04X ARG:0x%08x RES:%s%s%s%s%s%s%s%s%s rw:%c len:%d blksize:%d",
          cmd->cmd_code,
          reg_cmd,
          cmd->arg,
          resp_type(cmd) == RESP_NONE ? "NONE"  : "",
          resp_type(cmd) == RESP_R1  ? "R1"  : "",
          resp_type(cmd) == RESP_R1B ? "R1B"  : "",
          resp_type(cmd) == RESP_R2  ? "R2"  : "",
          resp_type(cmd) == RESP_R3  ? "R3"  : "",
          resp_type(cmd) == RESP_R4  ? "R4"  : "",
          resp_type(cmd) == RESP_R5  ? "R5"  : "",
          resp_type(cmd) == RESP_R6  ? "R6"  : "",
          resp_type(cmd) == RESP_R7  ? "R7"  : "",
          data ? (data->flags & DATA_DIR_WRITE ?  'w' : 'r') : '-',
          data ? data->blks * data->blksize : 0,
          data ? data->blksize : 0
         );

    /* config data reg */
    if (data != RT_NULL)
    {
        rt_uint32_t dir = 0;
        rt_uint32_t size = data->blks * data->blksize;
        int order;

        order = get_order(data->blksize);
        dir = (data->flags & DATA_DIR_READ) ? HW_SDIO_TO_HOST : 0;

        data_flag = data->flags;
    }

    /* transfer config */
    if (data_flag & DATA_DIR_READ)
    {
        rthw_sdio_transfer_by_dma(sdio, pkg);
    }

    /* send cmd */
292 293
    hw_sdio[SDxARG3] = cmd->arg;
    hw_sdio[SDxCMD]  = reg_cmd;
G
greedyhao 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311

    /* wait cmd completed */
    rthw_sdio_wait_completed(sdio);

    /* transfer config */
    if (data != RT_NULL)
    {
        do {
            if ((data_flag & DATA_DIR_WRITE) || ((data_flag & DATA_DIR_READ) && (pkg->xfer_blks != 0))) {
                rthw_sdio_transfer_by_dma(sdio, pkg);
            }

            rt_uint32_t status = 0;

            if (rt_event_recv(&sdio->event, 0xFFFFFFFF & ~HW_SDIO_CON_DFLAG, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
                            rt_tick_from_millisecond(5000), &status) != RT_EOK)
            {
                LOG_E("wait completed timeout");
312
                LOG_E("SDxCON=0x%X SDxCMD=0x%X\n", hw_sdio[SDxCON], hw_sdio[SDxCMD]);
G
greedyhao 已提交
313 314 315 316
                cmd->err = -RT_ETIMEOUT;
            }

            if (data_flag & DATA_DIR_WRITE) {
317
                if (((hw_sdio[SDxCON] & HW_SDIO_CON_CRCS) >> 17) != 2) {
G
greedyhao 已提交
318 319
                    LOG_E("Write CRC error!");
                    cmd->err = -RT_ERROR;
320
                    hw_sdio[SDxCPND] = HW_SDIO_CON_DFLAG;
G
greedyhao 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
                }
            }
        } while(++pkg->xfer_blks != data->blks);
    }

    /* clear pkg */
    sdio->pkg = RT_NULL;
}

/**
  * @brief  This function send sdio request.
  * @param  host  rt_mmcsd_host
  * @param  req   request
  * @retval None
  */
static void rthw_sdio_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
{
    struct sdio_pkg pkg;
    struct rthw_sdio *sdio = host->private_data;
    struct rt_mmcsd_data *data;

    RTHW_SDIO_LOCK(sdio);

    if (req->cmd != RT_NULL)
    {
        rt_memset(&pkg, 0, sizeof(pkg));
        data = req->cmd->data;
        pkg.cmd = req->cmd;

        if (data != RT_NULL)
        {
            rt_uint32_t size = data->blks * data->blksize;

            RT_ASSERT(size <= SDIO_BUFF_SIZE);

            pkg.buff = data->buf;
            if ((rt_uint32_t)data->buf & (SDIO_ALIGN_LEN - 1))
            {
                pkg.buff = cache_buf;
                if (data->flags & DATA_DIR_WRITE)
                {
                    rt_memcpy(cache_buf, data->buf, size);
                }
            }
        }

        rthw_sdio_send_command(sdio, &pkg);

        if ((data != RT_NULL) && (data->flags & DATA_DIR_READ) && ((rt_uint32_t)data->buf & (SDIO_ALIGN_LEN - 1)))
        {
            rt_memcpy(data->buf, cache_buf, data->blksize * data->blks);
        }
    }

    if (req->stop != RT_NULL)
    {
        rt_memset(&pkg, 0, sizeof(pkg));
        pkg.cmd = req->stop;
        rthw_sdio_send_command(sdio, &pkg);
    }

    RTHW_SDIO_UNLOCK(sdio);

    mmcsd_req_complete(sdio->host);
}

/**
  * @brief  This function config sdio.
  * @param  host    rt_mmcsd_host
  * @param  io_cfg  rt_mmcsd_io_cfg
  * @retval None
  */
static void rthw_sdio_iocfg(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg)
{
    rt_uint32_t clkcr, div, clk_src;
    rt_uint32_t clk = io_cfg->clock;
    struct rthw_sdio *sdio = host->private_data;
    hal_sfr_t hw_sdio = sdio->sdio_des.hw_sdio;

    clk_src = sdio->sdio_des.clk_get(sdio->sdio_des.hw_sdio);
    if (clk_src < 240 * 1000)
    {
        LOG_E("The clock rate is too low! rata:%d", clk_src);
        return;
    }

    if (clk > host->freq_max) clk = host->freq_max;

    if (clk > clk_src)
    {
        // LOG_W("Setting rate(%d) is greater than clock source rate(%d).", clk, clk_src);
        // clk = clk_src;
    }

    LOG_D("clk:%d width:%s%s%s power:%s%s%s",
          clk,
          io_cfg->bus_width == MMCSD_BUS_WIDTH_8 ? "8" : "",
          io_cfg->bus_width == MMCSD_BUS_WIDTH_4 ? "4" : "",
          io_cfg->bus_width == MMCSD_BUS_WIDTH_1 ? "1" : "",
          io_cfg->power_mode == MMCSD_POWER_OFF ? "OFF" : "",
          io_cfg->power_mode == MMCSD_POWER_UP ? "UP" : "",
          io_cfg->power_mode == MMCSD_POWER_ON ? "ON" : ""
         );

    RTHW_SDIO_LOCK(sdio);

    switch (io_cfg->power_mode)
    {
    case MMCSD_POWER_OFF:
430
        hw_sdio[SDxCON] &= ~BIT(0);
G
greedyhao 已提交
431 432 433
        break;
    case MMCSD_POWER_UP:
        sd_baud = 199;
434
        hw_sdio[SDxCON] = 0;
G
greedyhao 已提交
435 436
        rt_thread_mdelay(1);

437 438 439 440 441
        hw_sdio[SDxCON] |= BIT(0);                 /* SD control enable */
        hw_sdio[SDxBAUD] = sysclk_update_baud(sd_baud);
        hw_sdio[SDxCON] |= BIT(3);                 /* Keep clock output */
        hw_sdio[SDxCON] |= BIT(4);
        hw_sdio[SDxCON] |= BIT(5);                 /* Data interrupt enable */
G
greedyhao 已提交
442 443 444 445 446

        hal_mdelay(40);
        break;
    case MMCSD_POWER_ON:
        if (clk == SDIO_MAX_FREQ) {
447
            hw_sdio[SDxCON] &= ~BIT(3);
G
greedyhao 已提交
448
            sd_baud = 3;
449
            hw_sdio[SDxBAUD] = sysclk_update_baud(sd_baud);
G
greedyhao 已提交
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
        }
        break;
    default:
        LOG_W("unknown power_mode %d", io_cfg->power_mode);
        break;
    }

    RTHW_SDIO_UNLOCK(sdio);
}

/**
  * @brief  This function update sdio interrupt.
  * @param  host    rt_mmcsd_host
  * @param  enable
  * @retval None
  */
void rthw_sdio_irq_update(struct rt_mmcsd_host *host, rt_int32_t enable)
{
    struct rthw_sdio *sdio = host->private_data;
    hal_sfr_t hw_sdio = sdio->sdio_des.hw_sdio;

    if (enable)
    {
        LOG_D("enable sdio irq");
        rt_hw_irq_enable(IRQ_SD_VECTOR);
    }
    else
    {
        LOG_D("disable sdio irq");
        rt_hw_irq_disable(IRQ_SD_VECTOR);
    }
}

/**
  * @brief  This function detect sdcard.
  * @param  host    rt_mmcsd_host
  * @retval 0x01
  */
static rt_int32_t rthw_sd_detect(struct rt_mmcsd_host *host)
{
    LOG_D("try to detect device");
    return 0x01;
}

/**
  * @brief  This function interrupt process function.
  * @param  host  rt_mmcsd_host
  * @retval None
  */
G
greedyhao 已提交
499
RT_SECTION(".irq.sdio")
G
greedyhao 已提交
500 501 502 503 504
void rthw_sdio_irq_process(struct rt_mmcsd_host *host)
{
    int complete = 0;
    struct rthw_sdio *sdio = host->private_data;
    hal_sfr_t hw_sdio = sdio->sdio_des.hw_sdio;
505
    rt_uint32_t intstatus = hw_sdio[SDxCON];
G
greedyhao 已提交
506 507 508 509

    /* clear flag */
    if (intstatus & HW_SDIO_CON_CFLAG) {
        complete = 1;
510
        hw_sdio[SDxCPND] = HW_SDIO_CON_CFLAG;
G
greedyhao 已提交
511 512 513 514
    }

    if (intstatus & HW_SDIO_CON_DFLAG) {
        complete = 1;
515
        hw_sdio[SDxCPND] = HW_SDIO_CON_DFLAG;
G
greedyhao 已提交
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
    }

    if (complete)
    {
        rt_event_send(&sdio->event, intstatus);
    }
}

static const struct rt_mmcsd_host_ops ab32_sdio_ops =
{
    rthw_sdio_request,
    rthw_sdio_iocfg,
    rthw_sd_detect,
    rthw_sdio_irq_update,
};

/**
  * @brief  This function create mmcsd host.
  * @param  sdio_des  ab32_sdio_des
  * @retval rt_mmcsd_host
  */
struct rt_mmcsd_host *sdio_host_create(struct ab32_sdio_des *sdio_des)
{
    struct rt_mmcsd_host *host;
    struct rthw_sdio *sdio = RT_NULL;

    if ((sdio_des == RT_NULL) || (sdio_des->txconfig == RT_NULL) || (sdio_des->rxconfig == RT_NULL))
    {
        LOG_E("L:%d F:%s %s %s %s",
              (sdio_des == RT_NULL ? "sdio_des is NULL" : ""),
              (sdio_des ? (sdio_des->txconfig ? "txconfig is NULL" : "") : ""),
              (sdio_des ? (sdio_des->rxconfig ? "rxconfig is NULL" : "") : "")
             );
        return RT_NULL;
    }

    sdio = rt_malloc(sizeof(struct rthw_sdio));
    if (sdio == RT_NULL)
    {
        LOG_E("L:%d F:%s malloc rthw_sdio fail");
        return RT_NULL;
    }
    rt_memset(sdio, 0, sizeof(struct rthw_sdio));

    host = mmcsd_alloc_host();
    if (host == RT_NULL)
    {
        LOG_E("L:%d F:%s mmcsd alloc host fail");
        rt_free(sdio);
        return RT_NULL;
    }

    rt_memcpy(&sdio->sdio_des, sdio_des, sizeof(struct ab32_sdio_des));
    sdio->sdio_des.hw_sdio = (sdio_des->hw_sdio == RT_NULL ? SDMMC0_BASE : sdio_des->hw_sdio);
    sdio->sdio_des.clk_get = (sdio_des->clk_get == RT_NULL ? ab32_sdio_clk_get : sdio_des->clk_get);

    rt_event_init(&sdio->event, "sdio", RT_IPC_FLAG_FIFO);
    rt_mutex_init(&sdio->mutex, "sdio", RT_IPC_FLAG_FIFO);

    /* set host defautl attributes */
    host->ops = &ab32_sdio_ops;
    host->freq_min = 240 * 1000;
    host->freq_max = SDIO_MAX_FREQ;
    host->valid_ocr = 0X00FFFF80;/* The voltage range supported is 1.65v-3.6v */
#ifndef SDIO_USING_1_BIT
    host->flags = MMCSD_BUSWIDTH_4 | MMCSD_MUTBLKWRITE | MMCSD_SUP_SDIO_IRQ;
#else
    host->flags = MMCSD_MUTBLKWRITE | MMCSD_SUP_SDIO_IRQ;
#endif
    host->max_seg_size = SDIO_BUFF_SIZE;
    host->max_dma_segs = 1;
    host->max_blk_size = 512;
    host->max_blk_count = 512;

    /* link up host and sdio */
    sdio->host = host;
    host->private_data = sdio;

    rthw_sdio_irq_update(host, 1);

    /* ready to change */
    mmcsd_change(host);

    return host;
}

static rt_err_t _dma_txconfig(rt_uint32_t *src, int Size)
{
    hal_sfr_t sdiox = sdio_config->instance;

606 607
    sdiox[SDxDMAADR] = DMA_ADR(src);
    sdiox[SDxDMACNT] = BIT(18) | BIT(17) | BIT(16) | Size;
G
greedyhao 已提交
608 609 610 611 612 613 614
    return RT_EOK;
}

static rt_err_t _dma_rxconfig(rt_uint32_t *dst, int Size)
{
    hal_sfr_t sdiox = sdio_config->instance;

615 616
    sdiox[SDxDMAADR] = DMA_ADR(dst);
    sdiox[SDxDMACNT] = (Size);
G
greedyhao 已提交
617 618 619
    return RT_EOK;
}

G
greedyhao 已提交
620
RT_SECTION(".irq.sdio")
G
greedyhao 已提交
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
void sdio_isr(int vector, void *param)
{
    /* enter interrupt */
    rt_interrupt_enter();
    /* Process All SDIO Interrupt Sources */
    rthw_sdio_irq_process(host);

    /* leave interrupt */
    rt_interrupt_leave();
}

int rt_hw_sdio_init(void)
{
    struct ab32_sdio_des sdio_des = {0};
    struct sd_handle hsd = {0};
636
    rt_uint8_t param = 0;
G
greedyhao 已提交
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
    hsd.instance = SDMMC0_BASE;

    hal_rcu_periph_clk_enable(RCU_SD0);
    hal_sd_mspinit(&hsd);

    rt_hw_interrupt_install(IRQ_SD_VECTOR, sdio_isr, &param, "sd_isr");

    sdio_des.clk_get    = ab32_sdio_clk_get;
    sdio_des.hw_sdio    = SDMMC0_BASE;
    sdio_des.rxconfig   = _dma_rxconfig;
    sdio_des.txconfig   = _dma_txconfig;

    host = sdio_host_create(&sdio_des);

    return 0;
}
INIT_DEVICE_EXPORT(rt_hw_sdio_init);

void ab32_mmcsd_change(void)
{
    mmcsd_change(host);
}

#endif // 0