Lines Matching +full:0 +full:us

54 #define USBAT_DEV_HP8200	0x01
55 #define USBAT_DEV_FLASH 0x02
57 #define USBAT_EPP_PORT 0x10
58 #define USBAT_EPP_REGISTER 0x30
59 #define USBAT_ATA 0x40
60 #define USBAT_ISA 0x50
63 #define USBAT_CMD_READ_REG 0x00
64 #define USBAT_CMD_WRITE_REG 0x01
65 #define USBAT_CMD_READ_BLOCK 0x02
66 #define USBAT_CMD_WRITE_BLOCK 0x03
67 #define USBAT_CMD_COND_READ_BLOCK 0x04
68 #define USBAT_CMD_COND_WRITE_BLOCK 0x05
69 #define USBAT_CMD_WRITE_REGS 0x07
72 #define USBAT_CMD_EXEC_CMD 0x80
73 #define USBAT_CMD_SET_FEAT 0x81
74 #define USBAT_CMD_UIO 0x82
78 #define USBAT_UIO_WRITE 0
81 #define USBAT_QUAL_FCQ 0x20 /* full compare */
82 #define USBAT_QUAL_ALQ 0x10 /* auto load subcount */
85 #define USBAT_FLASH_MEDIA_NONE 0
89 #define USBAT_FLASH_MEDIA_SAME 0
93 #define USBAT_ATA_DATA 0x10 /* read/write data (R/W) */
94 #define USBAT_ATA_FEATURES 0x11 /* set features (W) */
95 #define USBAT_ATA_ERROR 0x11 /* error (R) */
96 #define USBAT_ATA_SECCNT 0x12 /* sector count (R/W) */
97 #define USBAT_ATA_SECNUM 0x13 /* sector number (R/W) */
98 #define USBAT_ATA_LBA_ME 0x14 /* cylinder low (R/W) */
99 #define USBAT_ATA_LBA_HI 0x15 /* cylinder high (R/W) */
100 #define USBAT_ATA_DEVICE 0x16 /* head/device selection (R/W) */
101 #define USBAT_ATA_STATUS 0x17 /* device status (R) */
102 #define USBAT_ATA_CMD 0x17 /* device command (W) */
103 #define USBAT_ATA_ALTSTATUS 0x0E /* status (no clear IRQ) (R) */
106 #define USBAT_UIO_EPAD 0x80 /* Enable Peripheral Control Signals */
107 #define USBAT_UIO_CDT 0x40 /* Card Detect (Read Only) */
109 #define USBAT_UIO_1 0x20 /* I/O 1 */
110 #define USBAT_UIO_0 0x10 /* I/O 0 */
111 #define USBAT_UIO_EPP_ATA 0x08 /* 1=EPP mode, 0=ATA mode */
112 #define USBAT_UIO_UI1 0x04 /* Input 1 */
113 #define USBAT_UIO_UI0 0x02 /* Input 0 */
114 #define USBAT_UIO_INTR_ACK 0x01 /* Interrupt (ATA/ISA)/Acknowledge (EPP) */
117 #define USBAT_UIO_DRVRST 0x80 /* Reset Peripheral */
118 #define USBAT_UIO_ACKD 0x40 /* Enable Card Detect */
119 #define USBAT_UIO_OE1 0x20 /* I/O 1 set=output/clr=input */
121 #define USBAT_UIO_OE0 0x10 /* I/O 0 set=output/clr=input */
122 #define USBAT_UIO_ADPRST 0x01 /* Reset SCM chip */
125 #define USBAT_FEAT_ETEN 0x80 /* External trigger enable */
126 #define USBAT_FEAT_U1 0x08
127 #define USBAT_FEAT_U0 0x04
128 #define USBAT_FEAT_ET1 0x02
129 #define USBAT_FEAT_ET2 0x01
144 #define LSB_of(s) ((s)&0xFF)
147 static int transferred = 0;
149 static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us);
150 static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us);
152 static int init_usbat_cd(struct us_data *us);
153 static int init_usbat_flash(struct us_data *us);
196 * Use cmd=0x20 for read, cmd=0x30 for write
202 buf[0] = 0; in usbat_pack_ata_sector_cmd()
204 buf[2] = sector & 0xFF; in usbat_pack_ata_sector_cmd()
205 buf[3] = (sector >> 8) & 0xFF; in usbat_pack_ata_sector_cmd()
206 buf[4] = (sector >> 16) & 0xFF; in usbat_pack_ata_sector_cmd()
207 buf[5] = 0xE0 | ((sector >> 24) & 0x0F); in usbat_pack_ata_sector_cmd()
214 static int usbat_get_device_type(struct us_data *us) in usbat_get_device_type() argument
216 return ((struct usbat_info*)us->extra)->devicetype; in usbat_get_device_type()
222 static int usbat_read(struct us_data *us, in usbat_read() argument
227 return usb_stor_ctrl_transfer(us, in usbat_read()
228 us->recv_ctrl_pipe, in usbat_read()
230 0xC0, in usbat_read()
232 0, in usbat_read()
240 static int usbat_write(struct us_data *us, in usbat_write() argument
245 return usb_stor_ctrl_transfer(us, in usbat_write()
246 us->send_ctrl_pipe, in usbat_write()
248 0x40, in usbat_write()
250 0, in usbat_write()
252 0); in usbat_write()
258 static int usbat_bulk_read(struct us_data *us, in usbat_bulk_read() argument
263 if (len == 0) in usbat_bulk_read()
266 usb_stor_dbg(us, "len = %d\n", len); in usbat_bulk_read()
267 return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, buf, len, use_sg, NULL); in usbat_bulk_read()
273 static int usbat_bulk_write(struct us_data *us, in usbat_bulk_write() argument
278 if (len == 0) in usbat_bulk_write()
281 usb_stor_dbg(us, "len = %d\n", len); in usbat_bulk_write()
282 return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, buf, len, use_sg, NULL); in usbat_bulk_write()
290 static int usbat_execute_command(struct us_data *us, in usbat_execute_command() argument
294 return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, in usbat_execute_command()
295 USBAT_CMD_EXEC_CMD, 0x40, 0, 0, in usbat_execute_command()
302 static int usbat_get_status(struct us_data *us, unsigned char *status) in usbat_get_status() argument
305 rc = usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status); in usbat_get_status()
307 usb_stor_dbg(us, "0x%02X\n", *status); in usbat_get_status()
314 static int usbat_check_status(struct us_data *us) in usbat_check_status() argument
316 unsigned char *reply = us->iobuf; in usbat_check_status()
319 rc = usbat_get_status(us, reply); in usbat_check_status()
323 /* error/check condition (0x51 is ok) */ in usbat_check_status()
324 if (*reply & 0x01 && *reply != 0x51) in usbat_check_status()
328 if (*reply & 0x20) in usbat_check_status()
338 static int usbat_set_shuttle_features(struct us_data *us, in usbat_set_shuttle_features() argument
346 unsigned char *command = us->iobuf; in usbat_set_shuttle_features()
348 command[0] = 0x40; in usbat_set_shuttle_features()
387 return usbat_execute_command(us, command, 8); in usbat_set_shuttle_features()
394 static int usbat_wait_not_busy(struct us_data *us, int minutes) in usbat_wait_not_busy() argument
398 unsigned char *status = us->iobuf; in usbat_wait_not_busy()
407 for (i=0; i<1200+minutes*60; i++) { in usbat_wait_not_busy()
409 result = usbat_get_status(us, status); in usbat_wait_not_busy()
413 if (*status & 0x01) { /* check condition */ in usbat_wait_not_busy()
414 result = usbat_read(us, USBAT_ATA, 0x10, status); in usbat_wait_not_busy()
417 if (*status & 0x20) /* device fault */ in usbat_wait_not_busy()
420 if ((*status & 0x80)==0x00) { /* not busy */ in usbat_wait_not_busy()
421 usb_stor_dbg(us, "Waited not busy for %d steps\n", i); in usbat_wait_not_busy()
435 usb_stor_dbg(us, "Waited not busy for %d minutes, timing out\n", in usbat_wait_not_busy()
443 static int usbat_read_block(struct us_data *us, in usbat_read_block() argument
449 unsigned char *command = us->iobuf; in usbat_read_block()
454 command[0] = 0xC0; in usbat_read_block()
457 command[3] = 0; in usbat_read_block()
458 command[4] = 0; in usbat_read_block()
459 command[5] = 0; in usbat_read_block()
463 result = usbat_execute_command(us, command, 8); in usbat_read_block()
467 result = usbat_bulk_read(us, buf, len, use_sg); in usbat_read_block()
475 static int usbat_write_block(struct us_data *us, in usbat_write_block() argument
483 unsigned char *command = us->iobuf; in usbat_write_block()
488 command[0] = 0x40; in usbat_write_block()
491 command[3] = 0; in usbat_write_block()
492 command[4] = 0; in usbat_write_block()
493 command[5] = 0; in usbat_write_block()
497 result = usbat_execute_command(us, command, 8); in usbat_write_block()
502 result = usbat_bulk_write(us, buf, len, use_sg); in usbat_write_block()
506 return usbat_wait_not_busy(us, minutes); in usbat_write_block()
512 static int usbat_hp8200e_rw_block_test(struct us_data *us, in usbat_hp8200e_rw_block_test() argument
529 us->recv_bulk_pipe : us->send_bulk_pipe; in usbat_hp8200e_rw_block_test()
531 unsigned char *command = us->iobuf; in usbat_hp8200e_rw_block_test()
534 unsigned char *data = us->iobuf; in usbat_hp8200e_rw_block_test()
535 unsigned char *status = us->iobuf; in usbat_hp8200e_rw_block_test()
539 for (i=0; i<20; i++) { in usbat_hp8200e_rw_block_test()
552 if (i==0) { in usbat_hp8200e_rw_block_test()
556 * Not really sure the 0x07, 0x17, 0xfc, 0xe7 is in usbat_hp8200e_rw_block_test()
560 command[0] = 0x40; in usbat_hp8200e_rw_block_test()
562 command[2] = 0x07; in usbat_hp8200e_rw_block_test()
563 command[3] = 0x17; in usbat_hp8200e_rw_block_test()
564 command[4] = 0xFC; in usbat_hp8200e_rw_block_test()
565 command[5] = 0xE7; in usbat_hp8200e_rw_block_test()
572 command[cmdlen-8] = (direction==DMA_TO_DEVICE ? 0x40 : 0xC0); in usbat_hp8200e_rw_block_test()
583 result = usbat_execute_command(us, command, cmdlen); in usbat_hp8200e_rw_block_test()
588 if (i==0) { in usbat_hp8200e_rw_block_test()
590 for (j=0; j<num_registers; j++) { in usbat_hp8200e_rw_block_test()
595 result = usbat_bulk_write(us, data, num_registers*2, 0); in usbat_hp8200e_rw_block_test()
601 result = usb_stor_bulk_transfer_sg(us, in usbat_hp8200e_rw_block_test()
614 * (i.e. bit 0 -- CHK -- of status is 0). The most likely in usbat_hp8200e_rw_block_test()
631 if (direction==DMA_FROM_DEVICE && i==0) { in usbat_hp8200e_rw_block_test()
632 if (usb_stor_clear_halt(us, in usbat_hp8200e_rw_block_test()
633 us->send_bulk_pipe) < 0) in usbat_hp8200e_rw_block_test()
641 result = usbat_read(us, USBAT_ATA, in usbat_hp8200e_rw_block_test()
648 if (*status & 0x01) /* check condition */ in usbat_hp8200e_rw_block_test()
650 if (*status & 0x20) /* device fault */ in usbat_hp8200e_rw_block_test()
653 usb_stor_dbg(us, "Redoing %s\n", in usbat_hp8200e_rw_block_test()
660 return usbat_wait_not_busy(us, minutes); in usbat_hp8200e_rw_block_test()
664 usb_stor_dbg(us, "Bummer! %s bulk data 20 times failed\n", in usbat_hp8200e_rw_block_test()
672 * Allows us to write specific data to any registers. The data to be written
677 static int usbat_multiple_write(struct us_data *us, in usbat_multiple_write() argument
683 unsigned char *data = us->iobuf; in usbat_multiple_write()
684 unsigned char *command = us->iobuf; in usbat_multiple_write()
689 command[0] = 0x40; in usbat_multiple_write()
693 command[2] = 0; in usbat_multiple_write()
694 command[3] = 0; in usbat_multiple_write()
695 command[4] = 0; in usbat_multiple_write()
696 command[5] = 0; in usbat_multiple_write()
703 result = usbat_execute_command(us, command, 8); in usbat_multiple_write()
708 for (i=0; i<num_registers; i++) { in usbat_multiple_write()
714 result = usbat_bulk_write(us, data, num_registers*2, 0); in usbat_multiple_write()
718 if (usbat_get_device_type(us) == USBAT_DEV_HP8200) in usbat_multiple_write()
719 return usbat_wait_not_busy(us, 0); in usbat_multiple_write()
726 * Allows us to read blocks from a specific data register, based upon the
736 static int usbat_read_blocks(struct us_data *us, in usbat_read_blocks() argument
742 unsigned char *command = us->iobuf; in usbat_read_blocks()
744 command[0] = 0xC0; in usbat_read_blocks()
748 command[4] = 0xFD; /* Timeout (ms); */ in usbat_read_blocks()
754 result = usbat_execute_command(us, command, 8); in usbat_read_blocks()
759 result = usbat_bulk_read(us, buffer, len, use_sg); in usbat_read_blocks()
768 * Allows us to write blocks to a specific data register, based upon the
778 static int usbat_write_blocks(struct us_data *us, in usbat_write_blocks() argument
784 unsigned char *command = us->iobuf; in usbat_write_blocks()
786 command[0] = 0x40; in usbat_write_blocks()
790 command[4] = 0xFD; /* Timeout (ms) */ in usbat_write_blocks()
796 result = usbat_execute_command(us, command, 8); in usbat_write_blocks()
801 result = usbat_bulk_write(us, buffer, len, use_sg); in usbat_write_blocks()
811 static int usbat_read_user_io(struct us_data *us, unsigned char *data_flags) in usbat_read_user_io() argument
815 result = usb_stor_ctrl_transfer(us, in usbat_read_user_io()
816 us->recv_ctrl_pipe, in usbat_read_user_io()
818 0xC0, in usbat_read_user_io()
819 0, in usbat_read_user_io()
820 0, in usbat_read_user_io()
824 usb_stor_dbg(us, "UIO register reads %02X\n", *data_flags); in usbat_read_user_io()
832 static int usbat_write_user_io(struct us_data *us, in usbat_write_user_io() argument
836 return usb_stor_ctrl_transfer(us, in usbat_write_user_io()
837 us->send_ctrl_pipe, in usbat_write_user_io()
839 0x40, in usbat_write_user_io()
841 0, in usbat_write_user_io()
850 static int usbat_device_reset(struct us_data *us) in usbat_device_reset() argument
858 rc = usbat_write_user_io(us, in usbat_device_reset()
868 rc = usbat_write_user_io(us, in usbat_device_reset()
880 static int usbat_device_enable_cdt(struct us_data *us) in usbat_device_enable_cdt() argument
885 rc = usbat_write_user_io(us, in usbat_device_enable_cdt()
897 static int usbat_flash_check_media_present(struct us_data *us, in usbat_flash_check_media_present() argument
901 usb_stor_dbg(us, "no media detected\n"); in usbat_flash_check_media_present()
911 static int usbat_flash_check_media_changed(struct us_data *us, in usbat_flash_check_media_changed() argument
915 usb_stor_dbg(us, "media change detected\n"); in usbat_flash_check_media_changed()
925 static int usbat_flash_check_media(struct us_data *us, in usbat_flash_check_media() argument
929 unsigned char *uio = us->iobuf; in usbat_flash_check_media()
931 rc = usbat_read_user_io(us, uio); in usbat_flash_check_media()
936 rc = usbat_flash_check_media_present(us, uio); in usbat_flash_check_media()
938 info->sense_key = 0x02; in usbat_flash_check_media()
939 info->sense_asc = 0x3A; in usbat_flash_check_media()
940 info->sense_ascq = 0x00; in usbat_flash_check_media()
945 rc = usbat_flash_check_media_changed(us, uio); in usbat_flash_check_media()
949 rc = usbat_device_reset(us); in usbat_flash_check_media()
952 rc = usbat_device_enable_cdt(us); in usbat_flash_check_media()
958 rc = usbat_read_user_io(us, uio); in usbat_flash_check_media()
963 info->sense_asc = 0x28; in usbat_flash_check_media()
964 info->sense_ascq = 0x00; in usbat_flash_check_media()
976 static int usbat_identify_device(struct us_data *us, in usbat_identify_device() argument
982 if (!us || !info) in usbat_identify_device()
985 rc = usbat_device_reset(us); in usbat_identify_device()
996 rc = usbat_write(us, USBAT_ATA, USBAT_ATA_CMD, 0xA1); in usbat_identify_device()
1000 rc = usbat_get_status(us, &status); in usbat_identify_device()
1005 if (status == 0xA1 || !(status & 0x01)) { in usbat_identify_device()
1007 usb_stor_dbg(us, "Detected HP8200 CDRW\n"); in usbat_identify_device()
1011 usb_stor_dbg(us, "Detected Flash reader/writer\n"); in usbat_identify_device()
1021 static int usbat_set_transport(struct us_data *us, in usbat_set_transport() argument
1030 usbat_identify_device(us, info); in usbat_set_transport()
1037 us->transport = usbat_hp8200e_transport; in usbat_set_transport()
1041 us->transport = usbat_flash_transport; in usbat_set_transport()
1045 return 0; in usbat_set_transport()
1051 static int usbat_flash_get_sector_count(struct us_data *us, in usbat_flash_get_sector_count() argument
1059 unsigned char command[3] = { 0x01, 0xA0, 0xEC }; in usbat_flash_get_sector_count()
1064 if (!us || !info) in usbat_flash_get_sector_count()
1072 rc = usbat_multiple_write(us, registers, command, 3); in usbat_flash_get_sector_count()
1074 usb_stor_dbg(us, "Gah! identify_device failed\n"); in usbat_flash_get_sector_count()
1080 if (usbat_get_status(us, &status) != USB_STOR_XFER_GOOD) { in usbat_flash_get_sector_count()
1088 rc = usbat_read_block(us, reply, 512, 0); in usbat_flash_get_sector_count()
1107 static int usbat_flash_read_data(struct us_data *us, in usbat_flash_read_data() argument
1126 unsigned int sg_offset = 0; in usbat_flash_read_data()
1129 result = usbat_flash_check_media(us, info); in usbat_flash_read_data()
1140 if (sector > 0x0FFFFFFF) in usbat_flash_read_data()
1162 thistime = (len / info->ssize) & 0xff; in usbat_flash_read_data()
1164 /* ATA command 0x20 (READ SECTORS) */ in usbat_flash_read_data()
1165 usbat_pack_ata_sector_cmd(command, thistime, sector, 0x20); in usbat_flash_read_data()
1168 result = usbat_multiple_write(us, registers, command, 7); in usbat_flash_read_data()
1173 result = usbat_read_blocks(us, buffer, len, 0); in usbat_flash_read_data()
1177 usb_stor_dbg(us, "%d bytes\n", len); in usbat_flash_read_data()
1180 usb_stor_access_xfer_buf(buffer, len, us->srb, in usbat_flash_read_data()
1185 } while (totallen > 0); in usbat_flash_read_data()
1198 static int usbat_flash_write_data(struct us_data *us, in usbat_flash_write_data() argument
1217 unsigned int sg_offset = 0; in usbat_flash_write_data()
1220 result = usbat_flash_check_media(us, info); in usbat_flash_write_data()
1231 if (sector > 0x0FFFFFFF) in usbat_flash_write_data()
1253 thistime = (len / info->ssize) & 0xff; in usbat_flash_write_data()
1256 usb_stor_access_xfer_buf(buffer, len, us->srb, in usbat_flash_write_data()
1259 /* ATA command 0x30 (WRITE SECTORS) */ in usbat_flash_write_data()
1260 usbat_pack_ata_sector_cmd(command, thistime, sector, 0x30); in usbat_flash_write_data()
1263 result = usbat_multiple_write(us, registers, command, 7); in usbat_flash_write_data()
1268 result = usbat_write_blocks(us, buffer, len, 0); in usbat_flash_write_data()
1274 } while (totallen > 0); in usbat_flash_write_data()
1288 static int usbat_hp8200e_handle_read10(struct us_data *us, in usbat_hp8200e_handle_read10() argument
1297 unsigned int sg_offset = 0; in usbat_hp8200e_handle_read10()
1300 usb_stor_dbg(us, "transfersize %d\n", srb->transfersize); in usbat_hp8200e_handle_read10()
1302 if (scsi_bufflen(srb) < 0x10000) { in usbat_hp8200e_handle_read10()
1304 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, in usbat_hp8200e_handle_read10()
1306 USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD, in usbat_hp8200e_handle_read10()
1323 if (data[7+0] == GPCMD_READ_CD) { in usbat_hp8200e_handle_read10()
1327 usb_stor_dbg(us, "GPCMD_READ_CD: len %d\n", len); in usbat_hp8200e_handle_read10()
1333 usb_stor_dbg(us, "transfersize 0, forcing %d\n", in usbat_hp8200e_handle_read10()
1344 usb_stor_dbg(us, "Max read is %d bytes\n", len); in usbat_hp8200e_handle_read10()
1352 transferred = 0; in usbat_hp8200e_handle_read10()
1359 data[3] = len&0xFF; /* (cylL) = expected length (L) */ in usbat_hp8200e_handle_read10()
1360 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */ in usbat_hp8200e_handle_read10()
1366 data[7+4] = MSB_of(sector&0xFFFF); in usbat_hp8200e_handle_read10()
1367 data[7+5] = LSB_of(sector&0xFFFF); in usbat_hp8200e_handle_read10()
1368 if (data[7+0] == GPCMD_READ_CD) in usbat_hp8200e_handle_read10()
1369 data[7+6] = 0; in usbat_hp8200e_handle_read10()
1373 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, in usbat_hp8200e_handle_read10()
1375 USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD, in usbat_hp8200e_handle_read10()
1379 len, 0, 1); in usbat_hp8200e_handle_read10()
1399 static int usbat_select_and_test_registers(struct us_data *us) in usbat_select_and_test_registers() argument
1402 unsigned char *status = us->iobuf; in usbat_select_and_test_registers()
1405 for (selector = 0xA0; selector <= 0xB0; selector += 0x10) { in usbat_select_and_test_registers()
1406 if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) != in usbat_select_and_test_registers()
1410 if (usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status) != in usbat_select_and_test_registers()
1414 if (usbat_read(us, USBAT_ATA, USBAT_ATA_DEVICE, status) != in usbat_select_and_test_registers()
1418 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_select_and_test_registers()
1422 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) != in usbat_select_and_test_registers()
1426 if (usbat_write(us, USBAT_ATA, USBAT_ATA_LBA_ME, 0x55) != in usbat_select_and_test_registers()
1430 if (usbat_write(us, USBAT_ATA, USBAT_ATA_LBA_HI, 0xAA) != in usbat_select_and_test_registers()
1434 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_select_and_test_registers()
1438 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_select_and_test_registers()
1449 static int init_usbat(struct us_data *us, int devicetype) in init_usbat() argument
1455 unsigned char *status = us->iobuf; in init_usbat()
1457 us->extra = kzalloc(sizeof(struct usbat_info), GFP_NOIO); in init_usbat()
1458 if (!us->extra) in init_usbat()
1461 info = (struct usbat_info *) (us->extra); in init_usbat()
1464 rc = usbat_write_user_io(us, in init_usbat()
1470 usb_stor_dbg(us, "INIT 1\n"); in init_usbat()
1474 rc = usbat_read_user_io(us, status); in init_usbat()
1478 usb_stor_dbg(us, "INIT 2\n"); in init_usbat()
1480 rc = usbat_read_user_io(us, status); in init_usbat()
1484 rc = usbat_read_user_io(us, status); in init_usbat()
1488 usb_stor_dbg(us, "INIT 3\n"); in init_usbat()
1490 rc = usbat_select_and_test_registers(us); in init_usbat()
1494 usb_stor_dbg(us, "INIT 4\n"); in init_usbat()
1496 rc = usbat_read_user_io(us, status); in init_usbat()
1500 usb_stor_dbg(us, "INIT 5\n"); in init_usbat()
1503 rc = usbat_device_enable_cdt(us); in init_usbat()
1507 usb_stor_dbg(us, "INIT 6\n"); in init_usbat()
1509 rc = usbat_read_user_io(us, status); in init_usbat()
1513 usb_stor_dbg(us, "INIT 7\n"); in init_usbat()
1517 rc = usbat_read_user_io(us, status); in init_usbat()
1521 usb_stor_dbg(us, "INIT 8\n"); in init_usbat()
1523 rc = usbat_select_and_test_registers(us); in init_usbat()
1527 usb_stor_dbg(us, "INIT 9\n"); in init_usbat()
1530 if (usbat_set_transport(us, info, devicetype)) in init_usbat()
1533 usb_stor_dbg(us, "INIT 10\n"); in init_usbat()
1535 if (usbat_get_device_type(us) == USBAT_DEV_FLASH) { in init_usbat()
1536 subcountH = 0x02; in init_usbat()
1537 subcountL = 0x00; in init_usbat()
1539 rc = usbat_set_shuttle_features(us, (USBAT_FEAT_ETEN | USBAT_FEAT_ET2 | USBAT_FEAT_ET1), in init_usbat()
1540 0x00, 0x88, 0x08, subcountH, subcountL); in init_usbat()
1544 usb_stor_dbg(us, "INIT 11\n"); in init_usbat()
1546 return 0; in init_usbat()
1552 static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us) in usbat_hp8200e_transport() argument
1555 unsigned char *status = us->iobuf; in usbat_hp8200e_transport()
1569 registers[0] = USBAT_ATA_FEATURES; in usbat_hp8200e_transport()
1576 data[0] = 0x00; in usbat_hp8200e_transport()
1577 data[1] = 0x00; in usbat_hp8200e_transport()
1578 data[2] = 0x00; in usbat_hp8200e_transport()
1579 data[3] = len&0xFF; /* (cylL) = expected length (L) */ in usbat_hp8200e_transport()
1580 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */ in usbat_hp8200e_transport()
1581 data[5] = 0xB0; /* (device sel) = slave */ in usbat_hp8200e_transport()
1582 data[6] = 0xA0; /* (command) = ATA PACKET COMMAND */ in usbat_hp8200e_transport()
1585 registers[i] = 0x10; in usbat_hp8200e_transport()
1586 data[i] = (i-7 >= srb->cmd_len) ? 0 : srb->cmnd[i-7]; in usbat_hp8200e_transport()
1589 result = usbat_get_status(us, status); in usbat_hp8200e_transport()
1590 usb_stor_dbg(us, "Status = %02X\n", *status); in usbat_hp8200e_transport()
1593 if (srb->cmnd[0] == TEST_UNIT_READY) in usbat_hp8200e_transport()
1594 transferred = 0; in usbat_hp8200e_transport()
1598 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, in usbat_hp8200e_transport()
1600 USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD, in usbat_hp8200e_transport()
1608 usb_stor_dbg(us, "Wrote %08X bytes\n", transferred); in usbat_hp8200e_transport()
1613 } else if (srb->cmnd[0] == READ_10 || in usbat_hp8200e_transport()
1614 srb->cmnd[0] == GPCMD_READ_CD) { in usbat_hp8200e_transport()
1616 return usbat_hp8200e_handle_read10(us, registers, data, srb); in usbat_hp8200e_transport()
1620 if (len > 0xFFFF) { in usbat_hp8200e_transport()
1621 usb_stor_dbg(us, "Error: len = %08X... what do I do now?\n", in usbat_hp8200e_transport()
1626 result = usbat_multiple_write(us, registers, data, 7); in usbat_hp8200e_transport()
1641 result = usbat_write_block(us, USBAT_ATA, srb->cmnd, 12, in usbat_hp8200e_transport()
1642 srb->cmnd[0] == GPCMD_BLANK ? 75 : 10, 0); in usbat_hp8200e_transport()
1649 if (len != 0 && (srb->sc_data_direction == DMA_FROM_DEVICE)) { in usbat_hp8200e_transport()
1653 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_hp8200e_transport()
1658 if (len > 0xFF) { /* need to read cylH also */ in usbat_hp8200e_transport()
1660 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) != in usbat_hp8200e_transport()
1670 result = usbat_read_block(us, scsi_sglist(srb), len, in usbat_hp8200e_transport()
1680 static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us) in usbat_flash_transport() argument
1683 struct usbat_info *info = (struct usbat_info *) (us->extra); in usbat_flash_transport()
1685 unsigned char *ptr = us->iobuf; in usbat_flash_transport()
1687 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00 in usbat_flash_transport()
1690 if (srb->cmnd[0] == INQUIRY) { in usbat_flash_transport()
1691 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n"); in usbat_flash_transport()
1693 fill_inquiry_response(us, ptr, 36); in usbat_flash_transport()
1697 if (srb->cmnd[0] == READ_CAPACITY) { in usbat_flash_transport()
1698 rc = usbat_flash_check_media(us, info); in usbat_flash_transport()
1702 rc = usbat_flash_get_sector_count(us, info); in usbat_flash_transport()
1707 info->ssize = 0x200; in usbat_flash_transport()
1708 usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n", in usbat_flash_transport()
1716 ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1); in usbat_flash_transport()
1723 if (srb->cmnd[0] == MODE_SELECT_10) { in usbat_flash_transport()
1724 usb_stor_dbg(us, "Gah! MODE_SELECT_10\n"); in usbat_flash_transport()
1728 if (srb->cmnd[0] == READ_10) { in usbat_flash_transport()
1734 usb_stor_dbg(us, "READ_10: read block 0x%04lx count %ld\n", in usbat_flash_transport()
1736 return usbat_flash_read_data(us, info, block, blocks); in usbat_flash_transport()
1739 if (srb->cmnd[0] == READ_12) { in usbat_flash_transport()
1749 usb_stor_dbg(us, "READ_12: read block 0x%04lx count %ld\n", in usbat_flash_transport()
1751 return usbat_flash_read_data(us, info, block, blocks); in usbat_flash_transport()
1754 if (srb->cmnd[0] == WRITE_10) { in usbat_flash_transport()
1760 usb_stor_dbg(us, "WRITE_10: write block 0x%04lx count %ld\n", in usbat_flash_transport()
1762 return usbat_flash_write_data(us, info, block, blocks); in usbat_flash_transport()
1765 if (srb->cmnd[0] == WRITE_12) { in usbat_flash_transport()
1775 usb_stor_dbg(us, "WRITE_12: write block 0x%04lx count %ld\n", in usbat_flash_transport()
1777 return usbat_flash_write_data(us, info, block, blocks); in usbat_flash_transport()
1781 if (srb->cmnd[0] == TEST_UNIT_READY) { in usbat_flash_transport()
1782 usb_stor_dbg(us, "TEST_UNIT_READY\n"); in usbat_flash_transport()
1784 rc = usbat_flash_check_media(us, info); in usbat_flash_transport()
1788 return usbat_check_status(us); in usbat_flash_transport()
1791 if (srb->cmnd[0] == REQUEST_SENSE) { in usbat_flash_transport()
1792 usb_stor_dbg(us, "REQUEST_SENSE\n"); in usbat_flash_transport()
1794 memset(ptr, 0, 18); in usbat_flash_transport()
1795 ptr[0] = 0xF0; in usbat_flash_transport()
1805 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { in usbat_flash_transport()
1813 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n", in usbat_flash_transport()
1814 srb->cmnd[0], srb->cmnd[0]); in usbat_flash_transport()
1815 info->sense_key = 0x05; in usbat_flash_transport()
1816 info->sense_asc = 0x20; in usbat_flash_transport()
1817 info->sense_ascq = 0x00; in usbat_flash_transport()
1821 static int init_usbat_cd(struct us_data *us) in init_usbat_cd() argument
1823 return init_usbat(us, USBAT_DEV_HP8200); in init_usbat_cd()
1826 static int init_usbat_flash(struct us_data *us) in init_usbat_flash() argument
1828 return init_usbat(us, USBAT_DEV_FLASH); in init_usbat_flash()
1836 struct us_data *us; in usbat_probe() local
1839 result = usb_stor_probe1(&us, intf, id, in usbat_probe()
1849 us->transport_name = "Shuttle USBAT"; in usbat_probe()
1850 us->transport = usbat_flash_transport; in usbat_probe()
1851 us->transport_reset = usb_stor_CB_reset; in usbat_probe()
1852 us->max_lun = 0; in usbat_probe()
1854 result = usb_stor_probe2(us); in usbat_probe()