28 #include <linux/sched.h>
29 #include <linux/slab.h>
51 return (ms_card->
err_code == err_code);
54 static int ms_parse_err_code(
struct rts51x_chip *chip)
59 static int ms_transfer_tpc(
struct rts51x_chip *chip,
u8 trans_mode,
u8 tpc,
67 rts51x_init_cmd(chip);
88 rts51x_clear_ms_error(chip);
103 TRACE_RET(chip, ms_parse_err_code(chip));
110 rts51x_clear_ms_error(chip);
112 TRACE_RET(chip, ms_parse_err_code(chip));
119 u16 sec_cnt,
u8 cfg,
int mode_2k,
int use_sg,
void *
buf,
128 if (!buf || !buf_len)
145 rts51x_init_cmd(chip);
149 (
u8) (sec_cnt >> 8));
178 ms_set_err_code(chip, err_code);
179 rts51x_clear_ms_error(chip);
185 ms_set_err_code(chip, err_code);
186 rts51x_clear_ms_error(chip);
203 if (!data || (data_len < cnt))
206 rts51x_init_cmd(chip);
208 for (i = 0; i <
cnt; i++) {
238 rts51x_clear_ms_error(chip);
244 TRACE_RET(chip, ms_parse_err_code(chip));
247 if (
CHK_MSPRO(ms_card) && !(val & 0x80)) {
251 ms_parse_err_code(chip));
259 TRACE_RET(chip, ms_parse_err_code(chip));
263 TRACE_RET(chip, ms_parse_err_code(chip));
278 rts51x_init_cmd(chip);
291 for (i = 0; i < data_len - 1; i++)
312 rts51x_clear_ms_error(chip);
318 TRACE_RET(chip, ms_parse_err_code(chip));
321 if (
CHK_MSPRO(ms_card) && !(val & 0x80)) {
325 ms_parse_err_code(chip));
333 TRACE_RET(chip, ms_parse_err_code(chip));
337 TRACE_RET(chip, ms_parse_err_code(chip));
340 rts51x_read_rsp_buf(chip, 1, data, data_len);
346 u8 read_start,
u8 read_cnt,
u8 write_start,
u8 write_cnt)
351 data[0] = read_start;
353 data[2] = write_start;
362 rts51x_clear_ms_error(chip);
379 u8 read_start,
u8 read_count,
380 u8 write_start,
u8 write_count,
386 if (!data || (data_len <= 0) || (data_len > 128)) {
404 if (i == MS_MAX_RETRY_COUNT)
410 retval = ms_send_cmd(chip, cmd,
WAIT_INT);
414 if (i == MS_MAX_RETRY_COUNT)
429 static int ms_auto_set_cmd(
struct rts51x_chip *chip,
430 u8 read_start,
u8 read_count,
431 u8 write_start,
u8 write_count,
432 u8 cmd,
u8 cfg,
u8 *data,
int data_len,
438 if (!data || (data_len <= 0) || (data_len > 128)) {
439 RTS51X_DEBUGP(
"ms_auto_set_cmd (data_len = %d)\n", data_len);
443 rts51x_init_cmd(chip);
472 rts51x_clear_ms_error(chip);
483 static int ms_set_init_para(
struct rts51x_chip *chip)
505 retval = switch_clock(chip, ms_card->
ms_clock);
525 retval = switch_clock(chip, ms_card->
ms_clock);
532 static void ms_pull_ctl_disable(
struct rts51x_chip *chip)
551 static void ms_pull_ctl_enable(
struct rts51x_chip *chip)
570 static int ms_prepare_reset(
struct rts51x_chip *chip)
582 rts51x_init_cmd(chip);
585 ms_pull_ctl_enable(chip);
593 if (!chip->
option.FT2_fast_mode) {
602 if (!chip->
option.FT2_fast_mode) {
621 rts51x_init_cmd(chip);
643 return ms_set_init_para(chip);
646 static int ms_identify_media_type(
struct rts51x_chip *chip,
int switch_8bit_bus)
664 if (i == MS_MAX_RETRY_COUNT)
690 }
else if ((val == 0x01) || (val == 0x02) || (val == 0x03)) {
704 }
else if (val == 7) {
717 static int ms_confirm_cpu_startup(
struct rts51x_chip *chip)
735 if (i == MS_MAX_RETRY_COUNT)
749 if (i == MS_MAX_RETRY_COUNT)
764 static int ms_switch_parallel_bus(
struct rts51x_chip *chip)
783 static int ms_switch_8bit_bus(
struct rts51x_chip *chip)
804 retval = ms_set_init_para(chip);
819 static int ms_pro_reset_flow(
struct rts51x_chip *chip,
int switch_8bit_bus)
824 for (i = 0; i < 3; i++) {
825 retval = ms_prepare_reset(chip);
829 retval = ms_identify_media_type(chip, switch_8bit_bus);
833 retval = ms_confirm_cpu_startup(chip);
837 retval = ms_switch_parallel_bus(chip);
854 retval = ms_set_init_para(chip);
858 if (
CHK_MSHG(ms_card) && switch_8bit_bus) {
859 retval = ms_switch_8bit_bus(chip);
905 static int ms_read_attribute_info(
struct rts51x_chip *chip)
912 u32 xc_total_blk = 0, xc_blk_size = 0;
914 u32 sys_info_addr = 0, sys_info_size;
915 #ifdef SUPPORT_PCGL_1P18
916 u32 model_name_addr = 0, model_name_size;
917 int found_sys_info = 0, found_model_name = 0;
969 0x40,
WAIT_INT, 0, 0, buf, 64 * 512);
973 rts51x_clear_ms_error(chip);
988 if ((val &
MS_INT_CED) || !(val & MS_INT_BREQ))
1007 if ((buf[0] != 0xa5) && (buf[1] != 0xc3)) {
1013 if ((buf[4] < 1) || (buf[4] > 12)) {
1018 for (i = 0; i < buf[4]; i++) {
1019 int cur_addr_off = 16 + i * 12;
1022 if ((buf[cur_addr_off + 8] == 0x10)
1023 || (buf[cur_addr_off + 8] == 0x13)) {
1025 if (buf[cur_addr_off + 8] == 0x10) {
1027 sys_info_addr = ((
u32) buf[cur_addr_off + 0] << 24) |
1028 ((
u32) buf[cur_addr_off + 1] << 16) |
1029 ((
u32) buf[cur_addr_off + 2] << 8) |
1030 buf[cur_addr_off + 3];
1032 ((
u32) buf[cur_addr_off + 4] << 24) |
1033 ((
u32) buf[cur_addr_off + 5] << 16) |
1034 ((
u32) buf[cur_addr_off + 6] << 8) |
1035 buf[cur_addr_off + 7];
1037 "sys_info_size = 0x%x\n",
1038 sys_info_addr, sys_info_size);
1039 if (sys_info_size != 96) {
1043 if (sys_info_addr < 0x1A0) {
1047 if ((sys_info_size + sys_info_addr) > 0x8000) {
1052 if (buf[cur_addr_off + 8] == 0x13)
1055 #ifdef SUPPORT_PCGL_1P18
1061 #ifdef SUPPORT_PCGL_1P18
1062 if (buf[cur_addr_off + 8] == 0x15) {
1063 model_name_addr = ((
u32) buf[cur_addr_off + 0] << 24) |
1064 ((
u32) buf[cur_addr_off + 1] << 16) |
1065 ((
u32) buf[cur_addr_off + 2] << 8) |
1066 buf[cur_addr_off + 3];
1068 ((
u32) buf[cur_addr_off + 4] << 24) |
1069 ((
u32) buf[cur_addr_off + 5] << 16) |
1070 ((
u32) buf[cur_addr_off + 6] << 8) |
1071 buf[cur_addr_off + 7];
1073 "model_name_size = 0x%x\n",
1074 model_name_addr, model_name_size);
1075 if (model_name_size != 48) {
1079 if (model_name_addr < 0x1A0) {
1083 if ((model_name_size + model_name_addr) > 0x8000) {
1088 found_model_name = 1;
1091 if (found_sys_info && found_model_name)
1101 class_code = buf[sys_info_addr + 0];
1102 device_type = buf[sys_info_addr + 56];
1103 sub_class = buf[sys_info_addr + 46];
1106 xc_total_blk = ((
u32) buf[sys_info_addr + 6] << 24) |
1107 ((
u32) buf[sys_info_addr + 7] << 16) |
1108 ((
u32) buf[sys_info_addr + 8] << 8) |
1109 buf[sys_info_addr + 9];
1110 xc_blk_size = ((
u32) buf[sys_info_addr + 32] << 24) |
1111 ((
u32) buf[sys_info_addr + 33] << 16) |
1112 ((
u32) buf[sys_info_addr + 34] << 8) |
1113 buf[sys_info_addr + 35];
1115 xc_total_blk, xc_blk_size);
1118 ((
u16) buf[sys_info_addr + 6] << 8) | buf[sys_info_addr +
1121 ((
u16) buf[sys_info_addr + 2] << 8) | buf[sys_info_addr +
1123 RTS51X_DEBUGP(
"total_blk = 0x%x, blk_size = 0x%x\n", total_blk,
1128 ((
u16) buf[sys_info_addr + 6] << 8) | buf[sys_info_addr + 7];
1129 blk_size = ((
u16) buf[sys_info_addr + 2] << 8) | buf[sys_info_addr + 3];
1130 RTS51X_DEBUGP(
"total_blk = 0x%x, blk_size = 0x%x\n", total_blk,
1135 "sub_class = 0x%x\n",
1136 class_code, device_type, sub_class);
1139 #ifdef SUPPORT_PCGL_1P18
1148 if (class_code != 0x03)
1151 if (class_code != 0x02)
1155 if (class_code != 0x02)
1159 if (device_type != 0x00) {
1160 if ((device_type == 0x01) || (device_type == 0x02)
1161 || (device_type == 0x03))
1166 if (sub_class & 0xC0)
1169 RTS51X_DEBUGP(
"class_code: 0x%x, device_type: 0x%x, sub_class: 0x%x\n",
1170 class_code, device_type, sub_class);
1175 xc_total_blk * xc_blk_size;
1188 #ifdef SUPPORT_MAGIC_GATE
1196 #ifdef XC_POWERCLASS
1197 u8 change_power_class = 2;
1200 #ifdef XC_POWERCLASS
1203 retval = ms_pro_reset_flow(chip, 1);
1206 retval = ms_pro_reset_flow(chip, 0);
1214 retval = ms_read_attribute_info(chip);
1217 #ifdef XC_POWERCLASS
1219 change_power_class = 0;
1221 if (change_power_class &&
CHK_MSXC(ms_card)) {
1224 if (change_power_class > power_class_mode)
1225 change_power_class = power_class_mode;
1226 if (change_power_class) {
1227 retval = msxc_change_power(chip, change_power_class);
1229 change_power_class--;
1236 #ifdef SUPPORT_MAGIC_GATE
1250 static int ms_read_status_reg(
struct rts51x_chip *chip)
1270 static int ms_check_boot_block(
struct rts51x_chip *chip,
u16 block_addr)
1285 data[2] = (
u8) (block_addr >> 8);
1286 data[3] = (
u8) block_addr;
1301 if (val & INT_REG_CED) {
1302 if (val & INT_REG_ERR) {
1303 retval = ms_read_status_reg(chip);
1326 static int ms_read_extra_data(
struct rts51x_chip *chip,
1327 u16 block_addr,
u8 page_num,
u8 *buf,
1332 u8 val = 0, data[10];
1343 data[2] = (
u8) (block_addr >> 8);
1344 data[3] = (
u8) block_addr;
1361 if (val & INT_REG_CMDNK) {
1365 if (val & INT_REG_CED) {
1366 if (val & INT_REG_ERR) {
1367 retval = ms_read_status_reg(chip);
1384 if (buf && buf_len) {
1387 memcpy(buf, data, buf_len);
1393 static int ms_write_extra_data(
struct rts51x_chip *chip,
1394 u16 block_addr,
u8 page_num,
u8 *buf,
1399 u8 val = 0, data[16];
1413 data[2] = (
u8) (block_addr >> 8);
1414 data[3] = (
u8) block_addr;
1421 data[i] = buf[i - 6];
1437 if (val & INT_REG_CMDNK) {
1441 if (val & INT_REG_CED) {
1442 if (val & INT_REG_ERR) {
1451 static int ms_read_page(
struct rts51x_chip *chip,
u16 block_addr,
u8 page_num)
1455 u8 val = 0, data[6];
1466 data[2] = (
u8) (block_addr >> 8);
1467 data[3] = (
u8) block_addr;
1478 if (val & INT_REG_CMDNK) {
1483 if (val & INT_REG_CED) {
1484 if (val & INT_REG_ERR) {
1489 retval = ms_read_status_reg(chip);
1493 if (!(val & INT_REG_BREQ)) {
1511 static int ms_set_bad_block(
struct rts51x_chip *chip,
u16 phy_blk)
1517 retval = ms_read_extra_data(chip, phy_blk, 0, extra, MS_EXTRA_SIZE);
1532 data[2] = (
u8) (phy_blk >> 8);
1533 data[3] = (
u8) phy_blk;
1536 data[6] = extra[0] & 0x7F;
1549 if (val & INT_REG_CMDNK) {
1554 if (val & INT_REG_CED) {
1555 if (val & INT_REG_ERR) {
1568 u8 val = 0, data[6];
1587 data[2] = (
u8) (phy_blk >> 8);
1588 data[3] = (
u8) phy_blk;
1602 if (val & INT_REG_CMDNK) {
1608 ms_set_bad_block(chip, phy_blk);
1612 if (val & INT_REG_CED) {
1613 if (val & INT_REG_ERR) {
1622 static void ms_set_page_status(
u16 log_blk,
u8 type,
u8 *extra,
int extra_len)
1624 if (!extra || (extra_len < MS_EXTRA_SIZE))
1627 memset(extra, 0xFF, MS_EXTRA_SIZE);
1634 extra[2] = (
u8) (log_blk >> 8);
1635 extra[3] = (
u8) log_blk;
1639 u8 start_page,
u8 end_page)
1644 memset(extra, 0xff, MS_EXTRA_SIZE);
1648 extra[2] = (
u8) (log_blk >> 8);
1649 extra[3] = (
u8) log_blk;
1651 for (i = start_page; i < end_page; i++) {
1656 ms_write_extra_data(chip, phy_blk, i, extra, MS_EXTRA_SIZE);
1665 u16 log_blk,
u8 start_page,
u8 end_page)
1668 int retval, rty_cnt, uncorrect_flag = 0;
1671 RTS51X_DEBUGP(
"Copy page from 0x%x to 0x%x, logical block is 0x%x\n",
1672 old_blk, new_blk, log_blk);
1673 RTS51X_DEBUGP(
"start_page = %d, end_page = %d\n", start_page,
1676 retval = ms_read_extra_data(chip, new_blk, 0, extra, MS_EXTRA_SIZE);
1680 retval = ms_read_status_reg(chip);
1696 if (!(val & INT_REG_CED)) {
1702 for (i = start_page; i < end_page; i++) {
1706 ms_read_extra_data(chip, old_blk, i, extra, MS_EXTRA_SIZE);
1725 data[2] = (
u8) (old_blk >> 8);
1726 data[3] = (
u8) old_blk;
1744 if (val & INT_REG_CMDNK) {
1749 if (val & INT_REG_CED) {
1750 if (val & INT_REG_ERR) {
1751 retval = ms_read_status_reg(chip);
1765 if (uncorrect_flag) {
1766 ms_set_page_status(log_blk,
setPS_NG,
1767 extra, MS_EXTRA_SIZE);
1770 ms_write_extra_data(chip, old_blk, i,
1774 "extra[0] = 0x%x\n",
1779 extra, MS_EXTRA_SIZE);
1780 ms_write_extra_data(chip, new_blk, i,
1781 extra, MS_EXTRA_SIZE);
1788 ms_transfer_tpc(chip,
1795 if (rty_cnt == MS_MAX_RETRY_COUNT)
1799 if (!(val & INT_REG_BREQ)) {
1807 (6 + MS_EXTRA_SIZE));
1821 data[2] = (
u8) (new_blk >> 8);
1822 data[3] = (
u8) new_blk;
1827 if ((extra[0] & 0x60) != 0x60)
1833 data[6 + 2] = (
u8) (log_blk >> 8);
1834 data[6 + 3] = (
u8) log_blk;
1854 if (val & INT_REG_CMDNK) {
1859 if (val & INT_REG_CED) {
1860 if (val & INT_REG_ERR) {
1884 data[2] = (
u8) (old_blk >> 8);
1885 data[3] = (
u8) old_blk;
1908 if (val & INT_REG_CMDNK) {
1913 if (val & INT_REG_CED) {
1914 if (val & INT_REG_ERR) {
1915 ms_set_err_code(chip,
1927 static int ms_auto_copy_page(
struct rts51x_chip *chip,
u16 old_blk,
u16 new_blk,
1928 u16 log_blk,
u8 start_page,
u8 end_page)
1936 "logical block is 0x%x\n",
1937 old_blk, new_blk, log_blk);
1938 RTS51X_DEBUGP(
"start_page = %d, end_page = %d\n", start_page,
1941 page_len = end_page - start_page;
1943 retval = ms_read_extra_data(chip, new_blk, 0, extra, MS_EXTRA_SIZE);
1947 retval = ms_read_status_reg(chip);
1953 if (val & BUF_FULL) {
1962 if (!(val & INT_REG_CED)) {
1976 rts51x_init_cmd(chip);
1980 (
u8) (old_blk >> 8));
1983 (
u8) (new_blk >> 8));
1986 (
u8) (log_blk >> 8));
1998 rts51x_clear_ms_error(chip);
2005 rts51x_clear_ms_error(chip);
2014 retval = ms_erase_block(chip, new_blk);
2019 ms_copy_page(chip, old_blk, new_blk, log_blk, start_page, end_page);
2033 #ifndef SUPPORT_MAGIC_GATE
2037 retval = ms_prepare_reset(chip);
2047 retval = ms_read_status_reg(chip);
2065 retval = ms_check_boot_block(chip, i);
2079 for (j = 0; j < 3; j++) {
2080 retval = ms_read_page(chip, ms_card->
boot_block, j);
2091 retval = ms_read_page(chip, ms_card->
boot_block, 0);
2101 rts51x_init_cmd(chip);
2126 ptr = rts51x_get_rsp_data(chip);
2131 if (ptr[0] != 0x00 || ptr[1] != 0x01) {
2135 if (ptr[12] != 0x02 || ptr[13] != 0x00) {
2139 if ((ptr[14] == 1) || (ptr[14] == 3))
2141 block_size = ((
u16) ptr[6] << 8) | ptr[7];
2142 if (block_size == 0x0010) {
2145 }
else if (block_size == 0x0008) {
2151 #ifdef SUPPORT_MAGIC_GATE
2170 eblock_cnt = ((
u16) ptr[10] << 8) | ptr[11];
2204 static int ms_init_l2p_tbl(
struct rts51x_chip *chip)
2220 retval = ms_read_page(chip, ms_card->
boot_block, 1);
2225 for (i = 0; i < (((ms_card->
total_block >> 9) * 10) + 1); i++) {
2233 defect_block = ((
u16) val1 << 8) | val2;
2234 if (defect_block == 0xFFFF)
2236 seg_no = defect_block / 512;
2243 ms_card->
segment[
i].build_flag = 0;
2248 ms_card->
segment[
i].unused_blk_cnt = 0;
2250 RTS51X_DEBUGP(
"defective block count of segment %d is %d\n",
2251 i, ms_card->
segment[i].disable_count);
2273 segment = &(ms_card->
segment[seg_no]);
2281 static void ms_set_l2p_tbl(
struct rts51x_chip *chip,
int seg_no,
u16 log_off,
2290 segment = &(ms_card->
segment[seg_no]);
2295 static void ms_set_unused_block(
struct rts51x_chip *chip,
u16 phy_blk)
2301 seg_no = (
int)phy_blk >> 9;
2302 segment = &(ms_card->
segment[seg_no]);
2310 static u16 ms_get_unused_block(
struct rts51x_chip *chip,
int seg_no)
2316 segment = &(ms_card->
segment[seg_no]);
2330 static const unsigned short ms_start_idx[] = {
2331 0, 494, 990, 1486, 1982, 2478, 2974, 3470,
2332 3966, 4462, 4958, 5454, 5950, 6446, 6942, 7438, 7934
2343 seg_no = (
int)phy_blk >> 9;
2344 segment = &(ms_card->
segment[seg_no]);
2350 ms_erase_block(chip, tmp_blk);
2351 ms_set_unused_block(chip, tmp_blk);
2355 ms_erase_block(chip, phy_blk);
2356 ms_set_unused_block(chip, phy_blk);
2359 if (phy_blk < tmp_blk) {
2361 ms_erase_block(chip, phy_blk);
2362 ms_set_unused_block(chip, phy_blk);
2365 ms_erase_block(chip, tmp_blk);
2366 ms_set_unused_block(chip, tmp_blk);
2374 static int ms_build_l2p_tbl(
struct rts51x_chip *chip,
int seg_no)
2378 int retval, table_size, disable_cnt, defect_flag,
i;
2385 retval = ms_init_l2p_tbl(chip);
2390 if (ms_card->
segment[seg_no].build_flag) {
2401 segment = &(ms_card->
segment[seg_no]);
2417 start = (
u16) seg_no << 9;
2418 end = (
u16) (seg_no + 1) << 9;
2425 for (phy_blk = start; phy_blk <
end; phy_blk++) {
2441 ms_read_extra_data(chip, phy_blk, 0, extra, MS_EXTRA_SIZE);
2444 ms_set_bad_block(chip, phy_blk);
2451 retval = ms_erase_block(chip, phy_blk);
2460 if (!(extra[0] & BLOCK_OK))
2464 if ((extra[0] &
PAGE_OK) != PAGE_OK)
2467 log_blk = ((
u16) extra[2] << 8) | extra[3];
2469 if (log_blk == 0xFFFF) {
2471 retval = ms_erase_block(chip, phy_blk);
2475 ms_set_unused_block(chip, phy_blk);
2479 if ((log_blk < ms_start_idx[seg_no]) ||
2480 (log_blk >= ms_start_idx[seg_no + 1])) {
2482 retval = ms_erase_block(chip, phy_blk);
2486 ms_set_unused_block(chip, phy_blk);
2490 if (segment->
l2p_table[log_blk - ms_start_idx[seg_no]] ==
2492 segment->
l2p_table[log_blk - ms_start_idx[seg_no]] =
2497 us1 = extra[0] & 0x10;
2498 tmp_blk = segment->
l2p_table[log_blk - ms_start_idx[seg_no]];
2500 ms_read_extra_data(chip, tmp_blk, 0, extra, MS_EXTRA_SIZE);
2503 us2 = extra[0] & 0x10;
2505 (
void)ms_arbitrate_l2p(chip, phy_blk,
2506 log_blk - ms_start_idx[seg_no], us1,
2526 for (log_blk = ms_start_idx[seg_no]; log_blk < ms_start_idx[seg_no + 1];
2528 if (segment->
l2p_table[log_blk - ms_start_idx[seg_no]] ==
2530 phy_blk = ms_get_unused_block(chip, seg_no);
2531 if (phy_blk == 0xFFFF) {
2535 retval = ms_init_page(chip, phy_blk, log_blk, 0, 1);
2538 segment->
l2p_table[log_blk - ms_start_idx[seg_no]] =
2555 for (log_blk = 0; log_blk < 494; log_blk++) {
2564 phy_blk = ms_get_unused_block(chip, 0);
2567 ms_auto_copy_page(chip, tmp_blk, phy_blk,
2571 retval = ms_copy_page(chip, tmp_blk, phy_blk,
2580 retval = ms_set_bad_block(chip, tmp_blk);
2619 retval = reset_ms_pro(chip);
2622 retval = reset_ms(chip);
2624 if (chip->
option.reset_or_rw_fail_set_pad_drive) {
2632 if (chip->
option.reset_or_rw_fail_set_pad_drive) {
2641 retval = ms_set_init_para(chip);
2646 retval = ms_build_l2p_tbl(chip, ms_card->
total_block / 512 - 1);
2656 static int mspro_set_rw_cmd(
struct rts51x_chip *chip,
u32 start_sec,
2657 u16 sec_cnt,
u8 cmd)
2663 data[1] = (
u8) (sec_cnt >> 8);
2664 data[2] = (
u8) sec_cnt;
2665 data[3] = (
u8) (start_sec >> 24);
2666 data[4] = (
u8) (start_sec >> 16);
2667 data[5] = (
u8) (start_sec >> 8);
2668 data[6] = (
u8) start_sec;
2677 if (i == MS_MAX_RETRY_COUNT)
2683 static void mspro_stop_seq_mode(
struct rts51x_chip *chip)
2703 static inline int ms_auto_tune_clock(
struct rts51x_chip *chip)
2725 static int mspro_rw_multi_sector(
struct scsi_cmnd *
srb,
2732 u8 val, trans_mode, rw_tpc, rw_cmd;
2739 if ((start_sector % 4) || (sector_cnt % 4)) {
2784 || !(val & MS_INT_BREQ)
2789 if (val & MS_INT_BREQ) {
2802 if (sector_cnt >= 0x80) {
2803 if ((ms_card->
capacity - start_sector) > 0xFE00)
2808 if (count > sector_cnt) {
2817 retval = mspro_set_rw_cmd(chip, start_sector, count, rw_cmd);
2826 mode_2k, scsi_sg_count(srb), scsi_sglist(srb),
2831 rts51x_clear_ms_error(chip);
2832 if (val & MS_INT_BREQ)
2836 ms_auto_tune_clock(chip);
2850 static int mspro_read_format_progress(
struct rts51x_chip *chip,
2851 const int short_data_len)
2855 u32 total_progress, cur_progress;
2879 if (short_data_len >= 256)
2882 cnt = (
u8) short_data_len;
2890 (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
2892 (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
2895 total_progress, cur_progress);
2897 if (total_progress == 0) {
2900 u64 ulltmp = (
u64) cur_progress * (
u64) 65535;
2901 do_div(ulltmp, total_progress);
2906 for (i = 0; i < 2500; i++) {
2922 if (tmp & MS_INT_CED) {
2925 }
else if (tmp & MS_INT_BREQ) {
2945 for (i = 0; i < 65535; i++) {
2974 int short_data_len,
int quick_format)
2990 switch (short_data_len) {
3012 if (i == MS_MAX_RETRY_COUNT)
3019 retval = mspro_set_rw_cmd(chip, 0, para,
PRO_FORMAT);
3027 if ((tmp & (MS_INT_BREQ | MS_INT_CED)) == MS_INT_BREQ) {
3034 if (tmp & MS_INT_CED) {
3046 static int ms_read_multiple_pages(
struct rts51x_chip *chip,
u16 phy_blk,
3047 u16 log_blk,
u8 start_page,
u8 end_page,
3048 u8 *buf,
void **ptr,
unsigned int *
offset)
3054 u8 page_cnt = end_page - start_page, page_addr, sec_cnt;
3056 if (end_page != (ms_card->
page_off + 1))
3062 ms_read_extra_data(chip, phy_blk, start_page, extra, MS_EXTRA_SIZE);
3064 if ((extra[1] & 0x30) != 0x30) {
3079 data[2] = (
u8) (phy_blk >> 8);
3080 data[3] = (
u8) phy_blk;
3084 data[5] = start_page;
3092 rts51x_init_cmd(chip);
3119 ptr, offset, 512 * page_cnt,
3120 scsi_sg_count(chip->
srb),
NULL, 2000);
3122 rts51x_clear_ms_error(chip);
3129 rts51x_clear_ms_error(chip);
3138 rts51x_init_cmd(chip);
3152 RTS51X_DEBUGP(
"%d pages need be transferred, %d pages remained\n",
3153 (
int)page_cnt, (
int)sec_cnt);
3154 page_addr = start_page + (page_cnt - sec_cnt);
3166 if ((val1 &
INT_CMDNK) || (val2 & INT_REG_CMDNK)) {
3171 if ((val1 &
INT_ERR) || (val2 & INT_REG_ERR)) {
3172 if ((val1 &
INT_BREQ) || (val2 & INT_REG_BREQ)) {
3173 retval = ms_read_status_reg(chip);
3177 ms_set_page_status(log_blk,
setPS_NG,
3178 extra, MS_EXTRA_SIZE);
3179 ms_write_extra_data(chip, phy_blk,
3192 if (!(val1 & INT_BREQ) && !(val2 & INT_REG_BREQ)) {
3197 if (!(val2 & INT_REG_BREQ)) {
3207 static int ms_write_multiple_pages(
struct rts51x_chip *chip,
u16 old_blk,
3208 u16 new_blk,
u16 log_blk,
u8 start_page,
3209 u8 end_page,
u8 *buf,
void **ptr,
3210 unsigned int *offset)
3216 u8 page_cnt = end_page - start_page;
3218 if ((end_page == (ms_card->
page_off + 1)) || (page_cnt == 1))
3233 data[2] = (
u8) (old_blk >> 8);
3234 data[3] = (
u8) old_blk;
3250 (6 + MS_EXTRA_SIZE));
3265 data[2] = (
u8) (new_blk >> 8);
3266 data[3] = (
u8) new_blk;
3269 if (page_cnt == 1) {
3276 data[5] = start_page;
3279 data[8] = (
u8) (log_blk >> 8);
3280 data[9] = (
u8) log_blk;
3282 for (i = 0x0A; i < 0x10; i++) {
3294 rts51x_init_cmd(chip);
3323 ptr, offset, 512 * page_cnt,
3324 scsi_sg_count(chip->
srb),
NULL, 2000);
3326 rts51x_clear_ms_error(chip);
3334 rts51x_clear_ms_error(chip);
3343 static int ms_read_multiple_pages(
struct rts51x_chip *chip,
u16 phy_blk,
3344 u16 log_blk,
u8 start_page,
u8 end_page,
3345 u8 *buf,
void **ptr,
unsigned int *offset)
3352 ms_read_extra_data(chip, phy_blk, start_page, extra, MS_EXTRA_SIZE);
3354 if ((extra[1] & 0x30) != 0x30) {
3375 data[2] = (
u8) (phy_blk >> 8);
3376 data[3] = (
u8) phy_blk;
3380 data[5] = start_page;
3388 if (i == MS_MAX_RETRY_COUNT)
3397 for (page_addr = start_page; page_addr < end_page; page_addr++) {
3410 if (val & INT_REG_CMDNK) {
3414 if (val & INT_REG_ERR) {
3415 if (val & INT_REG_BREQ) {
3416 retval = ms_read_status_reg(chip);
3420 ms_set_page_status(log_blk,
3423 ms_write_extra_data(chip,
3425 extra, MS_EXTRA_SIZE);
3427 ms_set_err_code(chip,
3436 if (!(val & INT_REG_BREQ)) {
3442 if (page_addr == (end_page - 1)) {
3443 if (!(val & INT_REG_CED)) {
3453 if (!(val & INT_REG_CED)) {
3463 rts51x_init_cmd(chip);
3483 (
void *)buf, ptr, offset, 512,
3484 scsi_sg_count(chip->
srb),
NULL,
3489 rts51x_clear_ms_error(chip);
3497 rts51x_clear_ms_error(chip);
3502 rts51x_clear_ms_error(chip);
3511 rts51x_clear_ms_error(chip);
3519 rts51x_clear_ms_error(chip);
3524 rts51x_clear_ms_error(chip);
3533 static int ms_write_multiple_pages(
struct rts51x_chip *chip,
u16 old_blk,
3534 u16 new_blk,
u16 log_blk,
u8 start_page,
3535 u8 end_page,
u8 *buf,
void **ptr,
3536 unsigned int *offset)
3540 u8 page_addr,
val, data[16];
3558 data[2] = (
u8) (old_blk >> 8);
3559 data[3] = (
u8) old_blk;
3584 (6 + MS_EXTRA_SIZE));
3599 data[2] = (
u8) (new_blk >> 8);
3600 data[3] = (
u8) new_blk;
3603 if ((end_page - start_page) == 1) {
3610 data[5] = start_page;
3613 data[8] = (
u8) (log_blk >> 8);
3614 data[9] = (
u8) log_blk;
3616 for (i = 0x0A; i < 0x10; i++) {
3628 if (i == MS_MAX_RETRY_COUNT)
3636 if (i == MS_MAX_RETRY_COUNT)
3643 for (page_addr = start_page; page_addr < end_page; page_addr++) {
3651 if (val & INT_REG_CMDNK) {
3655 if (val & INT_REG_ERR) {
3659 if (!(val & INT_REG_BREQ)) {
3666 rts51x_init_cmd(chip);
3686 (
void *)buf, ptr, offset, 512,
3687 scsi_sg_count(chip->
srb),
NULL,
3691 rts51x_clear_ms_error(chip);
3702 rts51x_clear_ms_error(chip);
3714 if ((end_page - start_page) == 1) {
3715 if (!(val & INT_REG_CED)) {
3721 if (page_addr == (end_page - 1)) {
3722 if (!(val & INT_REG_CED)) {
3737 if ((page_addr == (end_page - 1))
3738 || (page_addr == ms_card->
page_off)) {
3739 if (!(val & INT_REG_CED)) {
3740 ms_set_err_code(chip,
3759 retval = ms_auto_copy_page(chip, old_blk, new_blk, log_blk,
3762 retval = ms_copy_page(chip, old_blk, new_blk, log_blk,
3768 seg_no = old_blk >> 9;
3772 ms_set_bad_block(chip, old_blk);
3774 retval = ms_erase_block(chip, old_blk);
3776 ms_set_unused_block(chip, old_blk);
3779 ms_set_l2p_tbl(chip, seg_no, log_blk - ms_start_idx[seg_no], new_blk);
3785 u16 log_blk,
u8 start_page)
3792 ms_auto_copy_page(chip, old_blk, new_blk, log_blk, 0,
3796 ms_copy_page(chip, old_blk, new_blk, log_blk, 0,
3813 retval = ms_set_init_para(chip);
3818 retval = ms_finish_write(chip,
3840 u32 start_sector,
u16 sector_cnt)
3845 unsigned int offset = 0;
3847 u8 start_page, end_page = 0, page_cnt;
3856 buf = (
u8 *) scsi_sglist(srb);
3860 ms_rw_fail(srb, chip);
3865 start_page = (
u8) (start_sector & ms_card->
page_off);
3867 for (seg_no = 0; seg_no <
ARRAY_SIZE(ms_start_idx) - 1; seg_no++) {
3868 if (log_blk < ms_start_idx[seg_no + 1])
3872 if (ms_card->
segment[seg_no].build_flag == 0) {
3873 retval = ms_build_l2p_tbl(chip, seg_no);
3883 (delay_write->
logblock == log_blk) &&
3884 (start_page > delay_write->
pageoff)) {
3887 retval = ms_auto_copy_page(chip,
3894 retval = ms_copy_page(chip,
3897 log_blk, delay_write->
pageoff,
3908 (delay_write->
logblock == log_blk) &&
3909 (start_page == delay_write->
pageoff)) {
3921 ms_get_l2p_tbl(chip, seg_no,
3922 log_blk - ms_start_idx[seg_no]);
3923 new_blk = ms_get_unused_block(chip, seg_no);
3924 if ((old_blk == 0xFFFF) || (new_blk == 0xFFFF)) {
3931 ms_prepare_write(chip, old_blk, new_blk, log_blk,
3960 ms_get_l2p_tbl(chip, seg_no,
3961 log_blk - ms_start_idx[seg_no]);
3962 if (old_blk == 0xFFFF) {
3969 RTS51X_DEBUGP(
"seg_no = %d, old_blk = 0x%x, new_blk = 0x%x\n", seg_no,
3972 while (total_sec_cnt) {
3973 if ((start_page + total_sec_cnt) > (ms_card->
page_off + 1))
3976 end_page = start_page + (
u8) total_sec_cnt;
3977 page_cnt = end_page - start_page;
3981 start_page, end_page, page_cnt);
3984 retval = ms_read_multiple_pages(chip,
3986 start_page, end_page,
3987 buf, &ptr, &offset);
3989 retval = ms_write_multiple_pages(chip, old_blk,
3991 start_page, end_page,
3992 buf, &ptr, &offset);
4001 ms_rw_fail(srb, chip);
4006 if (end_page == (ms_card->
page_off + 1)) {
4007 retval = ms_erase_block(chip, old_blk);
4009 ms_set_unused_block(chip, old_blk);
4010 ms_set_l2p_tbl(chip, seg_no,
4011 log_blk - ms_start_idx[seg_no],
4016 total_sec_cnt -= page_cnt;
4018 if (total_sec_cnt == 0)
4023 for (seg_no = 0; seg_no <
ARRAY_SIZE(ms_start_idx) - 1;
4025 if (log_blk < ms_start_idx[seg_no + 1])
4029 if (ms_card->
segment[seg_no].build_flag == 0) {
4030 retval = ms_build_l2p_tbl(chip, seg_no);
4040 ms_get_l2p_tbl(chip, seg_no,
4041 log_blk - ms_start_idx[seg_no]);
4042 if (old_blk == 0xFFFF) {
4043 ms_rw_fail(srb, chip);
4048 new_blk = ms_get_unused_block(chip, seg_no);
4049 if (new_blk == 0xFFFF) {
4050 ms_rw_fail(srb, chip);
4055 RTS51X_DEBUGP(
"seg_no = %d, old_blk = 0x%x, new_blk = 0x%x\n",
4056 seg_no, old_blk, new_blk);
4062 if (end_page < (ms_card->
page_off + 1)) {
4067 delay_write->
pageoff = end_page;
4071 scsi_set_resid(srb, 0);
4084 mspro_rw_multi_sector(srb, chip, start_sector, sector_cnt);
4087 ms_rw_multi_sector(srb, chip, start_sector, sector_cnt);
4120 mspro_stop_seq_mode(chip);
4128 MS_2K_SECTOR_MODE, 0x00);
4138 static int ms_power_off_card3v3(
struct rts51x_chip *chip)
4142 rts51x_init_cmd(chip);
4146 ms_pull_ctl_disable(chip);
4152 if (!chip->
option.FT2_fast_mode) {
4183 #ifdef SUPPORT_PCGL_1P18
4187 retval = ms_power_off_card3v3(chip);