122 #include <linux/module.h>
123 #include <linux/kernel.h>
124 #include <linux/signal.h>
125 #include <linux/errno.h>
126 #include <linux/random.h>
127 #include <linux/poll.h>
129 #include <linux/slab.h>
136 #include "../../scsi/scsi.h"
144 #define DRIVER_VERSION "v0.4.3"
146 #define DRIVER_DESC "Microtek Scanmaker X6 USB scanner driver"
160 static struct usb_driver mts_usb_driver = {
161 .name =
"microtekX6",
162 .probe = mts_usb_probe,
163 .disconnect = mts_usb_disconnect,
164 .id_table = mts_usb_ids,
170 #define MTS_VERSION "0.4.3"
171 #define MTS_NAME "microtek usb (rev " MTS_VERSION "): "
173 #define MTS_WARNING(x...) \
174 printk( KERN_WARNING MTS_NAME x )
175 #define MTS_ERROR(x...) \
176 printk( KERN_ERR MTS_NAME x )
177 #define MTS_INT_ERROR(x...) \
179 #define MTS_MESSAGE(x...) \
180 printk( KERN_INFO MTS_NAME x )
182 #if defined MTS_DO_DEBUG
184 #define MTS_DEBUG(x...) \
185 printk( KERN_DEBUG MTS_NAME x )
187 #define MTS_DEBUG_GOT_HERE() \
188 MTS_DEBUG("got to %s:%d (%s)\n", __FILE__, (int)__LINE__, __func__ )
189 #define MTS_DEBUG_INT() \
190 do { MTS_DEBUG_GOT_HERE(); \
191 MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \
192 MTS_DEBUG("status = 0x%x data-length = 0x%x sent = 0x%x\n",transfer->status,(int)context->data_length, (int)transfer->actual_length ); \
193 mts_debug_dump(context->instance);\
197 #define MTS_NUL_STATEMENT do { } while(0)
199 #define MTS_DEBUG(x...) MTS_NUL_STATEMENT
200 #define MTS_DEBUG_GOT_HERE() MTS_NUL_STATEMENT
201 #define MTS_DEBUG_INT() MTS_NUL_STATEMENT
207 #define MTS_INT_INIT()\
208 struct mts_transfer_context* context = (struct mts_transfer_context*)transfer->context; \
213 static inline void mts_debug_dump(
struct mts_desc*
desc) {
214 MTS_DEBUG(
"desc at 0x%x: toggle = %02x%02x\n",
216 (
int)desc->
usb_dev->toggle[1],(
int)desc->usb_dev->toggle[0]
218 MTS_DEBUG(
"ep_out=%x ep_response=%x ep_image=%x\n",
219 usb_sndbulkpipe(desc->usb_dev,desc->ep_out),
220 usb_rcvbulkpipe(desc->usb_dev,desc->ep_response),
221 usb_rcvbulkpipe(desc->usb_dev,desc->ep_image)
226 static inline void mts_show_command(
struct scsi_cmnd *
srb)
230 switch (srb->
cmnd[0]) {
237 case READ_6: what =
"READ_6";
break;
238 case WRITE_6: what =
"WRITE_6";
break;
239 case SEEK_6: what =
"SEEK_6";
break;
242 case SPACE: what =
"SPACE";
break;
243 case INQUIRY: what =
"INQUIRY";
break;
246 case RESERVE: what =
"RESERVE";
break;
247 case RELEASE: what =
"RELEASE";
break;
248 case COPY: what =
"COPY";
break;
249 case ERASE: what =
"ERASE";
break;
257 case READ_10: what =
"READ_10";
break;
258 case WRITE_10: what =
"WRITE_10";
break;
259 case SEEK_10: what =
"SEEK_10";
break;
261 case VERIFY: what =
"VERIFY";
break;
271 case COMPARE: what =
"COMPARE";
break;
276 case READ_LONG: what =
"READ_LONG";
break;
280 case READ_TOC: what =
"READ_TOC";
break;
282 case LOG_SENSE: what =
"LOG_SENSE";
break;
286 case READ_12: what =
"READ_12";
break;
287 case WRITE_12: what =
"WRITE_12";
break;
303 MTS_DEBUG(
" %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
320 static inline void mts_urb_abort(
struct mts_desc*
desc) {
322 mts_debug_dump(desc);
339 static int mts_scsi_abort(
struct scsi_cmnd *srb)
350 static int mts_scsi_host_reset(
struct scsi_cmnd *srb)
356 mts_debug_dump(desc);
361 usb_unlock_device(desc->
usb_dev);
369 static void mts_transfer_cleanup(
struct urb *transfer );
370 static void mts_do_sg(
struct urb * transfer);
373 void mts_int_submit_urb (
struct urb* transfer,
386 usb_fill_bulk_urb(transfer,
397 MTS_INT_ERROR(
"could not submit URB! Error was %d\n",(
int)res );
399 mts_transfer_cleanup(transfer);
404 static void mts_transfer_cleanup(
struct urb *transfer )
413 static void mts_transfer_done(
struct urb *transfer )
420 mts_transfer_cleanup(transfer);
424 static void mts_get_status(
struct urb *transfer )
429 mts_int_submit_urb(transfer,
430 usb_rcvbulkpipe(
context->instance->usb_dev,
431 context->instance->ep_response),
437 static void mts_data_done(
struct urb* transfer )
440 int status = transfer->status;
443 if (
context->data_length != transfer->actual_length ) {
445 transfer->actual_length);
450 mts_get_status(transfer);
454 static void mts_command_done(
struct urb *transfer )
457 int status = transfer->status;
471 mts_transfer_cleanup(transfer);
477 mts_int_submit_urb(transfer,
482 }
else {
if (
context->data ) {
483 mts_int_submit_urb(transfer,
487 scsi_sg_count(
context->srb) > 1 ?
488 mts_do_sg : mts_data_done);
490 mts_get_status(transfer);
495 static void mts_do_sg (
struct urb* transfer)
498 int status = transfer->status;
506 mts_transfer_cleanup(transfer);
509 sg = scsi_sglist(
context->srb);
511 mts_int_submit_urb(transfer,
513 sg_virt(&sg[
context->fragment]),
516 mts_data_done : mts_do_sg);
519 static const u8 mts_read_image_sig[] = { 0x28, 00, 00, 00 };
520 static const u8 mts_read_image_sig_len = 4;
521 static const unsigned char mts_direction[256/8] = {
522 0x28, 0x81, 0x14, 0x14, 0x20, 0x01, 0x90, 0x77,
523 0x0C, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
524 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
525 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
529 #define MTS_DIRECTION_IS_IN(x) ((mts_direction[x>>3] >> (x & 7)) & 1)
543 if (!scsi_bufflen(srb)) {
548 sg = scsi_sglist(srb);
549 desc->
context.data = sg_virt(&sg[0]);
558 if ( !
memcmp( srb->
cmnd, mts_read_image_sig, mts_read_image_sig_len )
560 MTS_DEBUG(
"transferring from desc->ep_image == %d\n",
564 MTS_DEBUG(
"transferring from desc->ep_response == %d\n",
567 MTS_DEBUG(
"transferring to desc->ep_out == %d\n",
583 mts_show_command(srb);
584 mts_debug_dump(desc);
588 MTS_DEBUG(
"Command to LUN=%d ID=%d CHANNEL=%d from SCSI layer\n",(
int)srb->
device->lun,(
int)srb->
device->id, (
int)srb->
device->channel );
590 MTS_DEBUG(
"this device doesn't exist\n");
601 usb_fill_bulk_urb(desc->
urb,
611 mts_build_transfer_context( srb, desc );
618 MTS_ERROR(
"error %d submitting URB\n",(
int)res);
633 .name =
"microtekX6",
634 .proc_name =
"microtekX6",
635 .queuecommand = mts_scsi_queuecommand,
636 .eh_abort_handler = mts_scsi_abort,
637 .eh_host_reset_handler = mts_scsi_host_reset,
644 .slave_alloc = mts_slave_alloc,
645 .slave_configure = mts_slave_configure,
654 { USB_DEVICE(0x4ce, 0x0300) },
655 { USB_DEVICE(0x5da, 0x0094) },
656 { USB_DEVICE(0x5da, 0x0099) },
657 { USB_DEVICE(0x5da, 0x009a) },
658 { USB_DEVICE(0x5da, 0x00a0) },
659 { USB_DEVICE(0x5da, 0x00a3) },
660 { USB_DEVICE(0x5da, 0x80a3) },
661 { USB_DEVICE(0x5da, 0x80ac) },
662 { USB_DEVICE(0x5da, 0x00b6) },
676 int *ep_in_current = ep_in_set;
680 struct usb_device *
dev = interface_to_usbdev (intf);
683 struct usb_host_interface *altsetting;
686 MTS_DEBUG(
"usb-device descriptor at %x\n", (
int)dev );
688 MTS_DEBUG(
"product id = 0x%x, vendor id = 0x%x\n",
695 altsetting = intf->cur_altsetting;
701 MTS_WARNING(
"expecting %d got %d endpoints! Bailing out.\n",
702 (
int)
MTS_EP_TOTAL, (
int)altsetting->desc.bNumEndpoints );
706 for( i = 0; i < altsetting->desc.bNumEndpoints; i++ ) {
707 if ((altsetting->endpoint[i].desc.bmAttributes &
710 MTS_WARNING(
"can only deal with bulk endpoints; endpoint %d is not bulk.\n",
711 (
int)altsetting->endpoint[i].desc.bEndpointAddress );
713 if (altsetting->endpoint[i].desc.bEndpointAddress &
716 = altsetting->endpoint[
i].desc.bEndpointAddress &
719 if ( ep_out != -1 ) {
720 MTS_WARNING(
"can only deal with one output endpoints. Bailing out." );
724 ep_out = altsetting->endpoint[
i].desc.bEndpointAddress &
732 if ( ep_out == -1 ) {
733 MTS_WARNING(
"couldn't find an output bulk endpoint. Bailing out.\n" );
747 if (!new_desc->
context.scsi_status)
754 new_desc->
ep_out = ep_out;
759 MTS_WARNING(
"will this work? Command EP is not usually %d\n",
763 MTS_WARNING(
"will this work? Response EP is not usually %d\n",
767 MTS_WARNING(
"will this work? Image data EP is not usually %d\n",
775 new_desc->
host->hostdata[0] = (
unsigned long)new_desc;
776 if (scsi_add_host(new_desc->
host, &dev->dev)) {
782 usb_set_intfdata(intf, new_desc);
799 struct mts_desc *desc = usb_get_intfdata(intf);
801 usb_set_intfdata(intf,
NULL);