Lines Matching +full:host +full:- +full:only
2 * Copyright (c) 2006-2018, RT-Thread Development Team
4 * SPDX-License-Identifier: Apache-2.0
8 * 2015-06-15 hichard first version
52 const rt_uint32_t __mask = (__size < 32 ? 1 << __size : 0) - 1; in GET_BITS()
53 const rt_int32_t __off = 3 - ((start) / 32); in GET_BITS()
59 __res |= resp[__off-1] << ((32 - __shft) % 32); in GET_BITS()
65 * Given a 128-bit response, decode to our card CSD structure.
70 struct rt_mmcsd_csd *csd = &card->csd; in mmcsd_parse_csd()
71 rt_uint32_t *resp = card->resp_csd; in mmcsd_parse_csd()
74 * We only understand CSD structure v1.1 and v1.2. in mmcsd_parse_csd()
78 csd->csd_structure = GET_BITS(resp, 126, 2); in mmcsd_parse_csd()
79 if (csd->csd_structure == 0) { in mmcsd_parse_csd()
80 LOG_E("unrecognised CSD structure version %d!", csd->csd_structure); in mmcsd_parse_csd()
82 return -RT_ERROR; in mmcsd_parse_csd()
85 csd->taac = GET_BITS(resp, 112, 8); in mmcsd_parse_csd()
86 csd->nsac = GET_BITS(resp, 104, 8); in mmcsd_parse_csd()
87 csd->tran_speed = GET_BITS(resp, 96, 8); in mmcsd_parse_csd()
88 csd->card_cmd_class = GET_BITS(resp, 84, 12); in mmcsd_parse_csd()
89 csd->rd_blk_len = GET_BITS(resp, 80, 4); in mmcsd_parse_csd()
90 csd->rd_blk_part = GET_BITS(resp, 79, 1); in mmcsd_parse_csd()
91 csd->wr_blk_misalign = GET_BITS(resp, 78, 1); in mmcsd_parse_csd()
92 csd->rd_blk_misalign = GET_BITS(resp, 77, 1); in mmcsd_parse_csd()
93 csd->dsr_imp = GET_BITS(resp, 76, 1); in mmcsd_parse_csd()
94 csd->c_size = GET_BITS(resp, 62, 12); in mmcsd_parse_csd()
95 csd->c_size_mult = GET_BITS(resp, 47, 3); in mmcsd_parse_csd()
96 csd->r2w_factor = GET_BITS(resp, 26, 3); in mmcsd_parse_csd()
97 csd->wr_blk_len = GET_BITS(resp, 22, 4); in mmcsd_parse_csd()
98 csd->wr_blk_partial = GET_BITS(resp, 21, 1); in mmcsd_parse_csd()
99 csd->csd_crc = GET_BITS(resp, 1, 7); in mmcsd_parse_csd()
101 card->card_blksize = 1 << csd->rd_blk_len; in mmcsd_parse_csd()
102 card->tacc_clks = csd->nsac * 100; in mmcsd_parse_csd()
103 card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10; in mmcsd_parse_csd()
104 card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; in mmcsd_parse_csd()
105 if (csd->wr_blk_len >= 9) { in mmcsd_parse_csd()
108 card->erase_size = (a + 1) * (b + 1); in mmcsd_parse_csd()
109 card->erase_size <<= csd->wr_blk_len - 9; in mmcsd_parse_csd()
127 if (GET_BITS(card->resp_cid, 122, 4) < 4) in mmc_get_ext_csd()
137 return -RT_ENOMEM; in mmc_get_ext_csd()
171 mmcsd_send_request(card->host, &req); in mmc_get_ext_csd()
190 return -1; in mmc_parse_ext_csd()
193 card->flags |= CARD_FLAG_HIGHSPEED; in mmc_parse_ext_csd()
194 card->hs_max_data_rate = 200000000; in mmc_parse_ext_csd()
196 card->card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]); in mmc_parse_ext_csd()
197 card->card_capacity *= card->card_blksize; in mmc_parse_ext_csd()
198 card->card_capacity >>= 10; /* unit:KB */ in mmc_parse_ext_csd()
199 LOG_I("emmc card capacity %d KB.", card->card_capacity); in mmc_parse_ext_csd()
205 * mmc_switch - modify EXT_CSD register
217 struct rt_mmcsd_host *host = card->host; in mmc_switch() local
225 err = mmcsd_send_cmd(host, &cmd, 3); in mmc_switch()
244 err = -RT_ERROR; in mmc_compare_ext_csds()
248 /* only compare read only fields */ in mmc_compare_ext_csds()
277 err = -RT_ERROR; in mmc_compare_ext_csds()
285 * Select the bus width amoung 4-bit and 8-bit(SDR).
301 struct rt_mmcsd_host *host = card->host; in mmc_select_bus_width() local
305 if (GET_BITS(card->resp_cid, 122, 4) < 4) in mmc_select_bus_width()
316 * Host is capable of 8bit transfer, then switch in mmc_select_bus_width()
320 * bus width on the host. in mmc_select_bus_width()
329 mmcsd_set_bus_width(host, bus_width); in mmc_select_bus_width()
354 rt_err_t mmc_send_op_cond(struct rt_mmcsd_host *host, in mmc_send_op_cond() argument
364 cmd.arg = controller_is_spi(host) ? 0 : ocr; in mmc_send_op_cond()
367 for (i = 100; i; i--) { in mmc_send_op_cond()
368 err = mmcsd_send_cmd(host, &cmd, 3); in mmc_send_op_cond()
377 if (controller_is_spi(host)) { in mmc_send_op_cond()
385 err = -RT_ETIMEOUT; in mmc_send_op_cond()
390 if (rocr && !controller_is_spi(host)) in mmc_send_op_cond()
396 static rt_err_t mmc_set_card_addr(struct rt_mmcsd_host *host, rt_uint32_t rca) in mmc_set_card_addr() argument
407 err = mmcsd_send_cmd(host, &cmd, 3); in mmc_set_card_addr()
414 static rt_int32_t mmcsd_mmc_init_card(struct rt_mmcsd_host *host, in mmcsd_mmc_init_card() argument
424 mmcsd_go_idle(host); in mmcsd_mmc_init_card()
427 err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr); in mmcsd_mmc_init_card()
431 if (controller_is_spi(host)) in mmcsd_mmc_init_card()
433 err = mmcsd_spi_use_crc(host, 1); in mmcsd_mmc_init_card()
438 if (controller_is_spi(host)) in mmcsd_mmc_init_card()
439 err = mmcsd_get_cid(host, resp); in mmcsd_mmc_init_card()
441 err = mmcsd_all_get_cid(host, resp); in mmcsd_mmc_init_card()
449 err = -RT_ENOMEM; in mmcsd_mmc_init_card()
454 card->card_type = CARD_TYPE_MMC; in mmcsd_mmc_init_card()
455 card->host = host; in mmcsd_mmc_init_card()
456 card->rca = 1; in mmcsd_mmc_init_card()
457 rt_memcpy(card->resp_cid, resp, sizeof(card->resp_cid)); in mmcsd_mmc_init_card()
462 if (!controller_is_spi(host)) in mmcsd_mmc_init_card()
464 err = mmc_set_card_addr(host, card->rca); in mmcsd_mmc_init_card()
468 mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); in mmcsd_mmc_init_card()
471 err = mmcsd_get_csd(card, card->resp_csd); in mmcsd_mmc_init_card()
479 if (!controller_is_spi(host)) in mmcsd_mmc_init_card()
499 * addressing. See section 8.1 JEDEC Standard JED84-A441; in mmcsd_mmc_init_card()
502 if (!(card->flags & CARD_FLAG_SDHC) && (rocr & (1<<30))) in mmcsd_mmc_init_card()
503 card->flags |= CARD_FLAG_SDHC; in mmcsd_mmc_init_card()
506 max_data_rate = (unsigned int)-1; in mmcsd_mmc_init_card()
507 if (card->flags & CARD_FLAG_HIGHSPEED) in mmcsd_mmc_init_card()
509 if (max_data_rate > card->hs_max_data_rate) in mmcsd_mmc_init_card()
510 max_data_rate = card->hs_max_data_rate; in mmcsd_mmc_init_card()
512 else if (max_data_rate > card->max_data_rate) in mmcsd_mmc_init_card()
514 max_data_rate = card->max_data_rate; in mmcsd_mmc_init_card()
517 mmcsd_set_clock(host, max_data_rate); in mmcsd_mmc_init_card()
522 host->card = card; in mmcsd_mmc_init_card()
537 rt_int32_t init_mmc(struct rt_mmcsd_host *host, rt_uint32_t ocr) in init_mmc() argument
544 if (controller_is_spi(host)) in init_mmc()
546 err = mmcsd_spi_read_ocr(host, 0, &ocr); in init_mmc()
551 current_ocr = mmcsd_select_voltage(host, ocr); in init_mmc()
558 err = -RT_ERROR; in init_mmc()
565 err = mmcsd_mmc_init_card(host, current_ocr); in init_mmc()
569 mmcsd_host_unlock(host); in init_mmc()
571 err = rt_mmcsd_blk_probe(host->card); in init_mmc()
574 mmcsd_host_lock(host); in init_mmc()
579 mmcsd_host_lock(host); in init_mmc()
580 rt_mmcsd_blk_remove(host->card); in init_mmc()
581 rt_free(host->card); in init_mmc()
582 host->card = RT_NULL; in init_mmc()