ccflags-y := -Idrivers/scsi
rts5208-y := rtsx.o rtsx_chip.o rtsx_transport.o rtsx_scsi.o \
- rtsx_card.o general.o sd.o xd.o ms.o spi.o trace.o
+ rtsx_card.o general.o sd.o xd.o ms.o spi.o
static int ms_parse_err_code(struct rtsx_chip *chip)
{
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval < 0) {
rtsx_clear_ms_error(chip);
ms_set_err_code(chip, MS_TO_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
if (!(tpc & 0x08)) { /* Read Packet */
if (*ptr & MS_CRC16_ERR) {
ms_set_err_code(chip, MS_CRC16_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
} else { /* Write Packet */
if (CHK_MSPRO(ms_card) && !(*ptr & 0x80)) {
if (*ptr & (MS_INT_ERR | MS_INT_CMDNK)) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
}
if (*ptr & MS_RDY_TIMEOUT) {
rtsx_clear_ms_error(chip);
ms_set_err_code(chip, MS_TO_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
enum dma_data_direction dir;
if (!buf || !buf_len) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
dir = DMA_TO_DEVICE;
err_code = MS_FLASH_WRITE_ERROR;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
else
retval = STATUS_FAIL;
- rtsx_trace(chip);
return retval;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (val & (MS_INT_CMDNK | MS_INT_ERR | MS_CRC16_ERR | MS_RDY_TIMEOUT)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
int retval, i;
if (!data || (data_len < cnt)) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
if (!(tpc & 0x08)) {
if (val & MS_CRC16_ERR) {
ms_set_err_code(chip, MS_CRC16_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
} else {
if (CHK_MSPRO(ms_card) && !(val & 0x80)) {
if (val & (MS_INT_ERR | MS_INT_CMDNK)) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
}
if (val & MS_RDY_TIMEOUT) {
ms_set_err_code(chip, MS_TO_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
ms_set_err_code(chip, MS_TO_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
u8 *ptr;
if (!data) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
if (!(tpc & 0x08)) {
if (val & MS_CRC16_ERR) {
ms_set_err_code(chip, MS_CRC16_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
} else {
if (CHK_MSPRO(ms_card) && !(val & 0x80)) {
if (val & (MS_INT_ERR | MS_INT_CMDNK)) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
}
if (val & MS_RDY_TIMEOUT) {
ms_set_err_code(chip, MS_TO_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
ms_set_err_code(chip, MS_TO_ERROR);
- rtsx_trace(chip);
return ms_parse_err_code(chip);
}
rtsx_clear_ms_error(chip);
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = switch_clock(chip, ms_card->ms_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = select_card(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = select_card(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = switch_clock(chip, ms_card->ms_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
MS_D1_PD | MS_D2_PD | MS_CLK_PD |
MS_D6_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF,
MS_D3_PD | MS_D0_PD | MS_BS_PD |
XD_D4_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF,
MS_D7_PD | XD_CE_PD | XD_CLE_PD |
XD_CD_PU);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF,
XD_RDY_PD | SD_D3_PD | SD_D2_PD |
XD_ALE_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF,
MS_INS_PU | SD_WP_PD | SD_CD_PU |
SD_CMD_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF,
MS_D5_PD | MS_D4_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else if (CHECK_PID(chip, 0x5288)) {
retval = rtsx_write_register(chip, CARD_PULL_CTL1,
0xFF, 0x55);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL2,
0xFF, 0x55);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL3,
0xFF, 0x4B);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL4,
0xFF, 0x69);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_send_cmd(chip, MS_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_power_off_card3v3(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = enable_card_clock(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->asic_code) {
retval = ms_pull_ctl_enable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = rtsx_write_register(chip, FPGA_PULL_CTL,
FPGA_MS_PULL_CTL_BIT | 0x20, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
if (!chip->ft2_fast_mode) {
retval = card_power_on(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->ocp_stat & oc_mask) {
dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n",
chip->ocp_stat);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN,
MS_OUTPUT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
NO_EXTEND_TOGGLE |
MS_BUS_WIDTH_1);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else {
NO_EXTEND_TOGGLE |
MS_BUS_WIDTH_1);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, MS_TRANS_CFG, 0xFF,
NO_WAIT_INT | NO_AUTO_READ_INT_REG);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_STOP, MS_STOP | MS_CLR_ERR,
MS_STOP | MS_CLR_ERR);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = ms_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, Pro_StatusReg, 6, SystemParm, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, PPBUF_BASE2 + 2, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "Type register: 0x%x\n", val);
if (val != 0x02)
ms_card->check_ms_flow = 1;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, PPBUF_BASE2 + 4, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "Category register: 0x%x\n", val);
if (val != 0) {
ms_card->check_ms_flow = 1;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, PPBUF_BASE2 + 5, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "Class register: 0x%x\n", val);
if (val == 0) {
retval = rtsx_read_register(chip, PPBUF_BASE2, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (val & WRT_PRTCT)
chip->card_wp |= MS_CARD;
} else {
ms_card->check_ms_flow = 1;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, PPBUF_BASE2 + 3, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "IF Mode register: 0x%x\n", val);
ms_card->ms_type &= 0x0F;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
do {
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (k > 100) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
chip->card_wp |= (MS_CARD);
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
break;
}
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, MS_CFG, 0x98,
MS_BUS_WIDTH_8 | SAMPLE_TIME_FALLING);
if (retval) {
- rtsx_trace(chip);
return retval;
}
ms_card->ms_type |= MS_8BIT;
retval = ms_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT,
1, NO_WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
for (i = 0; i < 3; i++) {
retval = ms_prepare_reset(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_identify_media_type(chip, switch_8bit_bus);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_confirm_cpu_startup(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
continue;
}
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
/* Switch MS-PRO into Parallel mode */
retval = rtsx_write_register(chip, MS_CFG, 0x18, MS_BUS_WIDTH_4);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, MS_CFG, PUSH_TIME_ODD,
PUSH_TIME_ODD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = ms_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_8bit_bus(chip);
if (retval != STATUS_SUCCESS) {
ms_card->switch_8bit_fail = 1;
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, PRO_WRITE_REG, 6, NO_WAIT_INT, buf, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, XC_CHG_POWER, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, buf);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (buf[0] & (MS_INT_CMDNK | MS_INT_ERR)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, Pro_IntReg, 2, Pro_SystemParm, 7);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf = kmalloc(64 * 512, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, &val);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(val & MS_INT_BREQ)) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_transfer_data(chip, MS_TM_AUTO_READ,
}
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, &val);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
PRO_READ_LONG_DATA, 0, WAIT_INT);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if ((buf[0] != 0xa5) && (buf[1] != 0xc3)) {
/* Signature code is wrong */
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if ((buf[4] < 1) || (buf[4] > 12)) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
sys_info_addr, sys_info_size);
if (sys_info_size != 96) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (sys_info_addr < 0x1A0) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if ((sys_info_size + sys_info_addr) > 0x8000) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
model_name_addr, model_name_size);
if (model_name_size != 48) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (model_name_addr < 0x1A0) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if ((model_name_size + model_name_addr) > 0x8000) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (i == buf[4]) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#ifdef SUPPORT_MSXC
if (CHK_MSXC(ms_card)) {
if (class_code != 0x03) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
if (class_code != 0x02) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
#else
if (class_code != 0x02) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
(device_type == 0x03)) {
chip->card_wp |= MS_CARD;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (sub_class & 0xC0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ms_card->switch_8bit_fail) {
retval = ms_pro_reset_flow(chip, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_read_attribute_info(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
#ifdef SUPPORT_MAGIC_GATE
retval = mg_set_tpc_para_sub(chip, 0, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = ms_set_rw_reg_addr(chip, StatusReg0, 2, 0, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_bytes(chip, READ_REG, 2, NO_WAIT_INT, val, 2);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val[1] & (STS_UCDT | STS_UCEX | STS_UCFG)) {
ms_set_err_code(chip, MS_FLASH_READ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_NO_ERROR);
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CED) {
if (val & INT_REG_ERR) {
retval = ms_read_status_reg(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
MS_EXTRA_SIZE, SystemParm,
6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_read_bytes(chip, READ_REG, MS_EXTRA_SIZE, NO_WAIT_INT,
data, MS_EXTRA_SIZE);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
u8 val, data[16];
if (!buf || (buf_len < MS_EXTRA_SIZE)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, 6 + MS_EXTRA_SIZE);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE),
NO_WAIT_INT, data, 16);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_NO_ERROR);
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CED) {
if (val & INT_REG_ERR) {
ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_NO_ERROR);
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_ERR) {
if (!(val & INT_REG_BREQ)) {
ms_set_err_code(chip, MS_FLASH_READ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_status_reg(chip);
} else {
if (!(val & INT_REG_BREQ)) {
ms_set_err_code(chip, MS_BREQ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_transfer_tpc(chip, MS_TM_NORMAL_READ, READ_PAGE_DATA,
0, NO_WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ms_check_err_code(chip, MS_FLASH_WRITE_ERROR)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_extra_data(chip, phy_blk, 0, extra, MS_EXTRA_SIZE);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, 7);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT, data, 7);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_NO_ERROR);
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CED) {
if (val & INT_REG_ERR) {
ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ERASE_RTY:
retval = ms_send_cmd(chip, BLOCK_ERASE, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_NO_ERROR);
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_CMD_NK);
ms_set_bad_block(chip, phy_blk);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CED) {
if (val & INT_REG_ERR) {
ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
for (i = start_page; i < end_page; i++) {
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_extra_data(chip, phy_blk, i,
extra, MS_EXTRA_SIZE);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_read_extra_data(chip, new_blk, 0, extra, MS_EXTRA_SIZE);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_status_reg(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, PPBUF_BASE2, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (val & BUF_FULL) {
retval = ms_send_cmd(chip, CLEAR_BUF, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(val & INT_REG_CED)) {
ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
for (i = start_page; i < end_page; i++) {
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag,
MS_EXTRA_SIZE, SystemParm, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT,
data, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_NO_ERROR);
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
READ_PAGE_DATA,
0, NO_WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (rty_cnt == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (!(val & INT_REG_BREQ)) {
ms_set_err_code(chip, MS_BREQ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE),
NO_WAIT_INT, data, 16);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_set_err_code(chip, MS_NO_ERROR);
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CED) {
if (val & INT_REG_ERR) {
ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
MS_EXTRA_SIZE, SystemParm,
7);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, WRITE_REG, 7,
NO_WAIT_INT, data, 8);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_bytes(chip, GET_INT, 1,
NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_ERR) {
ms_set_err_code(chip,
MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_prepare_reset(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, MS_RESET, NO_WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_status_reg(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, PPBUF_BASE2, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (val & WRT_PRTCT)
while (i < (MAX_DEFECTIVE_BLOCK + 2)) {
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (i == (MAX_DEFECTIVE_BLOCK + 2)) {
dev_dbg(rtsx_dev(chip), "No boot block found!");
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_page(chip, ms_card->boot_block, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, MS_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, MS_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[15]) {
retval = ms_set_rw_reg_addr(chip, 0, 0, SystemParm, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, PPBUF_BASE2, 0xFF, 0x88);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, PPBUF_BASE2 + 1, 0xFF, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = ms_transfer_tpc(chip, MS_TM_WRITE_BYTES, WRITE_REG, 1,
NO_WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
PUSH_TIME_ODD |
MS_NO_CHECK_INT);
if (retval) {
- rtsx_trace(chip);
return retval;
}
size = ms_card->segment_cnt * sizeof(struct zone_entry);
ms_card->segment = vzalloc(size);
if (!ms_card->segment) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_page(chip, ms_card->boot_block, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto INIT_FAIL;
}
retval = rtsx_read_register(chip, reg_addr++, &val1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto INIT_FAIL;
}
retval = rtsx_read_register(chip, reg_addr++, &val2);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto INIT_FAIL;
}
if (!ms_card->segment) {
retval = ms_init_l2p_tbl(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return retval;
}
}
if (!segment->l2p_table) {
segment->l2p_table = vmalloc(array_size(table_size, 2));
if (!segment->l2p_table) {
- rtsx_trace(chip);
goto BUILD_FAIL;
}
}
if (!segment->free_table) {
segment->free_table = vmalloc(MS_FREE_TABLE_CNT * 2);
if (!segment->free_table) {
- rtsx_trace(chip);
goto BUILD_FAIL;
}
}
}
retval = ms_init_page(chip, phy_blk, log_blk, 0, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto BUILD_FAIL;
}
log_blk, 0,
ms_card->page_off + 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_bad_block(chip, tmp_blk);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = enable_card_clock(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = select_card(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ms_card->check_ms_flow) {
retval = reset_ms(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
*/
retval = ms_build_l2p_tbl(chip, seg_no);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (val & MS_INT_BREQ) {
retval = ms_send_cmd(chip, PRO_STOP, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = mspro_set_rw_cmd(chip, start_sector, count, rw_cmd);
if (retval != STATUS_SUCCESS) {
ms_card->seq_mode = 0;
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
chip->rw_need_retry = 0;
dev_dbg(rtsx_dev(chip), "No card exist, exit %s\n",
__func__);
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_auto_tune_clock(chip);
}
- rtsx_trace(chip);
return retval;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, &tmp);
if (retval != STATUS_SUCCESS) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
return STATUS_SUCCESS;
}
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
MS_NO_CHECK_INT);
if (retval != STATUS_SUCCESS) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
data, 8);
if (retval != STATUS_SUCCESS) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, &tmp);
if (retval != STATUS_SUCCESS) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (tmp & (MS_INT_CED | MS_INT_CMDNK |
retval = rtsx_write_register(chip, MS_CFG, MS_NO_CHECK_INT, 0);
if (retval != STATUS_SUCCESS) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (i == 5000) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (tmp & (MS_INT_CMDNK | MS_INT_ERR)) {
ms_card->format_status = FORMAT_FAIL;
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
ms_card->format_status = FORMAT_FAIL;
ms_card->pro_under_formatting = 0;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, 0x00, 0x00, Pro_TPCParm, 0x01);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = mspro_set_rw_cmd(chip, 0, para, PRO_FORMAT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, MS_TRANS_CFG, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (tmp & (MS_INT_CMDNK | MS_INT_ERR)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
return STATUS_SUCCESS;
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval == STATUS_SUCCESS) {
if ((extra[1] & 0x30) != 0x30) {
ms_set_err_code(chip, MS_FLASH_READ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_ERR) {
}
ms_set_err_code(chip,
MS_FLASH_READ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
ms_set_err_code(chip, MS_FLASH_READ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
if (!(val & INT_REG_BREQ)) {
ms_set_err_code(chip, MS_BREQ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (!(val & INT_REG_CED)) {
retval = ms_send_cmd(chip, BLOCK_END, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT,
&val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(val & INT_REG_CED)) {
ms_set_err_code(chip, MS_FLASH_READ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval == -ETIMEDOUT) {
ms_set_err_code(chip, MS_TO_ERROR);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_TIMEDOUT;
}
if (retval != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_TO_ERROR);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_TIMEDOUT;
}
if (val & (MS_CRC16_ERR | MS_RDY_TIMEOUT)) {
ms_set_err_code(chip, MS_CRC16_ERROR);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, 7);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT,
data, 8);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT, 1,
NO_WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
SystemParm, (6 + MS_EXTRA_SIZE));
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
ms_set_err_code(chip, MS_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_CMDNK) {
ms_set_err_code(chip, MS_CMD_NK);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (val & INT_REG_ERR) {
ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(val & INT_REG_BREQ)) {
ms_set_err_code(chip, MS_BREQ_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
rtsx_clear_ms_error(chip);
if (retval == -ETIMEDOUT) {
- rtsx_trace(chip);
return STATUS_TIMEDOUT;
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if ((end_page - start_page) == 1) {
if (!(val & INT_REG_CED)) {
ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = ms_send_cmd(chip, BLOCK_END,
WAIT_INT);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_read_bytes(chip, GET_INT, 1,
NO_WAIT_INT, &val, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (!(val & INT_REG_CED)) {
ms_set_err_code(chip,
MS_FLASH_WRITE_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_copy_page(chip, old_blk, new_blk, log_blk,
page_off, ms_card->page_off + 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_copy_page(chip, old_blk, new_blk, log_blk,
0, start_page);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (delay_write->delay_write_flag) {
retval = ms_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
delay_write->logblock,
delay_write->pageoff);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
ms_rw_fail(srb, chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
chip->card_fail |= MS_CARD;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
old_blk = delay_write->old_phyblock;
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
if ((old_blk == 0xFFFF) || (new_blk == 0xFFFF)) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
set_sense_type
(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#ifdef MS_DELAY_WRITE
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
if (old_blk == 0xFFFF) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_rw_fail(srb, chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
chip->card_fail |= MS_CARD;
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
log_blk - ms_start_idx[seg_no]);
if (old_blk == 0xFFFF) {
ms_rw_fail(srb, chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
new_blk = ms_get_unused_block(chip, seg_no);
if (new_blk == 0xFFFF) {
ms_rw_fail(srb, chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
set_sense_type
(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
ms_rw_fail(srb, chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = rtsx_send_cmd(chip, MS_CARD, 5000);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
val = *rtsx_get_cmd_data(chip);
if (val & MS_INT_ERR) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
}
if (i == MS_MAX_RETRY_COUNT) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (check_ms_err(chip)) {
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_write_bytes(chip, PRO_WRITE_REG, (type == 0) ? 1 : 6,
NO_WAIT_INT, buf, 6);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (scsi_bufflen(srb) < 12) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = mg_send_ex_cmd(chip, MG_SET_LID, 0);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB);
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf1, 32);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (check_ms_err(chip)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf = kmalloc(1540, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
retval = mg_send_ex_cmd(chip, MG_GET_LEKB, 0);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
- rtsx_trace(chip);
goto free_buffer;
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
goto free_buffer;
}
if (check_ms_err(chip)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
retval = STATUS_FAIL;
goto free_buffer;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = mg_send_ex_cmd(chip, MG_GET_ID, 0);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf, 32);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (check_ms_err(chip)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_poll_int(chip);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = mg_send_ex_cmd(chip, MG_SET_RD, 0);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
- rtsx_trace(chip);
return STATUS_FAIL;
}
32, WAIT_INT, buf, 32);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (check_ms_err(chip)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = mg_send_ex_cmd(chip, MG_MAKE_RMS, 0);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf1, 32);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (check_ms_err(chip)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_poll_int(chip);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = mg_send_ex_cmd(chip, MG_MAKE_KSE, 0);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf, 32);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (check_ms_err(chip)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf = kmalloc(1028, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
retval = mg_send_ex_cmd(chip, MG_GET_IBD, ms_card->mg_entry_num);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
goto free_buffer;
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
goto free_buffer;
}
if (check_ms_err(chip)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
rtsx_clear_ms_error(chip);
- rtsx_trace(chip);
retval = STATUS_FAIL;
goto free_buffer;
}
retval = ms_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf = kmalloc(1028, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
} else {
set_sense_type(chip, lun, SENSE_TYPE_MG_WRITE_ERR);
}
- rtsx_trace(chip);
goto SetICVFinish;
}
SENSE_TYPE_MG_WRITE_ERR);
}
retval = STATUS_FAIL;
- rtsx_trace(chip);
goto SetICVFinish;
}
}
} else {
set_sense_type(chip, lun, SENSE_TYPE_MG_WRITE_ERR);
}
- rtsx_trace(chip);
goto SetICVFinish;
}
#endif
retval = disable_card_clock(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->asic_code) {
retval = ms_pull_ctl_disable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
FPGA_MS_PULL_CTL_BIT | 0x20,
FPGA_MS_PULL_CTL_BIT);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!chip->ft2_fast_mode) {
retval = card_power_off(chip, MS_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = ms_power_off_card3v3(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
return (struct rtsx_dev *)host->hostdata;
}
-static inline void get_current_time(u8 *timeval_buf, int buf_len)
-{
- struct timespec64 ts64;
- u32 tv_usec;
-
- if (!timeval_buf || (buf_len < 8))
- return;
-
- getnstimeofday64(&ts64);
-
- tv_usec = ts64.tv_nsec / NSEC_PER_USEC;
-
- timeval_buf[0] = (u8)(ts64.tv_sec >> 24);
- timeval_buf[1] = (u8)(ts64.tv_sec >> 16);
- timeval_buf[2] = (u8)(ts64.tv_sec >> 8);
- timeval_buf[3] = (u8)(ts64.tv_sec);
- timeval_buf[4] = (u8)(tv_usec >> 24);
- timeval_buf[5] = (u8)(tv_usec >> 16);
- timeval_buf[6] = (u8)(tv_usec >> 8);
- timeval_buf[7] = (u8)(tv_usec);
-}
-
/*
* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
* single queue element srb for write access
/* struct scsi_cmnd transfer buffer access utilities */
enum xfer_buf_dir {TO_XFER_BUF, FROM_XFER_BUF};
-#define _MSG_TRACE
-
-#include "trace.h"
#include "rtsx_chip.h"
#include "rtsx_transport.h"
#include "rtsx_scsi.h"
clk, chip->cur_clk);
if ((clk <= 2) || (n > max_n)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, WAIT_TIME);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
udelay(10);
retval = rtsx_write_register(chip, CLK_CTL, CLK_LOW_FREQ, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
default:
dev_dbg(rtsx_dev(chip), "Try to switch to an illegal clock (%d)\n",
clk);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CLK_CTL, 0xFF, CLK_LOW_FREQ);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (sd_vpclk_phase_reset) {
retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
PHASE_NOT_RESET, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SD_VPCLK1_CTL,
PHASE_NOT_RESET, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, CLK_DIV, 0xFF,
(div << 4) | mcu_cnt);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CLK_SEL, 0xFF, sel);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
PHASE_NOT_RESET, PHASE_NOT_RESET);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SD_VPCLK1_CTL,
PHASE_NOT_RESET, PHASE_NOT_RESET);
if (retval) {
- rtsx_trace(chip);
return retval;
}
udelay(200);
}
retval = rtsx_write_register(chip, CLK_CTL, 0xFF, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_CLK_EN, clk_en, clk_en);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_CLK_EN, clk_en, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_send_cmd(chip, 0, 100);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, 100);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_PWR_CTL, mask, val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
int i;
if (!chip->rw_card[lun]) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
if (rtsx_check_chip_exist(chip) != STATUS_SUCCESS) {
rtsx_release_chip(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (detect_card_cd(chip, chip->cur_card) !=
STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else if (card == XD_CARD) {
value = CARD_SHARE_48_XD;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else if (card == XD_CARD) {
value = CARD_SHARE_BAROSSA_XD;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_SHARE_MODE, mask, value);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else if (card == SPI_CARD) {
mod = SPI_MOD_SEL;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_SELECT, 0x07, mod);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->cur_card = card;
retval = card_share_mode(chip, card);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
card_cd = XD_EXIST;
} else {
dev_dbg(rtsx_dev(chip), "Wrong card type: 0x%x\n", card);
- rtsx_trace(chip);
return STATUS_FAIL;
}
status = rtsx_readl(chip, RTSX_BIPR);
if (!(status & card_cd)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_PWR_CTL, 0x0F, 0x0F);
if (retval) {
- rtsx_trace(chip);
return retval;
}
MS_INS_PU | SD_WP_PU |
SD_CD_PU | SD_CMD_PU);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else {
0xFF,
FPGA_SD_PULL_CTL_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, CARD_SHARE_MODE, 0xFF,
CARD_SHARE_48_SD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
/* Enable SDIO internal clock */
retval = rtsx_write_register(chip, 0xFF2C, 0x01, 0x01);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SDIO_CTRL, 0xFF,
SDIO_BUS_CTRL | SDIO_CD_CTRL);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (CHECK_PID(chip, 0x5288)) {
retval = rtsx_read_register(chip, 0xFE5A, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (tmp & 0x08)
} else if (CHECK_PID(chip, 0x5208)) {
retval = rtsx_read_register(chip, 0xFE70, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (tmp & 0x80)
retval = rtsx_read_register(chip, TLPTISTAT, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
cd_toggle_mask = 0x08;
retval = rtsx_write_register(chip, 0xFE5A,
0x08, 0x00);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else if (CHECK_PID(chip, 0x5208)) {
retval = rtsx_write_register(chip, 0xFE70,
0x80, 0x00);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, TLPTISTAT, 0xFF,
tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (chip->asic_code) {
retval = sd_pull_ctl_enable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
FPGA_SD_PULL_CTL_BIT | 0x20,
0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = card_share_mode(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, 0xFE5A,
0x08, 0x08);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else if (CHECK_PID(chip, 0x5208)) {
retval = rtsx_write_register(chip, 0xFE70,
0x80, 0x80);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
} else {
retval = rtsx_write_register(chip, TLPTISTAT, 0x08, 0x08);
if (retval) {
- rtsx_trace(chip);
return retval;
}
ret = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF,
chip->aspm_l0s_l1_en);
if (ret != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (CHECK_PID(chip, 0x5208)) {
ret = rtsx_write_register(chip, ASPM_FORCE_CTL, 0xFF, 0x3F);
if (ret) {
- rtsx_trace(chip);
return ret;
}
}
ret = rtsx_write_config_byte(chip, LCTLR, chip->aspm_l0s_l1_en);
if (ret != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ret = rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1,
0xC0, 0xFF, chip->aspm_l0s_l1_en);
if (ret != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (chip->phy_debug_mode) {
ret = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0);
if (ret) {
- rtsx_trace(chip);
return ret;
}
rtsx_disable_bus_int(chip);
ret = rtsx_read_phy_register(chip, 0x00, ®);
if (ret != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
reg |= 0x80;
ret = rtsx_write_phy_register(chip, 0x00, reg);
if (ret != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
ret = rtsx_read_phy_register(chip, 0x1C, ®);
if (ret != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
reg &= 0xFFF7;
ret = rtsx_write_phy_register(chip, 0x1C, reg);
if (ret != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 0x00);
if (retval) {
- rtsx_trace(chip);
return retval;
}
/* Disable card clock */
retval = rtsx_write_register(chip, CARD_CLK_EN, 0x1E, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (CHECK_LUN_MODE(chip, SD_MS_2LUN)) {
retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else {
retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN,
MS_OC_POWER_DOWN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, OCPPARA1, OCP_TIME_MASK,
OCP_TIME_800);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, OCPPARA2, OCP_THD_MASK,
OCP_THD_244_946);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, OCPCTL, 0xFF,
CARD_OC_INT_EN | CARD_DETECT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
#else
retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN,
OC_POWER_DOWN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
#endif
if (!CHECK_PID(chip, 0x5288)) {
retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0xFF, 0x03);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
/* Turn off LED */
retval = rtsx_write_register(chip, CARD_GPIO, 0xFF, 0x03);
if (retval) {
- rtsx_trace(chip);
return retval;
}
/* Reset delink mode */
retval = rtsx_write_register(chip, CHANGE_LINK_STATE, 0x0A, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_DRIVE_SEL, 0xFF,
chip->card_drive_sel);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_AUTO_BLINK, 0xFF,
LED_BLINK_SPEED | BLINK_EN | LED_GPIO0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
#endif
retval = rtsx_write_register(chip, SSC_CTL1, 0xFF,
SSC_8X_EN | SSC_SEL_4M);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SSC_CTL2, 0xFF, 0x12);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
*/
retval = rtsx_write_register(chip, CHANGE_LINK_STATE, 0x16, 0x10);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (chip->aspm_l0s_l1_en) {
retval = rtsx_reset_aspm(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
if (chip->asic_code && CHECK_PID(chip, 0x5208)) {
retval = rtsx_write_phy_register(chip, 0x07, 0x0129);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_write_config_byte(chip, LCTLR,
chip->aspm_l0s_l1_en);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_write_config_byte(chip, 0x81, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
0xC0, 0xFF00, 0x0100);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (CHECK_PID(chip, 0x5288) && !CHK_SDIO_EXIST(chip)) {
retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFFFF, 0x0103);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_cfg_dw(chip, 2, 0x84, 0xFF, 0x03);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_write_register(chip, IRQSTAT0, LINK_RDY_INT,
LINK_RDY_INT);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, PERST_GLITCH_WIDTH, 0xFF, 0x80);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_enable_pcie_intr(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_pre_handle_sdio_old(chip);
#endif /* HW_AUTO_SWITCH_SD_BUS */
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SDIO_CTRL,
SDIO_BUS_CTRL | SDIO_CD_CTRL, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, SSC_CTL1, SSC_RSTB,
SSC_RSTB);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, RCCTL, 0x01, 0x00);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, MAIN_PWR_OFF_CTL, 0x03,
0x03);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
if (chip->remote_wakeup_en && !chip->auto_delink_en) {
retval = rtsx_write_register(chip, WAKE_SEL_CTL, 0x07, 0x07);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (chip->aux_pwr_exist) {
retval = rtsx_write_register(chip, PME_FORCE_CTL,
0xFF, 0x33);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
} else {
retval = rtsx_write_register(chip, WAKE_SEL_CTL, 0x07, 0x04);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, PME_FORCE_CTL, 0xFF, 0x30);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
if (CHECK_PID(chip, 0x5208) && (chip->ic_version >= IC_VER_D)) {
retval = rtsx_write_register(chip, PETXCFG, 0x1C, 0x14);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
if (chip->asic_code && CHECK_PID(chip, 0x5208)) {
retval = rtsx_clr_phy_reg_bit(chip, 0x1C, 2);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
MS_PARTIAL_POWER_ON |
SD_PARTIAL_POWER_ON);
if (retval) {
- rtsx_trace(chip);
return retval;
}
udelay(chip->pmos_pwr_on_interval);
retval = rtsx_write_register(chip, CARD_PWR_CTL, 0xFF,
MS_POWER_ON | SD_POWER_ON);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CLK_SEL, 0x03, 0x03);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_read_register(chip, CLK_SEL, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->asic_code = val == 0 ? 1 : 0;
if (chip->asic_code) {
retval = rtsx_read_phy_register(chip, 0x1C, ®);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = rtsx_read_register(chip, 0xFE80, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->ic_version = val;
retval = rtsx_read_register(chip, PDINFO, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val);
retval = rtsx_read_register(chip, 0xFE50, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->hw_bypass_sd = val & 0x01 ? 1 : 0;
if (chip->use_hw_setting) {
retval = rtsx_read_register(chip, CHANGE_LINK_STATE, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->auto_delink_en = val & 0x80 ? 1 : 0;
retval = rtsx_write_register(chip, CLK_SEL, 0x03, 0x03);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_read_register(chip, CLK_SEL, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->asic_code = val == 0 ? 1 : 0;
retval = rtsx_read_register(chip, PDINFO, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val);
retval = rtsx_read_register(chip, CARD_SHARE_MODE, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "CARD_SHARE_MODE: 0x%x\n", val);
retval = rtsx_read_register(chip, 0xFE5A, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->hw_bypass_sd = val & 0x10 ? 1 : 0;
retval = rtsx_read_cfg_dw(chip, 0, 0x718, &lval);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->use_hw_setting) {
retval = rtsx_read_register(chip, CHANGE_LINK_STATE, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
chip->auto_delink_en = val & 0x80 ? 1 : 0;
chip->ic_version = 0;
-#ifdef _MSG_TRACE
- chip->msg_idx = 0;
-#endif
-
memset(xd_card, 0, sizeof(struct xd_info));
memset(sd_card, 0, sizeof(struct sd_info));
memset(ms_card, 0, sizeof(struct ms_info));
retval = rtsx_write_register(chip, FPDCTL, SSC_POWER_DOWN, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
wait_timeout(200);
retval = rtsx_write_register(chip, CLK_DIV, 0x07, 0x07);
if (retval) {
- rtsx_trace(chip);
return retval;
}
dev_dbg(rtsx_dev(chip), "chip->use_hw_setting = %d\n",
if (CHECK_PID(chip, 0x5208)) {
retval = rts5208_init(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else if (CHECK_PID(chip, 0x5288)) {
retval = rts5288_init(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_reset_chip(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
val = rtsx_readl(chip, RTSX_HAIMR);
if ((val & BIT(31)) == 0) {
if (data != (u8)val) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
}
- rtsx_trace(chip);
return STATUS_TIMEDOUT;
}
}
if (i >= MAX_RW_REG_CNT) {
- rtsx_trace(chip);
return STATUS_TIMEDOUT;
}
0xFF,
(u8)(val & mask & 0xFF));
if (retval) {
- rtsx_trace(chip);
return retval;
}
mode |= (1 << i);
if (mode) {
retval = rtsx_write_register(chip, CFGADDR0, 0xFF, (u8)addr);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CFGADDR1, 0xFF,
(u8)(addr >> 8));
if (retval) {
- rtsx_trace(chip);
return retval;
}
0x80 | mode |
((func_no & 0x03) << 4));
if (retval) {
- rtsx_trace(chip);
return retval;
}
for (i = 0; i < MAX_RW_REG_CNT; i++) {
retval = rtsx_read_register(chip, CFGRWCTL, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if ((tmp & 0x80) == 0)
retval = rtsx_write_register(chip, CFGADDR0, 0xFF, (u8)addr);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CFGADDR1, 0xFF, (u8)(addr >> 8));
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CFGRWCTL, 0xFF,
0x80 | ((func_no & 0x03) << 4));
if (retval) {
- rtsx_trace(chip);
return retval;
}
for (i = 0; i < MAX_RW_REG_CNT; i++) {
retval = rtsx_read_register(chip, CFGRWCTL, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if ((tmp & 0x80) == 0)
for (i = 0; i < 4; i++) {
retval = rtsx_read_register(chip, CFGDATA0 + i, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
data |= (u32)tmp << (i * 8);
int retval;
if (!buf) {
- rtsx_trace(chip);
return STATUS_NOMEM;
}
data = vzalloc(array_size(dw_len, 4));
if (!data) {
- rtsx_trace(chip);
return STATUS_NOMEM;
}
mask = vzalloc(array_size(dw_len, 4));
if (!mask) {
vfree(data);
- rtsx_trace(chip);
return STATUS_NOMEM;
}
if (retval != STATUS_SUCCESS) {
vfree(data);
vfree(mask);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
data = vmalloc(array_size(dw_len, 4));
if (!data) {
- rtsx_trace(chip);
return STATUS_NOMEM;
}
data + i);
if (retval != STATUS_SUCCESS) {
vfree(data);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_write_register(chip, PHYDATA0, 0xFF, (u8)val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, PHYDATA1, 0xFF, (u8)(val >> 8));
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, PHYADDR, 0xFF, addr);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, PHYRWCTL, 0xFF, 0x81);
if (retval) {
- rtsx_trace(chip);
return retval;
}
for (i = 0; i < 100000; i++) {
retval = rtsx_read_register(chip, PHYRWCTL, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!(tmp & 0x80)) {
}
if (!finished) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, PHYADDR, 0xFF, addr);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, PHYRWCTL, 0xFF, 0x80);
if (retval) {
- rtsx_trace(chip);
return retval;
}
for (i = 0; i < 100000; i++) {
retval = rtsx_read_register(chip, PHYRWCTL, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!(tmp & 0x80)) {
}
if (!finished) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, PHYDATA0, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
data = tmp;
retval = rtsx_read_register(chip, PHYDATA1, &tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
data |= (u16)tmp << 8;
retval = rtsx_write_register(chip, EFUSE_CTRL, 0xFF, 0x80 | addr);
if (retval) {
- rtsx_trace(chip);
return retval;
}
for (i = 0; i < 100; i++) {
retval = rtsx_read_register(chip, EFUSE_CTRL, &data);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!(data & 0x80))
}
if (data & 0x80) {
- rtsx_trace(chip);
return STATUS_TIMEDOUT;
}
retval = rtsx_read_register(chip, EFUSE_DATA, &data);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (val)
retval = rtsx_write_register(chip, EFUSE_DATA, 0xFF, tmp);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, EFUSE_CTRL, 0xFF,
0xA0 | addr);
if (retval) {
- rtsx_trace(chip);
return retval;
}
for (j = 0; j < 100; j++) {
retval = rtsx_read_register(chip, EFUSE_CTRL, &data);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!(data & 0x80))
}
if (data & 0x80) {
- rtsx_trace(chip);
return STATUS_TIMEDOUT;
}
retval = rtsx_read_phy_register(chip, reg, &value);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
value &= ~(1 << bit);
retval = rtsx_write_phy_register(chip, reg, value);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_read_phy_register(chip, reg, &value);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
value |= (1 << bit);
retval = rtsx_write_phy_register(chip, reg, value);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
u8 *ptr;
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
retval = rtsx_send_cmd(chip, 0, 250);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, 250);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
u8 *ptr;
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
retval = rtsx_send_cmd(chip, 0, 250);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_send_cmd(chip, 0, 250);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
int rtsx_check_chip_exist(struct rtsx_chip *chip)
{
if (rtsx_readl(chip, 0) == 0xFFFFFFFF) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (mask) {
retval = rtsx_write_register(chip, FPDCTL, mask, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
val = mask;
retval = rtsx_write_register(chip, FPDCTL, mask, val);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
int spi_clock;
};
-#ifdef _MSG_TRACE
-struct trace_msg_t {
- u16 line;
-#define MSG_FUNC_LEN 64
- char func[MSG_FUNC_LEN];
-#define MSG_FILE_LEN 32
- char file[MSG_FILE_LEN];
-#define TIME_VAL_LEN 16
- u8 timeval_buf[TIME_VAL_LEN];
- u8 valid;
-};
-#endif
-
/************/
/* LUN mode */
/************/
struct spi_info spi;
-#ifdef _MSG_TRACE
- struct trace_msg_t trace_msg[TRACE_ITEM_CNT];
- int msg_idx;
-#endif
-
int auto_delink_cnt;
int auto_delink_allowed;
buf = vmalloc(scsi_bufflen(srb));
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (check_card_ready(chip, lun))
return TRANSPORT_GOOD;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
break;
}
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (prevent) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
buf = vmalloc(scsi_bufflen(srb));
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
scsi_set_resid(srb, scsi_bufflen(srb));
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
#endif
buf = kmalloc(data_size, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (!check_card_ready(chip, lun) || (get_card_size(chip, lun) == 0)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
*/
dev_dbg(rtsx_dev(chip), "SD card being erased!\n");
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_READ_FORBIDDEN);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
dev_dbg(rtsx_dev(chip), "SD card locked!\n");
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_READ_FORBIDDEN);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
sec_cnt = ((u16)(srb->cmnd[9]) << 8) | srb->cmnd[10];
} else {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if ((start_sec > get_card_size(chip, lun)) ||
((start_sec + sec_cnt) > get_card_size(chip, lun))) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LBA_OVER_RANGE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
else
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
dev_dbg(rtsx_dev(chip), "Write protected card!\n");
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_PROTECT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
SENSE_TYPE_MEDIA_WRITE_ERR);
}
retval = TRANSPORT_FAILED;
- rtsx_trace(chip);
goto exit;
} else {
chip->rw_fail_cnt[lun] = 0;
if (!check_card_ready(chip, lun)) {
if (!chip->mspro_formatter_enable) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
buf = kmalloc(buf_len, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
buf = kmalloc(8, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
retval = rtsx_force_power_on(chip, SSC_PDCTL);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
len);
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
if (addr < 0xFC00) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (retval != STATUS_SUCCESS) {
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
if (addr < 0xFC00) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len);
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (retval != STATUS_SUCCESS) {
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (get_lun_card(chip, lun) != SD_CARD) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
return TRANSPORT_GOOD;
}
-#ifdef _MSG_TRACE
-static int trace_msg_cmd(struct scsi_cmnd *srb, struct rtsx_chip *chip)
-{
- unsigned char *ptr, *buf = NULL;
- int i, msg_cnt;
- u8 clear;
- unsigned int buf_len;
-
- buf_len = 4 + ((2 + MSG_FUNC_LEN + MSG_FILE_LEN + TIME_VAL_LEN) *
- TRACE_ITEM_CNT);
-
- if ((scsi_bufflen(srb) < buf_len) || !scsi_sglist(srb)) {
- set_sense_type(chip, SCSI_LUN(srb),
- SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
- return TRANSPORT_FAILED;
- }
-
- clear = srb->cmnd[2];
-
- buf = vmalloc(scsi_bufflen(srb));
- if (!buf) {
- rtsx_trace(chip);
- return TRANSPORT_ERROR;
- }
- ptr = buf;
-
- if (chip->trace_msg[chip->msg_idx].valid)
- msg_cnt = TRACE_ITEM_CNT;
- else
- msg_cnt = chip->msg_idx;
-
- *(ptr++) = (u8)(msg_cnt >> 24);
- *(ptr++) = (u8)(msg_cnt >> 16);
- *(ptr++) = (u8)(msg_cnt >> 8);
- *(ptr++) = (u8)msg_cnt;
- dev_dbg(rtsx_dev(chip), "Trace message count is %d\n", msg_cnt);
-
- for (i = 1; i <= msg_cnt; i++) {
- int j, idx;
-
- idx = chip->msg_idx - i;
- if (idx < 0)
- idx += TRACE_ITEM_CNT;
-
- *(ptr++) = (u8)(chip->trace_msg[idx].line >> 8);
- *(ptr++) = (u8)(chip->trace_msg[idx].line);
- for (j = 0; j < MSG_FUNC_LEN; j++)
- *(ptr++) = chip->trace_msg[idx].func[j];
-
- for (j = 0; j < MSG_FILE_LEN; j++)
- *(ptr++) = chip->trace_msg[idx].file[j];
-
- for (j = 0; j < TIME_VAL_LEN; j++)
- *(ptr++) = chip->trace_msg[idx].timeval_buf[j];
- }
-
- rtsx_stor_set_xfer_buf(buf, scsi_bufflen(srb), srb);
- vfree(buf);
-
- if (clear) {
- chip->msg_idx = 0;
- for (i = 0; i < TRACE_ITEM_CNT; i++)
- chip->trace_msg[i].valid = 0;
- }
-
- scsi_set_resid(srb, 0);
- return TRANSPORT_GOOD;
-}
-#endif
-
static int read_host_reg(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{
u8 addr, buf[4];
default:
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else if (srb->cmnd[3] == 2) {
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
} else {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
default:
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
rtsx_stor_set_xfer_buf(&tmp, 1, srb);
} else {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
scsi_set_resid(srb, 0);
if (!CHECK_PID(chip, 0x5208)) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
chip->phy_debug_mode = 1;
retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = rtsx_read_phy_register(chip, 0x1C, ®);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
reg |= 0x0001;
retval = rtsx_write_phy_register(chip, 0x1C, reg);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
chip->phy_debug_mode = 0;
retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0x77);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = rtsx_read_phy_register(chip, 0x1C, ®);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
reg &= 0xFFFE;
retval = rtsx_write_phy_register(chip, 0x1C, reg);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
if (cmd_type > 2) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
addr = (srb->cmnd[5] << 8) | srb->cmnd[6];
if (scsi_bufflen(srb) < 1) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
rtsx_stor_set_xfer_buf(&value, 1, srb);
default:
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (len) {
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
set_sense_type
(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
retval = rtsx_force_power_on(chip, SSC_PDCTL);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else if (mode == 1) {
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len);
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (retval != STATUS_SUCCESS) {
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
vfree(buf);
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
len = (u8)min_t(unsigned int, scsi_bufflen(srb), len);
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
retval = rtsx_force_power_on(chip, SSC_PDCTL);
if (retval != STATUS_SUCCESS) {
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
retval = rtsx_read_phy_register(chip, 0x08, &val);
if (retval != STATUS_SUCCESS) {
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
LDO3318_PWR_MASK, LDO_OFF);
if (retval != STATUS_SUCCESS) {
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
0x4C00 | chip->phy_voltage);
if (retval != STATUS_SUCCESS) {
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
LDO3318_PWR_MASK, LDO_ON);
if (retval != STATUS_SUCCESS) {
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
retval = card_power_on(chip, SPI_CARD);
if (retval != STATUS_SUCCESS) {
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_WRITE_ERR);
result = TRANSPORT_FAILED;
- rtsx_trace(chip);
goto exit;
}
}
retval = card_power_off(chip, SPI_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
retval = rtsx_write_register(chip, PWR_GATE_CTRL,
LDO3318_PWR_MASK, LDO_OFF);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
retval = rtsx_write_phy_register(chip, 0x08, val);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
retval = rtsx_write_register(chip, PWR_GATE_CTRL,
LDO3318_PWR_MASK, LDO_ON);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
}
if (func > func_max) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (func > func_max) {
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len);
buf = vmalloc(len);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR);
vfree(buf);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
default:
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
bus_width = chip->card_bus_width[lun];
} else {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (CHECK_PID(chip, 0x5208) || CHECK_PID(chip, 0x5288)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
rtsx_write_register(chip, CARD_GPIO_DIR, 0x07, gpio_dir);
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
rtsx_write_register(chip, CARD_GPIO_DIR, 0x07, gpio_dir);
if (result != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
result = get_card_bus_width(srb, chip);
break;
-#ifdef _MSG_TRACE
- case TRACE_MSG:
- result = trace_msg_cmd(srb, chip);
- break;
-#endif
-
case SCSI_APP_CMD:
result = app_cmd(srb, chip);
break;
default:
set_sense_type(chip, SCSI_LUN(srb),
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (get_lun_card(chip, lun) != MS_CARD) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
(srb->cmnd[5] != 0x66) || (srb->cmnd[6] != 0x6D) ||
(srb->cmnd[7] != 0x74)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!check_card_ready(chip, lun) ||
(get_card_size(chip, lun) == 0)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
if (!(chip->card_ready & MS_CARD)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (chip->card_wp & MS_CARD) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_PROTECT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!CHK_MSPRO(ms_card)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = mspro_format(srb, chip, MS_SHORT_DATA_LEN, quick_format);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_FORMAT_CMD_FAILED);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (get_lun_card(chip, lun) != MS_CARD) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
(srb->cmnd[5] != 0x53) || (srb->cmnd[6] != 0x49) ||
(srb->cmnd[7] != 0x44)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
(!CHK_MSXC(ms_card) && (dev_info_id == 0x13)) ||
!CHK_MSPRO(ms_card)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
buf = kmalloc(buf_len, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (get_lun_card(chip, lun) != SD_CARD) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
default:
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (get_lun_card(chip, lun) != MS_CARD) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (srb->cmnd[7] != KC_MG_R_PRO) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!CHK_MSPRO(ms_card)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
(srb->cmnd[9] == 0x1C)) {
retval = mg_get_local_EKB(srb, chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
(srb->cmnd[9] == 0x24)) {
retval = mg_get_rsp_chg(srb, chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
(srb->cmnd[5] < 32)) {
retval = mg_get_ICV(srb, chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
default:
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!check_card_ready(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (check_card_wp(chip, lun)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_PROTECT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (get_lun_card(chip, lun) != MS_CARD) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (srb->cmnd[7] != KC_MG_R_PRO) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!CHK_MSPRO(ms_card)) {
set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
(srb->cmnd[9] == 0x0C)) {
retval = mg_set_leaf_id(srb, chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
(srb->cmnd[9] == 0x0C)) {
retval = mg_chg(srb, chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
(srb->cmnd[9] == 0x0C)) {
retval = mg_rsp(srb, chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
(srb->cmnd[5] < 32)) {
retval = mg_set_ICV(srb, chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
} else {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
default:
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
/* Logical Unit Not Ready Format in Progress */
set_sense_data(chip, lun, CUR_ERR,
0x02, 0, 0x04, 0x04, 0, 0);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
/* Logical Unit Not Ready Format in Progress */
set_sense_data(chip, lun, CUR_ERR, 0x02, 0, 0x04, 0x04,
0, (u16)(ms_card->progress));
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n",
chip->int_reg);
err = -ETIMEDOUT;
- rtsx_trace(chip);
goto finish_send_cmd;
}
retval = rtsx_read_register(chip, REG_SD_STAT1, &stat);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!(stat & SD_DAT0_STATUS)) {
sd_set_err_code(chip, SD_BUSY);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_check_data0_status(chip);
if (retval != STATUS_SUCCESS) {
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return retval;
}
} else {
}
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return retval;
}
if ((ptr[0] & 0xC0) != 0) {
sd_set_err_code(chip, SD_STS_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[stat_idx] & SD_CRC7_ERR) {
if (cmd_idx == WRITE_MULTIPLE_BLOCK) {
sd_set_err_code(chip, SD_CRC_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (rty_cnt < SD_MAX_RETRY_COUNT) {
goto RTY_SEND_CMD;
} else {
sd_set_err_code(chip, SD_CRC_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
(cmd_idx != SEND_IF_COND)) {
if (cmd_idx != STOP_TRANSMISSION) {
if (ptr[1] & 0x80) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
#endif
dev_dbg(rtsx_dev(chip), "ptr[1]: 0x%02x\n",
ptr[1]);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[2] & 0xFF) {
dev_dbg(rtsx_dev(chip), "ptr[2]: 0x%02x\n",
ptr[2]);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[3] & 0x80) {
dev_dbg(rtsx_dev(chip), "ptr[3]: 0x%02x\n",
ptr[3]);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[3] & 0x01)
buf_len = 0;
if (buf_len > 512) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
SD_RSP_TYPE_R1, NULL, 0);
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (buf && buf_len) {
retval = rtsx_read_ppbuf(chip, buf, buf_len);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (buf_len > 512) {
/* This function can't write data more than one page */
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (buf && buf_len) {
retval = rtsx_write_ppbuf(chip, buf, buf_len);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
SD_RSP_TYPE_R1, NULL, 0);
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
for (i = 0; i < 6; i++) {
if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (i == 6) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
else
sd_card->sd_clock = CLK_20;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, REG_SD_CFG1, 0x1C, val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_CFG1, mask, val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_set_sample_push_timing(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = switch_clock(chip, sd_card->sd_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, cmd_idx, addr, cmd_type, NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
SD_RSP_TYPE_R1, rsp, 5);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_card->sd_lock_status);
if (rsp[1] & 0x01) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_card->sd_addr, SD_RSP_TYPE_R1,
rsp, 5);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
return STATUS_SUCCESS;
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
0x4FC0 |
chip->phy_voltage);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = rtsx_write_register(chip, SD_PAD_CTL,
SD_IO_USING_1V8, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
0x4C40 |
chip->phy_voltage);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
SD_IO_USING_1V8,
SD_IO_USING_1V8);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP,
SD_CLK_TOGGLE_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_send_cmd_get_rsp(chip, VOLTAGE_SWITCH, 0, SD_RSP_TYPE_R1,
NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, SD_BUS_STAT, &stat);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (stat & (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS |
SD_DAT1_STATUS | SD_DAT0_STATUS)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_BUS_STAT, 0xFF,
SD_CLK_FORCE_STOP);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_change_bank_voltage(chip, SD_IO_1V8);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_BUS_STAT, 0xFF,
SD_CLK_TOGGLE_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
wait_timeout(10);
retval = rtsx_read_register(chip, SD_BUS_STAT, &stat);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if ((stat & (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS |
rtsx_write_register(chip, SD_BUS_STAT, SD_CLK_TOGGLE_EN |
SD_CLK_FORCE_STOP, 0);
rtsx_write_register(chip, CARD_CLK_EN, 0xFF, 0);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_BUS_STAT,
SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF,
DCM_RESET | DCM_RX);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, DCM_RX);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else {
retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF,
DCM_RESET | DCM_TX);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, DCM_TX);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, CLK_CTL, CHANGE_CLK,
CHANGE_CLK);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SD_VP_CTL, 0x1F,
sample_point);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
PHASE_NOT_RESET, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
PHASE_NOT_RESET, PHASE_NOT_RESET);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CLK_CTL, CHANGE_CLK, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else {
PHASE_CHANGE,
PHASE_CHANGE);
if (retval) {
- rtsx_trace(chip);
return retval;
}
udelay(50);
PHASE_NOT_RESET |
sample_point);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else {
retval = rtsx_write_register(chip, CLK_CTL,
CHANGE_CLK, CHANGE_CLK);
if (retval) {
- rtsx_trace(chip);
return retval;
}
udelay(50);
PHASE_NOT_RESET |
sample_point);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
DCMPS_CHANGE_DONE, DCMPS_CHANGE_DONE);
retval = rtsx_send_cmd(chip, SD_CARD, 100);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto fail;
}
val = *rtsx_get_cmd_data(chip);
if (val & DCMPS_ERROR) {
- rtsx_trace(chip);
goto fail;
}
if ((val & DCMPS_CURRENT_PHASE) != sample_point) {
- rtsx_trace(chip);
goto fail;
}
retval = rtsx_write_register(chip, SD_DCMPS_CTL,
DCMPS_CHANGE, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (ddr_rx) {
retval = rtsx_write_register(chip, SD_VP_CTL,
PHASE_CHANGE, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else {
retval = rtsx_write_register(chip, CLK_CTL,
CHANGE_CLK, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_write_register(chip, SD_CFG1, SD_ASYNC_FIFO_NOT_RST, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr,
SD_RSP_TYPE_R1, NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf, 8, 250);
if (retval != STATUS_SUCCESS) {
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
memcpy(sd_card->raw_scr, buf, 8);
if ((buf[0] & 0x0F) == 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
break;
default:
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else if (func_group == SD_FUNC_GROUP_3) {
break;
default:
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else if (func_group == SD_FUNC_GROUP_4) {
break;
default:
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (func_group == SD_FUNC_GROUP_1) {
if (!(buf[support_offset] & support_mask) ||
((buf[query_switch_offset] & 0x0F) != query_switch)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
/* Check 'Busy Status' */
if ((buf[DATA_STRUCTURE_VER_OFFSET] == 0x01) &&
((buf[check_busy_offset] & switch_busy) == switch_busy)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf, 64, 250);
if (retval != STATUS_SUCCESS) {
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
dev_dbg(rtsx_dev(chip), "Maximum current consumption: %dmA\n",
cc);
if ((cc == 0) || (cc > 800)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_query_switch_result(chip, func_group,
func_to_switch, buf, 64);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
SD_OCP_THD_MASK,
chip->sd_800mA_ocp_thd);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PWR_CTL,
PMOS_STRG_MASK,
PMOS_STRG_800mA);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
for (i = 0; i < 3; i++) {
if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, SD_STAT1, &stat);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (stat & SD_CRC16_ERR) {
dev_dbg(rtsx_dev(chip), "SD CRC16 error when switching mode\n");
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
}
if (!switch_good) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_check_switch_mode(chip, SD_CHECK_MODE, NO_ARGUMENT,
NO_ARGUMENT, bus_width);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_card->sd_switch_fail = SDR104_SUPPORT_MASK |
DDR50_SUPPORT_MASK | SDR50_SUPPORT_MASK;
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_PUSH_POINT_CTL, 0x06,
0x04);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_set_sample_push_timing(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
bus_width);
if (retval != STATUS_SUCCESS) {
if (sd_check_err_code(chip, SD_NO_CARD)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (CHK_SD_DDR50(sd_card)) {
retval = rtsx_write_register(chip, SD_PUSH_POINT_CTL, 0x06, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
for (i = 0; i < 100; i++) {
retval = rtsx_read_register(chip, SD_DATA_STATE, &val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (val & SD_DATA_IDLE) {
retval = sd_change_phase(chip, sample_point, TUNE_RX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
(void)sd_wait_data_idle(chip);
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_change_phase(chip, sample_point, TUNE_RX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr,
SD_RSP_TYPE_R1, NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
(void)sd_wait_data_idle(chip);
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_change_phase(chip, sample_point, TUNE_RX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
(void)sd_wait_data_idle(chip);
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_change_phase(chip, sample_point, TUNE_TX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
SD_RSP_80CLK_TIMEOUT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (sd_check_err_code(chip, SD_RSP_TIMEOUT)) {
rtsx_write_register(chip, SD_CFG3,
SD_RSP_80CLK_TIMEOUT_EN, 0);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_change_phase(chip, sample_point, TUNE_TX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_wait_state_data_ready(chip, 0x08, 1, 1000);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
SD_RSP_80CLK_TIMEOUT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (retval != STATUS_SUCCESS) {
rtsx_clear_sd_error(chip);
rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 0);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (CHK_MMC_DDR52(sd_card)) {
tuning_cmd = mmc_ddr_tuning_rx_cmd;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
for (j = MAX_PHASE; j >= 0; j--) {
if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
final_phase = sd_search_final_phase(chip, phase_map, TUNE_RX);
if (final_phase == 0xFF) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_change_phase(chip, final_phase, TUNE_RX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
SD_RSP_80CLK_TIMEOUT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
sd_set_err_code(chip, SD_NO_CARD);
rtsx_write_register(chip, SD_CFG3,
SD_RSP_80CLK_TIMEOUT_EN, 0);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX);
if (final_phase == 0xFF) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_change_phase(chip, final_phase, TUNE_TX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (CHK_MMC_DDR52(sd_card)) {
tuning_cmd = sd_ddr_tuning_tx_cmd;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
sd_set_err_code(chip, SD_NO_CARD);
rtsx_write_register(chip, SD_CFG3,
SD_RSP_80CLK_TIMEOUT_EN, 0);
- rtsx_trace(chip);
return STATUS_FAIL;
}
final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX);
if (final_phase == 0xFF) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_change_phase(chip, final_phase, TUNE_TX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_tuning_tx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_tuning_rx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) {
retval = sd_ddr_pre_tuning_tx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = sd_change_phase(chip, (u8)chip->sd_ddr_tx_phase,
TUNE_TX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = sd_tuning_rx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) {
retval = sd_tuning_tx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) {
retval = sd_ddr_pre_tuning_tx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = sd_change_phase(chip, (u8)chip->mmc_ddr_tx_phase,
TUNE_TX);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = sd_tuning_rx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) {
retval = sd_tuning_tx(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = select_card(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = switch_clock(chip, sd_card->sd_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = sd_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_CFG1, 0xFF, 0x40);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_STOP, SD_STOP | SD_CLR_ERR,
SD_STOP | SD_CLR_ERR);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = select_card(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
XD_D3_PD | SD_D7_PD | SD_CLK_PD |
SD_D5_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF,
SD_D6_PD | SD_D0_PD | SD_D1_PD |
XD_D5_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF,
SD_D4_PD | XD_CE_PD | XD_CLE_PD |
XD_CD_PU);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF,
XD_RDY_PD | SD_D3_PD | SD_D2_PD |
XD_ALE_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF,
MS_INS_PU | SD_WP_PD | SD_CD_PU |
SD_CMD_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF,
MS_D5_PD | MS_D4_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else if (CHECK_PID(chip, 0x5288)) {
retval = rtsx_write_register(chip, CARD_PULL_CTL1,
0xFF, 0x55);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL2,
0xFF, 0x55);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL3,
0xFF, 0x4B);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL4,
0xFF, 0x69);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = rtsx_send_cmd(chip, SD_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_power_off_card3v3(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = enable_card_clock(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->asic_code) {
retval = sd_pull_ctl_enable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = rtsx_write_register(chip, FPGA_PULL_CTL,
FPGA_SD_PULL_CTL_BIT | 0x20, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
if (!chip->ft2_fast_mode) {
retval = card_power_on(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) {
dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n",
chip->ocp_stat);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN,
SD_OUTPUT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_CFG3, 0x01, 0x01);
if (retval) {
- rtsx_trace(chip);
return retval;
}
wait_timeout(5);
retval = rtsx_write_register(chip, REG_SD_CFG3, 0x01, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
bus_width, NULL, 0, 100);
if (retval != STATUS_SUCCESS) {
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr,
SD_RSP_TYPE_R1, NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
SD_RSP_TYPE_R1, NULL, 0);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SD30_DRIVE_SEL, 0x07,
chip->sd30_drive_sel_1v8);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_H, 0xFF,
0x02);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_L, 0xFF,
0x00);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
return STATUS_SUCCESS;
status_fail:
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, BUSTEST_W, 0, SD_RSP_TYPE_R1, NULL,
0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return SWITCH_FAIL;
}
retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0x02);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return SWITCH_ERR;
}
if (retval != STATUS_SUCCESS) {
rtsx_clear_sd_error(chip);
rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0);
- rtsx_trace(chip);
return SWITCH_ERR;
}
retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return SWITCH_ERR;
}
retval = rtsx_send_cmd(chip, SD_CARD, 100);
if (retval < 0) {
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
return SWITCH_ERR;
}
}
}
- rtsx_trace(chip);
return SWITCH_FAIL;
}
sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
SD_RSP_TYPE_R1, NULL, 0);
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[0] & SD_TRANSFER_ERR) {
sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
SD_RSP_TYPE_R1, NULL, 0);
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_choose_proper_clock(chip);
retval = switch_clock(chip, sd_card->sd_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
CLR_MMC_8BIT(sd_card);
CLR_MMC_4BIT(sd_card);
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
switch_fail:
retval = sd_prepare_reset(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return retval;
}
retval = sd_send_cmd_get_rsp(chip, GO_IDLE_STATE, 0, SD_RSP_TYPE_R0,
NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
do {
if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_clr_err_code(chip);
goto RTY_MMC_RST;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
sd_clr_err_code(chip);
goto RTY_MMC_RST;
} else {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
} while (!(rsp[1] & 0x80) && (i < 255));
if (i == 255) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, ALL_SEND_CID, 0, SD_RSP_TYPE_R2,
NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, SET_RELATIVE_ADDR, sd_card->sd_addr,
SD_RSP_TYPE_R6, rsp, 5);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_check_csd(chip, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_select_card(chip, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, SD_RSP_TYPE_R1,
NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
MMC_UNLOCK_ENTRY:
retval = sd_update_lock_status(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
retval = sd_init_power(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_card->mmc_dont_switch_bus = 1;
- rtsx_trace(chip);
goto switch_fail;
}
}
if (CHK_MMC_SECTOR_MODE(sd_card) && (sd_card->capacity == 0)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (switch_ddr && CHK_MMC_DDR52(sd_card)) {
retval = sd_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
retval = sd_init_power(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
switch_ddr = false;
- rtsx_trace(chip);
goto switch_fail;
}
if (retval != STATUS_SUCCESS) {
retval = sd_init_power(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
switch_ddr = false;
- rtsx_trace(chip);
goto switch_fail;
}
}
retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_H, 0xFF,
0x02);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_L, 0xFF,
0x00);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = enable_card_clock(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->asic_code) {
retval = sd_pull_ctl_enable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
FPGA_SD_PULL_CTL_BIT |
0x20, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = card_share_mode(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
chip->sd_io = 1;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_init_power(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = reset_mmc(chip);
if (retval != STATUS_SUCCESS) {
if (sd_check_err_code(chip, SD_NO_CARD)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = reset_sd(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = reset_sd(chip);
if (retval != STATUS_SUCCESS) {
if (sd_check_err_code(chip, SD_NO_CARD)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->sd_io) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = reset_mmc(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_L, 0xFF, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_H, 0xFF, 2);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = enable_card_clock(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_init_power(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = reset_mmc(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_L, 0xFF, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_H, 0xFF, 2);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = sd_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
for (i = 0; i < WAIT_DATA_READY_RTY_CNT; i++) {
if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_card->sd_addr, SD_RSP_TYPE_R1,
NULL, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
sd_set_err_code(chip, SD_TO_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
chip->card_fail |= SD_CARD;
chip->capacity[chip->card2lun[SD_CARD]] = 0;
chip->rw_need_retry = 1;
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_IO_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
if (retval != STATUS_SUCCESS) {
chip->rw_need_retry = 1;
sd_set_err_code(chip, SD_STS_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
retval = rtsx_write_register(chip, RBCTL, RB_FLUSH, RB_FLUSH);
if (retval != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_IO_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
chip->rw_need_retry = 1;
sd_set_err_code(chip, SD_TO_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
if (retval != STATUS_SUCCESS) {
chip->rw_need_retry = 1;
sd_set_err_code(chip, SD_TO_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
NULL, 0);
if (retval != STATUS_SUCCESS) {
chip->rw_need_retry = 1;
- rtsx_trace(chip);
goto RW_FAIL;
}
chip->rw_need_retry = 0;
dev_dbg(rtsx_dev(chip), "No card exist, exit %s\n",
__func__);
- rtsx_trace(chip);
return STATUS_FAIL;
}
SD_RSP_TYPE_R1b, NULL, 0);
if (retval != STATUS_SUCCESS) {
sd_set_err_code(chip, SD_STS_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
if (stat & (SD_CRC7_ERR | SD_CRC16_ERR | SD_CRC_WRITE_ERR)) {
dev_dbg(rtsx_dev(chip), "SD CRC error, tune clock!\n");
sd_set_err_code(chip, SD_CRC_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
if (err == STATUS_TIMEDOUT) {
sd_set_err_code(chip, SD_TO_ERR);
- rtsx_trace(chip);
goto RW_FAIL;
}
- rtsx_trace(chip);
return err;
}
if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) {
chip->rw_need_retry = 0;
dev_dbg(rtsx_dev(chip), "No card exist, exit %s\n", __func__);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (rsp_type & SD_WAIT_BUSY_END) {
retval = sd_check_data0_status(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return retval;
}
} else {
sd_set_err_code(chip, SD_TO_ERR);
}
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
if ((ptr[0] & 0xC0) != 0) {
sd_set_err_code(chip, SD_STS_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[stat_idx] & SD_CRC7_ERR) {
if (cmd_idx == WRITE_MULTIPLE_BLOCK) {
sd_set_err_code(chip, SD_CRC_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (rty_cnt < SD_MAX_RETRY_COUNT) {
goto RTY_SEND_CMD;
} else {
sd_set_err_code(chip, SD_CRC_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
(cmd_idx == SEND_STATUS) || (cmd_idx == STOP_TRANSMISSION)) {
if ((cmd_idx != STOP_TRANSMISSION) && !special_check) {
if (ptr[1] & 0x80) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
#else
if (ptr[1] & 0x7F) {
#endif
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (ptr[2] & 0xF8) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (cmd_idx == SELECT_CARD) {
if (rsp_type == SD_RSP_TYPE_R2) {
if ((ptr[3] & 0x1E) != 0x04) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = rtsx_send_cmd(chip, SD_CARD, 100);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!(CHK_BIT(chip->lun_mc, lun))) {
SET_BIT(chip->lun_mc, lun);
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
(srb->cmnd[6] != 0x61) || (srb->cmnd[7] != 0x72) ||
(srb->cmnd[8] != 0x64)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
default:
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!sd_card->sd_pass_thru_en) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (sd_card->pre_cmd_err) {
sd_card->pre_cmd_err = 0;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = get_rsp_type(srb, &rsp_type, &rsp_len);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
sd_card->last_rsp_type = rsp_type;
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
SD_BUS_WIDTH_8);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
SD_BUS_WIDTH_4);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
#else
retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
#endif
if (standby) {
retval = sd_select_card(chip, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_cmd_failed;
}
}
SD_RSP_TYPE_R1, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_cmd_failed;
}
}
retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type,
sd_card->rsp, rsp_len, false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_cmd_failed;
}
if (standby) {
retval = sd_select_card(chip, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_cmd_failed;
}
}
#ifdef SUPPORT_SD_LOCK
retval = sd_update_lock_status(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_cmd_failed;
}
#endif
if (!(chip->card_ready & SD_CARD))
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!sd_card->sd_pass_thru_en) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (sd_card->pre_cmd_err) {
sd_card->pre_cmd_err = 0;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = get_rsp_type(srb, &rsp_type, &rsp_len);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
sd_card->last_rsp_type = rsp_type;
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
SD_RSP_TYPE_R1, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
}
if (standby) {
retval = sd_select_card(chip, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
}
SD_RSP_TYPE_R1, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
}
buf = kmalloc(data_len, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
read_err = true;
kfree(buf);
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
if (retval < 0) {
read_err = true;
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
} else {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
retval = ext_sd_get_rsp(chip, rsp_len, sd_card->rsp, rsp_type);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
if (standby) {
retval = sd_select_card(chip, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
}
SD_RSP_TYPE_R1b, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
}
SD_RSP_TYPE_R1, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
retval = rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
}
break;
}
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_read_cmd_failed;
}
if (!(chip->card_ready & SD_CARD))
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!sd_card->sd_pass_thru_en) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (sd_card->pre_cmd_err) {
sd_card->pre_cmd_err = 0;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = get_rsp_type(srb, &rsp_type, &rsp_len);
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
sd_card->last_rsp_type = rsp_type;
retval = sd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
SD_BUS_WIDTH_8);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
SD_BUS_WIDTH_4);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
}
#else
retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
#endif
SD_RSP_TYPE_R1, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
if (standby) {
retval = sd_select_card(chip, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
SD_RSP_TYPE_R1, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type,
sd_card->rsp, rsp_len, false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
buf = kmalloc(data_len, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return TRANSPORT_ERROR;
}
retval = rtsx_send_cmd(chip, 0, 250);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
retval = rtsx_send_cmd(chip, 0, 250);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
} else {
retval = rtsx_send_cmd(chip, 0, 250);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
DMA_TO_DEVICE, 10000);
} else {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
if (retval < 0) {
write_err = true;
rtsx_clear_sd_error(chip);
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
if (standby) {
retval = sd_select_card(chip, 1);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
SD_RSP_TYPE_R1b, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
SD_RSP_TYPE_R1, NULL, 0,
false);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
break;
}
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
retval = reset_sd(chip);
if (retval != STATUS_SUCCESS) {
sd_card->sd_lock_status &= ~(SD_UNLOCK_POW_ON | SD_SDR_RST);
- rtsx_trace(chip);
goto sd_execute_write_cmd_failed;
}
}
if (lock_cmd_fail) {
scsi_set_resid(srb, 0);
set_sense_type(chip, lun, SENSE_TYPE_NO_SENSE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
#endif /* SUPPORT_SD_LOCK */
if (!(chip->card_ready & SD_CARD))
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (!sd_card->sd_pass_thru_en) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (sd_card->pre_cmd_err) {
sd_card->pre_cmd_err = 0;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (sd_card->last_rsp_type == SD_RSP_TYPE_R0) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
} else if (sd_card->last_rsp_type == SD_RSP_TYPE_R2) {
count = (data_len < 17) ? data_len : 17;
if (!sd_card->sd_pass_thru_en) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
if (sd_card->pre_cmd_err) {
sd_card->pre_cmd_err = 0;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
(srb->cmnd[6] != 0x61) || (srb->cmnd[7] != 0x72) ||
(srb->cmnd[8] != 0x64)) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
#endif
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
sd_card->pre_cmd_err = 1;
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
#ifdef SUPPORT_SD_LOCK
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
sd_card->pre_cmd_err = 1;
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
break;
default:
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD);
- rtsx_trace(chip);
return TRANSPORT_FAILED;
}
retval = disable_card_clock(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!chip->ft2_fast_mode) {
retval = card_power_off(chip, SD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->asic_code) {
retval = sd_pull_ctl_disable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
FPGA_SD_PULL_CTL_BIT | 0x20,
FPGA_SD_PULL_CTL_BIT);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = sd_power_off_card3v3(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
CS_POLARITY_LOW | DTO_MSB_FIRST
| SPI_MASTER | SPI_MODE0 | SPI_AUTO);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SPI_TCTL, EDO_TIMING_MASK,
SAMPLE_DELAY_HALF);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SPI_CLK_DIVIDER1, 0xFF,
(u8)(spi->clk_div >> 8));
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SPI_CLK_DIVIDER0, 0xFF,
(u8)(spi->clk_div));
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = switch_clock(chip, spi->spi_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = select_card(chip, SPI_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_CLK_EN, SPI_CLK_EN,
SPI_CLK_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_OE, SPI_OUTPUT_EN,
SPI_OUTPUT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = spi_init(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval < 0) {
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_BUSY_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval < 0) {
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval < 0) {
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval < 0) {
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, SPI_CLK_DIVIDER1, 0xFF, 0x00);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SPI_CLK_DIVIDER0, 0xFF, 0x27);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = switch_clock(chip, clk);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = select_card(chip, SPI_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_CLK_EN, SPI_CLK_EN,
SPI_CLK_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_OE, SPI_OUTPUT_EN,
SPI_OUTPUT_EN);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SPI_CONTROL, 0xFF,
CS_POLARITY_HIGH | SPI_EEPROM_AUTO);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, SPI_TCTL, EDO_TIMING_MASK,
SAMPLE_DELAY_HALF);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_send_cmd(chip, 0, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_init_eeprom(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_eeprom_program_enable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = spi_init_eeprom(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_eeprom_program_enable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = spi_init_eeprom(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
wait_timeout(5);
retval = rtsx_read_register(chip, SPI_DATA, &data);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = spi_init_eeprom(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_eeprom_program_enable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
if (retval) {
- rtsx_trace(chip);
return retval;
}
len = ((u16)(srb->cmnd[7]) << 8) | srb->cmnd[8];
if (len > 512) {
spi_set_err_code(chip, SPI_INVALID_COMMAND);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval < 0) {
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (len) {
buf = kmalloc(len, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
if (retval != STATUS_SUCCESS) {
spi_set_err_code(chip, SPI_READ_ERR);
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
kfree(buf);
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (program_mode == BYTE_PROGRAM) {
buf = kmalloc(4, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
retval = sf_enable_write(chip, SPI_WREN);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
kfree(buf);
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_polling_status(chip, 100);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_enable_write(chip, SPI_WREN);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
buf = kmalloc(4, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
kfree(buf);
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_polling_status(chip, 100);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_disable_write(chip, SPI_WRDI);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_polling_status(chip, 100);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else if (program_mode == PAGE_PROGRAM) {
buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL);
if (!buf) {
- rtsx_trace(chip);
return STATUS_NOMEM;
}
retval = sf_enable_write(chip, SPI_WREN);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
kfree(buf);
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_polling_status(chip, 100);
if (retval != STATUS_SUCCESS) {
kfree(buf);
- rtsx_trace(chip);
return STATUS_FAIL;
}
kfree(buf);
} else {
spi_set_err_code(chip, SPI_INVALID_COMMAND);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (erase_mode == PAGE_ERASE) {
retval = sf_enable_write(chip, SPI_WREN);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_erase(chip, ins, 1, addr);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else if (erase_mode == CHIP_ERASE) {
retval = sf_enable_write(chip, SPI_WREN);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_erase(chip, ins, 0, 0);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
spi_set_err_code(chip, SPI_INVALID_COMMAND);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = spi_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = sf_enable_write(chip, ewsr);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
rtsx_clear_spi_error(chip);
spi_set_err_code(chip, SPI_HW_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
+++ /dev/null
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/kernel.h>
-#include <linux/string.h>
-
-#include "rtsx.h"
-
-#ifdef _MSG_TRACE
-
-void _rtsx_trace(struct rtsx_chip *chip, const char *file, const char *func,
- int line)
-{
- struct trace_msg_t *msg = &chip->trace_msg[chip->msg_idx];
-
- file = kbasename(file);
- dev_dbg(rtsx_dev(chip), "[%s][%s]:[%d]\n", file, func, line);
-
- strncpy(msg->file, file, MSG_FILE_LEN - 1);
- strncpy(msg->func, func, MSG_FUNC_LEN - 1);
- msg->line = (u16)line;
- get_current_time(msg->timeval_buf, TIME_VAL_LEN);
- msg->valid = 1;
-
- chip->msg_idx++;
- if (chip->msg_idx >= TRACE_ITEM_CNT)
- chip->msg_idx = 0;
-}
-#endif
+++ /dev/null
-/* Driver for Realtek PCI-Express card reader
- * Header file
- *
- * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author:
- * Wei WANG (wei_wang@realsil.com.cn)
- * Micky Ching (micky_ching@realsil.com.cn)
- */
-
-#ifndef __REALTEK_RTSX_TRACE_H
-#define __REALTEK_RTSX_TRACE_H
-
-struct rtsx_chip;
-
-#ifdef _MSG_TRACE
-void _rtsx_trace(struct rtsx_chip *chip, const char *file, const char *func,
- int line);
-#define rtsx_trace(chip) \
- _rtsx_trace(chip, __FILE__, __func__, __LINE__)
-#else
-static inline void rtsx_trace(struct rtsx_chip *chip)
-{
-}
-#endif
-
-#endif /* __REALTEK_RTSX_TRACE_H */
retval = switch_clock(chip, xd_card->xd_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = select_card(chip, XD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = switch_clock(chip, xd_card->xd_clock);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, XD_CARD, 20);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, XD_CARD, 500);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
int retval, i;
if (!buf || (buf_len < 0)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, 0, 250);
if (retval < 0) {
rtsx_clear_xd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
u8 reg;
if (!buf || (buf_len < 10)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, XD_CARD, 250);
if (retval == -ETIMEDOUT) {
rtsx_clear_xd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, XD_PAGE_STATUS, ®);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (reg != XD_GPG) {
rtsx_clear_xd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_read_register(chip, XD_CTL, ®);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!(reg & XD_ECC1_ERROR) || !(reg & XD_ECC1_UNCORRECTABLE)) {
retval = xd_read_data_from_ppb(chip, 0, buf, buf_len);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (reg & XD_ECC1_ERROR) {
retval = rtsx_read_register(chip, XD_ECC_BIT1,
&ecc_bit);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_read_register(chip, XD_ECC_BYTE1,
&ecc_byte);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = xd_read_data_from_ppb(chip, 256, buf, buf_len);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (reg & XD_ECC2_ERROR) {
retval = rtsx_read_register(chip, XD_ECC_BIT2,
&ecc_bit);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_read_register(chip, XD_ECC_BYTE2,
&ecc_byte);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
} else {
rtsx_clear_xd_error(chip);
- rtsx_trace(chip);
return STATUS_FAIL;
}
XD_D1_PD |
XD_D0_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF,
XD_D5_PD |
XD_D4_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF,
XD_CLE_PD |
XD_CD_PU);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF,
XD_RE_PD |
XD_ALE_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF,
SD_CD_PU |
SD_CMD_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF,
MS_D5_PD | MS_D4_PD);
if (retval) {
- rtsx_trace(chip);
return retval;
}
} else if (CHECK_PID(chip, 0x5288)) {
retval = rtsx_write_register(chip, CARD_PULL_CTL1,
0xFF, 0x55);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL2,
0xFF, 0x55);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL3,
0xFF, 0x4B);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_write_register(chip, CARD_PULL_CTL4,
0xFF, 0x69);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = select_card(chip, XD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, XD_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!chip->ft2_fast_mode) {
retval = card_power_off(chip, XD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, XD_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = card_power_on(chip, XD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) {
dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n",
chip->ocp_stat);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = rtsx_send_cmd(chip, XD_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = xd_set_init_para(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, XD_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = xd_read_id(chip, READ_ID, id_buf, 4);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
for (j = 0; j < 10; j++) {
retval = xd_read_id(chip, READ_ID, id_buf, 4);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
xd_card->addr_cycle = 0;
xd_card->capacity = 0;
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = xd_read_id(chip, READ_xD_ID, id_buf, 4);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
dev_dbg(rtsx_dev(chip), "READ_xD_ID: 0x%x 0x%x 0x%x 0x%x\n",
id_buf[0], id_buf[1], id_buf[2], id_buf[3]);
if (id_buf[2] != XD_ID_CODE) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
u32 page_addr;
if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = xd_read_cis(chip, page_addr, buf, 10);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
dev_dbg(rtsx_dev(chip), "CIS block: 0x%x\n", xd_card->cis_block);
if (xd_card->cis_block == 0xFFFF) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
xd_card->zone_cnt);
if (xd_card->zone_cnt < 1) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
xd_card->zone = vmalloc(size);
if (!xd_card->zone) {
- rtsx_trace(chip);
return STATUS_ERROR;
}
retval = enable_card_clock(chip, XD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = reset_xd(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = xd_init_l2p_tbl(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
dev_dbg(rtsx_dev(chip), "mark block 0x%x as bad block\n", phy_blk);
if (phy_blk == BLK_NOT_FOUND) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
xd_set_err_code(chip, XD_PRG_ERROR);
else
xd_set_err_code(chip, XD_TO_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
dev_dbg(rtsx_dev(chip), "Init block 0x%x\n", phy_blk);
if (start_page > end_page) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (phy_blk == BLK_NOT_FOUND) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
xd_set_err_code(chip, XD_TO_ERROR);
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
old_blk, new_blk);
if (start_page > end_page) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND)) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_DATA_SOURCE, 0x01,
PINGPONG_BUFFER);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
rtsx_clear_xd_error(chip);
xd_set_err_code(chip, XD_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (detect_card_cd(chip,
XD_CARD) != STATUS_SUCCESS) {
xd_set_err_code(chip, XD_NO_CARD);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
} else {
xd_set_err_code(chip, XD_TO_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
} else {
xd_set_err_code(chip, XD_TO_ERROR);
}
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_send_cmd(chip, XD_CARD, 100);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (((ptr[0] & READY_FLAG) == READY_STATE) && (ptr[1] & XD_RDY))
return STATUS_SUCCESS;
- rtsx_trace(chip);
return STATUS_FAIL;
}
int i, retval;
if (phy_blk == BLK_NOT_FOUND) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (reg & PROGRAM_ERROR) {
xd_mark_bad_block(chip, phy_blk);
xd_set_err_code(chip, XD_PRG_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
xd_set_err_code(chip, XD_ERASE_FAIL);
retval = xd_reset_cmd(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
continue;
if (*ptr & PROGRAM_ERROR) {
xd_mark_bad_block(chip, phy_blk);
xd_set_err_code(chip, XD_PRG_ERROR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
xd_mark_bad_block(chip, phy_blk);
xd_set_err_code(chip, XD_ERASE_FAIL);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (!zone->l2p_table) {
zone->l2p_table = vmalloc(2000);
if (!zone->l2p_table) {
- rtsx_trace(chip);
goto build_fail;
}
}
if (!zone->free_table) {
zone->free_table = vmalloc(XD_FREE_TABLE_CNT * 2);
if (!zone->free_table) {
- rtsx_trace(chip);
goto build_fail;
}
}
retval = rtsx_send_cmd(chip, XD_CARD, 200);
if (retval < 0) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
xd_set_err_code(chip, XD_TO_ERROR);
goto status_fail;
} else {
- rtsx_trace(chip);
goto fail;
}
}
fail:
retval = rtsx_read_register(chip, XD_PAGE_STATUS, ®_val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
retval = rtsx_read_register(chip, XD_CTL, ®_val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
status_fail:
- rtsx_trace(chip);
return STATUS_FAIL;
}
dev_dbg(rtsx_dev(chip), "log_blk = 0x%x\n", log_blk);
if (page_off > xd_card->page_off) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = xd_erase_block(chip, new_blk);
if (retval == STATUS_SUCCESS)
xd_set_unused_block(chip, new_blk);
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
xd_set_unused_block(chip, new_blk);
}
XD_CLR_BAD_NEWBLK(xd_card);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (page_off) {
retval = xd_copy_page(chip, old_blk, new_blk, 0, page_off);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
xd_set_err_code(chip, XD_TO_ERROR);
goto status_fail;
} else {
- rtsx_trace(chip);
goto fail;
}
}
fail:
retval = rtsx_read_register(chip, XD_DAT, ®_val);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (reg_val & PROGRAM_ERROR) {
}
status_fail:
- rtsx_trace(chip);
return STATUS_FAIL;
}
dev_dbg(rtsx_dev(chip), "%s\n", __func__);
retval = xd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
delay_write->logblock,
delay_write->pageoff);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
retval = xd_switch_clock(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
chip->card_fail |= XD_CARD;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
chip->card_fail |= XD_CARD;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
(new_blk == BLK_NOT_FOUND)) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#ifdef XD_DELAY_WRITE
if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
if (old_blk == BLK_NOT_FOUND) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
chip->card_fail |= XD_CARD;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
if (retval != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
chip->card_fail |= XD_CARD;
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (new_blk == BLK_NOT_FOUND) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
}
if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
chip->card_fail |= XD_CARD;
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
set_sense_type(chip, lun,
SENSE_TYPE_MEDIA_NOT_PRESENT);
- rtsx_trace(chip);
return STATUS_FAIL;
}
set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR);
- rtsx_trace(chip);
return STATUS_FAIL;
}
#endif
retval = disable_card_clock(chip, XD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
retval = rtsx_write_register(chip, CARD_OE, XD_OUTPUT_EN, 0);
if (retval) {
- rtsx_trace(chip);
return retval;
}
if (!chip->ft2_fast_mode) {
retval = card_power_off(chip, XD_CARD);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
if (chip->asic_code) {
retval = xd_pull_ctl_disable(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}
} else {
retval = rtsx_write_register(chip, FPGA_PULL_CTL, 0xFF, 0xDF);
if (retval) {
- rtsx_trace(chip);
return retval;
}
}
retval = xd_power_off_card3v3(chip);
if (retval != STATUS_SUCCESS) {
- rtsx_trace(chip);
return STATUS_FAIL;
}