altos: Add bit-bang i2c driver
[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 + 7 * AO_USB_HAS_IN3)
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 #ifndef AO_USBCONFIG_SYMBOL
64 #define AO_USBCONFIG_SYMBOL AO_ROMCONFIG_SYMBOL
65 #endif
66
67 /* USB descriptors in one giant block of bytes */
68 AO_USBCONFIG_SYMBOL uint8_t ao_usb_descriptors [] =
69 {
70         /* Device descriptor */
71         0x12,
72         AO_USB_DESC_DEVICE,
73         LE_WORD(0x0110),        /*  bcdUSB */
74         AO_USB_DEVICE_CLASS,    /*  bDeviceClass */
75         0x00,                   /*  bDeviceSubClass */
76         0x00,                   /*  bDeviceProtocol */
77         AO_USB_CONTROL_SIZE,    /*  bMaxPacketSize */
78         LE_WORD(AO_idVendor_NUMBER),    /*  idVendor */
79         LE_WORD(AO_idProduct_NUMBER),   /*  idProduct */
80         LE_WORD(0x0100),        /*  bcdDevice */
81         0x01,                   /*  iManufacturer */
82         0x02,                   /*  iProduct */
83         0x03,                   /*  iSerialNumber */
84         0x01,                   /*  bNumConfigurations */
85
86         /* Configuration descriptor */
87         0x09,
88         AO_USB_DESC_CONFIGURATION,
89         LE_WORD(TOTAL_LENGTH),  /*  wTotalLength */
90         NUM_INTERFACES,         /*  bNumInterfaces */
91         0x01,                   /*  bConfigurationValue */
92         0x00,                   /*  iConfiguration */
93         0x80 | (AO_USB_SELF_POWER << 6),        /*  bmAttributes */
94         AO_USB_MAX_POWER >> 1,  /*  bMaxPower, 2mA units */
95
96 #if AO_USB_HAS_INT
97         /* Control class interface */
98         0x09,
99         AO_USB_DESC_INTERFACE,
100         0x00,                   /*  bInterfaceNumber */
101         0x00,                   /*  bAlternateSetting */
102         0x01,                   /*  bNumEndPoints */
103         AO_USB_INTERFACE_CLASS_CONTROL, /*  bInterfaceClass */
104         0x02,                   /*  bInterfaceSubClass */
105         0x01,                   /*  bInterfaceProtocol, linux requires value of 1 for the cdc_acm module */
106         0x00,                   /*  iInterface */
107
108         /* Header functional descriptor */
109         0x05,
110         AO_USB_CS_INTERFACE,
111         0x00,                   /*  bDescriptor SubType Header */
112         LE_WORD(0x0110),        /*  CDC version 1.1 */
113
114         /* Call management functional descriptor */
115         0x05,
116         AO_USB_CS_INTERFACE,
117         0x01,                   /* bDescriptor SubType Call Management */
118         0x01,                   /* bmCapabilities = device handles call management */
119         0x01,                   /* bDataInterface call management interface number */
120
121         /* ACM functional descriptor */
122         0x04,
123         AO_USB_CS_INTERFACE,
124         0x02,                   /* bDescriptor SubType Abstract Control Management */
125         0x02,                   /* bmCapabilities = D1 (Set_line_Coding, Set_Control_Line_State, Get_Line_Coding and Serial_State) */
126
127         /* Union functional descriptor */
128         0x05,
129         AO_USB_CS_INTERFACE,
130         0x06,                   /* bDescriptor SubType Union Functional descriptor */
131         0x00,                   /* bMasterInterface */
132         0x01,                   /* bSlaveInterface0 */
133
134         /* Notification EP */
135         0x07,
136         AO_USB_DESC_ENDPOINT,
137         AO_USB_INT_EP|0x80,     /* bEndpointAddress */
138         0x03,                   /* bmAttributes = intr */
139         LE_WORD(8),             /* wMaxPacketSize */
140         0xff,                   /* bInterval */
141 #endif
142
143         /* Data class interface descriptor */
144         0x09,
145         AO_USB_DESC_INTERFACE,
146         AO_USB_HAS_INT,                 /* bInterfaceNumber */
147         0x00,                           /* bAlternateSetting */
148         AO_USB_HAS_OUT + AO_USB_HAS_IN + AO_USB_HAS_IN2 + AO_USB_HAS_IN3,       /* bNumEndPoints */
149         AO_USB_INTERFACE_CLASS_DATA,    /* bInterfaceClass = data */
150         0x00,                           /* bInterfaceSubClass */
151         0x00,                           /* bInterfaceProtocol */
152         0x00,                           /* iInterface */
153
154 #if AO_USB_HAS_OUT
155         /* Data EP OUT */
156         0x07,
157         AO_USB_DESC_ENDPOINT,
158         AO_USB_OUT_EP,          /* bEndpointAddress */
159         0x02,                   /* bmAttributes = bulk */
160         LE_WORD(AO_USB_OUT_SIZE),/* wMaxPacketSize */
161         0x00,                   /* bInterval */
162 #endif
163
164 #if AO_USB_HAS_IN
165         /* Data EP in */
166         0x07,
167         AO_USB_DESC_ENDPOINT,
168         AO_USB_IN_EP|0x80,      /* bEndpointAddress */
169         0x02,                   /* bmAttributes = bulk */
170         LE_WORD(AO_USB_IN_SIZE),/* wMaxPacketSize */
171         0x00,                   /* bInterval */
172 #endif
173
174 #if AO_USB_HAS_IN2
175         /* Data EP in 2 */
176         0x07,
177         AO_USB_DESC_ENDPOINT,
178         AO_USB_IN2_EP|0x80,     /* bEndpointAddress */
179         0x02,                   /* bmAttributes = bulk */
180         LE_WORD(AO_USB_IN_SIZE),/* wMaxPacketSize */
181         0x00,                   /* bInterval */
182 #endif
183
184 #if AO_USB_HAS_IN3
185         /* Data EP in 3 */
186         0x07,
187         AO_USB_DESC_ENDPOINT,
188         AO_USB_IN3_EP|0x80,     /* bEndpointAddress */
189         0x02,                   /* bmAttributes = bulk */
190         LE_WORD(AO_USB_IN_SIZE),/* wMaxPacketSize */
191         0x00,                   /* bInterval */
192 #endif
193
194         /* String descriptors */
195         0x04,
196         AO_USB_DESC_STRING,
197         LE_WORD(0x0409),
198
199         /* iManufacturer */
200         AO_iManufacturer_LEN,
201         AO_USB_DESC_STRING,
202         AO_iManufacturer_UCS2,
203
204         /* iProduct */
205         AO_iProduct_LEN,
206         AO_USB_DESC_STRING,
207         AO_iProduct_UCS2,
208
209         /* iSerial */
210         AO_iSerial_LEN,
211         AO_USB_DESC_STRING,
212         AO_iSerial_UCS2,
213
214         /* Terminating zero */
215         0
216 };
217 #endif