Home | History | Annotate | Line # | Download | only in usb
umass_quirks.c revision 1.7
      1 /*	$NetBSD: umass_quirks.c,v 1.7 2001/12/29 13:46:23 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/scsipi/scsipi_all.h> /* for scsiconf.h below */
     45 #include <dev/scsipi/scsiconf.h> /* for quirks defines */
     46 
     47 #include <dev/usb/usb.h>
     48 #include <dev/usb/usbdi.h>
     49 #include <dev/usb/usbdevs.h>
     50 
     51 #include <dev/usb/umassvar.h>
     52 #include <dev/usb/umass_quirks.h>
     53 
     54 Static usbd_status umass_init_insystem(struct umass_softc *);
     55 Static usbd_status umass_init_shuttle(struct umass_softc *);
     56 
     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_START_STOP,
     64 	  PQUIRK_NOTUR | PQUIRK_NOSENSE,
     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_START_STOP,
     72 	  PQUIRK_NOTUR,
     73 	  UMATCH_VENDOR_PRODUCT,
     74 	  umass_init_insystem, NULL
     75 	},
     76 
     77 	{ { USB_VENDOR_IOMEGA, USB_PRODUCT_IOMEGA_ZIP100 },
     78 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     79 	  0,
     80 	  PQUIRK_NOTUR,
     81 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     82 	  NULL, NULL
     83 	},
     84 
     85 	{ { USB_VENDOR_IOMEGA, USB_PRODUCT_IOMEGA_ZIP250 },
     86 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
     87 	  0,
     88 	  PQUIRK_NOTUR,
     89 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
     90 	  NULL, NULL
     91 	},
     92 
     93 	{ { USB_VENDOR_MICROTECH, USB_PRODUCT_MICROTECH_DPCM },
     94 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
     95 	  0,
     96 	  0,
     97 	  UMATCH_VENDOR_PRODUCT,
     98 	  NULL, NULL
     99 	},
    100 
    101 	{ { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
    102 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    103 	  UMASS_QUIRK_WRONG_CSWSIG,
    104 	  0,
    105 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    106 	  NULL, NULL
    107 	},
    108 
    109 	{ { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
    110 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    111 	  0,
    112 	  0,
    113 	  UMATCH_VENDOR_PRODUCT,
    114 	  NULL, NULL
    115 	},
    116 
    117 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
    118 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    119 	  UMASS_QUIRK_NO_START_STOP,
    120 	  PQUIRK_NOTUR,
    121 	  UMATCH_VENDOR_PRODUCT,
    122 	  umass_init_shuttle, NULL
    123 	},
    124 
    125 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ZIOMMC },
    126 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    127 	  UMASS_QUIRK_NO_START_STOP,
    128 	  PQUIRK_NOTUR,
    129 	  UMATCH_VENDOR_PRODUCT,
    130 	  NULL, NULL
    131 	},
    132 
    133 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_MSC },
    134 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    135 	  UMASS_QUIRK_FORCE_SHORT_INQUIRY,
    136 	  0,
    137 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    138 	  NULL, umass_fixup_sony
    139 	},
    140 
    141 	{ { USB_VENDOR_SONY, USB_PRODUCT_ANY },
    142 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_RBC,
    143 	  0,
    144 	  0,
    145 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    146 	  NULL, umass_fixup_sony
    147 	},
    148 
    149 	{ { USB_VENDOR_YANO, USB_PRODUCT_YANO_U640MO },
    150 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    151 	  UMASS_QUIRK_FORCE_SHORT_INQUIRY,
    152 	  0,
    153 	  UMATCH_VENDOR_PRODUCT,
    154 	  NULL, NULL
    155 	},
    156 
    157 	{ { USB_VENDOR_YEDATA, USB_PRODUCT_YEDATA_FLASHBUSTERU },
    158 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    159 	  UMASS_QUIRK_RS_NO_CLEAR_UA,
    160 	  0,
    161 	  UMATCH_VENDOR_PRODUCT_REV,
    162 	  NULL, umass_fixup_yedata
    163 	},
    164 
    165 	/* InSystem Design ATA over USB devices */
    166 	{ { USB_VENDOR_ATI, USB_PRODUCT_ATI2_205 },
    167 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    168 	  0,
    169 	  0,
    170 	  UMATCH_VENDOR_PRODUCT,
    171 	  NULL, NULL
    172 	},
    173 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI },
    174 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    175 	  0,
    176 	  0,
    177 	  UMATCH_VENDOR_PRODUCT,
    178 	  NULL, NULL
    179 	},
    180 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 },
    181 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    182 	  0,
    183 	  0,
    184 	  UMATCH_VENDOR_PRODUCT,
    185 	  NULL, NULL
    186 	},
    187 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 },
    188 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    189 	  0,
    190 	  0,
    191 	  UMATCH_VENDOR_PRODUCT,
    192 	  NULL, NULL
    193 	},
    194 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_DRIVEV2 },
    195 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
    196 	  0,
    197 	  0,
    198 	  UMATCH_VENDOR_PRODUCT,
    199 	  NULL, NULL
    200 	},
    201 };
    202 
    203 const struct umass_quirk *
    204 umass_lookup(u_int16_t vendor, u_int16_t product)
    205 {
    206 	return ((const struct umass_quirk *)
    207 		usb_lookup(umass_quirks, vendor, product));
    208 }
    209 
    210 Static usbd_status
    211 umass_init_insystem(struct umass_softc *sc)
    212 {
    213 	usbd_status err;
    214 
    215 	err = usbd_set_interface(sc->sc_iface, 1);
    216 	if (err) {
    217 		DPRINTF(UDMASS_USB,
    218 			("%s: could not switch to Alt Interface 1\n",
    219 			USBDEVNAME(sc->sc_dev)));
    220 		return (err);
    221 	}
    222 
    223 	return (USBD_NORMAL_COMPLETION);
    224 }
    225 
    226 Static usbd_status
    227 umass_init_shuttle(struct umass_softc *sc)
    228 {
    229 	usb_device_request_t req;
    230 	u_int8_t status[2];
    231 
    232 	/* The Linux driver does this */
    233 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    234 	req.bRequest = 1;
    235 	USETW(req.wValue, 0);
    236 	USETW(req.wIndex, sc->sc_ifaceno);
    237 	USETW(req.wLength, sizeof(status));
    238 
    239 	return (usbd_do_request(sc->sc_udev, &req, &status));
    240 }
    241 
    242 Static void
    243 umass_fixup_sony(struct umass_softc *sc)
    244 {
    245 	usb_interface_descriptor_t *id;
    246 
    247 	id = usbd_get_interface_descriptor(sc->sc_iface);
    248 	if (id->bInterfaceSubClass == 0xff) {
    249 		sc->sc_cmd = UMASS_CPROTO_RBC;
    250 	}
    251 }
    252 
    253 Static void
    254 umass_fixup_yedata(struct umass_softc *sc)
    255 {
    256 	usb_device_descriptor_t *dd;
    257 
    258 	dd = usbd_get_device_descriptor(sc->sc_udev);
    259 
    260 	/*
    261 	 * Revisions < 1.28 do not handle the interrupt endpoint very well.
    262 	 */
    263 	if (UGETW(dd->bcdDevice) < 0x128)
    264 		sc->sc_wire = UMASS_WPROTO_CBI;
    265 	else
    266 		sc->sc_wire = UMASS_WPROTO_CBI_I;
    267 
    268 	/*
    269 	 * Revisions < 1.28 do not have the TEST UNIT READY command
    270 	 * Revisions == 1.28 have a broken TEST UNIT READY
    271 	 */
    272 	if (UGETW(dd->bcdDevice) <= 0x128)
    273 		sc->sc_busquirks |= PQUIRK_NOTUR;
    274 }
    275