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