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