| 655 | } |
| 656 | |
| 657 | static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host, |
| 658 | rt_uint32_t ocr) |
| 659 | { |
| 660 | struct rt_mmcsd_card *card; |
| 661 | rt_int32_t err; |
| 662 | rt_uint32_t resp[4]; |
| 663 | rt_uint32_t max_data_rate; |
| 664 | |
| 665 | mmcsd_go_idle(host); |
| 666 | |
| 667 | /* |
| 668 | * If SD_SEND_IF_COND indicates an SD 2.0 |
| 669 | * compliant card and we should set bit 30 |
| 670 | * of the ocr to indicate that we can handle |
| 671 | * block-addressed SDHC cards. |
| 672 | */ |
| 673 | err = mmcsd_send_if_cond(host, ocr); |
| 674 | if (!err) |
| 675 | ocr |= 1 << 30; |
| 676 | |
| 677 | /* Switch to UHS voltage if both Host and the Card support this feature */ |
| 678 | if (((host->valid_ocr & VDD_165_195) != 0) && (host->ops->switch_uhs_voltage != RT_NULL)) |
| 679 | { |
| 680 | ocr |= OCR_S18R; |
| 681 | } |
| 682 | err = mmcsd_send_app_op_cond(host, ocr, &ocr); |
| 683 | if (err) |
| 684 | goto err2; |
| 685 | |
| 686 | /* Select voltage */ |
| 687 | if (ocr & OCR_S18R) |
| 688 | { |
| 689 | ocr = VDD_165_195; |
| 690 | err = sd_switch_voltage(host); |
| 691 | if (err) |
| 692 | goto err2; |
| 693 | err = sd_switch_uhs_voltage(host); |
| 694 | if (err) |
| 695 | goto err2; |
| 696 | } |
| 697 | |
| 698 | if (controller_is_spi(host)) |
| 699 | err = mmcsd_get_cid(host, resp); |
| 700 | else |
| 701 | err = mmcsd_all_get_cid(host, resp); |
| 702 | if (err) |
| 703 | goto err2; |
| 704 | |
| 705 | card = rt_malloc(sizeof(struct rt_mmcsd_card)); |
| 706 | if (!card) |
| 707 | { |
| 708 | LOG_E("malloc card failed!"); |
| 709 | err = -RT_ENOMEM; |
| 710 | goto err2; |
| 711 | } |
| 712 | rt_memset(card, 0, sizeof(struct rt_mmcsd_card)); |
| 713 | |
| 714 | card->card_type = CARD_TYPE_SD; |
no test coverage detected