blob: 31f212b47c48696398d9342ed37a3652263f2e24 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2014 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#include <err.h>
25#include <stdio.h>
26#include <debug.h>
27#include <platform.h>
28#include <platform/lpc.h>
29#include <arch/arm/cm.h>
30
31void lpc_debug_early_init(void);
32void lpc_debug_init(void);
33
34void lpc_gpio_early_init(void);
35void lpc_gpio_init(void);
36
37void lpc_usbc_early_init(void);
38void lpc_usbc_init(void);
39
40void platform_early_init(void)
41{
42 /* set up clocking for a board with an external oscillator */
43 Chip_SetupXtalClocking();
44
45 /* Set USB PLL input to main oscillator */
46 Chip_Clock_SetUSBPLLSource(SYSCTL_PLLCLKSRC_MAINOSC);
47 /* Setup USB PLL (FCLKIN = 12MHz) * 4 = 48MHz
48 MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
49 FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
50 FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
51 Chip_Clock_SetupUSBPLL(3, 1);
52
53 /* Powerup USB PLL */
54 Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPLL_PD);
55
56 /* Wait for PLL to lock */
57 while (!Chip_Clock_IsUSBPLLLocked()) {}
58
59 /* Set default system tick divder to 1 */
60 Chip_Clock_SetSysTickClockDiv(1);
61
62 /* start the generic systick driver */
63 arm_cm_systick_init(Chip_Clock_GetMainClockRate());
64
65 lpc_debug_early_init();
66}
67
68void platform_init(void)
69{
70 lpc_debug_init();
71}
72
73// vim: set ts=4 sw=4 expandtab: