1 /* Driver for Realtek RTS51xx USB card reader
3 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 * wwang (wei_wang@realsil.com.cn)
20 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
22 * Edwin Rong (edwin_rong@realsil.com.cn)
23 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
26 #include <linux/blkdev.h>
27 #include <linux/kthread.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
34 #include "rts51x_transport.h"
35 #include "rts51x_scsi.h"
36 #include "rts51x_card.h"
37 #include "rts51x_chip.h"
42 static inline int get_rsp_type(u8 rsp_code
, u8
*rsp_type
, int *rsp_len
)
44 if (!rsp_type
|| !rsp_len
)
49 *rsp_type
= SD_RSP_TYPE_R0
; /* no response */
54 *rsp_type
= SD_RSP_TYPE_R1
; /* R1,R6(,R4,R5) */
59 *rsp_type
= SD_RSP_TYPE_R1b
; /* R1b */
64 *rsp_type
= SD_RSP_TYPE_R2
; /* R2 */
69 *rsp_type
= SD_RSP_TYPE_R3
; /* R3 */
77 return STATUS_SUCCESS
;
80 int soft_reset_sd_card(struct rts51x_chip
*chip
)
82 return reset_sd(chip
);
85 int ext_sd_send_cmd_get_rsp(struct rts51x_chip
*chip
, u8 cmd_idx
,
86 u32 arg
, u8 rsp_type
, u8
*rsp
, int rsp_len
,
96 RTS51X_DEBUGP("EXT SD/MMC CMD %d\n", cmd_idx
);
98 if (rsp_type
== SD_RSP_TYPE_R1b
)
103 rts51x_init_cmd(chip
);
105 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD0
, 0xFF, 0x40 | cmd_idx
);
106 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD1
, 0xFF, (u8
) (arg
>> 24));
107 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD2
, 0xFF, (u8
) (arg
>> 16));
108 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD3
, 0xFF, (u8
) (arg
>> 8));
109 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD4
, 0xFF, (u8
) arg
);
111 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CFG2
, 0xFF, rsp_type
);
112 rts51x_add_cmd(chip
, WRITE_REG_CMD
, CARD_DATA_SOURCE
,
113 0x01, PINGPONG_BUFFER
);
114 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_TRANSFER
,
115 0xFF, SD_TM_CMD_RSP
| SD_TRANSFER_START
);
116 rts51x_add_cmd(chip
, CHECK_REG_CMD
, SD_TRANSFER
, SD_TRANSFER_END
,
119 rts51x_add_cmd(chip
, READ_REG_CMD
, SD_STAT1
, 0, 0);
121 if (CHECK_USB(chip
, USB_20
)) {
122 if (rsp_type
== SD_RSP_TYPE_R2
) {
123 for (reg_addr
= PPBUF_BASE2
;
124 reg_addr
< PPBUF_BASE2
+ 16; reg_addr
++) {
125 rts51x_add_cmd(chip
, READ_REG_CMD
, reg_addr
, 0,
129 } else if (rsp_type
!= SD_RSP_TYPE_R0
) {
130 /* Read data from SD_CMDx registers */
131 for (reg_addr
= SD_CMD0
; reg_addr
<= SD_CMD4
;
133 rts51x_add_cmd(chip
, READ_REG_CMD
, reg_addr
, 0,
140 rts51x_add_cmd(chip
, READ_REG_CMD
, SD_CMD5
, 0, 0);
145 retval
= rts51x_send_cmd(chip
, MODE_CR
, 100);
146 if (retval
!= STATUS_SUCCESS
)
147 TRACE_RET(chip
, retval
);
149 retval
= rts51x_get_rsp(chip
, len
, timeout
);
151 if (CHECK_SD_TRANS_FAIL(chip
, retval
)) {
152 rts51x_clear_sd_error(chip
);
154 if (retval
== STATUS_TIMEDOUT
) {
155 if (rsp_type
& SD_WAIT_BUSY_END
) {
156 retval
= sd_check_data0_status(chip
);
157 if (retval
!= STATUS_SUCCESS
)
158 TRACE_RET(chip
, retval
);
161 TRACE_RET(chip
, STATUS_FAIL
);
164 if (rsp_type
== SD_RSP_TYPE_R0
)
165 return STATUS_SUCCESS
;
167 if (CHECK_USB(chip
, USB_20
)) {
168 rts51x_read_rsp_buf(chip
, 2, buf
, len
- 2);
170 if (rsp_type
== SD_RSP_TYPE_R2
) {
171 reg_addr
= PPBUF_BASE2
;
178 rts51x_seq_read_register(chip
, reg_addr
,
179 (unsigned short)len
, buf
);
180 if (retval
!= STATUS_SUCCESS
)
181 TRACE_RET(chip
, retval
);
182 RTS51X_READ_REG(chip
, SD_CMD5
, buf
+ len
);
184 stat
= chip
->rsp_buf
[1];
186 if ((buf
[0] & 0xC0) != 0)
187 TRACE_RET(chip
, STATUS_FAIL
);
189 if (!(rsp_type
& SD_NO_CHECK_CRC7
)) {
190 if (stat
& SD_CRC7_ERR
) {
191 if (cmd_idx
== WRITE_MULTIPLE_BLOCK
)
192 TRACE_RET(chip
, STATUS_FAIL
);
193 if (rty_cnt
< SD_MAX_RETRY_COUNT
) {
198 TRACE_RET(chip
, STATUS_FAIL
);
203 if ((cmd_idx
== SELECT_CARD
) || (cmd_idx
== APP_CMD
) ||
204 (cmd_idx
== SEND_STATUS
) || (cmd_idx
== STOP_TRANSMISSION
)) {
205 if ((cmd_idx
!= STOP_TRANSMISSION
) && (special_check
== 0)) {
207 TRACE_RET(chip
, STATUS_FAIL
);
209 #ifdef SUPPORT_SD_LOCK
214 TRACE_RET(chip
, STATUS_FAIL
);
217 TRACE_RET(chip
, STATUS_FAIL
);
219 if (cmd_idx
== SELECT_CARD
) {
220 if (rsp_type
== SD_RSP_TYPE_R2
) {
221 if ((buf
[3] & 0x1E) != 0x04)
222 TRACE_RET(chip
, STATUS_FAIL
);
223 } else if (rsp_type
== SD_RSP_TYPE_R2
) {
224 if ((buf
[3] & 0x1E) != 0x03)
225 TRACE_RET(chip
, STATUS_FAIL
);
231 memcpy(rsp
, buf
, rsp_len
);
233 return STATUS_SUCCESS
;
236 int ext_sd_get_rsp(struct rts51x_chip
*chip
, int len
, u8
* rsp
, u8 rsp_type
)
241 if (rsp_type
== SD_RSP_TYPE_R0
)
242 return STATUS_SUCCESS
;
244 rts51x_init_cmd(chip
);
246 if (rsp_type
== SD_RSP_TYPE_R2
) {
247 for (reg_addr
= PPBUF_BASE2
; reg_addr
< PPBUF_BASE2
+ 16;
249 rts51x_add_cmd(chip
, READ_REG_CMD
, reg_addr
, 0xFF, 0);
252 } else if (rsp_type
!= SD_RSP_TYPE_R0
) {
253 for (reg_addr
= SD_CMD0
; reg_addr
<= SD_CMD4
; reg_addr
++)
254 rts51x_add_cmd(chip
, READ_REG_CMD
, reg_addr
, 0xFF, 0);
257 rts51x_add_cmd(chip
, READ_REG_CMD
, SD_CMD5
, 0xFF, 0);
259 retval
= rts51x_send_cmd(chip
, MODE_CR
, 100);
260 if (retval
!= STATUS_SUCCESS
)
261 TRACE_RET(chip
, retval
);
263 retval
= rts51x_get_rsp(chip
, rsp_len
, 100);
265 if (retval
!= STATUS_SUCCESS
)
266 TRACE_RET(chip
, retval
);
269 int min_len
= (rsp_len
< len
) ? rsp_len
: len
;
271 memcpy(rsp
, rts51x_get_rsp_data(chip
), min_len
);
273 RTS51X_DEBUGP("min_len = %d\n", min_len
);
274 RTS51X_DEBUGP("Response in cmd buf: 0x%x 0x%x 0x%x 0x%x\n",
275 rsp
[0], rsp
[1], rsp
[2], rsp
[3]);
278 return STATUS_SUCCESS
;
281 int ext_sd_execute_no_data(struct rts51x_chip
*chip
, unsigned int lun
,
282 u8 cmd_idx
, u8 standby
, u8 acmd
, u8 rsp_code
,
285 struct sd_info
*sd_card
= &(chip
->sd_card
);
289 retval
= sd_switch_clock(chip
);
290 if (retval
!= STATUS_SUCCESS
)
291 TRACE_RET(chip
, TRANSPORT_FAILED
);
293 if (sd_card
->pre_cmd_err
) {
294 sd_card
->pre_cmd_err
= 0;
295 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
296 TRACE_RET(chip
, TRANSPORT_FAILED
);
298 retval
= get_rsp_type(rsp_code
, &rsp_type
, &rsp_len
);
299 if (retval
!= STATUS_SUCCESS
) {
300 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
301 TRACE_RET(chip
, TRANSPORT_FAILED
);
303 sd_card
->last_rsp_type
= rsp_type
;
305 retval
= sd_switch_clock(chip
);
306 if (retval
!= STATUS_SUCCESS
)
307 TRACE_RET(chip
, TRANSPORT_FAILED
);
308 #ifdef SUPPORT_SD_LOCK
309 if ((sd_card
->sd_lock_status
& SD_LOCK_1BIT_MODE
) == 0) {
310 if (CHK_MMC_8BIT(sd_card
)) {
312 rts51x_write_register(chip
, SD_CFG1
, 0x03,
314 if (retval
!= STATUS_SUCCESS
)
315 TRACE_RET(chip
, TRANSPORT_FAILED
);
316 } else if (CHK_SD(sd_card
) || CHK_MMC_4BIT(sd_card
)) {
318 rts51x_write_register(chip
, SD_CFG1
, 0x03,
320 if (retval
!= STATUS_SUCCESS
)
321 TRACE_RET(chip
, TRANSPORT_FAILED
);
325 /* Set H/W SD/MMC Bus Width */
326 rts51x_write_register(chip
, SD_CFG1
, 0x03, SD_BUS_WIDTH_4
);
330 retval
= sd_select_card(chip
, 0);
331 if (retval
!= STATUS_SUCCESS
)
332 TRACE_GOTO(chip
, SD_Execute_Cmd_Failed
);
337 ext_sd_send_cmd_get_rsp(chip
, APP_CMD
, sd_card
->sd_addr
,
338 SD_RSP_TYPE_R1
, NULL
, 0, 0);
339 if (retval
!= STATUS_SUCCESS
)
340 TRACE_GOTO(chip
, SD_Execute_Cmd_Failed
);
343 retval
= ext_sd_send_cmd_get_rsp(chip
, cmd_idx
, arg
, rsp_type
,
344 sd_card
->rsp
, rsp_len
, 0);
345 if (retval
!= STATUS_SUCCESS
)
346 TRACE_GOTO(chip
, SD_Execute_Cmd_Failed
);
349 retval
= sd_select_card(chip
, 1);
350 if (retval
!= STATUS_SUCCESS
)
351 TRACE_GOTO(chip
, SD_Execute_Cmd_Failed
);
353 #ifdef SUPPORT_SD_LOCK
354 /* Get SD lock status */
355 retval
= sd_update_lock_status(chip
);
356 if (retval
!= STATUS_SUCCESS
)
357 TRACE_GOTO(chip
, SD_Execute_Cmd_Failed
);
360 return TRANSPORT_GOOD
;
362 SD_Execute_Cmd_Failed
:
363 sd_card
->pre_cmd_err
= 1;
364 set_sense_type(chip
, lun
, SENSE_TYPE_NO_SENSE
);
365 release_sd_card(chip
);
366 do_reset_sd_card(chip
);
367 if (!(chip
->card_ready
& SD_CARD
))
368 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
370 TRACE_RET(chip
, TRANSPORT_FAILED
);
373 int ext_sd_execute_read_data(struct rts51x_chip
*chip
, unsigned int lun
,
374 u8 cmd_idx
, u8 cmd12
, u8 standby
,
375 u8 acmd
, u8 rsp_code
, u32 arg
, u32 data_len
,
376 void *data_buf
, unsigned int buf_len
, int use_sg
)
378 struct sd_info
*sd_card
= &(chip
->sd_card
);
379 int retval
, rsp_len
, i
;
380 int cmd13_checkbit
= 0, read_err
= 0;
381 u8 rsp_type
, bus_width
;
383 if (sd_card
->pre_cmd_err
) {
384 sd_card
->pre_cmd_err
= 0;
385 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
386 TRACE_RET(chip
, TRANSPORT_FAILED
);
389 retval
= sd_switch_clock(chip
);
390 if (retval
!= STATUS_SUCCESS
)
391 TRACE_RET(chip
, STATUS_FAIL
);
392 retval
= get_rsp_type(rsp_code
, &rsp_type
, &rsp_len
);
393 if (retval
!= STATUS_SUCCESS
) {
394 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
395 TRACE_RET(chip
, TRANSPORT_FAILED
);
397 sd_card
->last_rsp_type
= rsp_type
;
399 retval
= sd_switch_clock(chip
);
400 if (retval
!= STATUS_SUCCESS
)
401 TRACE_RET(chip
, TRANSPORT_FAILED
);
402 #ifdef SUPPORT_SD_LOCK
403 if ((sd_card
->sd_lock_status
& SD_LOCK_1BIT_MODE
) == 0) {
404 if (CHK_MMC_8BIT(sd_card
))
405 bus_width
= SD_BUS_WIDTH_8
;
406 else if (CHK_SD(sd_card
) || CHK_MMC_4BIT(sd_card
))
407 bus_width
= SD_BUS_WIDTH_4
;
409 bus_width
= SD_BUS_WIDTH_1
;
411 bus_width
= SD_BUS_WIDTH_4
;
413 RTS51X_DEBUGP("bus_width = %d\n", bus_width
);
415 bus_width
= SD_BUS_WIDTH_4
;
418 if (data_len
< 512) {
419 retval
= ext_sd_send_cmd_get_rsp(chip
, SET_BLOCKLEN
, data_len
,
420 SD_RSP_TYPE_R1
, NULL
, 0, 0);
421 if (retval
!= STATUS_SUCCESS
)
422 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
426 retval
= sd_select_card(chip
, 0);
427 if (retval
!= STATUS_SUCCESS
)
428 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
433 ext_sd_send_cmd_get_rsp(chip
, APP_CMD
, sd_card
->sd_addr
,
434 SD_RSP_TYPE_R1
, NULL
, 0, 0);
435 if (retval
!= STATUS_SUCCESS
)
436 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
439 if (data_len
<= 512) {
442 u16 byte_cnt
, blk_cnt
;
444 unsigned int offset
= 0;
447 byte_cnt
= (u16
) (data_len
& 0x3FF);
450 cmd
[0] = 0x40 | cmd_idx
;
451 cmd
[1] = (u8
) (arg
>> 24);
452 cmd
[2] = (u8
) (arg
>> 16);
453 cmd
[3] = (u8
) (arg
>> 8);
456 buf
= kmalloc(data_len
, GFP_KERNEL
);
458 TRACE_RET(chip
, TRANSPORT_ERROR
);
460 retval
= sd_read_data(chip
, SD_TM_NORMAL_READ
, cmd
, 5, byte_cnt
,
461 blk_cnt
, bus_width
, buf
, data_len
, 2000);
462 if (retval
!= STATUS_SUCCESS
) {
465 rts51x_write_register(chip
, CARD_STOP
,
466 SD_STOP
| SD_CLR_ERR
,
467 SD_STOP
| SD_CLR_ERR
);
468 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
471 min_len
= min(data_len
, buf_len
);
473 rts51x_access_sglist(buf
, min_len
, (void *)data_buf
,
474 &sg
, &offset
, TO_XFER_BUF
);
476 memcpy(data_buf
, buf
, min_len
);
479 } else if (!(data_len
& 0x1FF)) {
480 rts51x_init_cmd(chip
);
481 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BYTE_CNT_H
, 0xFF, 0x02);
482 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BYTE_CNT_L
, 0xFF, 0x00);
483 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BLOCK_CNT_H
,
484 0xFF, (u8
) (data_len
>> 17));
485 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BLOCK_CNT_L
,
486 0xFF, (u8
) ((data_len
& 0x0001FE00) >> 9));
487 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD0
, 0xFF,
489 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD1
, 0xFF,
491 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD2
, 0xFF,
493 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD3
, 0xFF,
495 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CMD4
, 0xFF, (u8
) arg
);
496 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CFG1
, 0x03, bus_width
);
497 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_CFG2
, 0xFF, rsp_type
);
498 trans_dma_enable(DMA_FROM_DEVICE
, chip
, data_len
, DMA_512
);
499 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_TRANSFER
, 0xFF,
500 SD_TM_AUTO_READ_2
| SD_TRANSFER_START
);
501 rts51x_add_cmd(chip
, CHECK_REG_CMD
, SD_TRANSFER
,
502 SD_TRANSFER_END
, SD_TRANSFER_END
);
503 retval
= rts51x_send_cmd(chip
, MODE_CDIR
, 100);
504 if (retval
!= STATUS_SUCCESS
) {
506 rts51x_ep0_write_register(chip
, CARD_STOP
,
507 SD_STOP
| SD_CLR_ERR
,
508 SD_STOP
| SD_CLR_ERR
);
509 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
513 rts51x_transfer_data_rcc(chip
, RCV_BULK_PIPE(chip
),
514 data_buf
, buf_len
, use_sg
, NULL
,
516 if (retval
!= STATUS_SUCCESS
) {
518 rts51x_ep0_write_register(chip
, CARD_STOP
,
519 SD_STOP
| SD_CLR_ERR
,
520 SD_STOP
| SD_CLR_ERR
);
521 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
523 retval
= rts51x_get_rsp(chip
, 1, 500);
524 if (CHECK_SD_TRANS_FAIL(chip
, retval
)) {
526 rts51x_ep0_write_register(chip
, CARD_STOP
,
527 SD_STOP
| SD_CLR_ERR
,
528 SD_STOP
| SD_CLR_ERR
);
529 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
532 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
535 retval
= ext_sd_get_rsp(chip
, rsp_len
, sd_card
->rsp
, rsp_type
);
536 if (retval
!= STATUS_SUCCESS
)
537 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
540 retval
= sd_select_card(chip
, 1);
541 if (retval
!= STATUS_SUCCESS
)
542 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
546 retval
= ext_sd_send_cmd_get_rsp(chip
, STOP_TRANSMISSION
,
547 0, SD_RSP_TYPE_R1b
, NULL
, 0,
549 if (retval
!= STATUS_SUCCESS
)
550 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
553 if (data_len
< 512) {
554 retval
= ext_sd_send_cmd_get_rsp(chip
, SET_BLOCKLEN
, 0x200,
555 SD_RSP_TYPE_R1
, NULL
, 0, 0);
556 if (retval
!= STATUS_SUCCESS
)
557 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
559 rts51x_write_register(chip
, SD_BYTE_CNT_H
, 0xFF, 0x02);
560 rts51x_write_register(chip
, SD_BYTE_CNT_L
, 0xFF, 0x00);
563 if (standby
|| cmd12
)
566 for (i
= 0; i
< 3; i
++) {
568 ext_sd_send_cmd_get_rsp(chip
, SEND_STATUS
, sd_card
->sd_addr
,
569 SD_RSP_TYPE_R1
, NULL
, 0,
571 if (retval
== STATUS_SUCCESS
)
574 if (retval
!= STATUS_SUCCESS
)
575 TRACE_GOTO(chip
, SD_Execute_Read_Cmd_Failed
);
577 return TRANSPORT_GOOD
;
579 SD_Execute_Read_Cmd_Failed
:
580 sd_card
->pre_cmd_err
= 1;
581 set_sense_type(chip
, lun
, SENSE_TYPE_NO_SENSE
);
583 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR
);
584 release_sd_card(chip
);
585 do_reset_sd_card(chip
);
586 if (!(chip
->card_ready
& SD_CARD
))
587 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
589 TRACE_RET(chip
, TRANSPORT_FAILED
);
592 int ext_sd_execute_write_data(struct rts51x_chip
*chip
, unsigned int lun
,
593 u8 cmd_idx
, u8 cmd12
, u8 standby
, u8 acmd
,
594 u8 rsp_code
, u32 arg
, u32 data_len
,
595 void *data_buf
, unsigned int buf_len
, int use_sg
)
597 struct sd_info
*sd_card
= &(chip
->sd_card
);
599 int cmd13_checkbit
= 0, write_err
= 0;
602 #ifdef SUPPORT_SD_LOCK
603 int lock_cmd_fail
= 0;
604 u8 sd_lock_state
= 0;
605 u8 lock_cmd_type
= 0;
608 if (sd_card
->pre_cmd_err
) {
609 sd_card
->pre_cmd_err
= 0;
610 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
611 TRACE_RET(chip
, TRANSPORT_FAILED
);
614 retval
= sd_switch_clock(chip
);
615 if (retval
!= STATUS_SUCCESS
)
616 TRACE_RET(chip
, STATUS_FAIL
);
617 #ifdef SUPPORT_SD_LOCK
618 if (cmd_idx
== LOCK_UNLOCK
) {
619 sd_lock_state
= sd_card
->sd_lock_status
;
620 sd_lock_state
&= SD_LOCKED
;
624 retval
= get_rsp_type(rsp_code
, &rsp_type
, &rsp_len
);
625 if (retval
!= STATUS_SUCCESS
) {
626 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
627 TRACE_RET(chip
, TRANSPORT_FAILED
);
629 sd_card
->last_rsp_type
= rsp_type
;
631 retval
= sd_switch_clock(chip
);
632 if (retval
!= STATUS_SUCCESS
)
633 TRACE_RET(chip
, TRANSPORT_FAILED
);
634 #ifdef SUPPORT_SD_LOCK
635 if ((sd_card
->sd_lock_status
& SD_LOCK_1BIT_MODE
) == 0) {
636 if (CHK_MMC_8BIT(sd_card
)) {
638 rts51x_write_register(chip
, SD_CFG1
, 0x03,
640 if (retval
!= STATUS_SUCCESS
)
641 TRACE_RET(chip
, TRANSPORT_FAILED
);
642 } else if (CHK_SD(sd_card
) || CHK_MMC_4BIT(sd_card
)) {
644 rts51x_write_register(chip
, SD_CFG1
, 0x03,
646 if (retval
!= STATUS_SUCCESS
)
647 TRACE_RET(chip
, TRANSPORT_FAILED
);
651 rts51x_write_register(chip
, SD_CFG1
, 0x03, SD_BUS_WIDTH_4
);
654 if (data_len
< 512) {
655 retval
= ext_sd_send_cmd_get_rsp(chip
, SET_BLOCKLEN
, data_len
,
656 SD_RSP_TYPE_R1
, NULL
, 0, 0);
657 if (retval
!= STATUS_SUCCESS
)
658 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
662 retval
= sd_select_card(chip
, 0);
663 if (retval
!= STATUS_SUCCESS
)
664 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
669 ext_sd_send_cmd_get_rsp(chip
, APP_CMD
, sd_card
->sd_addr
,
670 SD_RSP_TYPE_R1
, NULL
, 0, 0);
671 if (retval
!= STATUS_SUCCESS
)
672 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
675 retval
= ext_sd_send_cmd_get_rsp(chip
, cmd_idx
, arg
, rsp_type
,
676 sd_card
->rsp
, rsp_len
, 0);
677 if (retval
!= STATUS_SUCCESS
)
678 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
680 if (data_len
<= 512) {
682 unsigned int offset
= 0;
685 buf
= kmalloc(data_len
, GFP_KERNEL
);
687 TRACE_RET(chip
, TRANSPORT_ERROR
);
690 rts51x_access_sglist(buf
, data_len
, (void *)data_buf
,
691 &sg
, &offset
, FROM_XFER_BUF
);
693 memcpy(buf
, data_buf
, data_len
);
695 #ifdef SUPPORT_SD_LOCK
696 if (cmd_idx
== LOCK_UNLOCK
)
697 lock_cmd_type
= buf
[0] & 0x0F;
700 if (data_len
> 256) {
701 rts51x_init_cmd(chip
);
702 for (i
= 0; i
< 256; i
++) {
703 rts51x_add_cmd(chip
, WRITE_REG_CMD
,
704 (u16
) (PPBUF_BASE2
+ i
), 0xFF,
707 retval
= rts51x_send_cmd(chip
, MODE_C
, 250);
708 if (retval
!= STATUS_SUCCESS
) {
710 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
713 rts51x_init_cmd(chip
);
714 for (i
= 256; i
< data_len
; i
++) {
715 rts51x_add_cmd(chip
, WRITE_REG_CMD
,
716 (u16
) (PPBUF_BASE2
+ i
), 0xFF,
719 retval
= rts51x_send_cmd(chip
, MODE_C
, 250);
720 if (retval
!= STATUS_SUCCESS
) {
722 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
725 rts51x_init_cmd(chip
);
726 for (i
= 0; i
< data_len
; i
++) {
727 rts51x_add_cmd(chip
, WRITE_REG_CMD
,
728 (u16
) (PPBUF_BASE2
+ i
), 0xFF,
731 retval
= rts51x_send_cmd(chip
, MODE_C
, 250);
732 if (retval
!= STATUS_SUCCESS
) {
734 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
740 rts51x_init_cmd(chip
);
742 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BYTE_CNT_H
, 0xFF,
743 (u8
) ((data_len
>> 8) & 0x03));
744 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BYTE_CNT_L
, 0xFF,
746 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BLOCK_CNT_H
, 0xFF, 0x00);
747 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BLOCK_CNT_L
, 0xFF, 0x01);
748 rts51x_add_cmd(chip
, WRITE_REG_CMD
, CARD_DATA_SOURCE
, 0x01,
751 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_TRANSFER
, 0xFF,
752 SD_TM_AUTO_WRITE_3
| SD_TRANSFER_START
);
753 rts51x_add_cmd(chip
, CHECK_REG_CMD
, SD_TRANSFER
,
754 SD_TRANSFER_END
, SD_TRANSFER_END
);
756 retval
= rts51x_send_cmd(chip
, MODE_CR
, 100);
757 if (retval
!= STATUS_SUCCESS
)
758 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
760 retval
= rts51x_get_rsp(chip
, 1, 250);
761 if (CHECK_SD_TRANS_FAIL(chip
, retval
))
762 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
763 } else if (!(data_len
& 0x1FF)) {
764 rts51x_init_cmd(chip
);
766 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BYTE_CNT_H
, 0xFF, 0x02);
767 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BYTE_CNT_L
, 0xFF, 0x00);
768 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BLOCK_CNT_H
,
769 0xFF, (u8
) (data_len
>> 17));
770 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_BLOCK_CNT_L
,
771 0xFF, (u8
) ((data_len
& 0x0001FE00) >> 9));
773 trans_dma_enable(DMA_TO_DEVICE
, chip
, data_len
, DMA_512
);
775 rts51x_add_cmd(chip
, WRITE_REG_CMD
, SD_TRANSFER
, 0xFF,
776 SD_TM_AUTO_WRITE_3
| SD_TRANSFER_START
);
777 rts51x_add_cmd(chip
, CHECK_REG_CMD
, SD_TRANSFER
,
778 SD_TRANSFER_END
, SD_TRANSFER_END
);
780 retval
= rts51x_send_cmd(chip
, MODE_CDOR
, 100);
781 if (retval
!= STATUS_SUCCESS
)
782 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
785 rts51x_transfer_data_rcc(chip
, SND_BULK_PIPE(chip
),
786 data_buf
, buf_len
, use_sg
, NULL
,
788 if (retval
!= STATUS_SUCCESS
)
789 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
791 retval
= rts51x_get_rsp(chip
, 1, 10000);
792 if (CHECK_SD_TRANS_FAIL(chip
, retval
))
793 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
796 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
801 rts51x_write_register(chip
, CARD_STOP
, SD_STOP
| SD_CLR_ERR
,
802 SD_STOP
| SD_CLR_ERR
);
803 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
805 #ifdef SUPPORT_SD_LOCK
806 if (cmd_idx
== LOCK_UNLOCK
) {
807 if (lock_cmd_type
== SD_ERASE
) {
808 sd_card
->sd_erase_status
= SD_UNDER_ERASING
;
809 scsi_set_resid(srb
, 0);
810 return TRANSPORT_GOOD
;
813 rts51x_init_cmd(chip
);
814 rts51x_add_cmd(chip
, CHECK_REG_CMD
, SD_BUS_STAT
, SD_DAT0_STATUS
,
816 retval
= rts51x_send_cmd(chip
, MODE_CR
, 250);
817 if (retval
!= STATUS_SUCCESS
)
818 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
819 rts51x_get_rsp(chip
, 1, 200); /* Don't care return value */
821 retval
= sd_update_lock_status(chip
);
822 if (retval
!= STATUS_SUCCESS
) {
823 RTS51X_DEBUGP("Lock command fail!\n");
827 #endif /* SUPPORT_SD_LOCK */
830 retval
= sd_select_card(chip
, 1);
831 if (retval
!= STATUS_SUCCESS
)
832 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
836 retval
= ext_sd_send_cmd_get_rsp(chip
, STOP_TRANSMISSION
,
837 0, SD_RSP_TYPE_R1b
, NULL
, 0,
839 if (retval
!= STATUS_SUCCESS
)
840 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
843 if (data_len
< 512) {
844 retval
= ext_sd_send_cmd_get_rsp(chip
, SET_BLOCKLEN
, 0x200,
845 SD_RSP_TYPE_R1
, NULL
, 0, 0);
846 if (retval
!= STATUS_SUCCESS
)
847 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
849 rts51x_write_register(chip
, SD_BYTE_CNT_H
, 0xFF, 0x02);
850 rts51x_write_register(chip
, SD_BYTE_CNT_L
, 0xFF, 0x00);
853 if (cmd12
|| standby
) {
854 /* There is CMD7 or CMD12 sent before CMD13 */
858 for (i
= 0; i
< 3; i
++) {
860 ext_sd_send_cmd_get_rsp(chip
, SEND_STATUS
, sd_card
->sd_addr
,
861 SD_RSP_TYPE_R1
, NULL
, 0,
863 if (retval
== STATUS_SUCCESS
)
866 if (retval
!= STATUS_SUCCESS
)
867 TRACE_GOTO(chip
, SD_Execute_Write_Cmd_Failed
);
868 #ifdef SUPPORT_SD_LOCK
869 if (cmd_idx
== LOCK_UNLOCK
) {
870 if (!lock_cmd_fail
) {
871 RTS51X_DEBUGP("lock_cmd_type = 0x%x\n",
873 if (lock_cmd_type
& SD_CLR_PWD
)
874 sd_card
->sd_lock_status
&= ~SD_PWD_EXIST
;
875 if (lock_cmd_type
& SD_SET_PWD
)
876 sd_card
->sd_lock_status
|= SD_PWD_EXIST
;
879 RTS51X_DEBUGP("sd_lock_state = 0x%x,"
880 "sd_card->sd_lock_status = 0x%x\n",
881 sd_lock_state
, sd_card
->sd_lock_status
);
882 if (sd_lock_state
^ (sd_card
->sd_lock_status
& SD_LOCKED
)) {
883 sd_card
->sd_lock_notify
= 1;
885 if (sd_card
->sd_lock_status
&
887 sd_card
->sd_lock_status
|=
888 (SD_UNLOCK_POW_ON
| SD_SDR_RST
);
889 if (CHK_SD(sd_card
)) {
890 retval
= reset_sd(chip
);
891 if (retval
!= STATUS_SUCCESS
) {
892 sd_card
->sd_lock_status
893 &= ~(SD_UNLOCK_POW_ON
|
896 SD_Execute_Write_Cmd_Failed
);
900 sd_card
->sd_lock_status
&=
901 ~(SD_UNLOCK_POW_ON
| SD_SDR_RST
);
908 scsi_set_resid(srb
, 0);
909 set_sense_type(chip
, lun
, SENSE_TYPE_NO_SENSE
);
910 TRACE_RET(chip
, TRANSPORT_FAILED
);
912 #endif /* SUPPORT_SD_LOCK */
914 return TRANSPORT_GOOD
;
916 SD_Execute_Write_Cmd_Failed
:
917 sd_card
->pre_cmd_err
= 1;
918 set_sense_type(chip
, lun
, SENSE_TYPE_NO_SENSE
);
920 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_WRITE_ERR
);
921 release_sd_card(chip
);
922 do_reset_sd_card(chip
);
923 if (!(chip
->card_ready
& SD_CARD
))
924 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
926 TRACE_RET(chip
, TRANSPORT_FAILED
);
929 int sd_pass_thru_mode(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
931 struct sd_info
*sd_card
= &(chip
->sd_card
);
932 unsigned int lun
= SCSI_LUN(srb
);
939 0x00, /* Version Number */
940 0x00, /* WP | Media Type */
941 0x00, /* RCA (Low byte) */
942 0x00, /* RCA (High byte) */
950 0x00, /* Max LUN Number */
955 sd_card
->pre_cmd_err
= 0;
957 if (!(CHK_BIT(chip
->lun_mc
, lun
))) {
958 SET_BIT(chip
->lun_mc
, lun
);
959 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
960 TRACE_RET(chip
, TRANSPORT_FAILED
);
963 if ((0x53 != srb
->cmnd
[2]) || (0x44 != srb
->cmnd
[3])
964 || (0x20 != srb
->cmnd
[4]) || (0x43 != srb
->cmnd
[5])
965 || (0x61 != srb
->cmnd
[6]) || (0x72 != srb
->cmnd
[7])
966 || (0x64 != srb
->cmnd
[8])) {
967 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
968 TRACE_RET(chip
, TRANSPORT_FAILED
);
971 switch (srb
->cmnd
[1] & 0x0F) {
973 sd_card
->sd_pass_thru_en
= 0;
977 sd_card
->sd_pass_thru_en
= 1;
981 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
982 TRACE_RET(chip
, TRANSPORT_FAILED
);
985 /* 0x01:SD Memory Card; 0x02:Other Media; 0x03:Illegal Media; */
986 buf
[5] = (1 == CHK_SD(sd_card
)) ? 0x01 : 0x02;
987 if (chip
->card_wp
& SD_CARD
)
990 buf
[6] = (u8
) (sd_card
->sd_addr
>> 16);
991 buf
[7] = (u8
) (sd_card
->sd_addr
>> 24);
993 buf
[15] = chip
->max_lun
;
995 len
= min(18, (int)scsi_bufflen(srb
));
996 rts51x_set_xfer_buf(buf
, len
, srb
);
998 return TRANSPORT_GOOD
;
1001 int sd_execute_no_data(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1003 struct sd_info
*sd_card
= &(chip
->sd_card
);
1004 unsigned int lun
= SCSI_LUN(srb
);
1006 u8 cmd_idx
, rsp_code
;
1007 u8 standby
= 0, acmd
= 0;
1010 if (!sd_card
->sd_pass_thru_en
) {
1011 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1012 TRACE_RET(chip
, TRANSPORT_FAILED
);
1015 cmd_idx
= srb
->cmnd
[2] & 0x3F;
1016 if (srb
->cmnd
[1] & 0x02)
1018 if (srb
->cmnd
[1] & 0x01)
1021 arg
= ((u32
) srb
->cmnd
[3] << 24) | ((u32
) srb
->cmnd
[4] << 16) |
1022 ((u32
) srb
->cmnd
[5] << 8) | srb
->cmnd
[6];
1024 rsp_code
= srb
->cmnd
[10];
1027 ext_sd_execute_no_data(chip
, lun
, cmd_idx
, standby
, acmd
, rsp_code
,
1029 scsi_set_resid(srb
, 0);
1033 int sd_execute_read_data(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1035 struct sd_info
*sd_card
= &(chip
->sd_card
);
1037 unsigned int lun
= SCSI_LUN(srb
);
1038 u8 cmd_idx
, rsp_code
, send_cmd12
= 0, standby
= 0, acmd
= 0;
1041 if (!sd_card
->sd_pass_thru_en
) {
1042 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1043 TRACE_RET(chip
, TRANSPORT_FAILED
);
1046 cmd_idx
= srb
->cmnd
[2] & 0x3F;
1047 if (srb
->cmnd
[1] & 0x04)
1049 if (srb
->cmnd
[1] & 0x02)
1051 if (srb
->cmnd
[1] & 0x01)
1054 arg
= ((u32
) srb
->cmnd
[3] << 24) | ((u32
) srb
->cmnd
[4] << 16) |
1055 ((u32
) srb
->cmnd
[5] << 8) | srb
->cmnd
[6];
1058 ((u32
) srb
->cmnd
[7] << 16) | ((u32
) srb
->cmnd
[8] << 8) |
1060 rsp_code
= srb
->cmnd
[10];
1063 ext_sd_execute_read_data(chip
, lun
, cmd_idx
, send_cmd12
, standby
,
1064 acmd
, rsp_code
, arg
, data_len
,
1065 scsi_sglist(srb
), scsi_bufflen(srb
),
1066 scsi_sg_count(srb
));
1067 scsi_set_resid(srb
, 0);
1071 int sd_execute_write_data(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1073 struct sd_info
*sd_card
= &(chip
->sd_card
);
1075 unsigned int lun
= SCSI_LUN(srb
);
1076 u8 cmd_idx
, rsp_code
, send_cmd12
= 0, standby
= 0, acmd
= 0;
1079 if (!sd_card
->sd_pass_thru_en
) {
1080 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1081 TRACE_RET(chip
, TRANSPORT_FAILED
);
1084 cmd_idx
= srb
->cmnd
[2] & 0x3F;
1085 if (srb
->cmnd
[1] & 0x04)
1087 if (srb
->cmnd
[1] & 0x02)
1089 if (srb
->cmnd
[1] & 0x01)
1093 ((u32
) srb
->cmnd
[7] << 16) | ((u32
) srb
->cmnd
[8] << 8) |
1096 ((u32
) srb
->cmnd
[3] << 24) | ((u32
) srb
->cmnd
[4] << 16) |
1097 ((u32
) srb
->cmnd
[5] << 8) | srb
->cmnd
[6];
1098 rsp_code
= srb
->cmnd
[10];
1101 ext_sd_execute_write_data(chip
, lun
, cmd_idx
, send_cmd12
, standby
,
1102 acmd
, rsp_code
, arg
, data_len
,
1103 scsi_sglist(srb
), scsi_bufflen(srb
),
1104 scsi_sg_count(srb
));
1105 scsi_set_resid(srb
, 0);
1109 int sd_get_cmd_rsp(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1111 struct sd_info
*sd_card
= &(chip
->sd_card
);
1112 unsigned int lun
= SCSI_LUN(srb
);
1116 if (!sd_card
->sd_pass_thru_en
) {
1117 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1118 TRACE_RET(chip
, TRANSPORT_FAILED
);
1121 if (sd_card
->pre_cmd_err
) {
1122 sd_card
->pre_cmd_err
= 0;
1123 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
1124 TRACE_RET(chip
, TRANSPORT_FAILED
);
1127 data_len
= ((u16
) srb
->cmnd
[7] << 8) | srb
->cmnd
[8];
1129 if (sd_card
->last_rsp_type
== SD_RSP_TYPE_R0
) {
1130 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1131 TRACE_RET(chip
, TRANSPORT_FAILED
);
1132 } else if (sd_card
->last_rsp_type
== SD_RSP_TYPE_R2
) {
1133 count
= (data_len
< 17) ? data_len
: 17;
1135 count
= (data_len
< 6) ? data_len
: 6;
1137 rts51x_set_xfer_buf(sd_card
->rsp
, count
, srb
);
1139 RTS51X_DEBUGP("Response length: %d\n", data_len
);
1140 RTS51X_DEBUGP("Response: 0x%x 0x%x 0x%x 0x%x\n",
1141 sd_card
->rsp
[0], sd_card
->rsp
[1], sd_card
->rsp
[2],
1144 scsi_set_resid(srb
, 0);
1145 return TRANSPORT_GOOD
;
1148 int sd_hw_rst(struct scsi_cmnd
*srb
, struct rts51x_chip
*chip
)
1150 struct sd_info
*sd_card
= &(chip
->sd_card
);
1151 unsigned int lun
= SCSI_LUN(srb
);
1154 if (!sd_card
->sd_pass_thru_en
) {
1155 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1156 TRACE_RET(chip
, TRANSPORT_FAILED
);
1159 if (sd_card
->pre_cmd_err
) {
1160 sd_card
->pre_cmd_err
= 0;
1161 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_CHANGE
);
1162 TRACE_RET(chip
, TRANSPORT_FAILED
);
1165 if ((0x53 != srb
->cmnd
[2]) || (0x44 != srb
->cmnd
[3])
1166 || (0x20 != srb
->cmnd
[4]) || (0x43 != srb
->cmnd
[5])
1167 || (0x61 != srb
->cmnd
[6]) || (0x72 != srb
->cmnd
[7])
1168 || (0x64 != srb
->cmnd
[8])) {
1169 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1170 TRACE_RET(chip
, TRANSPORT_FAILED
);
1173 switch (srb
->cmnd
[1] & 0x0F) {
1175 /* SD Card Power Off -> ON and Initialization */
1176 #ifdef SUPPORT_SD_LOCK
1177 if (0x64 == srb
->cmnd
[9]) {
1179 sd_card
->sd_lock_status
|= SD_SDR_RST
;
1181 #endif /* SUPPORT_SD_LOCK */
1182 retval
= reset_sd_card(chip
);
1183 if (retval
!= STATUS_SUCCESS
) {
1184 #ifdef SUPPORT_SD_LOCK
1185 sd_card
->sd_lock_status
&= ~SD_SDR_RST
;
1187 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1188 sd_card
->pre_cmd_err
= 1;
1189 TRACE_RET(chip
, TRANSPORT_FAILED
);
1191 #ifdef SUPPORT_SD_LOCK
1192 sd_card
->sd_lock_status
&= ~SD_SDR_RST
;
1197 /* reset CMD(CMD0) and Initialization
1198 * (without SD Card Power Off -> ON) */
1199 retval
= soft_reset_sd_card(chip
);
1200 if (retval
!= STATUS_SUCCESS
) {
1201 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_NOT_PRESENT
);
1202 sd_card
->pre_cmd_err
= 1;
1203 TRACE_RET(chip
, TRANSPORT_FAILED
);
1208 set_sense_type(chip
, lun
, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD
);
1209 TRACE_RET(chip
, TRANSPORT_FAILED
);
1212 scsi_set_resid(srb
, 0);
1213 return TRANSPORT_GOOD
;