umass_quirks.c revision 1.1 1 /* $NetBSD: umass_quirks.c,v 1.1 2001/12/17 12:16:15 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 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 const struct umass_quirk *
154 umass_lookup(u_int16_t vendor, u_int16_t product)
155 {
156 const struct usb_devno *udev;
157 int n, i;
158
159 n = sizeof(umass_quirks) / sizeof(umass_quirks[0]);
160
161 udev = usb_match_device((const struct usb_devno *)umass_quirks, n,
162 sizeof(struct umass_quirk), vendor, product);
163 if (udev != NULL)
164 return ((const struct umass_quirk *)udev);
165
166 for (i = 0 ; i < n ; i++) {
167 if (umass_quirks[i].uq_dev.ud_vendor == vendor &&
168 umass_quirks[i].uq_dev.ud_product == USB_PRODUCT_ANY)
169 return (&umass_quirks[i]);
170 }
171
172 return (NULL);
173 }
174
175 Static usbd_status
176 umass_init_insystem(struct umass_softc *sc)
177 {
178 usbd_status err;
179
180 err = usbd_set_interface(sc->sc_iface, 1);
181 if (err) {
182 DPRINTF(UDMASS_USB,
183 ("%s: could not switch to Alt Interface 1\n",
184 USBDEVNAME(sc->sc_dev)));
185 return (err);
186 }
187
188 return (USBD_NORMAL_COMPLETION);
189 }
190
191 Static usbd_status
192 umass_init_shuttle(struct umass_softc *sc)
193 {
194 usb_device_request_t req;
195 u_int8_t status[2];
196
197 /* The Linux driver does this */
198 req.bmRequestType = UT_READ_VENDOR_DEVICE;
199 req.bRequest = 1;
200 USETW(req.wValue, 0);
201 USETW(req.wIndex, sc->sc_ifaceno);
202 USETW(req.wLength, sizeof(status));
203
204 return (usbd_do_request(sc->sc_udev, &req, &status));
205 }
206
207 Static void
208 umass_fixup_iomega(struct umass_softc *sc)
209 {
210 sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED;
211 }
212
213 Static void
214 umass_fixup_microtech(struct umass_softc *sc)
215 {
216 sc->transfer_speed = UMASS_ZIP100_TRANSFER_SPEED * 2;
217 }
218
219 Static void
220 umass_fixup_sony(struct umass_softc *sc)
221 {
222 usb_interface_descriptor_t *id;
223
224 id = usbd_get_interface_descriptor(sc->sc_iface);
225 if (id->bInterfaceSubClass == 0xff) {
226 sc->sc_cmd = UMASS_CPROTO_RBC;
227 sc->transfer_speed = 500;
228 }
229 }
230
231 Static void
232 umass_fixup_yedata(struct umass_softc *sc)
233 {
234 usb_device_descriptor_t *dd;
235
236 dd = usbd_get_device_descriptor(sc->sc_udev);
237
238 /*
239 * Revisions < 1.28 do not handle the interrupt endpoint very well.
240 */
241 if (UGETW(dd->bcdDevice) < 0x128)
242 sc->sc_wire = UMASS_WPROTO_CBI;
243 else
244 sc->sc_wire = UMASS_WPROTO_CBI_I;
245
246 /*
247 * Revisions < 1.28 do not have the TEST UNIT READY command
248 * Revisions == 1.28 have a broken TEST UNIT READY
249 */
250 if (UGETW(dd->bcdDevice) <= 0x128)
251 sc->sc_quirks |= UMASS_QUIRK_NO_TEST_UNIT_READY;
252 }
253