Subversion Repositories freemyipod

Rev

Rev 889 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
881 theseven 1
#include "global.h"
2
#include "app/umsboot/usbglue.h"
3
#include "app/umsboot/ums.h"
4
#include "sys/util.h"
5
#include UMSBOOT_USB_DRIVER_HEADER
6
 
7
static const struct usb_devicedescriptor usb_devicedescriptor __attribute__((section(".dmarodata.usb_devicedescriptor"),aligned(CACHEALIGN_SIZE))) =
8
{
9
    .bLength = sizeof(struct usb_devicedescriptor),
10
    .bDescriptorType = USB_DESCRIPTOR_TYPE_DEVICE,
11
    .bcdUSB = 0x0200,
12
    .bDeviceClass = 0,
13
    .bDeviceSubClass = 0,
14
    .bDeviceProtocol = 0,
15
    .bMaxPacketSize0 = 64,
16
    .idVendor = UMSBOOT_USB_VENDORID,
17
    .idProduct = UMSBOOT_USB_PRODUCTID,
18
    .bcdDevice = UMSBOOT_USB_DEVICEREVISION,
19
    .iManufacturer = 1,
20
    .iProduct = 2,
21
    .iSerialNumber = 0,
22
    .bNumConfigurations = 1,
23
};
24
 
25
static struct __attribute__((packed)) _usb_config1_descriptors
26
{
27
    struct usb_configurationdescriptor c1;
28
    struct usb_interfacedescriptor c1_i0_a0;
29
    struct usb_endpointdescriptor c1_i0_a0_e1out;
30
    struct usb_endpointdescriptor c1_i0_a0_e1in;
31
} usb_config1_descriptors __attribute__((section(".dmadata.usb_config1_descriptors"),aligned(CACHEALIGN_SIZE))) =
32
{
33
    .c1 =
34
    {
35
        .bLength = sizeof(struct usb_configurationdescriptor),
36
        .bDescriptorType = USB_DESCRIPTOR_TYPE_CONFIGURATION,
37
        .wTotalLength = sizeof(struct _usb_config1_descriptors),
38
        .bNumInterfaces = 1,
39
        .bConfigurationValue = 1,
40
        .iConfiguration = 0,
41
        .bmAttributes = { .buspowered = 1, .selfpowered = 1 },
42
        .bMaxPower = UMSBOOT_USB_MAXCURRENT / 2,
43
    },
44
    .c1_i0_a0 =
45
    {
46
        .bLength = sizeof(struct usb_interfacedescriptor),
47
        .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE,
48
        .bInterfaceNumber = 0,
49
        .bAlternateSetting = 0,
50
        .bNumEndpoints = 2,
51
        .bInterfaceClass = 0x08,
52
        .bInterfaceSubClass = 0x06,
53
        .bInterfaceProtocol = 0x50,
54
        .iInterface = 0,
55
    },
56
    .c1_i0_a0_e1out =
57
    {
58
        .bLength = sizeof(struct usb_endpointdescriptor),
59
        .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT,
60
        .bEndpointAddress = { .number = UMSBOOT_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT },
61
        .bmAttributes = { .type = USB_ENDPOINT_ATTRIBUTE_TYPE_BULK },
62
        .wMaxPacketSize = 512,
63
        .bInterval = 1,
64
    },
65
    .c1_i0_a0_e1in =
66
    {
67
        .bLength = sizeof(struct usb_endpointdescriptor),
68
        .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT,
69
        .bEndpointAddress = { .number = UMSBOOT_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN },
70
        .bmAttributes = { .type = USB_ENDPOINT_ATTRIBUTE_TYPE_BULK },
71
        .wMaxPacketSize = 512,
72
        .bInterval = 1,
73
    },
74
};
75
 
76
static const struct usb_stringdescriptor usb_string_language __attribute__((section(".dmarodata.usb_string_language"),aligned(CACHEALIGN_SIZE))) =
77
{
78
    .bLength = sizeof(usb_string_language) + sizeof(*usb_string_language.wString),
79
    .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING,
80
    .wString = { 0x0409 },
81
};
82
 
