/* To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND before SD_APP_OP_COND. This command will harmlessly fail for SD 1.0 cards.  */
rt_err_t mmcsd_send_if_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr)
/* To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND before SD_APP_OP_COND. This command will harmlessly fail for SD 1.0 cards.  */
rt_err_t mmcsd_send_if_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr)
{
    struct rt_mmcsd_cmd cmd;
    rt_err_t err;
    rt_uint8_t pattern;
    cmd.cmd_code = SD_SEND_IF_COND;
    cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | 0xAA;
    cmd.flags = RESP_SPI_R7 | RESP_R7 | CMD_BCR;
    err = mmcsd_send_cmd(host, &cmd, 0);
    if (err)
        return err;
    if (controller_is_spi(host))
        pattern = cmd.resp[1] & 0xFF;
    else
        pattern = cmd.resp[0] & 0xFF;
    if (pattern != 0xAA)
        return -RT_ERROR;
    return RT_EOK;
}