Lines Matching defs: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)
59 return mmc_cmd6(handle, SDIO_HW_EMMC_EXT_CSD_BOOT_CNF | config);
62 void process_csd_mmc_speed(struct sd_handle *handle, uint32_t csd_mmc_speed)
109 chal_sd_set_clock((CHAL_HANDLE *) handle->device, div_ctrl_setting, 0);
111 chal_sd_set_clock((CHAL_HANDLE *) handle->device, div_ctrl_setting, 1);
122 int set_card_data_width(struct sd_handle *handle, int width)
162 rc = mmc_cmd6(handle, data_width);
167 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device,
191 static int abort_err(struct sd_handle *handle)
196 handle->device->ctrl.argReg = 0;
197 handle->device->ctrl.cmdIndex = SD_CMD_STOP_TRANSMISSION;
204 chal_sd_send_cmd((CHAL_HANDLE *) handle->device,
205 handle->device->ctrl.cmdIndex,
206 handle->device->ctrl.argReg, options);
208 event = wait_for_event(handle,
211 handle->device->cfg.wfe_retry);
220 chal_sd_get_response((CHAL_HANDLE *) handle->device,
223 process_cmd_response(handle, handle->device->ctrl.cmdIndex,
231 chal_sd_get_present_status((CHAL_HANDLE *) handle->device);
253 int process_data_xfer(struct sd_handle *handle, uint8_t *buffer, uint32_t addr,
258 if (handle->device->cfg.dma == SD_DMA_OFF) {
262 if (write_buffer(handle, length, buffer))
265 wait_for_event(handle,
268 handle->device->cfg.wfe_retry);
270 if (handle->device->ctrl.cmdStatus == SD_OK)
273 check_error(handle, handle->device->ctrl.cmdStatus);
281 if (handle->device->cfg.dma == SD_DMA_OFF) {
285 if (read_buffer(handle, length, buffer))
294 wait_for_event(handle,
297 handle->device->cfg.wfe_retry);
299 if (handle->device->ctrl.cmdStatus == SD_OK)
302 check_error(handle, handle->device->ctrl.cmdStatus);
314 int select_blk_sz(struct sd_handle *handle, uint16_t size)
316 return sd_cmd16(handle, size);
326 int init_card(struct sd_handle *handle, int detection)
332 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device,
338 handle->device->ctrl.present = 0; /* init card present to be no card */
340 init_mmc_card(handle);
342 handle->device->ctrl.present = 1; /* card is detected */
345 if (handle->card->type != SD_CARD_MMC)
362 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device,
364 if ((!set_card_data_width(handle, SD_BUS_DATA_WIDTH_8BIT)) &&
365 (!mmc_cmd8(handle, buffer)) &&
373 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device,
375 if ((!set_card_data_width(handle, SD_BUS_DATA_WIDTH_4BIT)) &&
376 (!mmc_cmd8(handle, buffer)) &&
384 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device,
387 if (!set_card_data_width(handle, SD_BUS_DATA_WIDTH_1BIT))
398 int init_mmc_card(struct sd_handle *handle)
404 handle->card->type = SD_CARD_MMC;
410 rc = sd_cmd1(handle, cmd1_option, &newOcr);
419 handle->card->type = SD_CARD_UNKNOWN;
425 handle->device->ctrl.ocr = ocr;
428 rc = sd_cmd2(handle);
430 handle->card->type = SD_CARD_UNKNOWN;
434 rc = sd_cmd3(handle);
436 handle->card->type = SD_CARD_UNKNOWN;
440 rc = sd_cmd9(handle, &emmc_global_vars_ptr->cardData);
442 handle->card->type = SD_CARD_UNKNOWN;
449 process_csd_mmc_speed(handle,
453 rc = sd_cmd7(handle, handle->device->ctrl.rca);
455 handle->card->type = SD_CARD_UNKNOWN;
459 rc = mmc_cmd8(handle, emmc_global_buf_ptr->u.Ext_CSD_storage);
468 handle->card->size / (1024 * 1024));
471 handle->card->size = (uint64_t)sec_count * 512;
474 handle->card->size / (1024 * 1024));
478 handle->device->ctrl.ocr |= SD_CARD_HIGH_CAPACITY;
479 handle->device->cfg.blockSize = 512;
482 if (handle->device->ctrl.ocr & SD_CARD_HIGH_CAPACITY) {
493 return handle->card->type;
501 int reset_card(struct sd_handle *handle)
506 handle->device->ctrl.rca = 0;
508 res = sd_cmd0(handle);
521 static int xfer_data(struct sd_handle *handle,
530 if ((length / handle->device->cfg.blockSize) > 1) {
533 rc = sd_cmd18(handle, addr, length, base);
537 rc = sd_cmd25(handle, addr, length, base);
545 rc = sd_cmd17(handle, addr,
546 handle->device->cfg.blockSize, base);
550 rc = sd_cmd24(handle, addr,
551 handle->device->cfg.blockSize, base);
565 int erase_card(struct sd_handle *handle, uint32_t addr, uint32_t blocks)
571 if (sd_cmd35(handle, addr) != SD_OK)
575 if (sd_cmd36(handle, end_addr) != SD_OK)
578 if (sd_cmd38(handle) != SD_OK)
589 int read_block(struct sd_handle *handle,
603 rel = xfer_data(handle, SD_OP_READ, addr, len, dst);
614 int read_block(struct sd_handle *handle,
617 return xfer_data(handle, SD_OP_READ, addr, len, dst);
626 int write_block(struct sd_handle *handle,
640 rel = xfer_data(handle, SD_OP_WRITE, addr, len, src);
654 int write_buffer(struct sd_handle *handle, uint32_t length, uint8_t *data)
659 blockSize = handle->device->cfg.blockSize;
667 event = wait_for_event(handle,
670 handle->device->cfg.wfe_retry);
672 if (handle->device->ctrl.cmdStatus) {
673 check_error(handle, handle->device->ctrl.cmdStatus);
678 chal_sd_write_buffer((CHAL_HANDLE *) handle->device,
681 chal_sd_write_buffer((CHAL_HANDLE *) handle->device,
695 event = wait_for_event(handle,
698 handle->device->cfg.wfe_retry);
700 if (handle->device->ctrl.cmdStatus != SD_OK) {
701 check_error(handle, handle->device->ctrl.cmdStatus);
705 handle->device->ctrl.eventList &= ~SD4_EMMC_TOP_INTR_TXDONE_MASK;
718 int read_buffer(struct sd_handle *handle, uint32_t length, uint8_t *data)
723 blockSize = handle->device->cfg.blockSize;
730 event = wait_for_event(handle,
733 handle->device->cfg.wfe_retry);
735 if (handle->device->ctrl.cmdStatus) {
736 check_error(handle, handle->device->ctrl.cmdStatus);
741 chal_sd_read_buffer((CHAL_HANDLE *) handle->device,
744 chal_sd_read_buffer((CHAL_HANDLE *) handle->device, rem,
757 chal_sd_dump_fifo((CHAL_HANDLE *) handle->device);
761 event = wait_for_event(handle, SD4_EMMC_TOP_INTR_TXDONE_MASK,
762 handle->device->cfg.wfe_retry);
764 if (handle->device->ctrl.cmdStatus) {
765 check_error(handle, handle->device->ctrl.cmdStatus);
769 handle->device->ctrl.eventList &= ~SD4_EMMC_TOP_INTR_TXDONE_MASK;
781 int check_error(struct sd_handle *handle, uint32_t ints)
785 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device,
790 chal_sd_reset_line((CHAL_HANDLE *) handle->device,
792 rel = abort_err(handle);
794 chal_sd_reset_line((CHAL_HANDLE *) handle->device,
796 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device,
802 rel = err_recovery(handle, ints);
805 chal_sd_set_irq_signal((CHAL_HANDLE *) handle->device,
816 static int err_recovery(struct sd_handle *handle, uint32_t errors)
827 chal_sd_reset_line((CHAL_HANDLE *) handle->device,
831 chal_sd_reset_line((CHAL_HANDLE *) handle->device,
835 if ((handle->device->ctrl.cmdIndex == 18) ||
836 (handle->device->ctrl.cmdIndex == 25))
837 rel = abort_err(handle);
847 int process_cmd_response(struct sd_handle *handle,
911 (handle->card->type == SD_CARD_SD)) {
928 void data_xfer_setup(struct sd_handle *handle, uint8_t *data, uint32_t length,
931 chal_sd_setup_xfer((CHAL_HANDLE *)handle->device, data, length, dir);
943 int reset_host_ctrl(struct sd_handle *handle)
950 static void pstate_log(struct sd_handle *handle)
953 (handle->device->ctrl.sdRegBaseAddr +
956 (handle->device->ctrl.sdRegBaseAddr +
969 uint32_t wait_for_event(struct sd_handle *handle,
974 handle->device->ctrl.cmdStatus = 0; /* no error */
977 chal_sd_get_irq_status((CHAL_HANDLE *)handle->device));
981 regval = chal_sd_get_irq_status((CHAL_HANDLE *)handle->device);
984 chal_sd_set_dma_addr((CHAL_HANDLE *)handle->device,
987 handle->device));
988 chal_sd_clear_irq((CHAL_HANDLE *)handle->device,
994 handle->device->ctrl.cmdIndex,
996 handle->device->ctrl.cmdStatus = SD_CMD_MISSING;
997 pstate_log(handle);
1004 handle->device->ctrl.cmdIndex, regval);
1005 handle->device->ctrl.cmdStatus =
1007 pstate_log(handle);
1012 handle->device->ctrl.cmdIndex, regval);
1013 handle->device->ctrl.cmdStatus = SD_CMD_ERROR_FLAGS;
1014 pstate_log(handle);
1018 cmd12 = chal_sd_get_atuo12_error((CHAL_HANDLE *)handle->device);
1021 handle->device->ctrl.cmdIndex, cmd12);
1022 handle->device->ctrl.cmdStatus = cmd12;
1023 pstate_log(handle);
1029 handle->device->ctrl.cmdIndex, regval);
1030 handle->device->ctrl.cmdStatus =
1032 pstate_log(handle);
1042 chal_sd_clear_irq((CHAL_HANDLE *)handle->device, (regval & mask));
1047 int32_t set_config(struct sd_handle *handle, uint32_t speed, uint32_t retry,
1053 if (handle == NULL)
1056 handle->device->cfg.wfe_retry = wfe_retry;
1058 rel = chal_sd_config((CHAL_HANDLE *)handle->device, speed, retry,
1064 int mmc_cmd1(struct sd_handle *handle)
1073 chal_sd_config_bus_width((CHAL_HANDLE *) handle->device,
1079 handle->device->ctrl.present = 0; /* init card present to be no card */
1081 handle->card->type = SD_CARD_MMC;
1083 res = sd_cmd1(handle, cmd1_option, &newOcr);