83
static const struct usb_stringdescriptor usb_string_vendor __attribute__((section(".dmarodata.usb_string_vendor"),aligned(CACHEALIGN_SIZE))) =
84
{
85
    .bLength = sizeof(usb_string_vendor) + sizeof(*usb_string_vendor.wString) * UMSBOOT_USB_VENDORSTRING_LEN,
86
    .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING,
87
    .wString = UMSBOOT_USB_VENDORSTRING,
88
};
89
 
90
static const struct usb_stringdescriptor usb_string_product __attribute__((section(".dmarodata.usb_string_product"),aligned(CACHEALIGN_SIZE))) =
91
{
92
    .bLength = sizeof(usb_string_product) + sizeof(*usb_string_product.wString) * UMSBOOT_USB_PRODUCTSTRING_LEN,
93
    .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING,
94
    .wString = UMSBOOT_USB_PRODUCTSTRING,
95
};
96
 
97
static const struct usb_stringdescriptor* usb_stringdescriptors[] =
98
{
99
    &usb_string_language,
100
    &usb_string_vendor,
101
    &usb_string_product,
102
};
103
 
104
static const struct usb_endpoint usb_c1_i0_a0_ep1out =
105
{
106
    .number = { .number = UMSBOOT_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT },
107
    .ctrl_request = ums_ep_ctrl_request,
108
    .xfer_complete = ums_xfer_complete,
109
    .setup_received = NULL,
110
};
111
 
112
static const struct usb_endpoint usb_c1_i0_a0_ep1in =
113
{
114
    .number = { .number = UMSBOOT_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN },
115
    .xfer_complete = ums_xfer_complete,
116
    .timeout = ums_timeout,
117
};
118
 
119
static const struct usb_altsetting usb_c1_i0_a0 =
120
{
121
    .set_altsetting = ums_set_altsetting,
122
    .unset_altsetting = ums_unset_altsetting,
123
    .endpoint_count = 2,
124
    .endpoints =
125
    {
126
        &usb_c1_i0_a0_ep1out,
127
        &usb_c1_i0_a0_ep1in,
128
    },
129
};
130
 
131
static void usbglue_bus_reset(const struct usb_instance* data, int highspeed)
132
{
133
    usb_config1_descriptors.c1_i0_a0_e1out.wMaxPacketSize = highspeed ? 512 : 64;
134
    usb_config1_descriptors.c1_i0_a0_e1in.wMaxPacketSize = highspeed ? 512 : 64;
135
}
136
 
137
static struct usb_interface usb_c1_i0 =
138
{
139
    .bus_reset = ums_bus_reset,
140
    .ctrl_request = ums_ctrl_request,
141
    .altsetting_count = 1,
142
    .altsettings =
143
    {
144
        &usb_c1_i0_a0,
145
    },
146
};
147
 
148
static const struct usb_configuration usb_c1 =
149
{
150
    .descriptor = &usb_config1_descriptors.c1,
151
    .set_configuration = NULL,
152
    .unset_configuration = NULL,
153
    .interface_count = 1,
154
    .interfaces =
155
    {
156
        &usb_c1_i0,
157
    },
158
};
159
 
160
 
161
static UMSBOOT_USB_DRIVER_CONFIG_TYPE usb_driver_config = UMSBOOT_USB_DRIVER_CONFIG;
162
 
163
static UMSBOOT_USB_DRIVER_STATE_TYPE usb_driver_state = UMSBOOT_USB_DRIVER_STATE;
164
 
165
static struct usb_state usb_state;
166
 
167
static union usb_ep0_buffer usb_buffer __attribute__((section(".dmabss.usb_buffer"),aligned(CACHEALIGN_SIZE)));
168
 
169
const struct usb_instance usb_data =
170
{
171
    .driver = &UMSBOOT_USB_DRIVER,
172
    .driver_config = &usb_driver_config,
173
    .driver_state = &usb_driver_state,
174
    .state = &usb_state,
175
    .buffer = &usb_buffer,
176
    .bus_reset = usbglue_bus_reset,
177
    .ep0_setup_hook = NULL,
178
    .ep0_data_hook = NULL,
179
    .configuration_count = 1,
180
    .stringdescriptor_count = 3,
181
    .devicedescriptor = &usb_devicedescriptor,
182
    .stringdescriptors = usb_stringdescriptors,
183
    .configurations =
184
    {
185
        &usb_c1,
186
    },
187
};