upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / usb / gadget / f_gadgetfs.h
1 /*
2  * f_gadgetfs.h -- support file for f_gadgetfs.c
3  *
4  * Copyright (C) 2009 MCCI Corporation
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  
21 #ifndef __F_GADGETFS_H__
22 #define __F_GADGETFS_H__
23
24 /* string id's are dynamically assigned */
25 #ifdef ESCAPE_MCCI
26         #define GADGETFS_MANUFACTURER_IDX       2
27         #define GADGETFS_PRODUCT_IDX            1
28         #define GADGETFS_INTERFACE_IDX          0
29 #else
30         #define GADGETFS_MANUFACTURER_IDX       0
31         #define GADGETFS_PRODUCT_IDX            1
32         #define GADGETFS_INTERFACE_IDX          2
33 #endif
34
35 #define GADGETFS_DRIVER_DESC            "GadgetFS Function"
36 #define GADGETFS_DRIVER_VERSION         "0.4"
37
38 #ifdef ESCAPE_MCCI
39         #define GADGETFS_INTERFACE_ID           0
40 #else
41         #define GADGETFS_INTERFACE_ID           2
42 #endif
43
44 /*-------------------------------------------------------------------------*/
45
46 struct f_gadgetfs;
47
48 /*-------------------------------------------------------------------------*/
49
50 struct gadgetfs_endpoint_descriptors {
51         struct usb_endpoint_descriptor  *in;
52         struct usb_endpoint_descriptor  *out;
53         struct usb_endpoint_descriptor  *status;
54 };
55
56 /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
57 static struct usb_string gadgetfs_string_defines[] = {
58         [GADGETFS_MANUFACTURER_IDX].s   = "MCCI",
59         [GADGETFS_PRODUCT_IDX].s        = "GadgetFS Composite Driver",
60         [GADGETFS_INTERFACE_IDX].s      = "MTP Interface",
61         {  },   /* end of list */
62 };
63
64 static struct usb_gadget_strings gadgetfs_string_table = {
65         .language       = 0x0409,               // en-us
66         .strings        = gadgetfs_string_defines,
67 };
68
69 static struct usb_gadget_strings *gadgetfs_strings[] = {
70         &gadgetfs_string_table,
71         NULL,
72 };
73
74 /* Control Interface Descriptor */
75 static struct usb_interface_descriptor gadgetfs_control_interface_descriptor __initdata = {
76         .bLength                = sizeof(gadgetfs_control_interface_descriptor),
77         .bDescriptorType        = USB_DT_INTERFACE,
78         .bNumEndpoints          = 3,
79         .bInterfaceClass        = USB_CLASS_STILL_IMAGE,
80         .bInterfaceSubClass     = 1,
81         .bInterfaceProtocol     = 1,
82         .iInterface             = GADGETFS_INTERFACE_IDX,
83 };
84
85 /* High-Speed Support */
86 static struct usb_endpoint_descriptor gadgetfs_high_speed_ep_out_descriptor __initdata = {
87         .bLength                = USB_DT_ENDPOINT_SIZE,
88         .bDescriptorType        = USB_DT_ENDPOINT,
89         .bEndpointAddress       = USB_DIR_OUT,
90         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
91         .wMaxPacketSize         = cpu_to_le16(512),
92 };
93
94 static struct usb_endpoint_descriptor gadgetfs_high_speed_ep_in_descriptor __initdata = {
95         .bLength                = USB_DT_ENDPOINT_SIZE,
96         .bDescriptorType        = USB_DT_ENDPOINT,
97         .bEndpointAddress       = USB_DIR_IN,
98         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
99         .wMaxPacketSize         = cpu_to_le16(512),
100         .bInterval              = 1,
101 };
102
103 static struct usb_endpoint_descriptor gadgetfs_high_speed_status_descriptor __initdata = {
104         .bLength                = USB_DT_ENDPOINT_SIZE,
105         .bDescriptorType        = USB_DT_ENDPOINT,
106         .bmAttributes           = USB_ENDPOINT_XFER_INT,
107         .bEndpointAddress       = USB_DIR_IN,
108         .wMaxPacketSize         = __constant_cpu_to_le16 (8),//16+4),
109         .bInterval              = 5 + 3,
110 };
111
112 static struct usb_descriptor_header *gadgetfs_high_speed_function[] __initdata = {
113         /* GadgetFS control descriptors */
114         (struct usb_descriptor_header *) &gadgetfs_control_interface_descriptor,
115         /* NOTE: status endpoint might need to be removed */
116         (struct usb_descriptor_header *) &gadgetfs_high_speed_status_descriptor,
117         (struct usb_descriptor_header *) &gadgetfs_high_speed_ep_in_descriptor,
118         (struct usb_descriptor_header *) &gadgetfs_high_speed_ep_out_descriptor,
119         NULL,
120 };
121
122 /* Full-Speed Support */
123 static struct usb_endpoint_descriptor gadgetfs_full_speed_ep_in_descriptor __initdata = {
124         .bLength                = USB_DT_ENDPOINT_SIZE,
125         .bDescriptorType        = USB_DT_ENDPOINT,
126         .bEndpointAddress       = USB_DIR_IN,
127         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
128         .wMaxPacketSize         = __constant_cpu_to_le16 (64),
129 };
130
131 static struct usb_endpoint_descriptor gadgetfs_full_speed_ep_out_descriptor __initdata = {
132         .bLength                = USB_DT_ENDPOINT_SIZE,
133         .bDescriptorType        = USB_DT_ENDPOINT,
134         .bEndpointAddress       = USB_DIR_OUT,
135         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
136         .wMaxPacketSize         = __constant_cpu_to_le16 (64),
137 };
138
139 static struct usb_endpoint_descriptor gadgetfs_full_speed_status_descriptor __initdata = {
140         .bLength                = USB_DT_ENDPOINT_SIZE,
141         .bDescriptorType        = USB_DT_ENDPOINT,
142         .bEndpointAddress       = USB_DIR_IN,
143         .bmAttributes           = USB_ENDPOINT_XFER_INT,
144         .wMaxPacketSize         = __constant_cpu_to_le16 (8),//16+4),
145         .bInterval              = (1 << 5),
146 };
147
148 static struct usb_descriptor_header *gadgetfs_full_speed_function[] __initdata = {
149         /* GadgetFS control descriptors */
150         (struct usb_descriptor_header *) &gadgetfs_control_interface_descriptor,
151         /* NOTE: status endpoint might need to be removed */
152         (struct usb_descriptor_header *) &gadgetfs_full_speed_status_descriptor,
153         (struct usb_descriptor_header *) &gadgetfs_full_speed_ep_in_descriptor,
154         (struct usb_descriptor_header *) &gadgetfs_full_speed_ep_out_descriptor,
155         NULL,
156 };
157
158 /* Internal data structure */
159 struct f_gadgetfs {
160         struct usb_function                     function;
161         struct usb_composite_dev                *cdev;          /* unused */
162         struct usb_gadget                       *gadget;        /* unused */ /* copy of cdev->gadget */
163         struct usb_ep                           *ep_in;
164         struct usb_ep                           *ep_out;
165         struct usb_ep                           *ep_int;
166         struct usb_ep                           *ep0;
167         struct gadgetfs_endpoint_descriptors    full_speed_descriptor, high_speed_descriptor;
168         int                                     interface_id;
169         
170         spinlock_t                              lock;
171 };
172
173 /*-------------------------------------------------------------------------*/
174
175 struct f_gadgetfs       *the_gadget = NULL;
176
177 /*-------------------------------------------------------------------------*/
178
179 #endif /* __F_GADGETFS_H__ */