diff options
author | 3gg <3gg@shellblade.net> | 2025-02-08 17:50:57 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-02-08 17:50:57 -0800 |
commit | 1b5d7cd40eb1c1f55deedf34d3d6324498b5f000 (patch) | |
tree | a0bc21168f8270ee5fcb139498131dff884a7450 /src/raspi.c | |
parent | 0e1595330211351823e68691fca013bb47772aeb (diff) |
Hello world.
Diffstat (limited to 'src/raspi.c')
-rw-r--r-- | src/raspi.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/raspi.c b/src/raspi.c new file mode 100644 index 0000000..bc76f89 --- /dev/null +++ b/src/raspi.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <raspi.h> | ||
2 | |||
3 | #include <stdint.h> | ||
4 | |||
5 | int raspi_init() { | ||
6 | int raspi; | ||
7 | uint32_t reg; | ||
8 | |||
9 | // Read the system register. | ||
10 | #if __aarch64__ | ||
11 | asm volatile ("mrs %x0, midr_el1" : "=r" (reg)); | ||
12 | #else | ||
13 | asm volatile ("mrc p15,0,%0,c0,c0,0" : "=r" (reg)); | ||
14 | #endif | ||
15 | |||
16 | // Get the PartNum and detect the board. | ||
17 | switch ((reg >> 4) & 0xFFF) { | ||
18 | case 0xB76: raspi = 1; break; | ||
19 | case 0xC07: raspi = 2; break; | ||
20 | case 0xD03: raspi = 3; break; | ||
21 | case 0xD08: raspi = 4; break; | ||
22 | default: raspi = 0; break; | ||
23 | } | ||
24 | |||
25 | return raspi; | ||
26 | } | ||
27 | |||