From 4a9dbdaeda77cc1bf4795f71b5263da4e1a4d8f6 Mon Sep 17 00:00:00 2001
From: hydrogenium2020
<107231979+hydrogenium2020-offical@users.noreply.github.com>
Date: Sun, 11 Feb 2024 14:51:13 +0800
Subject: [PATCH] Fix: Correct the copyright and avoid repeated inclusion of
header files.
---
loader/bootrom.h | 2 --
loader/gpio.c | 1 +
loader/gpio.h | 24 +++++++++++++++++++++++-
loader/i2c.c | 39 +++++++++++++++++++++++++++++++++++++++
loader/i2c.h | 19 ++-----------------
loader/main.c | 41 ++++++++++++++++++++++++++---------------
loader/pmc.h | 38 +++++++++++++++++++++++++++++++++++++-
loader/timer.h | 6 +++++-
loader/uart.c | 18 ++++++++++++++++++
loader/uart.h | 24 +++++++++++++++++++++++-
loader/usb.c | 1 -
loader/usb.h | 5 ++---
loader/util.c | 18 ++++++++++++++++++
loader/util.h | 35 ++++++++++++++++++++---------------
14 files changed, 214 insertions(+), 57 deletions(-)
create mode 100644 loader/i2c.c
diff --git a/loader/bootrom.h b/loader/bootrom.h
index 0ae055c..a3e8e00 100644
--- a/loader/bootrom.h
+++ b/loader/bootrom.h
@@ -20,6 +20,4 @@
#define BOOTROM_USB_WRITE_EP1 0x001065C0
#define BOOTROM_USB_READ_EP1 0x00106612
-
-
#endif
\ No newline at end of file
diff --git a/loader/gpio.c b/loader/gpio.c
index a3d0ac2..5a53ba9 100644
--- a/loader/gpio.c
+++ b/loader/gpio.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2024 hydrogenium2020-offical
* Copyright (c) 2018 naehrwert
+* Copyright (c) 2018-2022 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
diff --git a/loader/gpio.h b/loader/gpio.h
index 7a4beb6..f4f5f36 100644
--- a/loader/gpio.h
+++ b/loader/gpio.h
@@ -1 +1,23 @@
-void config_gpios();
\ No newline at end of file
+/*
+* Copyright (c) 2024 hydrogenium2020-offical
+* Copyright (c) 2018 naehrwert
+* Copyright (c) 2019-2023 CTCaer
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms and conditions of the GNU General Public License,
+* version 2, as published by the Free Software Foundation.
+*
+* This program is distributed in the hope it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+* more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*/
+#ifndef _T124_GPIO_H_
+#define _T124_GPIO_H_
+
+void config_gpios();
+
+#endif
diff --git a/loader/i2c.c b/loader/i2c.c
new file mode 100644
index 0000000..16dbb21
--- /dev/null
+++ b/loader/i2c.c
@@ -0,0 +1,39 @@
+/*
+* Copyright (c) 2024 hydrogenium2020-offical
+* Copyright (c) 2018 naehrwert
+* Copyright (c) 2020 CTCaer
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms and conditions of the GNU General Public License,
+* version 2, as published by the Free Software Foundation.
+*
+* This program is distributed in the hope it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+* more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*/
+#include "types.h"
+#include "i2c.h"
+void i2c_init(u32 i2c_idx)
+{
+ vu32 *base = (vu32 *)(I2C_BASE + (u32)_i2c_base_offsets[i2c_idx]);
+
+ base[I2C_CLK_DIVISOR] = (5 << 16) | 1; // SF mode Div: 6, HS mode div: 2.
+ base[I2C_BUS_CLEAR_CONFIG] = (9 << 16) | BC_TERMINATE | BC_ENABLE;
+
+ // Load configuration.
+ _i2c_load_cfg_wait(base);
+
+ for (u32 i = 0; i < 10; i++)
+ {
+ if (base[I2C_INT_STATUS] & BUS_CLEAR_DONE)
+ break;
+ usleep(25);
+ }
+
+ (vu32)base[I2C_BUS_CLEAR_STATUS];
+ base[I2C_INT_STATUS] = base[I2C_INT_STATUS];
+}
\ No newline at end of file
diff --git a/loader/i2c.h b/loader/i2c.h
index 90ac430..440db7d 100755
--- a/loader/i2c.h
+++ b/loader/i2c.h
@@ -1,22 +1,7 @@
-/*
-* Copyright (c) 2018 naehrwert
-*
-* This program is free software; you can redistribute it and/or modify it
-* under the terms and conditions of the GNU General Public License,
-* version 2, as published by the Free Software Foundation.
-*
-* This program is distributed in the hope it will be useful, but WITHOUT
-* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-* more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see .
-*/
-
/*
* Copyright (c) 2024 hydrogenium2020-offical
* Copyright (c) 2018 naehrwert
+* Copyright (c) 2020 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -42,6 +27,6 @@
#define I2C_5 4
#define I2C_6 5
-void i2c_init(u32 idx);
+void i2c_init(u32 i2c_idx);
#endif
diff --git a/loader/main.c b/loader/main.c
index 52c30e7..e862388 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2024 hydrogenium2020-offical
* Copyright (c) 2018 naehrwert
+* Copyright (c) 2018-2023 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -17,9 +18,7 @@
#include "types.h"
#include "printf.h"
#include "string.h"
-
#include "t124.h"
-#include "se.h"
#include "usb.h"
#include "bootrom.h"
#include "fuse.h"
@@ -28,8 +27,9 @@
#include "util.h"
#include "pinmux.h"
#include "gpio.h"
-#include "i2c.h"
#include "uart.h"
+#include "sdram.h"
+#include "memory_map.h"
static inline u32 read32(uintptr_t addr) {
return *(vu32 *)addr;
@@ -76,36 +76,47 @@ void config_hw(){
// uart_init(UART_D, 115200, UART_AO_TX_AO_RX);
// uart_invert(UART_D, 0, UART_INVERT_TXD);
- uart_send(UART_D, (u8 *)"hekate: Hello!\r\n", 16);
- uart_wait_xfer(UART_D, UART_TX_IDLE);
+ //uart_send(UART_D, (u8 *)"hekate: Hello!\r\n", 16);
+ //uart_wait_xfer(UART_D, UART_TX_IDLE);
- mc_enable();
- printf_("[x] mc setup\n");
+ // mc_enable();
+ // printf_("[x] mc setup\n");
config_gpios();
printf_("[x] GPIO setup\n");
-
+
+ sdram_init();
+ printf_("[x] SDRAM setup\n");
+
}
extern void pivot_stack(u32 stack_top);
__attribute__((section(".init")))
void _start() {
// u8 *buffer = (u8*)0x40020000;
- printf_("gardenia is booting.");
+ printf_("gardenia is booting.\n");
//printf_("%p",&_start);
- //pivot_stack(0x200);
//Setting up hardware
dump_pkc();
config_hw();
- //FIXME!!!->init memory
- //Pivot the stack so we have enough space.
-// pivot_stack(0x40000000);
+ printf_("%d\n",MMIO_REG32(0x90010000,0));
+ MMIO_REG32(0x90010000,0)=0x123456;
+ printf_("%d\n",MMIO_REG32(0x90010000,0));
+ sleep(200);
+ printf_("%d\n",MMIO_REG32(0x90010000,0));
- //Tegra/Horizon configuration goes to 0x80000000+, package2 goes to 0xA9800000, we place our heap in between.
-// heap_init(0x90020000);
+ u32 total_size = (MC(MC_EMEM_CFG) >>
+ MC_EMEM_CFG_SIZE_MB_SHIFT) & MC_EMEM_CFG_SIZE_MB_MASK;
+
+ printf_("Total SDRAM (MB): %u\n", total_size);
+ //Pivot the stack so we have enough space.
+ pivot_stack(IPL_STACK_TOP);
+ printf_("alive");
+
+ heap_init(IPL_HEAP_START);
enter_rcm();
}
diff --git a/loader/pmc.h b/loader/pmc.h
index 8493f3c..ac1e0bd 100644
--- a/loader/pmc.h
+++ b/loader/pmc.h
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2024 hydrogenium2020-offical
* Copyright (c) 2018 naehrwert
+* Copyright (c) 2020 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -14,9 +15,44 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+
+#ifndef _T124_PMC_H_
+#define _T124_PMC_H_
+
#include "types.h"
#define APBDEV_PMC_OSC_EDPD_OVER 0x1A4
+
+//SDRAM
+#define APBDEV_PMC_VDDP_SEL 0x1CC
+#define APBDEV_PMC_DDR_PWR 0xE8
+#define APBDEV_PMC_NO_IOPOWER 0x44
+#define APBDEV_PMC_REG_SHORT 0x2CC
+#define APBDEV_PMC_DDR_CFG 0x1D0
+#define APBDEV_PMC_POR_DPD_CTRL 0x264
+#define APBDEV_PMC_IO_DPD3_REQ 0x45c
enum {
PMC_XOFS_SHIFT = 1,
PMC_XOFS_MASK = 0x3f << PMC_XOFS_SHIFT
-};
\ No newline at end of file
+};
+
+enum {
+ PMC_POR_DPD_CTRL_MEM0_ADDR0_CLK_SEL_DPD_MASK = 1 << 0,
+ PMC_POR_DPD_CTRL_MEM0_ADDR1_CLK_SEL_DPD_MASK = 1 << 1,
+ PMC_POR_DPD_CTRL_MEM0_HOLD_CKE_LOW_OVR_MASK = 1 << 31,
+};
+enum {
+ PMC_DDR_CFG_PKG_MASK = 1 << 0,
+ PMC_DDR_CFG_IF_MASK = 1 << 1,
+ PMC_DDR_CFG_XM0_RESET_TRI_MASK = 1 << 12,
+ PMC_DDR_CFG_XM0_RESET_DPDIO_MASK = 1 << 13,
+};
+enum {
+ PMC_DDR_PWR_EMMC_MASK = 1 << 1,
+ PMC_DDR_PWR_VAL_MASK = 1 << 0,
+};
+enum {
+ PMC_NO_IOPOWER_MEM_MASK = 1 << 7,
+ PMC_NO_IOPOWER_MEM_COMP_MASK = 1 << 16,
+};
+
+#endif
\ No newline at end of file
diff --git a/loader/timer.h b/loader/timer.h
index 42c969c..72e979b 100644
--- a/loader/timer.h
+++ b/loader/timer.h
@@ -14,5 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+#ifndef _T124_TIMER_H_
+#define _T124_TIMER_H_
+
#define TIMERUS_CNTR_1US (0x10 + 0x0)
-#define TIMERUS_USEC_CFG (0x10 + 0x4)
\ No newline at end of file
+
+#endif
\ No newline at end of file
diff --git a/loader/uart.c b/loader/uart.c
index 0d72e0c..24a7596 100644
--- a/loader/uart.c
+++ b/loader/uart.c
@@ -1,3 +1,21 @@
+/*
+* Copyright (c) 2018 naehrwert
+* Copyright (c) 2019-2022 CTCaer
+* Copyright (c) 2024 hydrogenium2020-offical
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms and conditions of the GNU General Public License,
+* version 2, as published by the Free Software Foundation.
+*
+* This program is distributed in the hope it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+* more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*/
+
#include "uart.h"
#include "t124.h"
#include "util.h"
diff --git a/loader/uart.h b/loader/uart.h
index 4a2adf4..1a675f7 100644
--- a/loader/uart.h
+++ b/loader/uart.h
@@ -1,3 +1,23 @@
+/*
+* Copyright (c) 2018 naehrwert
+* Copyright (c) 2019-2020 CTCaer
+* Copyright (c) 2024 hydrogenium2020-offical
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms and conditions of the GNU General Public License,
+* version 2, as published by the Free Software Foundation.
+*
+* This program is distributed in the hope it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+* more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*/
+#ifndef _T124_UART_H_
+#define _T124_UART_H_
+
#include "types.h"
#define UART_A 0
#define UART_B 1
@@ -80,4 +100,6 @@ typedef struct _uart_t
void uart_wait_xfer(u32 idx, u32 which);
void uart_invert(u32 idx, u32 enable, u32 invert_mask);
void uart_init(u32 idx, u32 baud, u32 mode);
-void uart_send(u32 idx, const u8 *buf, u32 len);
\ No newline at end of file
+void uart_send(u32 idx, const u8 *buf, u32 len);
+
+#endif
diff --git a/loader/usb.c b/loader/usb.c
index 0544b8c..a99f4af 100644
--- a/loader/usb.c
+++ b/loader/usb.c
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2024 hydrogenium2020-offical
-* Copyright (c) 2018 naehrwert
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
diff --git a/loader/usb.h b/loader/usb.h
index 592f980..ca8dc45 100644
--- a/loader/usb.h
+++ b/loader/usb.h
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2024 hydrogenium2020-offical
-* Copyright (c) 2018 naehrwert
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -14,8 +13,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-#ifndef _T124_UTIL_H_
-#define _T124_UTIL_H_
+#ifndef _T124_USB_H_
+#define _T124_USB_H_
#include "types.h"
#define USB_MAX_TXFR_BYTES 0x1000
u32 _usb_log(char *msg);
diff --git a/loader/util.c b/loader/util.c
index 1405fc6..46fe34d 100644
--- a/loader/util.c
+++ b/loader/util.c
@@ -25,3 +25,21 @@ void sleep(u32 ticks)
while (TIMER0(TIMERUS_CNTR_1US) - start <= ticks)
;
}
+// static inline void setbits32(uint32_t bits, void *addr)
+// {
+// write32(addr, read32(addr) | bits);
+// }
+
+// static inline void clrbits32(uint32_t bits, void *addr)
+// {
+// write32(addr, read32(addr) & ~bits);
+// }
+
+
+// void clrsetbits32(addr, mask, set){
+// MMIO_REG32(addr,0)=MMIO_REG32(addr,0) &~(mask) | (value & mask);
+// }
+// static void writebits(uint32_t value, uint32_t *addr, uint32_t mask)
+// {
+// clrsetbits32(addr, mask, (value & mask));
+// }
diff --git a/loader/util.h b/loader/util.h
index d0d6930..ea1882e 100644
--- a/loader/util.h
+++ b/loader/util.h
@@ -1,18 +1,23 @@
/*
-* Copyright (c) 2024 hydrogenium2020-offical
-* Copyright (c) 2018 naehrwert
-*
-* This program is free software; you can redistribute it and/or modify it
-* under the terms and conditions of the GNU General Public License,
-* version 2, as published by the Free Software Foundation.
-*
-* This program is distributed in the hope it will be useful, but WITHOUT
-* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-* more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see .
-*/
+ * Copyright (c) 2024 hydrogenium2020-offical
+ * Copyright (c) 2019 CTCaer
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+#ifndef _T124_UTIL_H_
+#define _T124_UTIL_H_
+
#include "types.h"
void sleep(u32 ticks);
+
+#endif
\ No newline at end of file