/* Initialize SD - Get Card ID, Set RCA, Frequency and bus width.  */
int sd_init(uint32_t instance, int bus_width)
/* Initialize SD - Get Card ID, Set RCA, Frequency and bus width.  */
int sd_init(uint32_t instance, int bus_width)
{
    int status = FAIL;
    usdhc_printf("Get CID.\n");
    if (card_get_cid(instance) == SUCCESS) {
        usdhc_printf("Get RCA.\n");
        if (sd_get_rca(instance) == SUCCESS) {
            usdhc_printf("Set operating frequency.\n");
            host_cfg_clock(instance, OPERATING_FREQ);
            if (bus_width == EIGHT) {
                bus_width = FOUR;
            }
            usdhc_printf("Enter transfer state.\n");
            if (card_enter_trans(instance) == SUCCESS) {
                usdhc_printf("Set bus width.\n");
                if (sd_set_bus_width(instance, bus_width) == SUCCESS) {
                    host_set_bus_width(instance, bus_width);
                    {
                        status = SUCCESS;
                    }
                }
            }
        }
    }
    return status;
}