change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / property / usb / cdc_descriptor.c
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>
5
6 #define THOR_VENDOR_NUM                 0x04E8
7 #define THOR_PRODUCT_NUM                0x685D
8
9 static struct usb_device_descriptor thor_device_desc_high __align (32)= {
10         .bLength                        = sizeof(thor_device_desc_high),
11         .bDescriptorType        = USB_DT_DEVICE,
12
13         .bcdUSB                         = __constant_cpu_to_le16(0x0200),
14         .bDeviceClass           = USB_CLASS_COMM,
15
16         .bDeviceSubClass        = 0x02,
17         .bDeviceProtocol        = 0x00,
18
19         .bMaxPacketSize0        = 64,
20
21         .idVendor                       = __constant_cpu_to_le16(THOR_VENDOR_NUM),
22         .idProduct                      = __constant_cpu_to_le16(THOR_PRODUCT_NUM),
23         .bcdDevice                      = cpu_to_le16(0x021B),
24
25         .iManufacturer          = 0x01,
26         .iProduct                       = 0x02,
27
28         .iSerialNumber          = 0x00,
29         .bNumConfigurations     = 0x01,
30 };
31
32 static struct usb_device_descriptor thor_device_desc_full __align (32) = {
33         .bLength                        = sizeof(thor_device_desc_full),
34         .bDescriptorType        = USB_DT_DEVICE,
35
36         .bcdUSB                         = __constant_cpu_to_le16(0x0101),
37         .bDeviceClass           = USB_CLASS_COMM,
38
39         .bDeviceSubClass        = 0x02,
40         .bDeviceProtocol        = 0x00,
41
42         .bMaxPacketSize0        = 64,
43
44         .idVendor                       = __constant_cpu_to_le16(THOR_VENDOR_NUM),
45         .idProduct                      = __constant_cpu_to_le16(THOR_PRODUCT_NUM),
46         .bcdDevice                      = cpu_to_le16(0x021B),
47
48         .iManufacturer          = 0x01,
49         .iProduct                       = 0x02,
50
51         .iSerialNumber          = 0x00,
52         .bNumConfigurations     = 0x01,
53 };
54
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,
59
60         .wTotalLength                   = __constant_cpu_to_le16(67),
61
62         .bNumInterfaces                 = 0x02,
63         .bConfigurationValue    = 0x01,
64         .iConfiguration                 = 0x00,
65
66         .bmAttributes                   = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
67         .bMaxPower                              = 0x19,
68 };
69
70 static struct usb_interface_descriptor thor_downloader_intf_init __align (32) = {
71         .bLength                                = sizeof(thor_downloader_intf_init),
72         .bDescriptorType                = USB_DT_INTERFACE,
73
74         .bInterfaceNumber               = 0,
75         .bAlternateSetting              = 0,
76         .bNumEndpoints                  = 1,
77
78         .bInterfaceClass                = USB_CLASS_COMM,
79
80         .bInterfaceSubClass             = USB_CDC_SUBCLASS_ACM,
81         .bInterfaceProtocol             = USB_CDC_ACM_PROTO_AT_V25TER,
82         .iInterface                             = 3,
83 };
84
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),
90 };
91
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,
98 };
99
100 static struct usb_cdc_acm_descriptor thor_downloader_func_desc_abstract __align (32) = {
101         .bLength                                = 0x04,
102         .bDescriptorType                = USB_DT_CS_INTERFACE,
103         .bDescriptorSubType             = USB_CDC_ACM_TYPE,
104         .bmCapabilities                 = 0x0F,
105 };
106
107 static struct usb_cdc_union_desc thor_downloader_cdc_union __align (32) = {
108         .bLength                                = 0x05,
109         .bDescriptorType                = USB_DT_CS_INTERFACE,
110         .bDescriptorSubType             = USB_CDC_UNION_TYPE,
111         .bMasterInterface0              = 0x00,
112         .bSlaveInterface0               = 0x01,
113 };
114
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),
121         .bInterval = 0x9,
122 };
123
124 static const struct usb_interface_descriptor thor_downloader_intf_data __align (32) = {
125         .bLength                                = USB_DT_INTERFACE_SIZE,
126         .bDescriptorType                = USB_DT_INTERFACE,
127
128         .bInterfaceNumber               = 1,
129         .bAlternateSetting              = 0,
130
131         .bNumEndpoints                  = 2,
132         .bInterfaceClass                = USB_CLASS_CDC_DATA,
133
134         .bInterfaceSubClass             = 0,
135         .bInterfaceProtocol             = 0,
136         .iInterface                             = 4,
137 };
138
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),
145         .bInterval                      = 0,
146 };
147
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),
154         .bInterval                      = 0,
155 };
156
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,
167 };
168
169 static struct usb_cdc_acm_descriptor thor_downloader_func_desc_abstract_full __align (32) = {
170         .bLength                                = 0x04,
171         .bDescriptorType                = USB_DT_CS_INTERFACE,
172         .bDescriptorSubType             = USB_CDC_ACM_TYPE,
173         .bmCapabilities                 = 0x00,
174 };
175
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),
182         .bInterval                      = 0,
183 };
184
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),
191         .bInterval                      = 0,
192 };
193
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,
204 };
205
206 static char function_desc_buf[67] __align(32);
207
208 #define CONFIG_THOR_STRING_PRODUCT                      "SAMSUNG USB DRIVER"
209 static char string_product[2 + 2 * (sizeof(CONFIG_THOR_STRING_PRODUCT) - 1)] __align(32);
210
211 #define CONFIG_THOR_STRING_MANUFACTURER         "SAMSUNG"
212 static char string_manufacturer[2 + 2 * (sizeof(CONFIG_THOR_STRING_MANUFACTURER) - 1)] __align(32);
213
214 static char string_lang_ids[4] __align (32) = {4, USB_DT_STRING, 0x9, 0x4};
215
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);
218
219 #define CONFIG_THOR_STRING_CONTROL                      "SAMSUNG SERIAL CONTROL"
220 static char string_control[2 + 2 * (sizeof(CONFIG_THOR_STRING_CONTROL) - 1)] __align(32);
221
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,
227
228         .bDeviceSubClass        = 0x00,
229         .bDeviceProtocol        = 0x00,
230         .bMaxPacketSize0        = 64,
231
232         .bNumConfigurations     = 0x01,
233         .bRESERVED                      = 0x00,
234 };
235
236 static char thor_device_qualifer_desc_buf[sizeof(struct usb_qualifier_descriptor)] __align(32);
237
238 unsigned char g_USB_Other_Speed_ConfigDescr[] __align(32) =
239 {
240         0x09,0x07,0x43,0x00,0x02,0x01,0x00,0xC0,
241         0x19,
242         0x09,0x04,0x00,0x00,0x01,0x02,0x02,0x01,
243         0x03,
244         0x05,0x24,0x00,0x10,0x01,
245         0x05,0x24,0x01,0x00,0x01,
246         0x04,0x24,0x02,0x0f,
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,
250         0x04,
251         0x07,0x05,0x81,0x02,0x40,0x00,0x00,  //Ep 1 In  64    
252         0x07,0x05,0x02,0x02,0x40,0x00,0x00,  //Ep 2 OUT  64                     
253 };
254
255 unsigned char *thor_get_device_desc(unsigned int speed)
256 {
257         if (speed == 0x00)              /* USB HIGH */
258                 return (unsigned char *) &thor_device_desc_high;
259         else
260                 return (unsigned char *) &thor_device_desc_full;
261 }
262
263 unsigned char *thor_get_config_desc(unsigned int speed)
264 {
265         usb_gadget_config_buf(&thor_config_desc, &function_desc_buf, 256, thor_function_high);
266
267         if (speed == 0x00)              /* USB_HIGH */
268                 usb_gadget_config_buf(&thor_config_desc, &function_desc_buf, 256, thor_function_high);
269         else
270                 usb_gadget_config_buf(&thor_config_desc, &function_desc_buf, 256, thor_function_full);
271
272         return (unsigned char *) &function_desc_buf;
273 }
274
275 static void str2wide (char *str, u16 * wide)
276 {
277         int i;
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);
283                 #else
284                         #error "__LITTLE_ENDIAN or __BIG_ENDIAN undefined"
285                 #endif
286         }
287 }
288
289 unsigned char *thor_get_string_desc(unsigned char index)
290 {
291         struct usb_string_descriptor *string;
292
293         switch (index) {
294                 case 0:
295                         string = (struct usb_string_descriptor *) string_lang_ids;
296
297                         return (unsigned char *) string_lang_ids;
298                 case 1:
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);
303
304                         return (unsigned char *) string;
305                 case 3:
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);
310
311                         return (unsigned char *) string;
312                 case 6:
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);
317
318                         return (unsigned char *) string;
319                 case 2:
320                 default:
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);
325
326                         return (unsigned char *) string;
327         }
328
329     return NULL;
330 }
331
332 unsigned char *thor_get_qualifer_desc(void)
333 {
334     return (unsigned char *) &thor_dev_qualifier_desc;
335 }
336
337 unsigned char *thor_get_other_speed_config_desc(void)
338 {
339     return (unsigned char *) g_USB_Other_Speed_ConfigDescr;
340 }