Lines Matching refs:handle

51 static int set_card_data_width(struct sd_handle *handle, int width);
52 static int abort_err(struct sd_handle *handle);
53 static int err_recovery(struct sd_handle *handle, uint32_t errors);
54 static int xfer_data(struct sd_handle *handle, uint32_t mode, uint32_t addr,
57 int set_boot_config(struct sd_handle *handle, uint32_t config) in set_boot_config() argument
59 return mmc_cmd6(handle, SDIO_HW_EMMC_EXT_CSD_BOOT_CNF | config); in set_boot_config()
62 void process_csd_mmc_speed(struct sd_handle *handle, uint32_t csd_mmc_speed) in process_csd_mmc_speed() argument
109 chal_sd_set_clock((CHAL_HANDLE *) handle->device, div_ctrl_setting, 0); in process_csd_mmc_speed()
111 chal_sd_set_clock((CHAL_HANDLE *) handle->device, div_ctrl_setting, 1); in process_csd_mmc_speed()
122 int set_card_data_width(struct sd_handle *handle, int width) in set_card_data_width() argument
162 rc = mmc_cmd6(handle, data_width); in set_card_data_width()
167 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device, in set_card_data_width()
191 static int abort_err(struct sd_handle *handle) in abort_err() argument
196 handle->device->ctrl.argReg = 0; in abort_err()
197 handle->device->ctrl.cmdIndex = SD_CMD_STOP_TRANSMISSION; in abort_err()
204 chal_sd_send_cmd((CHAL_HANDLE *) handle->device, in abort_err()
205 handle->device->ctrl.cmdIndex, in abort_err()
206 handle->device->ctrl.argReg, options); in abort_err()
208 event = wait_for_event(handle, in abort_err()
211 handle->device->cfg.wfe_retry); in abort_err()
220 chal_sd_get_response((CHAL_HANDLE *) handle->device, in abort_err()
223 process_cmd_response(handle, handle->device->ctrl.cmdIndex, in abort_err()
231 chal_sd_get_present_status((CHAL_HANDLE *) handle->device); in abort_err()
253 int process_data_xfer(struct sd_handle *handle, uint8_t *buffer, uint32_t addr, in process_data_xfer() argument
258 if (handle->device->cfg.dma == SD_DMA_OFF) { in process_data_xfer()
262 if (write_buffer(handle, length, buffer)) in process_data_xfer()
265 wait_for_event(handle, in process_data_xfer()
268 handle->device->cfg.wfe_retry); in process_data_xfer()
270 if (handle->device->ctrl.cmdStatus == SD_OK) in process_data_xfer()
273 check_error(handle, handle->device->ctrl.cmdStatus); in process_data_xfer()
281 if (handle->device->cfg.dma == SD_DMA_OFF) { in process_data_xfer()
285 if (read_buffer(handle, length, buffer)) in process_data_xfer()
294 wait_for_event(handle, in process_data_xfer()
297 handle->device->cfg.wfe_retry); in process_data_xfer()
299 if (handle->device->ctrl.cmdStatus == SD_OK) in process_data_xfer()
302 check_error(handle, handle->device->ctrl.cmdStatus); in process_data_xfer()
314 int select_blk_sz(struct sd_handle *handle, uint16_t size) in select_blk_sz() argument
316 return sd_cmd16(handle, size); in select_blk_sz()
326 int init_card(struct sd_handle *handle, int detection) in init_card() argument
332 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device, in init_card()
338 handle->device->ctrl.present = 0; /* init card present to be no card */ in init_card()
340 init_mmc_card(handle); in init_card()
342 handle->device->ctrl.present = 1; /* card is detected */ in init_card()
345 if (handle->card->type != SD_CARD_MMC) in init_card()
362 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device, in init_card()
364 if ((!set_card_data_width(handle, SD_BUS_DATA_WIDTH_8BIT)) && in init_card()
365 (!mmc_cmd8(handle, buffer)) && in init_card()
373 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device, in init_card()
375 if ((!set_card_data_width(handle, SD_BUS_DATA_WIDTH_4BIT)) && in init_card()
376 (!mmc_cmd8(handle, buffer)) && in init_card()
384 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device, in init_card()
387 if (!set_card_data_width(handle, SD_BUS_DATA_WIDTH_1BIT)) in init_card()
398 int init_mmc_card(struct sd_handle *handle) in init_mmc_card() argument
404 handle->card->type = SD_CARD_MMC; in init_mmc_card()
410 rc = sd_cmd1(handle, cmd1_option, &newOcr); in init_mmc_card()
419 handle->card->type = SD_CARD_UNKNOWN; in init_mmc_card()
425 handle->device->ctrl.ocr = ocr; in init_mmc_card()
428 rc = sd_cmd2(handle); in init_mmc_card()
430 handle->card->type = SD_CARD_UNKNOWN; in init_mmc_card()
434 rc = sd_cmd3(handle); in init_mmc_card()
436 handle->card->type = SD_CARD_UNKNOWN; in init_mmc_card()
440 rc = sd_cmd9(handle, &emmc_global_vars_ptr->cardData); in init_mmc_card()
442 handle->card->type = SD_CARD_UNKNOWN; in init_mmc_card()
449 process_csd_mmc_speed(handle, in init_mmc_card()
453 rc = sd_cmd7(handle, handle->device->ctrl.rca); in init_mmc_card()
455 handle->card->type = SD_CARD_UNKNOWN; in init_mmc_card()
459 rc = mmc_cmd8(handle, emmc_global_buf_ptr->u.Ext_CSD_storage); in init_mmc_card()
468 handle->card->size / (1024 * 1024)); in init_mmc_card()
471 handle->card->size = (uint64_t)sec_count * 512; in init_mmc_card()
474 handle->card->size / (1024 * 1024)); in init_mmc_card()
478 handle->device->ctrl.ocr |= SD_CARD_HIGH_CAPACITY; in init_mmc_card()
479 handle->device->cfg.blockSize = 512; in init_mmc_card()
482 if (handle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY) in init_mmc_card()
492 return handle->card->type; in init_mmc_card()
500 int reset_card(struct sd_handle *handle) in reset_card() argument
505 handle->device->ctrl.rca = 0; in reset_card()
507 res = sd_cmd0(handle); in reset_card()
520 static int xfer_data(struct sd_handle *handle, in xfer_data() argument
529 if ((length / handle->device->cfg.blockSize) > 1) { in xfer_data()
532 rc = sd_cmd18(handle, addr, length, base); in xfer_data()
536 rc = sd_cmd25(handle, addr, length, base); in xfer_data()
544 rc = sd_cmd17(handle, addr, in xfer_data()
545 handle->device->cfg.blockSize, base); in xfer_data()
549 rc = sd_cmd24(handle, addr, in xfer_data()
550 handle->device->cfg.blockSize, base); in xfer_data()
564 int erase_card(struct sd_handle *handle, uint32_t addr, uint32_t blocks) in erase_card() argument
570 if (sd_cmd35(handle, addr) != SD_OK) in erase_card()
574 if (sd_cmd36(handle, end_addr) != SD_OK) in erase_card()
577 if (sd_cmd38(handle) != SD_OK) in erase_card()
588 int read_block(struct sd_handle *handle, in read_block() argument
602 rel = xfer_data(handle, SD_OP_READ, addr, len, dst); in read_block()
613 int read_block(struct sd_handle *handle, in read_block() argument
616 return xfer_data(handle, SD_OP_READ, addr, len, dst); in read_block()
625 int write_block(struct sd_handle *handle, in write_block() argument
639 rel = xfer_data(handle, SD_OP_WRITE, addr, len, src); in write_block()
653 int write_buffer(struct sd_handle *handle, uint32_t length, uint8_t *data) in write_buffer() argument
658 blockSize = handle->device->cfg.blockSize; in write_buffer()
666 event = wait_for_event(handle, in write_buffer()
669 handle->device->cfg.wfe_retry); in write_buffer()
671 if (handle->device->ctrl.cmdStatus) { in write_buffer()
672 check_error(handle, handle->device->ctrl.cmdStatus); in write_buffer()
677 chal_sd_write_buffer((CHAL_HANDLE *) handle->device, in write_buffer()
680 chal_sd_write_buffer((CHAL_HANDLE *) handle->device, in write_buffer()
694 event = wait_for_event(handle, in write_buffer()
697 handle->device->cfg.wfe_retry); in write_buffer()
699 if (handle->device->ctrl.cmdStatus != SD_OK) { in write_buffer()
700 check_error(handle, handle->device->ctrl.cmdStatus); in write_buffer()
704 handle->device->ctrl.eventList &= ~SD4_EMMC_TOP_INTR_TXDONE_MASK; in write_buffer()
717 int read_buffer(struct sd_handle *handle, uint32_t length, uint8_t *data) in read_buffer() argument
722 blockSize = handle->device->cfg.blockSize; in read_buffer()
729 event = wait_for_event(handle, in read_buffer()
732 handle->device->cfg.wfe_retry); in read_buffer()
734 if (handle->device->ctrl.cmdStatus) { in read_buffer()
735 check_error(handle, handle->device->ctrl.cmdStatus); in read_buffer()
740 chal_sd_read_buffer((CHAL_HANDLE *) handle->device, in read_buffer()
743 chal_sd_read_buffer((CHAL_HANDLE *) handle->device, rem, in read_buffer()
756 chal_sd_dump_fifo((CHAL_HANDLE *) handle->device); in read_buffer()
760 event = wait_for_event(handle, SD4_EMMC_TOP_INTR_TXDONE_MASK, in read_buffer()
761 handle->device->cfg.wfe_retry); in read_buffer()
763 if (handle->device->ctrl.cmdStatus) { in read_buffer()
764 check_error(handle, handle->device->ctrl.cmdStatus); in read_buffer()
768 handle->device->ctrl.eventList &= ~SD4_EMMC_TOP_INTR_TXDONE_MASK; in read_buffer()
780 int check_error(struct sd_handle *handle, uint32_t ints) in check_error() argument
784 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device, in check_error()
789 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in check_error()
791 rel = abort_err(handle); in check_error()
793 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in check_error()
795 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device, in check_error()
801 rel = err_recovery(handle, ints); in check_error()
804 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device, in check_error()
815 static int err_recovery(struct sd_handle *handle, uint32_t errors) in err_recovery() argument
826 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in err_recovery()
830 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in err_recovery()
834 if ((handle->device->ctrl.cmdIndex == 18) || in err_recovery()
835 (handle->device->ctrl.cmdIndex == 25)) in err_recovery()
836 rel = abort_err(handle); in err_recovery()
846 int process_cmd_response(struct sd_handle *handle, in process_cmd_response() argument
910 (handle->card->type == SD_CARD_SD)) { in process_cmd_response()
927 void data_xfer_setup(struct sd_handle *handle, uint8_t *data, uint32_t length, in data_xfer_setup() argument
930 chal_sd_setup_xfer((CHAL_HANDLE *)handle->device, data, length, dir); in data_xfer_setup()
942 int reset_host_ctrl(struct sd_handle *handle) in reset_host_ctrl() argument
949 static void pstate_log(struct sd_handle *handle) in pstate_log() argument
952 (handle->device->ctrl.sdRegBaseAddr + in pstate_log()
955 (handle->device->ctrl.sdRegBaseAddr + in pstate_log()
968 uint32_t wait_for_event(struct sd_handle *handle, in wait_for_event() argument
973 handle->device->ctrl.cmdStatus = 0; /* no error */ in wait_for_event()
976 chal_sd_get_irq_status((CHAL_HANDLE *)handle->device)); in wait_for_event()
980 regval = chal_sd_get_irq_status((CHAL_HANDLE *)handle->device); in wait_for_event()
983 chal_sd_set_dma_addr((CHAL_HANDLE *)handle->device, in wait_for_event()
986 handle->device)); in wait_for_event()
987 chal_sd_clear_irq((CHAL_HANDLE *)handle->device, in wait_for_event()
993 handle->device->ctrl.cmdIndex, in wait_for_event()
995 handle->device->ctrl.cmdStatus = SD_CMD_MISSING; in wait_for_event()
996 pstate_log(handle); in wait_for_event()
1003 handle->device->ctrl.cmdIndex, regval); in wait_for_event()
1004 handle->device->ctrl.cmdStatus = in wait_for_event()
1006 pstate_log(handle); in wait_for_event()
1011 handle->device->ctrl.cmdIndex, regval); in wait_for_event()
1012 handle->device->ctrl.cmdStatus = SD_CMD_ERROR_FLAGS; in wait_for_event()
1013 pstate_log(handle); in wait_for_event()
1017 cmd12 = chal_sd_get_atuo12_error((CHAL_HANDLE *)handle->device); in wait_for_event()
1020 handle->device->ctrl.cmdIndex, cmd12); in wait_for_event()
1021 handle->device->ctrl.cmdStatus = cmd12; in wait_for_event()
1022 pstate_log(handle); in wait_for_event()
1028 handle->device->ctrl.cmdIndex, regval); in wait_for_event()
1029 handle->device->ctrl.cmdStatus = in wait_for_event()
1031 pstate_log(handle); in wait_for_event()
1041 chal_sd_clear_irq((CHAL_HANDLE *)handle->device, (regval & mask)); in wait_for_event()
1046 int32_t set_config(struct sd_handle *handle, uint32_t speed, uint32_t retry, in set_config() argument
1052 if (handle == NULL) in set_config()
1055 handle->device->cfg.wfe_retry = wfe_retry; in set_config()
1057 rel = chal_sd_config((CHAL_HANDLE *)handle->device, speed, retry, in set_config()
1063 int mmc_cmd1(struct sd_handle *handle) in mmc_cmd1() argument
1072 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device, in mmc_cmd1()
1078 handle->device->ctrl.present = 0; /* init card present to be no card */ in mmc_cmd1()
1080 handle->card->type = SD_CARD_MMC; in mmc_cmd1()
1082 res = sd_cmd1(handle, cmd1_option, &newOcr); in mmc_cmd1()