Home | History | Annotate | Line # | Download | only in usb
umass_quirks.c revision 1.4
      1 /*	$NetBSD: umass_quirks.c,v 1.4 2001/12/24 13:43:25 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by MAEKAWA Masahide (gehenna (at) NetBSD.org).
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	  This product includes software developed by the NetBSD
     21  *	  Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 #include <sys/buf.h>
     43 
     44 #include <dev/usb/usb.h>
     45 #include <dev/usb/usbdi.h>
     46 #include <dev/usb/usbdevs.h>
     47 
     48 #include <dev/usb/umassvar.h>
     49 #include <dev/usb/umass_quirks.h>
     50 
     51 Static usbd_status umass_init_insystem(struct umass_softc *);
     52 Static usbd_status umass_init_shuttle(struct umass_softc *);
     53 
     54 Static void umass_fixup_iomega(struct umass_softc *);
     55 Static void umass_fixup_microtech(struct umass_softc *);
     56 Static void umass_fixup_sony(struct umass_softc *);
     57 Static void umass_fixup_yedata(struct umass_softc *);
     58 
     59 Static const struct umass_quirk umass_quirks[] = {
     60 	{ { USB_VENDOR_FUJIPHOTO, USB_PRODUCT_FUJIPHOTO_MASS0100 },
     61 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     62 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP |
     63 	  UMASS_QUIRK_NO_REQUEST_SENSE,
     64 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     65 	  NULL, NULL
     66 	},
     67 
     68 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE },
     69 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
     70 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP,
     71 	  UMATCH_VENDOR_PRODUCT,
     72 	  umass_init_insystem, NULL
     73 	},
     74 
     75 	{ { USB_VENDOR_IOMEGA, USB_PRODUCT_IOMEGA_ZIP100 },
     76 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     77 	  UMASS_QUIRK_NO_TEST_UNIT_READY,
     78 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     79 	  NULL, umass_fixup_iomega
     80 	},
     81 
     82 	{ { USB_VENDOR_IOMEGA, USB_PRODUCT_IOMEGA_ZIP250 },
     83 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     84 	  UMASS_QUIRK_NO_TEST_UNIT_READY,
     85 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     86 	  NULL, umass_fixup_iomega
     87 	},
     88 
     89 	{ { USB_VENDOR_MICROTECH, USB_PRODUCT_MICROTECH_DPCM },
     90 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
     91 	  0,
     92 	  UMATCH_VENDOR_PRODUCT,
     93 	  NULL, umass_fixup_microtech
     94 	},
     95 
     96 	{ { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
     97 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     98 	  UMASS_QUIRK_WRONG_CSWSIG,
     99 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    100 	  NULL, NULL
    101 	},
    102 
    103 	{ { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
    104 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    105 	  0,
    106 	  UMATCH_VENDOR_PRODUCT,
    107 	  NULL, NULL
    108 	},
    109 
    110 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
    111 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    112 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP,
    113 	  UMATCH_VENDOR_PRODUCT,
    114 	  umass_init_shuttle, NULL
    115 	},
    116 
    117 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ZIOMMC },
    118 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    119 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP,
    120 	  UMATCH_VENDOR_PRODUCT,
    121 	  NULL, NULL
    122 	},
    123 
    124 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_MSC },
    125 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    126 	  UMASS_QUIRK_FORCE_SHORT_INQUIRY,
    127 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    128 	  NULL, umass_fixup_sony
    129 	},
    130 
    131 	{ { USB_VENDOR_SONY, USB_PRODUCT_ANY },
    132 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_RBC,
    133 	  0,
    134 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    135 	  NULL, umass_fixup_sony
    136 	},
    137 
    138 	{ { USB_VENDOR_YANO, USB_PRODUCT_YANO_U640MO },
    139 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    140 	  UMASS_QUIRK_FORCE_SHORT_INQUIRY,
    141 	  UMATCH_VENDOR_PRODUCT,
    142 	  NULL, NULL
    143 	},
    144 
    145 	{ { USB_VENDOR_YEDATA, USB_PRODUCT_YEDATA_FLASHBUSTERU },
    146 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    147 	  UMASS_QUIRK_RS_NO_CLEAR_UA,
    148 	  UMATCH_VENDOR_PRODUCT_REV,
    149 	  NULL, umass_fixup_yedata
    150 	},
    151 
    152 	/* InSystem Design ATA over USB devices */
    153 	{ { USB_VENDOR_ATI, USB_PRODUCT_ATI2_205 },
    154 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    155 	  0,
    156 	  UMATCH_VENDOR_PRODUCT,
    157 	  NULL, NULL
    158 	},
    159 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI },
    160 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    161 	  0,
    162 	  UMATCH_VENDOR_PRODUCT,
    163 	  NULL, NULL
    164 	},
    165 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 },
    166 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    167 	  0,
    168 	  UMATCH_VENDOR_PRODUCT,
    169 	  NULL, NULL
    170 	},
    171 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 },
    172 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    173 	  0,
    174 	  UMATCH_VENDOR_PRODUCT,
    175 	  NULL, NULL
    176 	},
    177 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_DRIVEV2 },
    178 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    179 	  0,
    180 	  UMATCH_VENDOR_PRODUCT,
    181 	  NULL, NULL
    182 	},
    183 };
    184 
    185 const struct umass_quirk *
    186 umass_lookup(u_int16_t vendor, u_int16_t product)
    187 {
    188 	const struct usb_devno *udev;
    189 	int n, i;
    190 
    191 	n = sizeof(umass_quirks) / sizeof(umass_quirks[0]);
    192 
    193 	udev = usb_match_device((const struct usb_devno *)umass_quirks, n,
    194 				sizeof(struct umass_quirk), vendor, product);
    195 	if (udev != NULL)
    196 		return ((const struct umass_quirk *)udev);
    197 
    198 	for (i = 0 ; i < n ; i++) {
    199 		if (umass_quirks[i].uq_dev.ud_vendor == vendor &&
    200 		    umass_quirks[i].uq_dev.ud_product == USB_PRODUCT_ANY)
    201 			return (&umass_quirks[i]);
    202 	}
    203 
    204 	return (NULL);
    205 }
    206 
    207 Static usbd_status
    208 umass_init_insystem(struct umass_softc *sc)
    209 {
    210 	usbd_status err;
    211 
    212 	err = usbd_set_interface(sc->sc_iface, 1);
    213 	if (err) {
    214 		DPRINTF(UDMASS_USB,
    215 			("%s: could not switch to Alt Interface 1\n",
    216 			USBDEVNAME(sc->sc_dev)));
    217 		return (err);
    218 	}
    219 
    220 	return (USBD_NORMAL_COMPLETION);
    221 }
    222 
    223 Static usbd_status
    224 umass_init_shuttle(struct umass_softc *sc)
    225 {
    226 	usb_device_request_t req;
    227 	u_int8_t status[2];
    228 
    229 	/* The Linux driver does this */
    230 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    231 	req.bRequest = 1;
    232 	USETW(req.wValue, 0);
    233 	USETW(req.wIndex, sc->sc_ifaceno);
    234 	USETW(req.wLength, sizeof(status));
    235 
    236 	return (usbd_do_request(sc->sc_udev, &req, &status));
    237 }
    238 
    239 Static void
    240 umass_fixup_iomega(struct umass_softc *sc)
    241 {
    242 	sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED;
    243 }
    244 
    245 Static void
    246 umass_fixup_microtech(struct umass_softc *sc)
    247 {
    248 	sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED * 2;
    249 }
    250 
    251 Static void
    252 umass_fixup_sony(struct umass_softc *sc)
    253 {
    254 	usb_interface_descriptor_t *id;
    255 
    256 	id = usbd_get_interface_descriptor(sc->sc_iface);
    257 	if (id->bInterfaceSubClass == 0xff) {
    258 		sc->sc_cmd = UMASS_CPROTO_RBC;
    259 		sc->transfer_speed = 500;
    260 	}
    261 }
    262 
    263 Static void
    264 umass_fixup_yedata(struct umass_softc *sc)
    265 {
    266 	usb_device_descriptor_t *dd;
    267 
    268 	dd = usbd_get_device_descriptor(sc->sc_udev);
    269 
    270 	/*
    271 	 * Revisions < 1.28 do not handle the interrupt endpoint very well.
    272 	 */
    273 	if (UGETW(dd->bcdDevice) < 0x128)
    274 		sc->sc_wire = UMASS_WPROTO_CBI;
    275 	else
    276 		sc->sc_wire = UMASS_WPROTO_CBI_I;
    277 
    278 	/*
    279 	 * Revisions < 1.28 do not have the TEST UNIT READY command
    280 	 * Revisions == 1.28 have a broken TEST UNIT READY
    281 	 */
    282 	if (UGETW(dd->bcdDevice) <= 0x128)
    283 		sc->sc_quirks |= UMASS_QUIRK_NO_TEST_UNIT_READY;
    284 }
    285