28 #include <linux/sched.h>
29 #include <linux/slab.h>
44 if (!rsp_type || !rsp_len)
98 rts51x_init_cmd(chip);
147 rts51x_clear_sd_error(chip);
163 rts51x_read_rsp_buf(chip, 2, buf, len - 2);
174 (
unsigned short)len, buf);
181 if ((buf[0] & 0xC0) != 0)
211 if ((buf[3] & 0x1E) != 0x04)
214 if ((buf[3] & 0x1E) != 0x03)
221 memcpy(rsp, buf, rsp_len);
226 static int ext_sd_get_rsp(
struct rts51x_chip *chip,
int len,
227 u8 *rsp,
u8 rsp_type)
235 rts51x_init_cmd(chip);
260 int min_len = (rsp_len < len) ? rsp_len : len;
262 memcpy(rsp, rts51x_get_rsp_data(chip), min_len);
266 rsp[0], rsp[1], rsp[2], rsp[3]);
289 retval = get_rsp_type(rsp_code, &rsp_type, &rsp_len);
316 retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type,
317 sd_card->
rsp, rsp_len, 0);
329 SD_Execute_Cmd_Failed:
343 void *
data_buf,
unsigned int buf_len,
int use_sg)
347 int cmd13_checkbit = 0, read_err = 0;
359 retval = get_rsp_type(rsp_code, &rsp_type, &rsp_len);
371 if (data_len < 512) {
372 retval = ext_sd_send_cmd_get_rsp(chip,
SET_BLOCKLEN, data_len,
392 if (data_len <= 512) {
400 byte_cnt = (
u16) (data_len & 0x3FF);
404 cmd[1] = (
u8) (arg >> 24);
405 cmd[2] = (
u8) (arg >> 16);
406 cmd[3] = (
u8) (arg >> 8);
414 blk_cnt, bus_width, buf, data_len, 2000);
424 min_len =
min(data_len, buf_len);
429 memcpy(data_buf, buf, min_len);
432 }
else if (!(data_len & 0x1FF)) {
433 rts51x_init_cmd(chip);
437 0xFF, (
u8) (data_len >> 17));
439 0xFF, (
u8) ((data_len & 0x0001FE00) >> 9));
467 data_buf, buf_len, use_sg,
NULL,
488 retval = ext_sd_get_rsp(chip, rsp_len, sd_card->
rsp, rsp_type);
506 if (data_len < 512) {
507 retval = ext_sd_send_cmd_get_rsp(chip,
SET_BLOCKLEN, 0x200,
516 if (standby || cmd12)
519 for (i = 0; i < 3; i++) {
532 SD_Execute_Read_Cmd_Failed:
548 void *
data_buf,
unsigned int buf_len,
int use_sg)
552 int cmd13_checkbit = 0, write_err = 0;
566 retval = get_rsp_type(rsp_code, &rsp_type, &rsp_len);
578 if (data_len < 512) {
579 retval = ext_sd_send_cmd_get_rsp(chip,
SET_BLOCKLEN, data_len,
582 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
588 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
596 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
599 retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type,
600 sd_card->
rsp, rsp_len, 0);
602 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
604 if (data_len <= 512) {
617 memcpy(buf, data_buf, data_len);
620 if (data_len > 256) {
621 rts51x_init_cmd(chip);
622 for (i = 0; i < 256; i++) {
630 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
633 rts51x_init_cmd(chip);
642 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
645 rts51x_init_cmd(chip);
654 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
660 rts51x_init_cmd(chip);
663 (
u8) ((data_len >> 8) & 0x03));
678 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
682 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
683 }
else if (!(data_len & 0x1FF)) {
684 rts51x_init_cmd(chip);
689 0xFF, (
u8) (data_len >> 17));
691 0xFF, (
u8) ((data_len & 0x0001FE00) >> 9));
702 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
706 data_buf, buf_len, use_sg,
NULL,
709 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
713 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
716 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
723 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
729 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
737 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
740 if (data_len < 512) {
741 retval = ext_sd_send_cmd_get_rsp(chip,
SET_BLOCKLEN, 0x200,
744 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
750 if (cmd12 || standby) {
755 for (i = 0; i < 3; i++) {
764 TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed);
768 SD_Execute_Write_Cmd_Failed:
815 if ((0x53 != srb->
cmnd[2]) || (0x44 != srb->
cmnd[3])
816 || (0x20 != srb->
cmnd[4]) || (0x43 != srb->
cmnd[5])
817 || (0x61 != srb->
cmnd[6]) || (0x72 != srb->
cmnd[7])
818 || (0x64 != srb->
cmnd[8])) {
823 switch (srb->
cmnd[1] & 0x0F) {
838 buf[5] = (1 ==
CHK_SD(sd_card)) ? 0x01 : 0x02;
847 len =
min_t(
unsigned, 18, scsi_bufflen(srb));
867 cmd_idx = srb->
cmnd[2] & 0x3F;
868 if (srb->
cmnd[1] & 0x02)
870 if (srb->
cmnd[1] & 0x01)
876 rsp_code = srb->
cmnd[10];
881 scsi_set_resid(srb, 0);
898 cmd_idx = srb->
cmnd[2] & 0x3F;
899 if (srb->
cmnd[1] & 0x04)
901 if (srb->
cmnd[1] & 0x02)
903 if (srb->
cmnd[1] & 0x01)
912 rsp_code = srb->
cmnd[10];
916 acmd, rsp_code, arg, data_len,
917 scsi_sglist(srb), scsi_bufflen(srb),
919 scsi_set_resid(srb, 0);
936 cmd_idx = srb->
cmnd[2] & 0x3F;
937 if (srb->
cmnd[1] & 0x04)
939 if (srb->
cmnd[1] & 0x02)
941 if (srb->
cmnd[1] & 0x01)
950 rsp_code = srb->
cmnd[10];
954 acmd, rsp_code, arg, data_len,
955 scsi_sglist(srb), scsi_bufflen(srb),
957 scsi_set_resid(srb, 0);
979 data_len = ((
u16) srb->
cmnd[7] << 8) | srb->
cmnd[8];
985 count = (data_len < 17) ? data_len : 17;
987 count = (data_len < 6) ? data_len : 6;
993 sd_card->
rsp[0], sd_card->
rsp[1], sd_card->
rsp[2],
996 scsi_set_resid(srb, 0);
1017 if ((0x53 != srb->
cmnd[2]) || (0x44 != srb->
cmnd[3])
1018 || (0x20 != srb->
cmnd[4]) || (0x43 != srb->
cmnd[5])
1019 || (0x61 != srb->
cmnd[6]) || (0x72 != srb->
cmnd[7])
1020 || (0x64 != srb->
cmnd[8])) {
1025 switch (srb->
cmnd[1] & 0x0F) {
1052 scsi_set_resid(srb, 0);