summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/boot-x1000.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/boot-x1000.h')
-rw-r--r--firmware/target/mips/ingenic_x1000/boot-x1000.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/boot-x1000.h b/firmware/target/mips/ingenic_x1000/boot-x1000.h
new file mode 100644
index 0000000000..400eb93dc1
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/boot-x1000.h
@@ -0,0 +1,91 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __BOOT_X1000_H__
23#define __BOOT_X1000_H__
24
25#include "x1000/cpm.h"
26#include <stdbool.h>
27
28enum {
29 BOOT_OPTION_ROCKBOX = 0,
30 BOOT_OPTION_OFW_PLAYER,
31 BOOT_OPTION_OFW_RECOVERY,
32};
33
34enum {
35 /* 3 bits to store the boot option selected by the SPL */
36 BOOT_OPTION_MASK = 0x7,
37 BOOT_OPTION_SHIFT = 0,
38
39 /* Set after running clk_init() and setting up system clocks */
40 BOOT_FLAG_CLK_INIT = (1 << 31),
41
42 /* Set by the SPL if it was loaded over USB boot */
43 BOOT_FLAG_USB_BOOT = (1 << 30),
44};
45
46/* Note: these functions are inlined to minimize SPL code size.
47 * They are private to the X1000 early boot code anyway... */
48
49static inline void cpm_scratch_set(uint32_t value)
50{
51 /* TODO: see if this holds its state over a WDT reset */
52 REG_CPM_SCRATCH_PROT = 0x5a5a;
53 REG_CPM_SCRATCH = value;
54 REG_CPM_SCRATCH_PROT = 0xa5a5;
55}
56
57static inline void init_boot_flags(void)
58{
59 cpm_scratch_set(0);
60}
61
62static inline bool get_boot_flag(uint32_t bit)
63{
64 return (REG_CPM_SCRATCH & bit) != 0;
65}
66
67static inline void set_boot_flag(uint32_t bit)
68{
69 cpm_scratch_set(REG_CPM_SCRATCH | bit);
70}
71
72static inline void clr_boot_flag(uint32_t bit)
73{
74 cpm_scratch_set(REG_CPM_SCRATCH & ~bit);
75}
76
77static inline void set_boot_option(int opt)
78{
79 uint32_t r = REG_CPM_SCRATCH;
80 r &= ~(BOOT_OPTION_MASK << BOOT_OPTION_SHIFT);
81 r |= (opt & BOOT_OPTION_MASK) << BOOT_OPTION_SHIFT;
82 cpm_scratch_set(r);
83}
84
85static inline int get_boot_option(void)
86{
87 uint32_t r = REG_CPM_SCRATCH;
88 return (r >> BOOT_OPTION_SHIFT) & BOOT_OPTION_MASK;
89}
90
91#endif /* __BOOT_X1000_H__ */