* Starting point for SD card init. */
| 814 | * Starting point for SD card init. |
| 815 | */ |
| 816 | rt_int32_t init_sd(struct rt_mmcsd_host *host, rt_uint32_t ocr) |
| 817 | { |
| 818 | rt_int32_t err = -RT_EINVAL; |
| 819 | rt_uint32_t current_ocr; |
| 820 | /* |
| 821 | * We need to get OCR a different way for SPI. |
| 822 | */ |
| 823 | if (controller_is_spi(host)) |
| 824 | { |
| 825 | mmcsd_go_idle(host); |
| 826 | |
| 827 | err = mmcsd_spi_read_ocr(host, 0, &ocr); |
| 828 | if (err) |
| 829 | goto _err; |
| 830 | } |
| 831 | |
| 832 | current_ocr = mmcsd_select_voltage(host, ocr); |
| 833 | |
| 834 | /* |
| 835 | * Can we support the voltage(s) of the card(s)? |
| 836 | */ |
| 837 | if (!current_ocr) |
| 838 | { |
| 839 | err = -RT_ERROR; |
| 840 | goto _err; |
| 841 | } |
| 842 | |
| 843 | /* |
| 844 | * Detect and init the card. |
| 845 | */ |
| 846 | err = mmcsd_sd_init_card(host, current_ocr); |
| 847 | if (err) |
| 848 | goto _err; |
| 849 | |
| 850 | mmcsd_host_unlock(host); |
| 851 | |
| 852 | err = rt_mmcsd_blk_probe(host->card); |
| 853 | if (err) |
| 854 | goto remove_card; |
| 855 | mmcsd_host_lock(host); |
| 856 | |
| 857 | return 0; |
| 858 | |
| 859 | remove_card: |
| 860 | mmcsd_host_lock(host); |
| 861 | rt_mmcsd_blk_remove(host->card); |
| 862 | rt_free(host->card); |
| 863 | host->card = RT_NULL; |
| 864 | _err: |
| 865 | |
| 866 | LOG_D("init SD card failed!"); |
| 867 | |
| 868 | return err; |
| 869 | } |
no test coverage detected