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()
493 return handle->card->type; in init_mmc_card()
501 int reset_card(struct sd_handle *handle) in reset_card() argument
506 handle->device->ctrl.rca = 0; in reset_card()
508 res = sd_cmd0(handle); in reset_card()
521 static int xfer_data(struct sd_handle *handle, in xfer_data() argument
530 if ((length / handle->device->cfg.blockSize) > 1) { in xfer_data()
533 rc = sd_cmd18(handle, addr, length, base); in xfer_data()
537 rc = sd_cmd25(handle, addr, length, base); in xfer_data()
545 rc = sd_cmd17(handle, addr, in xfer_data()
546 handle->device->cfg.blockSize, base); in xfer_data()
550 rc = sd_cmd24(handle, addr, in xfer_data()
551 handle->device->cfg.blockSize, base); in xfer_data()
565 int erase_card(struct sd_handle *handle, uint32_t addr, uint32_t blocks) in erase_card() argument
571 if (sd_cmd35(handle, addr) != SD_OK) in erase_card()
575 if (sd_cmd36(handle, end_addr) != SD_OK) in erase_card()
578 if (sd_cmd38(handle) != SD_OK) in erase_card()
589 int read_block(struct sd_handle *handle, in read_block() argument
603 rel = xfer_data(handle, SD_OP_READ, addr, len, dst); in read_block()
614 int read_block(struct sd_handle *handle, in read_block() argument
617 return xfer_data(handle, SD_OP_READ, addr, len, dst); in read_block()
626 int write_block(struct sd_handle *handle, in write_block() argument
640 rel = xfer_data(handle, SD_OP_WRITE, addr, len, src); in write_block()
654 int write_buffer(struct sd_handle *handle, uint32_t length, uint8_t *data) in write_buffer() argument
659 blockSize = handle->device->cfg.blockSize; in write_buffer()
667 event = wait_for_event(handle, in write_buffer()
670 handle->device->cfg.wfe_retry); in write_buffer()
672 if (handle->device->ctrl.cmdStatus) { in write_buffer()
673 check_error(handle, handle->device->ctrl.cmdStatus); in write_buffer()
678 chal_sd_write_buffer((CHAL_HANDLE *) handle->device, in write_buffer()
681 chal_sd_write_buffer((CHAL_HANDLE *) handle->device, in write_buffer()
695 event = wait_for_event(handle, in write_buffer()
698 handle->device->cfg.wfe_retry); in write_buffer()
700 if (handle->device->ctrl.cmdStatus != SD_OK) { in write_buffer()
701 check_error(handle, handle->device->ctrl.cmdStatus); in write_buffer()
705 handle->device->ctrl.eventList &= ~SD4_EMMC_TOP_INTR_TXDONE_MASK; in write_buffer()
718 int read_buffer(struct sd_handle *handle, uint32_t length, uint8_t *data) in read_buffer() argument
723 blockSize = handle->device->cfg.blockSize; in read_buffer()
730 event = wait_for_event(handle, in read_buffer()
733 handle->device->cfg.wfe_retry); in read_buffer()
735 if (handle->device->ctrl.cmdStatus) { in read_buffer()
736 check_error(handle, handle->device->ctrl.cmdStatus); in read_buffer()
741 chal_sd_read_buffer((CHAL_HANDLE *) handle->device, in read_buffer()
744 chal_sd_read_buffer((CHAL_HANDLE *) handle->device, rem, in read_buffer()
757 chal_sd_dump_fifo((CHAL_HANDLE *) handle->device); in read_buffer()
761 event = wait_for_event(handle, SD4_EMMC_TOP_INTR_TXDONE_MASK, in read_buffer()
762 handle->device->cfg.wfe_retry); in read_buffer()
764 if (handle->device->ctrl.cmdStatus) { in read_buffer()
765 check_error(handle, handle->device->ctrl.cmdStatus); in read_buffer()
769 handle->device->ctrl.eventList &= ~SD4_EMMC_TOP_INTR_TXDONE_MASK; in read_buffer()
781 int check_error(struct sd_handle *handle, uint32_t ints) in check_error() argument
785 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device, in check_error()
790 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in check_error()
792 rel = abort_err(handle); in check_error()
794 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in check_error()
796 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device, in check_error()
802 rel = err_recovery(handle, ints); in check_error()
805 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device, in check_error()
816 static int err_recovery(struct sd_handle *handle, uint32_t errors) in err_recovery() argument
827 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in err_recovery()
831 chal_sd_reset_line((CHAL_HANDLE *) handle->device, in err_recovery()
835 if ((handle->device->ctrl.cmdIndex == 18) || in err_recovery()
836 (handle->device->ctrl.cmdIndex == 25)) in err_recovery()
837 rel = abort_err(handle); in err_recovery()
847 int process_cmd_response(struct sd_handle *handle, in process_cmd_response() argument
911 (handle->card->type == SD_CARD_SD)) { in process_cmd_response()
928 void data_xfer_setup(struct sd_handle *handle, uint8_t *data, uint32_t length, in data_xfer_setup() argument
931 chal_sd_setup_xfer((CHAL_HANDLE *)handle->device, data, length, dir); in data_xfer_setup()
943 int reset_host_ctrl(struct sd_handle *handle) in reset_host_ctrl() argument
950 static void pstate_log(struct sd_handle *handle) in pstate_log() argument
953 (handle->device->ctrl.sdRegBaseAddr + in pstate_log()
956 (handle->device->ctrl.sdRegBaseAddr + in pstate_log()
969 uint32_t wait_for_event(struct sd_handle *handle, in wait_for_event() argument
974 handle->device->ctrl.cmdStatus = 0; /* no error */ in wait_for_event()
977 chal_sd_get_irq_status((CHAL_HANDLE *)handle->device)); in wait_for_event()
981 regval = chal_sd_get_irq_status((CHAL_HANDLE *)handle->device); in wait_for_event()
984 chal_sd_set_dma_addr((CHAL_HANDLE *)handle->device, in wait_for_event()
987 handle->device)); in wait_for_event()
988 chal_sd_clear_irq((CHAL_HANDLE *)handle->device, in wait_for_event()
994 handle->device->ctrl.cmdIndex, in wait_for_event()
996 handle->device->ctrl.cmdStatus = SD_CMD_MISSING; in wait_for_event()
997 pstate_log(handle); in wait_for_event()
1004 handle->device->ctrl.cmdIndex, regval); in wait_for_event()
1005 handle->device->ctrl.cmdStatus = in wait_for_event()
1007 pstate_log(handle); in wait_for_event()
1012 handle->device->ctrl.cmdIndex, regval); in wait_for_event()
1013 handle->device->ctrl.cmdStatus = SD_CMD_ERROR_FLAGS; in wait_for_event()
1014 pstate_log(handle); in wait_for_event()
1018 cmd12 = chal_sd_get_atuo12_error((CHAL_HANDLE *)handle->device); in wait_for_event()
1021 handle->device->ctrl.cmdIndex, cmd12); in wait_for_event()
1022 handle->device->ctrl.cmdStatus = cmd12; in wait_for_event()
1023 pstate_log(handle); in wait_for_event()
1029 handle->device->ctrl.cmdIndex, regval); in wait_for_event()
1030 handle->device->ctrl.cmdStatus = in wait_for_event()
1032 pstate_log(handle); in wait_for_event()
1042 chal_sd_clear_irq((CHAL_HANDLE *)handle->device, (regval & mask)); in wait_for_event()
1047 int32_t set_config(struct sd_handle *handle, uint32_t speed, uint32_t retry, in set_config() argument
1053 if (handle == NULL) in set_config()
1056 handle->device->cfg.wfe_retry = wfe_retry; in set_config()
1058 rel = chal_sd_config((CHAL_HANDLE *)handle->device, speed, retry, in set_config()
1064 int mmc_cmd1(struct sd_handle *handle) in mmc_cmd1() argument
1073 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device, in mmc_cmd1()
1079 handle->device->ctrl.present = 0; /* init card present to be no card */ in mmc_cmd1()
1081 handle->card->type = SD_CARD_MMC; in mmc_cmd1()
1083 res = sd_cmd1(handle, cmd1_option, &newOcr); in mmc_cmd1()