* Starting point for mmc card init. */
| 739 | * Starting point for mmc card init. |
| 740 | */ |
| 741 | rt_int32_t init_mmc(struct rt_mmcsd_host *host, rt_uint32_t ocr) |
| 742 | { |
| 743 | rt_int32_t err; |
| 744 | rt_uint32_t current_ocr; |
| 745 | /* |
| 746 | * We need to get OCR a different way for SPI. |
| 747 | */ |
| 748 | if (controller_is_spi(host)) |
| 749 | { |
| 750 | err = mmcsd_spi_read_ocr(host, 0, &ocr); |
| 751 | if (err) |
| 752 | goto err; |
| 753 | } |
| 754 | |
| 755 | current_ocr = mmcsd_select_voltage(host, ocr); |
| 756 | |
| 757 | /* |
| 758 | * Can we support the voltage(s) of the card(s)? |
| 759 | */ |
| 760 | if (!current_ocr) |
| 761 | { |
| 762 | err = -RT_ERROR; |
| 763 | goto err; |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * Detect and init the card. |
| 768 | */ |
| 769 | err = mmcsd_mmc_init_card(host, current_ocr); |
| 770 | if (err) |
| 771 | goto err; |
| 772 | |
| 773 | mmcsd_host_unlock(host); |
| 774 | |
| 775 | err = rt_mmcsd_blk_probe(host->card); |
| 776 | if (err) |
| 777 | goto remove_card; |
| 778 | mmcsd_host_lock(host); |
| 779 | |
| 780 | return 0; |
| 781 | |
| 782 | remove_card: |
| 783 | mmcsd_host_lock(host); |
| 784 | rt_mmcsd_blk_remove(host->card); |
| 785 | rt_free(host->card); |
| 786 | host->card = RT_NULL; |
| 787 | err: |
| 788 | |
| 789 | LOG_E("init MMC card failed!"); |
| 790 | |
| 791 | return err; |
| 792 | } |
no test coverage detected