diff options
Diffstat (limited to 'drivers/staging/rts5208/xd.c')
-rw-r--r-- | drivers/staging/rts5208/xd.c | 607 |
1 files changed, 429 insertions, 178 deletions
diff --git a/drivers/staging/rts5208/xd.c b/drivers/staging/rts5208/xd.c index 0d029fe92b40..8fd108e50509 100644 --- a/drivers/staging/rts5208/xd.c +++ b/drivers/staging/rts5208/xd.c @@ -60,8 +60,10 @@ static int xd_set_init_para(struct rtsx_chip *chip) xd_card->xd_clock = CLK_50; retval = switch_clock(chip, xd_card->xd_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -72,12 +74,16 @@ static int xd_switch_clock(struct rtsx_chip *chip) int retval; retval = select_card(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = switch_clock(chip, xd_card->xd_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -99,8 +105,10 @@ static int xd_read_id(struct rtsx_chip *chip, u8 id_cmd, u8 *id_buf, u8 buf_len) rtsx_add_cmd(chip, READ_REG_CMD, (u16)(XD_ADDRESS1 + i), 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 20); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip) + 1; if (id_buf && buf_len) { @@ -167,8 +175,10 @@ static int xd_read_redundant(struct rtsx_chip *chip, u32 page_addr, rtsx_add_cmd(chip, READ_REG_CMD, XD_PARITY, 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 500); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (buf && buf_len) { u8 *ptr = rtsx_get_cmd_data(chip) + 1; @@ -186,8 +196,10 @@ static int xd_read_data_from_ppb(struct rtsx_chip *chip, int offset, { int retval, i; - if (!buf || (buf_len < 0)) - TRACE_RET(chip, STATUS_FAIL); + if (!buf || (buf_len < 0)) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -198,7 +210,8 @@ static int xd_read_data_from_ppb(struct rtsx_chip *chip, int offset, retval = rtsx_send_cmd(chip, 0, 250); if (retval < 0) { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } memcpy(buf, rtsx_get_cmd_data(chip), buf_len); @@ -212,8 +225,10 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, int retval; u8 reg; - if (!buf || (buf_len < 10)) - TRACE_RET(chip, STATUS_FAIL); + if (!buf || (buf_len < 10)) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -233,25 +248,47 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, retval = rtsx_send_cmd(chip, XD_CARD, 250); if (retval == -ETIMEDOUT) { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } - RTSX_READ_REG(chip, XD_PAGE_STATUS, ®); + retval = rtsx_read_register(chip, XD_PAGE_STATUS, ®); + if (retval) { + rtsx_trace(chip); + return retval; + } if (reg != XD_GPG) { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } - RTSX_READ_REG(chip, XD_CTL, ®); + 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) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (reg & XD_ECC1_ERROR) { u8 ecc_bit, ecc_byte; - RTSX_READ_REG(chip, XD_ECC_BIT1, &ecc_bit); - RTSX_READ_REG(chip, XD_ECC_BYTE1, &ecc_byte); + 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; + } dev_dbg(rtsx_dev(chip), "ECC_BIT1 = 0x%x, ECC_BYTE1 = 0x%x\n", ecc_bit, ecc_byte); @@ -267,13 +304,25 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, rtsx_clear_xd_error(chip); retval = xd_read_data_from_ppb(chip, 256, buf, buf_len); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (reg & XD_ECC2_ERROR) { u8 ecc_bit, ecc_byte; - RTSX_READ_REG(chip, XD_ECC_BIT2, &ecc_bit); - RTSX_READ_REG(chip, XD_ECC_BYTE2, &ecc_byte); + 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; + } dev_dbg(rtsx_dev(chip), "ECC_BIT2 = 0x%x, ECC_BYTE2 = 0x%x\n", ecc_bit, ecc_byte); @@ -287,7 +336,8 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, } } else { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -363,24 +413,71 @@ static void xd_fill_pull_ctl_enable(struct rtsx_chip *chip) static int xd_pull_ctl_disable(struct rtsx_chip *chip) { + int retval; + if (CHECK_PID(chip, 0x5208)) { - RTSX_WRITE_REG(chip, CARD_PULL_CTL1, 0xFF, - XD_D3_PD | XD_D2_PD | XD_D1_PD | XD_D0_PD); - RTSX_WRITE_REG(chip, CARD_PULL_CTL2, 0xFF, - XD_D7_PD | XD_D6_PD | XD_D5_PD | XD_D4_PD); - RTSX_WRITE_REG(chip, CARD_PULL_CTL3, 0xFF, - XD_WP_PD | XD_CE_PD | XD_CLE_PD | XD_CD_PU); - RTSX_WRITE_REG(chip, CARD_PULL_CTL4, 0xFF, - XD_RDY_PD | XD_WE_PD | XD_RE_PD | XD_ALE_PD); - RTSX_WRITE_REG(chip, CARD_PULL_CTL5, 0xFF, - MS_INS_PU | SD_WP_PD | SD_CD_PU | SD_CMD_PD); - RTSX_WRITE_REG(chip, CARD_PULL_CTL6, 0xFF, MS_D5_PD | MS_D4_PD); + retval = rtsx_write_register(chip, CARD_PULL_CTL1, 0xFF, + XD_D3_PD | XD_D2_PD | XD_D1_PD | XD_D0_PD); + if (retval) { + rtsx_trace(chip); + return retval; + } + retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF, + XD_D7_PD | XD_D6_PD | XD_D5_PD | XD_D4_PD); + if (retval) { + rtsx_trace(chip); + return retval; + } + retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF, + XD_WP_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 | XD_WE_PD | XD_RE_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)) { if (CHECK_BARO_PKG(chip, QFN)) { - RTSX_WRITE_REG(chip, CARD_PULL_CTL1, 0xFF, 0x55); - RTSX_WRITE_REG(chip, CARD_PULL_CTL2, 0xFF, 0x55); - RTSX_WRITE_REG(chip, CARD_PULL_CTL3, 0xFF, 0x4B); - RTSX_WRITE_REG(chip, CARD_PULL_CTL4, 0xFF, 0x69); + 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; + } } } @@ -394,8 +491,10 @@ static int reset_xd(struct rtsx_chip *chip) u8 *ptr, id_buf[4], redunt[11]; retval = select_card(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -418,13 +517,17 @@ static int reset_xd(struct rtsx_chip *chip) rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_OE, XD_OUTPUT_EN, 0); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + 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) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(250); @@ -439,19 +542,24 @@ static int reset_xd(struct rtsx_chip *chip) } retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = card_power_on(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } #ifdef SUPPORT_OCP wait_timeout(50); 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); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif } @@ -472,15 +580,19 @@ static int reset_xd(struct rtsx_chip *chip) rtsx_add_cmd(chip, WRITE_REG_CMD, XD_CTL, XD_CE_DISEN, XD_CE_DISEN); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!chip->ft2_fast_mode) wait_timeout(200); retval = xd_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* Read ID to check if the timing setting is right */ for (i = 0; i < 4; i++) { @@ -502,8 +614,10 @@ static int reset_xd(struct rtsx_chip *chip) rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip) + 1; @@ -515,8 +629,10 @@ static int reset_xd(struct rtsx_chip *chip) continue; retval = xd_read_id(chip, READ_ID, id_buf, 4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "READ_ID: 0x%x 0x%x 0x%x 0x%x\n", id_buf[0], id_buf[1], id_buf[2], id_buf[3]); @@ -596,8 +712,10 @@ static int reset_xd(struct rtsx_chip *chip) /* Confirm timing setting */ for (j = 0; j < 10; j++) { retval = xd_read_id(chip, READ_ID, id_buf, 4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (id_buf[1] != xd_card->device_code) break; @@ -613,23 +731,30 @@ static int reset_xd(struct rtsx_chip *chip) xd_card->addr_cycle = 0; xd_card->capacity = 0; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_read_id(chip, READ_xD_ID, id_buf, 4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + 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) - TRACE_RET(chip, STATUS_FAIL); + if (id_buf[2] != XD_ID_CODE) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* Search CIS block */ for (i = 0; i < 24; i++) { u32 page_addr; - if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_addr = (u32)i << xd_card->block_shift; @@ -667,8 +792,10 @@ static int reset_xd(struct rtsx_chip *chip) page_addr += j; retval = xd_read_cis(chip, page_addr, buf, 10); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if ((buf[0] == 0x01) && (buf[1] == 0x03) && (buf[2] == 0xD9) @@ -684,8 +811,10 @@ static int reset_xd(struct rtsx_chip *chip) } dev_dbg(rtsx_dev(chip), "CIS block: 0x%x\n", xd_card->cis_block); - if (xd_card->cis_block == 0xFFFF) - TRACE_RET(chip, STATUS_FAIL); + if (xd_card->cis_block == 0xFFFF) { + rtsx_trace(chip); + return STATUS_FAIL; + } chip->capacity[chip->card2lun[XD_CARD]] = xd_card->capacity; @@ -739,15 +868,19 @@ static int xd_init_l2p_tbl(struct rtsx_chip *chip) dev_dbg(rtsx_dev(chip), "xd_init_l2p_tbl: zone_cnt = %d\n", xd_card->zone_cnt); - if (xd_card->zone_cnt < 1) - TRACE_RET(chip, STATUS_FAIL); + if (xd_card->zone_cnt < 1) { + rtsx_trace(chip); + return STATUS_FAIL; + } size = xd_card->zone_cnt * sizeof(struct zone_entry); dev_dbg(rtsx_dev(chip), "Buffer size for l2p table is %d\n", size); xd_card->zone = vmalloc(size); - if (!xd_card->zone) - TRACE_RET(chip, STATUS_ERROR); + if (!xd_card->zone) { + rtsx_trace(chip); + return STATUS_ERROR; + } for (i = 0; i < xd_card->zone_cnt; i++) { xd_card->zone[i].build_flag = 0; @@ -927,16 +1060,22 @@ int reset_xd_card(struct rtsx_chip *chip) xd_card->delay_write.delay_write_flag = 0; retval = enable_card_clock(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = reset_xd(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = xd_init_l2p_tbl(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -950,8 +1089,10 @@ static int xd_mark_bad_block(struct rtsx_chip *chip, u32 phy_blk) dev_dbg(rtsx_dev(chip), "mark block 0x%x as bad block\n", phy_blk); - if (phy_blk == BLK_NOT_FOUND) - TRACE_RET(chip, STATUS_FAIL); + if (phy_blk == BLK_NOT_FOUND) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -986,7 +1127,8 @@ static int xd_mark_bad_block(struct rtsx_chip *chip, u32 phy_blk) xd_set_err_code(chip, XD_PRG_ERROR); else xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1002,10 +1144,14 @@ static int xd_init_page(struct rtsx_chip *chip, u32 phy_blk, dev_dbg(rtsx_dev(chip), "Init block 0x%x\n", phy_blk); - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); - if (phy_blk == BLK_NOT_FOUND) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } + if (phy_blk == BLK_NOT_FOUND) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -1040,7 +1186,8 @@ static int xd_init_page(struct rtsx_chip *chip, u32 phy_blk, } else { xd_set_err_code(chip, XD_TO_ERROR); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1057,24 +1204,34 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, dev_dbg(rtsx_dev(chip), "Copy page from block 0x%x to block 0x%x\n", old_blk, new_blk); - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } - if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND)) - TRACE_RET(chip, STATUS_FAIL); + if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND)) { + rtsx_trace(chip); + return STATUS_FAIL; + } old_page = (old_blk << xd_card->block_shift) + start_page; new_page = (new_blk << xd_card->block_shift) + start_page; XD_CLR_BAD_NEWBLK(xd_card); - RTSX_WRITE_REG(chip, CARD_DATA_SOURCE, 0x01, PINGPONG_BUFFER); + retval = rtsx_write_register(chip, CARD_DATA_SOURCE, 0x01, + PINGPONG_BUFFER); + if (retval) { + rtsx_trace(chip); + return retval; + } for (i = start_page; i < end_page; i++) { if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { rtsx_clear_xd_error(chip); xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_init_cmd(chip); @@ -1100,7 +1257,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (((reg & (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) == @@ -1119,7 +1277,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, } } else { xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1147,7 +1306,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, } else { xd_set_err_code(chip, XD_TO_ERROR); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } old_page++; @@ -1172,14 +1332,17 @@ static int xd_reset_cmd(struct rtsx_chip *chip) rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip) + 1; if (((ptr[0] & READY_FLAG) == READY_STATE) && (ptr[1] & XD_RDY)) return STATUS_SUCCESS; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) @@ -1189,8 +1352,10 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) u8 reg = 0, *ptr; int i, retval; - if (phy_blk == BLK_NOT_FOUND) - TRACE_RET(chip, STATUS_FAIL); + if (phy_blk == BLK_NOT_FOUND) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_addr = phy_blk << xd_card->block_shift; @@ -1212,13 +1377,16 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) if (reg & PROGRAM_ERROR) { xd_mark_bad_block(chip, phy_blk); xd_set_err_code(chip, XD_PRG_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { xd_set_err_code(chip, XD_ERASE_FAIL); } retval = xd_reset_cmd(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } continue; } @@ -1226,7 +1394,8 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) if (*ptr & PROGRAM_ERROR) { xd_mark_bad_block(chip, phy_blk); xd_set_err_code(chip, XD_PRG_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1234,7 +1403,8 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) xd_mark_bad_block(chip, phy_blk); xd_set_err_code(chip, XD_ERASE_FAIL); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } @@ -1266,15 +1436,19 @@ static int xd_build_l2p_tbl(struct rtsx_chip *chip, int zone_no) if (zone->l2p_table == NULL) { zone->l2p_table = vmalloc(2000); - if (zone->l2p_table == NULL) - TRACE_GOTO(chip, Build_Fail); + if (zone->l2p_table == NULL) { + rtsx_trace(chip); + goto Build_Fail; + } } memset((u8 *)(zone->l2p_table), 0xff, 2000); if (zone->free_table == NULL) { zone->free_table = vmalloc(XD_FREE_TABLE_CNT * 2); - if (zone->free_table == NULL) - TRACE_GOTO(chip, Build_Fail); + if (zone->free_table == NULL) { + rtsx_trace(chip); + goto Build_Fail; + } } memset((u8 *)(zone->free_table), 0xff, XD_FREE_TABLE_CNT * 2); @@ -1440,8 +1614,10 @@ static int xd_send_cmd(struct rtsx_chip *chip, u8 cmd) XD_TRANSFER_END, XD_TRANSFER_END); retval = rtsx_send_cmd(chip, XD_CARD, 200); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1457,8 +1633,10 @@ static int xd_read_multiple_pages(struct rtsx_chip *chip, u32 phy_blk, u8 reg_val, page_cnt; int zone_no, retval, i; - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_cnt = end_page - start_page; zone_no = (int)(log_blk / 1000); @@ -1474,7 +1652,8 @@ static int xd_read_multiple_pages(struct rtsx_chip *chip, u32 phy_blk, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } @@ -1509,21 +1688,31 @@ static int xd_read_multiple_pages(struct rtsx_chip *chip, u32 phy_blk, if (retval == -ETIMEDOUT) { xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { - TRACE_GOTO(chip, Fail); + rtsx_trace(chip); + goto Fail; } } return STATUS_SUCCESS; Fail: - RTSX_READ_REG(chip, XD_PAGE_STATUS, ®_val); + retval = rtsx_read_register(chip, XD_PAGE_STATUS, ®_val); + if (retval) { + rtsx_trace(chip); + return retval; + } if (reg_val != XD_GPG) xd_set_err_code(chip, XD_PRG_ERROR); - RTSX_READ_REG(chip, XD_CTL, ®_val); + retval = rtsx_read_register(chip, XD_CTL, ®_val); + if (retval) { + rtsx_trace(chip); + return retval; + } if (((reg_val & (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) == (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) @@ -1533,7 +1722,8 @@ Fail: if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } xd_set_err_code(chip, XD_ECC_ERROR); @@ -1541,7 +1731,8 @@ Fail: new_blk = xd_get_unused_block(chip, zone_no); if (new_blk == NO_NEW_BLK) { XD_CLR_BAD_OLDBLK(xd_card); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_copy_page(chip, phy_blk, new_blk, 0, @@ -1555,7 +1746,8 @@ Fail: XD_CLR_BAD_NEWBLK(xd_card); } XD_CLR_BAD_OLDBLK(xd_card); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } xd_set_l2p_tbl(chip, zone_no, log_off, (u16)(new_blk & 0x3FF)); xd_erase_block(chip, phy_blk); @@ -1563,7 +1755,8 @@ Fail: XD_CLR_BAD_OLDBLK(xd_card); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } static int xd_finish_write(struct rtsx_chip *chip, @@ -1576,8 +1769,10 @@ static int xd_finish_write(struct rtsx_chip *chip, dev_dbg(rtsx_dev(chip), "xd_finish_write, old_blk = 0x%x, new_blk = 0x%x, log_blk = 0x%x\n", old_blk, new_blk, log_blk); - if (page_off > xd_card->page_off) - TRACE_RET(chip, STATUS_FAIL); + if (page_off > xd_card->page_off) { + rtsx_trace(chip); + return STATUS_FAIL; + } zone_no = (int)(log_blk / 1000); log_off = (u16)(log_blk % 1000); @@ -1589,7 +1784,8 @@ static int xd_finish_write(struct rtsx_chip *chip, retval = xd_erase_block(chip, new_blk); if (retval == STATUS_SUCCESS) xd_set_unused_block(chip, new_blk); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { retval = xd_copy_page(chip, old_blk, new_blk, @@ -1601,7 +1797,8 @@ static int xd_finish_write(struct rtsx_chip *chip, xd_set_unused_block(chip, new_blk); } XD_CLR_BAD_NEWBLK(xd_card); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_erase_block(chip, old_blk); @@ -1633,8 +1830,10 @@ static int xd_prepare_write(struct rtsx_chip *chip, if (page_off) { retval = xd_copy_page(chip, old_blk, new_blk, 0, page_off); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1655,8 +1854,10 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk, dev_dbg(rtsx_dev(chip), "%s, old_blk = 0x%x, new_blk = 0x%x, log_blk = 0x%x\n", __func__, old_blk, new_blk, log_blk); - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_cnt = end_page - start_page; zone_no = (int)(log_blk / 1000); @@ -1665,8 +1866,10 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk, page_addr = (new_blk << xd_card->block_shift) + start_page; retval = xd_send_cmd(chip, READ1_1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -1701,9 +1904,11 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk, if (retval == -ETIMEDOUT) { xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { - TRACE_GOTO(chip, Fail); + rtsx_trace(chip); + goto Fail; } } @@ -1730,13 +1935,18 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk, return STATUS_SUCCESS; Fail: - RTSX_READ_REG(chip, XD_DAT, ®_val); + retval = rtsx_read_register(chip, XD_DAT, ®_val); + if (retval) { + rtsx_trace(chip); + return retval; + } if (reg_val & PROGRAM_ERROR) { xd_set_err_code(chip, XD_PRG_ERROR); xd_mark_bad_block(chip, new_blk); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #ifdef XD_DELAY_WRITE @@ -1749,16 +1959,20 @@ int xd_delay_write(struct rtsx_chip *chip) if (delay_write->delay_write_flag) { dev_dbg(rtsx_dev(chip), "xd_delay_write\n"); retval = xd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } delay_write->delay_write_flag = 0; retval = xd_finish_write(chip, delay_write->old_phyblock, delay_write->new_phyblock, delay_write->logblock, delay_write->pageoff); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1790,14 +2004,17 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, ptr = (u8 *)scsi_sglist(srb); retval = xd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + 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); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } log_blk = start_sector >> xd_card->block_shift; @@ -1810,7 +2027,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1828,7 +2046,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } old_blk = delay_write->old_phyblock; @@ -1844,7 +2063,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif old_blk = xd_get_l2p_tbl(chip, zone_no, log_off); @@ -1853,7 +2073,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, (new_blk == BLK_NOT_FOUND)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_prepare_write(chip, old_blk, new_blk, @@ -1863,11 +2084,13 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #ifdef XD_DELAY_WRITE } @@ -1879,11 +2102,13 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif @@ -1891,7 +2116,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (old_blk == BLK_NOT_FOUND) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1901,7 +2127,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if ((start_page + total_sec_cnt) > (xd_card->page_off + 1)) @@ -1917,7 +2144,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { retval = xd_write_multiple_pages(chip, old_blk, @@ -1927,7 +2155,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1948,7 +2177,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1961,7 +2191,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (srb->sc_data_direction == DMA_TO_DEVICE) { @@ -1969,7 +2200,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (new_blk == BLK_NOT_FOUND) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1988,7 +2220,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_finish_write(chip, old_blk, new_blk, @@ -1997,10 +2230,12 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif } @@ -2049,25 +2284,39 @@ int xd_power_off_card3v3(struct rtsx_chip *chip) int retval; retval = disable_card_clock(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } - RTSX_WRITE_REG(chip, CARD_OE, XD_OUTPUT_EN, 0); + 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) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(50); } if (chip->asic_code) { retval = xd_pull_ctl_disable(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { - RTSX_WRITE_REG(chip, FPGA_PULL_CTL, 0xFF, 0xDF); + retval = rtsx_write_register(chip, FPGA_PULL_CTL, 0xFF, 0xDF); + if (retval) { + rtsx_trace(chip); + return retval; + } } return STATUS_SUCCESS; @@ -2087,8 +2336,10 @@ int release_xd_card(struct rtsx_chip *chip) xd_free_l2p_tbl(chip); retval = xd_power_off_card3v3(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } |