3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
17 #include <linux/jiffies.h>
18 #include <linux/errno.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
22 #include <scsi/scsi.h>
23 #include <scsi/scsi_cmnd.h>
25 #include <linux/firmware.h>
28 #include "transport.h"
32 MODULE_DESCRIPTION("Driver for ENE UB6250 reader");
33 MODULE_LICENSE("GPL");
37 * The table of devices
39 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
40 vendorName, productName, useProtocol, useTransport, \
41 initFunction, flags) \
42 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
43 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
45 struct usb_device_id ene_ub6250_usb_ids
[] = {
46 # include "unusual_ene_ub6250.h"
47 { } /* Terminating entry */
49 MODULE_DEVICE_TABLE(usb
, ene_ub6250_usb_ids
);
56 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
57 vendor_name, product_name, use_protocol, use_transport, \
58 init_function, Flags) \
60 .vendorName = vendor_name, \
61 .productName = product_name, \
62 .useProtocol = use_protocol, \
63 .useTransport = use_transport, \
64 .initFunction = init_function, \
67 static struct us_unusual_dev ene_ub6250_unusual_dev_list
[] = {
68 # include "unusual_ene_ub6250.h"
69 { } /* Terminating entry */
76 /* ENE bin code len */
77 #define ENE_BIN_CODE_LEN 0x800
79 #define REG_CARD_STATUS 0xFF83
80 #define REG_HW_TRAP1 0xFF89
83 #define SS_SUCCESS 0x00 /* No Sense */
84 #define SS_NOT_READY 0x02
85 #define SS_MEDIUM_ERR 0x03
86 #define SS_HW_ERR 0x04
87 #define SS_ILLEGAL_REQUEST 0x05
88 #define SS_UNIT_ATTENTION 0x06
90 /* ENE Load FW Pattern */
91 #define SD_INIT1_PATTERN 1
92 #define SD_INIT2_PATTERN 2
93 #define SD_RW_PATTERN 3
94 #define MS_INIT_PATTERN 4
95 #define MSP_RW_PATTERN 5
96 #define MS_RW_PATTERN 6
97 #define SM_INIT_PATTERN 7
98 #define SM_RW_PATTERN 8
136 /* SD Block Length */
137 /* 2^9 = 512 Bytes, The HW maximum read/write data length */
138 #define SD_BLOCK_LEN 9
140 struct ene_ub6250_info
{
142 struct SD_STATUS SD_Status
;
143 struct MS_STATUS MS_Status
;
144 struct SM_STATUS SM_Status
;
146 /* ----- SD Control Data ---------------- */
147 /*SD_REGISTER SD_Regs; */
153 /* SD/MMC New spec. */
156 u8 SD20_HIGH_CAPACITY
;
160 u8 MMC_HIGH_CAPACITY
;
162 /*----- MS Control Data ---------------- */
165 /*MS_LibControl MS_Lib;*/
169 /*----- SM Control Data ---------------- */
173 unsigned char *testbuf
;
178 /*------Power Managerment ---------------*/
182 static int ene_sd_init(struct us_data
*us
);
183 static int ene_load_bincode(struct us_data
*us
, unsigned char flag
);
185 static void ene_ub6250_info_destructor(void *extra
)
191 static int ene_send_scsi_cmd(struct us_data
*us
, u8 fDir
, void *buf
, int use_sg
)
193 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
194 struct bulk_cs_wrap
*bcs
= (struct bulk_cs_wrap
*) us
->iobuf
;
197 unsigned int residue
;
198 unsigned int cswlen
= 0, partial
= 0;
199 unsigned int transfer_length
= bcb
->DataTransferLength
;
201 /* US_DEBUGP("transport --- ene_send_scsi_cmd\n"); */
202 /* send cmd to out endpoint */
203 result
= usb_stor_bulk_transfer_buf(us
, us
->send_bulk_pipe
,
204 bcb
, US_BULK_CB_WRAP_LEN
, NULL
);
205 if (result
!= USB_STOR_XFER_GOOD
) {
206 US_DEBUGP("send cmd to out endpoint fail ---\n");
207 return USB_STOR_TRANSPORT_ERROR
;
211 unsigned int pipe
= fDir
;
213 if (fDir
== FDIR_READ
)
214 pipe
= us
->recv_bulk_pipe
;
216 pipe
= us
->send_bulk_pipe
;
220 result
= usb_stor_bulk_srb(us
, pipe
, us
->srb
);
222 result
= usb_stor_bulk_transfer_sg(us
, pipe
, buf
,
223 transfer_length
, 0, &partial
);
225 if (result
!= USB_STOR_XFER_GOOD
) {
226 US_DEBUGP("data transfer fail ---\n");
227 return USB_STOR_TRANSPORT_ERROR
;
231 /* Get CSW for device status */
232 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
, bcs
,
233 US_BULK_CS_WRAP_LEN
, &cswlen
);
235 if (result
== USB_STOR_XFER_SHORT
&& cswlen
== 0) {
236 US_DEBUGP("Received 0-length CSW; retrying...\n");
237 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
,
238 bcs
, US_BULK_CS_WRAP_LEN
, &cswlen
);
241 if (result
== USB_STOR_XFER_STALLED
) {
242 /* get the status again */
243 US_DEBUGP("Attempting to get CSW (2nd try)...\n");
244 result
= usb_stor_bulk_transfer_buf(us
, us
->recv_bulk_pipe
,
245 bcs
, US_BULK_CS_WRAP_LEN
, NULL
);
248 if (result
!= USB_STOR_XFER_GOOD
)
249 return USB_STOR_TRANSPORT_ERROR
;
251 /* check bulk status */
252 residue
= le32_to_cpu(bcs
->Residue
);
254 /* try to compute the actual residue, based on how much data
255 * was really transferred and what the device tells us */
256 if (residue
&& !(us
->fflags
& US_FL_IGNORE_RESIDUE
)) {
257 residue
= min(residue
, transfer_length
);
259 scsi_set_resid(us
->srb
, max(scsi_get_resid(us
->srb
),
263 if (bcs
->Status
!= US_BULK_STAT_OK
)
264 return USB_STOR_TRANSPORT_ERROR
;
266 return USB_STOR_TRANSPORT_GOOD
;
269 static int sd_scsi_test_unit_ready(struct us_data
*us
, struct scsi_cmnd
*srb
)
271 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
273 if (info
->SD_Status
.Insert
&& info
->SD_Status
.Ready
)
274 return USB_STOR_TRANSPORT_GOOD
;
277 return USB_STOR_TRANSPORT_GOOD
;
280 return USB_STOR_TRANSPORT_GOOD
;
283 static int sd_scsi_inquiry(struct us_data
*us
, struct scsi_cmnd
*srb
)
285 unsigned char data_ptr
[36] = {
286 0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55,
287 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61,
288 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20,
289 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30 };
291 usb_stor_set_xfer_buf(data_ptr
, 36, srb
);
292 return USB_STOR_TRANSPORT_GOOD
;
295 static int sd_scsi_mode_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
297 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
298 unsigned char mediaNoWP
[12] = {
299 0x0b, 0x00, 0x00, 0x08, 0x00, 0x00,
300 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
301 unsigned char mediaWP
[12] = {
302 0x0b, 0x00, 0x80, 0x08, 0x00, 0x00,
303 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00 };
305 if (info
->SD_Status
.WtP
)
306 usb_stor_set_xfer_buf(mediaWP
, 12, srb
);
308 usb_stor_set_xfer_buf(mediaNoWP
, 12, srb
);
311 return USB_STOR_TRANSPORT_GOOD
;
314 static int sd_scsi_read_capacity(struct us_data
*us
, struct scsi_cmnd
*srb
)
318 unsigned int offset
= 0;
319 unsigned char buf
[8];
320 struct scatterlist
*sg
= NULL
;
321 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
323 US_DEBUGP("sd_scsi_read_capacity\n");
324 if (info
->SD_Status
.HiCapacity
) {
326 if (info
->SD_Status
.IsMMC
)
327 bl_num
= info
->HC_C_SIZE
-1;
329 bl_num
= (info
->HC_C_SIZE
+ 1) * 1024 - 1;
331 bl_len
= 1<<(info
->SD_READ_BL_LEN
);
332 bl_num
= info
->SD_Block_Mult
* (info
->SD_C_SIZE
+ 1)
333 * (1 << (info
->SD_C_SIZE_MULT
+ 2)) - 1;
335 info
->bl_num
= bl_num
;
336 US_DEBUGP("bl_len = %x\n", bl_len
);
337 US_DEBUGP("bl_num = %x\n", bl_num
);
339 /*srb->request_bufflen = 8; */
340 buf
[0] = (bl_num
>> 24) & 0xff;
341 buf
[1] = (bl_num
>> 16) & 0xff;
342 buf
[2] = (bl_num
>> 8) & 0xff;
343 buf
[3] = (bl_num
>> 0) & 0xff;
344 buf
[4] = (bl_len
>> 24) & 0xff;
345 buf
[5] = (bl_len
>> 16) & 0xff;
346 buf
[6] = (bl_len
>> 8) & 0xff;
347 buf
[7] = (bl_len
>> 0) & 0xff;
349 usb_stor_access_xfer_buf(buf
, 8, srb
, &sg
, &offset
, TO_XFER_BUF
);
351 return USB_STOR_TRANSPORT_GOOD
;
354 static int sd_scsi_read(struct us_data
*us
, struct scsi_cmnd
*srb
)
357 unsigned char *cdb
= srb
->cmnd
;
358 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
359 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
361 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
362 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
363 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
364 u32 bnByte
= bn
* 0x200;
365 u32 blenByte
= blen
* 0x200;
367 if (bn
> info
->bl_num
)
368 return USB_STOR_TRANSPORT_ERROR
;
370 result
= ene_load_bincode(us
, SD_RW_PATTERN
);
371 if (result
!= USB_STOR_XFER_GOOD
) {
372 US_DEBUGP("Load SD RW pattern Fail !!\n");
373 return USB_STOR_TRANSPORT_ERROR
;
376 if (info
->SD_Status
.HiCapacity
)
379 /* set up the command wrapper */
380 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
381 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
382 bcb
->DataTransferLength
= blenByte
;
385 bcb
->CDB
[5] = (unsigned char)(bnByte
);
386 bcb
->CDB
[4] = (unsigned char)(bnByte
>>8);
387 bcb
->CDB
[3] = (unsigned char)(bnByte
>>16);
388 bcb
->CDB
[2] = (unsigned char)(bnByte
>>24);
390 result
= ene_send_scsi_cmd(us
, FDIR_READ
, scsi_sglist(srb
), 1);
394 static int sd_scsi_write(struct us_data
*us
, struct scsi_cmnd
*srb
)
397 unsigned char *cdb
= srb
->cmnd
;
398 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
399 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
401 u32 bn
= ((cdb
[2] << 24) & 0xff000000) | ((cdb
[3] << 16) & 0x00ff0000) |
402 ((cdb
[4] << 8) & 0x0000ff00) | ((cdb
[5] << 0) & 0x000000ff);
403 u16 blen
= ((cdb
[7] << 8) & 0xff00) | ((cdb
[8] << 0) & 0x00ff);
404 u32 bnByte
= bn
* 0x200;
405 u32 blenByte
= blen
* 0x200;
407 if (bn
> info
->bl_num
)
408 return USB_STOR_TRANSPORT_ERROR
;
410 result
= ene_load_bincode(us
, SD_RW_PATTERN
);
411 if (result
!= USB_STOR_XFER_GOOD
) {
412 US_DEBUGP("Load SD RW pattern Fail !!\n");
413 return USB_STOR_TRANSPORT_ERROR
;
416 if (info
->SD_Status
.HiCapacity
)
419 /* set up the command wrapper */
420 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
421 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
422 bcb
->DataTransferLength
= blenByte
;
425 bcb
->CDB
[5] = (unsigned char)(bnByte
);
426 bcb
->CDB
[4] = (unsigned char)(bnByte
>>8);
427 bcb
->CDB
[3] = (unsigned char)(bnByte
>>16);
428 bcb
->CDB
[2] = (unsigned char)(bnByte
>>24);
430 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, scsi_sglist(srb
), 1);
434 static int ene_get_card_type(struct us_data
*us
, u16 index
, void *buf
)
436 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
439 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
440 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
441 bcb
->DataTransferLength
= 0x01;
444 bcb
->CDB
[2] = (unsigned char)(index
>>8);
445 bcb
->CDB
[3] = (unsigned char)index
;
447 result
= ene_send_scsi_cmd(us
, FDIR_READ
, buf
, 0);
451 static int ene_get_card_status(struct us_data
*us
, u8
*buf
)
455 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
457 /*US_DEBUGP("transport --- ENE_ReadSDReg\n");*/
458 reg4b
= *(u32
*)&buf
[0x18];
459 info
->SD_READ_BL_LEN
= (u8
)((reg4b
>> 8) & 0x0f);
461 tmpreg
= (u16
) reg4b
;
462 reg4b
= *(u32
*)(&buf
[0x14]);
463 if (info
->SD_Status
.HiCapacity
&& !info
->SD_Status
.IsMMC
)
464 info
->HC_C_SIZE
= (reg4b
>> 8) & 0x3fffff;
466 info
->SD_C_SIZE
= ((tmpreg
& 0x03) << 10) | (u16
)(reg4b
>> 22);
467 info
->SD_C_SIZE_MULT
= (u8
)(reg4b
>> 7) & 0x07;
468 if (info
->SD_Status
.HiCapacity
&& info
->SD_Status
.IsMMC
)
469 info
->HC_C_SIZE
= *(u32
*)(&buf
[0x100]);
471 if (info
->SD_READ_BL_LEN
> SD_BLOCK_LEN
) {
472 info
->SD_Block_Mult
= 1 << (info
->SD_READ_BL_LEN
-SD_BLOCK_LEN
);
473 info
->SD_READ_BL_LEN
= SD_BLOCK_LEN
;
475 info
->SD_Block_Mult
= 1;
478 return USB_STOR_TRANSPORT_GOOD
;
481 static int ene_load_bincode(struct us_data
*us
, unsigned char flag
)
484 char *fw_name
= NULL
;
485 unsigned char *buf
= NULL
;
486 const struct firmware
*sd_fw
= NULL
;
487 int result
= USB_STOR_TRANSPORT_ERROR
;
488 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
489 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
491 if (info
->BIN_FLAG
== flag
)
492 return USB_STOR_TRANSPORT_GOOD
;
496 case SD_INIT1_PATTERN
:
497 US_DEBUGP("SD_INIT1_PATTERN\n");
498 fw_name
= "ene-ub6250/sd_init1.bin";
500 case SD_INIT2_PATTERN
:
501 US_DEBUGP("SD_INIT2_PATTERN\n");
502 fw_name
= "ene-ub6250/sd_init2.bin";
505 US_DEBUGP("SD_RDWR_PATTERN\n");
506 fw_name
= "ene-ub6250/sd_rdwr.bin";
509 US_DEBUGP("----------- Unknown PATTERN ----------\n");
513 err
= request_firmware(&sd_fw
, fw_name
, &us
->pusb_dev
->dev
);
515 US_DEBUGP("load firmware %s failed\n", fw_name
);
518 buf
= kmalloc(sd_fw
->size
, GFP_KERNEL
);
520 US_DEBUGP("Malloc memory for fireware failed!\n");
523 memcpy(buf
, sd_fw
->data
, sd_fw
->size
);
524 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
525 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
526 bcb
->DataTransferLength
= sd_fw
->size
;
530 result
= ene_send_scsi_cmd(us
, FDIR_WRITE
, buf
, 0);
531 info
->BIN_FLAG
= flag
;
536 release_firmware(sd_fw
);
543 static int ene_sd_init(struct us_data
*us
)
547 struct bulk_cb_wrap
*bcb
= (struct bulk_cb_wrap
*) us
->iobuf
;
548 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*) us
->extra
;
550 US_DEBUGP("transport --- ENE_SDInit\n");
552 result
= ene_load_bincode(us
, SD_INIT1_PATTERN
);
553 if (result
!= USB_STOR_XFER_GOOD
) {
554 US_DEBUGP("Load SD Init Code Part-1 Fail !!\n");
555 return USB_STOR_TRANSPORT_ERROR
;
558 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
559 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
563 result
= ene_send_scsi_cmd(us
, FDIR_READ
, NULL
, 0);
564 if (result
!= USB_STOR_XFER_GOOD
) {
565 US_DEBUGP("Execution SD Init Code Fail !!\n");
566 return USB_STOR_TRANSPORT_ERROR
;
570 result
= ene_load_bincode(us
, SD_INIT2_PATTERN
);
571 if (result
!= USB_STOR_XFER_GOOD
) {
572 US_DEBUGP("Load SD Init Code Part-2 Fail !!\n");
573 return USB_STOR_TRANSPORT_ERROR
;
576 memset(bcb
, 0, sizeof(struct bulk_cb_wrap
));
577 bcb
->Signature
= cpu_to_le32(US_BULK_CB_SIGN
);
578 bcb
->DataTransferLength
= 0x200;
582 result
= ene_send_scsi_cmd(us
, FDIR_READ
, &buf
, 0);
583 if (result
!= USB_STOR_XFER_GOOD
) {
584 US_DEBUGP("Execution SD Init Code Fail !!\n");
585 return USB_STOR_TRANSPORT_ERROR
;
588 info
->SD_Status
= *(struct SD_STATUS
*)&buf
[0];
589 if (info
->SD_Status
.Insert
&& info
->SD_Status
.Ready
) {
590 ene_get_card_status(us
, (unsigned char *)&buf
);
591 US_DEBUGP("Insert = %x\n", info
->SD_Status
.Insert
);
592 US_DEBUGP("Ready = %x\n", info
->SD_Status
.Ready
);
593 US_DEBUGP("IsMMC = %x\n", info
->SD_Status
.IsMMC
);
594 US_DEBUGP("HiCapacity = %x\n", info
->SD_Status
.HiCapacity
);
595 US_DEBUGP("HiSpeed = %x\n", info
->SD_Status
.HiSpeed
);
596 US_DEBUGP("WtP = %x\n", info
->SD_Status
.WtP
);
598 US_DEBUGP("SD Card Not Ready --- %x\n", buf
[0]);
599 return USB_STOR_TRANSPORT_ERROR
;
601 return USB_STOR_TRANSPORT_GOOD
;
605 static int ene_init(struct us_data
*us
)
609 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
611 result
= ene_get_card_type(us
, REG_CARD_STATUS
, &misc_reg03
);
612 if (result
!= USB_STOR_XFER_GOOD
)
613 return USB_STOR_TRANSPORT_ERROR
;
615 if (misc_reg03
& 0x01) {
616 if (!info
->SD_Status
.Ready
) {
617 result
= ene_sd_init(us
);
618 if (result
!= USB_STOR_XFER_GOOD
)
619 return USB_STOR_TRANSPORT_ERROR
;
626 /*----- sd_scsi_irp() ---------*/
627 static int sd_scsi_irp(struct us_data
*us
, struct scsi_cmnd
*srb
)
630 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)us
->extra
;
632 info
->SrbStatus
= SS_SUCCESS
;
633 switch (srb
->cmnd
[0]) {
634 case TEST_UNIT_READY
:
635 result
= sd_scsi_test_unit_ready(us
, srb
);
638 result
= sd_scsi_inquiry(us
, srb
);
641 result
= sd_scsi_mode_sense(us
, srb
);
645 result = SD_SCSI_Start_Stop(us, srb);
649 result
= sd_scsi_read_capacity(us
, srb
);
652 result
= sd_scsi_read(us
, srb
);
655 result
= sd_scsi_write(us
, srb
);
658 info
->SrbStatus
= SS_ILLEGAL_REQUEST
;
659 result
= USB_STOR_TRANSPORT_FAILED
;
665 static int ene_transport(struct scsi_cmnd
*srb
, struct us_data
*us
)
668 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
670 /*US_DEBUG(usb_stor_show_command(srb)); */
671 scsi_set_resid(srb
, 0);
672 if (unlikely(!info
->SD_Status
.Ready
))
673 result
= ene_init(us
);
675 result
= sd_scsi_irp(us
, srb
);
681 static int ene_ub6250_probe(struct usb_interface
*intf
,
682 const struct usb_device_id
*id
)
688 result
= usb_stor_probe1(&us
, intf
, id
,
689 (id
- ene_ub6250_usb_ids
) + ene_ub6250_unusual_dev_list
);
693 /* FIXME: where should the code alloc extra buf ? */
695 us
->extra
= kzalloc(sizeof(struct ene_ub6250_info
), GFP_KERNEL
);
698 us
->extra_destructor
= ene_ub6250_info_destructor
;
701 us
->transport_name
= "ene_ub6250";
702 us
->transport
= ene_transport
;
705 result
= usb_stor_probe2(us
);
709 /* probe card type */
710 result
= ene_get_card_type(us
, REG_CARD_STATUS
, &misc_reg03
);
711 if (result
!= USB_STOR_XFER_GOOD
) {
712 usb_stor_disconnect(intf
);
713 return USB_STOR_TRANSPORT_ERROR
;
716 if (!(misc_reg03
& 0x01)) {
718 printk(KERN_NOTICE
"ums_eneub6250: The driver only supports SD\
719 card. To use SM/MS card, please build driver/stagging/keucr\n");
720 usb_stor_disconnect(intf
);
729 static int ene_ub6250_resume(struct usb_interface
*iface
)
732 struct us_data
*us
= usb_get_intfdata(iface
);
733 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
735 mutex_lock(&us
->dev_mutex
);
737 US_DEBUGP("%s\n", __func__
);
738 if (us
->suspend_resume_hook
)
739 (us
->suspend_resume_hook
)(us
, US_RESUME
);
741 mutex_unlock(&us
->dev_mutex
);
743 info
->Power_IsResum
= true;
744 /*info->SD_Status.Ready = 0; */
745 info
->SD_Status
= *(struct SD_STATUS
*)&tmp
;
746 info
->MS_Status
= *(struct MS_STATUS
*)&tmp
;
747 info
->SM_Status
= *(struct SM_STATUS
*)&tmp
;
752 static int ene_ub6250_reset_resume(struct usb_interface
*iface
)
755 struct us_data
*us
= usb_get_intfdata(iface
);
756 struct ene_ub6250_info
*info
= (struct ene_ub6250_info
*)(us
->extra
);
757 US_DEBUGP("%s\n", __func__
);
758 /* Report the reset to the SCSI core */
759 usb_stor_reset_resume(iface
);
761 /* FIXME: Notify the subdrivers that they need to reinitialize
763 info
->Power_IsResum
= true;
764 /*info->SD_Status.Ready = 0; */
765 info
->SD_Status
= *(struct SD_STATUS
*)&tmp
;
766 info
->MS_Status
= *(struct MS_STATUS
*)&tmp
;
767 info
->SM_Status
= *(struct SM_STATUS
*)&tmp
;
774 #define ene_ub6250_resume NULL
775 #define ene_ub6250_reset_resume NULL
779 static struct usb_driver ene_ub6250_driver
= {
780 .name
= "ums_eneub6250",
781 .probe
= ene_ub6250_probe
,
782 .disconnect
= usb_stor_disconnect
,
783 .suspend
= usb_stor_suspend
,
784 .resume
= ene_ub6250_resume
,
785 .reset_resume
= ene_ub6250_reset_resume
,
786 .pre_reset
= usb_stor_pre_reset
,
787 .post_reset
= usb_stor_post_reset
,
788 .id_table
= ene_ub6250_usb_ids
,
792 static int __init
ene_ub6250_init(void)
794 return usb_register(&ene_ub6250_driver
);
797 static void __exit
ene_ub6250_exit(void)
799 usb_deregister(&ene_ub6250_driver
);
802 module_init(ene_ub6250_init
);
803 module_exit(ene_ub6250_exit
);