Home | History | Annotate | Line # | Download | only in usb
umass_quirks.c revision 1.2
      1 /*	$NetBSD: umass_quirks.c,v 1.2 2001/12/22 13:21:59 gehenna 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/umassbus.h>
     49 #include <dev/usb/umassvar.h>
     50 #include <dev/usb/umass_quirks.h>
     51 
     52 Static usbd_status umass_init_insystem(struct umass_softc *);
     53 Static usbd_status umass_init_shuttle(struct umass_softc *);
     54 
     55 Static void umass_fixup_iomega(struct umass_softc *);
     56 Static void umass_fixup_microtech(struct umass_softc *);
     57 Static void umass_fixup_sony(struct umass_softc *);
     58 Static void umass_fixup_yedata(struct umass_softc *);
     59 
     60 Static const struct umass_quirk umass_quirks[] = {
     61 	{ { USB_VENDOR_FUJIPHOTO, USB_PRODUCT_FUJIPHOTO_MASS0100 },
     62 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     63 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP |
     64 	  UMASS_QUIRK_NO_REQUEST_SENSE,
     65 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     66 	  NULL, NULL
     67 	},
     68 
     69 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE },
     70 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
     71 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP,
     72 	  UMATCH_VENDOR_PRODUCT,
     73 	  umass_init_insystem, NULL
     74 	},
     75 
     76 	{ { USB_VENDOR_IOMEGA, USB_PRODUCT_IOMEGA_ZIP100 },
     77 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     78 	  UMASS_QUIRK_NO_TEST_UNIT_READY,
     79 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     80 	  NULL, umass_fixup_iomega
     81 	},
     82 
     83 	{ { USB_VENDOR_IOMEGA, USB_PRODUCT_IOMEGA_ZIP250 },
     84 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     85 	  UMASS_QUIRK_NO_TEST_UNIT_READY,
     86 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     87 	  NULL, umass_fixup_iomega
     88 	},
     89 
     90 	{ { USB_VENDOR_MICROTECH, USB_PRODUCT_MICROTECH_DPCM },
     91 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
     92 	  0,
     93 	  UMATCH_VENDOR_PRODUCT,
     94 	  NULL, umass_fixup_microtech
     95 	},
     96 
     97 	{ { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
     98 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     99 	  UMASS_QUIRK_WRONG_CSWSIG,
    100 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    101 	  NULL, NULL
    102 	},
    103 
    104 	{ { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
    105 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    106 	  0,
    107 	  UMATCH_VENDOR_PRODUCT,
    108 	  NULL, NULL
    109 	},
    110 
    111 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
    112 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    113 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP,
    114 	  UMATCH_VENDOR_PRODUCT,
    115 	  umass_init_shuttle, NULL
    116 	},
    117 
    118 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ZIOMMC },
    119 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    120 	  UMASS_QUIRK_NO_TEST_UNIT_READY | UMASS_QUIRK_NO_START_STOP,
    121 	  UMATCH_VENDOR_PRODUCT,
    122 	  NULL, NULL
    123 	},
    124 
    125 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_MSC },
    126 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    127 	  UMASS_QUIRK_FORCE_SHORT_INQUIRY,
    128 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    129 	  NULL, umass_fixup_sony
    130 	},
    131 
    132 	{ { USB_VENDOR_SONY, USB_PRODUCT_ANY },
    133 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_RBC,
    134 	  0,
    135 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    136 	  NULL, umass_fixup_sony
    137 	},
    138 
    139 	{ { USB_VENDOR_YANO, USB_PRODUCT_YANO_U640MO },
    140 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    141 	  UMASS_QUIRK_FORCE_SHORT_INQUIRY,
    142 	  UMATCH_VENDOR_PRODUCT,
    143 	  NULL, NULL
    144 	},
    145 
    146 	{ { USB_VENDOR_YEDATA, USB_PRODUCT_YEDATA_FLASHBUSTERU },
    147 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    148 	  UMASS_QUIRK_RS_NO_CLEAR_UA,
    149 	  UMATCH_VENDOR_PRODUCT_REV,
    150 	  NULL, umass_fixup_yedata
    151 	},
    152 };
    153 
    154 const struct umass_quirk *
    155 umass_lookup(u_int16_t vendor, u_int16_t product)
    156 {
    157 	const struct usb_devno *udev;
    158 	int n, i;
    159 
    160 	n = sizeof(umass_quirks) / sizeof(umass_quirks[0]);
    161 
    162 	udev = usb_match_device((const struct usb_devno *)umass_quirks, n,
    163 				sizeof(struct umass_quirk), vendor, product);
    164 	if (udev != NULL)
    165 		return ((const struct umass_quirk *)udev);
    166 
    167 	for (i = 0 ; i < n ; i++) {
    168 		if (umass_quirks[i].uq_dev.ud_vendor == vendor &&
    169 		    umass_quirks[i].uq_dev.ud_product == USB_PRODUCT_ANY)
    170 			return (&umass_quirks[i]);
    171 	}
    172 
    173 	return (NULL);
    174 }
    175 
    176 Static usbd_status
    177 umass_init_insystem(struct umass_softc *sc)
    178 {
    179 	usbd_status err;
    180 
    181 	err = usbd_set_interface(sc->sc_iface, 1);
    182 	if (err) {
    183 		DPRINTF(UDMASS_USB,
    184 			("%s: could not switch to Alt Interface 1\n",
    185 			USBDEVNAME(sc->sc_dev)));
    186 		return (err);
    187 	}
    188 
    189 	return (USBD_NORMAL_COMPLETION);
    190 }
    191 
    192 Static usbd_status
    193 umass_init_shuttle(struct umass_softc *sc)
    194 {
    195 	usb_device_request_t req;
    196 	u_int8_t status[2];
    197 
    198 	/* The Linux driver does this */
    199 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    200 	req.bRequest = 1;
    201 	USETW(req.wValue, 0);
    202 	USETW(req.wIndex, sc->sc_ifaceno);
    203 	USETW(req.wLength, sizeof(status));
    204 
    205 	return (usbd_do_request(sc->sc_udev, &req, &status));
    206 }
    207 
    208 Static void
    209 umass_fixup_iomega(struct umass_softc *sc)
    210 {
    211 	sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED;
    212 }
    213 
    214 Static void
    215 umass_fixup_microtech(struct umass_softc *sc)
    216 {
    217 	sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED * 2;
    218 }
    219 
    220 Static void
    221 umass_fixup_sony(struct umass_softc *sc)
    222 {
    223 	usb_interface_descriptor_t *id;
    224 
    225 	id = usbd_get_interface_descriptor(sc->sc_iface);
    226 	if (id->bInterfaceSubClass == 0xff) {
    227 		sc->sc_cmd = UMASS_CPROTO_RBC;
    228 		sc->transfer_speed = 500;
    229 	}
    230 }
    231 
    232 Static void
    233 umass_fixup_yedata(struct umass_softc *sc)
    234 {
    235 	usb_device_descriptor_t *dd;
    236 
    237 	dd = usbd_get_device_descriptor(sc->sc_udev);
    238 
    239 	/*
    240 	 * Revisions < 1.28 do not handle the interrupt endpoint very well.
    241 	 */
    242 	if (UGETW(dd->bcdDevice) < 0x128)
    243 		sc->sc_wire = UMASS_WPROTO_CBI;
    244 	else
    245 		sc->sc_wire = UMASS_WPROTO_CBI_I;
    246 
    247 	/*
    248 	 * Revisions < 1.28 do not have the TEST UNIT READY command
    249 	 * Revisions == 1.28 have a broken TEST UNIT READY
    250 	 */
    251 	if (UGETW(dd->bcdDevice) <= 0x128)
    252 		sc->sc_quirks |= UMASS_QUIRK_NO_TEST_UNIT_READY;
    253 }
    254