1 /*
2  * Copyright (c) 2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 
9 #include <lk/err.h>
10 #include <stdio.h>
11 #include <lk/debug.h>
12 #include <platform.h>
13 #include <platform/lpc.h>
14 #include <arch/arm/cm.h>
15 
16 void lpc_debug_early_init(void);
17 void lpc_debug_init(void);
18 
19 void lpc_gpio_early_init(void);
20 void lpc_gpio_init(void);
21 
22 void lpc_usbc_early_init(void);
23 void lpc_usbc_init(void);
24 
platform_early_init(void)25 void platform_early_init(void) {
26     /* set up clocking for a board with an external oscillator */
27     Chip_SetupXtalClocking();
28 
29     /* Set USB PLL input to main oscillator */
30     Chip_Clock_SetUSBPLLSource(SYSCTL_PLLCLKSRC_MAINOSC);
31     /* Setup USB PLL  (FCLKIN = 12MHz) * 4 = 48MHz
32        MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
33        FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
34        FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
35     Chip_Clock_SetupUSBPLL(3, 1);
36 
37     /* Powerup USB PLL */
38     Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPLL_PD);
39 
40     /* Wait for PLL to lock */
41     while (!Chip_Clock_IsUSBPLLLocked()) {}
42 
43     /* Set default system tick divder to 1 */
44     Chip_Clock_SetSysTickClockDiv(1);
45 
46     /* start the generic systick driver */
47     arm_cm_systick_init(Chip_Clock_GetMainClockRate());
48 
49     lpc_debug_early_init();
50 }
51 
platform_init(void)52 void platform_init(void) {
53     lpc_debug_init();
54 }
55 
56 // vim: set ts=4 sw=4 expandtab:
57