1 /*
2  * Copyright (c) 2012 Ian McKellar
3  * Copyright (c) 2013 Travis Geiselbrecht
4  *
5  * Use of this source code is governed by a MIT-style
6  * license that can be found in the LICENSE file or at
7  * https://opensource.org/licenses/MIT
8  */
9 
10 #include <lk/err.h>
11 #include <stdio.h>
12 #include <lk/debug.h>
13 #include <platform.h>
14 #include <dev/usb.h>
15 #include <arch/arm/cm.h>
16 
17 #include "ti_driverlib.h"
18 
19 
20 void stellaris_debug_early_init(void);
21 void stellaris_debug_init(void);
22 
23 void stellaris_gpio_early_init(void);
24 void stellaris_gpio_init(void);
25 
26 void stellaris_usbc_early_init(void);
27 void stellaris_usbc_init(void);
28 
platform_early_init(void)29 void platform_early_init(void) {
30     //
31     // Enable lazy stacking for interrupt handlers.  This allows floating-point
32     // instructions to be used within interrupt handlers, but at the expense of
33     // extra stack usage.
34     //
35 //  FPULazyStackingEnable();
36 
37     //
38     // Set the clocking to run directly from the crystal.
39     //
40 
41     ulong config = SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN;
42 #if !defined(CRYSTAL_FREQ) || CRYSTAL_FREQ == 16000000
43     config |= SYSCTL_XTAL_16MHZ;
44 #elif CRYSTAL_FREQ == 8000000
45     config |= SYSCTL_XTAL_8MHZ;
46 #else
47 #error add more cases for additional frequencies
48 #endif
49 
50     SysCtlClockSet(config);
51 
52     // start the generic systick timer
53     arm_cm_systick_init(SysCtlClockGet());
54 
55     stellaris_gpio_early_init();
56 
57     stellaris_debug_early_init();
58 
59     stellaris_usbc_early_init();
60 }
61 
platform_init(void)62 void platform_init(void) {
63     stellaris_gpio_init();
64     stellaris_debug_init();
65     stellaris_usbc_init();
66 
67     // print device information
68     printf("raw revision registers: 0x%lx 0x%lx\n", HWREG(SYSCTL_DID0), HWREG(SYSCTL_DID1));
69 
70     printf("stellaris device class: ");
71     if (CLASS_IS_SANDSTORM) printf("sandstorm");
72     if (CLASS_IS_FURY) printf("fury");
73     if (CLASS_IS_DUSTDEVIL) printf("dustdevil");
74     if (CLASS_IS_TEMPEST) printf("tempst");
75     if (CLASS_IS_FIRESTORM) printf("firestorm");
76     if (CLASS_IS_BLIZZARD) printf("blizzard");
77     printf("\n");
78 
79     printf("revision register: ");
80     uint rev = (HWREG(SYSCTL_DID0) & SYSCTL_DID0_MAJ_M) >> 8;
81     printf("%c", rev + 'A');
82     printf("%ld", HWREG(SYSCTL_DID0) & (SYSCTL_DID0_MIN_M));
83     printf("\n");
84 
85 }
86