altos: Start work on LPC I2C driver
[fw/altos] / src / lpc / lpc.h
1 /*
2  * Copyright © 2013 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 #ifndef _LPC_H_
20 #define _LPC_H_
21
22 #include <stdint.h>
23
24 typedef volatile uint32_t       vuint32_t;
25 typedef volatile uint16_t       vuint16_t;
26 typedef volatile uint8_t        vuint8_t;
27 typedef volatile void *         vvoid_t;
28
29 struct lpc_ioconf {
30         vuint32_t       pio0_0;
31         vuint32_t       pio0_1;
32         vuint32_t       pio0_2;
33         vuint32_t       pio0_3;
34
35         vuint32_t       pio0_4;
36         vuint32_t       pio0_5;
37         vuint32_t       pio0_6;
38         vuint32_t       pio0_7;
39
40         vuint32_t       pio0_8;
41         vuint32_t       pio0_9;
42         vuint32_t       pio0_10;
43         vuint32_t       pio0_11;
44
45         vuint32_t       pio0_12;
46         vuint32_t       pio0_13;
47         vuint32_t       pio0_14;
48         vuint32_t       pio0_15;
49
50         vuint32_t       pio0_16;
51         vuint32_t       pio0_17;
52         vuint32_t       pio0_18;
53         vuint32_t       pio0_19;
54
55         vuint32_t       pio0_20;
56         vuint32_t       pio0_21;
57         vuint32_t       pio0_22;
58         vuint32_t       pio0_23;
59
60         vuint32_t       pio1_0;         /* 0x60 */
61         vuint32_t       pio1_1;
62         vuint32_t       pio1_2;
63         vuint32_t       pio1_3;
64
65         vuint32_t       pio1_4;
66         vuint32_t       pio1_5;
67         vuint32_t       pio1_6;
68         vuint32_t       pio1_7;
69
70         vuint32_t       pio1_8;         /* 0x80 */
71         vuint32_t       pio1_9;
72         vuint32_t       pio1_10;
73         vuint32_t       pio1_11;
74
75         vuint32_t       pio1_12;
76         vuint32_t       pio1_13;
77         vuint32_t       pio1_14;
78         vuint32_t       pio1_15;
79
80         vuint32_t       pio1_16;        /* 0xa0 */
81         vuint32_t       pio1_17;
82         vuint32_t       pio1_18;
83         vuint32_t       pio1_19;
84
85         vuint32_t       pio1_20;
86         vuint32_t       pio1_21;
87         vuint32_t       pio1_22;
88         vuint32_t       pio1_23;
89
90         vuint32_t       pio1_24;        /* 0xc0 */
91         vuint32_t       pio1_25;
92         vuint32_t       pio1_26;
93         vuint32_t       pio1_27;
94
95         vuint32_t       pio1_28;
96         vuint32_t       pio1_29;
97         vuint32_t       pio1_30;
98         vuint32_t       pio1_31;
99 };
100
101 extern struct lpc_ioconf lpc_ioconf;
102 #define lpc_ioconf (*(struct lpc_ioconf *) 0x40044000)
103
104 #define LPC_IOCONF_FUNC         0
105
106 /* PIO0_0 */
107 #define  LPC_IOCONF_FUNC_RESET          0
108 #define  LPC_IOCONF_FUNC_PIO0_0         1
109
110 /* PIO0_1 */
111 #define  LPC_IOCONF_FUNC_PIO0_1         0
112 #define  LPC_IOCONF_FUNC_CLKOUT         1
113 #define  LPC_IOCONF_FUNC_PIO0_1_CT32B0_MAT2     2
114 #define  LPC_IOCONF_FUNC_USB_FTOGGLE    3
115
116 /* PIO0_2 */
117 #define  LPC_IOCONF_FUNC_PIO0_2         0
118 #define  LPC_IOCONF_FUNC_SSEL0          1
119 #define  LPC_IOCONF_FUNC_PIO0_2_CT16B0_CAP0     2
120
121 /* PIO0_3 */
122 #define  LPC_IOCONF_FUNC_PIO0_3         0
123 #define  LPC_IOCONF_FUNC_USB_VBUS       1
124
125 /* PIO0_4 */
126 #define  LPC_IOCONF_FUNC_PIO0_4         0
127 #define  LPC_IOCONF_FUNC_I2C_SCL        1
128
129 /* PIO0_5 */
130 #define  LPC_IOCONF_FUNC_PIO0_5         0
131 #define  LPC_IOCONF_FUNC_I2C_SDA        1
132
133 /* PIO0_6 */
134 #define  LPC_IOCONF_FUNC_PIO0_6         0
135 #define  LPC_IOCONF_FUNC_USB_CONNECT    1
136 #define  LPC_IOCONF_FUNC_PIO0_6_SCK0    2
137
138 /* PIO0_7 */
139 #define  LPC_IOCONF_FUNC_PIO0_7         0
140 #define  LPC_IOCONF_FUNC_CTS            1
141
142 /* PIO0_8 */
143 #define  LPC_IOCONF_FUNC_PIO0_8         0
144 #define  LPC_IOCONF_FUNC_MISO0          1
145 #define  LPC_IOCONF_FUNC_PIO0_8_CT16B0_MAT0     2
146
147 /* PIO0_9 */
148 #define  LPC_IOCONF_FUNC_PIO0_9         0
149 #define  LPC_IOCONF_FUNC_MOSI0          1
150 #define  LPC_IOCONF_FUNC_PIO0_9_CT16B0_MAT1     2
151
152 /* PIO0_10 */
153 #define  LPC_IOCONF_FUNC_SWCLK          0
154 #define  LPC_IOCONF_FUNC_PIO0_10        1
155 #define  LPC_IOCONF_FUNC_PIO0_10_SCK0   2
156 #define  LPC_IOCONF_FUNC_PIO0_10_CT16B0_MAT2    3
157
158 /* PIO0_11 */
159 #define  LPC_IOCONF_FUNC_TDI            0
160 #define  LPC_IOCONF_FUNC_PIO0_11        1
161 #define  LPC_IOCONF_FUNC_AD0            2
162 #define  LPC_IOCONF_FUNC_PIO0_11_CT32B0_MAT3    3
163
164 /* PIO0_12 */
165 #define  LPC_IOCONF_FUNC_TMS            0
166 #define  LPC_IOCONF_FUNC_PIO0_12        1
167 #define  LPC_IOCONF_FUNC_AD1            2
168 #define  LPC_IOCONF_FUNC_PIO0_12_CT32B1_CAP0    3
169
170 /* PIO0_13 */
171 #define  LPC_IOCONF_FUNC_TD0            0
172 #define  LPC_IOCONF_FUNC_PIO0_13        1
173 #define  LPC_IOCONF_FUNC_AD2            2
174 #define  LPC_IOCONF_FUNC_PIO0_13_CT32B1_MAT0    3
175
176 /* PIO0_14 */
177 #define  LPC_IOCONF_FUNC_TRST           0
178 #define  LPC_IOCONF_FUNC_PIO0_14        1
179 #define  LPC_IOCONF_FUNC_AD3            2
180 #define  LPC_IOCONF_FUNC_PIO0_14_CT32B1_MAT1    3
181
182 /* PIO0_15 */
183 #define  LPC_IOCONF_FUNC_SWDIO          0
184 #define  LPC_IOCONF_FUNC_PIO0_15        1
185 #define  LPC_IOCONF_FUNC_AD4            2
186 #define  LPC_IOCONF_FUNC_PIO0_15_CT32B1_MAT2    3
187
188 /* PIO0_16 */
189 #define  LPC_IOCONF_FUNC_PIO0_16        0
190 #define  LPC_IOCONF_FUNC_AD5            1
191 #define  LPC_IOCONF_FUNC_PIO0_16_CT32B1_MAT3    2
192
193 /* PIO0_17 */
194 #define  LPC_IOCONF_FUNC_PIO0_17        0
195 #define  LPC_IOCONF_FUNC_RTS            1
196 #define  LPC_IOCONF_FUNC_CT32B0_CAP0    2
197 #define  LPC_IOCONF_FUNC_SCLK           3
198
199 /* PIO0_18 */
200 #define  LPC_IOCONF_FUNC_PIO0_18                0
201 #define  LPC_IOCONF_FUNC_PIO0_18_RXD            1
202 #define  LPC_IOCONF_FUNC_PIO0_18_CT32B0_MAT0    2
203
204 /* PIO0_19 */
205 #define  LPC_IOCONF_FUNC_PIO0_19                0
206 #define  LPC_IOCONF_FUNC_PIO0_19_TXD            1
207 #define  LPC_IOCONF_FUNC_PIO0_19_CT32B0_MAT1    2
208
209 /* PIO0_20 */
210 #define  LPC_IOCONF_FUNC_PIO0_20        0
211 #define  LPC_IOCONF_FUNC_PIO0_20_CT16B1_CAP0    1
212
213 /* PIO0_21 */
214 #define  LPC_IOCONF_FUNC_PIO0_21        0
215 #define  LPC_IOCONF_FUNC_PIO0_21_CT16B1_MAT0    1
216 #define  LPC_IOCONF_FUNC_PIO0_21_MOSI1  2
217
218 /* PIO0_22 */
219 #define  LPC_IOCONF_FUNC_PIO0_22        0
220 #define  LPC_IOCONF_FUNC_AD6            1
221 #define  LPC_IOCONF_FUNC_PIO0_22_CT16B1_MAT1    2
222 #define  LPC_IOCONF_FUNC_PIO0_22_MISO1  3
223
224 /* PIO0_23 */
225 #define  LPC_IOCONF_FUNC_PIO0_23        0
226 #define  LPC_IOCONF_FUNC_AD7            1
227
228 /* PIO1_0 */
229 #define  LPC_IOCONF_FUNC_PIO1_0         0
230 #define  LPC_IOCONF_FUNC_PIO1_0_CT32B1_MAT1     1
231
232 /* PIO1_1 */
233 #define  LPC_IOCONF_FUNC_PIO1_1         0
234 #define  LPC_IOCONF_FUNC_PIO1_1_CT32B1_MAT1     1
235
236 /* PIO1_2 */
237 #define  LPC_IOCONF_FUNC_PIO1_2         0
238 #define  LPC_IOCONF_FUNC_PIO1_2_CT32B1_MAT2     1
239
240 /* PIO1_3*/
241 #define  LPC_IOCONF_FUNC_PIO1_3         0
242 #define  LPC_IOCONF_FUNC_PIO1_3_CT32B1_MAT3     1
243
244 /* PIO1_4 */
245 #define  LPC_IOCONF_FUNC_PIO1_4         0
246 #define  LPC_IOCONF_FUNC_PIO1_4_CT32B1_CAP0     1
247
248 /* PIO1_5 */
249 #define  LPC_IOCONF_FUNC_PIO1_5         0
250 #define  LPC_IOCONF_FUNC_PIO1_5_CT32B1_CAP1     1
251
252 /* PIO1_6 */
253 #define  LPC_IOCONF_FUNC_PIO1_6         0
254
255 /* PIO1_7 */
256 #define  LPC_IOCONF_FUNC_PIO1_7         0
257
258 /* PIO1_8 */
259 #define  LPC_IOCONF_FUNC_PIO1_8         0
260
261 /* PIO1_9 */
262 #define  LPC_IOCONF_FUNC_PIO1_9         0
263
264 /* PIO1_10 */
265 #define  LPC_IOCONF_FUNC_PIO1_10        0
266
267 /* PIO1_11 */
268 #define  LPC_IOCONF_FUNC_PIO1_11        0
269
270 /* PIO1_12 */
271 #define  LPC_IOCONF_FUNC_PIO1_12        0
272
273 /* PIO1_13 */
274 #define  LPC_IOCONF_FUNC_PIO1_13        0
275 #define  LPC_IOCONF_FUNC_DTR            1
276 #define  LPC_IOCONF_FUNC_PIO1_13_CT16B0_MAT0    2
277 #define  LPC_IOCONF_FUNC_PIO1_13_TXD            3
278
279 /* PIO1_14 */
280 #define  LPC_IOCONF_FUNC_PIO1_14        0
281 #define  LPC_IOCONF_FUNC_DSR            1
282 #define  LPC_IOCONF_FUNC_PIO1_14_CT16B0_MAT1    2
283 #define  LPC_IOCONF_FUNC_PIO1_13_RXD            3
284
285 /* PIO1_15 */
286 #define  LPC_IOCONF_FUNC_PIO1_15        0
287 #define  LPC_IOCONF_FUNC_DCD            1
288 #define  LPC_IOCONF_FUNC_PIO1_15_CT16B0_MAT2    2
289 #define  LPC_IOCONF_FUNC_PIO1_15_SCK1   3
290
291 /* PIO1_16 */
292 #define  LPC_IOCONF_FUNC_PIO1_16        0
293 #define  LPC_IOCONF_FUNC_RI             1
294 #define  LPC_IOCONF_FUNC_PIO1_16_CT16B0_CAP0    2
295
296 /* PIO1_17 */
297 #define  LPC_IOCONF_FUNC_PIO1_17        0
298 #define  LPC_IOCONF_FUNC_PIO1_17_CT16B0_CAP1    1
299 #define  LPC_IOCONF_FUNC_PIO1_17_RXD            2
300
301 /* PIO1_18 */
302 #define  LPC_IOCONF_FUNC_PIO1_18        0
303 #define  LPC_IOCONF_FUNC_PIO1_18_CT16B1_CAP1    1
304 #define  LPC_IOCONF_FUNC_PIO1_18_TXD            2
305
306 /* PIO1_19 */
307 #define  LPC_IOCONF_FUNC_PIO1_19        0
308 #define  LPC_IOCONF_FUNC_DTR            1
309 #define  LPC_IOCONF_FUNC_SSEL1          2
310
311 /* PIO1_20 */
312 #define  LPC_IOCONF_FUNC_PIO1_20        0
313 #define  LPC_IOCONF_FUNC_DSR            1
314 #define  LPC_IOCONF_FUNC_PIO1_20_SCK1           2
315
316 /* PIO1_21 */
317 #define  LPC_IOCONF_FUNC_PIO1_21        0
318 #define  LPC_IOCONF_FUNC_DCD            1
319 #define  LPC_IOCONF_FUNC_PIO1_21_MISO1          2
320
321 /* PIO1_22 */
322 #define  LPC_IOCONF_FUNC_PIO1_22        0
323 #define  LPC_IOCONF_FUNC_RI             1
324 #define  LPC_IOCONF_FUNC_PIO1_22_MOSI1  2
325
326 /* PIO1_23 */
327 #define  LPC_IOCONF_FUNC_PIO1_23        0
328 #define  LPC_IOCONF_FUNC_PIO1_23_CT16B1_MAT1    1
329 #define  LPC_IOCONF_FUNC_SSEL1          2
330
331 /* PIO1_24 */
332 #define  LPC_IOCONF_FUNC_PIO1_24        0
333 #define  LPC_IOCONF_FUNC_PIO1_24_CT32B0_MAT0    1
334
335 /* PIO1_25 */
336 #define  LPC_IOCONF_FUNC_PIO1_25        0
337 #define  LPC_IOCONF_FUNC_PIO1_25_CT32B0_MAT1    1
338
339 /* PIO1_26 */
340 #define  LPC_IOCONF_FUNC_PIO1_26        0
341 #define  LPC_IOCONF_FUNC_PIO1_26_CT32B0_MAT2    1
342 #define  LPC_IOCONF_FUNC_PIO1_26_RXD            2
343
344 /* PIO1_27 */
345 #define  LPC_IOCONF_FUNC_PIO1_27        0
346 #define  LPC_IOCONF_FUNC_PIO1_27_CT32B0_MAT3    1
347 #define  LPC_IOCONF_FUNC_PIO1_27_TXD            2
348
349 /* PIO1_28 */
350 #define  LPC_IOCONF_FUNC_PIO1_28        0
351 #define  LPC_IOCONF_FUNC_PIO1_28_CT32B0_CAP0    1
352 #define  LPC_IOCONF_FUNC_PIO1_28_SCLK           2
353
354 /* PIO1_29 */
355 #define  LPC_IOCONF_FUNC_PIO1_29                0
356 #define  LPC_IOCONF_FUNC_PIO1_29_SCK0           1
357 #define  LPC_IOCONF_FUNC_PIO1_29_CT32B0_CAP1    2
358
359 /* PIO1_31 */
360 #define  LPC_IOCONF_FUNC_PIO1_31        0
361
362 #define  LPC_IOCONF_FUNC_MASK           0x7UL
363
364 #define ao_lpc_alternate(func) (((func) << LPC_IOCONF_FUNC) | \
365                                 (LPC_IOCONF_MODE_INACTIVE << LPC_IOCONF_MODE) | \
366                                 (0 << LPC_IOCONF_HYS) |                 \
367                                 (0 << LPC_IOCONF_INV) |                 \
368                                 (0 << LPC_IOCONF_OD) |                  \
369                                 0x80)
370
371 #define LPC_IOCONF_MODE                 3
372 #define  LPC_IOCONF_MODE_INACTIVE               0
373 #define  LPC_IOCONF_MODE_PULL_DOWN              1
374 #define  LPC_IOCONF_MODE_PULL_UP                2
375 #define  LPC_IOCONF_MODE_REPEATER               3
376 #define  LPC_IOCONF_MODE_MASK                   3UL
377
378 #define LPC_IOCONF_HYS                  5
379
380 #define LPC_IOCONF_INV                  6
381 #define LPC_IOCONF_ADMODE               7
382 #define LPC_IOCONF_FILTR                8
383 #define LPC_IOCONF_OD                   10
384
385 struct lpc_scb {
386         vuint32_t       sysmemremap;    /* 0x00 */
387         vuint32_t       presetctrl;
388         vuint32_t       syspllctrl;
389         vuint32_t       syspllstat;
390
391         vuint32_t       usbpllctrl;     /* 0x10 */
392         vuint32_t       usbpllstat;
393         uint32_t        r18;
394         uint32_t        r1c;
395
396         vuint32_t       sysoscctrl;     /* 0x20 */
397         vuint32_t       wdtoscctrl;
398         uint32_t        r28;
399         uint32_t        r2c;
400
401         vuint32_t       sysrststat;     /* 0x30 */
402         uint32_t        r34;
403         uint32_t        r38;
404         uint32_t        r3c;
405
406         vuint32_t       syspllclksel;   /* 0x40 */
407         vuint32_t       syspllclkuen;
408         vuint32_t       usbpllclksel;
409         vuint32_t       usbpllclkuen;
410
411         uint32_t        r50[8];
412
413         vuint32_t       mainclksel;     /* 0x70 */
414         vuint32_t       mainclkuen;
415         vuint32_t       sysahbclkdiv;
416         uint32_t        r7c;
417
418         vuint32_t       sysahbclkctrl;  /* 0x80 */
419         uint32_t        r84[3];
420
421         uint32_t        r90;            /* 0x90 */
422         vuint32_t       ssp0clkdiv;
423         vuint32_t       uartclkdiv;
424         vuint32_t       ssp1clkdiv;
425
426         uint32_t        ra0[8];
427
428         vuint32_t       usbclksel;      /* 0xc0 */
429         vuint32_t       usbclkuen;
430         vuint32_t       usbclkdiv;
431         uint32_t        rcc;
432
433         uint32_t        rd0[4];
434
435         vuint32_t       clkoutsel;      /* 0xe0 */
436         vuint32_t       clkoutuen;
437         vuint32_t       clkoutdiv;
438         uint32_t        rec;
439
440         uint32_t        rf0[4];         /* 0xf0 */
441
442         vuint32_t       pioporcap0;     /* 0x100 */
443         vuint32_t       pioporcap1;
444         uint32_t        r102[2];
445
446         uint32_t        r110[4];        /* 0x110 */
447         uint32_t        r120[4];        /* 0x120 */
448         uint32_t        r130[4];        /* 0x130 */
449         uint32_t        r140[4];        /* 0x140 */
450
451         vuint32_t       bodctrl;        /* 0x150 */
452         vuint32_t       systckcal;
453         uint32_t        r158[2];
454
455         uint32_t        r160[4];        /* 0x160 */
456
457         vuint32_t       irqlatency;     /* 0x170 */
458         vuint32_t       nmisrc;
459         vuint32_t       pintsel[8];
460
461         vuint32_t       usbclkctrl;     /* 0x198 */
462         vuint32_t       usbclkst;
463
464         uint32_t        r1a0[6*4];      /* 0x1a0 */
465
466         uint32_t        r200;           /* 0x200 */
467         vuint32_t       starterp0;
468         uint32_t        r208[2];
469
470         uint32_t        r210;           /* 0x210 */
471         vuint32_t       starterp1;
472         uint32_t        r218[2];
473
474         uint32_t        r220[4];        /* 0x220 */
475
476         vuint32_t       pdsleepcfg;     /* 0x230 */
477         vuint32_t       pdawakecfg;
478         vuint32_t       pdruncfg;
479         uint32_t        r23c;
480
481         uint32_t        r240[12 * 4];   /* 0x240 */
482
483         uint32_t        r300[15 * 4];   /* 0x300 */
484
485         uint32_t        r3f0;           /* 0x3f0 */
486         vuint32_t       device_id;
487 };
488
489 extern struct lpc_scb lpc_scb;
490 #define lpc_scb (*(struct lpc_scb *) 0x40048000)
491
492 #define LPC_SCB_SYSMEMREMAP_MAP         0
493 # define LPC_SCB_SYSMEMREMAP_MAP_BOOT_LOADER    0
494 # define LPC_SCB_SYSMEMREMAP_MAP_RAM            1
495 # define LPC_SCB_SYSMEMREMAP_MAP_FLASH          2
496
497 #define LPC_SCB_PRESETCTRL_SSP0_RST_N   0
498 #define LPC_SCB_PRESETCTRL_I2C_RST_N    1
499 #define LPC_SCB_PRESETCTRL_SSP1_RST_N   2
500
501 #define LPC_SCB_SYSPLLCTRL_MSEL         0
502 #define LPC_SCB_SYSPLLCTRL_PSEL         5
503 #define  LPC_SCB_SYSPLLCTRL_PSEL_1              0
504 #define  LPC_SCB_SYSPLLCTRL_PSEL_2              1
505 #define  LPC_SCB_SYSPLLCTRL_PSEL_4              2
506 #define  LPC_SCB_SYSPLLCTRL_PSEL_8              3
507 #define  LPC_SCB_SYSPLLCTRL_PSEL_MASK           3UL
508
509 #define LPC_SCB_SYSPLLSTAT_LOCK         0
510
511 #define LPC_SCB_USBPLLCTRL_MSEL         0
512 #define LPC_SCB_USBPLLCTRL_PSEL         5
513 #define  LPC_SCB_USBPLLCTRL_PSEL_1              0
514 #define  LPC_SCB_USBPLLCTRL_PSEL_2              1
515 #define  LPC_SCB_USBPLLCTRL_PSEL_4              2
516 #define  LPC_SCB_USBPLLCTRL_PSEL_8              3
517 #define  LPC_SCB_USBPLLCTRL_PSEL_MASK           3UL
518
519 #define LPC_SCB_USBPLLSTAT_LOCK         0
520
521 #define LPC_SCB_SYSOSCCTRL_BYPASS       0
522 #define LPC_SCB_SYSOSCCTRL_FREQRANGE    1
523 #define  LPC_SCB_SYSOSCCTRL_FREQRANGE_1_20      0
524 #define  LPC_SCB_SYSOSCCTRL_FREQRANGE_15_25     1
525
526 #define LPC_SCB_WDTOSCCTRL_DIVSEL               0
527 #define  LPC_SCB_WDTOSCCTRL_DIVSEL_MASK                 0x1fUL
528 #define LPC_SCB_WDTOSCCTRL_FREQSEL              5
529 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_0_6                 1
530 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_1_05                2
531 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_1_4                 3
532 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_1_75                4
533 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_2_1                 5
534 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_2_4                 6
535 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_2_7                 7
536 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_3_0                 8
537 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_3_25                9
538 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_3_5                 0x0a
539 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_3_75                0x0b
540 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_4_0                 0x0c
541 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_4_2                 0x0d
542 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_4_4                 0x0e
543 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_4_6                 0x0f
544 #define  LPC_SCB_WDTOSCCTRL_FREQSEL_MASK                0x0fUL
545
546 #define LPC_SCB_SYSRSTSTAT_POR          0
547 #define LPC_SCB_SYSRSTSTAT_EXTRST       1
548 #define LPC_SCB_SYSRSTSTAT_WDT          2
549 #define LPC_SCB_SYSRSTSTAT_BOD          3
550 #define LPC_SCB_SYSRSTSTAT_SYSRST       4
551
552 #define LPC_SCB_SYSPLLCLKSEL_SEL        0
553 #define  LPC_SCB_SYSPLLCLKSEL_SEL_IRC           0
554 #define  LPC_SCB_SYSPLLCLKSEL_SEL_SYSOSC        1
555 #define  LPC_SCB_SYSPLLCLKSEL_SEL_MASK          3UL
556
557 #define LPC_SCB_SYSPLLCLKUEN_ENA        0
558
559 #define LPC_SCB_USBPLLCLKSEL_SEL        0
560 #define  LPC_SCB_USBPLLCLKSEL_SEL_IRC           0
561 #define  LPC_SCB_USBPLLCLKSEL_SEL_SYSOSC        1
562 #define  LPC_SCB_USBPLLCLKSEL_SEL_MASK          3UL
563
564 #define LPC_SCB_USBPLLCLKUEN_ENA        0
565
566 #define LPC_SCB_MAINCLKSEL_SEL          0
567 #define  LPC_SCB_MAINCLKSEL_SEL_IRC             0
568 #define  LPC_SCB_MAINCLKSEL_SEL_PLL_INPUT       1
569 #define  LPC_SCB_MAINCLKSEL_SEL_WATCHDOG        2
570 #define  LPC_SCB_MAINCLKSEL_SEL_PLL_OUTPUT      3
571 #define  LPC_SCB_MAINCLKSEL_SEL_MASK            3UL
572
573 #define LPC_SCB_MAINCLKUEN_ENA          0
574
575 #define LPC_SCB_SYSAHBCLKDIV_DIV        0
576
577 #define LPC_SCB_SYSAHBCLKCTRL_SYS       0
578 #define LPC_SCB_SYSAHBCLKCTRL_ROM       1
579 #define LPC_SCB_SYSAHBCLKCTRL_RAM0      2
580 #define LPC_SCB_SYSAHBCLKCTRL_FLASHREG  3
581 #define LPC_SCB_SYSAHBCLKCTRL_FLASHARRAY        4
582 #define LPC_SCB_SYSAHBCLKCTRL_I2C       5
583 #define LPC_SCB_SYSAHBCLKCTRL_GPIO      6
584 #define LPC_SCB_SYSAHBCLKCTRL_CT16B0    7
585 #define LPC_SCB_SYSAHBCLKCTRL_CT16B1    8
586 #define LPC_SCB_SYSAHBCLKCTRL_CT32B0    9
587 #define LPC_SCB_SYSAHBCLKCTRL_CT32B1    10
588 #define LPC_SCB_SYSAHBCLKCTRL_SSP0      11
589 #define LPC_SCB_SYSAHBCLKCTRL_USART     12
590 #define LPC_SCB_SYSAHBCLKCTRL_ADC       13
591 #define LPC_SCB_SYSAHBCLKCTRL_USB       14
592 #define LPC_SCB_SYSAHBCLKCTRL_WWDT      15
593 #define LPC_SCB_SYSAHBCLKCTRL_IOCON     16
594 #define LPC_SCB_SYSAHBCLKCTRL_SSP1      18
595 #define LPC_SCB_SYSAHBCLKCTRL_PINT      19
596 #define LPC_SCB_SYSAHBCLKCTRL_GROUP0INT 23
597 #define LPC_SCB_SYSAHBCLKCTRL_GROUP1INT 24
598 #define LPC_SCB_SYSAHBCLKCTRL_RAM1      26
599 #define LPC_SCB_SYSAHBCLKCTRL_USBRAM    27
600
601 #define LPC_SCB_SSP0CLKDIV_
602 #define LPC_SCB_UARTCLKDIV_
603 #define LPC_SCB_SSP1CLKDIV_
604
605 #define LPC_SCB_USBCLKSEL_SEL           0
606 #define LPC_SCB_USBCLKSEL_SEL_USB_PLL           0
607 #define LPC_SCB_USBCLKSEL_SEL_MAIN_CLOCK        1
608
609 #define LPC_SCB_USBCLKUEN_ENA           0
610 #define LPC_SCB_USBCLKDIV_DIV           0
611
612 #define LPC_SCB_CLKOUTSEL_SEL           0
613 #define  LPC_SCB_CLKOUTSEL_SEL_IRC              0
614 #define  LPC_SCB_CLKOUTSEL_SEL_SYSOSC           1
615 #define  LPC_SCB_CLKOUTSEL_SEL_LF               2
616 #define  LPC_SCB_CLKOUTSEL_SEL_MAIN_CLOCK       3
617
618 #define LPC_SCB_CLKOUTUEN_ENA           0
619
620 #define LPC_SCB_BOD_BODRSTLEV           0
621 # define LPC_SCB_BOD_BODRSTLEV_1_46             0
622 # define LPC_SCB_BOD_BODRSTLEV_2_06             1
623 # define LPC_SCB_BOD_BODRSTLEV_2_35             2
624 # define LPC_SCB_BOD_BODRSTLEV_2_63             3
625 #define LPC_SCB_BOD_BODINTVAL           2
626 # define LPC_SCB_BOD_BODINTVAL_RESERVED         0
627 # define LPC_SCB_BOD_BODINTVAL_2_22             1
628 # define LPC_SCB_BOD_BODINTVAL_2_52             2
629 # define LPC_SCB_BOD_BODINTVAL_2_80             3
630 #define LPC_SCB_BOD_BODRSTENA           4
631
632 #define LPC_SCB_PDRUNCFG_IRCOUT_PD      0
633 #define LPC_SCB_PDRUNCFG_IRC_PD         1
634 #define LPC_SCB_PDRUNCFG_FLASH_PD       2
635 #define LPC_SCB_PDRUNCFG_BOD_PD         3
636 #define LPC_SCB_PDRUNCFG_ADC_PD         4
637 #define LPC_SCB_PDRUNCFG_SYSOSC_PD      5
638 #define LPC_SCB_PDRUNCFG_WDTOSC_PD      6
639 #define LPC_SCB_PDRUNCFG_SYSPLL_PD      7
640 #define LPC_SCB_PDRUNCFG_USBPLL_PD      8
641 #define LPC_SCB_PDRUNCFG_USBPAD_PD      10
642
643 struct lpc_i2c {
644         vuint32_t       conset;
645         vuint32_t       stat;
646         vuint32_t       dat;
647         vuint32_t       adr0;
648
649         vuint32_t       sclh;
650         vuint32_t       scll;
651         vuint32_t       conclr;
652         vuint32_t       mmctrl;
653
654         vuint32_t       adr[3];
655         vuint32_t       data_buffer;
656
657         vuint32_t       mask[4];
658 };
659
660 extern struct lpc_i2c lpc_i2c;
661
662 #define lpc_i2c (*(struct lpc_i2c *) 0x40000000)
663
664 #define LPC_I2C_CONSET_AA       2
665 #define LPC_I2C_CONSET_SI       3
666 #define LPC_I2C_CONSET_STO      4
667 #define LPC_I2C_CONSET_STA      5
668 #define LPC_I2C_CONSET_I2EN     6
669
670 /* master status values */
671 #define LPC_I2C_STAT_ERROR              0x00
672 #define LPC_I2C_STAT_START              0x08
673 #define LPC_I2C_STAT_REPEAT_START       0x10
674 #define LPC_I2C_STAT_TX_START_ACK       0x18
675 #define LPC_I2C_STAT_TX_START_NACK      0x20
676 #define LPC_I2C_STAT_TX_ACK             0x28
677 #define LPC_I2C_STAT_TX_NACK            0x30
678 #define LPC_I2C_STAT_TX_ARB_LOST        0x38
679 #define LPC_I2C_STAT_RX_START_ACK       0x40
680 #define LPC_I2C_STAT_RX_START_NACK      0x48
681 #define LPC_I2C_STAT_RX_ACK             0x50
682 #define LPC_I2C_STAT_RX_NACK            0x58
683
684
685 #define LPC_I2C_ADR_GC          0
686 #define LPC_I2C_ADR_ADDRESS     1
687
688 #define LPC_I2C_CONCLR_AAC      2
689 #define LPC_I2C_CONCLR_SIC      3
690 #define LPC_I2C_CONCLR_STAC     5
691 #define LPC_I2C_CONCLR_I2ENC    6
692
693 #define LPC_I2C_MMCTRL_MM_ENA   0
694 #define LPC_I2C_MMCTRL_ENA_SCL  1
695 #define LPC_I2C_MMCTRL_MATCH_ALL        2
696
697 #define LPC_I2C_MASK_MASK       1
698
699 struct lpc_flash {
700         uint32_t        r0[4];          /* 0x0 */
701
702         vuint32_t       flashcfg;       /* 0x10 */
703 };
704
705 extern struct lpc_flash lpc_flash;
706 #define lpc_flash (*(struct lpc_flash *) 0x4003c000)
707
708 struct lpc_gpio_pin {
709         vuint32_t       isel;           /* 0x00 */
710         vuint32_t       ienr;
711         vuint32_t       sienr;
712         vuint32_t       cienr;
713
714         vuint32_t       ienf;           /* 0x10 */
715         vuint32_t       sienf;
716         vuint32_t       cienf;
717         vuint32_t       rise;
718
719         vuint32_t       fall;           /* 0x20 */
720         vuint32_t       ist;
721 };
722
723 extern struct lpc_gpio_pin lpc_gpio_pin;
724 #define lpc_gpio_pin (*(struct lpc_gpio_pin *) 0x4004c000)
725
726 struct lpc_gpio_group0 {
727 };
728
729 extern struct lpc_gpio_group0 lpc_gpio_group0;
730
731 struct lpc_gpio_group1 {
732 };
733
734 extern struct lpc_gpio_group1 lpc_gpio_group1;
735
736 struct lpc_gpio {
737         vuint8_t        byte[0x40];     /* 0x0000 */
738
739         uint8_t         r0030[0x1000 - 0x40];
740
741         vuint32_t       word[0x40];     /* 0x1000 */
742
743         uint8_t         r1100[0x2000 - 0x1100];
744
745         vuint32_t       dir[2];         /* 0x2000 */
746
747         uint8_t         r2008[0x2080 - 0x2008];
748
749         vuint32_t       mask[2];        /* 0x2080 */
750
751         uint8_t         r2088[0x2100 - 0x2088];
752
753         vuint32_t       pin[2];         /* 0x2100 */
754
755         uint8_t         r2108[0x2200 - 0x2108];
756
757         vuint32_t       set[2];         /* 0x2200 */
758
759         uint8_t         r2208[0x2280 - 0x2208];
760
761         vuint32_t       clr[2];         /* 0x2280 */
762
763         uint8_t         r2288[0x2300 - 0x2288];
764
765         vuint32_t       not[2];         /* 0x2300 */
766 };
767
768 extern struct lpc_gpio lpc_gpio;
769 #define lpc_gpio (*(struct lpc_gpio *) 0x50000000)
770
771 struct lpc_systick {
772         uint8_t         r0000[0x10];    /* 0x0000 */
773
774         vuint32_t       csr;            /* 0x0010 */
775         vuint32_t       rvr;
776         vuint32_t       cvr;
777         vuint32_t       calib;
778 };
779
780 extern struct lpc_systick lpc_systick;
781 #define lpc_systick (*(struct lpc_systick *) 0xe000e000)
782
783 #define LPC_SYSTICK_CSR_ENABLE          0
784 #define LPC_SYSTICK_CSR_TICKINT         1
785 #define LPC_SYSTICK_CSR_CLKSOURCE       2
786 #define  LPC_SYSTICK_CSR_CLKSOURCE_CPU_OVER_2           0
787 #define  LPC_SYSTICK_CSR_CLKSOURCE_CPU                  1
788 #define LPC_SYSTICK_CSR_COUNTFLAG       16
789
790 struct lpc_usart {
791         vuint32_t       rbr_thr;        /* 0x0000 */
792         vuint32_t       ier;
793         vuint32_t       iir_fcr;
794         vuint32_t       lcr;
795
796         vuint32_t       mcr;            /* 0x0010 */
797         vuint32_t       lsr;
798         vuint32_t       msr;
799         vuint32_t       scr;
800
801         vuint32_t       acr;            /* 0x0020 */
802         vuint32_t       icr;
803         vuint32_t       fdr;
804         vuint32_t       osr;
805
806         vuint32_t       ter;            /* 0x0030 */
807         uint32_t        r34[3];
808
809         vuint32_t       hden;           /* 0x0040 */
810         uint32_t        r44;
811         vuint32_t       scictrl;
812         vuint32_t       rs485ctrl;
813
814         vuint32_t       rs485addrmatch; /* 0x0050 */
815         vuint32_t       rs485dly;
816         vuint32_t       syncctrl;
817 };
818
819 extern struct lpc_usart lpc_usart;
820 #define lpc_usart (*(struct lpc_usart *) 0x40008000)
821
822 #define LPC_USART_IER_RBRINTEN  0
823 #define LPC_USART_IER_THREINTEN 1
824 #define LPC_USART_IER_RSLINTEN  2
825 #define LPC_USART_IER_MSINTEN   3
826 #define LPC_USART_IER_ABEOINTEN 8
827 #define LPC_USART_IER_ABTOINTEN 9
828
829 #define LPC_USART_IIR_INTSTATUS         0
830 #define LPC_USART_IIR_INTID             1
831 #define LPC_USART_IIR_INTID_RLS                 3
832 #define LPC_USART_IIR_INTID_RDA                 2
833 #define LPC_USART_IIR_INTID_CTI                 6
834 #define LPC_USART_IIR_INTID_THRE                1
835 #define LPC_USART_IIR_INTID_MS                  0
836 #define LPC_USART_IIR_INTID_MASK                7UL
837 #define LPC_USART_IIR_FIFOEN            6
838 #define LPC_USART_IIR_ABEOINT           8
839 #define LPC_USART_IIR_ABTOINT           9
840
841 #define LPC_USART_FCR_FIFOEN            0
842 #define LPC_USART_FCR_RXFIFORES         1
843 #define LPC_USART_FCR_TXFIFORES         2
844 #define LPC_USART_FCR_RXTL              6
845 #define LPC_USART_FCR_RXTL_1                    0
846 #define LPC_USART_FCR_RXTL_4                    1
847 #define LPC_USART_FCR_RXTL_8                    2
848 #define LPC_USART_FCR_RXTL_14                   3
849
850 #define LPC_USART_LCR_WLS       0
851 #define LPC_USART_LCR_WLS_5             0
852 #define LPC_USART_LCR_WLS_6             1
853 #define LPC_USART_LCR_WLS_7             2
854 #define LPC_USART_LCR_WLS_8             3
855 #define LPC_USART_LCR_WLS_MASK          3UL
856 #define LPC_USART_LCR_SBS       2
857 #define LPC_USART_LCR_SBS_1             0
858 #define LPC_USART_LCR_SBS_2             1
859 #define LPC_USART_LCR_SBS_MASK          1UL
860 #define LPC_USART_LCR_PE        3
861 #define LPC_USART_LCR_PS        4
862 #define LPC_USART_LCR_PS_ODD            0
863 #define LPC_USART_LCR_PS_EVEN           1
864 #define LPC_USART_LCR_PS_ONE            2
865 #define LPC_USART_LCR_PS_ZERO           3
866 #define LPC_USART_LCR_PS_MASK           3UL
867 #define LPC_USART_LCR_BC        6
868 #define LPC_USART_LCR_DLAB      7
869
870 #define LPC_USART_MCR_DTRCTRL   0
871 #define LPC_USART_MCR_RTSCTRL   1
872 #define LPC_USART_MCR_LMS       4
873 #define LPC_USART_MCR_RTSEN     6
874 #define LPC_USART_MCR_CTSEN     7
875
876 #define LPC_USART_LSR_RDR       0
877 #define LPC_USART_LSR_OE        1
878 #define LPC_USART_LSR_PE        2
879 #define LPC_USART_LSR_FE        3
880 #define LPC_USART_LSR_BI        4
881 #define LPC_USART_LSR_THRE      5
882 #define LPC_USART_LSR_TEMT      6
883 #define LPC_USART_LSR_RXFE      7
884 #define LPC_USART_LSR_TXERR     8
885
886 #define LPC_USART_MSR_DCTS      0
887 #define LPC_USART_MSR_DDSR      1
888 #define LPC_USART_MSR_TERI      2
889 #define LPC_USART_MSR_DDCD      3
890 #define LPC_USART_MSR_CTS       4
891 #define LPC_USART_MSR_DSR       5
892 #define LPC_USART_MSR_RI        6
893 #define LPC_USART_MSR_DCD       7
894
895 #define LPC_USART_ACR_START     0
896 #define LPC_USART_ACR_MODE      1
897 #define LPC_USART_ACR_AUTORESTART       2
898 #define LPC_USART_ACR_ABEOINTCLR        8
899 #define LPC_USART_ACR_ABTOINTCLR        9
900
901 #define LPC_USART_FDR_DIVADDVAL 0
902 #define LPC_USART_FDR_MULVAL    4
903
904 #define LPC_USART_OSR_OSFRAC    1
905 #define LPC_USART_OSR_OSINT     4
906 #define LPC_USART_OSR_FDINT     8
907
908 #define LPC_USART_TER_TXEN      7
909
910 #define LPC_USART_HDEN_HDEN     0
911
912 struct lpc_usb {
913         vuint32_t       devcmdstat;
914         vuint32_t       info;
915         vuint32_t       epliststart;
916         vuint32_t       databufstart;
917         vuint32_t       lpm;
918         vuint32_t       epskip;
919         vuint32_t       epinuse;
920         vuint32_t       epbufcfg;
921         vuint32_t       intstat;
922         vuint32_t       inten;
923         vuint32_t       intsetstat;
924         vuint32_t       introuting;
925         uint32_t        r30;
926         vuint32_t       eptoggle;
927 };
928
929 extern struct lpc_usb lpc_usb;
930 #define lpc_usb (*(struct lpc_usb *) 0x40080000)
931
932 #define LPC_USB_DEVCMDSTAT_DEV_ADDR     0
933 #define LPC_USB_DEVCMDSTAT_DEV_ADDR_MASK        0x7fUL
934 #define LPC_USB_DEVCMDSTAT_DEV_EN       7
935 #define LPC_USB_DEVCMDSTAT_SETUP        8
936 #define LPC_USB_DEVCMDSTAT_PLL_ON       9
937 #define LPC_USB_DEVCMDSTAT_LPM_SUP      11
938 #define LPC_USB_DEVCMDSTAT_INTONNAK_AO  12
939 #define LPC_USB_DEVCMDSTAT_INTONNAK_AI  13
940 #define LPC_USB_DEVCMDSTAT_INTONNAK_CO  14
941 #define LPC_USB_DEVCMDSTAT_INTONNAK_CI  15
942 #define LPC_USB_DEVCMDSTAT_DCON         16
943 #define LPC_USB_DEVCMDSTAT_DSUS         17
944 #define LPC_USB_DEVCMDSTAT_LPM_SUS      19
945 #define LPC_USB_DEVCMDSTAT_LPM_REWP     20
946 #define LPC_USB_DEVCMDSTAT_DCON_C       24
947 #define LPC_USB_DEVCMDSTAT_DSUS_C       25
948 #define LPC_USB_DEVCMDSTAT_DRES_C       26
949 #define LPC_USB_DEVCMDSTAT_VBUSDEBOUNCED        28
950
951 #define LPC_USB_INFO_FRAME_NR           0
952 #define LPC_USB_INFO_FRAME_NR_MASK      0x3ffUL
953 #define LPC_USB_INFO_ERR_CODE           11
954 #define LPC_USB_INFO_ERR_CODE_NO_ERROR                  0
955 #define LPC_USB_INFO_ERR_CODE_PID_ENCODING_ERROR        1
956 #define LPC_USB_INFO_ERR_CODE_PID_UNKNOWN               2
957 #define LPC_USB_INFO_ERR_CODE_PACKET_UNEXPECTED         3
958 #define LPC_USB_INFO_ERR_CODE_TOKEN_CRC_ERROR           4
959 #define LPC_USB_INFO_ERR_CODE_DATA_CRC_ERROR            5
960 #define LPC_USB_INFO_ERR_CODE_TIME_OUT                  6
961 #define LPC_USB_INFO_ERR_CODE_BABBLE                    7
962 #define LPC_USB_INFO_ERR_CODE_TRUNCATED_EOP             8
963 #define LPC_USB_INFO_ERR_CODE_SENT_RECEIVED_NAK         9
964 #define LPC_USB_INFO_ERR_CODE_SENT_STALL                0xa
965 #define LPC_USB_INFO_ERR_CODE_OVERRUN                   0xb
966 #define LPC_USB_INFO_ERR_CODE_SENT_EMPTY_PACKET         0xc
967 #define LPC_USB_INFO_ERR_CODE_BITSTUFF_ERROR            0xd
968 #define LPC_USB_INFO_ERR_CODE_SYNC_ERROR                0xe
969 #define LPC_USB_INFO_ERR_CODE_WRONG_DATA_TOGGLE         0xf
970 #define LPC_USB_INFO_ERR_CODE_MASK                      0xfUL
971
972 #define LPC_USB_EPLISTSTART_EP_LIST                     0
973
974 #define LPC_USB_DATABUFSTART_DA_BUF                     0
975
976 #define LPC_USB_LPM_HIRD_HW             0
977 #define LPC_USB_LPM_HIRD_HW_MASK                0xfUL
978 #define LPC_USB_LPM_HIRD_SW             4
979 #define LPC_USB_LPM_HIRD_SW_MASK                0xfUL
980 #define LPC_USB_LPM_DATA_PENDING        8
981
982 #define LPC_USB_EPSKIP_SKIP             0
983
984 #define LPC_USB_EPINUSE_BUF(ep)         (ep)
985
986 #define LPC_USB_EPBUFCFG_BUF_SB(ep)     (ep)
987
988 #define LPC_USB_INT_EPOUT(ep)           ((ep) << 1)
989 #define LPC_USB_INT_EPIN(ep)            (((ep) << 1) + 1)
990
991 #define LPC_USB_INT_FRAME               30
992 #define LPC_USB_INT_DEV                 31
993
994 #define LPC_USB_INTIN_EP_INT_EN(ep)     (ep)
995 #define LPC_USB_INTIN_FRAME_INT_EN      30
996 #define LPC_USB_INTIN_DEV_INT_EN        31
997
998 #define LPC_USB_INTSETSTAT_EP_SET_INT(ep)       (ep)
999 #define LPC_USB_INTSETSTAT_FRAME_SET_INT        30
1000 #define LPC_USB_INTSETSTAT_DEV_SET_INT          31
1001
1002 #define LPC_USB_INTROUTING_ROUTE_INT(ep)        (ep)
1003 #define LPC_USB_INTROUTING_INT30                30
1004 #define LPC_USB_INTROUTING_INT31                31
1005
1006 #define LPC_USB_EPTOGGLE_TOGGLE(ep)             (ep)
1007
1008 struct lpc_usb_epn {
1009         vuint32_t               out[2];
1010         vuint32_t               in[2];
1011 };
1012
1013 struct lpc_usb_endpoint {
1014         vuint32_t               ep0_out;
1015         vuint32_t               setup;
1016         vuint32_t               ep0_in;
1017         vuint32_t               reserved_0c;
1018         struct lpc_usb_epn      epn[4];
1019 };
1020 #define lpc_usb_endpoint        (*(struct lpc_usb_endpoint *) 0x20004700)
1021
1022 /* Assigned in registers.ld to point at the base
1023  * of USB ram
1024  */
1025
1026 extern uint8_t lpc_usb_sram[];
1027 #define lpc_usb_sram            ((uint8_t*) 0x20004000)
1028
1029 #define LPC_USB_EP_ACTIVE               31
1030 #define LPC_USB_EP_DISABLED             30
1031 #define LPC_USB_EP_STALL                29
1032 #define LPC_USB_EP_TOGGLE_RESET         28
1033 #define LPC_USB_EP_RATE_FEEDBACK        27
1034 #define LPC_USB_EP_ENDPOINT_ISO         26
1035 #define LPC_USB_EP_NBYTES               16
1036 #define  LPC_USB_EP_NBYTES_MASK                 0x3ffUL
1037 #define LPC_USB_EP_OFFSET               0
1038
1039 #define LPC_ISR_PIN_INT0_POS    0
1040 #define LPC_ISR_PIN_INT1_POS    1
1041 #define LPC_ISR_PIN_INT2_POS    2
1042 #define LPC_ISR_PIN_INT3_POS    3
1043 #define LPC_ISR_PIN_INT4_POS    4
1044 #define LPC_ISR_PIN_INT5_POS    5
1045 #define LPC_ISR_PIN_INT6_POS    6
1046 #define LPC_ISR_PIN_INT7_POS    7
1047 #define LPC_ISR_GINT0_POS       8
1048 #define LPC_ISR_GINT1_POS       9
1049 #define LPC_ISR_SSP1_POS        14
1050 #define LPC_ISR_I2C_POS         15
1051 #define LPC_ISR_CT16B0_POS      16
1052 #define LPC_ISR_CT16B1_POS      17
1053 #define LPC_ISR_CT32B0_POS      18
1054 #define LPC_ISR_CT32B1_POS      19
1055 #define LPC_ISR_SSP0_POS        20
1056 #define LPC_ISR_USART_POS       21
1057 #define LPC_ISR_USB_IRQ_POS     22
1058 #define LPC_ISR_USB_FIQ_POS     23
1059 #define LPC_ISR_ADC_POS         24
1060 #define LPC_ISR_WWDT_POS        25
1061 #define LPC_ISR_BOD_POS         26
1062 #define LPC_ISR_FLASH_POS       27
1063 #define LPC_ISR_USB_WAKEUP_POS  30
1064
1065 struct lpc_nvic {
1066         vuint32_t       iser;           /* 0x000 0xe000e100 Set Enable Register */
1067
1068         uint8_t         _unused020[0x080 - 0x004];
1069
1070         vuint32_t       icer;           /* 0x080 0xe000e180 Clear Enable Register */
1071
1072         uint8_t         _unused0a0[0x100 - 0x084];
1073
1074         vuint32_t       ispr;           /* 0x100 0xe000e200 Set Pending Register */
1075
1076         uint8_t         _unused120[0x180 - 0x104];
1077
1078         vuint32_t       icpr;           /* 0x180 0xe000e280 Clear Pending Register */
1079
1080         uint8_t         _unused1a0[0x300 - 0x184];
1081
1082         vuint32_t       ipr[8];         /* 0x300 0xe000e400 Priority Register */
1083 };
1084
1085 extern struct lpc_nvic lpc_nvic;
1086 #define lpc_nvic (*(struct lpc_nvic *) 0xe000e100)
1087
1088 static inline void
1089 lpc_nvic_set_enable(int irq) {
1090         lpc_nvic.iser = (1 << irq);
1091 }
1092
1093 static inline void
1094 lpc_nvic_clear_enable(int irq) {
1095         lpc_nvic.icer = (1 << irq);
1096 }
1097
1098 static inline int
1099 lpc_nvic_enabled(int irq) {
1100         return (lpc_nvic.iser >> irq) & 1;
1101 }
1102
1103
1104 static inline void
1105 lpc_nvic_set_pending(int irq) {
1106         lpc_nvic.ispr = (1 << irq);
1107 }
1108
1109 static inline void
1110 lpc_nvic_clear_pending(int irq) {
1111         lpc_nvic.icpr = (1 << irq);
1112 }
1113
1114 static inline int
1115 lpc_nvic_pending(int irq) {
1116         return (lpc_nvic.ispr >> irq) & 1;
1117 }
1118
1119 #define IRQ_PRIO_REG(irq)       ((irq) >> 2)
1120 #define IRQ_PRIO_BIT(irq)       (((irq) & 3) << 3)
1121 #define IRQ_PRIO_MASK(irq)      (0xffUL << IRQ_PRIO_BIT(irq))
1122
1123 static inline void
1124 lpc_nvic_set_priority(int irq, uint8_t prio) {
1125         int             n = IRQ_PRIO_REG(irq);
1126         uint32_t        v;
1127
1128         v = lpc_nvic.ipr[n];
1129         v &= ~IRQ_PRIO_MASK(irq);
1130         v |= (prio) << IRQ_PRIO_BIT(irq);
1131         lpc_nvic.ipr[n] = v;
1132 }
1133
1134 static inline uint8_t
1135 lpc_nvic_get_priority(int irq) {
1136         return (lpc_nvic.ipr[IRQ_PRIO_REG(irq)] >> IRQ_PRIO_BIT(irq)) & IRQ_PRIO_MASK(0);
1137 }
1138
1139 struct arm_scb {
1140         vuint32_t       cpuid;
1141         vuint32_t       icsr;
1142         uint32_t        reserved08;
1143         vuint32_t       aircr;
1144
1145         vuint32_t       scr;
1146         vuint32_t       ccr;
1147         uint32_t        reserved18;
1148         vuint32_t       shpr2;
1149
1150         vuint32_t       shpr3;
1151 };
1152
1153 extern struct arm_scb arm_scb;
1154 #define arm_scb (*(struct arm_scb *) 0xe000ed00)
1155
1156 struct lpc_ssp {
1157         vuint32_t       cr0;    /* 0x00 */
1158         vuint32_t       cr1;
1159         vuint32_t       dr;
1160         vuint32_t       sr;
1161
1162         vuint32_t       cpsr;   /* 0x10 */
1163         vuint32_t       imsc;
1164         vuint32_t       ris;
1165         vuint32_t       mis;
1166
1167         vuint32_t       icr;    /* 0x20 */
1168 };
1169
1170 extern struct lpc_ssp lpc_ssp0, lpc_ssp1;
1171 #define lpc_ssp0 (*(struct lpc_ssp *) 0x40040000)
1172 #define lpc_ssp1 (*(struct lpc_ssp *) 0x40058000)
1173
1174 #define LPC_NUM_SPI             2
1175
1176 #define LPC_SSP_FIFOSIZE        8
1177
1178 #define LPC_SSP_CR0_DSS         0
1179 #define  LPC_SSP_CR0_DSS_4              0x3
1180 #define  LPC_SSP_CR0_DSS_5              0x4
1181 #define  LPC_SSP_CR0_DSS_6              0x5
1182 #define  LPC_SSP_CR0_DSS_7              0x6
1183 #define  LPC_SSP_CR0_DSS_8              0x7
1184 #define  LPC_SSP_CR0_DSS_9              0x8
1185 #define  LPC_SSP_CR0_DSS_10             0x9
1186 #define  LPC_SSP_CR0_DSS_11             0xa
1187 #define  LPC_SSP_CR0_DSS_12             0xb
1188 #define  LPC_SSP_CR0_DSS_13             0xc
1189 #define  LPC_SSP_CR0_DSS_14             0xd
1190 #define  LPC_SSP_CR0_DSS_15             0xe
1191 #define  LPC_SSP_CR0_DSS_16             0xf
1192 #define LPC_SSP_CR0_FRF         4
1193 #define  LPC_SSP_CR0_FRF_SPI            0
1194 #define  LPC_SSP_CR0_FRF_TI             1
1195 #define  LPC_SSP_CR0_FRF_MICROWIRE      2
1196 #define LPC_SSP_CR0_CPOL        6
1197 #define  LPC_SSP_CR0_CPOL_LOW           0
1198 #define  LPC_SSP_CR0_CPOL_HIGH          1
1199 #define LPC_SSP_CR0_CPHA        7
1200 #define  LPC_SSP_CR0_CPHA_FIRST         0
1201 #define  LPC_SSP_CR0_CPHA_SECOND        1
1202 #define LPC_SSP_CR0_SCR         8
1203
1204 #define LPC_SSP_CR1_LBM         0
1205 #define LPC_SSP_CR1_SSE         1
1206 #define LPC_SSP_CR1_MS          2
1207 #define  LPC_SSP_CR1_MS_MASTER          0
1208 #define  LPC_SSP_CR1_MS_SLAVE           1
1209 #define LPC_SSP_CR1_SOD         3
1210
1211 #define LPC_SSP_SR_TFE          0
1212 #define LPC_SSP_SR_TNF          1
1213 #define LPC_SSP_SR_RNE          2
1214 #define LPC_SSP_SR_RFF          3
1215 #define LPC_SSP_SR_BSY          4
1216
1217 #define LPC_SSP_IMSC_RORIM      0
1218 #define LPC_SSP_IMSC_RTIM       1
1219 #define LPC_SSP_IMSC_RXIM       2
1220 #define LPC_SSP_IMSC_TXIM       3
1221
1222 #define LPC_SSP_RIS_RORRIS      0
1223 #define LPC_SSP_RIS_RTRIS       1
1224 #define LPC_SSP_RIS_RXRIS       2
1225 #define LPC_SSP_RIS_TXRIS       3
1226
1227 #define LPC_SSP_MIS_RORMIS      0
1228 #define LPC_SSP_MIS_RTMIS       1
1229 #define LPC_SSP_MIS_RXMIS       2
1230 #define LPC_SSP_MIS_TXMIS       3
1231
1232 #define LPC_SSP_ICR_RORIC       0
1233 #define LPC_SSP_ICR_RTIC        1
1234
1235 struct lpc_adc {
1236         vuint32_t       cr;     /* 0x00 */
1237         vuint32_t       gdr;
1238         uint32_t        r08;
1239         vuint32_t       inten;
1240
1241         vuint32_t       dr[8];  /* 0x10 */
1242
1243         vuint32_t       stat;   /* 0x30 */
1244 };
1245
1246 extern struct lpc_adc lpc_adc;
1247 #define lpc_adc (*(struct lpc_adc *) 0x4001c000)
1248
1249 #define LPC_ADC_CR_SEL          0
1250 #define LPC_ADC_CR_CLKDIV       8
1251 #define LPC_ADC_CR_BURST        16
1252 #define LPC_ADC_CR_CLKS         17
1253 #define  LPC_ADC_CR_CLKS_11             0
1254 #define  LPC_ADC_CR_CLKS_10             1
1255 #define  LPC_ADC_CR_CLKS_9              2
1256 #define  LPC_ADC_CR_CLKS_8              3
1257 #define  LPC_ADC_CR_CLKS_7              4
1258 #define  LPC_ADC_CR_CLKS_6              5
1259 #define  LPC_ADC_CR_CLKS_5              6
1260 #define  LPC_ADC_CR_CLKS_4              7
1261 #define LPC_ADC_CR_START        24
1262 #define  LPC_ADC_CR_START_NONE          0
1263 #define  LPC_ADC_CR_START_NOW           1
1264
1265 #define LPC_ADC_GDR_CHN                 24
1266 #define LPC_ADC_GDR_OVERRUN             30
1267 #define LPC_ADC_GDR_DONE                31
1268
1269 #define LPC_ADC_INTEN_ADINTEN   0
1270 #define LPC_ADC_INTEN_ADGINTEN  8
1271
1272 #define LPC_ADC_STAT_DONE       0
1273 #define LPC_ADC_STAT_OVERRUN    8
1274 #define LPC_ADC_STAT_ADINT      16
1275
1276 struct lpc_ct16b {
1277         vuint32_t       ir;     /* 0x00 */
1278         vuint32_t       tcr;
1279         vuint32_t       tc;
1280         vuint32_t       pr;
1281
1282         vuint32_t       pc;     /* 0x10 */
1283         vuint32_t       mcr;
1284         vuint32_t       mr[4];  /* 0x18 */
1285         vuint32_t       ccr;    /* 0x28 */
1286         vuint32_t       cr0;
1287
1288         vuint32_t       cr1_0;  /* 0x30 (only for ct16b0 */
1289         vuint32_t       cr1_1;  /* 0x34 (only for ct16b1 */
1290         uint32_t        r38;
1291         vuint32_t       emr;
1292
1293         uint8_t         r40[0x70 - 0x40];
1294
1295         vuint32_t       ctcr;   /* 0x70 */
1296         vuint32_t       pwmc;
1297 };
1298
1299 extern struct lpc_ct16b lpc_ct16b0, lpc_ct16b1;
1300 #define lpc_ct16b0      (*(struct lpc_ct16b *) 0x4000c000)
1301 #define lpc_ct16b1      (*(struct lpc_ct16b *) 0x40010000)
1302
1303 #define LPC_CT16B_IR_MR0INT     0
1304 #define LPC_CT16B_IR_MR1INT     1
1305 #define LPC_CT16B_IR_MR2INT     2
1306 #define LPC_CT16B_IR_MR3INT     3
1307 #define LPC_CT16B_IR_CR0INT     4
1308 #define LPC_CT16B0_IR_CR1INT    6
1309 #define LPC_CT16B1_IR_CR1INT    5
1310
1311 #define LPC_CT16B_TCR_CEN       0
1312 #define LPC_CT16B_TCR_CRST      1
1313
1314 #define LPC_CT16B_MCR_MR0I      0
1315 #define LPC_CT16B_MCR_MR0R      1
1316 #define LPC_CT16B_MCR_MR0S      2
1317 #define LPC_CT16B_MCR_MR1I      3
1318 #define LPC_CT16B_MCR_MR1R      4
1319 #define LPC_CT16B_MCR_MR1S      5
1320 #define LPC_CT16B_MCR_MR2I      6
1321 #define LPC_CT16B_MCR_MR2R      7
1322 #define LPC_CT16B_MCR_MR2S      8
1323 #define LPC_CT16B_MCR_MR3I      9
1324 #define LPC_CT16B_MCR_MR3R      10
1325 #define LPC_CT16B_MCR_MR3S      11
1326
1327 #define LPC_CT16B_CCR_CAP0RE    0
1328 #define LPC_CT16B_CCR_CAP0FE    1
1329 #define LPC_CT16B_CCR_CAP0I     2
1330 #define LPC_CT16B0_CCR_CAP1RE   6
1331 #define LPC_CT16B0_CCR_CAP1FE   7
1332 #define LPC_CT16B0_CCR_CAP1I    8
1333 #define LPC_CT16B1_CCR_CAP1RE   3
1334 #define LPC_CT16B1_CCR_CAP1FE   4
1335 #define LPC_CT16B1_CCR_CAP1I    5
1336
1337 #define LPC_CT16B_EMR_EM0       0
1338 #define LPC_CT16B_EMR_EM1       1
1339 #define LPC_CT16B_EMR_EM2       2
1340 #define LPC_CT16B_EMR_EM3       3
1341 #define LPC_CT16B_EMR_EMC0      4
1342 #define LPC_CT16B_EMR_EMC1      6
1343 #define LPC_CT16B_EMR_EMC2      8
1344 #define LPC_CT16B_EMR_EMC3      10
1345
1346 #define LPC_CT16B_EMR_EMC_NOTHING       0
1347 #define LPC_CT16B_EMR_EMC_CLEAR         1
1348 #define LPC_CT16B_EMR_EMC_SET           2
1349 #define LPC_CT16B_EMR_EMC_TOGGLE        3
1350
1351 #define LPC_CT16B_CCR_CTM       0
1352 #define  LPC_CT16B_CCR_CTM_TIMER                0
1353 #define  LPC_CT16B_CCR_CTM_COUNTER_RISING       1
1354 #define  LPC_CT16B_CCR_CTM_COUNTER_FALLING      2
1355 #define  LPC_CT16B_CCR_CTM_COUNTER_BOTH         3
1356 #define LPC_CT16B_CCR_CIS       2
1357 #define  LPC_CT16B_CCR_CIS_CAP0                 0
1358 #define  LPC_CT16B0_CCR_CIS_CAP1                2
1359 #define  LPC_CT16B1_CCR_CIS_CAP1                1
1360 #define LPC_CT16B_CCR_ENCC      4
1361 #define LPC_CT16B_CCR_SELCC     5
1362 #define  LPC_CT16B_CCR_SELCC_RISING_CAP0        0
1363 #define  LPC_CT16B_CCR_SELCC_FALLING_CAP0       1
1364 #define  LPC_CT16B0_CCR_SELCC_RISING_CAP1       4
1365 #define  LPC_CT16B0_CCR_SELCC_FALLING_CAP1      5
1366 #define  LPC_CT16B1_CCR_SELCC_RISING_CAP1       2
1367 #define  LPC_CT16B1_CCR_SELCC_FALLING_CAP1      3
1368 #define LPC_CT16B_CCR_
1369
1370 #define LPC_CT16B_PWMC_PWMEN0   0
1371 #define LPC_CT16B_PWMC_PWMEN1   1
1372 #define LPC_CT16B_PWMC_PWMEN2   2
1373 #define LPC_CT16B_PWMC_PWMEN3   3
1374
1375 struct lpc_ct32b {
1376         vuint32_t       ir;     /* 0x00 */
1377         vuint32_t       tcr;
1378         vuint32_t       tc;
1379         vuint32_t       pr;
1380
1381         vuint32_t       pc;     /* 0x10 */
1382         vuint32_t       mcr;
1383         vuint32_t       mr[4];  /* 0x18 */
1384         vuint32_t       ccr;    /* 0x28 */
1385         vuint32_t       cr0;
1386
1387         vuint32_t       cr1_0;  /* 0x30 (only for ct32b0 */
1388         vuint32_t       cr1_1;  /* 0x34 (only for ct32b1 */
1389         uint32_t        r38;
1390         vuint32_t       emr;
1391
1392         uint32_t        r40[12];
1393
1394         vuint32_t       ctcr;   /* 0x70 */
1395         vuint32_t       pwmc;
1396 };
1397
1398 extern struct lpc_ct32b lpc_ct32b0, lpc_ct32b1;
1399 #define lpc_ct32b0 (*(struct lpc_ct32b *) 0x40014000)
1400 #define lpc_ct32b1 (*(struct lpc_ct32b *) 0x40018000)
1401
1402 #define LPC_CT32B_TCR_CEN       0
1403 #define LPC_CT32B_TCR_CRST      1
1404
1405 #define LPC_CT32B_MCR_MR0R      1
1406
1407 #define LPC_CT32B_PWMC_PWMEN0   0
1408 #define LPC_CT32B_PWMC_PWMEN1   1
1409 #define LPC_CT32B_PWMC_PWMEN2   2
1410 #define LPC_CT32B_PWMC_PWMEN3   3
1411
1412 #define LPC_CT32B_EMR_EMC0      4
1413 #define LPC_CT32B_EMR_EMC1      6
1414 #define LPC_CT32B_EMR_EMC2      8
1415 #define LPC_CT32B_EMR_EMC3      10
1416
1417 #define LPC_CT32B_EMR_EMC_NOTHING       0
1418 #define LPC_CT32B_EMR_EMC_CLEAR         1
1419 #define LPC_CT32B_EMR_EMC_SET           2
1420 #define LPC_CT32B_EMR_EMC_TOGGLE        3
1421
1422 #define isr_decl(name) \
1423         void lpc_ ## name ## _isr(void)
1424
1425 isr_decl(halt);
1426 isr_decl(ignore);
1427
1428 isr_decl(nmi);
1429 isr_decl(hardfault);
1430 isr_decl(memmanage);
1431 isr_decl(busfault);
1432 isr_decl(usagefault);
1433 isr_decl(svc);
1434 isr_decl(debugmon);
1435 isr_decl(pendsv);
1436 isr_decl(systick);
1437
1438 isr_decl(pin_int0);     /* IRQ0 */
1439 isr_decl(pin_int1);
1440 isr_decl(pin_int2);
1441 isr_decl(pin_int3);
1442 isr_decl(pin_int4);     /* IRQ4 */
1443 isr_decl(pin_int5);
1444 isr_decl(pin_int6);
1445 isr_decl(pin_int7);
1446
1447 isr_decl(gint0);        /* IRQ8 */
1448 isr_decl(gint1);
1449 isr_decl(ssp1);
1450 isr_decl(i2c);
1451
1452 isr_decl(ct16b0);       /* IRQ16 */
1453 isr_decl(ct16b1);
1454 isr_decl(ct32b0);
1455 isr_decl(ct32b1);
1456 isr_decl(ssp0); /* IRQ20 */
1457 isr_decl(usart);
1458 isr_decl(usb_irq);
1459 isr_decl(usb_fiq);
1460
1461 isr_decl(adc);  /* IRQ24 */
1462 isr_decl(wwdt);
1463 isr_decl(bod);
1464 isr_decl(flash);
1465
1466 isr_decl(usb_wakeup);
1467
1468 #endif /* _LPC_H_ */