umass_quirks.c revision 1.3 1 /* $NetBSD: umass_quirks.c,v 1.3 2001/12/24 13:25:52 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 };
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