aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/storage/shuttle_usbat.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/storage/shuttle_usbat.c')
-rw-r--r--drivers/usb/storage/shuttle_usbat.c105
1 files changed, 66 insertions, 39 deletions
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index f2bc5c9e23d5..8fcec01dc622 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -131,28 +131,30 @@ static int usbat_write(struct us_data *us,
131 * Convenience function to perform a bulk read 131 * Convenience function to perform a bulk read
132 */ 132 */
133static int usbat_bulk_read(struct us_data *us, 133static int usbat_bulk_read(struct us_data *us,
134 unsigned char *data, 134 unsigned char *data,
135 unsigned int len) 135 unsigned int len,
136 int use_sg)
136{ 137{
137 if (len == 0) 138 if (len == 0)
138 return USB_STOR_XFER_GOOD; 139 return USB_STOR_XFER_GOOD;
139 140
140 US_DEBUGP("usbat_bulk_read: len = %d\n", len); 141 US_DEBUGP("usbat_bulk_read: len = %d\n", len);
141 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, data, len, NULL); 142 return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, data, len, use_sg, NULL);
142} 143}
143 144
144/* 145/*
145 * Convenience function to perform a bulk write 146 * Convenience function to perform a bulk write
146 */ 147 */
147static int usbat_bulk_write(struct us_data *us, 148static int usbat_bulk_write(struct us_data *us,
148 unsigned char *data, 149 unsigned char *data,
149 unsigned int len) 150 unsigned int len,
151 int use_sg)
150{ 152{
151 if (len == 0) 153 if (len == 0)
152 return USB_STOR_XFER_GOOD; 154 return USB_STOR_XFER_GOOD;
153 155
154 US_DEBUGP("usbat_bulk_write: len = %d\n", len); 156 US_DEBUGP("usbat_bulk_write: len = %d\n", len);
155 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, data, len, NULL); 157 return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, data, len, use_sg, NULL);
156} 158}
157 159
158/* 160/*
@@ -317,7 +319,8 @@ static int usbat_wait_not_busy(struct us_data *us, int minutes)
317 */ 319 */
318static int usbat_read_block(struct us_data *us, 320static int usbat_read_block(struct us_data *us,
319 unsigned char *content, 321 unsigned char *content,
320 unsigned short len) 322 unsigned short len,
323 int use_sg)
321{ 324{
322 int result; 325 int result;
323 unsigned char *command = us->iobuf; 326 unsigned char *command = us->iobuf;
@@ -338,7 +341,7 @@ static int usbat_read_block(struct us_data *us,
338 if (result != USB_STOR_XFER_GOOD) 341 if (result != USB_STOR_XFER_GOOD)
339 return USB_STOR_TRANSPORT_ERROR; 342 return USB_STOR_TRANSPORT_ERROR;
340 343
341 result = usbat_bulk_read(us, content, len); 344 result = usbat_bulk_read(us, content, len, use_sg);
342 return (result == USB_STOR_XFER_GOOD ? 345 return (result == USB_STOR_XFER_GOOD ?
343 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR); 346 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
344} 347}
@@ -350,7 +353,8 @@ static int usbat_write_block(struct us_data *us,
350 unsigned char access, 353 unsigned char access,
351 unsigned char *content, 354 unsigned char *content,
352 unsigned short len, 355 unsigned short len,
353 int minutes) 356 int minutes,
357 int use_sg)
354{ 358{
355 int result; 359 int result;
356 unsigned char *command = us->iobuf; 360 unsigned char *command = us->iobuf;
@@ -372,7 +376,7 @@ static int usbat_write_block(struct us_data *us,
372 if (result != USB_STOR_XFER_GOOD) 376 if (result != USB_STOR_XFER_GOOD)
373 return USB_STOR_TRANSPORT_ERROR; 377 return USB_STOR_TRANSPORT_ERROR;
374 378
375 result = usbat_bulk_write(us, content, len); 379 result = usbat_bulk_write(us, content, len, use_sg);
376 if (result != USB_STOR_XFER_GOOD) 380 if (result != USB_STOR_XFER_GOOD)
377 return USB_STOR_TRANSPORT_ERROR; 381 return USB_STOR_TRANSPORT_ERROR;
378 382
@@ -465,7 +469,7 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
465 data[1+(j<<1)] = data_out[j]; 469 data[1+(j<<1)] = data_out[j];
466 } 470 }
467 471
468 result = usbat_bulk_write(us, data, num_registers*2); 472 result = usbat_bulk_write(us, data, num_registers*2, 0);
469 if (result != USB_STOR_XFER_GOOD) 473 if (result != USB_STOR_XFER_GOOD)
470 return USB_STOR_TRANSPORT_ERROR; 474 return USB_STOR_TRANSPORT_ERROR;
471 475
@@ -583,7 +587,7 @@ static int usbat_multiple_write(struct us_data *us,
583 } 587 }
584 588
585 /* Send the data */ 589 /* Send the data */
586 result = usbat_bulk_write(us, data, num_registers*2); 590 result = usbat_bulk_write(us, data, num_registers*2, 0);
587 if (result != USB_STOR_XFER_GOOD) 591 if (result != USB_STOR_XFER_GOOD)
588 return USB_STOR_TRANSPORT_ERROR; 592 return USB_STOR_TRANSPORT_ERROR;
589 593
@@ -606,8 +610,9 @@ static int usbat_multiple_write(struct us_data *us,
606 * other related details) are defined beforehand with _set_shuttle_features(). 610 * other related details) are defined beforehand with _set_shuttle_features().
607 */ 611 */
608static int usbat_read_blocks(struct us_data *us, 612static int usbat_read_blocks(struct us_data *us,
609 unsigned char *buffer, 613 unsigned char *buffer,
610 int len) 614 int len,
615 int use_sg)
611{ 616{
612 int result; 617 int result;
613 unsigned char *command = us->iobuf; 618 unsigned char *command = us->iobuf;
@@ -627,7 +632,7 @@ static int usbat_read_blocks(struct us_data *us,
627 return USB_STOR_TRANSPORT_FAILED; 632 return USB_STOR_TRANSPORT_FAILED;
628 633
629 /* Read the blocks we just asked for */ 634 /* Read the blocks we just asked for */
630 result = usbat_bulk_read(us, buffer, len); 635 result = usbat_bulk_read(us, buffer, len, use_sg);
631 if (result != USB_STOR_XFER_GOOD) 636 if (result != USB_STOR_XFER_GOOD)
632 return USB_STOR_TRANSPORT_FAILED; 637 return USB_STOR_TRANSPORT_FAILED;
633 638
@@ -648,7 +653,8 @@ static int usbat_read_blocks(struct us_data *us,
648 */ 653 */
649static int usbat_write_blocks(struct us_data *us, 654static int usbat_write_blocks(struct us_data *us,
650 unsigned char *buffer, 655 unsigned char *buffer,
651 int len) 656 int len,
657 int use_sg)
652{ 658{
653 int result; 659 int result;
654 unsigned char *command = us->iobuf; 660 unsigned char *command = us->iobuf;
@@ -668,7 +674,7 @@ static int usbat_write_blocks(struct us_data *us,
668 return USB_STOR_TRANSPORT_FAILED; 674 return USB_STOR_TRANSPORT_FAILED;
669 675
670 /* Write the data */ 676 /* Write the data */
671 result = usbat_bulk_write(us, buffer, len); 677 result = usbat_bulk_write(us, buffer, len, use_sg);
672 if (result != USB_STOR_XFER_GOOD) 678 if (result != USB_STOR_XFER_GOOD)
673 return USB_STOR_TRANSPORT_FAILED; 679 return USB_STOR_TRANSPORT_FAILED;
674 680
@@ -887,22 +893,28 @@ static int usbat_identify_device(struct us_data *us,
887 * Set the transport function based on the device type 893 * Set the transport function based on the device type
888 */ 894 */
889static int usbat_set_transport(struct us_data *us, 895static int usbat_set_transport(struct us_data *us,
890 struct usbat_info *info) 896 struct usbat_info *info,
897 int devicetype)
891{ 898{
892 int rc;
893 899
894 if (!info->devicetype) { 900 if (!info->devicetype)
895 rc = usbat_identify_device(us, info); 901 info->devicetype = devicetype;
896 if (rc != USB_STOR_TRANSPORT_GOOD) {
897 US_DEBUGP("usbat_set_transport: Could not identify device\n");
898 return 1;
899 }
900 }
901 902
902 if (usbat_get_device_type(us) == USBAT_DEV_HP8200) 903 if (!info->devicetype)
904 usbat_identify_device(us, info);
905
906 switch (info->devicetype) {
907 default:
908 return USB_STOR_TRANSPORT_ERROR;
909
910 case USBAT_DEV_HP8200:
903 us->transport = usbat_hp8200e_transport; 911 us->transport = usbat_hp8200e_transport;
904 else if (usbat_get_device_type(us) == USBAT_DEV_FLASH) 912 break;
913
914 case USBAT_DEV_FLASH:
905 us->transport = usbat_flash_transport; 915 us->transport = usbat_flash_transport;
916 break;
917 }
906 918
907 return 0; 919 return 0;
908} 920}
@@ -947,7 +959,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
947 msleep(100); 959 msleep(100);
948 960
949 /* Read the device identification data */ 961 /* Read the device identification data */
950 rc = usbat_read_block(us, reply, 512); 962 rc = usbat_read_block(us, reply, 512, 0);
951 if (rc != USB_STOR_TRANSPORT_GOOD) 963 if (rc != USB_STOR_TRANSPORT_GOOD)
952 goto leave; 964 goto leave;
953 965
@@ -1031,7 +1043,7 @@ static int usbat_flash_read_data(struct us_data *us,
1031 goto leave; 1043 goto leave;
1032 1044
1033 /* Read the data we just requested */ 1045 /* Read the data we just requested */
1034 result = usbat_read_blocks(us, buffer, len); 1046 result = usbat_read_blocks(us, buffer, len, 0);
1035 if (result != USB_STOR_TRANSPORT_GOOD) 1047 if (result != USB_STOR_TRANSPORT_GOOD)
1036 goto leave; 1048 goto leave;
1037 1049
@@ -1125,7 +1137,7 @@ static int usbat_flash_write_data(struct us_data *us,
1125 goto leave; 1137 goto leave;
1126 1138
1127 /* Write the data */ 1139 /* Write the data */
1128 result = usbat_write_blocks(us, buffer, len); 1140 result = usbat_write_blocks(us, buffer, len, 0);
1129 if (result != USB_STOR_TRANSPORT_GOOD) 1141 if (result != USB_STOR_TRANSPORT_GOOD)
1130 goto leave; 1142 goto leave;
1131 1143
@@ -1310,7 +1322,7 @@ static int usbat_select_and_test_registers(struct us_data *us)
1310/* 1322/*
1311 * Initialize the USBAT processor and the storage device 1323 * Initialize the USBAT processor and the storage device
1312 */ 1324 */
1313int init_usbat(struct us_data *us) 1325static int init_usbat(struct us_data *us, int devicetype)
1314{ 1326{
1315 int rc; 1327 int rc;
1316 struct usbat_info *info; 1328 struct usbat_info *info;
@@ -1392,7 +1404,7 @@ int init_usbat(struct us_data *us)
1392 US_DEBUGP("INIT 9\n"); 1404 US_DEBUGP("INIT 9\n");
1393 1405
1394 /* At this point, we need to detect which device we are using */ 1406 /* At this point, we need to detect which device we are using */
1395 if (usbat_set_transport(us, info)) 1407 if (usbat_set_transport(us, info, devicetype))
1396 return USB_STOR_TRANSPORT_ERROR; 1408 return USB_STOR_TRANSPORT_ERROR;
1397 1409
1398 US_DEBUGP("INIT 10\n"); 1410 US_DEBUGP("INIT 10\n");
@@ -1503,10 +1515,10 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1503 * AT SPEED 4 IS UNRELIABLE!!! 1515 * AT SPEED 4 IS UNRELIABLE!!!
1504 */ 1516 */
1505 1517
1506 if ( (result = usbat_write_block(us, 1518 if ((result = usbat_write_block(us,
1507 USBAT_ATA, srb->cmnd, 12, 1519 USBAT_ATA, srb->cmnd, 12,
1508 srb->cmnd[0]==GPCMD_BLANK ? 75 : 10)) != 1520 (srb->cmnd[0]==GPCMD_BLANK ? 75 : 10), 0) !=
1509 USB_STOR_TRANSPORT_GOOD) { 1521 USB_STOR_TRANSPORT_GOOD)) {
1510 return result; 1522 return result;
1511 } 1523 }
1512 1524
@@ -1533,7 +1545,7 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1533 len = *status; 1545 len = *status;
1534 1546
1535 1547
1536 result = usbat_read_block(us, srb->request_buffer, len); 1548 result = usbat_read_block(us, srb->request_buffer, len, srb->use_sg);
1537 1549
1538 /* Debug-print the first 32 bytes of the transfer */ 1550 /* Debug-print the first 32 bytes of the transfer */
1539 1551
@@ -1695,6 +1707,22 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1695 return USB_STOR_TRANSPORT_FAILED; 1707 return USB_STOR_TRANSPORT_FAILED;
1696} 1708}
1697 1709
1710int init_usbat_cd(struct us_data *us)
1711{
1712 return init_usbat(us, USBAT_DEV_HP8200);
1713}
1714
1715
1716int init_usbat_flash(struct us_data *us)
1717{
1718 return init_usbat(us, USBAT_DEV_FLASH);
1719}
1720
1721int init_usbat_probe(struct us_data *us)
1722{
1723 return init_usbat(us, 0);
1724}
1725
1698/* 1726/*
1699 * Default transport function. Attempts to detect which transport function 1727 * Default transport function. Attempts to detect which transport function
1700 * should be called, makes it the new default, and calls it. 1728 * should be called, makes it the new default, and calls it.
@@ -1708,9 +1736,8 @@ int usbat_transport(struct scsi_cmnd *srb, struct us_data *us)
1708{ 1736{
1709 struct usbat_info *info = (struct usbat_info*) (us->extra); 1737 struct usbat_info *info = (struct usbat_info*) (us->extra);
1710 1738
1711 if (usbat_set_transport(us, info)) 1739 if (usbat_set_transport(us, info, 0))
1712 return USB_STOR_TRANSPORT_ERROR; 1740 return USB_STOR_TRANSPORT_ERROR;
1713 1741
1714 return us->transport(srb, us); 1742 return us->transport(srb, us);
1715} 1743}
1716