| 827 | } |
| 828 | |
| 829 | static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr) |
| 830 | { |
| 831 | rt_int32_t err = 0; |
| 832 | rt_int32_t i, function_num; |
| 833 | rt_uint32_t cmd5_resp; |
| 834 | struct rt_mmcsd_card *card; |
| 835 | |
| 836 | err = sdio_io_send_op_cond(host, ocr, &cmd5_resp); |
| 837 | if (err) |
| 838 | goto err; |
| 839 | |
| 840 | if (controller_is_spi(host)) |
| 841 | { |
| 842 | err = mmcsd_spi_use_crc(host, host->spi_use_crc); |
| 843 | if (err) |
| 844 | goto err; |
| 845 | } |
| 846 | |
| 847 | function_num = (cmd5_resp & 0x70000000) >> 28; |
| 848 | |
| 849 | card = rt_malloc(sizeof(struct rt_mmcsd_card)); |
| 850 | if (!card) |
| 851 | { |
| 852 | LOG_E("malloc card failed"); |
| 853 | err = -RT_ENOMEM; |
| 854 | goto err; |
| 855 | } |
| 856 | rt_memset(card, 0, sizeof(struct rt_mmcsd_card)); |
| 857 | |
| 858 | card->card_type = CARD_TYPE_SDIO; |
| 859 | card->sdio_function_num = function_num; |
| 860 | card->host = host; |
| 861 | host->card = card; |
| 862 | |
| 863 | card->sdio_function[0] = rt_malloc(sizeof(struct rt_sdio_function)); |
| 864 | if (!card->sdio_function[0]) |
| 865 | { |
| 866 | LOG_E("malloc sdio_func0 failed"); |
| 867 | err = -RT_ENOMEM; |
| 868 | goto err1; |
| 869 | } |
| 870 | rt_memset(card->sdio_function[0], 0, sizeof(struct rt_sdio_function)); |
| 871 | card->sdio_function[0]->card = card; |
| 872 | card->sdio_function[0]->num = 0; |
| 873 | |
| 874 | if (!controller_is_spi(host)) |
| 875 | { |
| 876 | err = mmcsd_get_card_addr(host, &card->rca); |
| 877 | if (err) |
| 878 | goto err2; |
| 879 | |
| 880 | mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); |
| 881 | } |
| 882 | |
| 883 | if (!controller_is_spi(host)) |
| 884 | { |
| 885 | err = mmcsd_select_card(card); |
| 886 | if (err) |
no test coverage detected