Switch from GPLv2 to GPLv2+
[fw/altos] / src / kernel / ao_product.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include "ao.h"
20 #include "ao_product.h"
21
22 /* Defines which mark this particular AltOS product */
23
24 const char ao_version[AO_MAX_VERSION] = AO_iVersion_STRING;
25 const char ao_manufacturer[] = AO_iManufacturer_STRING;
26 const char ao_product[] = AO_iProduct_STRING;
27
28 #define LE_WORD(x)    ((x)&0xFF),((uint8_t) (((uint16_t) (x))>>8))
29
30 #if HAS_USB
31
32 /* Maximum power in mA */
33 #ifndef AO_USB_MAX_POWER
34 #define AO_USB_MAX_POWER        100
35 #endif
36
37 #ifndef AO_USB_SELF_POWER
38 #define AO_USB_SELF_POWER       1
39 #endif
40
41 #define AO_USB_DEVICE_CLASS_COMMUNICATION       0x02
42 #define AO_USB_INTERFACE_CLASS_CONTROL_CDC      0x02
43 #define AO_USB_INTERFACE_CLASS_DATA_CDC         0x0A
44
45 #ifndef AO_USB_DEVICE_CLASS
46 #define AO_USB_DEVICE_CLASS             AO_USB_DEVICE_CLASS_COMMUNICATION
47 #endif
48
49 #ifndef AO_USB_INTERFACE_CLASS_DATA
50 #define AO_USB_INTERFACE_CLASS_CONTROL  AO_USB_INTERFACE_CLASS_CONTROL_CDC
51 #define AO_USB_INTERFACE_CLASS_DATA     AO_USB_INTERFACE_CLASS_DATA_CDC
52 #endif
53
54 #include "ao_usb.h"
55
56 #define HEADER_LEN              9
57 #define CONTROL_CLASS_LEN       35
58 #define DATA_LEN                (9 + 7 * AO_USB_HAS_OUT + 7 * AO_USB_HAS_IN + 7 * AO_USB_HAS_IN2)
59
60 #define TOTAL_LENGTH            (HEADER_LEN + AO_USB_HAS_INT * CONTROL_CLASS_LEN + DATA_LEN)
61 #define NUM_INTERFACES          (AO_USB_HAS_INT + 1)
62
63 /* USB descriptors in one giant block of bytes */
64 AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] =
65 {
66         /* Device descriptor */
67         0x12,
68         AO_USB_DESC_DEVICE,
69         LE_WORD(0x0110),        /*  bcdUSB */
70         AO_USB_DEVICE_CLASS,    /*  bDeviceClass */
71         0x00,                   /*  bDeviceSubClass */
72         0x00,                   /*  bDeviceProtocol */
73         AO_USB_CONTROL_SIZE,    /*  bMaxPacketSize */
74         LE_WORD(AO_idVendor_NUMBER),    /*  idVendor */
75         LE_WORD(AO_idProduct_NUMBER),   /*  idProduct */
76         LE_WORD(0x0100),        /*  bcdDevice */
77         0x01,                   /*  iManufacturer */
78         0x02,                   /*  iProduct */
79         0x03,                   /*  iSerialNumber */
80         0x01,                   /*  bNumConfigurations */
81
82         /* Configuration descriptor */
83         0x09,
84         AO_USB_DESC_CONFIGURATION,
85         LE_WORD(TOTAL_LENGTH),  /*  wTotalLength */
86         NUM_INTERFACES,         /*  bNumInterfaces */
87         0x01,                   /*  bConfigurationValue */
88         0x00,                   /*  iConfiguration */
89         0x80 | (AO_USB_SELF_POWER << 6),        /*  bmAttributes */
90         AO_USB_MAX_POWER >> 1,  /*  bMaxPower, 2mA units */
91
92 #if AO_USB_HAS_INT
93         /* Control class interface */
94         0x09,
95         AO_USB_DESC_INTERFACE,
96         0x00,                   /*  bInterfaceNumber */
97         0x00,                   /*  bAlternateSetting */
98         0x01,                   /*  bNumEndPoints */
99         AO_USB_INTERFACE_CLASS_CONTROL, /*  bInterfaceClass */
100         0x02,                   /*  bInterfaceSubClass */
101         0x01,                   /*  bInterfaceProtocol, linux requires value of 1 for the cdc_acm module */
102         0x00,                   /*  iInterface */
103
104         /* Header functional descriptor */
105         0x05,
106         AO_USB_CS_INTERFACE,
107         0x00,                   /*  bDescriptor SubType Header */
108         LE_WORD(0x0110),        /*  CDC version 1.1 */
109
110         /* Call management functional descriptor */
111         0x05,
112         AO_USB_CS_INTERFACE,
113         0x01,                   /* bDescriptor SubType Call Management */
114         0x01,                   /* bmCapabilities = device handles call management */
115         0x01,                   /* bDataInterface call management interface number */
116
117         /* ACM functional descriptor */
118         0x04,
119         AO_USB_CS_INTERFACE,
120         0x02,                   /* bDescriptor SubType Abstract Control Management */
121         0x02,                   /* bmCapabilities = D1 (Set_line_Coding, Set_Control_Line_State, Get_Line_Coding and Serial_State) */
122
123         /* Union functional descriptor */
124         0x05,
125         AO_USB_CS_INTERFACE,
126         0x06,                   /* bDescriptor SubType Union Functional descriptor */
127         0x00,                   /* bMasterInterface */
128         0x01,                   /* bSlaveInterface0 */
129
130         /* Notification EP */
131         0x07,
132         AO_USB_DESC_ENDPOINT,
133         AO_USB_INT_EP|0x80,     /* bEndpointAddress */
134         0x03,                   /* bmAttributes = intr */
135         LE_WORD(8),             /* wMaxPacketSize */
136         0xff,                   /* bInterval */
137 #endif
138
139         /* Data class interface descriptor */
140         0x09,
141         AO_USB_DESC_INTERFACE,
142         AO_USB_HAS_INT,                 /* bInterfaceNumber */
143         0x00,                           /* bAlternateSetting */
144         AO_USB_HAS_OUT + AO_USB_HAS_IN + AO_USB_HAS_IN2,        /* bNumEndPoints */
145         AO_USB_INTERFACE_CLASS_DATA,    /* bInterfaceClass = data */
146         0x00,                           /* bInterfaceSubClass */
147         0x00,                           /* bInterfaceProtocol */
148         0x00,                           /* iInterface */
149
150 #if AO_USB_HAS_OUT
151         /* Data EP OUT */
152         0x07,
153         AO_USB_DESC_ENDPOINT,
154         AO_USB_OUT_EP,          /* bEndpointAddress */
155         0x02,                   /* bmAttributes = bulk */
156         LE_WORD(AO_USB_OUT_SIZE),/* wMaxPacketSize */
157         0x00,                   /* bInterval */
158 #endif
159
160 #if AO_USB_HAS_IN
161         /* Data EP in */
162         0x07,
163         AO_USB_DESC_ENDPOINT,
164         AO_USB_IN_EP|0x80,      /* bEndpointAddress */
165         0x02,                   /* bmAttributes = bulk */
166         LE_WORD(AO_USB_IN_SIZE),/* wMaxPacketSize */
167         0x00,                   /* bInterval */
168 #endif
169
170 #if AO_USB_HAS_IN2
171         /* Data EP in 2 */
172         0x07,
173         AO_USB_DESC_ENDPOINT,
174         AO_USB_IN2_EP|0x80,     /* bEndpointAddress */
175         0x02,                   /* bmAttributes = bulk */
176         LE_WORD(AO_USB_IN_SIZE),/* wMaxPacketSize */
177         0x00,                   /* bInterval */
178 #endif
179
180         /* String descriptors */
181         0x04,
182         AO_USB_DESC_STRING,
183         LE_WORD(0x0409),
184
185         /* iManufacturer */
186         AO_iManufacturer_LEN,
187         AO_USB_DESC_STRING,
188         AO_iManufacturer_UCS2,
189
190         /* iProduct */
191         AO_iProduct_LEN,
192         AO_USB_DESC_STRING,
193         AO_iProduct_UCS2,
194
195         /* iSerial */
196         AO_iSerial_LEN,
197         AO_USB_DESC_STRING,
198         AO_iSerial_UCS2,
199
200         /* Terminating zero */
201         0
202 };
203 #endif