1 #include <asm/arch/sci_types.h>
2 #include <linux/usb/ch9.h>
3 #include <linux/usb/cdc.h>
4 #include <linux/byteorder/little_endian.h>
6 #define THOR_VENDOR_NUM 0x04E8
7 #define THOR_PRODUCT_NUM 0x685D
9 static struct usb_device_descriptor thor_device_desc_high __align (32)= {
10 .bLength = sizeof(thor_device_desc_high),
11 .bDescriptorType = USB_DT_DEVICE,
13 .bcdUSB = __constant_cpu_to_le16(0x0200),
14 .bDeviceClass = USB_CLASS_COMM,
16 .bDeviceSubClass = 0x02,
17 .bDeviceProtocol = 0x00,
19 .bMaxPacketSize0 = 64,
21 .idVendor = __constant_cpu_to_le16(THOR_VENDOR_NUM),
22 .idProduct = __constant_cpu_to_le16(THOR_PRODUCT_NUM),
23 .bcdDevice = cpu_to_le16(0x021B),
25 .iManufacturer = 0x01,
28 .iSerialNumber = 0x00,
29 .bNumConfigurations = 0x01,
32 static struct usb_device_descriptor thor_device_desc_full __align (32) = {
33 .bLength = sizeof(thor_device_desc_full),
34 .bDescriptorType = USB_DT_DEVICE,
36 .bcdUSB = __constant_cpu_to_le16(0x0101),
37 .bDeviceClass = USB_CLASS_COMM,
39 .bDeviceSubClass = 0x02,
40 .bDeviceProtocol = 0x00,
42 .bMaxPacketSize0 = 64,
44 .idVendor = __constant_cpu_to_le16(THOR_VENDOR_NUM),
45 .idProduct = __constant_cpu_to_le16(THOR_PRODUCT_NUM),
46 .bcdDevice = cpu_to_le16(0x021B),
48 .iManufacturer = 0x01,
51 .iSerialNumber = 0x00,
52 .bNumConfigurations = 0x01,
55 /* function descriptor */
56 static const struct usb_config_descriptor thor_config_desc __align (32) = {
57 .bLength = sizeof(thor_config_desc),
58 .bDescriptorType = USB_DT_CONFIG,
60 .wTotalLength = __constant_cpu_to_le16(67),
62 .bNumInterfaces = 0x02,
63 .bConfigurationValue = 0x01,
64 .iConfiguration = 0x00,
66 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
70 static struct usb_interface_descriptor thor_downloader_intf_init __align (32) = {
71 .bLength = sizeof(thor_downloader_intf_init),
72 .bDescriptorType = USB_DT_INTERFACE,
74 .bInterfaceNumber = 0,
75 .bAlternateSetting = 0,
78 .bInterfaceClass = USB_CLASS_COMM,
80 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
81 .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
85 static const struct usb_cdc_header_desc thor_downloader_func_desc __align (32) = {
86 .bLength = sizeof(thor_downloader_func_desc),
87 .bDescriptorType = USB_DT_CS_INTERFACE,
88 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
89 .bcdCDC = __constant_cpu_to_le16(0x0110),
92 static struct usb_cdc_call_mgmt_descriptor thor_downloader_func_desc_call __align (32) = {
93 .bLength = sizeof(thor_downloader_func_desc_call),
94 .bDescriptorType = USB_DT_CS_INTERFACE,
95 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
96 .bmCapabilities = 0x00,
97 .bDataInterface = 0x01,
100 static struct usb_cdc_acm_descriptor thor_downloader_func_desc_abstract __align (32) = {
102 .bDescriptorType = USB_DT_CS_INTERFACE,
103 .bDescriptorSubType = USB_CDC_ACM_TYPE,
104 .bmCapabilities = 0x0F,
107 static struct usb_cdc_union_desc thor_downloader_cdc_union __align (32) = {
109 .bDescriptorType = USB_DT_CS_INTERFACE,
110 .bDescriptorSubType = USB_CDC_UNION_TYPE,
111 .bMasterInterface0 = 0x00,
112 .bSlaveInterface0 = 0x01,
115 static struct usb_endpoint_descriptor thor_downloader_ep3_in __align (32) = {
116 .bLength = USB_DT_ENDPOINT_SIZE,
117 .bDescriptorType = USB_DT_ENDPOINT,
118 .bEndpointAddress = 0x83,
119 .bmAttributes = USB_ENDPOINT_XFER_INT,
120 .wMaxPacketSize = __constant_cpu_to_le16(16),
124 static const struct usb_interface_descriptor thor_downloader_intf_data __align (32) = {
125 .bLength = USB_DT_INTERFACE_SIZE,
126 .bDescriptorType = USB_DT_INTERFACE,
128 .bInterfaceNumber = 1,
129 .bAlternateSetting = 0,
132 .bInterfaceClass = USB_CLASS_CDC_DATA,
134 .bInterfaceSubClass = 0,
135 .bInterfaceProtocol = 0,
139 static struct usb_endpoint_descriptor thor_downloader_ep1_in __align (32) = {
140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT,
142 .bEndpointAddress = 0x81,
143 .bmAttributes = USB_ENDPOINT_XFER_BULK,
144 .wMaxPacketSize = __constant_cpu_to_le16(512),
148 static struct usb_endpoint_descriptor thor_downloader_ep2_out __align (32) = {
149 .bLength = USB_DT_ENDPOINT_SIZE,
150 .bDescriptorType = USB_DT_ENDPOINT,
151 .bEndpointAddress = 0x02,
152 .bmAttributes = USB_ENDPOINT_XFER_BULK,
153 .wMaxPacketSize = __constant_cpu_to_le16(512),
157 static const struct usb_descriptor_header *thor_function_high[] __align (32) = {
158 (struct usb_descriptor_header *) &thor_downloader_intf_init,
159 (struct usb_descriptor_header *) &thor_downloader_func_desc,
160 (struct usb_descriptor_header *) &thor_downloader_func_desc_call,
161 (struct usb_descriptor_header *) &thor_downloader_func_desc_abstract,
162 (struct usb_descriptor_header *) &thor_downloader_cdc_union,
163 (struct usb_descriptor_header *) &thor_downloader_ep3_in,
164 (struct usb_descriptor_header *) &thor_downloader_intf_data,
165 (struct usb_descriptor_header *) &thor_downloader_ep1_in,
166 (struct usb_descriptor_header *) &thor_downloader_ep2_out,
169 static struct usb_cdc_acm_descriptor thor_downloader_func_desc_abstract_full __align (32) = {
171 .bDescriptorType = USB_DT_CS_INTERFACE,
172 .bDescriptorSubType = USB_CDC_ACM_TYPE,
173 .bmCapabilities = 0x00,
176 static struct usb_endpoint_descriptor thor_downloader_ep1_in_full __align (32) = {
177 .bLength = USB_DT_ENDPOINT_SIZE,
178 .bDescriptorType = USB_DT_ENDPOINT,
179 .bEndpointAddress = 0x81,
180 .bmAttributes = USB_ENDPOINT_XFER_BULK,
181 .wMaxPacketSize = __constant_cpu_to_le16(64),
185 static struct usb_endpoint_descriptor thor_downloader_ep2_out_full __align (32) = {
186 .bLength = USB_DT_ENDPOINT_SIZE,
187 .bDescriptorType = USB_DT_ENDPOINT,
188 .bEndpointAddress = 0x02,
189 .bmAttributes = USB_ENDPOINT_XFER_BULK,
190 .wMaxPacketSize = __constant_cpu_to_le16(64),
194 static const struct usb_descriptor_header *thor_function_full[] __align (32) = {
195 (struct usb_descriptor_header *) &thor_downloader_intf_init,
196 (struct usb_descriptor_header *) &thor_downloader_func_desc,
197 (struct usb_descriptor_header *) &thor_downloader_func_desc_call,
198 (struct usb_descriptor_header *) &thor_downloader_func_desc_abstract_full,
199 (struct usb_descriptor_header *) &thor_downloader_cdc_union,
200 (struct usb_descriptor_header *) &thor_downloader_ep3_in,
201 (struct usb_descriptor_header *) &thor_downloader_intf_data,
202 (struct usb_descriptor_header *) &thor_downloader_ep1_in_full,
203 (struct usb_descriptor_header *) &thor_downloader_ep2_out_full,
206 static char function_desc_buf[67] __align(32);
208 #define CONFIG_THOR_STRING_PRODUCT "SAMSUNG USB DRIVER"
209 static char string_product[2 + 2 * (sizeof(CONFIG_THOR_STRING_PRODUCT) - 1)] __align(32);
211 #define CONFIG_THOR_STRING_MANUFACTURER "SAMSUNG"
212 static char string_manufacturer[2 + 2 * (sizeof(CONFIG_THOR_STRING_MANUFACTURER) - 1)] __align(32);
214 static char string_lang_ids[4] __align (32) = {4, USB_DT_STRING, 0x9, 0x4};
216 #define CONFIG_THOR_STRING_INTERFACE "CDC Abstract Control Model"
217 static char string_interface[2 + 2 * (sizeof(CONFIG_THOR_STRING_INTERFACE) - 1)] __align(32);
219 #define CONFIG_THOR_STRING_CONTROL "SAMSUNG SERIAL CONTROL"
220 static char string_control[2 + 2 * (sizeof(CONFIG_THOR_STRING_CONTROL) - 1)] __align(32);
222 static struct usb_qualifier_descriptor thor_dev_qualifier_desc __align(32) = {
223 .bLength = sizeof(thor_dev_qualifier_desc),
224 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
225 .bcdUSB = __constant_cpu_to_le16(0x0200),
226 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
228 .bDeviceSubClass = 0x00,
229 .bDeviceProtocol = 0x00,
230 .bMaxPacketSize0 = 64,
232 .bNumConfigurations = 0x01,
236 static char thor_device_qualifer_desc_buf[sizeof(struct usb_qualifier_descriptor)] __align(32);
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;