1 #include <asm/arch/sci_types.h>
2 #include <linux/usb/ch9.h>
3 #include <linux/usb/cdc.h>
4 #include <linux/usb/gadget.h>
5 #include <linux/byteorder/little_endian.h>
6 #include <linux/string.h>
8 #define THOR_VENDOR_NUM 0x04E8
9 #define THOR_PRODUCT_NUM 0x685D
11 static struct usb_device_descriptor thor_device_desc_high __align (32)= {
12 .bLength = sizeof(thor_device_desc_high),
13 .bDescriptorType = USB_DT_DEVICE,
15 .bcdUSB = __constant_cpu_to_le16(0x0200),
16 .bDeviceClass = USB_CLASS_COMM,
18 .bDeviceSubClass = 0x02,
19 .bDeviceProtocol = 0x00,
21 .bMaxPacketSize0 = 64,
23 .idVendor = __constant_cpu_to_le16(THOR_VENDOR_NUM),
24 .idProduct = __constant_cpu_to_le16(THOR_PRODUCT_NUM),
25 .bcdDevice = cpu_to_le16(0x021B),
27 .iManufacturer = 0x01,
30 .iSerialNumber = 0x00,
31 .bNumConfigurations = 0x01,
34 static struct usb_device_descriptor thor_device_desc_full __align (32) = {
35 .bLength = sizeof(thor_device_desc_full),
36 .bDescriptorType = USB_DT_DEVICE,
38 .bcdUSB = __constant_cpu_to_le16(0x0101),
39 .bDeviceClass = USB_CLASS_COMM,
41 .bDeviceSubClass = 0x02,
42 .bDeviceProtocol = 0x00,
44 .bMaxPacketSize0 = 64,
46 .idVendor = __constant_cpu_to_le16(THOR_VENDOR_NUM),
47 .idProduct = __constant_cpu_to_le16(THOR_PRODUCT_NUM),
48 .bcdDevice = cpu_to_le16(0x021B),
50 .iManufacturer = 0x01,
53 .iSerialNumber = 0x00,
54 .bNumConfigurations = 0x01,
57 /* function descriptor */
58 static const struct usb_config_descriptor thor_config_desc __align (32) = {
59 .bLength = sizeof(thor_config_desc),
60 .bDescriptorType = USB_DT_CONFIG,
62 .wTotalLength = __constant_cpu_to_le16(67),
64 .bNumInterfaces = 0x02,
65 .bConfigurationValue = 0x01,
66 .iConfiguration = 0x00,
68 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
72 static struct usb_interface_descriptor thor_downloader_intf_init __align (32) = {
73 .bLength = sizeof(thor_downloader_intf_init),
74 .bDescriptorType = USB_DT_INTERFACE,
76 .bInterfaceNumber = 0,
77 .bAlternateSetting = 0,
80 .bInterfaceClass = USB_CLASS_COMM,
82 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
83 .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
87 static const struct usb_cdc_header_desc thor_downloader_func_desc __align (32) = {
88 .bLength = sizeof(thor_downloader_func_desc),
89 .bDescriptorType = USB_DT_CS_INTERFACE,
90 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
91 .bcdCDC = __constant_cpu_to_le16(0x0110),
94 static struct usb_cdc_call_mgmt_descriptor thor_downloader_func_desc_call __align (32) = {
95 .bLength = sizeof(thor_downloader_func_desc_call),
96 .bDescriptorType = USB_DT_CS_INTERFACE,
97 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
98 .bmCapabilities = 0x00,
99 .bDataInterface = 0x01,
102 static struct usb_cdc_acm_descriptor thor_downloader_func_desc_abstract __align (32) = {
104 .bDescriptorType = USB_DT_CS_INTERFACE,
105 .bDescriptorSubType = USB_CDC_ACM_TYPE,
106 .bmCapabilities = 0x0F,
109 static struct usb_cdc_union_desc thor_downloader_cdc_union __align (32) = {
111 .bDescriptorType = USB_DT_CS_INTERFACE,
112 .bDescriptorSubType = USB_CDC_UNION_TYPE,
113 .bMasterInterface0 = 0x00,
114 .bSlaveInterface0 = 0x01,
117 static struct usb_endpoint_descriptor thor_downloader_ep3_in __align (32) = {
118 .bLength = USB_DT_ENDPOINT_SIZE,
119 .bDescriptorType = USB_DT_ENDPOINT,
120 .bEndpointAddress = 0x83,
121 .bmAttributes = USB_ENDPOINT_XFER_INT,
122 .wMaxPacketSize = __constant_cpu_to_le16(16),
126 static const struct usb_interface_descriptor thor_downloader_intf_data __align (32) = {
127 .bLength = USB_DT_INTERFACE_SIZE,
128 .bDescriptorType = USB_DT_INTERFACE,
130 .bInterfaceNumber = 1,
131 .bAlternateSetting = 0,
134 .bInterfaceClass = USB_CLASS_CDC_DATA,
136 .bInterfaceSubClass = 0,
137 .bInterfaceProtocol = 0,
141 static struct usb_endpoint_descriptor thor_downloader_ep1_in __align (32) = {
142 .bLength = USB_DT_ENDPOINT_SIZE,
143 .bDescriptorType = USB_DT_ENDPOINT,
144 .bEndpointAddress = 0x81,
145 .bmAttributes = USB_ENDPOINT_XFER_BULK,
146 .wMaxPacketSize = __constant_cpu_to_le16(512),
150 static struct usb_endpoint_descriptor thor_downloader_ep2_out __align (32) = {
151 .bLength = USB_DT_ENDPOINT_SIZE,
152 .bDescriptorType = USB_DT_ENDPOINT,
153 .bEndpointAddress = 0x02,
154 .bmAttributes = USB_ENDPOINT_XFER_BULK,
155 .wMaxPacketSize = __constant_cpu_to_le16(512),
159 static const struct usb_descriptor_header *thor_function_high[] __align (32) = {
160 (struct usb_descriptor_header *) &thor_downloader_intf_init,
161 (struct usb_descriptor_header *) &thor_downloader_func_desc,
162 (struct usb_descriptor_header *) &thor_downloader_func_desc_call,
163 (struct usb_descriptor_header *) &thor_downloader_func_desc_abstract,
164 (struct usb_descriptor_header *) &thor_downloader_cdc_union,
165 (struct usb_descriptor_header *) &thor_downloader_ep3_in,
166 (struct usb_descriptor_header *) &thor_downloader_intf_data,
167 (struct usb_descriptor_header *) &thor_downloader_ep1_in,
168 (struct usb_descriptor_header *) &thor_downloader_ep2_out,
171 static struct usb_cdc_acm_descriptor thor_downloader_func_desc_abstract_full __align (32) = {
173 .bDescriptorType = USB_DT_CS_INTERFACE,
174 .bDescriptorSubType = USB_CDC_ACM_TYPE,
175 .bmCapabilities = 0x00,
178 static struct usb_endpoint_descriptor thor_downloader_ep1_in_full __align (32) = {
179 .bLength = USB_DT_ENDPOINT_SIZE,
180 .bDescriptorType = USB_DT_ENDPOINT,
181 .bEndpointAddress = 0x81,
182 .bmAttributes = USB_ENDPOINT_XFER_BULK,
183 .wMaxPacketSize = __constant_cpu_to_le16(64),
187 static struct usb_endpoint_descriptor thor_downloader_ep2_out_full __align (32) = {
188 .bLength = USB_DT_ENDPOINT_SIZE,
189 .bDescriptorType = USB_DT_ENDPOINT,
190 .bEndpointAddress = 0x02,
191 .bmAttributes = USB_ENDPOINT_XFER_BULK,
192 .wMaxPacketSize = __constant_cpu_to_le16(64),
196 static const struct usb_descriptor_header *thor_function_full[] __align (32) = {
197 (struct usb_descriptor_header *) &thor_downloader_intf_init,
198 (struct usb_descriptor_header *) &thor_downloader_func_desc,
199 (struct usb_descriptor_header *) &thor_downloader_func_desc_call,
200 (struct usb_descriptor_header *) &thor_downloader_func_desc_abstract_full,
201 (struct usb_descriptor_header *) &thor_downloader_cdc_union,
202 (struct usb_descriptor_header *) &thor_downloader_ep3_in,
203 (struct usb_descriptor_header *) &thor_downloader_intf_data,
204 (struct usb_descriptor_header *) &thor_downloader_ep1_in_full,
205 (struct usb_descriptor_header *) &thor_downloader_ep2_out_full,
208 static char function_desc_buf[67] __align(32);
210 #define CONFIG_THOR_STRING_PRODUCT "SAMSUNG USB DRIVER"
211 static char string_product[2 + 2 * (sizeof(CONFIG_THOR_STRING_PRODUCT) - 1)] __align(32);
213 #define CONFIG_THOR_STRING_MANUFACTURER "SAMSUNG"
214 static char string_manufacturer[2 + 2 * (sizeof(CONFIG_THOR_STRING_MANUFACTURER) - 1)] __align(32);
216 static char string_lang_ids[4] __align (32) = {4, USB_DT_STRING, 0x9, 0x4};
218 #define CONFIG_THOR_STRING_INTERFACE "CDC Abstract Control Model"
219 static char string_interface[2 + 2 * (sizeof(CONFIG_THOR_STRING_INTERFACE) - 1)] __align(32);
221 #define CONFIG_THOR_STRING_CONTROL "SAMSUNG SERIAL CONTROL"
222 static char string_control[2 + 2 * (sizeof(CONFIG_THOR_STRING_CONTROL) - 1)] __align(32);
224 static struct usb_qualifier_descriptor thor_dev_qualifier_desc __align(32) = {
225 .bLength = sizeof(thor_dev_qualifier_desc),
226 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
227 .bcdUSB = __constant_cpu_to_le16(0x0200),
228 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
230 .bDeviceSubClass = 0x00,
231 .bDeviceProtocol = 0x00,
232 .bMaxPacketSize0 = 64,
234 .bNumConfigurations = 0x01,
238 unsigned char g_USB_Other_Speed_ConfigDescr[] __align(32) =
240 0x09,0x07,0x43,0x00,0x02,0x01,0x00,0xC0,
242 0x09,0x04,0x00,0x00,0x01,0x02,0x02,0x01,
244 0x05,0x24,0x00,0x10,0x01,
245 0x05,0x24,0x01,0x00,0x01,
247 0x05,0x24,0x06,0x00,0x01,
248 0x07,0x05,0x83,0x03,0x10,0x00,0x9, //Ep 3 In 64
249 0x09,0x04,0x01,0x00,0x02,0x0A,0x00,0x00,
251 0x07,0x05,0x81,0x02,0x40,0x00,0x00, //Ep 1 In 64
252 0x07,0x05,0x02,0x02,0x40,0x00,0x00, //Ep 2 OUT 64
255 unsigned char *thor_get_device_desc(unsigned int speed)
257 if (speed == 0x00) /* USB HIGH */
258 return (unsigned char *) &thor_device_desc_high;
260 return (unsigned char *) &thor_device_desc_full;
263 unsigned char *thor_get_config_desc(unsigned int speed)
265 usb_gadget_config_buf(&thor_config_desc, &function_desc_buf, 256, thor_function_high);
267 if (speed == 0x00) /* USB_HIGH */
268 usb_gadget_config_buf(&thor_config_desc, &function_desc_buf, 256, thor_function_high);
270 usb_gadget_config_buf(&thor_config_desc, &function_desc_buf, 256, thor_function_full);
272 return (unsigned char *) &function_desc_buf;
275 static void str2wide (char *str, u16 * wide)
278 for (i = 0; i < strlen (str) && str[i]; i++){
279 #if defined(__LITTLE_ENDIAN)
280 wide[i] = (u16) str[i];
281 #elif defined(__BIG_ENDIAN)
282 wide[i] = ((u16)(str[i])<<8);
284 #error "__LITTLE_ENDIAN or __BIG_ENDIAN undefined"
289 unsigned char *thor_get_string_desc(unsigned char index)
291 struct usb_string_descriptor *string;
295 string = (struct usb_string_descriptor *) string_lang_ids;
297 return (unsigned char *) string_lang_ids;
299 string = (struct usb_string_descriptor *) string_manufacturer;
300 string->bLength = sizeof(string_manufacturer);
301 string->bDescriptorType = USB_DT_STRING;
302 str2wide(CONFIG_THOR_STRING_MANUFACTURER, string->wData);
304 return (unsigned char *) string;
306 string = (struct usb_string_descriptor *) string_interface;
307 string->bLength = sizeof(string_interface);
308 string->bDescriptorType = USB_DT_STRING;
309 str2wide(CONFIG_THOR_STRING_INTERFACE, string->wData);
311 return (unsigned char *) string;
313 string = (struct usb_string_descriptor *) string_control;
314 string->bLength = sizeof(string_control);
315 string->bDescriptorType = USB_DT_STRING;
316 str2wide(CONFIG_THOR_STRING_CONTROL, string->wData);
318 return (unsigned char *) string;
321 string = (struct usb_string_descriptor *) string_product;
322 string->bLength = sizeof(string_product);
323 string->bDescriptorType = USB_DT_STRING;
324 str2wide(CONFIG_THOR_STRING_PRODUCT, string->wData);
326 return (unsigned char *) string;
332 unsigned char *thor_get_qualifer_desc(void)
334 return (unsigned char *) &thor_dev_qualifier_desc;
337 unsigned char *thor_get_other_speed_config_desc(void)
339 return (unsigned char *) g_USB_Other_Speed_ConfigDescr;