2 * Driver for Option High Speed Mobile Devices.
4 * (c) 2008 Dan Williams <dcbw@redhat.com>
6 * Inspiration taken from sierra_ms.c by Kevin Lloyd <klloyd@sierrawireless.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/usb.h>
24 #include <linux/slab.h>
27 #include "transport.h"
28 #include "option_ms.h"
31 #define ZCD_FORCE_MODEM 0x01
32 #define ZCD_ALLOW_MS 0x02
34 static unsigned int option_zero_cd
= ZCD_FORCE_MODEM
;
35 module_param(option_zero_cd
, uint
, S_IRUGO
| S_IWUSR
);
36 MODULE_PARM_DESC(option_zero_cd
, "ZeroCD mode (1=Force Modem (default),"
39 #define RESPONSE_LEN 1024
41 static int option_rezero(struct us_data
*us
)
43 const unsigned char rezero_msg
[] = {
44 0x55, 0x53, 0x42, 0x43, 0x78, 0x56, 0x34, 0x12,
45 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x01,
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
52 US_DEBUGP("Option MS: %s", "DEVICE MODE SWITCH\n");
54 buffer
= kzalloc(RESPONSE_LEN
, GFP_KERNEL
);
56 return USB_STOR_TRANSPORT_ERROR
;
58 memcpy(buffer
, rezero_msg
, sizeof(rezero_msg
));
59 result
= usb_stor_bulk_transfer_buf(us
,
61 buffer
, sizeof(rezero_msg
), NULL
);
62 if (result
!= USB_STOR_XFER_GOOD
) {
63 result
= USB_STOR_XFER_ERROR
;
67 /* Some of the devices need to be asked for a response, but we don't
68 * care what that response is.
70 usb_stor_bulk_transfer_buf(us
,
72 buffer
, RESPONSE_LEN
, NULL
);
75 usb_stor_bulk_transfer_buf(us
,
79 result
= USB_STOR_XFER_GOOD
;
86 static int option_inquiry(struct us_data
*us
)
88 const unsigned char inquiry_msg
[] = {
89 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78,
90 0x24, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x12,
91 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
97 US_DEBUGP("Option MS: %s", "device inquiry for vendor name\n");
99 buffer
= kzalloc(0x24, GFP_KERNEL
);
101 return USB_STOR_TRANSPORT_ERROR
;
103 memcpy(buffer
, inquiry_msg
, sizeof(inquiry_msg
));
104 result
= usb_stor_bulk_transfer_buf(us
,
106 buffer
, sizeof(inquiry_msg
), NULL
);
107 if (result
!= USB_STOR_XFER_GOOD
) {
108 result
= USB_STOR_XFER_ERROR
;
112 result
= usb_stor_bulk_transfer_buf(us
,
115 if (result
!= USB_STOR_XFER_GOOD
) {
116 result
= USB_STOR_XFER_ERROR
;
120 result
= memcmp(buffer
+8, "Option", 6);
123 result
= memcmp(buffer
+8, "ZCOPTION", 8);
126 usb_stor_bulk_transfer_buf(us
,
136 int option_ms_init(struct us_data
*us
)
140 US_DEBUGP("Option MS: option_ms_init called\n");
142 /* Additional test for vendor information via INQUIRY,
143 * because some vendor/product IDs are ambiguous
145 result
= option_inquiry(us
);
147 US_DEBUGP("Option MS: vendor is not Option or not determinable,"
148 " no action taken\n");
151 US_DEBUGP("Option MS: this is a genuine Option device,"
154 /* Force Modem mode */
155 if (option_zero_cd
== ZCD_FORCE_MODEM
) {
156 US_DEBUGP("Option MS: %s", "Forcing Modem Mode\n");
157 result
= option_rezero(us
);
158 if (result
!= USB_STOR_XFER_GOOD
)
159 US_DEBUGP("Option MS: Failed to switch to modem mode.\n");
161 } else if (option_zero_cd
== ZCD_ALLOW_MS
) {
162 /* Allow Mass Storage mode (keep CD-Rom) */
163 US_DEBUGP("Option MS: %s", "Allowing Mass Storage Mode if device"