diff --git a/Makefile b/Makefile index 3b5ee1d3..cdd3d9b5 100755 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ CUSTOMDEFINES += -DBL_VER_MJ=$(BLVERSION_MAJOR) -DBL_VER_MN=$(BLVERSION_MINOR) - CUSTOMDEFINES += -DNYX_VER_MJ=$(NYXVERSION_MAJOR) -DNYX_VER_MN=$(NYXVERSION_MINOR) -DNYX_VER_HF=$(NYXVERSION_HOTFX) -DNYX_VER_RL=$(NYXVERSION_REL) # BDK defines. -CUSTOMDEFINES += -DBDK_MALLOC_NO_DEFRAG -DBDK_MC_ENABLE_AHB_REDIRECT -DBDK_EMUMMC_ENABLE +CUSTOMDEFINES += -DBDK_MALLOC_NO_DEFRAG -DBDK_EMUMMC_ENABLE CUSTOMDEFINES += -DBDK_WATCHDOG_FIQ_ENABLE -DBDK_RESTART_BL_ON_WDT CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC) diff --git a/README.md b/README.md index de3314ee..82901169 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Custom Graphical Nintendo Switch bootloader, firmware patcher, tools, and many m ## Bootloader configuration -The bootloader can be configured via 'bootloader/hekate_ipl.ini' (if it is present on the SD card). Each ini section represents a boot entry, except for the special section 'config' that controls the global configuration. +The bootloader can be configured via `Nyx` -> `Options` or 'bootloader/hekate_ipl.ini'. The special section 'config' controls the actual global configuration. Any other ini section represents a boot entry and can only be edited manually via the ini. There are four possible type of entries. "**[ ]**": Boot entry, "**{ }**": Caption, "**#**": Comment, "*newline*": .ini cosmetic newline. @@ -75,22 +75,27 @@ There are four possible type of entries. "**[ ]**": Boot entry, "**{ }**": Capti **You can find a template [Here](./res/hekate_ipl_template.ini)** -### hekate Global Configuration keys/values (when entry is *[config]*): +### hekate Configuration keys/values (section *[config]*) + +Use `Options` in Nyx to edit the following configuration: | Config option | Description | | ------------------ | -------------------------------------------------------------- | | autoboot=0 | 0: Disable, #: Boot entry number to auto boot. | | autoboot_list=0 | 0: Read `autoboot` boot entry from hekate_ipl.ini, 1: Read from ini folder (ini files are ASCII ordered). | | bootwait=3 | 0: Disable (It also disables bootlogo. Having **VOL-** pressed since injection goes to menu.), #: Time to wait for **VOL-** to enter menu. Max: 20s. | -| noticker=0 | 0: Animated line is drawn during custom bootlogo, signifying time left to skip to menu. 1: Disable. | | autohosoff=1 | 0: Disable, 1: If woke up from HOS via an RTC alarm, shows logo, then powers off completely, 2: No logo, immediately powers off.| | autonogc=1 | 0: Disable, 1: Automatically applies nogc patch if unburnt fuses found and a >= 4.0.0 HOS is booted. | -| bootprotect=0 | 0: Disable, 1: Protect bootloader folder from being corrupted by disallowing reading or editing in HOS. | | updater2p=0 | 0: Disable, 1: Force updates (if needed) the reboot2payload binary to be hekate. | | backlight=100 | Screen backlight level. 0-255. | +| ------------------ | --------- *The following can be edited via ini only* --------- | +| noticker=0 | 0: Animated line is drawn during custom bootlogo, signifying time left to skip to menu. 1: Disable. | +| bootprotect=0 | 0: Disable, 1: Protect bootloader folder from being corrupted by disallowing reading or editing in HOS. | -### Boot entry key/value combinations: +### Boot entry key/value combinations + +A boot entry needs to be manually added/edited with the user's chosen key/value combos. | Config option | Description | | ---------------------- | ---------------------------------------------------------- | @@ -140,7 +145,9 @@ You can define `kip1` to load an extra kip or many via the wildcard (`/*`) usage That's in case the kips are incompatible between them. If compatible, you can override `pkg3`/`fss0` kips with no issues (useful for testing with intermediate kip changes). In such cases, the `kip1` line must be **after** `pkg3`/`fss0` line. -### Boot entry key/value combinations for Exosphère: +### Boot entry key/value combinations for Exosphère + +The following can be paired together with a HOS boot entry: | Config option | Description | | ---------------------- | ---------------------------------------------------------- | @@ -149,6 +156,7 @@ That's in case the kips are incompatible between them. If compatible, you can ov | cal0blank=1 | Overrides Exosphère config `blank_prodinfo_{sys/emu}mmc`. If that key doesn't exist, `exosphere.ini` will be used. | | cal0writesys=1 | Overrides Exosphère config `allow_writing_to_cal_sysmmc`. If that key doesn't exist, `exosphere.ini` will be used. | | usb3force=1 | Overrides system settings mitm config `usb30_force_enabled`. If that key doesn't exist, `system_settings.ini` will be used. | +| memmode=1 | Enables boot config memory mode for retail units. By default, max ram is limited to 4GB. Enabling this will automatically choose size. | **Note**: `cal0blank`, `cal0writesys`, `usb3force`, as stated override the `exosphere.ini` or `system_settings.ini`. 0: Disable, 1: Enable, Key Missing: Use original value. @@ -157,7 +165,7 @@ That's in case the kips are incompatible between them. If compatible, you can ov **Note2**: `blank_prodinfo_{sys/emu}mmc`, `allow_writing_to_cal_sysmmc` and `usb30_force_enabled` in `exosphere.ini` and `system_settings.ini` respectively, are the only atmosphere config keys that can affect hekate booting configuration externally, **if** the equivalent keys in hekate config are missing. -### Payload storage: +## Payload storage hekate has a boot storage in the binary that helps it configure it outside of BPMP environment: @@ -168,23 +176,25 @@ hekate has a boot storage in the binary that helps it configure it outside of BP | '0x96' autoboot_list | If `Force AutoBoot` and `autoboot` then it boots from ini folder. | | '0x97' extra_cfg | When menu is forced: bit5: `Run UMS`. | | '0x98' xt_str[128] | Depends on the set cfg bits. | -| '0x98' ums[1] | When `Run UMS` is set, it will launch the selected UMS. 0: SD, 1: eMMC BOOT0, 2: eMMC BOOT1, 3: eMMC GPP, 4: emuMMC BOOT0, 5: emuMMC BOOT1, 6: emuMMC GPP, | +| '0x98' ums[1] | When `Run UMS` is set, it will launch the selected UMS. 0: SD, 1/2/3: eMMC BOOT0/BOOT1/GPP, 4/5/6: emuMMC BOOT0/BOOT1/GPP, | | '0x98' id[8] | When `Boot from ID` is set, it will search all inis automatically and find the boot entry with that id and boot it. Must be NULL terminated. | | '0xA0' emummc_path[120] | When `Boot to emuMMC` is set, it will override the current emuMMC (boot entry or emummc.ini). Must be NULL terminated. | -### Nyx Configuration keys/values (nyx.ini): +## Nyx Configuration keys/values (nyx.ini) + +Use `Nyx Settings` in Nyx to edit the following configuration: | Config option | Description | | ------------------ | ---------------------------------------------------------- | -| themebg=2d2d2d | Sets Nyx background color in HEX. EXPERIMENTAL. | +| themebg=2d2d2d | Sets Nyx background color in HEX. 0x0B0B0B to 0xC7C7C7. | | themecolor=167 | Sets Nyx color of text highlights. | | entries5col=0 | 1: Sets Launch entry columns from 4 to 5 per line. For a total of 10 entries. | -| timeoffset=100 | Sets time offset in HEX. Must be in epoch format | -| timedst=0 | Enables automatic daylight saving hour adjustment | +| timeoffset=0 | Sets time offset in HEX. Must be in epoch format | +| timedst=1 | Enables automatic daylight saving hour adjustment | | homescreen=0 | Sets home screen. 0: Home menu, 1: All configs (merges Launch and More configs), 2: Launch, 3: More Configs. | | verification=1 | 0: Disable Backup/Restore verification, 1: Sparse (block based, fast and mostly reliable), 2: Full (sha256 based, slow and 100% reliable). | -| ------------------ | ------- The following options can only be edited in nyx.ini ------- | +| ------------------ | ----- *The following can be edited via nyx.ini only* ----- | | umsemmcrw=0 | 1: eMMC/emuMMC UMS will be mounted as writable by default. | | jcdisable=0 | 1: Disables Joycon driver completely. | | jcforceright=0 | 1: Forces right joycon to be used as main mouse control. | diff --git a/Versions.inc b/Versions.inc index adaeefd1..b2e18dd1 100644 --- a/Versions.inc +++ b/Versions.inc @@ -1,11 +1,11 @@ # IPL Version. BLVERSION_MAJOR := 6 BLVERSION_MINOR := 5 -BLVERSION_HOTFX := 1 +BLVERSION_HOTFX := 2 BLVERSION_REL := 0 # Nyx Version. NYXVERSION_MAJOR := 1 NYXVERSION_MINOR := 9 -NYXVERSION_HOTFX := 1 +NYXVERSION_HOTFX := 2 NYXVERSION_REL := 0 diff --git a/bdk/display/di.c b/bdk/display/di.c index 57f96061..3c8548c3 100644 --- a/bdk/display/di.c +++ b/bdk/display/di.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/bdk/display/vic.c b/bdk/display/vic.c index 10444489..5cd4f1ff 100644 --- a/bdk/display/vic.c +++ b/bdk/display/vic.c @@ -1,5 +1,5 @@ /* - * VIC driver for Tegra X1 + * VIC (4.0) driver for Tegra X1 * * Copyright (c) 2018-2024 CTCaer * @@ -45,9 +45,10 @@ #define VIC_FC_CFG_STRUCT_SLOT_CFG2 0x10B0C #define CACHE_WIDTH(n) ((n) << 16) #define CACHE_WIDTH_16BX16 0 // Block Linear. -#define CACHE_WIDTH_32BX8 1 // Block Linear. Recommended for Block Linear. -#define CACHE_WIDTH_64BX4 2 // Block Linear, Pitch. Recommended for Pitch. +#define CACHE_WIDTH_32BX8 1 // Block Linear. +#define CACHE_WIDTH_64BX4 2 // Block Linear, Pitch. Recommended. #define CACHE_WIDTH_128BX2 3 // Block Linear, Pitch. +#define CACHE_WIDTH_256BX1 4 // Pitch. #define OUTPUT_FLIP_X BIT(20) #define OUTPUT_FLIP_Y BIT(21) #define OUTPUT_TRANSPOSE BIT(22) @@ -374,7 +375,7 @@ static void _vic_write_priv(u32 addr, u32 data) VIC(PVIC_FALCON_ADDR) = 0; } -static int _vic_wait_idle() +int vic_wait_idle() { u32 timeout_count = 15000; // 150ms. @@ -384,7 +385,7 @@ static int _vic_wait_idle() timeout_count--; if (!timeout_count) - return -1; + return 1; }; return 0; @@ -508,7 +509,7 @@ void vic_set_surface(const vic_surface_t *sfc) _vic_write_priv(VIC_SC_PRAMSIZE, sizeof(vic_config_t) >> 6); // Wait for surface cache to get ready. - _vic_wait_idle(); + vic_wait_idle(); // Set slot mapping. _vic_write_priv(VIC_FC_SLOT_MAP, 0xFFFFFFF0); @@ -523,13 +524,13 @@ void vic_set_surface(const vic_surface_t *sfc) _vic_write_priv(VIC_BL_CONFIG, SLOTMASK(0x1F) | PROCESS_CFG_STRUCT_TRIGGER | SUBPARTITION_MODE); // Wait for surface cache to get ready. - _vic_wait_idle(); + vic_wait_idle(); } int vic_compose() { // Wait for surface cache to get ready. Otherwise VIC will hang. - int res = _vic_wait_idle(); + int res = vic_wait_idle(); // Start composition of a single frame. _vic_write_priv(VIC_FC_COMPOSE, COMPOSE_START); @@ -551,7 +552,7 @@ int vic_init() // Start Fetch Control Engine. _vic_write_priv(VIC_FC_FCE_CTRL, START_TRIGGER); - return _vic_wait_idle(); + return vic_wait_idle(); } void vic_end() diff --git a/bdk/display/vic.h b/bdk/display/vic.h index 20fbe6c4..23de6311 100644 --- a/bdk/display/vic.h +++ b/bdk/display/vic.h @@ -59,6 +59,7 @@ typedef struct _vic_surface_t } vic_surface_t; void vic_set_surface(const vic_surface_t *sfc); +int vic_wait_idle(); int vic_compose(); int vic_init(); void vic_end(); diff --git a/bdk/exception_handlers.S b/bdk/exception_handlers.S index 2f38bb30..50acb91a 100644 --- a/bdk/exception_handlers.S +++ b/bdk/exception_handlers.S @@ -41,9 +41,9 @@ * 11111 | SYS | r0–r7, SP, LR, PC, CPSR | r0–r14, PC, CPSR */ -#define EXCP_EN_ADDR 0x4003FFFC -#define EXCP_TYPE_ADDR 0x4003FFF8 -#define EXCP_LR_ADDR 0x4003FFF4 +#define EXCP_EN_ADDR 0x4003FF1C +#define EXCP_TYPE_ADDR 0x4003FF18 +#define EXCP_LR_ADDR 0x4003FF14 #define EXCP_VEC_BASE 0x6000F000 #define EVP_COP_RESET_VECTOR 0x200 diff --git a/bdk/ianos/elfload/elfload.c b/bdk/ianos/elfload/elfload.c index daf561a4..d56e99b9 100644 --- a/bdk/ianos/elfload/elfload.c +++ b/bdk/ianos/elfload/elfload.c @@ -21,7 +21,7 @@ el_status el_pread(el_ctx *ctx, void *def, size_t nb, size_t offset) { - return ctx->pread(ctx, def, nb, offset) ? EL_OK : EL_EIO; + return ctx->pread(ctx, def, nb, offset); } #define EL_PHOFF(ctx, num) (((ctx)->ehdr.e_phoff + (num) *(ctx)->ehdr.e_phentsize)) diff --git a/bdk/ianos/elfload/elfload.h b/bdk/ianos/elfload/elfload.h index 0a73e052..63942791 100644 --- a/bdk/ianos/elfload/elfload.h +++ b/bdk/ianos/elfload/elfload.h @@ -53,7 +53,7 @@ typedef enum typedef struct el_ctx { - bool (*pread)(struct el_ctx *ctx, void *dest, size_t nb, size_t offset); + el_status (*pread)(struct el_ctx *ctx, void *dest, size_t nb, size_t offset); /* base_load_* -> address we are actually going to load at */ @@ -61,6 +61,9 @@ typedef struct el_ctx base_load_paddr, base_load_vaddr; + /* original memory of binary */ + Elf_Addr eaddr; + /* size in memory of binary */ Elf_Addr memsz; diff --git a/bdk/ianos/ianos.c b/bdk/ianos/ianos.c index 99a996df..12a46442 100644 --- a/bdk/ianos/ianos.c +++ b/bdk/ianos/ianos.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 M4xw - * Copyright (c) 2018-2019 CTCaer + * Copyright (c) 2018-2026 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, @@ -21,103 +21,141 @@ #include "elfload/elfload.h" #include #include -#include #include #include #include -#define IRAM_LIB_ADDR 0x4002B000 -#define DRAM_LIB_ADDR 0xE0000000 - extern heap_t _heap; -void *elfBuf = NULL; -void *fileBuf = NULL; +static bdk_params_t _bdk_params = { + .gfx_con = (void *)&gfx_con, + .gfx_ctx = (void *)&gfx_ctxt, + .heap = &_heap, + .memcpy = (memcpy_t)&memcpy, + .memset = (memset_t)&memset, -static void _ianos_call_ep(moduleEntrypoint_t entrypoint, void *moduleConfig) -{ - bdkParams_t bdkParameters = (bdkParams_t)malloc(sizeof(struct _bdkParams_t)); - bdkParameters->gfxCon = (void *)&gfx_con; - bdkParameters->gfxCtx = (void *)&gfx_ctxt; - bdkParameters->memcpy = (memcpy_t)&memcpy; - bdkParameters->memset = (memset_t)&memset; - bdkParameters->sharedHeap = &_heap; - - // Extra functions. - bdkParameters->extension_magic = IANOS_EXT0; - bdkParameters->reg_voltage_set = (reg_voltage_set_t)&max7762x_regulator_set_voltage; - - entrypoint(moduleConfig, bdkParameters); -} + .extension_magic = 0 +}; static void *_ianos_alloc_cb(el_ctx *ctx, Elf_Addr phys, Elf_Addr virt, Elf_Addr size) { - (void)ctx; - (void)phys; - (void)size; return (void *)virt; } -static bool _ianos_read_cb(el_ctx *ctx, void *dest, size_t numberBytes, size_t offset) +static el_status _ianos_read_cb(el_ctx *ctx, void *dest, size_t nb, size_t offset) { - (void)ctx; + memcpy(dest, (void *)(ctx->eaddr + offset), nb); - memcpy(dest, fileBuf + offset, numberBytes); - - return true; + return EL_OK; } //TODO: Support shared libraries. -uintptr_t ianos_loader(char *path, elfType_t type, void *moduleConfig) +int ianos_loader(ianos_lib_t *lib, char *path) { el_ctx ctx; - uintptr_t epaddr = 0; + lib->buf = NULL; + if (!lib->bdk) + lib->bdk = &_bdk_params; // Read library. - fileBuf = sd_file_read(path, NULL); - - if (!fileBuf) - goto out; + ctx.eaddr = (Elf_Addr)sd_file_read(path, NULL); + if (!ctx.eaddr) + goto error; ctx.pread = _ianos_read_cb; if (el_init(&ctx)) - goto out; + goto error; + + if (lib->type & IA_SHARED_LIB) + goto error; // No support for shared libs now. // Set our relocated library's buffer. - switch (type & 0xFFFF) + switch (lib->type & ~IA_SHARED_LIB) { - case EXEC_ELF: - case AR64_ELF: - elfBuf = (void *)DRAM_LIB_ADDR; + case IA_DRAM_LIB: + lib->buf = malloc(ctx.memsz); // Aligned to 0x10 by default. break; + + case IA_IRAM_LIB: + break; + + case IA_AUTO_LIB: // Default to DRAM for now. default: - elfBuf = malloc(ctx.memsz); // Aligned to 0x10 by default. + lib->buf = malloc(ctx.memsz); // Aligned to 0x10 by default. + break; } - if (!elfBuf) - goto out; + if (!lib->buf) + goto error; // Load and relocate library. - ctx.base_load_vaddr = ctx.base_load_paddr = (uintptr_t)elfBuf; + ctx.base_load_vaddr = ctx.base_load_paddr = (Elf_Addr)lib->buf; if (el_load(&ctx, _ianos_alloc_cb)) - goto out_free; + goto error; if (el_relocate(&ctx)) - goto out_free; + goto error; + + free((void *)ctx.eaddr); // Launch. - epaddr = ctx.ehdr.e_entry + (uintptr_t)elfBuf; - moduleEntrypoint_t ep = (moduleEntrypoint_t)epaddr; + Elf_Addr epaddr = ctx.ehdr.e_entry + (Elf_Addr)lib->buf; + moduleEntrypoint ep = (moduleEntrypoint)epaddr; + ep(lib->private, lib->bdk); - _ianos_call_ep(ep, moduleConfig); + return 0; -out_free: - free(fileBuf); - elfBuf = NULL; - fileBuf = NULL; +error: + free((void *)ctx.eaddr); + free(lib->buf); -out: - return epaddr; -} \ No newline at end of file + return 1; +} + +uintptr_t ianos_static_module(char *path, void *private) +{ + el_ctx ctx; + Elf_Addr buf = 0; + Elf_Addr epaddr = 0; + + // Read library. + ctx.eaddr = (Elf_Addr)sd_file_read(path, NULL); + if (!ctx.eaddr) + goto error; + + ctx.pread = _ianos_read_cb; + + // Initialize elfload context. + if (el_init(&ctx)) + goto error; + + // Set our relocated library's buffer. + buf = (Elf_Addr)malloc(ctx.memsz); // Aligned to 0x10 by default. + if (!buf) + goto error; + + // Load and relocate library. + ctx.base_load_vaddr = ctx.base_load_paddr = buf; + if (el_load(&ctx, _ianos_alloc_cb)) + goto error; + + if (el_relocate(&ctx)) + goto error; + + free((void *)ctx.eaddr); + + // Launch. + epaddr = ctx.ehdr.e_entry + buf; + moduleEntrypoint ep = (moduleEntrypoint)epaddr; + ep(private, &_bdk_params); + + return (uintptr_t)epaddr; + +error: + free((void *)ctx.eaddr); + free((void *)buf); + + return 0; +} diff --git a/bdk/ianos/ianos.h b/bdk/ianos/ianos.h index 5ebec641..79d26478 100644 --- a/bdk/ianos/ianos.h +++ b/bdk/ianos/ianos.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 M4xw - * Copyright (c) 2018 CTCaer + * Copyright (c) 2018-2026 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, @@ -19,16 +19,26 @@ #define IANOS_H #include +#include typedef enum { - DRAM_LIB = 0, // DRAM library. - EXEC_ELF = 1, // Executable elf that does not return. - DR64_LIB = 2, // AARCH64 DRAM library. - AR64_ELF = 3, // Executable elf that does not return. - KEEP_IN_RAM = (1 << 31) // Shared library mask. -} elfType_t; + IA_DRAM_LIB = 0, // DRAM library. + IA_IRAM_LIB = 1, // IRAM library. No support for now. + IA_AUTO_LIB = 2, // AUTO library. Defaults to DRAM for now. + IA_SHARED_LIB = BIT(7) // Shared library mask. No support for now. +} ianos_type_t; -uintptr_t ianos_loader(char *path, elfType_t type, void* config); +typedef struct _ianos_lib_t +{ + uintptr_t epaddr; + void *buf; + void *private; + ianos_type_t type; + bdk_params_t *bdk; +} ianos_lib_t; -#endif \ No newline at end of file +int ianos_loader(ianos_lib_t *lib, char *path); +uintptr_t ianos_static_module(char *path, void *private); // Session-lived DRAM lib. + +#endif diff --git a/bdk/input/touch.c b/bdk/input/touch.c index 2d6ef034..40e0a64c 100644 --- a/bdk/input/touch.c +++ b/bdk/input/touch.c @@ -2,7 +2,7 @@ * Touch driver for Nintendo Switch's STM FingerTip S (FTM4CD60DA1BE/FTM4CD50TA1BE) touch controller * * Copyright (c) 2018 langerhans - * Copyright (c) 2018-2023 CTCaer + * Copyright (c) 2018-2026 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, @@ -29,10 +29,6 @@ #include #include "touch.h" - -#include -#define DPRINTF(...) gfx_printf(__VA_ARGS__) - static touch_panel_info_t _panels[] = { { 0, 1, 1, 1, "NISSHA NFT-K12D" },// 0. @@ -43,39 +39,52 @@ static touch_panel_info_t _panels[] = { -1, 1, 0, 1, "GiS VA 6.2\"" } // 2. }; -static int touch_command(u8 cmd, u8 *buf, u8 size) +static touch_info_t _touch_info = { 0 }; +static touch_panel_info_t _touch_panel_info = { 0 }; + +static int _touch_command(u8 cmd, u8 *buf, u8 size) { - int res = i2c_send_buf_small(I2C_3, STMFTS_I2C_ADDR, cmd, buf, size); - if (!res) - return 1; - return 0; + return i2c_send_buf_small(I2C_3, FTS4_I2C_ADDR, cmd, buf, size); } -static int touch_read_reg(u8 *cmd, u32 csize, u8 *buf, u32 size) +static int _touch_read_reg(u8 *cmd, u32 csize, u8 *buf, u32 size) { - int res = i2c_send_buf_small(I2C_3, STMFTS_I2C_ADDR, cmd[0], &cmd[1], csize - 1); - if (res) - res = i2c_recv_buf(buf, size, I2C_3, STMFTS_I2C_ADDR); - if (!res) - return 1; - - return 0; + return i2c_xfer_packet(I2C_3, FTS4_I2C_ADDR, cmd, csize, buf, size); } -static int touch_wait_event(u8 event, u8 status, u32 timeout, u8 *buf) +int touch_get_event_count() +{ + u8 cmd[3] = { FTS4_CMD_HW_REG_READ, 0, FTS4_HW_REG_EVENT_COUNT }; + u8 buf[2]; + + if (_touch_read_reg(cmd, sizeof(cmd), buf, sizeof(buf))) + return 0; + + return (buf[1] >> 1); +} + +static int _touch_wait_event(u8 event, u8 status, u32 timeout, u8 *buf) { u32 timer = get_tmr_ms() + timeout; while (true) { - u8 tmp[8] = {0}; - i2c_recv_buf_small(tmp, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_READ_ONE_EVENT); - if (tmp[1] == event && tmp[2] == status) + if (!touch_get_event_count()) + goto retry; + + u8 tmp[FTS4_EVENT_SIZE]; + int res = i2c_recv_buf_big(tmp, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_READ_ONE_EVENT); + + // Check that event type and status match. + if (!res && tmp[0] == event && tmp[1] == status) { if (buf) - memcpy(buf, &tmp[3], 5); + memcpy(buf, &tmp[2], 6); return 0; } +retry: + usleep(500); + if (get_tmr_ms() > timer) return 1; } @@ -85,7 +94,7 @@ static int touch_wait_event(u8 event, u8 status, u32 timeout, u8 *buf) #define Y_REAL_MAX 704 #define EDGE_OFFSET 15 -static void _touch_compensate_limits(touch_event *event, bool touching) +static void _touch_compensate_limits(touch_event_t *event, bool touching) { event->x = MAX(event->x, EDGE_OFFSET); event->x = MIN(event->x, X_REAL_MAX); @@ -103,116 +112,102 @@ static void _touch_compensate_limits(touch_event *event, bool touching) } } -static void _touch_process_contact_event(touch_event *event, bool touching) +static void _touch_process_contact_event(touch_event_t *event, bool touching) { - event->x = (event->raw[2] << 4) | ((event->raw[4] & STMFTS_MASK_Y_LSB) >> 4); + event->x = (event->raw[1] << 4) | ((event->raw[3] & FTS4_MASK_Y_LSB) >> 4); // Normally, GUI elements have bigger horizontal estate. // Avoid parsing y axis when finger is removed to minimize touch noise. if (touching) { - event->y = (event->raw[3] << 4) | (event->raw[4] & STMFTS_MASK_X_MSB); + event->y = (event->raw[2] << 4) | (event->raw[3] & FTS4_MASK_X_MSB); - event->z = event->raw[5] | (event->raw[6] << 8); + event->z = event->raw[4] | (event->raw[5] << 8); event->z = event->z << 6; u16 tmp = 0x40; - if ((event->raw[7] & 0x3F) != 1 && (event->raw[7] & 0x3F) != 0x3F) - tmp = event->raw[7] & 0x3F; + if ((event->raw[6] & 0x3F) != 1 && (event->raw[6] & 0x3F) != 0x3F) + tmp = event->raw[6] & 0x3F; event->z /= tmp + 0x40; - event->fingers = ((event->raw[1] & STMFTS_MASK_TOUCH_ID) >> 4) + 1; + event->finger = ((event->raw[0] & FTS4_MASK_TOUCH_ID) >> 4) + 1; } else - event->fingers = 0; + event->finger = 0; _touch_compensate_limits(event, touching); } -static void _touch_parse_event(touch_event *event) +static int _touch_parse_input_event(touch_event_t *event) { - event->type = event->raw[1] & STMFTS_MASK_EVENT_ID; - - switch (event->type) + switch (event->raw[0] & FTS4_MASK_EVENT_ID) { - case STMFTS_EV_MULTI_TOUCH_ENTER: - case STMFTS_EV_MULTI_TOUCH_MOTION: + case FTS4_EV_MULTI_TOUCH_ENTER: + case FTS4_EV_MULTI_TOUCH_MOTION: _touch_process_contact_event(event, true); - if (event->z < 255) // Reject palm rest. + if (event->z < 500) // Reject palm rest. event->touch = true; else - { event->touch = false; - event->type = STMFTS_EV_MULTI_TOUCH_LEAVE; - } - break; - case STMFTS_EV_MULTI_TOUCH_LEAVE: + return 0; + + case FTS4_EV_MULTI_TOUCH_LEAVE: event->touch = false; _touch_process_contact_event(event, false); - break; - case STMFTS_EV_NO_EVENT: - if (event->touch) - event->type = STMFTS_EV_MULTI_TOUCH_MOTION; - break; + return 0; + default: - if (event->touch && event->raw[0] == STMFTS_EV_MULTI_TOUCH_MOTION) - event->type = STMFTS_EV_MULTI_TOUCH_MOTION; - else - event->type = STMFTS_EV_MULTI_TOUCH_LEAVE; + return 1; // No event. + } +} + +int touch_poll(touch_event_t *event) +{ + u8 cmd = !_touch_info.clone ? FTS4_CMD_LATEST_EVENT : FTS4_CMD_READ_ONE_EVENT; + + int res = i2c_recv_buf_big(event->raw, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, cmd); + if (!res) + res = _touch_parse_input_event(event); + + return res; +} + +touch_info_t *touch_get_chip_info() +{ + u8 buf[7] = { 0 }; + + // Get chip info. + u8 cmd[3] = { FTS4_CMD_HW_REG_READ, 0, FTS4_HW_REG_CHIP_ID_INFO }; + if (_touch_read_reg(cmd, sizeof(cmd), buf, sizeof(buf))) + { + memset(&_touch_info, 0, sizeof(touch_info_t)); + goto exit; } - // gfx_con_setpos(0, 300); - // DPRINTF("x = %d \ny = %d \nz = %d \n", event->x, event->y, event->z); - // DPRINTF("0 = %02X\n1 = %02X\n2 = %02X\n3 = %02X\n", event->raw[0], event->raw[1], event->raw[2], event->raw[3]); - // DPRINTF("4 = %02X\n5 = %02X\n6 = %02X\n7 = %02X\n", event->raw[4], event->raw[5], event->raw[6], event->raw[7]); -} + _touch_info.chip_id = buf[1] << 8 | buf[2]; + _touch_info.fw_ver = buf[3] << 8 | buf[4]; + _touch_info.config_id = buf[5]; + _touch_info.config_ver = buf[6]; -void touch_poll(touch_event *event) -{ - i2c_recv_buf_small(event->raw, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_LATEST_EVENT); + // Validate that device is genuine or proper. + cmd[2] = 2; + _touch_read_reg(cmd, sizeof(cmd), buf, sizeof(buf)); + _touch_info.clone = _touch_info.chip_id != (buf[3] << 8 | buf[4]); - _touch_parse_event(event); -} - -touch_event touch_poll_wait() -{ - touch_event event; - do - { - touch_poll(&event); - } while (event.type != STMFTS_EV_MULTI_TOUCH_LEAVE); - - return event; -} - -touch_info touch_get_info() -{ - touch_info info; - u8 buf[8]; - memset(&buf, 0, 8); - i2c_recv_buf_small(buf, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_READ_INFO); - - info.chip_id = buf[0] << 8 | buf[1]; - info.fw_ver = buf[2] << 8 | buf[3]; - info.config_id = buf[4]; - info.config_ver = buf[5]; - - //DPRINTF("ID: %04X, FW Ver: %d.%02d\nCfg ID: %02X, Cfg Ver: %d\n", - // info.chip_id, info.fw_ver >> 8, info.fw_ver & 0xFF, info.config_id, info.config_ver); - - return info; +exit: + return &_touch_info; } touch_panel_info_t *touch_get_panel_vendor() { - u8 buf[5] = {0}; - u8 cmd = STMFTS_VENDOR_GPIO_STATE; - static touch_panel_info_t panel_info = { -2, 0, 0, 0, ""}; + _touch_panel_info.idx = -2; - if (touch_command(STMFTS_VENDOR, &cmd, 1)) + u8 cmd = FTS4_VENDOR_GPIO_STATE; + if (_touch_command(FTS4_CMD_VENDOR, &cmd, 1)) return NULL; - if (touch_wait_event(STMFTS_EV_VENDOR, STMFTS_VENDOR_GPIO_STATE, 2000, buf)) + u8 buf[6] = { 0 }; + if (_touch_wait_event(FTS4_EV_VENDOR, FTS4_VENDOR_GPIO_STATE, 2000, buf)) return NULL; for (u32 i = 0; i < ARRAY_SIZE(_panels); i++) @@ -223,37 +218,33 @@ touch_panel_info_t *touch_get_panel_vendor() } // Touch panel not found, return current gpios. - panel_info.gpio0 = buf[0]; - panel_info.gpio1 = buf[1]; - panel_info.gpio2 = buf[2]; + _touch_panel_info.gpio0 = buf[0]; + _touch_panel_info.gpio1 = buf[1]; + _touch_panel_info.gpio2 = buf[2]; - return &panel_info; + return &_touch_panel_info; } int touch_get_fw_info(touch_fw_info_t *fw) { - u8 buf[8] = {0}; + u8 buf[9] = { 0 }; memset(fw, 0, sizeof(touch_fw_info_t)); // Get fw address info. - u8 cmd[3] = { STMFTS_RW_FRAMEBUFFER_REG, 0, 0x60 }; - int res = touch_read_reg(cmd, 3, buf, 3); + u8 cmd[3] = { FTS4_CMD_FB_REG_READ, 0, 0x60 }; + int res = _touch_read_reg(cmd, sizeof(cmd), buf, 3); if (!res) { // Get fw info. cmd[1] = buf[2]; cmd[2] = buf[1]; - res = touch_read_reg(cmd, 3, buf, 8); + res = _touch_read_reg(cmd, sizeof(cmd), buf, sizeof(buf)); if (!res) { fw->fw_id = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | buf[4]; - fw->ftb_ver = (buf[6] << 8) | buf[5]; + fw->ftb_ver = (buf[6] << 8) | buf[5]; + fw->fw_rev = (buf[8] << 8) | buf[7]; } - - cmd[2]++; - res = touch_read_reg(cmd, 3, buf, 8); - if (!res) - fw->fw_rev = (buf[7] << 8) | buf[6]; } return res; @@ -261,16 +252,17 @@ int touch_get_fw_info(touch_fw_info_t *fw) int touch_sys_reset() { - u8 cmd[3] = { 0, 0x28, 0x80 }; // System reset cmd. + u8 cmd[3] = { 0, FTS4_HW_REG_SYS_RESET, 0x80 }; // System reset cmd. for (u8 retries = 0; retries < 3; retries++) { - if (touch_command(STMFTS_WRITE_REG, cmd, 3)) + if (_touch_command(FTS4_CMD_HW_REG_WRITE, cmd, 3)) { msleep(10); continue; } msleep(10); - if (touch_wait_event(STMFTS_EV_CONTROLLER_READY, 0, 20, NULL)) + + if (_touch_wait_event(FTS4_EV_CONTROLLER_READY, 0, 20, NULL)) continue; else return 0; @@ -281,36 +273,25 @@ int touch_sys_reset() int touch_panel_ito_test(u8 *err) { - int res = 0; + // Check that touch IC is supported. + touch_info_t *info = touch_get_chip_info(); + if (info->chip_id != FTS4_I2C_CHIP_ID || info->clone) + return 1; // Reset touchscreen module. if (touch_sys_reset()) - return res; + return 1; // Do ITO Production test. - u8 cmd[2] = { 1, 0 }; - if (touch_command(STMFTS_ITO_CHECK, cmd, 2)) - return res; + if (_touch_command(FTS4_CMD_ITO_CHECK, NULL, 0)) + return 1; - u32 timer = get_tmr_ms() + 2000; - while (true) + u8 buf[6] = { 0 }; + int res = _touch_wait_event(FTS4_EV_ERROR, FTS4_EV_ERROR_ITO_TEST, 2000, buf); + if (!res && err) { - u8 tmp[8] = {0}; - i2c_recv_buf_small(tmp, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_READ_ONE_EVENT); - if (tmp[1] == 0xF && tmp[2] == 0x5) - { - if (err) - { - err[0] = tmp[3]; - err[1] = tmp[4]; - } - - res = 1; - break; - } - - if (get_tmr_ms() > timer) - break; + err[0] = buf[0]; + err[1] = buf[1]; } // Reset touchscreen module. @@ -321,20 +302,19 @@ int touch_panel_ito_test(u8 *err) int touch_get_fb_info(u8 *buf) { - u8 tmp[5]; - - u8 cmd[3] = { STMFTS_RW_FRAMEBUFFER_REG, 0, 0 }; + u8 cmd[3] = { FTS4_CMD_FB_REG_READ, 0, 0 }; int res = 0; - for (u32 i = 0; i < 0x10000; i += 4) { if (!res) { cmd[1] = (i >> 8) & 0xFF; cmd[2] = i & 0xFF; - memset(tmp, 0xCC, 5); - res = touch_read_reg(cmd, 3, tmp, 5); + + u8 tmp[5]; + memset(tmp, 0xCC, sizeof(tmp)); + res = _touch_read_reg(cmd, sizeof(cmd), tmp, sizeof(tmp)); memcpy(&buf[i], tmp + 1, 4); } } @@ -342,70 +322,97 @@ int touch_get_fb_info(u8 *buf) return res; } +int touch_switch_sense_mode(u8 mode, bool gis_6_2) +{ + // Set detection config. + u8 cmd[3] = { 1, 0x64, 0 }; + + switch (mode) + { + case FTS4_STYLUS_MODE: + cmd[2] = !gis_6_2 ? 0xC8 : 0xAD; + break; + case FTS4_FINGER_MODE: + cmd[2] = !gis_6_2 ? 0x8C : 0x79; + break; + } + + if (_touch_command(FTS4_CMD_DETECTION_CONFIG, cmd, 3)) + return 1; + + // Sense mode. + cmd[0] = mode; + + return _touch_command(FTS4_CMD_SWITCH_SENSE_MODE, cmd, 1); +} + int touch_sense_enable() { // Switch sense mode and enable multi-touch sensing. - u8 cmd = STMFTS_FINGER_MODE; - if (touch_command(STMFTS_SWITCH_SENSE_MODE, &cmd, 1)) - return 0; + u8 cmd = FTS4_FINGER_MODE; + if (_touch_command(FTS4_CMD_SWITCH_SENSE_MODE, &cmd, 1)) + return 1; - if (touch_command(STMFTS_MS_MT_SENSE_ON, NULL, 0)) - return 0; + if (_touch_command(FTS4_CMD_MS_MT_SENSE_ON, NULL, 0)) + return 1; - if (touch_command(STMFTS_CLEAR_EVENT_STACK, NULL, 0)) - return 0; + if (_touch_command(FTS4_CMD_CLEAR_EVENT_STACK, NULL, 0)) + return 1; - return 1; + return 0; } int touch_execute_autotune() { + u8 buf[6] = { 0 }; + // Reset touchscreen module. if (touch_sys_reset()) - return 0; + return 1; // Trim low power oscillator. - if (touch_command(STMFTS_LP_TIMER_CALIB, NULL, 0)) - return 0; + if (_touch_command(FTS4_CMD_LP_TIMER_CALIB, NULL, 0)) + return 1; + msleep(200); // Apply Mutual Sense Compensation tuning. - if (touch_command(STMFTS_MS_CX_TUNING, NULL, 0)) - return 0; - if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_MS_CX_TUNING_DONE, 2000, NULL)) - return 0; + if (_touch_command(FTS4_CMD_MS_CX_TUNING, NULL, 0)) + return 1; + if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_MS_CX_TUNING_DONE, 2000, buf) || buf[0] || buf[1]) + return 1; // Apply Self Sense Compensation tuning. - if (touch_command(STMFTS_SS_CX_TUNING, NULL, 0)) - return 0; - if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_SS_CX_TUNING_DONE, 2000, NULL)) - return 0; + if (_touch_command(FTS4_CMD_SS_CX_TUNING, NULL, 0)) + return 1; + if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_SS_CX_TUNING_DONE, 2000, buf) || buf[0] || buf[1]) + return 1; // Save Compensation data to EEPROM. - if (touch_command(STMFTS_SAVE_CX_TUNING, NULL, 0)) - return 0; - if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_WRITE_CX_TUNE_DONE, 2000, NULL)) - return 0; + if (_touch_command(FTS4_CMD_SAVE_CX_TUNING, NULL, 0)) + return 1; + if (_touch_wait_event(FTS4_EV_STATUS, FTS4_EV_STATUS_WRITE_CX_TUNE_DONE, 2000, buf) || buf[0] || buf[1]) + return 1; return touch_sense_enable(); } static int touch_init() { + // Check that touch IC is supported. + touch_info_t *info = touch_get_chip_info(); + if (info->chip_id != FTS4_I2C_CHIP_ID) + return 1; + // Initialize touchscreen module. if (touch_sys_reset()) - return 0; + return 1; return touch_sense_enable(); } int touch_power_on() { - // Configure Touscreen and GCAsic shared GPIO. - PINMUX_AUX(PINMUX_AUX_CAM_I2C_SDA) = PINMUX_LPDR | PINMUX_INPUT_ENABLE | PINMUX_TRISTATE | PINMUX_PULL_UP | 2; - PINMUX_AUX(PINMUX_AUX_CAM_I2C_SCL) = PINMUX_IO_HV | PINMUX_LPDR | PINMUX_TRISTATE | PINMUX_PULL_DOWN | 2; // Unused. - gpio_config(GPIO_PORT_S, GPIO_PIN_3, GPIO_MODE_GPIO); // GC detect. - // Configure touchscreen Touch Reset pin. PINMUX_AUX(PINMUX_AUX_DAP4_SCLK) = PINMUX_PULL_DOWN | 1; gpio_direction_output(GPIO_PORT_J, GPIO_PIN_7, GPIO_LOW); @@ -426,13 +433,13 @@ int touch_power_on() usleep(10000); // Wait for the touchscreen module to get ready. - touch_wait_event(STMFTS_EV_CONTROLLER_READY, 0, 20, NULL); + _touch_wait_event(FTS4_EV_CONTROLLER_READY, 0, 20, NULL); // Check for forced boot time calibration. if (btn_read_vol() == (BTN_VOL_UP | BTN_VOL_DOWN)) { u8 err[2]; - if (touch_panel_ito_test(err)) + if (!touch_panel_ito_test(err)) if (!err[0] && !err[1]) return touch_execute_autotune(); } @@ -441,12 +448,12 @@ int touch_power_on() u32 retries = 3; while (retries) { - if (touch_init()) - return 1; + if (!touch_init()) + return 0; retries--; } - return 0; + return 1; } void touch_power_off() diff --git a/bdk/input/touch.h b/bdk/input/touch.h index 871659eb..48893b95 100644 --- a/bdk/input/touch.h +++ b/bdk/input/touch.h @@ -2,7 +2,7 @@ * Touch driver for Nintendo Switch's STM FingerTip S (4CD60D) touch controller * * Copyright (c) 2018 langerhans - * Copyright (c) 2018-2020 CTCaer + * Copyright (c) 2018-2026 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, @@ -22,92 +22,100 @@ #include -#define STMFTS_I2C_ADDR 0x49 +#define FTS4_I2C_ADDR 0x49 -/* I2C commands */ -#define STMFTS_READ_INFO 0x80 -#define STMFTS_READ_STATUS 0x84 -#define STMFTS_READ_ONE_EVENT 0x85 -#define STMFTS_READ_ALL_EVENT 0x86 -#define STMFTS_LATEST_EVENT 0x87 -#define STMFTS_SLEEP_IN 0x90 -#define STMFTS_SLEEP_OUT 0x91 -#define STMFTS_MS_MT_SENSE_OFF 0x92 -#define STMFTS_MS_MT_SENSE_ON 0x93 -#define STMFTS_SS_HOVER_SENSE_OFF 0x94 -#define STMFTS_SS_HOVER_SENSE_ON 0x95 -#define STMFTS_LP_TIMER_CALIB 0x97 -#define STMFTS_MS_KEY_SENSE_OFF 0x9A -#define STMFTS_MS_KEY_SENSE_ON 0x9B -#define STMFTS_SYSTEM_RESET 0xA0 -#define STMFTS_CLEAR_EVENT_STACK 0xA1 -#define STMFTS_FULL_FORCE_CALIBRATION 0xA2 -#define STMFTS_MS_CX_TUNING 0xA3 -#define STMFTS_SS_CX_TUNING 0xA4 -#define STMFTS_ITO_CHECK 0xA7 -#define STMFTS_RELEASEINFO 0xAA -#define STMFTS_WRITE_REG 0xB6 -#define STMFTS_SWITCH_SENSE_MODE 0xC3 -#define STMFTS_NOISE_WRITE 0xC7 -#define STMFTS_NOISE_READ 0xC8 -#define STMFTS_RW_FRAMEBUFFER_REG 0xD0 -#define STMFTS_SAVE_CX_TUNING 0xFC +#define FTS4_I2C_CHIP_ID 0x3670 -#define STMFTS_DETECTION_CONFIG 0xB0 -#define STMFTS_REQU_COMP_DATA 0xB8 -#define STMFTS_VENDOR 0xCF -#define STMFTS_FLASH_UNLOCK 0xF7 -#define STMFTS_FLASH_WRITE_64K 0xF8 -#define STMFTS_FLASH_STATUS 0xF9 -#define STMFTS_FLASH_OP 0xFA -#define STMFTS_UNK5 0x62 +/* I2C commands. */ +#define FTS4_CMD_READ_INFO 0x80 +#define FTS4_CMD_READ_STATUS 0x84 +#define FTS4_CMD_READ_ONE_EVENT 0x85 +#define FTS4_CMD_READ_ALL_EVENT 0x86 +#define FTS4_CMD_LATEST_EVENT 0x87 // Clears event stack. +#define FTS4_CMD_SLEEP_IN 0x90 +#define FTS4_CMD_SLEEP_OUT 0x91 +#define FTS4_CMD_MS_MT_SENSE_OFF 0x92 +#define FTS4_CMD_MS_MT_SENSE_ON 0x93 +#define FTS4_CMD_SS_HOVER_SENSE_OFF 0x94 +#define FTS4_CMD_SS_HOVER_SENSE_ON 0x95 +#define FTS4_CMD_LP_TIMER_CALIB 0x97 +#define FTS4_CMD_MS_KEY_SENSE_OFF 0x9A +#define FTS4_CMD_MS_KEY_SENSE_ON 0x9B +#define FTS4_CMD_SYSTEM_RESET 0xA0 +#define FTS4_CMD_CLEAR_EVENT_STACK 0xA1 +#define FTS4_CMD_FULL_FORCE_CALIB 0xA2 +#define FTS4_CMD_MS_CX_TUNING 0xA3 +#define FTS4_CMD_SS_CX_TUNING 0xA4 +#define FTS4_CMD_ITO_CHECK 0xA7 +#define FTS4_CMD_RELEASEINFO 0xAA +#define FTS4_CMD_HW_REG_READ 0xB6 // u16be address offset. Any size read. +#define FTS4_CMD_HW_REG_WRITE FTS4_CMD_HW_REG_READ // u16be address offset, bytes to write. +#define FTS4_CMD_SWITCH_SENSE_MODE 0xC3 +#define FTS4_CMD_NOISE_WRITE 0xC7 +#define FTS4_CMD_NOISE_READ 0xC8 +#define FTS4_CMD_FB_REG_READ 0xD0 +#define FTS4_CMD_FB_REG_WRITE FTS4_CMD_FB_REG_READ +#define FTS4_CMD_SAVE_CX_TUNING 0xFC -/* cmd parameters */ -#define STMFTS_VENDOR_GPIO_STATE 0x01 -#define STMFTS_VENDOR_SENSE_MODE 0x02 -#define STMFTS_STYLUS_MODE 0x00 -#define STMFTS_FINGER_MODE 0x01 -#define STMFTS_HOVER_MODE 0x02 +#define FTS4_CMD_DETECTION_CONFIG 0xB0 +#define FTS4_CMD_REQ_CX_DATA 0xB8 +#define FTS4_CMD_VENDOR 0xCF +#define FTS4_CMD_FLASH_UNLOCK 0xF7 +#define FTS4_CMD_FLASH_WRITE_64K 0xF8 +#define FTS4_CMD_FLASH_STATUS 0xF9 +#define FTS4_CMD_FLASH_OP 0xFA +#define FTS4_CMD_UNK_62 0x62 -/* events */ -#define STMFTS_EV_NO_EVENT 0x00 -#define STMFTS_EV_MULTI_TOUCH_DETECTED 0x02 -#define STMFTS_EV_MULTI_TOUCH_ENTER 0x03 -#define STMFTS_EV_MULTI_TOUCH_LEAVE 0x04 -#define STMFTS_EV_MULTI_TOUCH_MOTION 0x05 -#define STMFTS_EV_HOVER_ENTER 0x07 -#define STMFTS_EV_HOVER_LEAVE 0x08 -#define STMFTS_EV_HOVER_MOTION 0x09 -#define STMFTS_EV_KEY_STATUS 0x0e -#define STMFTS_EV_ERROR 0x0f -#define STMFTS_EV_NOISE_READ 0x17 -#define STMFTS_EV_NOISE_WRITE 0x18 -#define STMFTS_EV_VENDOR 0x20 +/* Command parameters. */ +#define FTS4_VENDOR_GPIO_STATE 0x01 +#define FTS4_VENDOR_SENSE_MODE 0x02 +#define FTS4_STYLUS_MODE 0x00 +#define FTS4_FINGER_MODE 0x01 +#define FTS4_HOVER_MODE 0x02 -#define STMFTS_EV_CONTROLLER_READY 0x10 -#define STMFTS_EV_STATUS 0x16 -#define STMFTS_EV_DEBUG 0xDB +/* HW Registers */ +#define FTS4_HW_REG_CHIP_ID_INFO 0x0004 +#define FTS4_HW_REG_EVENT_COUNT 0x0023 +#define FTS4_HW_REG_SYS_RESET 0x0028 -#define STMFTS_EV_STATUS_MS_CX_TUNING_DONE 1 -#define STMFTS_EV_STATUS_SS_CX_TUNING_DONE 2 -#define STMFTS_EV_STATUS_WRITE_CX_TUNE_DONE 4 +/* FB Addresses */ +#define FTS4_FB_REG_FW_INFO_ADDRESS 0x0060 -/* multi touch related event masks */ -#define STMFTS_MASK_EVENT_ID 0x0F -#define STMFTS_MASK_TOUCH_ID 0xF0 -#define STMFTS_MASK_LEFT_EVENT 0x0F -#define STMFTS_MASK_X_MSB 0x0F -#define STMFTS_MASK_Y_LSB 0xF0 +/* Events. */ +#define FTS4_EV_NO_EVENT 0x00 +#define FTS4_EV_MULTI_TOUCH_DETECTED 0x02 +#define FTS4_EV_MULTI_TOUCH_ENTER 0x03 +#define FTS4_EV_MULTI_TOUCH_LEAVE 0x04 +#define FTS4_EV_MULTI_TOUCH_MOTION 0x05 +#define FTS4_EV_HOVER_ENTER 0x07 +#define FTS4_EV_HOVER_LEAVE 0x08 +#define FTS4_EV_HOVER_MOTION 0x09 +#define FTS4_EV_KEY_STATUS 0x0E +#define FTS4_EV_ERROR 0x0F +#define FTS4_EV_CONTROLLER_READY 0x10 +#define FTS4_EV_STATUS 0x16 +#define FTS4_EV_NOISE_READ 0x17 +#define FTS4_EV_NOISE_WRITE 0x18 +#define FTS4_EV_VENDOR 0x20 +#define FTS4_EV_DEBUG 0xDB -/* key related event masks */ -#define STMFTS_MASK_KEY_NO_TOUCH 0x00 -#define STMFTS_MASK_KEY_MENU 0x01 -#define STMFTS_MASK_KEY_BACK 0x02 +/* FTS4_EV_STATUS Events. */ +#define FTS4_EV_STATUS_MS_CX_TUNING_DONE 0x01 +#define FTS4_EV_STATUS_SS_CX_TUNING_DONE 0x02 +#define FTS4_EV_STATUS_WRITE_CX_TUNE_DONE 0x04 -#define STMFTS_EVENT_SIZE 8 -#define STMFTS_STACK_DEPTH 32 -#define STMFTS_DATA_MAX_SIZE (STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH) -#define STMFTS_MAX_FINGERS 10 +#define FTS4_EV_ERROR_ITO_TEST 0x05 + +/* Multi touch related event masks. */ +#define FTS4_MASK_EVENT_ID 0x0F +#define FTS4_MASK_TOUCH_ID 0xF0 +#define FTS4_MASK_X_MSB 0x0F +#define FTS4_MASK_Y_LSB 0xF0 + +#define FTS4_EVENT_SIZE 8 +#define FTS4_STACK_DEPTH 32 // Actual 128. +#define FTS4_DATA_MAX_SIZE (FTS4_EVENT_SIZE * FTS4_STACK_DEPTH) +#define FTS4_MAX_FINGERS 10 typedef enum _touch_ito_error { ITO_NO_ERROR = 0, @@ -130,15 +138,13 @@ typedef enum _touch_ito_error { ITO_MAX_ERR_REACHED = 0xFF } touch_ito_error; -typedef struct _touch_event { - u8 raw[8]; - u16 type; // Event type. - u16 x; // Horizontal coordinates. - u16 y; // Vertical coordinates. - u32 z; - u8 fingers; +typedef struct _touch_event_t { + u8 raw[FTS4_EVENT_SIZE]; + u16 x, y; // Coordinates. + u32 z; // Orientation. bool touch; -} touch_event; + int finger; +} touch_event_t; typedef struct _touch_panel_info_t { @@ -149,12 +155,13 @@ typedef struct _touch_panel_info_t char *vendor; } touch_panel_info_t; -typedef struct _touch_info { - u16 chip_id; - u16 fw_ver; - u16 config_id; - u16 config_ver; -} touch_info; +typedef struct _touch_info_t { + u16 chip_id; + u16 fw_ver; + u16 config_id; + u16 config_ver; + bool clone; +} touch_info_t; typedef struct _touch_fw_info_t { u32 fw_id; @@ -162,15 +169,16 @@ typedef struct _touch_fw_info_t { u16 fw_rev; } touch_fw_info_t; -void touch_poll(touch_event *event); -touch_event touch_poll_wait(); +int touch_poll(touch_event_t *event); +touch_info_t *touch_get_chip_info(); touch_panel_info_t *touch_get_panel_vendor(); int touch_get_fw_info(touch_fw_info_t *fw); -touch_info touch_get_info(); +int touch_get_event_count(); int touch_panel_ito_test(u8 *err); int touch_execute_autotune(); +int touch_switch_sense_mode(u8 mode, bool gis_6_2); int touch_sense_enable(); int touch_power_on(); void touch_power_off(); -#endif /* __TOUCH_H_ */ \ No newline at end of file +#endif /* __TOUCH_H_ */ diff --git a/bdk/libs/lv_conf.h b/bdk/libs/lv_conf.h index e11351c8..bb63fea9 100644 --- a/bdk/libs/lv_conf.h +++ b/bdk/libs/lv_conf.h @@ -346,7 +346,7 @@ #define USE_LV_KB 0 /*Check box (dependencies: lv_btn, lv_label)*/ -#define USE_LV_CB 1 +#define USE_LV_CB 0 /*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ #define USE_LV_LIST 1 @@ -370,7 +370,7 @@ #define USE_LV_SLIDER 1 /*Switch (dependencies: lv_slider)*/ -#define USE_LV_SW 1 +#define USE_LV_SW 0 #endif /*LV_CONF_H*/ diff --git a/bdk/libs/lvgl/lv_objx/lv_line.c b/bdk/libs/lvgl/lv_objx/lv_line.c index 0e163371..8a7129bb 100644 --- a/bdk/libs/lvgl/lv_objx/lv_line.c +++ b/bdk/libs/lvgl/lv_objx/lv_line.c @@ -1,3 +1,19 @@ +/* + * 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 . + */ + /** * @file lv_line.c * diff --git a/bdk/libs/lvgl/lv_objx/lv_slider.c b/bdk/libs/lvgl/lv_objx/lv_slider.c index eaf04e8c..204e60b5 100644 --- a/bdk/libs/lvgl/lv_objx/lv_slider.c +++ b/bdk/libs/lvgl/lv_objx/lv_slider.c @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2026 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 . + */ /** * @file lv_slider.c @@ -437,16 +452,17 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par lv_indev_get_point(param, &p); int16_t tmp = 0; if(w > h) { - lv_coord_t knob_w = h; - p.x -= slider->coords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/ - tmp = (int32_t)((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - knob_w); - tmp += ext->bar.min_value; + lv_coord_t knob_w = h; + lv_coord_t offset = (ext->knob_in == 0) ? w : w - knob_w; + p.x -= slider->coords.x1 + ((ext->knob_in == 0) ? 0 : knob_w / 2); + tmp = ((int32_t)p.x * (ext->bar.max_value - ext->bar.min_value) + offset / 2) / offset; } else { - lv_coord_t knob_h = w; - p.y -= slider->coords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/ - tmp = (int32_t)((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - knob_h); - tmp = ext->bar.max_value - tmp; /*Invert the value: smaller value means higher y*/ + lv_coord_t knob_h = w; + lv_coord_t offset = (ext->knob_in == 0) ? h : h - knob_h; + p.y -= slider->coords.y1 + ((ext->knob_in == 0) ? 0 : knob_h / 2); + tmp = ((int32_t)p.y * (ext->bar.max_value - ext->bar.min_value) + offset / 2) / offset; } + tmp += ext->bar.min_value; if(tmp < ext->bar.min_value) tmp = ext->bar.min_value; else if(tmp > ext->bar.max_value) tmp = ext->bar.max_value; diff --git a/bdk/libs/lvgl/lv_themes/lv_theme.h b/bdk/libs/lvgl/lv_themes/lv_theme.h index f66f9c84..20bd5a47 100644 --- a/bdk/libs/lvgl/lv_themes/lv_theme.h +++ b/bdk/libs/lvgl/lv_themes/lv_theme.h @@ -82,13 +82,6 @@ typedef struct { } label; #endif -#if USE_LV_IMG != 0 - struct { - lv_style_t *light; - lv_style_t *dark; - } img; -#endif - #if USE_LV_LINE != 0 struct { lv_style_t *decor; diff --git a/bdk/libs/lvgl/lv_themes/lv_theme_hekate.c b/bdk/libs/lvgl/lv_themes/lv_theme_hekate.c index 9a4532a2..97b7c263 100644 --- a/bdk/libs/lvgl/lv_themes/lv_theme_hekate.c +++ b/bdk/libs/lvgl/lv_themes/lv_theme_hekate.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022 CTCaer + * Copyright (c) 2018-2026 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, @@ -25,22 +25,27 @@ * DEFINES *********************/ #define DEF_RADIUS 4 -#define COLOR_SHADOW_LIGHT LV_COLOR_HEX(0xAAAAAA) -#define COLOR_SHADOW_DARK LV_COLOR_HEX(0x1F1F1F) -#define COLOR_HOS_TURQUOISE (lv_color_hsv_to_rgb(_hue, 100, 100)) // 0x00FFC9 -#define COLOR_HOS_TEAL_LIGHTER (lv_color_hsv_to_rgb(_hue, 100, 93)) // 0x00EDBA -#define COLOR_HOS_TEAL_LIGHT (lv_color_hsv_to_rgb(_hue, 100, 72)) // 0x00B78F -#define COLOR_HOS_TEAL (lv_color_hsv_to_rgb(_hue, 100, 64)) // 0x00A273 + +#define COLOR_HOS_TURQUOISE (_hue ? lv_color_hsv_to_rgb(_hue, 100, 100) : lv_color_hsv_to_rgb(53, 8, 90)) // 0x00FFC9 +#define COLOR_HOS_TEAL_LIGHTER (_hue ? lv_color_hsv_to_rgb(_hue, 100, 93) : lv_color_hsv_to_rgb(53, 8, 81)) // 0x00EDBA +#define COLOR_HOS_TEAL_LIGHT (_hue ? lv_color_hsv_to_rgb(_hue, 100, 72) : lv_color_hsv_to_rgb(53, 8, 65)) // 0x00B78F +#define COLOR_HOS_TEAL (_hue ? lv_color_hsv_to_rgb(_hue, 100, 64) : lv_color_hsv_to_rgb(53, 8, 58)) // 0x00A273 #define COLOR_HOS_ORANGE LV_COLOR_HEX(0xFF5500) #define COLOR_HOS_TXT_WHITE LV_COLOR_HEX(0xFBFBFB) -#define COLOR_BG_DARKER LV_COLOR_HEX(theme_bg_color ? (theme_bg_color - 0x121212) : 0x0B0B0B) // 0x1B1B1B. #define COLOR_BG_DARK LV_COLOR_HEX(theme_bg_color ? (theme_bg_color - 0x0B0B0B) : 0x121212) // 0x222222. #define COLOR_BG LV_COLOR_HEX(theme_bg_color) // 0x2D2D2D. #define COLOR_BG_LIGHT LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x101010) : 0x2D2D2D) // 0x3D3D3D. #define COLOR_BG_LIGHTER LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x191919) : 0x363636) // 0x464646. -#define COLOR_LIGHT_BORDER LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x202020) : 0x3D3D3D) // 0x4D4D4D. +#define COLOR_INACTIVE LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x171717) : 0x343434) // 0x444444. +#define COLOR_BAR LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x202020) : 0x3D3D3D) // 0x4D4D4D. +#define COLOR_PRESS LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x232323) : 0x404040) // 0x505050. +#define COLOR_LINE LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x383838) : 0x555555) // 0x656565. + +#define COLOR_SHADOW_LIGHT LV_COLOR_HEX(0xAAAAAA) +#define COLOR_SHADOW LV_COLOR_HEX(theme_bg_color ? theme_bg_color : 0x181818) // 0x2D2D2D. +#define COLOR_SHADOW_DARK LV_COLOR_HEX(theme_bg_color ? 0x1F1F1F : 0x0A0A0A) /********************** * TYPEDEFS @@ -92,9 +97,9 @@ static void basic_init(void) lv_style_copy(&panel, &def); panel.body.radius = DEF_RADIUS; panel.body.main_color = COLOR_BG; - panel.body.grad_color = COLOR_BG; + panel.body.grad_color = panel.body.main_color; panel.body.border.width = 1; - panel.body.border.color = COLOR_LIGHT_BORDER; + panel.body.border.color = COLOR_BAR; panel.body.border.opa = LV_OPA_COVER; panel.body.shadow.color = COLOR_SHADOW_LIGHT; panel.body.shadow.type = LV_SHADOW_BOTTOM; @@ -106,7 +111,7 @@ static void basic_init(void) lv_style_copy(&sb, &def); sb.body.main_color = LV_COLOR_BLACK; - sb.body.grad_color = LV_COLOR_BLACK; + sb.body.grad_color = sb.body.grad_color; sb.body.opa = LV_OPA_40; sb.body.padding.hor = LV_DPI / 25; @@ -147,7 +152,7 @@ static void btn_init(void) //rel.text.color = COLOR_HOS_TXT_WHITE; lv_style_copy(&pr, &rel); - pr.body.main_color = LV_COLOR_HEX(0x505050); + pr.body.main_color = COLOR_PRESS; pr.body.grad_color = pr.body.main_color; pr.body.shadow.width = 0; pr.body.border.color = COLOR_HOS_TEAL_LIGHTER; @@ -159,7 +164,7 @@ static void btn_init(void) tgl_rel.body.border.width = 4; lv_style_copy(&tgl_pr, &tgl_rel); - tgl_pr.body.main_color = LV_COLOR_HEX(0x505050); + tgl_pr.body.main_color = COLOR_PRESS; tgl_pr.body.grad_color = tgl_pr.body.main_color; tgl_pr.text.color = COLOR_HOS_TURQUOISE; tgl_pr.body.shadow.width = 0; @@ -201,30 +206,12 @@ static void label_init(void) #endif } -static void img_init(void) -{ -#if USE_LV_IMG != 0 - static lv_style_t img_light, img_dark; - lv_style_copy(&img_light, &def); - img_light.image.color = LV_COLOR_WHITE; - img_light.image.intense = LV_OPA_80; - - lv_style_copy(&img_dark, &def); - img_dark.image.color = COLOR_BG_DARKER; - img_dark.image.intense = LV_OPA_80; - - - theme.img.light = &def; - theme.img.dark = &def; -#endif -} - static void line_init(void) { #if USE_LV_LINE != 0 static lv_style_t line; lv_style_copy(&line, &def); - line.line.color = LV_COLOR_HEX(0x656565); + line.line.color = COLOR_LINE; theme.line.decor = &line; #endif } @@ -239,7 +226,7 @@ static void led_init(void) led.body.border.width = LV_DPI / 30; led.body.border.opa = LV_OPA_30; led.body.main_color = lv_color_hsv_to_rgb(_hue, 100, 100); - led.body.grad_color = lv_color_hsv_to_rgb(_hue, 100, 100); + led.body.grad_color = led.body.main_color; led.body.border.color = lv_color_hsv_to_rgb(_hue, 60, 60); led.body.shadow.color = lv_color_hsv_to_rgb(_hue, 100, 100); @@ -253,7 +240,7 @@ static void bar_init(void) static lv_style_t bar_bg, bar_indic; lv_style_copy(&bar_bg, &def); - bar_bg.body.main_color = COLOR_LIGHT_BORDER; + bar_bg.body.main_color = COLOR_BAR; bar_bg.body.grad_color = bar_bg.body.main_color; bar_bg.body.radius = 3; bar_bg.body.border.width = 0; @@ -402,7 +389,7 @@ static void calendar_init(void) static lv_style_t week_box; lv_style_copy(&week_box, &def); week_box.body.main_color = lv_color_hsv_to_rgb(_hue, 40, 100); - week_box.body.grad_color = lv_color_hsv_to_rgb(_hue, 40, 100); + week_box.body.grad_color = week_box.body.main_color; week_box.body.padding.ver = LV_DPI / 20; week_box.body.padding.hor = theme.panel->body.padding.hor; week_box.body.border.color = theme.panel->body.border.color; @@ -413,7 +400,7 @@ static void calendar_init(void) static lv_style_t today_box; lv_style_copy(&today_box, &def); today_box.body.main_color = LV_COLOR_WHITE; - today_box.body.grad_color = LV_COLOR_WHITE; + today_box.body.grad_color = today_box.body.main_color; today_box.body.padding.ver = LV_DPI / 20; today_box.body.radius = 0; @@ -541,7 +528,7 @@ static void mbox_init(void) lv_style_copy(&bg, theme.panel); bg.body.main_color = COLOR_BG_LIGHTER; bg.body.grad_color = bg.body.main_color; - bg.body.shadow.color = COLOR_BG; + bg.body.shadow.color = COLOR_SHADOW; bg.body.shadow.type = LV_SHADOW_FULL; bg.body.shadow.width = 8; @@ -617,13 +604,13 @@ static void list_init(void) rel.body.padding.hor = LV_DPI / 8; rel.body.padding.ver = LV_DPI / 6; rel.body.radius = 0; - rel.body.border.color = LV_COLOR_HEX(0x444444); + rel.body.border.color = COLOR_INACTIVE; rel.body.border.width = 1; rel.body.border.part = LV_BORDER_BOTTOM; lv_style_copy(&pr, &rel); pr.glass = 0; - pr.body.main_color = LV_COLOR_HEX(0x505050); + pr.body.main_color = COLOR_PRESS; pr.body.grad_color = pr.body.main_color; //pr.body.border.width = 1; pr.body.empty = 0; @@ -637,7 +624,7 @@ static void list_init(void) tgl_rel.text.color = COLOR_HOS_TEAL_LIGHTER; lv_style_copy(&tgl_pr, &tgl_rel); - tgl_pr.body.main_color = LV_COLOR_HEX(0x505050); + tgl_pr.body.main_color = COLOR_PRESS; tgl_pr.body.grad_color = tgl_pr.body.main_color; tgl_pr.body.border.width = 0; @@ -692,7 +679,7 @@ static void roller_init(void) roller_bg.text.line_space = LV_DPI / 8; roller_bg.text.font = _font; roller_bg.glass = 0; - roller_bg.text.color = LV_COLOR_HEX(0x444444); + roller_bg.text.color = COLOR_INACTIVE; lv_style_copy(&roller_sel, &roller_bg); roller_sel.text.color = COLOR_HOS_TURQUOISE; @@ -866,7 +853,6 @@ lv_theme_t * lv_theme_hekate_init(uint32_t bg_color, uint16_t hue, lv_font_t * f cont_init(); btn_init(); label_init(); - img_init(); line_init(); led_init(); bar_init(); diff --git a/bdk/libs/lvgl/lv_themes/lv_theme_hekate.h b/bdk/libs/lvgl/lv_themes/lv_theme_hekate.h index 45448b93..2481e027 100644 --- a/bdk/libs/lvgl/lv_themes/lv_theme_hekate.h +++ b/bdk/libs/lvgl/lv_themes/lv_theme_hekate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022 CTCaer + * Copyright (c) 2018-2026 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, @@ -35,14 +35,17 @@ extern "C" { /********************* * DEFINES *********************/ -#define COLOR_HOS_BG_BASE_DEFAULT 0x1B1B1B -#define COLOR_HOS_BG_BASE_BLACK 0x000000 +#define COLOR_BG_BASE_MIN 0x0B0B0B +#define COLOR_BG_BASE_MAX 0xC7C7C7 -#define COLOR_HOS_BG_DARKER 0x1B1B1B -#define COLOR_HOS_BG_DARK 0x222222 -#define COLOR_HOS_BG 0x2D2D2D -#define COLOR_HOS_BG_LIGHT 0x3D3D3D -#define COLOR_HOS_LIGHT_BORDER 0x4D4D4D +#define COLOR_HOS_BG_DARKER LV_COLOR_HEX(0x1B1B1B) +#define COLOR_HOS_BG_DARK LV_COLOR_HEX(0x222222) +#define COLOR_HOS_BG LV_COLOR_HEX(0x2D2D2D) +#define COLOR_HOS_BG_RGB 0x2D2D2D +#define COLOR_HOS_BG_LIGHT LV_COLOR_HEX(0x3D3D3D) +#define COLOR_HOS_BG_LIGHTER LV_COLOR_HEX(0x4D4D4D) + +#define COLOR_HOS_TURQUOISE_EX(hue) (hue ? lv_color_hsv_to_rgb(hue, 100, 100) : lv_color_hsv_to_rgb(53, 8, 90)) // 0x00FFC9 /********************** * TYPEDEFS diff --git a/bdk/mem/heap.c b/bdk/mem/heap.c index 430cf22f..33c4c4bb 100644 --- a/bdk/mem/heap.c +++ b/bdk/mem/heap.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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/bdk/mem/mc.c b/bdk/mem/mc.c index 52552142..2dd56baf 100644 --- a/bdk/mem/mc.c +++ b/bdk/mem/mc.c @@ -107,13 +107,13 @@ void mc_config_carveout_hos() } // SDMMC, TSEC, XUSB and probably more need it to access < DRAM_START. -void mc_enable_ahb_redirect() +void mc_enable_ahb_redirect(u32 offset) { // Bypass ARC clock gating. CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRD) |= BIT(19); //MC(MC_IRAM_REG_CTRL) &= ~BIT(0); MC(MC_IRAM_BOM) = IRAM_BASE; - MC(MC_IRAM_TOM) = DRAM_START; // Default is only IRAM: 0x4003F000. + MC(MC_IRAM_TOM) = DRAM_START - offset; // Default is only IRAM: 0x4003F000. } void mc_disable_ahb_redirect() @@ -149,9 +149,6 @@ void mc_enable() CLOCK(CLK_RST_CONTROLLER_RST_DEV_H_CLR) = BIT(CLK_H_EMC) | BIT(CLK_H_MEM); usleep(5); -#ifdef BDK_MC_ENABLE_AHB_REDIRECT - mc_enable_ahb_redirect(); -#else - mc_disable_ahb_redirect(); -#endif + // Enable redirection by default. + mc_enable_ahb_redirect(1); } diff --git a/bdk/mem/mc.h b/bdk/mem/mc.h index 05a8ad9e..b20a39f9 100644 --- a/bdk/mem/mc.h +++ b/bdk/mem/mc.h @@ -22,7 +22,7 @@ void mc_config_tsec_carveout(u32 bom, u32 size1mb, bool lock); void mc_config_carveout_hos(); -void mc_enable_ahb_redirect(); +void mc_enable_ahb_redirect(u32 offset); void mc_disable_ahb_redirect(); bool mc_client_has_access(void *address); void mc_enable(); diff --git a/bdk/mem/minerva.c b/bdk/mem/minerva.c index 583fc9b0..7e9aa925 100644 --- a/bdk/mem/minerva.c +++ b/bdk/mem/minerva.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2025 CTCaer + * Copyright (c) 2019-2026 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, @@ -37,7 +37,7 @@ static bool no_table = false; static mtc_config_t *mtc_cfg = NULL; void (*mtc_call)(mtc_config_t *mtc_cfg, void *); -u32 minerva_init(minerva_str_t *mtc_str) +int minerva_init(minerva_str_t *mtc_str) { mtc_call = NULL; mtc_cfg = (mtc_config_t *)&mtc_str->mtc_cfg; @@ -52,8 +52,7 @@ u32 minerva_init(minerva_str_t *mtc_str) { // Load library and do a periodic training if needed. mtc_cfg->train_mode = OP_PERIODIC_TRAIN; - u32 ep_addr = ianos_loader("bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)mtc_cfg); - mtc_call = (void *)ep_addr; + mtc_call = (void *)ianos_static_module("bootloader/sys/libsys_minerva.bso", (void *)mtc_cfg); return !mtc_call ? 1 : 0; } @@ -67,7 +66,7 @@ u32 minerva_init(minerva_str_t *mtc_str) mtc_tmp.init_done = !no_table ? MTC_NEW_MAGIC : MTC_IRB_MAGIC; // Load library and get table. - u32 ep_addr = ianos_loader("bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_tmp); + u32 ep_addr = ianos_static_module("bootloader/sys/libsys_minerva.bso", (void *)&mtc_tmp); // Ensure that Minerva is initialized. if (mtc_tmp.init_done == MTC_INIT_MAGIC) @@ -88,7 +87,7 @@ u32 minerva_init(minerva_str_t *mtc_str) mtc_cfg->sdram_id = fuse_read_dramid(false); mtc_cfg->init_done = !no_table ? MTC_NEW_MAGIC : MTC_IRB_MAGIC; - u32 ep_addr = ianos_loader("bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)mtc_cfg); + u32 ep_addr = ianos_static_module("bootloader/sys/libsys_minerva.bso", (void *)mtc_cfg); // Ensure that Minerva is initialized. if (mtc_cfg->init_done == MTC_INIT_MAGIC) diff --git a/bdk/mem/minerva.h b/bdk/mem/minerva.h index 96dfa689..a0611c18 100644 --- a/bdk/mem/minerva.h +++ b/bdk/mem/minerva.h @@ -72,7 +72,7 @@ typedef enum } minerva_freq_t; extern void (*minerva_cfg)(mtc_config_t *mtc_cfg, void *); -u32 minerva_init(minerva_str_t *mtc_str); +int minerva_init(minerva_str_t *mtc_str); void minerva_deinit(); void minerva_change_freq(minerva_freq_t freq); void minerva_sdmmc_la_program(void *table, bool t210b01); diff --git a/bdk/mem/sdram.c b/bdk/mem/sdram.c index 427f75ae..052beeaf 100644 --- a/bdk/mem/sdram.c +++ b/bdk/mem/sdram.c @@ -85,9 +85,9 @@ static const u8 dram_encoding_t210b01[] = { #include "sdram_config.inl" #include "sdram_config_t210b01.inl" -static bool _sdram_wait_emc_status(u32 reg_offset, u32 bit_mask, bool updated_state, s32 emc_channel) +static int _sdram_wait_emc_status(u32 reg_offset, u32 bit_mask, bool updated_state, s32 emc_channel) { - bool err = true; + int err = 1; for (s32 i = 0; i < EMC_STATUS_UPDATE_TIMEOUT; i++) { @@ -98,13 +98,13 @@ static bool _sdram_wait_emc_status(u32 reg_offset, u32 bit_mask, bool updated_st if (((EMC_CH1(reg_offset) & bit_mask) != 0) == updated_state) { - err = false; + err = 0; break; } } else if (((EMC(reg_offset) & bit_mask) != 0) == updated_state) { - err = false; + err = 0; break; } usleep(1); diff --git a/bdk/mem/sdram_config.inl b/bdk/mem/sdram_config.inl index 7f9a8f59..0c68b017 100644 --- a/bdk/mem/sdram_config.inl +++ b/bdk/mem/sdram_config.inl @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2020-2025 CTCaer + * Copyright (c) 2020-2026 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, @@ -497,7 +497,7 @@ static const sdram_params_t210_t _dram_cfg_0_samsung_4gb = { .mc_emem_adr_cfg_bank_mask2 = 0x4B9C1000, /* * Specifies the value for MC_EMEM_CFG which holds the external memory - * size (in KBytes) + * size (in MBytes) */ .mc_emem_cfg = 0x00001000, // 4GB total density. Max 8GB. @@ -685,5 +685,7 @@ static const sdram_vendor_patch_t sdram_cfg_vendor_patches_t210[] = { { 0x00080302, DRAM_ID(LPDDR4_ICOSA_8GB_SAMSUNG_K4FBE3D4HM_MGXX), DCFG_OFFSET_OF(mc_emem_adr_cfg_dev0) }, // 1024MB Chip 0 density. { 0x00080302, DRAM_ID(LPDDR4_ICOSA_8GB_SAMSUNG_K4FBE3D4HM_MGXX), DCFG_OFFSET_OF(mc_emem_adr_cfg_dev1) }, // 1024MB Chip 1 density. { 0x00002000, DRAM_ID(LPDDR4_ICOSA_8GB_SAMSUNG_K4FBE3D4HM_MGXX), DCFG_OFFSET_OF(mc_emem_cfg) }, // 8GB total density. Max 8GB. + { 0x00000007, DRAM_ID(LPDDR4_ICOSA_8GB_SAMSUNG_K4FBE3D4HM_MGXX), DCFG_OFFSET_OF(mc_emem_arb_timing_rfcpb) }, + { 0x72A30504, DRAM_ID(LPDDR4_ICOSA_8GB_SAMSUNG_K4FBE3D4HM_MGXX), DCFG_OFFSET_OF(mc_emem_arb_misc0) }, }; #undef DCFG_OFFSET_OF diff --git a/bdk/mem/sdram_config_t210b01.inl b/bdk/mem/sdram_config_t210b01.inl index 0aa8fea0..2ca469c4 100644 --- a/bdk/mem/sdram_config_t210b01.inl +++ b/bdk/mem/sdram_config_t210b01.inl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2025 CTCaer + * Copyright (c) 2020-2026 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, @@ -550,7 +550,7 @@ static const sdram_params_t210b01_t _dram_cfg_08_10_12_14_samsung_hynix_4gb = { .mc_emem_adr_cfg_bank_mask2 = 0x4B9C1000, /* * Specifies the value for MC_EMEM_CFG which holds the external memory - * size (in KBytes) + * size (in MBytes) */ .mc_emem_cfg = 0x00001000, // 4GB total density. Max 8GB. diff --git a/bdk/mem/smmu.c b/bdk/mem/smmu.c index dff576d9..f8dcf414 100644 --- a/bdk/mem/smmu.c +++ b/bdk/mem/smmu.c @@ -156,6 +156,7 @@ void smmu_disable() smmu_enable_payload[SMMU_PAYLOAD_EN_SHIFT] = SMMU_PAYLOAD_EN_SET; smmu_enabled = false; + smmu_heap = (void *)SMMU_HEAP_ADDR; } void smmu_reset_heap() @@ -163,7 +164,7 @@ void smmu_reset_heap() smmu_heap = (void *)SMMU_HEAP_ADDR; } -void *smmu_init_domain(u32 dev_base, u32 asid) +void *smmu_domain_init(u32 dev_base, u32 asid) { void *ptb = _smmu_pdir_alloc(); @@ -178,7 +179,7 @@ void *smmu_init_domain(u32 dev_base, u32 asid) return ptb; } -void smmu_deinit_domain(u32 dev_base, u32 asid) +void smmu_domain_deinit(u32 dev_base, u32 asid) { MC(MC_SMMU_PTB_ASID) = asid; MC(MC_SMMU_PTB_DATA) = 0; diff --git a/bdk/mem/smmu.h b/bdk/mem/smmu.h index 243089be..07a283f1 100644 --- a/bdk/mem/smmu.h +++ b/bdk/mem/smmu.h @@ -15,9 +15,11 @@ * along with this program. If not, see . */ -#include +#ifndef _SMMU_H_ +#define _SMMU_H_ #include +#include #define MC_SMMU_AVPC_ASID 0x23C #define MC_SMMU_TSEC_ASID 0x294 @@ -65,8 +67,10 @@ void smmu_init(); void smmu_enable(); void smmu_disable(); void smmu_reset_heap(); -void *smmu_init_domain(u32 dev_base, u32 asid); -void smmu_deinit_domain(u32 dev_base, u32 asid); +void *smmu_domain_init(u32 dev_base, u32 asid); +void smmu_domain_deinit(u32 dev_base, u32 asid); void smmu_domain_bypass(u32 dev_base, bool bypass); void smmu_map(void *ptb, u32 iova, u64 iopa, u32 pages, u32 attr); void smmu_map_huge(void *ptb, u32 iova, u64 iopa, u32 regions, u32 attr); + +#endif diff --git a/bdk/memory_map.h b/bdk/memory_map.h index b5159464..944c3770 100644 --- a/bdk/memory_map.h +++ b/bdk/memory_map.h @@ -29,6 +29,7 @@ #define SECMON_MIN_START 0x4002B000 // Minimum reserved address for secmon. #define SDRAM_PARAMS_ADDR 0x40030000 // SDRAM extraction buffer during sdram init. +#define SDRAM_PARAMS_SZ 0x838 /* start.S / exception_handlers.S */ #define SYS_STACK_TOP_INIT 0x4003FF00 @@ -36,7 +37,7 @@ #define IRQ_STACK_TOP 0x40040000 #define IPL_RELOC_ADDR 0x4003FF00 #define IPL_RELOC_SZ 0x10 -#define EXCP_STORAGE_ADDR 0x4003FFF0 +#define EXCP_STORAGE_ADDR 0x4003FF10 #define EXCP_STORAGE_SZ 0x10 /* --- DRAM START --- */ @@ -71,9 +72,9 @@ //#define DRAM_LIB_ADDR 0xE0000000 /* --- Chnldr: 252MB 0xC03C0000 - 0xCFFFFFFF --- */ //! Only used when chainloading. -// SDMMC DMA buffers 1 -#define SDMMC_UPPER_BUFFER 0xE5000000 -#define SDMMC_UP_BUF_SZ SZ_128M +// SDMMC DMA buffer. Used for unaligned DMA buffer address. +#define SDMMC_ALT_DMA_BUFFER 0xE5000000 +#define SDMMC_ALT_DMA_BUF_SZ SZ_128M // Nyx buffers. !Do not change! #define NYX_STORAGE_ADDR 0xED000000 @@ -81,10 +82,10 @@ #define NYX_RES_ADDR 0xEE000000 #define NYX_RES_SZ SZ_16M -// SDMMC DMA buffers 2 -#define SDXC_BUF_ALIGNED 0xEF000000 -#define MIXD_BUF_ALIGNED 0xF0000000 -#define EMMC_BUF_ALIGNED MIXD_BUF_ALIGNED +// SDMMC Application DMA aligned buffers. +#define SDXC_BUF_ALIGNED 0xEF000000 // Also used by UMS. +#define EMMC_BUF_ALIGNED 0xF0000000 +#define MIXD_BUF_ALIGNED EMMC_BUF_ALIGNED #define SDMMC_DMA_BUF_SZ SZ_16M // 4MB currently used. // Nyx LvGL buffers. diff --git a/bdk/module.h b/bdk/module.h index acc048c3..59fbfa15 100644 --- a/bdk/module.h +++ b/bdk/module.h @@ -1,6 +1,7 @@ /* * Common Module Header * Copyright (c) 2018 M4xw + * Copyright (c) 2018-2026 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, @@ -21,7 +22,7 @@ #include #include -#define IANOS_EXT0 0x304E4149 +#define IANOS_EXT1 0x314E4149 // Module Callback typedef void (*cbMainModule_t)(const char *s); @@ -31,16 +32,15 @@ typedef int (*reg_voltage_set_t)(u32, u32); typedef struct _bdkParams_t { - void *gfxCon; - void *gfxCtx; - heap_t *sharedHeap; + void *gfx_con; + void *gfx_ctx; + heap_t *heap; memcpy_t memcpy; memset_t memset; u32 extension_magic; - reg_voltage_set_t reg_voltage_set; -} *bdkParams_t; +} bdk_params_t; -// Module Entrypoint -typedef void (*moduleEntrypoint_t)(void *, bdkParams_t); +// Module Caller. +typedef void (*moduleEntrypoint)(void *, bdk_params_t *); #endif diff --git a/bdk/power/bm92t36.c b/bdk/power/bm92t36.c index a95730bb..39b65dd4 100644 --- a/bdk/power/bm92t36.c +++ b/bdk/power/bm92t36.c @@ -1,7 +1,7 @@ /* * USB-PD driver for Nintendo Switch's TI BM92T36 * - * Copyright (c) 2020-2025 CTCaer + * Copyright (c) 2020-2026 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, @@ -55,9 +55,14 @@ #define STATUS1_INSERT BIT(7) // Cable inserted. #define VER_36 0x36 -#define MAX_ROHM 0x4B5 +#define MAN_ROHM 0x4B5 #define DEV_BM92T 0x3B0 +#define PDO_TYPE_FIXED 0 +#define PDO_TYPE_BATT 1 +#define PDO_TYPE_VAR 2 +#define PDO_TYPE_APDO 3 + typedef struct _pd_object_t { unsigned int amp:10; unsigned int volt:10; @@ -84,13 +89,13 @@ int bm92t36_get_version(u32 *value) if (value) *value = (dev << 16) | version; - if (version == VER_36 && man == MAX_ROHM && dev == DEV_BM92T) + if (version == VER_36 && man == MAN_ROHM && dev == DEV_BM92T) return 0; else - return -1; + return 1; } -void bm92t36_get_sink_info(bool *inserted, usb_pd_objects_t *usb_pd) +void bm92t36_get_source_info(bool *inserted, usb_pd_objects_t *usb_pd) { u8 buf[32]; pd_object_t pdos[7]; @@ -112,15 +117,22 @@ void bm92t36_get_sink_info(bool *inserted, usb_pd_objects_t *usb_pd) if (usb_pd->pdo_no > 7) usb_pd->pdo_no = 7; + u32 idx = 0; for (u32 i = 0; i < usb_pd->pdo_no; i++) { - usb_pd->pdos[i].amperage = pdos[i].amp * 10; - usb_pd->pdos[i].voltage = (pdos[i].volt * 50) / 1000; + // Parse fixed type pdos only. + if (pdos[i].type != PDO_TYPE_FIXED) + continue; + + usb_pd->pdos[idx].amperage = pdos[i].amp * 10; + usb_pd->pdos[idx].voltage = (pdos[i].volt * 50) / 1000; + idx++; } + usb_pd->pdo_no = idx; _bm92t36_read_reg(buf, 5, CURRENT_PDO_REG); memcpy(pdos, &buf[1], 4); - usb_pd->selected_pdo.amperage = pdos[0].amp * 10; - usb_pd->selected_pdo.voltage = (pdos[0].volt * 50) / 1000; + usb_pd->selected_pdo.amperage = pdos[0].amp * 10; + usb_pd->selected_pdo.voltage = (pdos[0].volt * 50) / 1000; } } diff --git a/bdk/power/bm92t36.h b/bdk/power/bm92t36.h index c288a6fc..4ff0791e 100644 --- a/bdk/power/bm92t36.h +++ b/bdk/power/bm92t36.h @@ -37,6 +37,6 @@ typedef struct _usb_pd_objects_t } usb_pd_objects_t; int bm92t36_get_version(u32 *value); -void bm92t36_get_sink_info(bool *inserted, usb_pd_objects_t *usb_pd); +void bm92t36_get_source_info(bool *inserted, usb_pd_objects_t *usb_pd); #endif diff --git a/bdk/power/bq24193.c b/bdk/power/bq24193.c index 73b31f1f..ea4d5825 100644 --- a/bdk/power/bq24193.c +++ b/bdk/power/bq24193.c @@ -34,7 +34,7 @@ int bq24193_get_version(u32 *value) if (data == 0x2F) return 0; else - return -1; + return 1; } int bq24193_get_property(enum BQ24193_reg_prop prop, int *value) @@ -162,7 +162,7 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value) *value = (data & BQ24193_VENDORPART_PN_MASK) >> 3; break; default: - return -1; + return 1; } return 0; } diff --git a/bdk/power/max17050.c b/bdk/power/max17050.c index 468bad75..d4c868ac 100644 --- a/bdk/power/max17050.c +++ b/bdk/power/max17050.c @@ -69,7 +69,7 @@ int max17050_get_version(u32 *value) if (data == 0x00AC) return 0; else - return -1; + return 1; } int max17050_get_property(enum MAX17050_reg reg, int *value) @@ -138,7 +138,7 @@ int max17050_get_property(enum MAX17050_reg reg, int *value) *value = (int)(s16)data * 15625 / ADJ_RSENSE_MOHM / 10; /* Units of LSB = 1.5625uV / Rsense = 156.25uA */ break; default: - return -1; + return 1; } return 0; } @@ -147,18 +147,14 @@ static int _max17050_write_verify_reg(u8 reg, u16 value) { int retries = 8; int ret; - u16 read_value; do { ret = i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, reg, (u8 *)&value, 2); - read_value = max17050_get_reg(reg); - if (read_value != value) - { - ret = -1; - retries--; - } - } while (retries && read_value != value); + u16 read_value = max17050_get_reg(reg); + if (!ret && read_value == value) + break; + } while (--retries); return ret; } @@ -251,7 +247,7 @@ static void _max17050_set_por_bit(u16 value) _max17050_write_verify_reg(MAX17050_STATUS, value); } -int max17050_fix_configuration() +void max17050_fix_configuration() { /* Init phase, set the POR bit */ _max17050_set_por_bit(STATUS_POR_BIT); @@ -285,8 +281,6 @@ int max17050_fix_configuration() // Sets POR, BI, BR. _max17050_set_por_bit(0x8801); - - return 0; } void max17050_dump_regs(void *buf) diff --git a/bdk/power/max17050.h b/bdk/power/max17050.h index 25555b4f..acb1338a 100644 --- a/bdk/power/max17050.h +++ b/bdk/power/max17050.h @@ -121,7 +121,7 @@ enum MAX17050_reg { int max17050_get_version(u32 *value); int max17050_get_property(enum MAX17050_reg reg, int *value); -int max17050_fix_configuration(); +void max17050_fix_configuration(); void max17050_dump_regs(void *buf); #endif /* __MAX17050_H_ */ diff --git a/bdk/power/max7762x.c b/bdk/power/max7762x.c index f0aefb5a..fa087052 100644 --- a/bdk/power/max7762x.c +++ b/bdk/power/max7762x.c @@ -137,7 +137,7 @@ static void _max7762x_set_reg(u8 addr, u8 reg, u8 val) u32 retries = 100; while (retries) { - if (i2c_send_byte(I2C_5, addr, reg, val)) + if (!i2c_send_byte(I2C_5, addr, reg, val)) break; usleep(50); @@ -166,7 +166,7 @@ int max77620_regulator_get_status(u32 id) int max77620_regulator_config_fps(u32 id) { if (id > REGULATOR_LDO8) - return 0; + return 1; const max77620_regulator_t *reg = &_pmic_regulators[id]; @@ -177,22 +177,22 @@ int max77620_regulator_config_fps(u32 id) (reg->fps.pu_period << MAX77620_FPS_PU_PERIOD_SHIFT) | (reg->fps.pd_period << MAX77620_FPS_PD_PERIOD_SHIFT)); - return 1; + return 0; } int max7762x_regulator_set_voltage(u32 id, u32 uv) { if (id > REGULATOR_MAX) - return 0; + return 1; const max77620_regulator_t *reg = &_pmic_regulators[id]; if (uv < reg->uv_min || uv > reg->uv_max) - return 0; + return 1; u8 addr = _max7762x_get_i2c_address(id); if (!addr) - return 0; + return 1; // Calculate voltage multiplier. u32 mult = (uv + reg->uv_step - 1 - reg->uv_min) / reg->uv_step; @@ -209,7 +209,7 @@ int max7762x_regulator_set_voltage(u32 id, u32 uv) // Wait for ramp up/down delay. usleep(1000); - return 1; + return 0; } int max7762x_regulator_enable(u32 id, bool enable) @@ -220,7 +220,7 @@ int max7762x_regulator_enable(u32 id, bool enable) u8 enable_shift; if (id > REGULATOR_MAX) - return 0; + return 1; const max77620_regulator_t *reg = &_pmic_regulators[id]; @@ -252,12 +252,12 @@ int max7762x_regulator_enable(u32 id, bool enable) enable_shift = reg->enable.shift; break; default: - return 0; + return 1; } u8 addr = _max7762x_get_i2c_address(id); if (!addr) - return 0; + return 1; // Read and enable/disable. u8 val = i2c_recv_byte(I2C_5, addr, reg_addr); @@ -272,7 +272,7 @@ int max7762x_regulator_enable(u32 id, bool enable) // Wait for enable/disable ramp delay. usleep(1000); - return 1; + return 0; } void max77620_config_gpio(u32 gpio_id, bool enable) diff --git a/bdk/sec/se.c b/bdk/sec/se.c index ceabd8ca..bdfafea4 100644 --- a/bdk/sec/se.c +++ b/bdk/sec/se.c @@ -88,7 +88,7 @@ static int _se_op_wait() (SE(SE_ERR_STATUS_REG) != 0) ) { - return 0; + return 1; } // WAR: Coherency flushing. @@ -104,7 +104,7 @@ static int _se_op_wait() while (SE(SE_STATUS_REG) & SE_STATUS_MEM_IF_BUSY) { if (!retries) - return 0; + return 1; usleep(1); retries--; } @@ -115,13 +115,13 @@ static int _se_op_wait() while (AHB_GIZMO(AHB_ARBITRATION_AHB_MEM_WRQUE_MST_ID) & MEM_WRQUE_SE_MST_ID) { if (!retries) - return 0; + return 1; usleep(1); retries--; } } - return 1; + return 0; } static int _se_execute_finalize() @@ -137,7 +137,7 @@ static int _se_execute_finalize() static int _se_execute(u32 op, void *dst, u32 dst_size, const void *src, u32 src_size, bool is_oneshot) { if (dst_size > SE_LL_MAX_SIZE || src_size > SE_LL_MAX_SIZE) - return 0; + return 1; ll_src_ptr = NULL; ll_dst_ptr = NULL; @@ -170,7 +170,7 @@ static int _se_execute(u32 op, void *dst, u32 dst_size, const void *src, u32 src if (is_oneshot) return _se_execute_finalize(); - return 1; + return 0; } static int _se_execute_oneshot(u32 op, void *dst, u32 dst_size, const void *src, u32 src_size) @@ -186,7 +186,7 @@ static int _se_execute_aes_oneshot(void *dst, const void *src, u32 size) u32 size_aligned = ALIGN_DOWN(size, SE_AES_BLOCK_SIZE); u32 size_residue = size % SE_AES_BLOCK_SIZE; - int res = 1; + int res = 0; // Handle initial aligned message. if (size_aligned) @@ -197,7 +197,7 @@ static int _se_execute_aes_oneshot(void *dst, const void *src, u32 size) } // Handle leftover partial message. - if (res && size_residue) + if (!res && size_residue) { // Copy message to a block sized buffer in case it's partial. u32 block[SE_AES_BLOCK_SIZE / sizeof(u32)] = {0}; @@ -380,7 +380,6 @@ int se_aes_crypt_ctr(u32 ks, void *dst, const void *src, u32 size, void *ctr) int se_aes_crypt_xts_sec(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, void *dst, void *src, u32 secsize) { - int res = 0; u32 tmp[SE_AES_BLOCK_SIZE / sizeof(u32)]; u8 *tweak = (u8 *)tmp; u8 *pdst = (u8 *)dst; @@ -392,27 +391,27 @@ int se_aes_crypt_xts_sec(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, void *dst tweak[i] = sec & 0xFF; sec >>= 8; } - if (!se_aes_crypt_ecb(tweak_ks, ENCRYPT, tweak, tweak, SE_AES_BLOCK_SIZE)) - goto out; + if (se_aes_crypt_ecb(tweak_ks, ENCRYPT, tweak, tweak, SE_AES_BLOCK_SIZE)) + return 1; // We are assuming a 0x10-aligned sector size in this implementation. for (u32 i = 0; i < secsize / SE_AES_BLOCK_SIZE; i++) { for (u32 j = 0; j < SE_AES_BLOCK_SIZE; j++) pdst[j] = psrc[j] ^ tweak[j]; - if (!se_aes_crypt_ecb(crypt_ks, enc, pdst, pdst, SE_AES_BLOCK_SIZE)) - goto out; + + if (se_aes_crypt_ecb(crypt_ks, enc, pdst, pdst, SE_AES_BLOCK_SIZE)) + return 1; + for (u32 j = 0; j < SE_AES_BLOCK_SIZE; j++) pdst[j] = pdst[j] ^ tweak[j]; + _se_ls_1bit(tweak); psrc += SE_AES_BLOCK_SIZE; pdst += SE_AES_BLOCK_SIZE; } - res = 1; - -out: - return res; + return 0; } int se_aes_crypt_xts_sec_nx(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, u8 *tweak, bool regen_tweak, u32 tweak_exp, void *dst, void *src, u32 sec_size) @@ -428,8 +427,8 @@ int se_aes_crypt_xts_sec_nx(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, u8 *tw tweak[i] = sec & 0xFF; sec >>= 8; } - if (!se_aes_crypt_ecb(tweak_ks, ENCRYPT, tweak, tweak, SE_AES_BLOCK_SIZE)) - return 0; + if (se_aes_crypt_ecb(tweak_ks, ENCRYPT, tweak, tweak, SE_AES_BLOCK_SIZE)) + return 1; } // tweak_exp allows using a saved tweak to reduce _se_ls_1bit_le calls. @@ -450,8 +449,8 @@ int se_aes_crypt_xts_sec_nx(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, u8 *tw pdst += sizeof(u32); } - if (!se_aes_crypt_ecb(crypt_ks, enc, dst, dst, sec_size)) - return 0; + if (se_aes_crypt_ecb(crypt_ks, enc, dst, dst, sec_size)) + return 1; pdst = (u32 *)dst; ptweak = (u32 *)orig_tweak; @@ -464,7 +463,7 @@ int se_aes_crypt_xts_sec_nx(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, u8 *tw pdst += sizeof(u32); } - return 1; + return 0; } int se_aes_crypt_xts(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, void *dst, void *src, u32 secsize, u32 num_secs) @@ -473,10 +472,10 @@ int se_aes_crypt_xts(u32 tweak_ks, u32 crypt_ks, int enc, u64 sec, void *dst, vo u8 *psrc = (u8 *)src; for (u32 i = 0; i < num_secs; i++) - if (!se_aes_crypt_xts_sec(tweak_ks, crypt_ks, enc, sec + i, pdst + secsize * i, psrc + secsize * i, secsize)) - return 0; + if (se_aes_crypt_xts_sec(tweak_ks, crypt_ks, enc, sec + i, pdst + secsize * i, psrc + secsize * i, secsize)) + return 1; - return 1; + return 0; } static void _se_sha_hash_256_get_hash(void *hash) @@ -498,7 +497,7 @@ static int _se_sha_hash_256(void *hash, u64 total_size, const void *src, u32 src 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C, 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55 }; memcpy(hash, null_hash, SE_SHA_256_SIZE); - return 1; + return 0; } // Increase leftover size if not last message. (Engine will always stop at src_size.) @@ -530,7 +529,7 @@ static int _se_sha_hash_256(void *hash, u64 total_size, const void *src, u32 src // Trigger the operation. src vs total size decides if it's partial. int res = _se_execute(SE_OP_START, NULL, 0, src, src_size, is_oneshot); - if (res && is_oneshot) + if (!res && is_oneshot) _se_sha_hash_256_get_hash(hash); return res; @@ -550,7 +549,7 @@ int se_sha_hash_256_partial_start(void *hash, const void *src, u32 size, bool is { // Check if aligned SHA256 block size. if (size % SE_SHA2_MIN_BLOCK_SIZE) - return 0; + return 1; return _se_sha_hash_256(hash, 0, src, size, is_oneshot); } @@ -559,7 +558,7 @@ int se_sha_hash_256_partial_update(void *hash, const void *src, u32 size, bool i { // Check if aligned to SHA256 block size. if (size % SE_SHA2_MIN_BLOCK_SIZE) - return 0; + return 1; return _se_sha_hash_256(hash, size - 1, src, size, is_oneshot); } @@ -600,7 +599,7 @@ int se_rng_pseudo(void *dst, u32 size) } // Handle leftover partial message. - if (res && size_residue) + if (!res && size_residue) { // Copy message to a block sized buffer in case it's partial. u32 block[SE_RNG_BLOCK_SIZE / sizeof(u32)] = {0}; @@ -610,8 +609,7 @@ int se_rng_pseudo(void *dst, u32 size) res = _se_execute_oneshot(SE_OP_START, block, SE_RNG_BLOCK_SIZE, NULL, 0); // Copy result back. - if (res) - memcpy(dst + size_aligned, block, size_residue); + memcpy(dst + size_aligned, block, size_residue); } return res; @@ -682,8 +680,8 @@ int se_aes_hash_cmac(u32 ks, void *hash, const void *src, u32 size) // Generate sub key (CBC with zeroed IV, basically ECB). se_aes_iv_clear(ks); - if (!se_aes_crypt_cbc(ks, ENCRYPT, subkey, subkey, SE_KEY_128_SIZE)) - return 0; + if (se_aes_crypt_cbc(ks, ENCRYPT, subkey, subkey, SE_KEY_128_SIZE)) + return 1; // Generate K1 subkey. _se_ls_1bit(subkey); @@ -700,8 +698,8 @@ int se_aes_hash_cmac(u32 ks, void *hash, const void *src, u32 size) { SE(SE_CRYPTO_LAST_BLOCK_REG) = num_blocks - 2; - if (!_se_execute_oneshot(SE_OP_START, NULL, 0, src, size)) - return 0; + if (_se_execute_oneshot(SE_OP_START, NULL, 0, src, size)) + return 1; // Use updated IV for next OP as a continuation. SE(SE_CRYPTO_CONFIG_REG) |= SE_CRYPTO_IV_SEL(IV_UPDATED); @@ -721,15 +719,13 @@ int se_aes_hash_cmac(u32 ks, void *hash, const void *src, u32 size) SE(SE_CRYPTO_LAST_BLOCK_REG) = (SE_AES_BLOCK_SIZE >> 4) - 1; - int res = _se_execute_oneshot(SE_OP_START, NULL, 0, last_block, SE_AES_BLOCK_SIZE); + if (_se_execute_oneshot(SE_OP_START, NULL, 0, last_block, SE_AES_BLOCK_SIZE)) + return 1; // Copy output hash. - if (res) - { - u32 *hash32 = (u32 *)hash; - for (u32 i = 0; i < (SE_AES_CMAC_DIGEST_SIZE / sizeof(u32)); i++) - hash32[i] = SE(SE_HASH_RESULT_REG + sizeof(u32) * i); - } + u32 *hash32 = (u32 *)hash; + for (u32 i = 0; i < (SE_AES_CMAC_DIGEST_SIZE / sizeof(u32)); i++) + hash32[i] = SE(SE_HASH_RESULT_REG + sizeof(u32) * i); - return res; + return 0; } diff --git a/bdk/sec/tsec.c b/bdk/sec/tsec.c index 405fae51..03511948 100644 --- a/bdk/sec/tsec.c +++ b/bdk/sec/tsec.c @@ -44,9 +44,9 @@ static int _tsec_dma_wait_idle() while (!(TSEC(TSEC_DMATRFCMD) & TSEC_DMATRFCMD_IDLE)) if (get_tmr_ms() > timeout) - return 0; + return 1; - return 1; + return 0; } static int _tsec_dma_pa_to_internal_100(int not_imem, int i_offset, int pa_offset) @@ -97,7 +97,7 @@ int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt) pmc_domain_pwrgate_set(POWER_RAIL_CE3, DISABLE); // Enable AHB aperture and set it to full mmio. - mc_enable_ahb_redirect(); + mc_enable_ahb_redirect(0); } // Configure Falcon. @@ -116,7 +116,7 @@ int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt) TSEC_IRQDEST_SWGEN0 | TSEC_IRQDEST_SWGEN1; TSEC(TSEC_ITFEN) = TSEC_ITFEN_CTXEN | TSEC_ITFEN_MTHDEN; - if (!_tsec_dma_wait_idle()) + if (_tsec_dma_wait_idle()) { res = -1; goto out; @@ -136,7 +136,7 @@ int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt) for (u32 addr = 0; addr < tsec_ctxt->size; addr += 0x100) { - if (!_tsec_dma_pa_to_internal_100(false, addr, addr)) + if (_tsec_dma_pa_to_internal_100(false, addr, addr)) { res = -2; goto out_free; @@ -146,7 +146,7 @@ int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt) if (type == TSEC_FW_TYPE_EMU) { // Init SMMU translation for TSEC. - ptb = smmu_init_domain(MC_SMMU_TSEC_ASID, 1); + ptb = smmu_domain_init(MC_SMMU_TSEC_ASID, 1); smmu_init(); // Enable SMMU. @@ -230,7 +230,7 @@ int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt) if (kidx != 8) { res = -6; - smmu_deinit_domain(MC_SMMU_TSEC_ASID, 1); + smmu_domain_deinit(MC_SMMU_TSEC_ASID, 1); goto out_free; } @@ -241,7 +241,7 @@ int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt) memcpy(tsec_keys, &key, 0x20); memcpy(tsec_ctxt->pkg1, iram, 0x30000); - smmu_deinit_domain(MC_SMMU_TSEC_ASID, 1); + smmu_domain_deinit(MC_SMMU_TSEC_ASID, 1); // for (int i = 0; i < kidx; i++) // gfx_printf("key %08X\n", key[i]); @@ -257,7 +257,7 @@ int tsec_query(void *tsec_keys, tsec_ctxt_t *tsec_ctxt) } else { - if (!_tsec_dma_wait_idle()) + if (_tsec_dma_wait_idle()) { res = -3; goto out_free; @@ -307,10 +307,8 @@ out: bpmp_mmu_enable(); bpmp_clk_rate_relaxed(false); -#ifdef BDK_MC_ENABLE_AHB_REDIRECT // Re-enable AHB aperture. - mc_enable_ahb_redirect(); -#endif + mc_enable_ahb_redirect(1); return res; } diff --git a/bdk/soc/bpmp.h b/bdk/soc/bpmp.h index cffec232..1864538e 100644 --- a/bdk/soc/bpmp.h +++ b/bdk/soc/bpmp.h @@ -51,7 +51,7 @@ typedef enum BPMP_CLK_SUPER_BOOST, // 576MHz 41% - 144MHz APB. BPMP_CLK_HYPER_BOOST, // 589MHz 44% - 147MHz APB. //BPMP_CLK_DEV_BOOST, // 608MHz 49% - 152MHz APB. - BPMP_CLK_NUM + BPMP_CLK_NUM } bpmp_freq_t; typedef enum diff --git a/bdk/soc/clock.c b/bdk/soc/clock.c index bec3b1b0..84e4c7af 100644 --- a/bdk/soc/clock.c +++ b/bdk/soc/clock.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -89,14 +89,14 @@ static const clk_rst_t _clock_uart[] = { { RST_DEV_Y_SET, CLK_ENB_Y_SET, CLK_RST_CONTROLLER_CLK_SOURCE_UARTAPE, CLK_Y_UARTAPE, 0, CLK_SRC_DIV(2) } }; -//I2C default parameters - TLOW: 4, THIGH: 2, DEBOUNCE: 0, FM_DIV: 26. +// I2C Fout = Fin / (TLOW + THIGH + 2) / FM_DIV). Default parameters - TLOW: 4, THIGH: 2, DEBOUNCE: 0, FM_DIV: 6. static const clk_rst_t _clock_i2c[] = { - { RST_DEV_L_SET, CLK_ENB_L_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C1, CLK_L_I2C1, 0, CLK_SRC_DIV(10.5) }, // 20.4 MHz -> 100 KHz - { RST_DEV_H_SET, CLK_ENB_H_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C2, CLK_H_I2C2, 0, CLK_SRC_DIV(3) }, // 81.6 MHz -> 400 KHz - { RST_DEV_U_SET, CLK_ENB_U_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C3, CLK_U_I2C3, 0, CLK_SRC_DIV(3) }, // 81.6 MHz -> 400 KHz - { RST_DEV_V_SET, CLK_ENB_V_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C4, CLK_V_I2C4, 0, CLK_SRC_DIV(10.5) }, // 20.4 MHz -> 100 KHz - { RST_DEV_H_SET, CLK_ENB_H_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C5, CLK_H_I2C5, 0, CLK_SRC_DIV(3) }, // 81.6 MHz -> 400 KHz - { RST_DEV_X_SET, CLK_ENB_X_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C6, CLK_X_I2C6, 0, CLK_SRC_DIV(10.5) } // 20.4 MHz -> 100 KHz + { RST_DEV_L_SET, CLK_ENB_L_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C1, CLK_L_I2C1, 6, CLK_I2C_SRC_DIV(4) }, // 4.8 MHz -> 100 KHz + { RST_DEV_H_SET, CLK_ENB_H_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C2, CLK_H_I2C2, 6, CLK_I2C_SRC_DIV(1) }, // 19.2 MHz -> 400 KHz + { RST_DEV_U_SET, CLK_ENB_U_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C3, CLK_U_I2C3, 6, CLK_I2C_SRC_DIV(1) }, // 19.2 MHz -> 400 KHz + { RST_DEV_V_SET, CLK_ENB_V_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C4, CLK_V_I2C4, 6, CLK_I2C_SRC_DIV(4) }, // 4.8 MHz -> 100 KHz + { RST_DEV_H_SET, CLK_ENB_H_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C5, CLK_H_I2C5, 6, CLK_I2C_SRC_DIV(1) }, // 19.2 MHz -> 400 KHz + { RST_DEV_X_SET, CLK_ENB_X_SET, CLK_RST_CONTROLLER_CLK_SOURCE_I2C6, CLK_X_I2C6, 6, CLK_I2C_SRC_DIV(4) } // 4.8 MHz -> 100 KHz }; static clk_rst_t _clock_se = { @@ -733,7 +733,7 @@ static int _clock_sdmmc_config_clock_host(u32 *pclock, u32 id, u32 clock) u32 source = SDMMC_CLOCK_SRC_PLLP_OUT0; if (id > SDMMC_4) - return 0; + return 1; // Get IO clock divisor. switch (clock) @@ -813,7 +813,7 @@ static int _clock_sdmmc_config_clock_host(u32 *pclock, u32 id, u32 clock) const clk_rst_mgd_t *clk = &_clock_sdmmc[id]; CLOCK(clk->source) = (source << 29u) | divisor; - return 1; + return 0; } void clock_sdmmc_config_clock_source(u32 *pclock, u32 id, u32 clock) diff --git a/bdk/soc/clock.h b/bdk/soc/clock.h index be275d9a..9e9dc646 100644 --- a/bdk/soc/clock.h +++ b/bdk/soc/clock.h @@ -199,7 +199,8 @@ #define UTMIPLL_LOCK BIT(31) /*! Clock source */ -#define CLK_SRC_DIV(d) ((d) ? ((u32)(((d) - 1) * 2)) : 0) +#define CLK_SRC_DIV(d) ((d) ? ((u32)(((d) - 1) * 2)) : 0) +#define CLK_I2C_SRC_DIV(d) ((d) ? ((u32)(((d) - 1))) : 0) /*! PTO_CLK_CNT */ #define PTO_REF_CLK_WIN_CFG_MASK 0xF diff --git a/bdk/soc/hw_init.c b/bdk/soc/hw_init.c index 9d3d961d..24934972 100644 --- a/bdk/soc/hw_init.c +++ b/bdk/soc/hw_init.c @@ -438,9 +438,9 @@ void hw_init() if (!tegra_t210) { // This is not actually needed since it's done by bootrom. The read locks are extra. - PMC(APBDEV_PMC_TZRAM_PWR_CNTRL) &= ~PMC_TZRAM_PWR_CNTRL_SD; - PMC(APBDEV_PMC_TZRAM_NON_SEC_DISABLE) = PMC_TZRAM_DISABLE_REG_WRITE | PMC_TZRAM_DISABLE_REG_READ; - PMC(APBDEV_PMC_TZRAM_SEC_DISABLE) = PMC_TZRAM_DISABLE_REG_WRITE | PMC_TZRAM_DISABLE_REG_READ; + PMC(APBDEV_PMC_TZRAM_PWR_CNTRL_B01) &= ~PMC_TZRAM_PWR_CNTRL_SD; + PMC(APBDEV_PMC_TZRAM_NON_SEC_DISABLE_B01) = PMC_TZRAM_DISABLE_REG_WRITE | PMC_TZRAM_DISABLE_REG_READ; + PMC(APBDEV_PMC_TZRAM_SEC_DISABLE_B01) = PMC_TZRAM_DISABLE_REG_WRITE | PMC_TZRAM_DISABLE_REG_READ; } // Set arbiter. diff --git a/bdk/soc/i2c.c b/bdk/soc/i2c.c index c38e9526..1c4d29cc 100644 --- a/bdk/soc/i2c.c +++ b/bdk/soc/i2c.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2022 CTCaer + * Copyright (c) 2018-2026 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, @@ -49,6 +49,9 @@ #define I2C_TX_FIFO (0x50 / 4) #define I2C_RX_FIFO (0x54 / 4) +#define I2C_PACKET_TRANSFER_STATUS (0x58 / 4) +#define PKT_TRANSFER_COMPLETE BIT(24) + #define I2C_FIFO_CONTROL (0x5C / 4) #define RX_FIFO_FLUSH BIT(0) #define TX_FIFO_FLUSH BIT(1) @@ -96,10 +99,10 @@ static void _i2c_load_cfg_wait(vu32 *base) } } -static int _i2c_send_single(u32 i2c_idx, u32 dev_addr, const u8 *buf, u32 size) +static int _i2c_send_normal(u32 i2c_idx, u32 dev_addr, const u8 *buf, u32 size) { if (size > 8) - return 0; + return 1; u32 tmp = 0; @@ -129,25 +132,25 @@ static int _i2c_send_single(u32 i2c_idx, u32 dev_addr, const u8 *buf, u32 size) _i2c_load_cfg_wait(base); // Initiate transaction on normal mode. - base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFF9FF) | NORMAL_MODE_GO; + base[I2C_CNFG] = (base[I2C_CNFG] & ~NORMAL_MODE_GO) | NORMAL_MODE_GO; - u32 timeout = get_tmr_us() + 200000; // Actual for max 8 bytes at 100KHz is 0.74ms. + u32 timeout = get_tmr_ms() + 100; // Actual for max 8 bytes at 100KHz is 0.74ms. while (base[I2C_STATUS] & I2C_STATUS_BUSY) { - if (get_tmr_us() > timeout) - return 0; + if (get_tmr_ms() > timeout) + return 1; } if (base[I2C_STATUS] & I2C_STATUS_NOACK) - return 0; + return 1; - return 1; + return 0; } -static int _i2c_recv_single(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr) +static int _i2c_recv_normal(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr) { if (size > 8) - return 0; + return 1; vu32 *base = (vu32 *)(I2C_BASE + (u32)_i2c_base_offsets[i2c_idx]); @@ -161,17 +164,17 @@ static int _i2c_recv_single(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr) _i2c_load_cfg_wait(base); // Initiate transaction on normal mode. - base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFF9FF) | NORMAL_MODE_GO; + base[I2C_CNFG] = (base[I2C_CNFG] & ~NORMAL_MODE_GO) | NORMAL_MODE_GO; - u32 timeout = get_tmr_us() + 200000; // Actual for max 8 bytes at 100KHz is 0.74ms. + u32 timeout = get_tmr_ms() + 100; // Actual for max 8 bytes at 100KHz is 0.74ms. while (base[I2C_STATUS] & I2C_STATUS_BUSY) { - if (get_tmr_us() > timeout) - return 0; + if (get_tmr_ms() > timeout) + return 1; } if (base[I2C_STATUS] & I2C_STATUS_NOACK) - return 0; + return 1; u32 tmp = base[I2C_CMD_DATA1]; // Get LS value. if (size > 4) @@ -183,23 +186,18 @@ static int _i2c_recv_single(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr) else memcpy(buf, &tmp, size); - return 1; + return 0; } -static int _i2c_send_pkt(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr) +static int _i2c_send_packet(u32 i2c_idx, const u8 *buf, u32 size, u32 dev_addr) { if (size > 32) - return 0; + return 1; int res = 0; vu32 *base = (vu32 *)(I2C_BASE + (u32)_i2c_base_offsets[i2c_idx]); - // Enable interrupts. - base[I2C_INT_EN] = ALL_PACKETS_COMPLETE | PACKET_COMPLETE | NO_ACK | - ARB_LOST | TX_FIFO_OVER | RX_FIFO_UNDER | TX_FIFO_DATA_REQ; - base[I2C_INT_STATUS] = base[I2C_INT_STATUS]; - // Set device address and send mode. base[I2C_CMD_ADDR0] = (dev_addr << 1) | ADDR0_WRITE; @@ -213,31 +211,28 @@ static int _i2c_send_pkt(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr) _i2c_load_cfg_wait(base); // Initiate transaction on packet mode. - base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFF9FF) | PACKET_MODE_GO; - - u32 hdr[3]; - hdr[0] = I2C_PACKET_PROT_I2C; - hdr[1] = size - 1; - hdr[2] = I2C_HEADER_IE_ENABLE | I2C_HEADER_CONT_XFER | (dev_addr << 1); + base[I2C_CNFG] = (base[I2C_CNFG] & ~NORMAL_MODE_GO) | PACKET_MODE_GO; // Send header with request. - base[I2C_TX_FIFO] = hdr[0]; - base[I2C_TX_FIFO] = hdr[1]; - base[I2C_TX_FIFO] = hdr[2]; + base[I2C_TX_FIFO] = I2C_PACKET_PROT_I2C; + base[I2C_TX_FIFO] = size - 1; + base[I2C_TX_FIFO] = I2C_HEADER_IE_ENABLE | I2C_HEADER_CONT_XFER | (dev_addr << 1); - u32 timeout = get_tmr_ms() + 400; - while (size) + // Send data. + u32 rem = size; + while (rem) { - if (base[I2C_FIFO_STATUS] & TX_FIFO_EMPTY_CNT) - { - u32 tmp = 0; - u32 snd_size = MIN(size, 4); - memcpy(&tmp, buf, snd_size); - base[I2C_TX_FIFO] = tmp; - buf += snd_size; - size -= snd_size; - } + u32 len = MIN(rem, sizeof(u32)); + u32 word = 0; + memcpy(&word, buf, len); + base[I2C_TX_FIFO] = word; + buf += len; + rem -= len; + } + u32 timeout = get_tmr_ms() + 200; + while (((base[I2C_PACKET_TRANSFER_STATUS] >> 4) & 0xFFF) != (size - 1)) + { if (get_tmr_ms() > timeout) { res = 1; @@ -245,33 +240,27 @@ static int _i2c_send_pkt(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr) } } - if (base[I2C_STATUS] & I2C_STATUS_NOACK || base[I2C_INT_STATUS] & NO_ACK) + // Check if no reply. + if (base[I2C_STATUS] & I2C_STATUS_NOACK) res = 1; - // Disable packet mode. + // Wait for STOP and disable packet mode. usleep(20); - base[I2C_CNFG] &= 0xFFFFF9FF; - - // Disable interrupts. - base[I2C_INT_EN] = 0; + base[I2C_CNFG] &= ~(PACKET_MODE_GO | NORMAL_MODE_GO); return res; } -static int _i2c_recv_pkt(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr, u32 reg) +int i2c_xfer_packet(u32 i2c_idx, u32 dev_addr, const u8 *tx_buf, u32 tx_size, u8 *rx_buf, u32 rx_size) { - if (size > 32) - return 0; + // Max 32 bytes TX/RX fifo. + if (tx_size > 20 || rx_size > 32) // Header included. + return 1; int res = 0; vu32 *base = (vu32 *)(I2C_BASE + (u32)_i2c_base_offsets[i2c_idx]); - // Enable interrupts. - base[I2C_INT_EN] = ALL_PACKETS_COMPLETE | PACKET_COMPLETE | NO_ACK | - ARB_LOST | TX_FIFO_OVER | RX_FIFO_UNDER | RX_FIFO_DATA_REQ; - base[I2C_INT_STATUS] = base[I2C_INT_STATUS]; - // Set device address and recv mode. base[I2C_CMD_ADDR0] = (dev_addr << 1) | ADDR0_READ; @@ -285,44 +274,51 @@ static int _i2c_recv_pkt(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr, u32 reg) _i2c_load_cfg_wait(base); // Initiate transaction on packet mode. - base[I2C_CNFG] = (base[I2C_CNFG] & 0xFFFFF9FF) | PACKET_MODE_GO; + base[I2C_CNFG] = (base[I2C_CNFG] & ~NORMAL_MODE_GO) | PACKET_MODE_GO; - // Send reg request. - u32 hdr[3]; - hdr[0] = I2C_PACKET_PROT_I2C; - hdr[1] = 1 - 1; - hdr[2] = I2C_HEADER_REP_START | (dev_addr << 1); + // Send header with send request. + base[I2C_TX_FIFO] = I2C_PACKET_PROT_I2C; + base[I2C_TX_FIFO] = tx_size - 1; + base[I2C_TX_FIFO] = I2C_HEADER_REP_START | (dev_addr << 1); - // Send header with reg request. - base[I2C_TX_FIFO] = hdr[0]; - base[I2C_TX_FIFO] = hdr[1]; - base[I2C_TX_FIFO] = hdr[2]; - base[I2C_TX_FIFO] = reg; + // Send data. + u32 tx_rem = tx_size; + while (tx_rem) + { + u32 len = MIN(tx_rem, sizeof(u32)); + u32 word = 0; + memcpy(&word, tx_buf, len); + base[I2C_TX_FIFO] = word; + tx_buf += len; + tx_rem -= len; + } - u32 timeout = get_tmr_ms() + 400; - while (!(base[I2C_FIFO_STATUS] & TX_FIFO_EMPTY_CNT)) + u32 timeout = get_tmr_ms() + 200; + while (((base[I2C_PACKET_TRANSFER_STATUS] >> 4) & 0xFFF) != (tx_size - 1)) + { if (get_tmr_ms() > timeout) - break; + { + res = 1; + goto out; + } + } - // Send read request. - hdr[1] = size - 1; - hdr[2] = I2C_HEADER_READ | (dev_addr << 1); + // Send header with receive request + base[I2C_TX_FIFO] = I2C_PACKET_PROT_I2C; + base[I2C_TX_FIFO] = rx_size - 1; + base[I2C_TX_FIFO] = I2C_HEADER_READ | (dev_addr << 1); - // Send header with read request. - base[I2C_TX_FIFO] = hdr[0]; - base[I2C_TX_FIFO] = hdr[1]; - base[I2C_TX_FIFO] = hdr[2]; - - timeout = get_tmr_ms() + 400; - while (size) + // Receive data. + timeout = get_tmr_ms() + 200; + while (rx_size) { if (base[I2C_FIFO_STATUS] & RX_FIFO_FULL_CNT) { - u32 rcv_size = MIN(size, 4); - u32 tmp = base[I2C_RX_FIFO]; - memcpy(buf, &tmp, rcv_size); - buf += rcv_size; - size -= rcv_size; + u32 len = MIN(rx_size, sizeof(u32)); + u32 word = base[I2C_RX_FIFO]; + memcpy(rx_buf, &word, len); + rx_buf += len; + rx_size -= len; } if (get_tmr_ms() > timeout) @@ -332,15 +328,14 @@ static int _i2c_recv_pkt(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr, u32 reg) } } - if (base[I2C_STATUS] & I2C_STATUS_NOACK || base[I2C_INT_STATUS] & NO_ACK) +out: + // Check if no reply. + if (base[I2C_STATUS] & I2C_STATUS_NOACK) res = 1; - // Disable packet mode. + // Wait for STOP and disable packet mode. usleep(20); - base[I2C_CNFG] &= 0xFFFFF9FF; - - // Disable interrupts. - base[I2C_INT_EN] = 0; + base[I2C_CNFG] &= ~(PACKET_MODE_GO | NORMAL_MODE_GO); return res; } @@ -366,42 +361,33 @@ void i2c_init(u32 i2c_idx) base[I2C_INT_STATUS] = base[I2C_INT_STATUS]; } -int i2c_recv_buf(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr) +int i2c_send_buf_big(u32 i2c_idx, u32 dev_addr, const u8 *buf, u32 size) { - return _i2c_recv_single(i2c_idx, buf, size, dev_addr); -} - -int i2c_send_buf_big(u32 i2c_idx, u32 dev_addr, u8 *buf, u32 size) -{ - if (size > 32) - return 0; - - return _i2c_send_pkt(i2c_idx, buf, size, dev_addr); + return _i2c_send_packet(i2c_idx, buf, size, dev_addr); } int i2c_recv_buf_big(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg) { - return _i2c_recv_pkt(i2c_idx, buf, size, dev_addr, reg); + return i2c_xfer_packet(i2c_idx, dev_addr, (u8 *)®, 1, buf, size); } int i2c_send_buf_small(u32 i2c_idx, u32 dev_addr, u32 reg, const u8 *buf, u32 size) { - u8 tmp[8]; - if (size > 7) - return 0; + return 1; + u8 tmp[8]; tmp[0] = reg; memcpy(tmp + 1, buf, size); - return _i2c_send_single(i2c_idx, dev_addr, tmp, size + 1); + return _i2c_send_normal(i2c_idx, dev_addr, tmp, size + 1); } int i2c_recv_buf_small(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg) { - int res = _i2c_send_single(i2c_idx, dev_addr, (u8 *)®, 1); - if (res) - res = _i2c_recv_single(i2c_idx, buf, size, dev_addr); + int res = _i2c_send_normal(i2c_idx, dev_addr, (u8 *)®, 1); + if (!res) + res = _i2c_recv_normal(i2c_idx, buf, size, dev_addr); return res; } diff --git a/bdk/soc/i2c.h b/bdk/soc/i2c.h index ab3078ee..35cbca30 100644 --- a/bdk/soc/i2c.h +++ b/bdk/soc/i2c.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2020 CTCaer + * Copyright (c) 2020-2026 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, @@ -28,8 +28,8 @@ #define I2C_6 5 void i2c_init(u32 i2c_idx); -int i2c_recv_buf(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr); -int i2c_send_buf_big(u32 i2c_idx, u32 dev_addr, u8 *buf, u32 size); +int i2c_xfer_packet(u32 i2c_idx, u32 dev_addr, const u8 *tx_buf, u32 tx_size, u8 *rx_buf, u32 rx_size); +int i2c_send_buf_big(u32 i2c_idx, u32 dev_addr, const u8 *buf, u32 size); int i2c_recv_buf_big(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg); int i2c_send_buf_small(u32 i2c_idx, u32 dev_addr, u32 reg, const u8 *buf, u32 size); int i2c_recv_buf_small(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg); diff --git a/bdk/soc/kfuse.c b/bdk/soc/kfuse.c index 2da95931..5f1bf236 100644 --- a/bdk/soc/kfuse.c +++ b/bdk/soc/kfuse.c @@ -25,25 +25,25 @@ int kfuse_wait_ready() ; if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) - return 0; + return 1; - return 1; + return 0; } int kfuse_read(u32 *buf) { - int res = 0; + int res = 1; clock_enable_kfuse(); - if (!kfuse_wait_ready()) + if (kfuse_wait_ready()) goto out; KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC; for (int i = 0; i < KFUSE_NUM_WORDS; i++) buf[i] = KFUSE(KFUSE_KEYS); - res = 1; + res = 0; out: clock_disable_kfuse(); diff --git a/bdk/soc/pinmux.c b/bdk/soc/pinmux.c index 84969c67..e11be09b 100644 --- a/bdk/soc/pinmux.c +++ b/bdk/soc/pinmux.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2024 CTCaer + * Copyright (c) 2018-2026 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, @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -30,6 +31,13 @@ void pinmux_config_i2c(u32 idx) { PINMUX_AUX(PINMUX_AUX_X_I2C_SCL(idx)) = PINMUX_INPUT_ENABLE; PINMUX_AUX(PINMUX_AUX_X_I2C_SDA(idx)) = PINMUX_INPUT_ENABLE; + + // Detach I2C4 pins from I2C3 function. + if (idx == I2C_3 || idx == I2C_4) + { + PINMUX_AUX(PINMUX_AUX_X_I2C_SCL(I2C_4)) |= 1; + PINMUX_AUX(PINMUX_AUX_X_I2C_SDA(I2C_4)) |= 1; + } } void pinmux_config_i2s(u32 idx) diff --git a/bdk/soc/pmc.c b/bdk/soc/pmc.c index 2f5d4cc8..b814235b 100644 --- a/bdk/soc/pmc.c +++ b/bdk/soc/pmc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 CTCaer + * Copyright (c) 2020-2026 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, @@ -75,10 +75,10 @@ void pmc_scratch_lock(pmc_sec_lock_t lock_mask) PMC(APBDEV_PMC_SEC_DISABLE) |= 0xFF000; // RW lock: 4-7 if (lock_mask & PMC_SEC_LOCK_SE2_SRK_B01) - PMC(APBDEV_PMC_SEC_DISABLE9) |= 0x3FC; // RW lock: 120-123 (T210B01). LP0 also sets global bits (b0-1). + PMC(APBDEV_PMC_SEC_DISABLE9_B01) |= 0x3FC; // RW lock: 120-123 (T210B01). LP0 also sets global bits (b0-1). if (lock_mask & PMC_SEC_LOCK_MISC_B01) - PMC(APBDEV_PMC_SEC_DISABLE10) = 0xFFFFFFFF; // RW lock: 135-150. Happens on T210B01 LP0 always. + PMC(APBDEV_PMC_SEC_DISABLE10_B01) = 0xFFFFFFFF; // RW lock: 135-150. Happens on T210B01 LP0 always. if (lock_mask & PMC_SEC_LOCK_CARVEOUTS_L4T) PMC(APBDEV_PMC_SEC_DISABLE2) |= 0x5555; // W: 8-15 LP0 and Carveouts. Superseded by LP0 lock. @@ -87,15 +87,15 @@ void pmc_scratch_lock(pmc_sec_lock_t lock_mask) // They could also use the NS write disable registers instead. if (lock_mask & PMC_SEC_LOCK_LP0_PARAMS_B01) { - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE0) |= 0xCBCFE0; // W lock: 5-11, 14-17, 19, 22-23. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE1) |= 0x583FF; // W lock: 24-33, 39-40, 42. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE2) |= 0x1BE; // W lock: 44-48, 50-51. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE3) = 0xFFFFFFFF; // W lock: 56-87. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE4) |= 0xFFFFFFF; // W lock: 88-115. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE5) |= 0xFFFFFFF8; // W lock: 123-151. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE6) = 0xFFFFFFFF; // W lock: 152-183. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE7) |= 0xFC00FFFF; // W lock: 184-199, 210-215. - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE8) |= 0xF; // W lock: 216-219. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE0_B01) |= 0xCBCFE0; // W lock: 5-11, 14-17, 19, 22-23. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE1_B01) |= 0x583FF; // W lock: 24-33, 39-40, 42. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE2_B01) |= 0x1BE; // W lock: 44-48, 50-51. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE3_B01) = 0xFFFFFFFF; // W lock: 56-87. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE4_B01) |= 0xFFFFFFF; // W lock: 88-115. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE5_B01) |= 0xFFFFFFF8; // W lock: 123-151. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE6_B01) = 0xFFFFFFFF; // W lock: 152-183. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE7_B01) |= 0xFC00FFFF; // W lock: 184-199, 210-215. + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE8_B01) |= 0xF; // W lock: 216-219. } } @@ -115,28 +115,26 @@ int pmc_domain_pwrgate_set(pmc_power_rail_t part, u32 enable) // Check if the power domain has the state we want. if ((PMC(APBDEV_PMC_PWRGATE_STATUS) & part_mask) == desired_state) - return 1; + return 0; - u32 i = 5001; + int retries = 5000; while (PMC(APBDEV_PMC_PWRGATE_TOGGLE) & PMC_PWRGATE_TOGGLE_START) { usleep(1); - i--; - if (i < 1) - return 0; + if (--retries < 1) + return 1; } // Toggle power gating. PMC(APBDEV_PMC_PWRGATE_TOGGLE) = part | PMC_PWRGATE_TOGGLE_START; - i = 5001; - while (i > 0) + retries = 5000; + while ((PMC(APBDEV_PMC_PWRGATE_STATUS) & part_mask) != desired_state) { - if ((PMC(APBDEV_PMC_PWRGATE_STATUS) & part_mask) == desired_state) - break; usleep(1); - i--; + if (--retries < 1) + return 1; } - return 1; + return 0; } diff --git a/bdk/soc/pmc.h b/bdk/soc/pmc.h index def67d9b..d6f54578 100644 --- a/bdk/soc/pmc.h +++ b/bdk/soc/pmc.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2018 naehrwert * Copyright (c) 2018 st4rk - * Copyright (c) 2018-2024 CTCaer + * Copyright (c) 2018-2026 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, @@ -20,185 +20,7 @@ #define _PMC_H_ #include - -/*! PMC registers. */ -#define APBDEV_PMC_CNTRL 0x0 -#define PMC_CNTRL_RTC_CLK_DIS BIT(1) -#define PMC_CNTRL_RTC_RST BIT(2) -#define PMC_CNTRL_MAIN_RST BIT(4) -#define PMC_CNTRL_LATCHWAKE_EN BIT(5) -#define PMC_CNTRL_BLINK_EN BIT(7) -#define PMC_CNTRL_PWRREQ_OE BIT(9) -#define PMC_CNTRL_SYSCLK_OE BIT(11) -#define PMC_CNTRL_PWRGATE_DIS BIT(12) -#define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) -#define PMC_CNTRL_CPUPWRREQ_OE BIT(16) -#define PMC_CNTRL_FUSE_OVERRIDE BIT(18) -#define PMC_CNTRL_SHUTDOWN_OE BIT(22) -#define APBDEV_PMC_SEC_DISABLE 0x4 -#define APBDEV_PMC_PWRGATE_TOGGLE 0x30 -#define PMC_PWRGATE_TOGGLE_START BIT(8) -#define APBDEV_PMC_PWRGATE_STATUS 0x38 -#define APBDEV_PMC_NO_IOPOWER 0x44 -#define PMC_NO_IOPOWER_MEM BIT(7) -#define PMC_NO_IOPOWER_SDMMC1 BIT(12) -#define PMC_NO_IOPOWER_SDMMC4 BIT(14) -#define PMC_NO_IOPOWER_MEM_COMP BIT(16) -#define PMC_NO_IOPOWER_AUDIO_HV BIT(18) -#define PMC_NO_IOPOWER_GPIO BIT(21) -#define APBDEV_PMC_SCRATCH0 0x50 -#define PMC_SCRATCH0_MODE_WARMBOOT BIT(0) -#define PMC_SCRATCH0_MODE_RCM BIT(1) -#define PMC_SCRATCH0_MODE_PAYLOAD BIT(29) -#define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30) -#define PMC_SCRATCH0_MODE_RECOVERY BIT(31) -#define PMC_SCRATCH0_MODE_CUSTOM_ALL (PMC_SCRATCH0_MODE_RECOVERY | \ - PMC_SCRATCH0_MODE_BOOTLOADER | \ - PMC_SCRATCH0_MODE_PAYLOAD) -#define APBDEV_PMC_BLINK_TIMER 0x40 -#define PMC_BLINK_ON(n) ((n & 0x7FFF)) -#define PMC_BLINK_FORCE BIT(15) -#define PMC_BLINK_OFF(n) ((u32)(n & 0xFFFF) << 16) -#define APBDEV_PMC_SCRATCH1 0x54 -#define APBDEV_PMC_SCRATCH20 0xA0 // ODM data/config scratch. -#define APBDEV_PMC_SECURE_SCRATCH4 0xC0 -#define APBDEV_PMC_SECURE_SCRATCH5 0xC4 -#define APBDEV_PMC_PWR_DET_VAL 0xE4 -#define PMC_PWR_DET_33V_SDMMC1 BIT(12) -#define PMC_PWR_DET_33V_AUDIO_HV BIT(18) -#define PMC_PWR_DET_33V_GPIO BIT(21) -#define APBDEV_PMC_DDR_PWR 0xE8 -#define APBDEV_PMC_USB_AO 0xF0 -#define APBDEV_PMC_CRYPTO_OP 0xF4 -#define PMC_CRYPTO_OP_SE_ENABLE 0 -#define PMC_CRYPTO_OP_SE_DISABLE 1 -#define APBDEV_PMC_PLLP_WB0_OVERRIDE 0xF8 -#define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE_ENABLE BIT(11) -#define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE BIT(12) -#define APBDEV_PMC_SCRATCH33 0x120 -#define APBDEV_PMC_SCRATCH37 0x130 -#define PMC_SCRATCH37_KERNEL_PANIC_MAGIC 0x4E415054 // "TPAN" -#define APBDEV_PMC_SCRATCH39 0x138 -#define APBDEV_PMC_SCRATCH40 0x13C -#define APBDEV_PMC_OSC_EDPD_OVER 0x1A4 -#define PMC_OSC_EDPD_OVER_OSC_CTRL_OVER BIT(22) -#define APBDEV_PMC_CLK_OUT_CNTRL 0x1A8 -#define PMC_CLK_OUT_CNTRL_CLK1_FORCE_EN BIT(2) -#define PMC_CLK_OUT_CNTRL_CLK2_FORCE_EN BIT(10) -#define PMC_CLK_OUT_CNTRL_CLK3_FORCE_EN BIT(18) -#define PMC_CLK_OUT_CNTRL_CLK1_SRC_SEL(src) (((src) & 3) << 6) -#define PMC_CLK_OUT_CNTRL_CLK2_SRC_SEL(src) (((src) & 3) << 14) -#define PMC_CLK_OUT_CNTRL_CLK3_SRC_SEL(src) (((src) & 3) << 22) -#define OSC_DIV1 0 -#define OSC_DIV2 1 -#define OSC_DIV4 2 -#define OSC_CAR 3 -#define APBDEV_PMC_RST_STATUS 0x1B4 -#define PMC_RST_STATUS_MASK 7 -#define PMC_RST_STATUS_POR 0 -#define PMC_RST_STATUS_WATCHDOG 1 -#define PMC_RST_STATUS_SENSOR 2 -#define PMC_RST_STATUS_SW_MAIN 3 -#define PMC_RST_STATUS_LP0 4 -#define PMC_RST_STATUS_AOTAG 5 -#define APBDEV_PMC_IO_DPD_REQ 0x1B8 -#define PMC_IO_DPD_REQ_DPD_IDLE (0 << 30u) -#define PMC_IO_DPD_REQ_DPD_OFF (1 << 30u) -#define PMC_IO_DPD_REQ_DPD_ON (2 << 30u) -#define APBDEV_PMC_IO_DPD2_REQ 0x1C0 -#define APBDEV_PMC_VDDP_SEL 0x1CC -#define APBDEV_PMC_DDR_CFG 0x1D0 -#define APBDEV_PMC_SECURE_SCRATCH6 0x224 -#define APBDEV_PMC_SECURE_SCRATCH7 0x228 -#define APBDEV_PMC_SCRATCH45 0x234 -#define APBDEV_PMC_SCRATCH46 0x238 -#define APBDEV_PMC_SCRATCH49 0x244 -#define APBDEV_PMC_SCRATCH52 0x250 -#define APBDEV_PMC_SCRATCH53 0x254 -#define APBDEV_PMC_SCRATCH54 0x258 -#define APBDEV_PMC_SCRATCH55 0x25C -#define APBDEV_PMC_TSC_MULT 0x2B4 -#define APBDEV_PMC_STICKY_BITS 0x2C0 -#define PMC_STICKY_BITS_HDA_LPBK_DIS BIT(0) -#define APBDEV_PMC_SEC_DISABLE2 0x2C4 -#define APBDEV_PMC_WEAK_BIAS 0x2C8 -#define APBDEV_PMC_REG_SHORT 0x2CC -#define APBDEV_PMC_SEC_DISABLE3 0x2D8 -#define APBDEV_PMC_SECURE_SCRATCH21 0x334 -#define PMC_FUSE_PRIVATEKEYDISABLE_TZ_STICKY_BIT BIT(4) -#define APBDEV_PMC_SECURE_SCRATCH22 0x338 // AArch32 reset address. -#define APBDEV_PMC_SECURE_SCRATCH32 0x360 -#define APBDEV_PMC_SECURE_SCRATCH34 0x368 // AArch64 reset address. -#define APBDEV_PMC_SECURE_SCRATCH35 0x36C // AArch64 reset hi-address. -#define APBDEV_PMC_SECURE_SCRATCH49 0x3A4 -#define APBDEV_PMC_CNTRL2 0x440 -#define PMC_CNTRL2_WAKE_INT_EN BIT(0) -#define PMC_CNTRL2_WAKE_DET_EN BIT(9) -#define PMC_CNTRL2_SYSCLK_ORRIDE BIT(10) -#define PMC_CNTRL2_HOLD_CKE_LOW_EN BIT(12) -#define PMC_CNTRL2_ALLOW_PULSE_WAKE BIT(14) -#define APBDEV_PMC_FUSE_CONTROL 0x450 -#define PMC_FUSE_CONTROL_PS18_LATCH_SET BIT(8) -#define PMC_FUSE_CONTROL_PS18_LATCH_CLR BIT(9) -#define APBDEV_PMC_IO_DPD3_REQ 0x45C -#define APBDEV_PMC_IO_DPD4_REQ 0x464 -#define APBDEV_PMC_UTMIP_PAD_CFG1 0x4C4 -#define APBDEV_PMC_UTMIP_PAD_CFG3 0x4CC -#define APBDEV_PMC_DDR_CNTRL 0x4E4 -#define APBDEV_PMC_SEC_DISABLE4 0x5B0 -#define APBDEV_PMC_SEC_DISABLE5 0x5B4 -#define APBDEV_PMC_SEC_DISABLE6 0x5B8 -#define APBDEV_PMC_SEC_DISABLE7 0x5BC -#define APBDEV_PMC_SEC_DISABLE8 0x5C0 -#define APBDEV_PMC_SEC_DISABLE9 0x5C4 -#define APBDEV_PMC_SEC_DISABLE10 0x5C8 -#define APBDEV_PMC_SCRATCH188 0x810 -#define APBDEV_PMC_SCRATCH190 0x818 -#define APBDEV_PMC_SCRATCH200 0x840 -#define PMC_NX_PANIC_SAFE_MODE 0x20 -#define PMC_NX_PANIC_BYPASS_FUSES 0x21 -#define APBDEV_PMC_SCRATCH201 0x844 -#define APBDEV_PMC_SCRATCH250 0x908 -#define APBDEV_PMC_SECURE_SCRATCH108 0xB08 -#define APBDEV_PMC_SECURE_SCRATCH109 0xB0C -#define APBDEV_PMC_SECURE_SCRATCH110 0xB10 -#define APBDEV_PMC_SECURE_SCRATCH112 0xB18 -#define APBDEV_PMC_SECURE_SCRATCH113 0xB1C -#define APBDEV_PMC_SECURE_SCRATCH114 0xB20 -#define APBDEV_PMC_SECURE_SCRATCH119 0xB34 - -// Only in T210B01. -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE0 0xA48 -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE1 0xA4C -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE2 0xA50 -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE3 0xA54 -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE4 0xA58 -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE5 0xA5C -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE6 0xA60 -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE7 0xA64 -#define APBDEV_PMC_SCRATCH_WRITE_DISABLE8 0xA68 -#define APBDEV_PMC_LED_BREATHING_CTRL 0xB48 -#define PMC_LED_BREATHING_CTRL_ENABLE BIT(0) -#define PMC_LED_BREATHING_CTRL_COUNTER1_EN BIT(1) -#define APBDEV_PMC_LED_BREATHING_SLOPE_STEPS 0xB4C -#define APBDEV_PMC_LED_BREATHING_ON_COUNTER 0xB50 -#define APBDEV_PMC_LED_BREATHING_OFF_COUNTER1 0xB54 -#define APBDEV_PMC_LED_BREATHING_OFF_COUNTER0 0xB58 -#define PMC_LED_BREATHING_COUNTER_HZ 32768 -#define APBDEV_PMC_LED_BREATHING_STATUS 0xB5C -#define PMC_LED_BREATHING_FSM_STATUS_MASK 0x7 -#define PMC_LED_BREATHING_FSM_STS_IDLE 0 -#define PMC_LED_BREATHING_FSM_STS_UP_RAMP 1 -#define PMC_LED_BREATHING_FSM_STS_PLATEAU 2 -#define PMC_LED_BREATHING_FSM_STS_DOWN_RAMP 3 -#define PMC_LED_BREATHING_FSM_STS_SHORT_LOW_PERIOD 4 -#define PMC_LED_BREATHING_FSM_STS_LONG_LOW_PERIOD 5 -#define APBDEV_PMC_TZRAM_PWR_CNTRL 0xBE8 -#define PMC_TZRAM_PWR_CNTRL_SD BIT(0) -#define APBDEV_PMC_TZRAM_SEC_DISABLE 0xBEC -#define APBDEV_PMC_TZRAM_NON_SEC_DISABLE 0xBF0 -#define PMC_TZRAM_DISABLE_REG_WRITE BIT(0) -#define PMC_TZRAM_DISABLE_REG_READ BIT(1) +#include typedef enum _pmc_sec_lock_t { diff --git a/bdk/soc/pmc_lp0_t210.h b/bdk/soc/pmc_lp0_t210.h deleted file mode 100644 index 5b87d5ae..00000000 --- a/bdk/soc/pmc_lp0_t210.h +++ /dev/null @@ -1,564 +0,0 @@ -/* - * Copyright (c) 2010-2015, NVIDIA CORPORATION. All rights reserved. - * - * 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. - */ - -#ifndef _TEGRA210_PMC_H_ -#define _TEGRA210_PMC_H_ - -#include - -struct tegra_pmc_regs -{ - u32 cntrl; - u32 sec_disable; - u32 pmc_swrst; - u32 wake_mask; - u32 wake_lvl; - u32 wake_status; - u32 sw_wake_status; - u32 dpd_pads_oride; - u32 dpd_sample; - u32 dpd_enable; - u32 pwrgate_timer_off; - u32 clamp_status; - u32 pwrgate_toggle; - u32 remove_clamping_cmd; - u32 pwrgate_status; - u32 pwrgood_timer; - u32 blink_timer; - u32 no_iopower; - u32 pwr_det; - u32 pwr_det_latch; - u32 scratch0; - u32 scratch1; - u32 scratch2; - u32 scratch3; - u32 scratch4; - u32 scratch5; - u32 scratch6; - u32 scratch7; - u32 scratch8; - u32 scratch9; - u32 scratch10; - u32 scratch11; - u32 scratch12; - u32 scratch13; - u32 scratch14; - u32 scratch15; - u32 scratch16; - u32 scratch17; - u32 scratch18; - u32 scratch19; - u32 odmdata; - u32 scratch21; - u32 scratch22; - u32 scratch23; - u32 secure_scratch0; - u32 secure_scratch1; - u32 secure_scratch2; - u32 secure_scratch3; - u32 secure_scratch4; - u32 secure_scratch5; - u32 cpupwrgood_timer; - u32 cpupwroff_timer; - u32 pg_mask; - u32 pg_mask_1; - u32 auto_wake_lvl; - u32 auto_wake_lvl_mask; - u32 wake_delay; - u32 pwr_det_val; - u32 ddr_pwr; - u32 usb_debounce_del; - u32 usb_a0; - u32 crypto_op; - u32 pllp_wb0_override; - u32 scratch24; - u32 scratch25; - u32 scratch26; - u32 scratch27; - u32 scratch28; - u32 scratch29; - u32 scratch30; - u32 scratch31; - u32 scratch32; - u32 scratch33; - u32 scratch34; - u32 scratch35; - u32 scratch36; - u32 scratch37; - u32 scratch38; - u32 scratch39; - u32 scratch40; - u32 scratch41; - u32 scratch42; - u32 bondout_mirror[3]; - u32 sys_33v_en; - u32 bondout_mirror_access; - u32 gate; - u32 wake2_mask; - u32 wake2_lvl; - u32 wake2_status; - u32 sw_wake2_status; - u32 auto_wake2_lvl_mask; - u32 pg_mask_2; - u32 pg_mask_ce1; - u32 pg_mask_ce2; - u32 pg_mask_ce3; - u32 pwrgate_timer_ce[7]; - u32 pcx_edpd_cntrl; - u32 osc_edpd_over; - u32 clk_out_cntrl; - u32 sata_pwrgt; - u32 sensor_ctrl; - u32 rst_status; - u32 io_dpd_req; - u32 io_dpd_status; - u32 io_dpd2_req; - u32 io_dpd2_status; - u32 sel_dpd_tim; - u32 vddp_sel; - u32 ddr_cfg; - u32 e_no_vttgen; - u8 _rsv0[4]; - u32 pllm_wb0_override_freq; - u32 test_pwrgate; - u32 pwrgate_timer_mult; - u32 dis_sel_dpd; - u32 utmip_uhsic_triggers; - u32 utmip_uhsic_saved_state; - u32 utmip_pad_cfg; - u32 utmip_term_pad_cfg; - u32 utmip_uhsic_sleep_cfg; - u32 utmip_uhsic_sleepwalk_cfg; - u32 utmip_sleepwalk_p[3]; - u32 uhsic_sleepwalk_p0; - u32 utmip_uhsic_status; - u32 utmip_uhsic_fake; - u32 bondout_mirror3[5 - 3]; - u32 secure_scratch6; - u32 secure_scratch7; - u32 scratch43; - u32 scratch44; - u32 scratch45; - u32 scratch46; - u32 scratch47; - u32 scratch48; - u32 scratch49; - u32 scratch50; - u32 scratch51; - u32 scratch52; - u32 scratch53; - u32 scratch54; - u32 scratch55; - u32 scratch0_eco; - u32 por_dpd_ctrl; - u32 scratch2_eco; - u32 utmip_uhsic_line_wakeup; - u32 utmip_bias_master_cntrl; - u32 utmip_master_config; - u32 td_pwrgate_inter_part_timer; - u32 utmip_uhsic2_triggers; - u32 utmip_uhsic2_saved_state; - u32 utmip_uhsic2_sleep_cfg; - u32 utmip_uhsic2_sleepwalk_cfg; - u32 uhsic2_sleepwalk_p1; - u32 utmip_uhsic2_status; - u32 utmip_uhsic2_fake; - u32 utmip_uhsic2_line_wakeup; - u32 utmip_master2_config; - u32 utmip_uhsic_rpd_cfg; - u32 pg_mask_ce0; - u32 pg_mask3[5 - 3]; - u32 pllm_wb0_override2; - u32 tsc_mult; - u32 cpu_vsense_override; - u32 glb_amap_cfg; - u32 sticky_bits; - u32 sec_disable2; - u32 weak_bias; - u32 reg_short; - u32 pg_mask_andor; - u8 _rsv1[0x2c]; - u32 secure_scratch8; /* offset 0x300 */ - u32 secure_scratch9; - u32 secure_scratch10; - u32 secure_scratch11; - u32 secure_scratch12; - u32 secure_scratch13; - u32 secure_scratch14; - u32 secure_scratch15; - u32 secure_scratch16; - u32 secure_scratch17; - u32 secure_scratch18; - u32 secure_scratch19; - u32 secure_scratch20; - u32 secure_scratch21; - u32 secure_scratch22; - u32 secure_scratch23; - u32 secure_scratch24; - u32 secure_scratch25; - u32 secure_scratch26; - u32 secure_scratch27; - u32 secure_scratch28; - u32 secure_scratch29; - u32 secure_scratch30; - u32 secure_scratch31; - u32 secure_scratch32; - u32 secure_scratch33; - u32 secure_scratch34; - u32 secure_scratch35; - u32 secure_scratch36; - u32 secure_scratch37; - u32 secure_scratch38; - u32 secure_scratch39; - u32 secure_scratch40; - u32 secure_scratch41; - u32 secure_scratch42; - u32 secure_scratch43; - u32 secure_scratch44; - u32 secure_scratch45; - u32 secure_scratch46; - u32 secure_scratch47; - u32 secure_scratch48; - u32 secure_scratch49; - u32 secure_scratch50; - u32 secure_scratch51; - u32 secure_scratch52; - u32 secure_scratch53; - u32 secure_scratch54; - u32 secure_scratch55; - u32 secure_scratch56; - u32 secure_scratch57; - u32 secure_scratch58; - u32 secure_scratch59; - u32 secure_scratch60; - u32 secure_scratch61; - u32 secure_scratch62; - u32 secure_scratch63; - u32 secure_scratch64; - u32 secure_scratch65; - u32 secure_scratch66; - u32 secure_scratch67; - u32 secure_scratch68; - u32 secure_scratch69; - u32 secure_scratch70; - u32 secure_scratch71; - u32 secure_scratch72; - u32 secure_scratch73; - u32 secure_scratch74; - u32 secure_scratch75; - u32 secure_scratch76; - u32 secure_scratch77; - u32 secure_scratch78; - u32 secure_scratch79; - u32 _rsv0x420[8]; - u32 cntrl2; /* 0x440 */ - u32 _rsv0x444[2]; - u32 event_counter; /* 0x44C */ - u32 fuse_control; - u32 scratch1_eco; - u32 _rsv0x458[1]; - u32 io_dpd3_req; /* 0x45C */ - u32 io_dpd3_status; - u32 io_dpd4_req; - u32 io_dpd4_status; - u32 _rsv0x46C[30]; - u32 ddr_cntrl; /* 0x4E4 */ - u32 _rsv0x4E8[70]; - u32 scratch56; /* 0x600 */ - u32 scratch57; - u32 scratch58; - u32 scratch59; - u32 scratch60; - u32 scratch61; - u32 scratch62; - u32 scratch63; - u32 scratch64; - u32 scratch65; - u32 scratch66; - u32 scratch67; - u32 scratch68; - u32 scratch69; - u32 scratch70; - u32 scratch71; - u32 scratch72; - u32 scratch73; - u32 scratch74; - u32 scratch75; - u32 scratch76; - u32 scratch77; - u32 scratch78; - u32 scratch79; - u32 scratch80; - u32 scratch81; - u32 scratch82; - u32 scratch83; - u32 scratch84; - u32 scratch85; - u32 scratch86; - u32 scratch87; - u32 scratch88; - u32 scratch89; - u32 scratch90; - u32 scratch91; - u32 scratch92; - u32 scratch93; - u32 scratch94; - u32 scratch95; - u32 scratch96; - u32 scratch97; - u32 scratch98; - u32 scratch99; - u32 scratch100; - u32 scratch101; - u32 scratch102; - u32 scratch103; - u32 scratch104; - u32 scratch105; - u32 scratch106; - u32 scratch107; - u32 scratch108; - u32 scratch109; - u32 scratch110; - u32 scratch111; - u32 scratch112; - u32 scratch113; - u32 scratch114; - u32 scratch115; - u32 scratch116; - u32 scratch117; - u32 scratch118; - u32 scratch119; - u32 scratch120; /* 0x700 */ - u32 scratch121; - u32 scratch122; - u32 scratch123; - u32 scratch124; - u32 scratch125; - u32 scratch126; - u32 scratch127; - u32 scratch128; - u32 scratch129; - u32 scratch130; - u32 scratch131; - u32 scratch132; - u32 scratch133; - u32 scratch134; - u32 scratch135; - u32 scratch136; - u32 scratch137; - u32 scratch138; - u32 scratch139; - u32 scratch140; - u32 scratch141; - u32 scratch142; - u32 scratch143; - u32 scratch144; - u32 scratch145; - u32 scratch146; - u32 scratch147; - u32 scratch148; - u32 scratch149; - u32 scratch150; - u32 scratch151; - u32 scratch152; - u32 scratch153; - u32 scratch154; - u32 scratch155; - u32 scratch156; - u32 scratch157; - u32 scratch158; - u32 scratch159; - u32 scratch160; - u32 scratch161; - u32 scratch162; - u32 scratch163; - u32 scratch164; - u32 scratch165; - u32 scratch166; - u32 scratch167; - u32 scratch168; - u32 scratch169; - u32 scratch170; - u32 scratch171; - u32 scratch172; - u32 scratch173; - u32 scratch174; - u32 scratch175; - u32 scratch176; - u32 scratch177; - u32 scratch178; - u32 scratch179; - u32 scratch180; - u32 scratch181; - u32 scratch182; - u32 scratch183; - u32 scratch184; - u32 scratch185; - u32 scratch186; - u32 scratch187; - u32 scratch188; - u32 scratch189; - u32 scratch190; - u32 scratch191; - u32 scratch192; - u32 scratch193; - u32 scratch194; - u32 scratch195; - u32 scratch196; - u32 scratch197; - u32 scratch198; - u32 scratch199; - u32 scratch200; - u32 scratch201; - u32 scratch202; - u32 scratch203; - u32 scratch204; - u32 scratch205; - u32 scratch206; - u32 scratch207; - u32 scratch208; - u32 scratch209; - u32 scratch210; - u32 scratch211; - u32 scratch212; - u32 scratch213; - u32 scratch214; - u32 scratch215; - u32 scratch216; - u32 scratch217; - u32 scratch218; - u32 scratch219; - u32 scratch220; - u32 scratch221; - u32 scratch222; - u32 scratch223; - u32 scratch224; - u32 scratch225; - u32 scratch226; - u32 scratch227; - u32 scratch228; - u32 scratch229; - u32 scratch230; - u32 scratch231; - u32 scratch232; - u32 scratch233; - u32 scratch234; - u32 scratch235; - u32 scratch236; - u32 scratch237; - u32 scratch238; - u32 scratch239; - u32 scratch240; - u32 scratch241; - u32 scratch242; - u32 scratch243; - u32 scratch244; - u32 scratch245; - u32 scratch246; - u32 scratch247; - u32 scratch248; - u32 scratch249; - u32 scratch250; - u32 scratch251; - u32 scratch252; - u32 scratch253; - u32 scratch254; - u32 scratch255; - u32 scratch256; - u32 scratch257; - u32 scratch258; - u32 scratch259; - u32 scratch260; - u32 scratch261; - u32 scratch262; - u32 scratch263; - u32 scratch264; - u32 scratch265; - u32 scratch266; - u32 scratch267; - u32 scratch268; - u32 scratch269; - u32 scratch270; - u32 scratch271; - u32 scratch272; - u32 scratch273; - u32 scratch274; - u32 scratch275; - u32 scratch276; - u32 scratch277; - u32 scratch278; - u32 scratch279; - u32 scratch280; - u32 scratch281; - u32 scratch282; - u32 scratch283; - u32 scratch284; - u32 scratch285; - u32 scratch286; - u32 scratch287; - u32 scratch288; - u32 scratch289; - u32 scratch290; - u32 scratch291; - u32 scratch292; - u32 scratch293; - u32 scratch294; - u32 scratch295; - u32 scratch296; - u32 scratch297; - u32 scratch298; - u32 scratch299; /* 0x9CC */ - u32 _rsv0x9D0[50]; - u32 secure_scratch80; /* 0xa98 */ - u32 secure_scratch81; - u32 secure_scratch82; - u32 secure_scratch83; - u32 secure_scratch84; - u32 secure_scratch85; - u32 secure_scratch86; - u32 secure_scratch87; - u32 secure_scratch88; - u32 secure_scratch89; - u32 secure_scratch90; - u32 secure_scratch91; - u32 secure_scratch92; - u32 secure_scratch93; - u32 secure_scratch94; - u32 secure_scratch95; - u32 secure_scratch96; - u32 secure_scratch97; - u32 secure_scratch98; - u32 secure_scratch99; - u32 secure_scratch100; - u32 secure_scratch101; - u32 secure_scratch102; - u32 secure_scratch103; - u32 secure_scratch104; - u32 secure_scratch105; - u32 secure_scratch106; - u32 secure_scratch107; - u32 secure_scratch108; - u32 secure_scratch109; - u32 secure_scratch110; - u32 secure_scratch111; - u32 secure_scratch112; - u32 secure_scratch113; - u32 secure_scratch114; - u32 secure_scratch115; - u32 secure_scratch116; - u32 secure_scratch117; - u32 secure_scratch118; - u32 secure_scratch119; -}; - -#endif /* _TEGRA210_PMC_H_ */ diff --git a/bdk/soc/pmc_t210.h b/bdk/soc/pmc_t210.h new file mode 100644 index 00000000..d02a69f7 --- /dev/null +++ b/bdk/soc/pmc_t210.h @@ -0,0 +1,1428 @@ +/* + * Copyright (c) 2018-2026 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. + */ + +#ifndef _PMC_T210_H_ +#define _PMC_T210_H_ + +/*! PMC registers. */ +#define APBDEV_PMC_CNTRL 0x0 +#define PMC_CNTRL_RTC_CLK_DIS BIT(1) +#define PMC_CNTRL_RTC_RST BIT(2) +#define PMC_CNTRL_MAIN_RST BIT(4) +#define PMC_CNTRL_LATCHWAKE_EN BIT(5) +#define PMC_CNTRL_BLINK_EN BIT(7) +#define PMC_CNTRL_PWRREQ_OE BIT(9) +#define PMC_CNTRL_SYSCLK_OE BIT(11) +#define PMC_CNTRL_PWRGATE_DIS BIT(12) +#define PMC_CNTRL_SIDE_EFFECT_LP0 BIT(14) +#define PMC_CNTRL_CPUPWRREQ_OE BIT(16) +#define PMC_CNTRL_FUSE_OVERRIDE BIT(18) +#define PMC_CNTRL_SHUTDOWN_OE BIT(22) + +#define APBDEV_PMC_SEC_DISABLE 0x4 +#define APBDEV_PMC_PMC_SWRST 0x8 +#define APBDEV_PMC_WAKE_MASK 0xC +#define APBDEV_PMC_WAKE_LVL 0x10 +#define APBDEV_PMC_WAKE_STATUS 0x14 +#define APBDEV_PMC_SW_WAKE_STATUS 0x18 +#define APBDEV_PMC_DPD_PADS_ORIDE 0x1C +#define APBDEV_PMC_DPD_SAMPLE 0x20 +#define APBDEV_PMC_DPD_ENABLE 0x24 +#define APBDEV_PMC_PWRGATE_TIMER_OFF 0x28 +#define APBDEV_PMC_CLAMP_STATUS 0x2C + +#define APBDEV_PMC_PWRGATE_TOGGLE 0x30 +#define PMC_PWRGATE_TOGGLE_START BIT(8) + +#define APBDEV_PMC_REMOVE_CLAMPING_CMD 0x34 +#define APBDEV_PMC_PWRGATE_STATUS 0x38 +#define APBDEV_PMC_PWRGOOD_TIMER 0x3C +#define APBDEV_PMC_BLINK_TIMER 0x40 +#define PMC_BLINK_ON(n) ((n & 0x7FFF)) +#define PMC_BLINK_FORCE BIT(15) +#define PMC_BLINK_OFF(n) ((u32)(n & 0xFFFF) << 16) + +#define APBDEV_PMC_NO_IOPOWER 0x44 +#define PMC_NO_IOPOWER_MEM BIT(7) +#define PMC_NO_IOPOWER_SDMMC1 BIT(12) +#define PMC_NO_IOPOWER_SDMMC4 BIT(14) +#define PMC_NO_IOPOWER_MEM_COMP BIT(16) +#define PMC_NO_IOPOWER_AUDIO_HV BIT(18) +#define PMC_NO_IOPOWER_GPIO BIT(21) + +#define APBDEV_PMC_PWR_DET 0x48 +#define APBDEV_PMC_PWR_DET_LATCH 0x4C + +#define APBDEV_PMC_SCRATCH0 0x50 +#define PMC_SCRATCH0_MODE_WARMBOOT BIT(0) +#define PMC_SCRATCH0_MODE_RCM BIT(1) +#define PMC_SCRATCH0_MODE_PAYLOAD BIT(29) +#define PMC_SCRATCH0_MODE_BOOTLOADER BIT(30) +#define PMC_SCRATCH0_MODE_RECOVERY BIT(31) +#define PMC_SCRATCH0_MODE_CUSTOM_ALL (PMC_SCRATCH0_MODE_RECOVERY | \ + PMC_SCRATCH0_MODE_BOOTLOADER | \ + PMC_SCRATCH0_MODE_PAYLOAD) + +#define APBDEV_PMC_SCRATCH1 0x54 +#define APBDEV_PMC_SCRATCH2 0x58 +#define APBDEV_PMC_SCRATCH3 0x5C +#define APBDEV_PMC_SCRATCH4 0x60 +#define APBDEV_PMC_SCRATCH5 0x64 +#define APBDEV_PMC_SCRATCH6 0x68 +#define APBDEV_PMC_SCRATCH7 0x6C +#define APBDEV_PMC_SCRATCH8 0x70 +#define APBDEV_PMC_SCRATCH9 0x74 +#define APBDEV_PMC_SCRATCH10 0x78 +#define APBDEV_PMC_SCRATCH11 0x7C +#define APBDEV_PMC_SCRATCH12 0x80 +#define APBDEV_PMC_SCRATCH13 0x84 +#define APBDEV_PMC_SCRATCH14 0x88 +#define APBDEV_PMC_SCRATCH15 0x8C +#define APBDEV_PMC_SCRATCH16 0x90 +#define APBDEV_PMC_SCRATCH17 0x94 +#define APBDEV_PMC_SCRATCH18 0x98 +#define APBDEV_PMC_SCRATCH19 0x9C +#define APBDEV_PMC_SCRATCH20 0xA0 // ODM data/config scratch. +#define APBDEV_PMC_SCRATCH21 0xA4 +#define APBDEV_PMC_SCRATCH22 0xA8 +#define APBDEV_PMC_SCRATCH23 0xAC +#define APBDEV_PMC_SECURE_SCRATCH0 0xB0 +#define APBDEV_PMC_SECURE_SCRATCH1 0xB4 +#define APBDEV_PMC_SECURE_SCRATCH2 0xB8 +#define APBDEV_PMC_SECURE_SCRATCH3 0xBC +#define APBDEV_PMC_SECURE_SCRATCH4 0xC0 +#define APBDEV_PMC_SECURE_SCRATCH5 0xC4 +#define APBDEV_PMC_CPUPWRGOOD_TIMER 0xC8 +#define APBDEV_PMC_CPUPWROFF_TIMER 0xCC +#define APBDEV_PMC_PG_MASK 0xD0 +#define APBDEV_PMC_PG_MASK_1 0xD4 +#define APBDEV_PMC_AUTO_WAKE_LVL 0xD8 +#define APBDEV_PMC_AUTO_WAKE_LVL_MASK 0xDC +#define APBDEV_PMC_WAKE_DELAY 0xE0 + +#define APBDEV_PMC_PWR_DET_VAL 0xE4 +#define PMC_PWR_DET_33V_SDMMC1 BIT(12) +#define PMC_PWR_DET_33V_AUDIO_HV BIT(18) +#define PMC_PWR_DET_33V_GPIO BIT(21) + +#define APBDEV_PMC_DDR_PWR 0xE8 +#define APBDEV_PMC_USB_DEBOUNCE_DEL 0xEC +#define APBDEV_PMC_USB_AO 0xF0 + +#define APBDEV_PMC_CRYPTO_OP 0xF4 +#define PMC_CRYPTO_OP_SE_ENABLE 0 +#define PMC_CRYPTO_OP_SE_DISABLE 1 + +#define APBDEV_PMC_PLLP_WB0_OVERRIDE 0xF8 +#define PMC_PLLP_WB0_OVR_PLLM_OVR_ENABLE BIT(11) +#define PMC_PLLP_WB0_OVR_PLLM_ENABLE BIT(12) + +#define APBDEV_PMC_SCRATCH24 0xFC +#define APBDEV_PMC_SCRATCH25 0x100 +#define APBDEV_PMC_SCRATCH26 0x104 +#define APBDEV_PMC_SCRATCH27 0x108 +#define APBDEV_PMC_SCRATCH28 0x10C +#define APBDEV_PMC_SCRATCH29 0x110 +#define APBDEV_PMC_SCRATCH30 0x114 +#define APBDEV_PMC_SCRATCH31 0x118 +#define APBDEV_PMC_SCRATCH32 0x11C +#define APBDEV_PMC_SCRATCH33 0x120 +#define APBDEV_PMC_SCRATCH34 0x124 +#define APBDEV_PMC_SCRATCH35 0x128 +#define APBDEV_PMC_SCRATCH36 0x12C +#define APBDEV_PMC_SCRATCH37 0x130 +#define PMC_SCRATCH37_KERNEL_PANIC_MAGIC 0x4E415054 // "TPAN" + +#define APBDEV_PMC_SCRATCH38 0x134 +#define APBDEV_PMC_SCRATCH39 0x138 +#define APBDEV_PMC_SCRATCH40 0x13C +#define APBDEV_PMC_SCRATCH41 0x140 +#define APBDEV_PMC_SCRATCH42 0x144 +#define APBDEV_PMC_BONDOUT_MIRROR0 0x148 +#define APBDEV_PMC_BONDOUT_MIRROR1 0x14C +#define APBDEV_PMC_BONDOUT_MIRROR2 0x150 +#define APBDEV_PMC_SYS_33V_EN 0x154 +#define APBDEV_PMC_BONDOUT_MIRROR_ACCESS 0x158 +#define APBDEV_PMC_GATE 0x15C +#define APBDEV_PMC_WAKE2_MASK 0x160 +#define APBDEV_PMC_WAKE2_LVL 0x164 +#define APBDEV_PMC_WAKE2_STATUS 0x168 +#define APBDEV_PMC_SW_WAKE2_STATUS 0x16C +#define APBDEV_PMC_AUTO_WAKE2_LVL_MASK 0x170 +#define APBDEV_PMC_PG_MASK_2 0x174 +#define APBDEV_PMC_PG_MASK_CE1 0x178 +#define APBDEV_PMC_PG_MASK_CE2 0x17C +#define APBDEV_PMC_PG_MASK_CE3 0x180 +#define APBDEV_PMC_PWRGATE_TIMER_CE_0 0x184 +#define APBDEV_PMC_PWRGATE_TIMER_CE_1 0x188 +#define APBDEV_PMC_PWRGATE_TIMER_CE_2 0x18C +#define APBDEV_PMC_PWRGATE_TIMER_CE_3 0x190 +#define APBDEV_PMC_PWRGATE_TIMER_CE_4 0x194 +#define APBDEV_PMC_PWRGATE_TIMER_CE_5 0x198 +#define APBDEV_PMC_PWRGATE_TIMER_CE_6 0x19C +#define APBDEV_PMC_PCX_EDPD_CNTRL 0x1A0 + +#define APBDEV_PMC_OSC_EDPD_OVER 0x1A4 +#define PMC_OSC_EDPD_OVER_OSC_CTRL_OVER BIT(22) + +#define APBDEV_PMC_CLK_OUT_CNTRL 0x1A8 +#define PMC_CLK_OUT_CNTRL_CLK1_FORCE_EN BIT(2) +#define PMC_CLK_OUT_CNTRL_CLK2_FORCE_EN BIT(10) +#define PMC_CLK_OUT_CNTRL_CLK3_FORCE_EN BIT(18) +#define PMC_CLK_OUT_CNTRL_CLK1_SRC_SEL(src) (((src) & 3) << 6) +#define PMC_CLK_OUT_CNTRL_CLK2_SRC_SEL(src) (((src) & 3) << 14) +#define PMC_CLK_OUT_CNTRL_CLK3_SRC_SEL(src) (((src) & 3) << 22) +#define OSC_DIV1 0 +#define OSC_DIV2 1 +#define OSC_DIV4 2 +#define OSC_CAR 3 + +#define APBDEV_PMC_SATA_PWRGT 0x1AC +#define APBDEV_PMC_SENSOR_CTRL 0x1B0 + +#define APBDEV_PMC_RST_STATUS 0x1B4 +#define PMC_RST_STATUS_MASK 7 +#define PMC_RST_STATUS_POR 0 +#define PMC_RST_STATUS_WATCHDOG 1 +#define PMC_RST_STATUS_SENSOR 2 +#define PMC_RST_STATUS_SW_MAIN 3 +#define PMC_RST_STATUS_LP0 4 +#define PMC_RST_STATUS_AOTAG 5 + +#define APBDEV_PMC_IO_DPD_REQ 0x1B8 +#define PMC_IO_DPD_REQ_DPD_IDLE (0 << 30u) +#define PMC_IO_DPD_REQ_DPD_OFF (1 << 30u) +#define PMC_IO_DPD_REQ_DPD_ON (2 << 30u) + +#define APBDEV_PMC_IO_DPD_STATUS 0x1BC +#define APBDEV_PMC_IO_DPD2_REQ 0x1C0 +#define APBDEV_PMC_IO_DPD2_STATUS 0x1C4 +#define APBDEV_PMC_SEL_DPD_TIM 0x1C8 +#define APBDEV_PMC_VDDP_SEL 0x1CC +#define APBDEV_PMC_DDR_CFG 0x1D0 +#define APBDEV_PMC_E_NO_VTTGEN 0x1D4 +#define APBDEV_PMC_PLLM_WB0_OVERRIDE_FREQ 0x1DC +#define APBDEV_PMC_TEST_PWRGATE 0x1E0 +#define APBDEV_PMC_PWRGATE_TIMER_MULT 0x1E4 +#define APBDEV_PMC_DSI_SEL_DPD 0x1E8 +#define APBDEV_PMC_UTMIP_UHSIC_TRIGGERS 0x1EC +#define APBDEV_PMC_UTMIP_UHSIC_SAVED_STATE 0x1F0 +#define APBDEV_PMC_UTMIP_TERM_PAD_CFG 0x1F8 +#define APBDEV_PMC_UTMIP_UHSIC_SLEEP_CFG 0x1FC +#define APBDEV_PMC_UTMIP_UHSIC_SLEEPWALK_CFG 0x200 +#define APBDEV_PMC_UTMIP_SLEEPWALK_P0 0x204 +#define APBDEV_PMC_UTMIP_SLEEPWALK_P1 0x208 +#define APBDEV_PMC_UTMIP_SLEEPWALK_P2 0x20C +#define APBDEV_PMC_UHSIC_SLEEPWALK_P0 0x210 +#define APBDEV_PMC_UTMIP_UHSIC_STATUS 0x214 +#define APBDEV_PMC_UTMIP_UHSIC_FAKE 0x218 +#define APBDEV_PMC_BONDOUT_MIRROR3 0x21C +#define APBDEV_PMC_BONDOUT_MIRROR4 0x220 +#define APBDEV_PMC_SECURE_SCRATCH6 0x224 +#define APBDEV_PMC_SECURE_SCRATCH7 0x228 +#define APBDEV_PMC_SCRATCH43 0x22C +#define APBDEV_PMC_SCRATCH44 0x230 +#define APBDEV_PMC_SCRATCH45 0x234 +#define APBDEV_PMC_SCRATCH46 0x238 +#define APBDEV_PMC_SCRATCH47 0x23C +#define APBDEV_PMC_SCRATCH48 0x240 +#define APBDEV_PMC_SCRATCH49 0x244 +#define APBDEV_PMC_SCRATCH50 0x248 +#define APBDEV_PMC_SCRATCH51 0x24C +#define APBDEV_PMC_SCRATCH52 0x250 +#define APBDEV_PMC_SCRATCH53 0x254 +#define APBDEV_PMC_SCRATCH54 0x258 +#define APBDEV_PMC_SCRATCH55 0x25C +#define APBDEV_PMC_SCRATCH0_ECO 0x260 +#define APBDEV_PMC_POR_DPD_CTRL 0x264 +#define APBDEV_PMC_SCRATCH2_ECO 0x268 +#define APBDEV_PMC_UTMIP_UHSIC_LINE_WAKEUP 0x26C +#define APBDEV_PMC_UTMIP_BIAS_MASTER_CNTRL 0x270 +#define APBDEV_PMC_UTMIP_MASTER_CONFIG 0x274 +#define APBDEV_PMC_TD_PWRGATE_INTER_PART_TIMER 0x278 +#define APBDEV_PMC_UTMIP_UHSIC2_TRIGGERS 0x27C +#define APBDEV_PMC_UTMIP_UHSIC2_SAVED_STATE 0x280 +#define APBDEV_PMC_UTMIP_UHSIC2_SLEEP_CFG 0x284 +#define APBDEV_PMC_UTMIP_UHSIC2_SLEEPWALK_CFG 0x288 +#define APBDEV_PMC_UHSIC2_SLEEPWALK_P1 0x28C +#define APBDEV_PMC_UTMIP_UHSIC2_STATUS 0x290 +#define APBDEV_PMC_UTMIP_UHSIC2_FAKE 0x294 +#define APBDEV_PMC_UTMIP_UHSIC2_LINE_WAKEUP 0x298 +#define APBDEV_PMC_UTMIP_MASTER2_CONFIG 0x29C +#define APBDEV_PMC_UTMIP_UHSIC_RPD_CFG 0x2A0 +#define APBDEV_PMC_PG_MASK_CE0 0x2A4 +#define APBDEV_PMC_PG_MASK_3 0x2A8 +#define APBDEV_PMC_PG_MASK_4 0x2AC +#define APBDEV_PMC_PLLM_WB0_OVERRIDE2 0x2B0 +#define APBDEV_PMC_TSC_MULT 0x2B4 +#define APBDEV_PMC_CPU_VSENSE_OVERRIDE 0x2B8 +#define APBDEV_PMC_GLB_AMAP_CFG 0x2BC + +#define APBDEV_PMC_STICKY_BITS 0x2C0 +#define PMC_STICKY_BITS_HDA_LPBK_DIS BIT(0) + +#define APBDEV_PMC_SEC_DISABLE2 0x2C4 +#define APBDEV_PMC_WEAK_BIAS 0x2C8 +#define APBDEV_PMC_REG_SHORT 0x2CC +#define APBDEV_PMC_PG_MASK_ANDOR 0x2D0 +#define APBDEV_PMC_GPU_RG_CNTRL 0x2D4 +#define APBDEV_PMC_SEC_DISABLE3 0x2D8 +#define APBDEV_PMC_PG_MASK_5 0x2DC +#define APBDEV_PMC_PG_MASK_6 0x2E0 +#define APBDEV_PMC_SECURE_SCRATCH8 0x300 +#define APBDEV_PMC_SECURE_SCRATCH9 0x304 +#define APBDEV_PMC_SECURE_SCRATCH10 0x308 +#define APBDEV_PMC_SECURE_SCRATCH11 0x30C +#define APBDEV_PMC_SECURE_SCRATCH12 0x310 +#define APBDEV_PMC_SECURE_SCRATCH13 0x314 +#define APBDEV_PMC_SECURE_SCRATCH14 0x318 +#define APBDEV_PMC_SECURE_SCRATCH15 0x31C +#define APBDEV_PMC_SECURE_SCRATCH16 0x320 +#define APBDEV_PMC_SECURE_SCRATCH17 0x324 +#define APBDEV_PMC_SECURE_SCRATCH18 0x328 +#define APBDEV_PMC_SECURE_SCRATCH19 0x32C +#define APBDEV_PMC_SECURE_SCRATCH20 0x330 + +#define APBDEV_PMC_SECURE_SCRATCH21 0x334 +#define PMC_FUSE_PRIVATEKEYDISABLE_TZ_STICKY_BIT BIT(4) + +#define APBDEV_PMC_SECURE_SCRATCH22 0x338 // AArch32 reset address. +#define APBDEV_PMC_SECURE_SCRATCH23 0x33C +#define APBDEV_PMC_SECURE_SCRATCH24 0x340 +#define APBDEV_PMC_SECURE_SCRATCH25 0x344 +#define APBDEV_PMC_SECURE_SCRATCH26 0x348 +#define APBDEV_PMC_SECURE_SCRATCH27 0x34C +#define APBDEV_PMC_SECURE_SCRATCH28 0x350 +#define APBDEV_PMC_SECURE_SCRATCH29 0x354 +#define APBDEV_PMC_SECURE_SCRATCH30 0x358 +#define APBDEV_PMC_SECURE_SCRATCH31 0x35C +#define APBDEV_PMC_SECURE_SCRATCH32 0x360 +#define APBDEV_PMC_SECURE_SCRATCH33 0x364 +#define APBDEV_PMC_SECURE_SCRATCH34 0x368 // AArch64 reset address. +#define APBDEV_PMC_SECURE_SCRATCH35 0x36C // AArch64 reset hi-address. +#define APBDEV_PMC_SECURE_SCRATCH36 0x370 +#define APBDEV_PMC_SECURE_SCRATCH37 0x374 +#define APBDEV_PMC_SECURE_SCRATCH38 0x378 +#define APBDEV_PMC_SECURE_SCRATCH39 0x37C +#define APBDEV_PMC_SECURE_SCRATCH40 0x380 +#define APBDEV_PMC_SECURE_SCRATCH41 0x384 +#define APBDEV_PMC_SECURE_SCRATCH42 0x388 +#define APBDEV_PMC_SECURE_SCRATCH43 0x38C +#define APBDEV_PMC_SECURE_SCRATCH44 0x390 +#define APBDEV_PMC_SECURE_SCRATCH45 0x394 +#define APBDEV_PMC_SECURE_SCRATCH46 0x398 +#define APBDEV_PMC_SECURE_SCRATCH47 0x39C +#define APBDEV_PMC_SECURE_SCRATCH48 0x3A0 +#define APBDEV_PMC_SECURE_SCRATCH49 0x3A4 +#define APBDEV_PMC_SECURE_SCRATCH50 0x3A8 +#define APBDEV_PMC_SECURE_SCRATCH51 0x3AC +#define APBDEV_PMC_SECURE_SCRATCH52 0x3B0 +#define APBDEV_PMC_SECURE_SCRATCH53 0x3B4 +#define APBDEV_PMC_SECURE_SCRATCH54 0x3B8 +#define APBDEV_PMC_SECURE_SCRATCH55 0x3BC +#define APBDEV_PMC_SECURE_SCRATCH56 0x3C0 +#define APBDEV_PMC_SECURE_SCRATCH57 0x3C4 +#define APBDEV_PMC_SECURE_SCRATCH58 0x3C8 +#define APBDEV_PMC_SECURE_SCRATCH59 0x3CC +#define APBDEV_PMC_SECURE_SCRATCH60 0x3D0 +#define APBDEV_PMC_SECURE_SCRATCH61 0x3D4 +#define APBDEV_PMC_SECURE_SCRATCH62 0x3D8 +#define APBDEV_PMC_SECURE_SCRATCH63 0x3DC +#define APBDEV_PMC_SECURE_SCRATCH64 0x3E0 +#define APBDEV_PMC_SECURE_SCRATCH65 0x3E4 +#define APBDEV_PMC_SECURE_SCRATCH66 0x3E8 +#define APBDEV_PMC_SECURE_SCRATCH67 0x3EC +#define APBDEV_PMC_SECURE_SCRATCH68 0x3F0 +#define APBDEV_PMC_SECURE_SCRATCH69 0x3F4 +#define APBDEV_PMC_SECURE_SCRATCH70 0x3F8 +#define APBDEV_PMC_SECURE_SCRATCH71 0x3FC +#define APBDEV_PMC_SECURE_SCRATCH72 0x400 +#define APBDEV_PMC_SECURE_SCRATCH73 0x404 +#define APBDEV_PMC_SECURE_SCRATCH74 0x408 +#define APBDEV_PMC_SECURE_SCRATCH75 0x40C +#define APBDEV_PMC_SECURE_SCRATCH76 0x410 +#define APBDEV_PMC_SECURE_SCRATCH77 0x414 +#define APBDEV_PMC_SECURE_SCRATCH78 0x418 +#define APBDEV_PMC_SECURE_SCRATCH79 0x41C + +#define APBDEV_PMC_CNTRL2 0x440 +#define PMC_CNTRL2_WAKE_INT_EN BIT(0) +#define PMC_CNTRL2_WAKE_DET_EN BIT(9) +#define PMC_CNTRL2_SYSCLK_ORRIDE BIT(10) +#define PMC_CNTRL2_HOLD_CKE_LOW_EN BIT(12) +#define PMC_CNTRL2_ALLOW_PULSE_WAKE BIT(14) + +#define APBDEV_PMC_IO_DPD_OFF_MASK 0x444 +#define APBDEV_PMC_IO_DPD2_OFF_MASK 0x448 +#define APBDEV_PMC_EVENT_COUNTER 0x44C + +#define APBDEV_PMC_FUSE_CONTROL 0x450 +#define PMC_FUSE_CONTROL_PS18_LATCH_SET BIT(8) +#define PMC_FUSE_CONTROL_PS18_LATCH_CLR BIT(9) + +#define APBDEV_PMC_SCRATCH1_ECO 0x454 +#define APBDEV_PMC_IO_DPD3_REQ 0x45C +#define APBDEV_PMC_IO_DPD3_STATUS 0x460 +#define APBDEV_PMC_IO_DPD4_REQ 0x464 +#define APBDEV_PMC_IO_DPD4_STATUS 0x468 +#define APBDEV_PMC_DIRECT_THERMTRIP_CFG 0x474 +#define APBDEV_PMC_TSOSC_DELAY 0x478 +#define APBDEV_PMC_SET_SW_CLAMP 0x47C +#define APBDEV_PMC_DEBUG_AUTHENTICATION 0x480 +#define APBDEV_PMC_AOTAG_CFG 0x484 +#define APBDEV_PMC_AOTAG_THRESH1_CFG 0x488 +#define APBDEV_PMC_AOTAG_THRESH2_CFG 0x48C +#define APBDEV_PMC_AOTAG_THRESH3_CFG 0x490 +#define APBDEV_PMC_AOTAG_STATUS 0x494 +#define APBDEV_PMC_AOTAG_SECURITY 0x498 +#define APBDEV_PMC_TSENSOR_CONFIG0 0x49C +#define APBDEV_PMC_TSENSOR_CONFIG1 0x4A0 +#define APBDEV_PMC_TSENSOR_CONFIG2 0x4A4 +#define APBDEV_PMC_TSENSOR_STATUS0 0x4A8 +#define APBDEV_PMC_TSENSOR_STATUS1 0x4AC +#define APBDEV_PMC_TSENSOR_STATUS2 0x4B0 +#define APBDEV_PMC_TSENSOR_PDIV 0x4B4 +#define APBDEV_PMC_AOTAG_INTR_EN 0x4B8 +#define APBDEV_PMC_AOTAG_INTR_DIS 0x4BC +#define APBDEV_PMC_UTMIP_PAD_CFG0 0x4C0 +#define APBDEV_PMC_UTMIP_PAD_CFG1 0x4C4 +#define APBDEV_PMC_UTMIP_PAD_CFG2 0x4C8 +#define APBDEV_PMC_UTMIP_PAD_CFG3 0x4CC +#define APBDEV_PMC_UTMIP_UHSIC_SLEEP_CFG1 0x4D0 +#define APBDEV_PMC_CC4_HVC_CONTROL 0x4D4 +#define APBDEV_PMC_WAKE_DEBOUNCE_EN 0x4D8 +#define APBDEV_PMC_RAMDUMP_CTL_STATUS 0x4DC +#define APBDEV_PMC_UTMIP_SLEEPWALK_P3 0x4E0 +#define APBDEV_PMC_DDR_CNTRL 0x4E4 +#define APBDEV_PMC_SEC_DISABLE4 0x5B0 +#define APBDEV_PMC_SEC_DISABLE5 0x5B4 +#define APBDEV_PMC_SEC_DISABLE6 0x5B8 +#define APBDEV_PMC_SEC_DISABLE7 0x5BC +#define APBDEV_PMC_SEC_DISABLE8 0x5C0 +#define APBDEV_PMC_SCRATCH56 0x600 +#define APBDEV_PMC_SCRATCH57 0x604 +#define APBDEV_PMC_SCRATCH58 0x608 +#define APBDEV_PMC_SCRATCH59 0x60C +#define APBDEV_PMC_SCRATCH60 0x610 +#define APBDEV_PMC_SCRATCH61 0x614 +#define APBDEV_PMC_SCRATCH62 0x618 +#define APBDEV_PMC_SCRATCH63 0x61C +#define APBDEV_PMC_SCRATCH64 0x620 +#define APBDEV_PMC_SCRATCH65 0x624 +#define APBDEV_PMC_SCRATCH66 0x628 +#define APBDEV_PMC_SCRATCH67 0x62C +#define APBDEV_PMC_SCRATCH68 0x630 +#define APBDEV_PMC_SCRATCH69 0x634 +#define APBDEV_PMC_SCRATCH70 0x638 +#define APBDEV_PMC_SCRATCH71 0x63C +#define APBDEV_PMC_SCRATCH72 0x640 +#define APBDEV_PMC_SCRATCH73 0x644 +#define APBDEV_PMC_SCRATCH74 0x648 +#define APBDEV_PMC_SCRATCH75 0x64C +#define APBDEV_PMC_SCRATCH76 0x650 +#define APBDEV_PMC_SCRATCH77 0x654 +#define APBDEV_PMC_SCRATCH78 0x658 +#define APBDEV_PMC_SCRATCH79 0x65C +#define APBDEV_PMC_SCRATCH80 0x660 +#define APBDEV_PMC_SCRATCH81 0x664 +#define APBDEV_PMC_SCRATCH82 0x668 +#define APBDEV_PMC_SCRATCH83 0x66C +#define APBDEV_PMC_SCRATCH84 0x670 +#define APBDEV_PMC_SCRATCH85 0x674 +#define APBDEV_PMC_SCRATCH86 0x678 +#define APBDEV_PMC_SCRATCH87 0x67C +#define APBDEV_PMC_SCRATCH88 0x680 +#define APBDEV_PMC_SCRATCH89 0x684 +#define APBDEV_PMC_SCRATCH90 0x688 +#define APBDEV_PMC_SCRATCH91 0x68C +#define APBDEV_PMC_SCRATCH92 0x690 +#define APBDEV_PMC_SCRATCH93 0x694 +#define APBDEV_PMC_SCRATCH94 0x698 +#define APBDEV_PMC_SCRATCH95 0x69C +#define APBDEV_PMC_SCRATCH96 0x6A0 +#define APBDEV_PMC_SCRATCH97 0x6A4 +#define APBDEV_PMC_SCRATCH98 0x6A8 +#define APBDEV_PMC_SCRATCH99 0x6AC +#define APBDEV_PMC_SCRATCH100 0x6B0 +#define APBDEV_PMC_SCRATCH101 0x6B4 +#define APBDEV_PMC_SCRATCH102 0x6B8 +#define APBDEV_PMC_SCRATCH103 0x6BC +#define APBDEV_PMC_SCRATCH104 0x6C0 +#define APBDEV_PMC_SCRATCH105 0x6C4 +#define APBDEV_PMC_SCRATCH106 0x6C8 +#define APBDEV_PMC_SCRATCH107 0x6CC +#define APBDEV_PMC_SCRATCH108 0x6D0 +#define APBDEV_PMC_SCRATCH109 0x6D4 +#define APBDEV_PMC_SCRATCH110 0x6D8 +#define APBDEV_PMC_SCRATCH111 0x6DC +#define APBDEV_PMC_SCRATCH112 0x6E0 +#define APBDEV_PMC_SCRATCH113 0x6E4 +#define APBDEV_PMC_SCRATCH114 0x6E8 +#define APBDEV_PMC_SCRATCH115 0x6EC +#define APBDEV_PMC_SCRATCH116 0x6F0 +#define APBDEV_PMC_SCRATCH117 0x6F4 +#define APBDEV_PMC_SCRATCH118 0x6F8 +#define APBDEV_PMC_SCRATCH119 0x6FC +#define APBDEV_PMC_SCRATCH120 0x700 +#define APBDEV_PMC_SCRATCH121 0x704 +#define APBDEV_PMC_SCRATCH122 0x708 +#define APBDEV_PMC_SCRATCH123 0x70C +#define APBDEV_PMC_SCRATCH124 0x710 +#define APBDEV_PMC_SCRATCH125 0x714 +#define APBDEV_PMC_SCRATCH126 0x718 +#define APBDEV_PMC_SCRATCH127 0x71C +#define APBDEV_PMC_SCRATCH128 0x720 +#define APBDEV_PMC_SCRATCH129 0x724 +#define APBDEV_PMC_SCRATCH130 0x728 +#define APBDEV_PMC_SCRATCH131 0x72C +#define APBDEV_PMC_SCRATCH132 0x730 +#define APBDEV_PMC_SCRATCH133 0x734 +#define APBDEV_PMC_SCRATCH134 0x738 +#define APBDEV_PMC_SCRATCH135 0x73C +#define APBDEV_PMC_SCRATCH136 0x740 +#define APBDEV_PMC_SCRATCH137 0x744 +#define APBDEV_PMC_SCRATCH138 0x748 +#define APBDEV_PMC_SCRATCH139 0x74C +#define APBDEV_PMC_SCRATCH140 0x750 +#define APBDEV_PMC_SCRATCH141 0x754 +#define APBDEV_PMC_SCRATCH142 0x758 +#define APBDEV_PMC_SCRATCH143 0x75C +#define APBDEV_PMC_SCRATCH144 0x760 +#define APBDEV_PMC_SCRATCH145 0x764 +#define APBDEV_PMC_SCRATCH146 0x768 +#define APBDEV_PMC_SCRATCH147 0x76C +#define APBDEV_PMC_SCRATCH148 0x770 +#define APBDEV_PMC_SCRATCH149 0x774 +#define APBDEV_PMC_SCRATCH150 0x778 +#define APBDEV_PMC_SCRATCH151 0x77C +#define APBDEV_PMC_SCRATCH152 0x780 +#define APBDEV_PMC_SCRATCH153 0x784 +#define APBDEV_PMC_SCRATCH154 0x788 +#define APBDEV_PMC_SCRATCH155 0x78C +#define APBDEV_PMC_SCRATCH156 0x790 +#define APBDEV_PMC_SCRATCH157 0x794 +#define APBDEV_PMC_SCRATCH158 0x798 +#define APBDEV_PMC_SCRATCH159 0x79C +#define APBDEV_PMC_SCRATCH160 0x7A0 +#define APBDEV_PMC_SCRATCH161 0x7A4 +#define APBDEV_PMC_SCRATCH162 0x7A8 +#define APBDEV_PMC_SCRATCH163 0x7AC +#define APBDEV_PMC_SCRATCH164 0x7B0 +#define APBDEV_PMC_SCRATCH165 0x7B4 +#define APBDEV_PMC_SCRATCH166 0x7B8 +#define APBDEV_PMC_SCRATCH167 0x7BC +#define APBDEV_PMC_SCRATCH168 0x7C0 +#define APBDEV_PMC_SCRATCH169 0x7C4 +#define APBDEV_PMC_SCRATCH170 0x7C8 +#define APBDEV_PMC_SCRATCH171 0x7CC +#define APBDEV_PMC_SCRATCH172 0x7D0 +#define APBDEV_PMC_SCRATCH173 0x7D4 +#define APBDEV_PMC_SCRATCH174 0x7D8 +#define APBDEV_PMC_SCRATCH175 0x7DC +#define APBDEV_PMC_SCRATCH176 0x7E0 +#define APBDEV_PMC_SCRATCH177 0x7E4 +#define APBDEV_PMC_SCRATCH178 0x7E8 +#define APBDEV_PMC_SCRATCH179 0x7EC +#define APBDEV_PMC_SCRATCH180 0x7F0 +#define APBDEV_PMC_SCRATCH181 0x7F4 +#define APBDEV_PMC_SCRATCH182 0x7F8 +#define APBDEV_PMC_SCRATCH183 0x7FC +#define APBDEV_PMC_SCRATCH184 0x800 +#define APBDEV_PMC_SCRATCH185 0x804 +#define APBDEV_PMC_SCRATCH186 0x808 +#define APBDEV_PMC_SCRATCH187 0x80C +#define APBDEV_PMC_SCRATCH188 0x810 +#define APBDEV_PMC_SCRATCH189 0x814 +#define APBDEV_PMC_SCRATCH190 0x818 +#define APBDEV_PMC_SCRATCH191 0x81C +#define APBDEV_PMC_SCRATCH192 0x820 +#define APBDEV_PMC_SCRATCH193 0x824 +#define APBDEV_PMC_SCRATCH194 0x828 +#define APBDEV_PMC_SCRATCH195 0x82C +#define APBDEV_PMC_SCRATCH196 0x830 +#define APBDEV_PMC_SCRATCH197 0x834 +#define APBDEV_PMC_SCRATCH198 0x838 +#define APBDEV_PMC_SCRATCH199 0x83C + +#define APBDEV_PMC_SCRATCH200 0x840 +#define PMC_NX_PANIC_SAFE_MODE 0x20 +#define PMC_NX_PANIC_BYPASS_FUSES 0x21 + +#define APBDEV_PMC_SCRATCH201 0x844 +#define APBDEV_PMC_SCRATCH202 0x848 +#define APBDEV_PMC_SCRATCH203 0x84C +#define APBDEV_PMC_SCRATCH204 0x850 +#define APBDEV_PMC_SCRATCH205 0x854 +#define APBDEV_PMC_SCRATCH206 0x858 +#define APBDEV_PMC_SCRATCH207 0x85C +#define APBDEV_PMC_SCRATCH208 0x860 +#define APBDEV_PMC_SCRATCH209 0x864 +#define APBDEV_PMC_SCRATCH210 0x868 +#define APBDEV_PMC_SCRATCH211 0x86C +#define APBDEV_PMC_SCRATCH212 0x870 +#define APBDEV_PMC_SCRATCH213 0x874 +#define APBDEV_PMC_SCRATCH214 0x878 +#define APBDEV_PMC_SCRATCH215 0x87C +#define APBDEV_PMC_SCRATCH216 0x880 +#define APBDEV_PMC_SCRATCH217 0x884 +#define APBDEV_PMC_SCRATCH218 0x888 +#define APBDEV_PMC_SCRATCH219 0x88C +#define APBDEV_PMC_SCRATCH220 0x890 +#define APBDEV_PMC_SCRATCH221 0x894 +#define APBDEV_PMC_SCRATCH222 0x898 +#define APBDEV_PMC_SCRATCH223 0x89C +#define APBDEV_PMC_SCRATCH224 0x8A0 +#define APBDEV_PMC_SCRATCH225 0x8A4 +#define APBDEV_PMC_SCRATCH226 0x8A8 +#define APBDEV_PMC_SCRATCH227 0x8AC +#define APBDEV_PMC_SCRATCH228 0x8B0 +#define APBDEV_PMC_SCRATCH229 0x8B4 +#define APBDEV_PMC_SCRATCH230 0x8B8 +#define APBDEV_PMC_SCRATCH231 0x8BC +#define APBDEV_PMC_SCRATCH232 0x8C0 +#define APBDEV_PMC_SCRATCH233 0x8C4 +#define APBDEV_PMC_SCRATCH234 0x8C8 +#define APBDEV_PMC_SCRATCH235 0x8CC +#define APBDEV_PMC_SCRATCH236 0x8D0 +#define APBDEV_PMC_SCRATCH237 0x8D4 +#define APBDEV_PMC_SCRATCH238 0x8D8 +#define APBDEV_PMC_SCRATCH239 0x8DC +#define APBDEV_PMC_SCRATCH240 0x8E0 +#define APBDEV_PMC_SCRATCH241 0x8E4 +#define APBDEV_PMC_SCRATCH242 0x8E8 +#define APBDEV_PMC_SCRATCH243 0x8EC +#define APBDEV_PMC_SCRATCH244 0x8F0 +#define APBDEV_PMC_SCRATCH245 0x8F4 +#define APBDEV_PMC_SCRATCH246 0x8F8 +#define APBDEV_PMC_SCRATCH247 0x8FC +#define APBDEV_PMC_SCRATCH248 0x900 +#define APBDEV_PMC_SCRATCH249 0x904 +#define APBDEV_PMC_SCRATCH250 0x908 +#define APBDEV_PMC_SCRATCH251 0x90C +#define APBDEV_PMC_SCRATCH252 0x910 +#define APBDEV_PMC_SCRATCH253 0x914 +#define APBDEV_PMC_SCRATCH254 0x918 +#define APBDEV_PMC_SCRATCH255 0x91C +#define APBDEV_PMC_SCRATCH256 0x920 +#define APBDEV_PMC_SCRATCH257 0x924 +#define APBDEV_PMC_SCRATCH258 0x928 +#define APBDEV_PMC_SCRATCH259 0x92C +#define APBDEV_PMC_SCRATCH260 0x930 +#define APBDEV_PMC_SCRATCH261 0x934 +#define APBDEV_PMC_SCRATCH262 0x938 +#define APBDEV_PMC_SCRATCH263 0x93C +#define APBDEV_PMC_SCRATCH264 0x940 +#define APBDEV_PMC_SCRATCH265 0x944 +#define APBDEV_PMC_SCRATCH266 0x948 +#define APBDEV_PMC_SCRATCH267 0x94C +#define APBDEV_PMC_SCRATCH268 0x950 +#define APBDEV_PMC_SCRATCH269 0x954 +#define APBDEV_PMC_SCRATCH270 0x958 +#define APBDEV_PMC_SCRATCH271 0x95C +#define APBDEV_PMC_SCRATCH272 0x960 +#define APBDEV_PMC_SCRATCH273 0x964 +#define APBDEV_PMC_SCRATCH274 0x968 +#define APBDEV_PMC_SCRATCH275 0x96C +#define APBDEV_PMC_SCRATCH276 0x970 +#define APBDEV_PMC_SCRATCH277 0x974 +#define APBDEV_PMC_SCRATCH278 0x978 +#define APBDEV_PMC_SCRATCH279 0x97C +#define APBDEV_PMC_SCRATCH280 0x980 +#define APBDEV_PMC_SCRATCH281 0x984 +#define APBDEV_PMC_SCRATCH282 0x988 +#define APBDEV_PMC_SCRATCH283 0x98C +#define APBDEV_PMC_SCRATCH284 0x990 +#define APBDEV_PMC_SCRATCH285 0x994 +#define APBDEV_PMC_SCRATCH286 0x998 +#define APBDEV_PMC_SCRATCH287 0x99C +#define APBDEV_PMC_SCRATCH288 0x9A0 +#define APBDEV_PMC_SCRATCH289 0x9A4 +#define APBDEV_PMC_SCRATCH290 0x9A8 +#define APBDEV_PMC_SCRATCH291 0x9AC +#define APBDEV_PMC_SCRATCH292 0x9B0 +#define APBDEV_PMC_SCRATCH293 0x9B4 +#define APBDEV_PMC_SCRATCH294 0x9B8 +#define APBDEV_PMC_SCRATCH295 0x9BC +#define APBDEV_PMC_SCRATCH296 0x9C0 +#define APBDEV_PMC_SCRATCH297 0x9C4 +#define APBDEV_PMC_SCRATCH298 0x9C8 +#define APBDEV_PMC_SCRATCH299 0x9CC +#define APBDEV_PMC_SECURE_SCRATCH80 0xA98 +#define APBDEV_PMC_SECURE_SCRATCH81 0xA9C +#define APBDEV_PMC_SECURE_SCRATCH82 0xAA0 +#define APBDEV_PMC_SECURE_SCRATCH83 0xAA4 +#define APBDEV_PMC_SECURE_SCRATCH84 0xAA8 +#define APBDEV_PMC_SECURE_SCRATCH85 0xAAC +#define APBDEV_PMC_SECURE_SCRATCH86 0xAB0 +#define APBDEV_PMC_SECURE_SCRATCH87 0xAB4 +#define APBDEV_PMC_SECURE_SCRATCH88 0xAB8 +#define APBDEV_PMC_SECURE_SCRATCH89 0xABC +#define APBDEV_PMC_SECURE_SCRATCH90 0xAC0 +#define APBDEV_PMC_SECURE_SCRATCH91 0xAC4 +#define APBDEV_PMC_SECURE_SCRATCH92 0xAC8 +#define APBDEV_PMC_SECURE_SCRATCH93 0xACC +#define APBDEV_PMC_SECURE_SCRATCH94 0xAD0 +#define APBDEV_PMC_SECURE_SCRATCH95 0xAD4 +#define APBDEV_PMC_SECURE_SCRATCH96 0xAD8 +#define APBDEV_PMC_SECURE_SCRATCH97 0xADC +#define APBDEV_PMC_SECURE_SCRATCH98 0xAE0 +#define APBDEV_PMC_SECURE_SCRATCH99 0xAE4 +#define APBDEV_PMC_SECURE_SCRATCH100 0xAE8 +#define APBDEV_PMC_SECURE_SCRATCH101 0xAEC +#define APBDEV_PMC_SECURE_SCRATCH102 0xAF0 +#define APBDEV_PMC_SECURE_SCRATCH103 0xAF4 +#define APBDEV_PMC_SECURE_SCRATCH104 0xAF8 +#define APBDEV_PMC_SECURE_SCRATCH105 0xAFC +#define APBDEV_PMC_SECURE_SCRATCH106 0xB00 +#define APBDEV_PMC_SECURE_SCRATCH107 0xB04 +#define APBDEV_PMC_SECURE_SCRATCH108 0xB08 +#define APBDEV_PMC_SECURE_SCRATCH109 0xB0C +#define APBDEV_PMC_SECURE_SCRATCH110 0xB10 +#define APBDEV_PMC_SECURE_SCRATCH111 0xB14 +#define APBDEV_PMC_SECURE_SCRATCH112 0xB18 +#define APBDEV_PMC_SECURE_SCRATCH113 0xB1C +#define APBDEV_PMC_SECURE_SCRATCH114 0xB20 +#define APBDEV_PMC_SECURE_SCRATCH115 0xB24 +#define APBDEV_PMC_SECURE_SCRATCH116 0xB28 +#define APBDEV_PMC_SECURE_SCRATCH117 0xB2C +#define APBDEV_PMC_SECURE_SCRATCH118 0xB30 +#define APBDEV_PMC_SECURE_SCRATCH119 0xB34 + +/* T210B01 only registers */ +#define APBDEV_PMC_SEC_DISABLE9_B01 0x5C4 +#define APBDEV_PMC_SEC_DISABLE10_B01 0x5C8 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE0_B01 0xA48 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE1_B01 0xA4C +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE2_B01 0xA50 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE3_B01 0xA54 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE4_B01 0xA58 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE5_B01 0xA5C +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE6_B01 0xA60 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE7_B01 0xA64 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE8_B01 0xA68 +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE9_B01 0xA6C +#define APBDEV_PMC_SCRATCH_WRITE_DISABLE10_B01 0xA70 +#define APBDEV_PMC_SCRATCH_WRITE_LOCK_DISABLE_STICKY_B01 0xA74 +#define APBDEV_PMC_SECURE_SCRATCH120_B01 0xB38 +#define APBDEV_PMC_SECURE_SCRATCH121_B01 0xB3C +#define APBDEV_PMC_SECURE_SCRATCH122_B01 0xB40 +#define APBDEV_PMC_SECURE_SCRATCH123_B01 0xB44 + +#define APBDEV_PMC_LED_BREATHING_CTRL_B01 0xB48 +#define PMC_LED_BREATHING_CTRL_ENABLE BIT(0) +#define PMC_LED_BREATHING_CTRL_COUNTER1_EN BIT(1) + +#define APBDEV_PMC_LED_BREATHING_SLOPE_STEPS_B01 0xB4C +#define APBDEV_PMC_LED_BREATHING_ON_COUNTER_B01 0xB50 +#define APBDEV_PMC_LED_BREATHING_OFF_COUNTER1_B01 0xB54 +#define APBDEV_PMC_LED_BREATHING_OFF_COUNTER0_B01 0xB58 +#define PMC_LED_BREATHING_COUNTER_HZ 32768 + +#define APBDEV_PMC_LED_BREATHING_STATUS_B01 0xB5C +#define PMC_LED_BREATHING_FSM_STATUS_MASK 0x7 +#define PMC_LED_BREATHING_FSM_STS_IDLE 0 +#define PMC_LED_BREATHING_FSM_STS_UP_RAMP 1 +#define PMC_LED_BREATHING_FSM_STS_PLATEAU 2 +#define PMC_LED_BREATHING_FSM_STS_DOWN_RAMP 3 +#define PMC_LED_BREATHING_FSM_STS_SHORT_LOW_PERIOD 4 +#define PMC_LED_BREATHING_FSM_STS_LONG_LOW_PERIOD 5 + +#define APBDEV_PMC_SECURE_SCRATCH124_B01 0xB68 +#define APBDEV_PMC_SECURE_SCRATCH125_B01 0xB6C +#define APBDEV_PMC_SECURE_SCRATCH126_B01 0xB70 +#define APBDEV_PMC_SECURE_SCRATCH127_B01 0xB74 +#define APBDEV_PMC_SECURE_SCRATCH128_B01 0xB78 +#define APBDEV_PMC_SECURE_SCRATCH129_B01 0xB7C +#define APBDEV_PMC_SECURE_SCRATCH130_B01 0xB80 +#define APBDEV_PMC_SECURE_SCRATCH131_B01 0xB84 +#define APBDEV_PMC_SECURE_SCRATCH132_B01 0xB88 +#define APBDEV_PMC_SECURE_SCRATCH133_B01 0xB8C +#define APBDEV_PMC_SECURE_SCRATCH134_B01 0xB90 +#define APBDEV_PMC_SECURE_SCRATCH135_B01 0xB94 +#define APBDEV_PMC_SECURE_SCRATCH136_B01 0xB98 +#define APBDEV_PMC_SECURE_SCRATCH137_B01 0xB9C +#define APBDEV_PMC_SECURE_SCRATCH138_B01 0xBA0 +#define APBDEV_PMC_SECURE_SCRATCH139_B01 0xBA4 +#define APBDEV_PMC_SEC_DISABLE_NS_B01 0xBB0 +#define APBDEV_PMC_SEC_DISABLE2_NS_B01 0xBB4 +#define APBDEV_PMC_SEC_DISABLE3_NS_B01 0xBB8 +#define APBDEV_PMC_SEC_DISABLE4_NS_B01 0xBBC +#define APBDEV_PMC_SEC_DISABLE5_NS_B01 0xBC0 +#define APBDEV_PMC_SEC_DISABLE6_NS_B01 0xBC4 +#define APBDEV_PMC_SEC_DISABLE7_NS_B01 0xBC8 +#define APBDEV_PMC_SEC_DISABLE8_NS_B01 0xBCC +#define APBDEV_PMC_SEC_DISABLE9_NS_B01 0xBD0 +#define APBDEV_PMC_SEC_DISABLE10_NS_B01 0xBD4 + +#define APBDEV_PMC_TZRAM_PWR_CNTRL_B01 0xBE8 +#define PMC_TZRAM_PWR_CNTRL_SD BIT(0) + +#define APBDEV_PMC_TZRAM_SEC_DISABLE_B01 0xBEC +#define APBDEV_PMC_TZRAM_NON_SEC_DISABLE_B01 0xBF0 +#define PMC_TZRAM_DISABLE_REG_WRITE BIT(0) +#define PMC_TZRAM_DISABLE_REG_READ BIT(1) + +typedef struct _pmc_regs_t210_t { +/* 0x000 */ u32 pmc_cntrl; +/* 0x004 */ u32 pmc_sec_disable; +/* 0x008 */ u32 pmc_pmc_swrst; +/* 0x00c */ u32 pmc_wake_mask; +/* 0x010 */ u32 pmc_wake_lvl; +/* 0x014 */ u32 pmc_wake_status; +/* 0x018 */ u32 pmc_sw_wake_status; +/* 0x01c */ u32 pmc_dpd_pads_oride; +/* 0x020 */ u32 pmc_dpd_sample; +/* 0x024 */ u32 pmc_dpd_enable; +/* 0x028 */ u32 pmc_pwrgate_timer_off; +/* 0x02c */ u32 pmc_clamp_status; +/* 0x030 */ u32 pmc_pwrgate_toggle; +/* 0x034 */ u32 pmc_remove_clamping_cmd; +/* 0x038 */ u32 pmc_pwrgate_status; +/* 0x03c */ u32 pmc_pwrgood_timer; +/* 0x040 */ u32 pmc_blink_timer; +/* 0x044 */ u32 pmc_no_iopower; +/* 0x048 */ u32 pmc_pwr_det; +/* 0x04c */ u32 pmc_pwr_det_latch; +/* 0x050 */ u32 pmc_scratch0; +/* 0x054 */ u32 pmc_scratch1; +/* 0x058 */ u32 pmc_scratch2; +/* 0x05c */ u32 pmc_scratch3; +/* 0x060 */ u32 pmc_scratch4; +/* 0x064 */ u32 pmc_scratch5; +/* 0x068 */ u32 pmc_scratch6; +/* 0x06c */ u32 pmc_scratch7; +/* 0x070 */ u32 pmc_scratch8; +/* 0x074 */ u32 pmc_scratch9; +/* 0x078 */ u32 pmc_scratch10; +/* 0x07c */ u32 pmc_scratch11; +/* 0x080 */ u32 pmc_scratch12; +/* 0x084 */ u32 pmc_scratch13; +/* 0x088 */ u32 pmc_scratch14; +/* 0x08c */ u32 pmc_scratch15; +/* 0x090 */ u32 pmc_scratch16; +/* 0x094 */ u32 pmc_scratch17; +/* 0x098 */ u32 pmc_scratch18; +/* 0x09c */ u32 pmc_scratch19; +/* 0x0a0 */ u32 pmc_scratch20; // ODM data/config scratch. +/* 0x0a4 */ u32 pmc_scratch21; +/* 0x0a8 */ u32 pmc_scratch22; +/* 0x0ac */ u32 pmc_scratch23; +/* 0x0b0 */ u32 pmc_secure_scratch0; +/* 0x0b4 */ u32 pmc_secure_scratch1; +/* 0x0b8 */ u32 pmc_secure_scratch2; +/* 0x0bc */ u32 pmc_secure_scratch3; +/* 0x0c0 */ u32 pmc_secure_scratch4; +/* 0x0c4 */ u32 pmc_secure_scratch5; +/* 0x0c8 */ u32 pmc_cpupwrgood_timer; +/* 0x0cc */ u32 pmc_cpupwroff_timer; +/* 0x0d0 */ u32 pmc_pg_mask; +/* 0x0d4 */ u32 pmc_pg_mask_1; +/* 0x0d8 */ u32 pmc_auto_wake_lvl; +/* 0x0dc */ u32 pmc_auto_wake_lvl_mask; +/* 0x0e0 */ u32 pmc_wake_delay; +/* 0x0e4 */ u32 pmc_pwr_det_val; +/* 0x0e8 */ u32 pmc_ddr_pwr; +/* 0x0ec */ u32 pmc_usb_debounce_del; +/* 0x0f0 */ u32 pmc_usb_ao; +/* 0x0f4 */ u32 pmc_crypto_op; +/* 0x0f8 */ u32 pmc_pllp_wb0_override; +/* 0x0fc */ u32 pmc_scratch24; +/* 0x100 */ u32 pmc_scratch25; +/* 0x104 */ u32 pmc_scratch26; +/* 0x108 */ u32 pmc_scratch27; +/* 0x10c */ u32 pmc_scratch28; +/* 0x110 */ u32 pmc_scratch29; +/* 0x114 */ u32 pmc_scratch30; +/* 0x118 */ u32 pmc_scratch31; +/* 0x11c */ u32 pmc_scratch32; +/* 0x120 */ u32 pmc_scratch33; +/* 0x124 */ u32 pmc_scratch34; +/* 0x128 */ u32 pmc_scratch35; +/* 0x12c */ u32 pmc_scratch36; +/* 0x130 */ u32 pmc_scratch37; +/* 0x134 */ u32 pmc_scratch38; +/* 0x138 */ u32 pmc_scratch39; +/* 0x13c */ u32 pmc_scratch40; +/* 0x140 */ u32 pmc_scratch41; +/* 0x144 */ u32 pmc_scratch42; +/* 0x148 */ u32 pmc_bondout_mirror0; +/* 0x14c */ u32 pmc_bondout_mirror1; +/* 0x150 */ u32 pmc_bondout_mirror2; +/* 0x154 */ u32 pmc_sys_33v_en; +/* 0x158 */ u32 pmc_bondout_mirror_access; +/* 0x15c */ u32 pmc_gate; +/* 0x160 */ u32 pmc_wake2_mask; +/* 0x164 */ u32 pmc_wake2_lvl; +/* 0x168 */ u32 pmc_wake2_status; +/* 0x16c */ u32 pmc_sw_wake2_status; +/* 0x170 */ u32 pmc_auto_wake2_lvl_mask; +/* 0x174 */ u32 pmc_pg_mask_2; +/* 0x178 */ u32 pmc_pg_mask_ce1; +/* 0x17c */ u32 pmc_pg_mask_ce2; +/* 0x180 */ u32 pmc_pg_mask_ce3; +/* 0x184 */ u32 pmc_pwrgate_timer_ce_0; +/* 0x188 */ u32 pmc_pwrgate_timer_ce_1; +/* 0x18c */ u32 pmc_pwrgate_timer_ce_2; +/* 0x190 */ u32 pmc_pwrgate_timer_ce_3; +/* 0x194 */ u32 pmc_pwrgate_timer_ce_4; +/* 0x198 */ u32 pmc_pwrgate_timer_ce_5; +/* 0x19c */ u32 pmc_pwrgate_timer_ce_6; +/* 0x1a0 */ u32 pmc_pcx_edpd_cntrl; +/* 0x1a4 */ u32 pmc_osc_edpd_over; +/* 0x1a8 */ u32 pmc_clk_out_cntrl; +/* 0x1ac */ u32 pmc_sata_pwrgt; +/* 0x1b0 */ u32 pmc_sensor_ctrl; +/* 0x1b4 */ u32 pmc_rst_status; +/* 0x1b8 */ u32 pmc_io_dpd_req; +/* 0x1bc */ u32 pmc_io_dpd_status; +/* 0x1c0 */ u32 pmc_io_dpd2_req; +/* 0x1c4 */ u32 pmc_io_dpd2_status; +/* 0x1c8 */ u32 pmc_sel_dpd_tim; +/* 0x1cc */ u32 pmc_vddp_sel; +/* 0x1d0 */ u32 pmc_ddr_cfg; +/* 0x1d4 */ u32 pmc_e_no_vttgen; +/* 0x1d8 */ u32 rsvd_1d8; +/* 0x1dc */ u32 pmc_pllm_wb0_override_freq; +/* 0x1e0 */ u32 pmc_test_pwrgate; +/* 0x1e4 */ u32 pmc_pwrgate_timer_mult; +/* 0x1e8 */ u32 pmc_dsi_sel_dpd; +/* 0x1ec */ u32 pmc_utmip_uhsic_triggers; +/* 0x1f0 */ u32 pmc_utmip_uhsic_saved_state; +/* 0x1f4 */ u32 rsvd_1f4; +/* 0x1f8 */ u32 pmc_utmip_term_pad_cfg; +/* 0x1fc */ u32 pmc_utmip_uhsic_sleep_cfg; +/* 0x200 */ u32 pmc_utmip_uhsic_sleepwalk_cfg; +/* 0x204 */ u32 pmc_utmip_sleepwalk_p0; +/* 0x208 */ u32 pmc_utmip_sleepwalk_p1; +/* 0x20c */ u32 pmc_utmip_sleepwalk_p2; +/* 0x210 */ u32 pmc_uhsic_sleepwalk_p0; +/* 0x214 */ u32 pmc_utmip_uhsic_status; +/* 0x218 */ u32 pmc_utmip_uhsic_fake; +/* 0x21c */ u32 pmc_bondout_mirror3; +/* 0x220 */ u32 pmc_bondout_mirror4; +/* 0x224 */ u32 pmc_secure_scratch6; +/* 0x228 */ u32 pmc_secure_scratch7; +/* 0x22c */ u32 pmc_scratch43; +/* 0x230 */ u32 pmc_scratch44; +/* 0x234 */ u32 pmc_scratch45; +/* 0x238 */ u32 pmc_scratch46; +/* 0x23c */ u32 pmc_scratch47; +/* 0x240 */ u32 pmc_scratch48; +/* 0x244 */ u32 pmc_scratch49; +/* 0x248 */ u32 pmc_scratch50; +/* 0x24c */ u32 pmc_scratch51; +/* 0x250 */ u32 pmc_scratch52; +/* 0x254 */ u32 pmc_scratch53; +/* 0x258 */ u32 pmc_scratch54; +/* 0x25c */ u32 pmc_scratch55; +/* 0x260 */ u32 pmc_scratch0_eco; +/* 0x264 */ u32 pmc_por_dpd_ctrl; +/* 0x268 */ u32 pmc_scratch2_eco; +/* 0x26c */ u32 pmc_utmip_uhsic_line_wakeup; +/* 0x270 */ u32 pmc_utmip_bias_master_cntrl; +/* 0x274 */ u32 pmc_utmip_master_config; +/* 0x278 */ u32 pmc_td_pwrgate_inter_part_timer; +/* 0x27c */ u32 pmc_utmip_uhsic2_triggers; +/* 0x280 */ u32 pmc_utmip_uhsic2_saved_state; +/* 0x284 */ u32 pmc_utmip_uhsic2_sleep_cfg; +/* 0x288 */ u32 pmc_utmip_uhsic2_sleepwalk_cfg; +/* 0x28c */ u32 pmc_uhsic2_sleepwalk_p1; +/* 0x290 */ u32 pmc_utmip_uhsic2_status; +/* 0x294 */ u32 pmc_utmip_uhsic2_fake; +/* 0x298 */ u32 pmc_utmip_uhsic2_line_wakeup; +/* 0x29c */ u32 pmc_utmip_master2_config; +/* 0x2a0 */ u32 pmc_utmip_uhsic_rpd_cfg; +/* 0x2a4 */ u32 pmc_pg_mask_ce0; +/* 0x2a8 */ u32 pmc_pg_mask_3; +/* 0x2ac */ u32 pmc_pg_mask_4; +/* 0x2b0 */ u32 pmc_pllm_wb0_override2; +/* 0x2b4 */ u32 pmc_tsc_mult; +/* 0x2b8 */ u32 pmc_cpu_vsense_override; +/* 0x2bc */ u32 pmc_glb_amap_cfg; +/* 0x2c0 */ u32 pmc_sticky_bits; +/* 0x2c4 */ u32 pmc_sec_disable2; +/* 0x2c8 */ u32 pmc_weak_bias; +/* 0x2cc */ u32 pmc_reg_short; +/* 0x2d0 */ u32 pmc_pg_mask_andor; +/* 0x2d4 */ u32 pmc_gpu_rg_cntrl; +/* 0x2d8 */ u32 pmc_sec_disable3; +/* 0x2dc */ u32 pmc_pg_mask_5; +/* 0x2e0 */ u32 pmc_pg_mask_6; +/* 0x2e4 */ u32 rsvd_2e4[7]; +/* 0x300 */ u32 pmc_secure_scratch8; +/* 0x304 */ u32 pmc_secure_scratch9; +/* 0x308 */ u32 pmc_secure_scratch10; +/* 0x30c */ u32 pmc_secure_scratch11; +/* 0x310 */ u32 pmc_secure_scratch12; +/* 0x314 */ u32 pmc_secure_scratch13; +/* 0x318 */ u32 pmc_secure_scratch14; +/* 0x31c */ u32 pmc_secure_scratch15; +/* 0x320 */ u32 pmc_secure_scratch16; +/* 0x324 */ u32 pmc_secure_scratch17; +/* 0x328 */ u32 pmc_secure_scratch18; +/* 0x32c */ u32 pmc_secure_scratch19; +/* 0x330 */ u32 pmc_secure_scratch20; +/* 0x334 */ u32 pmc_secure_scratch21; +/* 0x338 */ u32 pmc_secure_scratch22; // AArch32 reset address. +/* 0x33c */ u32 pmc_secure_scratch23; +/* 0x340 */ u32 pmc_secure_scratch24; +/* 0x344 */ u32 pmc_secure_scratch25; +/* 0x348 */ u32 pmc_secure_scratch26; +/* 0x34c */ u32 pmc_secure_scratch27; +/* 0x350 */ u32 pmc_secure_scratch28; +/* 0x354 */ u32 pmc_secure_scratch29; +/* 0x358 */ u32 pmc_secure_scratch30; +/* 0x35c */ u32 pmc_secure_scratch31; +/* 0x360 */ u32 pmc_secure_scratch32; +/* 0x364 */ u32 pmc_secure_scratch33; +/* 0x368 */ u32 pmc_secure_scratch34; // AArch64 reset address. +/* 0x36c */ u32 pmc_secure_scratch35; // AArch64 reset hi-address. +/* 0x370 */ u32 pmc_secure_scratch36; +/* 0x374 */ u32 pmc_secure_scratch37; +/* 0x378 */ u32 pmc_secure_scratch38; +/* 0x37c */ u32 pmc_secure_scratch39; +/* 0x380 */ u32 pmc_secure_scratch40; +/* 0x384 */ u32 pmc_secure_scratch41; +/* 0x388 */ u32 pmc_secure_scratch42; +/* 0x38c */ u32 pmc_secure_scratch43; +/* 0x390 */ u32 pmc_secure_scratch44; +/* 0x394 */ u32 pmc_secure_scratch45; +/* 0x398 */ u32 pmc_secure_scratch46; +/* 0x39c */ u32 pmc_secure_scratch47; +/* 0x3a0 */ u32 pmc_secure_scratch48; +/* 0x3a4 */ u32 pmc_secure_scratch49; +/* 0x3a8 */ u32 pmc_secure_scratch50; +/* 0x3ac */ u32 pmc_secure_scratch51; +/* 0x3b0 */ u32 pmc_secure_scratch52; +/* 0x3b4 */ u32 pmc_secure_scratch53; +/* 0x3b8 */ u32 pmc_secure_scratch54; +/* 0x3bc */ u32 pmc_secure_scratch55; +/* 0x3c0 */ u32 pmc_secure_scratch56; +/* 0x3c4 */ u32 pmc_secure_scratch57; +/* 0x3c8 */ u32 pmc_secure_scratch58; +/* 0x3cc */ u32 pmc_secure_scratch59; +/* 0x3d0 */ u32 pmc_secure_scratch60; +/* 0x3d4 */ u32 pmc_secure_scratch61; +/* 0x3d8 */ u32 pmc_secure_scratch62; +/* 0x3dc */ u32 pmc_secure_scratch63; +/* 0x3e0 */ u32 pmc_secure_scratch64; +/* 0x3e4 */ u32 pmc_secure_scratch65; +/* 0x3e8 */ u32 pmc_secure_scratch66; +/* 0x3ec */ u32 pmc_secure_scratch67; +/* 0x3f0 */ u32 pmc_secure_scratch68; +/* 0x3f4 */ u32 pmc_secure_scratch69; +/* 0x3f8 */ u32 pmc_secure_scratch70; +/* 0x3fc */ u32 pmc_secure_scratch71; +/* 0x400 */ u32 pmc_secure_scratch72; +/* 0x404 */ u32 pmc_secure_scratch73; +/* 0x408 */ u32 pmc_secure_scratch74; +/* 0x40c */ u32 pmc_secure_scratch75; +/* 0x410 */ u32 pmc_secure_scratch76; +/* 0x414 */ u32 pmc_secure_scratch77; +/* 0x418 */ u32 pmc_secure_scratch78; +/* 0x41c */ u32 pmc_secure_scratch79; +/* 0x420 */ u32 rsvd_420[8]; +/* 0x440 */ u32 pmc_cntrl2; +/* 0x444 */ u32 pmc_io_dpd_off_mask; +/* 0x448 */ u32 pmc_io_dpd2_off_mask; +/* 0x44c */ u32 pmc_event_counter; +/* 0x450 */ u32 pmc_fuse_control; +/* 0x454 */ u32 pmc_scratch1_eco; +/* 0x458 */ u32 rsvd_458; +/* 0x45c */ u32 pmc_io_dpd3_req; +/* 0x460 */ u32 pmc_io_dpd3_status; +/* 0x464 */ u32 pmc_io_dpd4_req; +/* 0x468 */ u32 pmc_io_dpd4_status; +/* 0x46c */ u32 rsvd_46c[2]; +/* 0x474 */ u32 pmc_direct_thermtrip_cfg; +/* 0x478 */ u32 pmc_tsosc_delay; +/* 0x47c */ u32 pmc_set_sw_clamp; +/* 0x480 */ u32 pmc_debug_authentication; +/* 0x484 */ u32 pmc_aotag_cfg; +/* 0x488 */ u32 pmc_aotag_thresh1_cfg; +/* 0x48c */ u32 pmc_aotag_thresh2_cfg; +/* 0x490 */ u32 pmc_aotag_thresh3_cfg; +/* 0x494 */ u32 pmc_aotag_status; +/* 0x498 */ u32 pmc_aotag_security; +/* 0x49c */ u32 pmc_tsensor_config0; +/* 0x4a0 */ u32 pmc_tsensor_config1; +/* 0x4a4 */ u32 pmc_tsensor_config2; +/* 0x4a8 */ u32 pmc_tsensor_status0; +/* 0x4ac */ u32 pmc_tsensor_status1; +/* 0x4b0 */ u32 pmc_tsensor_status2; +/* 0x4b4 */ u32 pmc_tsensor_pdiv; +/* 0x4b8 */ u32 pmc_aotag_intr_en; +/* 0x4bc */ u32 pmc_aotag_intr_dis; +/* 0x4c0 */ u32 pmc_utmip_pad_cfg0; +/* 0x4c4 */ u32 pmc_utmip_pad_cfg1; +/* 0x4c8 */ u32 pmc_utmip_pad_cfg2; +/* 0x4cc */ u32 pmc_utmip_pad_cfg3; +/* 0x4d0 */ u32 pmc_utmip_uhsic_sleep_cfg1; +/* 0x4d4 */ u32 pmc_cc4_hvc_control; +/* 0x4d8 */ u32 pmc_wake_debounce_en; +/* 0x4dc */ u32 pmc_ramdump_ctl_status; +/* 0x4e0 */ u32 pmc_utmip_sleepwalk_p3; +/* 0x4e4 */ u32 pmc_ddr_cntrl; +/* 0x4e8 */ u32 rsvd_4e8[50]; +/* 0x5b0 */ u32 pmc_sec_disable4; +/* 0x5b4 */ u32 pmc_sec_disable5; +/* 0x5b8 */ u32 pmc_sec_disable6; +/* 0x5bc */ u32 pmc_sec_disable7; +/* 0x5c0 */ u32 pmc_sec_disable8; +/* 0x5c4 */ u32 pmc_sec_disable9_b01; +/* 0x5c8 */ u32 pmc_sec_disable10_b01; +/* 0x5cc */ u32 rsvd_5cc[13]; +/* 0x600 */ u32 pmc_scratch56; +/* 0x604 */ u32 pmc_scratch57; +/* 0x608 */ u32 pmc_scratch58; +/* 0x60c */ u32 pmc_scratch59; +/* 0x610 */ u32 pmc_scratch60; +/* 0x614 */ u32 pmc_scratch61; +/* 0x618 */ u32 pmc_scratch62; +/* 0x61c */ u32 pmc_scratch63; +/* 0x620 */ u32 pmc_scratch64; +/* 0x624 */ u32 pmc_scratch65; +/* 0x628 */ u32 pmc_scratch66; +/* 0x62c */ u32 pmc_scratch67; +/* 0x630 */ u32 pmc_scratch68; +/* 0x634 */ u32 pmc_scratch69; +/* 0x638 */ u32 pmc_scratch70; +/* 0x63c */ u32 pmc_scratch71; +/* 0x640 */ u32 pmc_scratch72; +/* 0x644 */ u32 pmc_scratch73; +/* 0x648 */ u32 pmc_scratch74; +/* 0x64c */ u32 pmc_scratch75; +/* 0x650 */ u32 pmc_scratch76; +/* 0x654 */ u32 pmc_scratch77; +/* 0x658 */ u32 pmc_scratch78; +/* 0x65c */ u32 pmc_scratch79; +/* 0x660 */ u32 pmc_scratch80; +/* 0x664 */ u32 pmc_scratch81; +/* 0x668 */ u32 pmc_scratch82; +/* 0x66c */ u32 pmc_scratch83; +/* 0x670 */ u32 pmc_scratch84; +/* 0x674 */ u32 pmc_scratch85; +/* 0x678 */ u32 pmc_scratch86; +/* 0x67c */ u32 pmc_scratch87; +/* 0x680 */ u32 pmc_scratch88; +/* 0x684 */ u32 pmc_scratch89; +/* 0x688 */ u32 pmc_scratch90; +/* 0x68c */ u32 pmc_scratch91; +/* 0x690 */ u32 pmc_scratch92; +/* 0x694 */ u32 pmc_scratch93; +/* 0x698 */ u32 pmc_scratch94; +/* 0x69c */ u32 pmc_scratch95; +/* 0x6a0 */ u32 pmc_scratch96; +/* 0x6a4 */ u32 pmc_scratch97; +/* 0x6a8 */ u32 pmc_scratch98; +/* 0x6ac */ u32 pmc_scratch99; +/* 0x6b0 */ u32 pmc_scratch100; +/* 0x6b4 */ u32 pmc_scratch101; +/* 0x6b8 */ u32 pmc_scratch102; +/* 0x6bc */ u32 pmc_scratch103; +/* 0x6c0 */ u32 pmc_scratch104; +/* 0x6c4 */ u32 pmc_scratch105; +/* 0x6c8 */ u32 pmc_scratch106; +/* 0x6cc */ u32 pmc_scratch107; +/* 0x6d0 */ u32 pmc_scratch108; +/* 0x6d4 */ u32 pmc_scratch109; +/* 0x6d8 */ u32 pmc_scratch110; +/* 0x6dc */ u32 pmc_scratch111; +/* 0x6e0 */ u32 pmc_scratch112; +/* 0x6e4 */ u32 pmc_scratch113; +/* 0x6e8 */ u32 pmc_scratch114; +/* 0x6ec */ u32 pmc_scratch115; +/* 0x6f0 */ u32 pmc_scratch116; +/* 0x6f4 */ u32 pmc_scratch117; +/* 0x6f8 */ u32 pmc_scratch118; +/* 0x6fc */ u32 pmc_scratch119; +/* 0x700 */ u32 pmc_scratch120; +/* 0x704 */ u32 pmc_scratch121; +/* 0x708 */ u32 pmc_scratch122; +/* 0x70c */ u32 pmc_scratch123; +/* 0x710 */ u32 pmc_scratch124; +/* 0x714 */ u32 pmc_scratch125; +/* 0x718 */ u32 pmc_scratch126; +/* 0x71c */ u32 pmc_scratch127; +/* 0x720 */ u32 pmc_scratch128; +/* 0x724 */ u32 pmc_scratch129; +/* 0x728 */ u32 pmc_scratch130; +/* 0x72c */ u32 pmc_scratch131; +/* 0x730 */ u32 pmc_scratch132; +/* 0x734 */ u32 pmc_scratch133; +/* 0x738 */ u32 pmc_scratch134; +/* 0x73c */ u32 pmc_scratch135; +/* 0x740 */ u32 pmc_scratch136; +/* 0x744 */ u32 pmc_scratch137; +/* 0x748 */ u32 pmc_scratch138; +/* 0x74c */ u32 pmc_scratch139; +/* 0x750 */ u32 pmc_scratch140; +/* 0x754 */ u32 pmc_scratch141; +/* 0x758 */ u32 pmc_scratch142; +/* 0x75c */ u32 pmc_scratch143; +/* 0x760 */ u32 pmc_scratch144; +/* 0x764 */ u32 pmc_scratch145; +/* 0x768 */ u32 pmc_scratch146; +/* 0x76c */ u32 pmc_scratch147; +/* 0x770 */ u32 pmc_scratch148; +/* 0x774 */ u32 pmc_scratch149; +/* 0x778 */ u32 pmc_scratch150; +/* 0x77c */ u32 pmc_scratch151; +/* 0x780 */ u32 pmc_scratch152; +/* 0x784 */ u32 pmc_scratch153; +/* 0x788 */ u32 pmc_scratch154; +/* 0x78c */ u32 pmc_scratch155; +/* 0x790 */ u32 pmc_scratch156; +/* 0x794 */ u32 pmc_scratch157; +/* 0x798 */ u32 pmc_scratch158; +/* 0x79c */ u32 pmc_scratch159; +/* 0x7a0 */ u32 pmc_scratch160; +/* 0x7a4 */ u32 pmc_scratch161; +/* 0x7a8 */ u32 pmc_scratch162; +/* 0x7ac */ u32 pmc_scratch163; +/* 0x7b0 */ u32 pmc_scratch164; +/* 0x7b4 */ u32 pmc_scratch165; +/* 0x7b8 */ u32 pmc_scratch166; +/* 0x7bc */ u32 pmc_scratch167; +/* 0x7c0 */ u32 pmc_scratch168; +/* 0x7c4 */ u32 pmc_scratch169; +/* 0x7c8 */ u32 pmc_scratch170; +/* 0x7cc */ u32 pmc_scratch171; +/* 0x7d0 */ u32 pmc_scratch172; +/* 0x7d4 */ u32 pmc_scratch173; +/* 0x7d8 */ u32 pmc_scratch174; +/* 0x7dc */ u32 pmc_scratch175; +/* 0x7e0 */ u32 pmc_scratch176; +/* 0x7e4 */ u32 pmc_scratch177; +/* 0x7e8 */ u32 pmc_scratch178; +/* 0x7ec */ u32 pmc_scratch179; +/* 0x7f0 */ u32 pmc_scratch180; +/* 0x7f4 */ u32 pmc_scratch181; +/* 0x7f8 */ u32 pmc_scratch182; +/* 0x7fc */ u32 pmc_scratch183; +/* 0x800 */ u32 pmc_scratch184; +/* 0x804 */ u32 pmc_scratch185; +/* 0x808 */ u32 pmc_scratch186; +/* 0x80c */ u32 pmc_scratch187; +/* 0x810 */ u32 pmc_scratch188; +/* 0x814 */ u32 pmc_scratch189; +/* 0x818 */ u32 pmc_scratch190; +/* 0x81c */ u32 pmc_scratch191; +/* 0x820 */ u32 pmc_scratch192; +/* 0x824 */ u32 pmc_scratch193; +/* 0x828 */ u32 pmc_scratch194; +/* 0x82c */ u32 pmc_scratch195; +/* 0x830 */ u32 pmc_scratch196; +/* 0x834 */ u32 pmc_scratch197; +/* 0x838 */ u32 pmc_scratch198; +/* 0x83c */ u32 pmc_scratch199; +/* 0x840 */ u32 pmc_scratch200; +/* 0x844 */ u32 pmc_scratch201; +/* 0x848 */ u32 pmc_scratch202; +/* 0x84c */ u32 pmc_scratch203; +/* 0x850 */ u32 pmc_scratch204; +/* 0x854 */ u32 pmc_scratch205; +/* 0x858 */ u32 pmc_scratch206; +/* 0x85c */ u32 pmc_scratch207; +/* 0x860 */ u32 pmc_scratch208; +/* 0x864 */ u32 pmc_scratch209; +/* 0x868 */ u32 pmc_scratch210; +/* 0x86c */ u32 pmc_scratch211; +/* 0x870 */ u32 pmc_scratch212; +/* 0x874 */ u32 pmc_scratch213; +/* 0x878 */ u32 pmc_scratch214; +/* 0x87c */ u32 pmc_scratch215; +/* 0x880 */ u32 pmc_scratch216; +/* 0x884 */ u32 pmc_scratch217; +/* 0x888 */ u32 pmc_scratch218; +/* 0x88c */ u32 pmc_scratch219; +/* 0x890 */ u32 pmc_scratch220; +/* 0x894 */ u32 pmc_scratch221; +/* 0x898 */ u32 pmc_scratch222; +/* 0x89c */ u32 pmc_scratch223; +/* 0x8a0 */ u32 pmc_scratch224; +/* 0x8a4 */ u32 pmc_scratch225; +/* 0x8a8 */ u32 pmc_scratch226; +/* 0x8ac */ u32 pmc_scratch227; +/* 0x8b0 */ u32 pmc_scratch228; +/* 0x8b4 */ u32 pmc_scratch229; +/* 0x8b8 */ u32 pmc_scratch230; +/* 0x8bc */ u32 pmc_scratch231; +/* 0x8c0 */ u32 pmc_scratch232; +/* 0x8c4 */ u32 pmc_scratch233; +/* 0x8c8 */ u32 pmc_scratch234; +/* 0x8cc */ u32 pmc_scratch235; +/* 0x8d0 */ u32 pmc_scratch236; +/* 0x8d4 */ u32 pmc_scratch237; +/* 0x8d8 */ u32 pmc_scratch238; +/* 0x8dc */ u32 pmc_scratch239; +/* 0x8e0 */ u32 pmc_scratch240; +/* 0x8e4 */ u32 pmc_scratch241; +/* 0x8e8 */ u32 pmc_scratch242; +/* 0x8ec */ u32 pmc_scratch243; +/* 0x8f0 */ u32 pmc_scratch244; +/* 0x8f4 */ u32 pmc_scratch245; +/* 0x8f8 */ u32 pmc_scratch246; +/* 0x8fc */ u32 pmc_scratch247; +/* 0x900 */ u32 pmc_scratch248; +/* 0x904 */ u32 pmc_scratch249; +/* 0x908 */ u32 pmc_scratch250; +/* 0x90c */ u32 pmc_scratch251; +/* 0x910 */ u32 pmc_scratch252; +/* 0x914 */ u32 pmc_scratch253; +/* 0x918 */ u32 pmc_scratch254; +/* 0x91c */ u32 pmc_scratch255; +/* 0x920 */ u32 pmc_scratch256; +/* 0x924 */ u32 pmc_scratch257; +/* 0x928 */ u32 pmc_scratch258; +/* 0x92c */ u32 pmc_scratch259; +/* 0x930 */ u32 pmc_scratch260; +/* 0x934 */ u32 pmc_scratch261; +/* 0x938 */ u32 pmc_scratch262; +/* 0x93c */ u32 pmc_scratch263; +/* 0x940 */ u32 pmc_scratch264; +/* 0x944 */ u32 pmc_scratch265; +/* 0x948 */ u32 pmc_scratch266; +/* 0x94c */ u32 pmc_scratch267; +/* 0x950 */ u32 pmc_scratch268; +/* 0x954 */ u32 pmc_scratch269; +/* 0x958 */ u32 pmc_scratch270; +/* 0x95c */ u32 pmc_scratch271; +/* 0x960 */ u32 pmc_scratch272; +/* 0x964 */ u32 pmc_scratch273; +/* 0x968 */ u32 pmc_scratch274; +/* 0x96c */ u32 pmc_scratch275; +/* 0x970 */ u32 pmc_scratch276; +/* 0x974 */ u32 pmc_scratch277; +/* 0x978 */ u32 pmc_scratch278; +/* 0x97c */ u32 pmc_scratch279; +/* 0x980 */ u32 pmc_scratch280; +/* 0x984 */ u32 pmc_scratch281; +/* 0x988 */ u32 pmc_scratch282; +/* 0x98c */ u32 pmc_scratch283; +/* 0x990 */ u32 pmc_scratch284; +/* 0x994 */ u32 pmc_scratch285; +/* 0x998 */ u32 pmc_scratch286; +/* 0x99c */ u32 pmc_scratch287; +/* 0x9a0 */ u32 pmc_scratch288; +/* 0x9a4 */ u32 pmc_scratch289; +/* 0x9a8 */ u32 pmc_scratch290; +/* 0x9ac */ u32 pmc_scratch291; +/* 0x9b0 */ u32 pmc_scratch292; +/* 0x9b4 */ u32 pmc_scratch293; +/* 0x9b8 */ u32 pmc_scratch294; +/* 0x9bc */ u32 pmc_scratch295; +/* 0x9c0 */ u32 pmc_scratch296; +/* 0x9c4 */ u32 pmc_scratch297; +/* 0x9c8 */ u32 pmc_scratch298; +/* 0x9cc */ u32 pmc_scratch299; +/* 0x9d0 */ u32 rsvd_9d0[30]; +/* 0xa48 */ u32 pmc_scratch_write_disable0_b01; +/* 0xa4c */ u32 pmc_scratch_write_disable1_b01; +/* 0xa50 */ u32 pmc_scratch_write_disable2_b01; +/* 0xa54 */ u32 pmc_scratch_write_disable3_b01; +/* 0xa58 */ u32 pmc_scratch_write_disable4_b01; +/* 0xa5c */ u32 pmc_scratch_write_disable5_b01; +/* 0xa60 */ u32 pmc_scratch_write_disable6_b01; +/* 0xa64 */ u32 pmc_scratch_write_disable7_b01; +/* 0xa68 */ u32 pmc_scratch_write_disable8_b01; +/* 0xa6c */ u32 pmc_scratch_write_disable9_b01; +/* 0xa70 */ u32 pmc_scratch_write_disable10_b01; +/* 0xa74 */ u32 pmc_scratch_write_lock_disable_sticky_b01; +/* 0xa78 */ u32 rsvd_a78[8]; +/* 0xa98 */ u32 pmc_secure_scratch80; +/* 0xa9c */ u32 pmc_secure_scratch81; +/* 0xaa0 */ u32 pmc_secure_scratch82; +/* 0xaa4 */ u32 pmc_secure_scratch83; +/* 0xaa8 */ u32 pmc_secure_scratch84; +/* 0xaac */ u32 pmc_secure_scratch85; +/* 0xab0 */ u32 pmc_secure_scratch86; +/* 0xab4 */ u32 pmc_secure_scratch87; +/* 0xab8 */ u32 pmc_secure_scratch88; +/* 0xabc */ u32 pmc_secure_scratch89; +/* 0xac0 */ u32 pmc_secure_scratch90; +/* 0xac4 */ u32 pmc_secure_scratch91; +/* 0xac8 */ u32 pmc_secure_scratch92; +/* 0xacc */ u32 pmc_secure_scratch93; +/* 0xad0 */ u32 pmc_secure_scratch94; +/* 0xad4 */ u32 pmc_secure_scratch95; +/* 0xad8 */ u32 pmc_secure_scratch96; +/* 0xadc */ u32 pmc_secure_scratch97; +/* 0xae0 */ u32 pmc_secure_scratch98; +/* 0xae4 */ u32 pmc_secure_scratch99; +/* 0xae8 */ u32 pmc_secure_scratch100; +/* 0xaec */ u32 pmc_secure_scratch101; +/* 0xaf0 */ u32 pmc_secure_scratch102; +/* 0xaf4 */ u32 pmc_secure_scratch103; +/* 0xaf8 */ u32 pmc_secure_scratch104; +/* 0xafc */ u32 pmc_secure_scratch105; +/* 0xb00 */ u32 pmc_secure_scratch106; +/* 0xb04 */ u32 pmc_secure_scratch107; +/* 0xb08 */ u32 pmc_secure_scratch108; +/* 0xb0c */ u32 pmc_secure_scratch109; +/* 0xb10 */ u32 pmc_secure_scratch110; +/* 0xb14 */ u32 pmc_secure_scratch111; +/* 0xb18 */ u32 pmc_secure_scratch112; +/* 0xb1c */ u32 pmc_secure_scratch113; +/* 0xb20 */ u32 pmc_secure_scratch114; +/* 0xb24 */ u32 pmc_secure_scratch115; +/* 0xb28 */ u32 pmc_secure_scratch116; +/* 0xb2c */ u32 pmc_secure_scratch117; +/* 0xb30 */ u32 pmc_secure_scratch118; +/* 0xb34 */ u32 pmc_secure_scratch119; +/* 0xb38 */ u32 pmc_secure_scratch120_b01; +/* 0xb3c */ u32 pmc_secure_scratch121_b01; +/* 0xb40 */ u32 pmc_secure_scratch122_b01; +/* 0xb44 */ u32 pmc_secure_scratch123_b01; +/* 0xb48 */ u32 pmc_led_breathing_ctrl_b01; +/* 0xb4c */ u32 pmc_led_breathing_counter0_b01; // Slope Steps. +/* 0xb50 */ u32 pmc_led_breathing_counter1_b01; // ON counter. +/* 0xb54 */ u32 pmc_led_breathing_counter2_b01; // OFF counter1. +/* 0xb58 */ u32 pmc_led_breathing_counter3_b01; // OFF counter0. +/* 0xb5c */ u32 pmc_led_breathing_status_b01; +/* 0xb60 */ u32 rsvd_b60[2]; +/* 0xb68 */ u32 pmc_secure_scratch124_b01; +/* 0xb6c */ u32 pmc_secure_scratch125_b01; +/* 0xb70 */ u32 pmc_secure_scratch126_b01; +/* 0xb74 */ u32 pmc_secure_scratch127_b01; +/* 0xb78 */ u32 pmc_secure_scratch128_b01; +/* 0xb7c */ u32 pmc_secure_scratch129_b01; +/* 0xb80 */ u32 pmc_secure_scratch130_b01; +/* 0xb84 */ u32 pmc_secure_scratch131_b01; +/* 0xb88 */ u32 pmc_secure_scratch132_b01; +/* 0xb8c */ u32 pmc_secure_scratch133_b01; +/* 0xb90 */ u32 pmc_secure_scratch134_b01; +/* 0xb94 */ u32 pmc_secure_scratch135_b01; +/* 0xb98 */ u32 pmc_secure_scratch136_b01; +/* 0xb9c */ u32 pmc_secure_scratch137_b01; +/* 0xba0 */ u32 pmc_secure_scratch138_b01; +/* 0xba4 */ u32 pmc_secure_scratch139_b01; +/* 0xba8 */ u32 rsvd_ba8[2]; +/* 0xbb0 */ u32 pmc_sec_disable_ns_b01; +/* 0xbb4 */ u32 pmc_sec_disable2_ns_b01; +/* 0xbb8 */ u32 pmc_sec_disable3_ns_b01; +/* 0xbbc */ u32 pmc_sec_disable4_ns_b01; +/* 0xbc0 */ u32 pmc_sec_disable5_ns_b01; +/* 0xbc4 */ u32 pmc_sec_disable6_ns_b01; +/* 0xbc8 */ u32 pmc_sec_disable7_ns_b01; +/* 0xbcc */ u32 pmc_sec_disable8_ns_b01; +/* 0xbd0 */ u32 pmc_sec_disable9_ns_b01; +/* 0xbd4 */ u32 pmc_sec_disable10_ns_b01; +/* 0xbd8 */ u32 rsvd_bd8[4]; +/* 0xbe8 */ u32 pmc_tzram_pwr_cntrl_b01; +/* 0xbec */ u32 pmc_tzram_sec_disable_b01; +/* 0xbf0 */ u32 pmc_tzram_non_sec_disable_b01; +} pmc_regs_t210_t; + + +#endif /* _PMC_T210_H_ */ diff --git a/bdk/soc/timer.c b/bdk/soc/timer.c index 786f1239..db4750a2 100644 --- a/bdk/soc/timer.c +++ b/bdk/soc/timer.c @@ -22,7 +22,7 @@ #include #include -#define EXCP_TYPE_ADDR 0x4003FFF8 +#define EXCP_TYPE_ADDR 0x4003FF18 #define EXCP_TYPE_WDT 0x544457 // "WDT". #define USE_RTC_TIMER diff --git a/bdk/storage/emmc.c b/bdk/storage/emmc.c index b1ab03d2..40c9b1df 100644 --- a/bdk/storage/emmc.c +++ b/bdk/storage/emmc.c @@ -79,7 +79,7 @@ int emmc_init_retry(bool power_cycle) switch (emmc_mode) { case EMMC_INIT_FAIL: // Reset to max. - return 0; + return 1; case EMMC_1BIT_HS52: bus_width = SDMMC_BUS_WIDTH_1; type = SDHCI_TIMING_MMC_HS52; @@ -100,7 +100,7 @@ int emmc_init_retry(bool power_cycle) return sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, bus_width, type); } -bool emmc_initialize(bool power_cycle) +int emmc_initialize(bool power_cycle) { // Reset mode in case of previous failure. if (emmc_mode == EMMC_INIT_FAIL) @@ -109,12 +109,12 @@ bool emmc_initialize(bool power_cycle) if (power_cycle) emmc_end(); - int res = !emmc_init_retry(false); + int res = emmc_init_retry(false); while (true) { if (!res) - return true; + return 0; else { emmc_errors[EMMC_ERROR_INIT_FAIL]++; @@ -122,13 +122,13 @@ bool emmc_initialize(bool power_cycle) if (emmc_mode == EMMC_INIT_FAIL) break; else - res = !emmc_init_retry(true); + res = emmc_init_retry(true); } } emmc_end(); - return false; + return 1; } int emmc_set_partition(u32 partition) { return sdmmc_storage_set_mmc_partition(&emmc_storage, partition); } @@ -190,7 +190,7 @@ int emmc_part_read(emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf { // The last LBA is inclusive. if (part->lba_start + sector_off > part->lba_end) - return 0; + return 1; #ifdef BDK_EMUMMC_ENABLE return emummc_storage_read(part->lba_start + sector_off, num_sectors, buf); @@ -203,7 +203,7 @@ int emmc_part_write(emmc_part_t *part, u32 sector_off, u32 num_sectors, void *bu { // The last LBA is inclusive. if (part->lba_start + sector_off > part->lba_end) - return 0; + return 1; #ifdef BDK_EMUMMC_ENABLE return emummc_storage_write(part->lba_start + sector_off, num_sectors, buf); diff --git a/bdk/storage/emmc.h b/bdk/storage/emmc.h index 904852d0..242cf9b0 100644 --- a/bdk/storage/emmc.h +++ b/bdk/storage/emmc.h @@ -62,7 +62,7 @@ void emmc_error_count_increment(u8 type); u16 *emmc_get_error_count(); u32 emmc_get_mode(); int emmc_init_retry(bool power_cycle); -bool emmc_initialize(bool power_cycle); +int emmc_initialize(bool power_cycle); int emmc_set_partition(u32 partition); void emmc_end(); diff --git a/bdk/storage/mmc_def.h b/bdk/storage/mmc_def.h index c7d6106f..5bcafe4b 100644 --- a/bdk/storage/mmc_def.h +++ b/bdk/storage/mmc_def.h @@ -416,8 +416,8 @@ /* * BKOPS modes */ -#define EXT_CSD_MANUAL_BKOPS_MASK 0x01 -#define EXT_CSD_AUTO_BKOPS_MASK 0x02 +#define EXT_CSD_BKOPS_MANUAL 0x01 /* STICKY! */ +#define EXT_CSD_BKOPS_AUTO 0x02 /* * Command Queue diff --git a/bdk/storage/nx_emmc_bis.c b/bdk/storage/nx_emmc_bis.c index d9a02c28..3755f450 100644 --- a/bdk/storage/nx_emmc_bis.c +++ b/bdk/storage/nx_emmc_bis.c @@ -91,7 +91,7 @@ static int nx_emmc_bis_write_block(u32 sector, u32 count, void *buff, bool flush } // Encrypt cluster. - if (!se_aes_crypt_xts_sec_nx(ks_tweak, ks_crypt, ENCRYPT, cluster, tweak, true, sector_in_cluster, bis_cache->dma_buff, buff, count * EMMC_BLOCKSIZE)) + if (se_aes_crypt_xts_sec_nx(ks_tweak, ks_crypt, ENCRYPT, cluster, tweak, true, sector_in_cluster, bis_cache->dma_buff, buff, count * EMMC_BLOCKSIZE)) return 1; // Encryption error. // If not reading from cache, do a regular read and decrypt. @@ -99,7 +99,7 @@ static int nx_emmc_bis_write_block(u32 sector, u32 count, void *buff, bool flush res = emmc_part_write(system_part, sector, count, bis_cache->dma_buff); else res = sdmmc_storage_write(&sd_storage, emu_offset + system_part->lba_start + sector, count, bis_cache->dma_buff); - if (!res) + if (res) return 1; // R/W error. // Mark cache entry not dirty if write succeeds. @@ -159,7 +159,7 @@ static int nx_emmc_bis_read_block_normal(u32 sector, u32 count, void *buff) res = emmc_part_read(system_part, sector, count, bis_cache->dma_buff); else res = sdmmc_storage_read(&sd_storage, emu_offset + system_part->lba_start + sector, count, bis_cache->dma_buff); - if (!res) + if (res) return 1; // R/W error. if (prev_cluster != cluster) // Sector in different cluster than last read. @@ -177,7 +177,7 @@ static int nx_emmc_bis_read_block_normal(u32 sector, u32 count, void *buff) tweak_exp = sector_in_cluster; // Maximum one cluster (1 XTS crypto block 16KB). - if (!se_aes_crypt_xts_sec_nx(ks_tweak, ks_crypt, DECRYPT, prev_cluster, tweak, regen_tweak, tweak_exp, buff, bis_cache->dma_buff, count * EMMC_BLOCKSIZE)) + if (se_aes_crypt_xts_sec_nx(ks_tweak, ks_crypt, DECRYPT, prev_cluster, tweak, regen_tweak, tweak_exp, buff, bis_cache->dma_buff, count * EMMC_BLOCKSIZE)) return 1; // R/W error. prev_sector = sector + count - 1; @@ -216,11 +216,11 @@ static int nx_emmc_bis_read_block_cached(u32 sector, u32 count, void *buff) res = emmc_part_read(system_part, cluster_sector, BIS_CLUSTER_SECTORS, bis_cache->dma_buff); else res = sdmmc_storage_read(&sd_storage, emu_offset + system_part->lba_start + cluster_sector, BIS_CLUSTER_SECTORS, bis_cache->dma_buff); - if (!res) + if (res) return 1; // R/W error. // Decrypt cluster. - if (!se_aes_crypt_xts_sec_nx(ks_tweak, ks_crypt, DECRYPT, cluster, cache_tweak, true, 0, bis_cache->dma_buff, bis_cache->dma_buff, BIS_CLUSTER_SIZE)) + if (se_aes_crypt_xts_sec_nx(ks_tweak, ks_crypt, DECRYPT, cluster, cache_tweak, true, 0, bis_cache->dma_buff, bis_cache->dma_buff, BIS_CLUSTER_SIZE)) return 1; // Decryption error. // Copy to cluster cache. @@ -258,14 +258,14 @@ int nx_emmc_bis_read(u32 sector, u32 count, void *buff) u32 sct_cnt = MIN(count, cnt_max); // Only allow cluster sized access. if (nx_emmc_bis_read_block(curr_sct, sct_cnt, buf)) - return 0; + return 1; count -= sct_cnt; curr_sct += sct_cnt; buf += sct_cnt * EMMC_BLOCKSIZE; } - return 1; + return 0; } int nx_emmc_bis_write(u32 sector, u32 count, void *buff) @@ -282,14 +282,14 @@ int nx_emmc_bis_write(u32 sector, u32 count, void *buff) u32 sct_cnt = MIN(count, cnt_max); // Only allow cluster sized access. if (nx_emmc_bis_write_block(curr_sct, sct_cnt, buf, false)) - return 0; + return 1; count -= sct_cnt; curr_sct += sct_cnt; buf += sct_cnt * EMMC_BLOCKSIZE; } - return 1; + return 0; } void nx_emmc_bis_init(emmc_part_t *part, bool enable_cache, u32 emummc_offset) diff --git a/bdk/storage/sd.c b/bdk/storage/sd.c index 2a61bbda..3a0f204d 100644 --- a/bdk/storage/sd.c +++ b/bdk/storage/sd.c @@ -103,7 +103,7 @@ int sd_init_retry(bool power_cycle) switch (sd_mode) { case SD_INIT_FAIL: // Reset to max. - return 0; + return 1; case SD_1BIT_HS25: bus_width = SDMMC_BUS_WIDTH_1; @@ -134,7 +134,7 @@ int sd_init_retry(bool power_cycle) } int res = sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, bus_width, type); - if (res) + if (!res) { sd_init_done = true; insertion_event = true; @@ -145,17 +145,17 @@ int sd_init_retry(bool power_cycle) return res; } -bool sd_initialize(bool power_cycle) +int sd_initialize(bool power_cycle) { if (power_cycle) sdmmc_storage_end(&sd_storage); - int res = !sd_init_retry(false); + int res = sd_init_retry(false); while (true) { if (!res) - return true; + return 0; else if (!sdmmc_get_sd_inserted()) // SD Card is not inserted. { sd_mode = SD_DEFAULT_SPEED; @@ -168,24 +168,24 @@ bool sd_initialize(bool power_cycle) if (sd_mode == SD_INIT_FAIL) break; else - res = !sd_init_retry(true); + res = sd_init_retry(true); } } sdmmc_storage_end(&sd_storage); - return false; + return 1; } -bool sd_mount() +int sd_mount() { if (sd_init_done && sd_mounted) - return true; + return 0; int res = 0; if (!sd_init_done) - res = !sd_initialize(false); + res = sd_initialize(false); if (res) { @@ -203,7 +203,7 @@ bool sd_mount() if (res == FR_OK) { sd_mounted = true; - return true; + return 0; } else { @@ -212,7 +212,7 @@ bool sd_mount() } } - return false; + return 1; } static void _sd_deinit(bool deinit) diff --git a/bdk/storage/sd.h b/bdk/storage/sd.h index 1153996a..6e85d606 100644 --- a/bdk/storage/sd.h +++ b/bdk/storage/sd.h @@ -55,8 +55,8 @@ bool sd_get_card_initialized(); bool sd_get_card_mounted(); u32 sd_get_mode(); int sd_init_retry(bool power_cycle); -bool sd_initialize(bool power_cycle); -bool sd_mount(); +int sd_initialize(bool power_cycle); +int sd_mount(); void sd_unmount(); void sd_end(); bool sd_is_gpt(); diff --git a/bdk/storage/sdmmc.c b/bdk/storage/sdmmc.c index d5842155..4cc9f4b0 100644 --- a/bdk/storage/sdmmc.c +++ b/bdk/storage/sdmmc.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -73,28 +73,28 @@ static int _sdmmc_storage_check_card_status(u32 res) R1_CARD_ECC_FAILED | R1_CC_ERROR | R1_ERROR | R1_CID_CSD_OVERWRITE | R1_WP_ERASE_SKIP | R1_ERASE_RESET | R1_SWITCH_ERROR)) - return 0; + return 1; // No errors. - return 1; + return 0; } static int _sdmmc_storage_execute_cmd_type1_ex(sdmmc_storage_t *storage, u32 *resp, u32 cmd, u32 arg, u32 check_busy, u32 expected_state, u32 mask) { sdmmc_cmd_t cmdbuf; sdmmc_init_cmd(&cmdbuf, cmd, arg, SDMMC_RSP_TYPE_1, check_busy); - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) + return 1; sdmmc_get_cached_rsp(storage->sdmmc, resp, SDMMC_RSP_TYPE_1); if (mask) *resp &= ~mask; - if (_sdmmc_storage_check_card_status(*resp)) + if (!_sdmmc_storage_check_card_status(*resp)) if (expected_state == R1_SKIP_STATE_CHECK || R1_CURRENT_STATE(*resp) == expected_state) - return 1; + return 0; - return 0; + return 1; } static int _sdmmc_storage_execute_cmd_type1(sdmmc_storage_t *storage, u32 cmd, u32 arg, u32 check_busy, u32 expected_state) @@ -115,12 +115,12 @@ static int _sdmmc_storage_get_cid(sdmmc_storage_t *storage) { sdmmc_cmd_t cmdbuf; sdmmc_init_cmd(&cmdbuf, MMC_ALL_SEND_CID, 0, SDMMC_RSP_TYPE_2, 0); - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) + return 1; sdmmc_get_cached_rsp(storage->sdmmc, (u32 *)storage->raw_cid, SDMMC_RSP_TYPE_2); - return 1; + return 0; } static int _sdmmc_storage_select_card(sdmmc_storage_t *storage) @@ -132,12 +132,12 @@ static int _sdmmc_storage_get_csd(sdmmc_storage_t *storage) { sdmmc_cmd_t cmdbuf; sdmmc_init_cmd(&cmdbuf, MMC_SEND_CSD, storage->rca << 16, SDMMC_RSP_TYPE_2, 0); - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) + return 1; sdmmc_get_cached_rsp(storage->sdmmc, (u32 *)storage->raw_csd, SDMMC_RSP_TYPE_2); - return 1; + return 0; } static int _sdmmc_storage_set_blocklen(sdmmc_storage_t *storage, u32 blocklen) @@ -160,8 +160,8 @@ int sdmmc_storage_execute_vendor_cmd(sdmmc_storage_t *storage, u32 arg) { sdmmc_cmd_t cmdbuf; sdmmc_init_cmd(&cmdbuf, MMC_VENDOR_62_CMD, arg, SDMMC_RSP_TYPE_1, 1); - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, 0, 0)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, 0, 0)) + return 1; u32 resp; sdmmc_get_cached_rsp(storage->sdmmc, &resp, SDMMC_RSP_TYPE_1); @@ -186,7 +186,7 @@ int sdmmc_storage_execute_vendor_cmd(sdmmc_storage_t *storage, u32 arg) int sdmmc_storage_vendor_sandisk_report(sdmmc_storage_t *storage, void *buf) { // Request health report. - if (!sdmmc_storage_execute_vendor_cmd(storage, MMC_SANDISK_HEALTH_REPORT)) + if (sdmmc_storage_execute_vendor_cmd(storage, MMC_SANDISK_HEALTH_REPORT)) return 2; u32 tmp = 0; @@ -203,15 +203,15 @@ int sdmmc_storage_vendor_sandisk_report(sdmmc_storage_t *storage, void *buf) reqbuf.is_auto_stop_trn = 0; u32 blkcnt_out; - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, &blkcnt_out)) + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, &blkcnt_out)) { sdmmc_stop_transmission(storage->sdmmc, &tmp); _sdmmc_storage_get_status(storage, &tmp, 0); - return 0; + return 1; } - return 1; + return 0; } static int _sdmmc_storage_readwrite_ex(sdmmc_storage_t *storage, u32 *blkcnt_out, u32 sector, u32 num_sectors, void *buf, u32 is_write) @@ -233,38 +233,38 @@ static int _sdmmc_storage_readwrite_ex(sdmmc_storage_t *storage, u32 *blkcnt_out reqbuf.is_multi_block = 1; reqbuf.is_auto_stop_trn = 1; - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, blkcnt_out)) + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, blkcnt_out)) { sdmmc_stop_transmission(storage->sdmmc, &tmp); _sdmmc_storage_get_status(storage, &tmp, 0); - return 0; + return 1; } sdmmc_get_cached_rsp(storage->sdmmc, &tmp, SDMMC_RSP_TYPE_1); - if (!_sdmmc_storage_check_card_status(tmp)) - return 0; + if (_sdmmc_storage_check_card_status(tmp)) + return 1; - return 1; + return 0; } int sdmmc_storage_end(sdmmc_storage_t *storage) { DPRINTF("[SDMMC%d] end\n", storage->sdmmc->id); - if (!_sdmmc_storage_go_idle_state(storage)) - return 0; + if (_sdmmc_storage_go_idle_state(storage)) + return 1; sdmmc_end(storage->sdmmc); storage->initialized = 0; - return 1; + return 0; } static int _sdmmc_storage_handle_io_error(sdmmc_storage_t *storage, bool first_reinit) { - int res = 0; + int res = 1; if (storage->sdmmc->id == SDMMC_1 || storage->sdmmc->id == SDMMC_4) { @@ -277,7 +277,7 @@ static int _sdmmc_storage_handle_io_error(sdmmc_storage_t *storage, bool first_r else { res = sd_init_retry(true); - if (!res) + if (res) sd_error_count_increment(SD_ERROR_INIT_FAIL); } } @@ -290,7 +290,7 @@ static int _sdmmc_storage_handle_io_error(sdmmc_storage_t *storage, bool first_r else { res = emmc_init_retry(true); - if (!res) + if (res) emmc_error_count_increment(EMMC_ERROR_INIT_FAIL); } } @@ -308,7 +308,7 @@ static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 nu // Exit if not initialized. if (!storage->initialized) - return 0; + return 1; // Check if out of bounds. if (((u64)sector + num_sectors) > storage->sec_cnt) @@ -316,7 +316,7 @@ static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 nu #ifdef ERROR_EXTRA_PRINTING EPRINTFARGS("SDMMC%d: Out of bounds!", storage->sdmmc->id + 1); #endif - return 0; + return 1; } while (sct_total) @@ -327,7 +327,7 @@ static int _sdmmc_storage_readwrite(sdmmc_storage_t *storage, u32 sector, u32 nu do { reinit_try: - if (_sdmmc_storage_readwrite_ex(storage, &blkcnt, sct_off, MIN(sct_total, SDMMC_AMAX_BLOCKNUM), bbuf, is_write)) + if (!_sdmmc_storage_readwrite_ex(storage, &blkcnt, sct_off, MIN(sct_total, SDMMC_AMAX_BLOCKNUM), bbuf, is_write)) goto out; else retries--; @@ -338,7 +338,7 @@ reinit_try: } while (retries); // Disk IO failure! Reinit SD/EMMC to a lower speed. - if (_sdmmc_storage_handle_io_error(storage, first_reinit)) + if (!_sdmmc_storage_handle_io_error(storage, first_reinit)) { // Reset values for a retry. blkcnt = 0; @@ -353,7 +353,7 @@ reinit_try: } // Failed. - return 0; + return 1; out: sct_off += blkcnt; @@ -361,38 +361,39 @@ out: bbuf += SDMMC_DAT_BLOCKSIZE * blkcnt; } - return 1; + return 0; } int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) { // Ensure that SDMMC has access to buffer and it's SDMMC DMA aligned. - if (mc_client_has_access(buf) && !((u32)buf % 8)) + if (mc_client_has_access(buf) && !((u32)buf % SDMMC_ADMA_ADDR_ALIGN)) return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 0); - if (num_sectors > (SDMMC_UP_BUF_SZ / SDMMC_DAT_BLOCKSIZE)) - return 0; - - u8 *tmp_buf = (u8 *)SDMMC_UPPER_BUFFER; - if (_sdmmc_storage_readwrite(storage, sector, num_sectors, tmp_buf, 0)) - { - memcpy(buf, tmp_buf, SDMMC_DAT_BLOCKSIZE * num_sectors); + if (num_sectors > (SDMMC_ALT_DMA_BUF_SZ / SDMMC_DAT_BLOCKSIZE)) return 1; - } + + u8 *tmp_buf = (u8 *)SDMMC_ALT_DMA_BUFFER; + if (_sdmmc_storage_readwrite(storage, sector, num_sectors, tmp_buf, 0)) + return 1; + + memcpy(buf, tmp_buf, SDMMC_DAT_BLOCKSIZE * num_sectors); + return 0; } int sdmmc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf) { // Ensure that SDMMC has access to buffer and it's SDMMC DMA aligned. - if (mc_client_has_access(buf) && !((u32)buf % 8)) + if (mc_client_has_access(buf) && !((u32)buf % SDMMC_ADMA_ADDR_ALIGN)) return _sdmmc_storage_readwrite(storage, sector, num_sectors, buf, 1); - if (num_sectors > (SDMMC_UP_BUF_SZ / SDMMC_DAT_BLOCKSIZE)) - return 0; + if (num_sectors > (SDMMC_ALT_DMA_BUF_SZ / SDMMC_DAT_BLOCKSIZE)) + return 1; - u8 *tmp_buf = (u8 *)SDMMC_UPPER_BUFFER; + u8 *tmp_buf = (u8 *)SDMMC_ALT_DMA_BUFFER; memcpy(tmp_buf, buf, SDMMC_DAT_BLOCKSIZE * num_sectors); + return _sdmmc_storage_readwrite(storage, sector, num_sectors, tmp_buf, 1); } @@ -416,12 +417,12 @@ static int _mmc_storage_get_op_cond_inner(sdmmc_storage_t *storage, u32 *pout, u break; default: - return 0; + return 1; } sdmmc_init_cmd(&cmdbuf, MMC_SEND_OP_COND, arg, SDMMC_RSP_TYPE_3, 0); - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) + return 1; return sdmmc_get_cached_rsp(storage->sdmmc, pout, SDMMC_RSP_TYPE_3); } @@ -433,7 +434,7 @@ static int _mmc_storage_get_op_cond(sdmmc_storage_t *storage, u32 power) while (true) { u32 cond = 0; - if (!_mmc_storage_get_op_cond_inner(storage, &cond, power)) + if (_mmc_storage_get_op_cond_inner(storage, &cond, power)) break; // Check if power up is done. @@ -443,7 +444,7 @@ static int _mmc_storage_get_op_cond(sdmmc_storage_t *storage, u32 power) if (cond & MMC_CARD_CCS) storage->has_sector_access = 1; - return 1; + return 0; } if (get_tmr_ms() > timeout) break; @@ -451,7 +452,7 @@ static int _mmc_storage_get_op_cond(sdmmc_storage_t *storage, u32 power) usleep(1000); } - return 0; + return 1; } static int _mmc_storage_set_relative_addr(sdmmc_storage_t *storage) @@ -515,54 +516,55 @@ static void _mmc_storage_parse_csd(sdmmc_storage_t *storage) storage->sec_cnt = storage->csd.capacity; } -static void _mmc_storage_parse_ext_csd(sdmmc_storage_t *storage, u8 *buf) +static void _mmc_storage_parse_ext_csd(sdmmc_storage_t *storage) { - storage->ext_csd.rev = buf[EXT_CSD_REV]; - storage->ext_csd.ext_struct = buf[EXT_CSD_STRUCTURE]; - storage->ext_csd.card_type = buf[EXT_CSD_CARD_TYPE]; - storage->ext_csd.dev_version = *(u16 *)&buf[EXT_CSD_DEVICE_VERSION]; - storage->ext_csd.boot_mult = buf[EXT_CSD_BOOT_MULT]; - storage->ext_csd.rpmb_mult = buf[EXT_CSD_RPMB_MULT]; - //storage->ext_csd.bkops = buf[EXT_CSD_BKOPS_SUPPORT]; - //storage->ext_csd.bkops_en = buf[EXT_CSD_BKOPS_EN]; - //storage->ext_csd.bkops_status = buf[EXT_CSD_BKOPS_STATUS]; + u8 *ext_csd = storage->raw_ext_csd; - storage->ext_csd.pre_eol_info = buf[EXT_CSD_PRE_EOL_INFO]; - storage->ext_csd.dev_life_est_a = buf[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]; - storage->ext_csd.dev_life_est_b = buf[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]; + storage->ext_csd.rev = ext_csd[EXT_CSD_REV]; + storage->ext_csd.ext_struct = ext_csd[EXT_CSD_STRUCTURE]; + storage->ext_csd.card_type = ext_csd[EXT_CSD_CARD_TYPE]; + storage->ext_csd.dev_version = *(u16 *)&ext_csd[EXT_CSD_DEVICE_VERSION]; + storage->ext_csd.boot_mult = ext_csd[EXT_CSD_BOOT_MULT]; + storage->ext_csd.rpmb_mult = ext_csd[EXT_CSD_RPMB_MULT]; + storage->ext_csd.bkops = ext_csd[EXT_CSD_BKOPS_SUPPORT]; + storage->ext_csd.bkops_en = ext_csd[EXT_CSD_BKOPS_EN]; - storage->ext_csd.cache_size = buf[EXT_CSD_CACHE_SIZE] | - (buf[EXT_CSD_CACHE_SIZE + 1] << 8) | - (buf[EXT_CSD_CACHE_SIZE + 2] << 16) | - (buf[EXT_CSD_CACHE_SIZE + 3] << 24); + storage->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO]; + storage->ext_csd.dev_life_est_a = ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]; + storage->ext_csd.dev_life_est_b = ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]; - storage->ext_csd.max_enh_mult = (buf[EXT_CSD_MAX_ENH_SIZE_MULT] | - (buf[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) | - (buf[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16)) * - buf[EXT_CSD_HC_WP_GRP_SIZE] * buf[EXT_CSD_HC_ERASE_GRP_SIZE]; + storage->ext_csd.cache_size = ext_csd[EXT_CSD_CACHE_SIZE] | + (ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8) | + (ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16) | + (ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24); - storage->sec_cnt = *(u32 *)&buf[EXT_CSD_SEC_CNT]; + storage->ext_csd.max_enh_mult = (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT] | + (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) | + (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16)) * + ext_csd[EXT_CSD_HC_WP_GRP_SIZE] * ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; + + storage->sec_cnt = *(u32 *)&ext_csd[EXT_CSD_SEC_CNT]; } -int mmc_storage_get_ext_csd(sdmmc_storage_t *storage, void *buf) +int mmc_storage_get_ext_csd(sdmmc_storage_t *storage) { sdmmc_cmd_t cmdbuf; sdmmc_init_cmd(&cmdbuf, MMC_SEND_EXT_CSD, 0, SDMMC_RSP_TYPE_1, 0); sdmmc_req_t reqbuf; - reqbuf.buf = buf; + reqbuf.buf = storage->raw_ext_csd; reqbuf.blksize = SDMMC_DAT_BLOCKSIZE; reqbuf.num_sectors = 1; reqbuf.is_write = 0; reqbuf.is_multi_block = 0; reqbuf.is_auto_stop_trn = 0; - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) + return 1; u32 tmp = 0; sdmmc_get_cached_rsp(storage->sdmmc, &tmp, SDMMC_RSP_TYPE_1); - _mmc_storage_parse_ext_csd(storage, buf); + _mmc_storage_parse_ext_csd(storage); return _sdmmc_storage_check_card_status(tmp); } @@ -570,7 +572,7 @@ int mmc_storage_get_ext_csd(sdmmc_storage_t *storage, void *buf) int sd_storage_get_ext_reg(sdmmc_storage_t *storage, u8 fno, u8 page, u16 address, u32 len, void *buf) { if (!(storage->scr.cmds & BIT(2))) - return 0; + return 1; sdmmc_cmd_t cmdbuf; @@ -586,8 +588,8 @@ int sd_storage_get_ext_reg(sdmmc_storage_t *storage, u8 fno, u8 page, u16 addres reqbuf.is_multi_block = 0; reqbuf.is_auto_stop_trn = 0; - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) + return 1; u32 tmp = 0; sdmmc_get_cached_rsp(storage->sdmmc, &tmp, SDMMC_RSP_TYPE_1); @@ -603,7 +605,7 @@ static int _mmc_storage_switch(sdmmc_storage_t *storage, u32 arg) static int _mmc_storage_switch_buswidth(sdmmc_storage_t *storage, u32 bus_width) { if (bus_width == SDMMC_BUS_WIDTH_1) - return 1; + return 0; u32 arg = 0; switch (bus_width) @@ -617,47 +619,47 @@ static int _mmc_storage_switch_buswidth(sdmmc_storage_t *storage, u32 bus_width) break; } - if (_mmc_storage_switch(storage, arg)) - if (_sdmmc_storage_check_status(storage)) + if (!_mmc_storage_switch(storage, arg)) + if (!_sdmmc_storage_check_status(storage)) { sdmmc_set_bus_width(storage->sdmmc, bus_width); - return 1; + return 0; } - return 0; + return 1; } static int _mmc_storage_enable_HS(sdmmc_storage_t *storage, bool check_sts_before_clk_setup) { - if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS))) - return 0; + if (_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS))) + return 1; - if (check_sts_before_clk_setup && !_sdmmc_storage_check_status(storage)) - return 0; + if (check_sts_before_clk_setup && _sdmmc_storage_check_status(storage)) + return 1; - if (!sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_HS52)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_HS52)) + return 1; DPRINTF("[MMC] switched to HS52\n"); storage->csd.busspeed = 52; - if (check_sts_before_clk_setup || _sdmmc_storage_check_status(storage)) - return 1; + if (check_sts_before_clk_setup || !_sdmmc_storage_check_status(storage)) + return 0; - return 0; + return 1; } static int _mmc_storage_enable_HS200(sdmmc_storage_t *storage) { - if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS200))) - return 0; + if (_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS200))) + return 1; - if (!sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_HS200)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_HS200)) + return 1; - if (!sdmmc_tuning_execute(storage->sdmmc, SDHCI_TIMING_MMC_HS200, MMC_SEND_TUNING_BLOCK_HS200)) - return 0; + if (sdmmc_tuning_execute(storage->sdmmc, SDHCI_TIMING_MMC_HS200, MMC_SEND_TUNING_BLOCK_HS200)) + return 1; DPRINTF("[MMC] switched to HS200\n"); storage->csd.busspeed = 200; @@ -667,22 +669,22 @@ static int _mmc_storage_enable_HS200(sdmmc_storage_t *storage) static int _mmc_storage_enable_HS400(sdmmc_storage_t *storage) { - if (!_mmc_storage_enable_HS200(storage)) - return 0; + if (_mmc_storage_enable_HS200(storage)) + return 1; sdmmc_save_tap_value(storage->sdmmc); - if (!_mmc_storage_enable_HS(storage, false)) - return 0; + if (_mmc_storage_enable_HS(storage, false)) + return 1; - if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_BUS_WIDTH, EXT_CSD_DDR_BUS_WIDTH_8))) - return 0; + if (_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_BUS_WIDTH, EXT_CSD_DDR_BUS_WIDTH_8))) + return 1; - if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS400))) - return 0; + if (_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS400))) + return 1; - if (!sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_HS400)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_HS400)) + return 1; DPRINTF("[MMC] switched to HS400\n"); storage->csd.busspeed = 400; @@ -711,14 +713,14 @@ hs52_mode: if (card_type & EXT_CSD_CARD_TYPE_HS_52) return _mmc_storage_enable_HS(storage, true); - return 1; + return 0; } /* static int _mmc_storage_enable_auto_bkops(sdmmc_storage_t *storage) { - if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_SET_BITS, EXT_CSD_BKOPS_EN, EXT_CSD_AUTO_BKOPS_MASK))) - return 0; + if (_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_SET_BITS, EXT_CSD_BKOPS_EN, EXT_CSD_BKOPS_AUTO))) + return 1; return _sdmmc_storage_check_status(storage); } @@ -732,70 +734,70 @@ int sdmmc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_wid DPRINTF("[MMC]-[init: bus: %d, type: %d]\n", bus_width, type); - if (!sdmmc_init(sdmmc, SDMMC_4, SDMMC_POWER_1_8, SDMMC_BUS_WIDTH_1, SDHCI_TIMING_MMC_ID)) - return 0; + if (sdmmc_init(sdmmc, SDMMC_4, SDMMC_POWER_1_8, SDMMC_BUS_WIDTH_1, SDHCI_TIMING_MMC_ID)) + return 1; DPRINTF("[MMC] after init\n"); // Wait 1ms + 74 cycles. usleep(1000 + (74 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); - if (!_sdmmc_storage_go_idle_state(storage)) - return 0; + if (_sdmmc_storage_go_idle_state(storage)) + return 1; DPRINTF("[MMC] went to idle state\n"); - if (!_mmc_storage_get_op_cond(storage, SDMMC_POWER_1_8)) - return 0; + if (_mmc_storage_get_op_cond(storage, SDMMC_POWER_1_8)) + return 1; DPRINTF("[MMC] got op cond\n"); - if (!_sdmmc_storage_get_cid(storage)) - return 0; + if (_sdmmc_storage_get_cid(storage)) + return 1; DPRINTF("[MMC] got cid\n"); - if (!_mmc_storage_set_relative_addr(storage)) - return 0; + if (_mmc_storage_set_relative_addr(storage)) + return 1; DPRINTF("[MMC] set relative addr\n"); - if (!_sdmmc_storage_get_csd(storage)) - return 0; + if (_sdmmc_storage_get_csd(storage)) + return 1; DPRINTF("[MMC] got csd\n"); _mmc_storage_parse_csd(storage); - if (!sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_LS26)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_MMC_LS26)) + return 1; DPRINTF("[MMC] after setup clock\n"); - if (!_sdmmc_storage_select_card(storage)) - return 0; + if (_sdmmc_storage_select_card(storage)) + return 1; DPRINTF("[MMC] card selected\n"); - if (!_sdmmc_storage_set_blocklen(storage, EMMC_BLOCKSIZE)) - return 0; + if (_sdmmc_storage_set_blocklen(storage, EMMC_BLOCKSIZE)) + return 1; DPRINTF("[MMC] set blocklen to EMMC_BLOCKSIZE\n"); // Check system specification version, only version 4.0 and later support below features. if (storage->csd.mmca_vsn < CSD_SPEC_VER_4) goto done; - if (!_mmc_storage_switch_buswidth(storage, bus_width)) - return 0; + if (_mmc_storage_switch_buswidth(storage, bus_width)) + return 1; DPRINTF("[MMC] switched buswidth\n"); - if (!mmc_storage_get_ext_csd(storage, (u8 *)SDMMC_UPPER_BUFFER)) - return 0; + if (mmc_storage_get_ext_csd(storage)) + return 1; DPRINTF("[MMC] got ext_csd\n"); _mmc_storage_parse_cid(storage); // This needs to be after csd and ext_csd. /* - if (storage->ext_csd.bkops & 0x1 && !(storage->ext_csd.bkops_en & EXT_CSD_AUTO_BKOPS_MASK)) + if (storage->cid.manfid == 0x11 && storage->ext_csd.bkops && !(storage->ext_csd.bkops_en & EXT_CSD_BKOPS_AUTO)) { _mmc_storage_enable_auto_bkops(storage); DPRINTF("[MMC] BKOPS enabled\n"); } */ - if (!_mmc_storage_enable_highspeed(storage, storage->ext_csd.card_type, type)) - return 0; + if (_mmc_storage_enable_highspeed(storage, storage->ext_csd.card_type, type)) + return 1; DPRINTF("[MMC] successfully switched to HS mode\n"); sdmmc_card_clock_powersave(storage->sdmmc, SDMMC_POWER_SAVE_ENABLE); @@ -803,20 +805,20 @@ int sdmmc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_wid done: storage->initialized = 1; - return 1; + return 0; } int sdmmc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition) { - if (!_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_PART_CONFIG, partition))) - return 0; + if (_mmc_storage_switch(storage, SDMMC_SWITCH(MMC_SWITCH_MODE_WRITE_BYTE, EXT_CSD_PART_CONFIG, partition))) + return 1; - if (!_sdmmc_storage_check_status(storage)) - return 0; + if (_sdmmc_storage_check_status(storage)) + return 1; storage->partition = partition; - return 1; + return 0; } /* @@ -826,16 +828,16 @@ int sdmmc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition) static int _sd_storage_execute_app_cmd(sdmmc_storage_t *storage, u32 expected_state, u32 mask, sdmmc_cmd_t *cmdbuf, sdmmc_req_t *req, u32 *blkcnt_out) { u32 tmp; - if (!_sdmmc_storage_execute_cmd_type1_ex(storage, &tmp, MMC_APP_CMD, storage->rca << 16, 0, expected_state, mask)) - return 0; + if (_sdmmc_storage_execute_cmd_type1_ex(storage, &tmp, MMC_APP_CMD, storage->rca << 16, 0, expected_state, mask)) + return 1; return sdmmc_execute_cmd(storage->sdmmc, cmdbuf, req, blkcnt_out); } static int _sd_storage_execute_app_cmd_type1(sdmmc_storage_t *storage, u32 *resp, u32 cmd, u32 arg, u32 check_busy, u32 expected_state) { - if (!_sdmmc_storage_execute_cmd_type1(storage, MMC_APP_CMD, storage->rca << 16, 0, R1_STATE_TRAN)) - return 0; + if (_sdmmc_storage_execute_cmd_type1(storage, MMC_APP_CMD, storage->rca << 16, 0, R1_STATE_TRAN)) + return 1; return _sdmmc_storage_execute_cmd_type1_ex(storage, resp, cmd, arg, check_busy, expected_state, 0); } @@ -972,16 +974,16 @@ static int _sd_storage_send_if_cond(sdmmc_storage_t *storage, bool *is_sdsc) sdmmc_cmd_t cmdbuf; u16 vhd_pattern = SD_VHS_27_36 | 0xAA; sdmmc_init_cmd(&cmdbuf, SD_SEND_IF_COND, vhd_pattern, SDMMC_RSP_TYPE_7, 0); - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) { // The SD Card is version 1.X (SDSC) if there is no response. if (storage->sdmmc->error_sts == SDHCI_ERR_INT_CMD_TIMEOUT) { *is_sdsc = 1; - return 1; + return 0; } - return 0; + return 1; } // For Card version >= 2.0, parse results. @@ -990,9 +992,9 @@ static int _sd_storage_send_if_cond(sdmmc_storage_t *storage, bool *is_sdsc) // Check if VHD was accepted and pattern was properly returned. if ((resp & 0xFFF) == vhd_pattern) - return 1; + return 0; - return 0; + return 1; } static int _sd_storage_get_op_cond_once(sdmmc_storage_t *storage, u32 *cond, bool is_sdsc, int bus_uhs_support) @@ -1009,8 +1011,8 @@ static int _sd_storage_get_op_cond_once(sdmmc_storage_t *storage, u32 *cond, boo sdmmc_init_cmd(&cmdbuf, SD_APP_OP_COND, arg, SDMMC_RSP_TYPE_3, 0); - if (!_sd_storage_execute_app_cmd(storage, R1_SKIP_STATE_CHECK, is_sdsc ? R1_ILLEGAL_COMMAND : 0, &cmdbuf, NULL, NULL)) - return 0; + if (_sd_storage_execute_app_cmd(storage, R1_SKIP_STATE_CHECK, is_sdsc ? R1_ILLEGAL_COMMAND : 0, &cmdbuf, NULL, NULL)) + return 1; return sdmmc_get_cached_rsp(storage->sdmmc, cond, SDMMC_RSP_TYPE_3); } @@ -1022,7 +1024,7 @@ static int _sd_storage_get_op_cond(sdmmc_storage_t *storage, bool is_sdsc, int b while (true) { u32 cond = 0; - if (!_sd_storage_get_op_cond_once(storage, &cond, is_sdsc, bus_uhs_support)) + if (_sd_storage_get_op_cond_once(storage, &cond, is_sdsc, bus_uhs_support)) break; // Check if power up is done. @@ -1038,13 +1040,13 @@ static int _sd_storage_get_op_cond(sdmmc_storage_t *storage, bool is_sdsc, int b if (cond & SD_ROCR_S18A && bus_uhs_support && !storage->is_low_voltage) { // Switch to 1.8V signaling. - if (_sdmmc_storage_execute_cmd_type1(storage, SD_SWITCH_VOLTAGE, 0, 0, R1_STATE_READY)) + if (!_sdmmc_storage_execute_cmd_type1(storage, SD_SWITCH_VOLTAGE, 0, 0, R1_STATE_READY)) { - if (!sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_UHS_SDR12)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_UHS_SDR12)) + return 1; - if (!sdmmc_enable_low_voltage(storage->sdmmc)) - return 0; + if (sdmmc_enable_low_voltage(storage->sdmmc)) + return 1; storage->is_low_voltage = 1; @@ -1056,14 +1058,14 @@ static int _sd_storage_get_op_cond(sdmmc_storage_t *storage, bool is_sdsc, int b DPRINTF("[SD] no low voltage support\n"); } - return 1; + return 0; } if (get_tmr_ms() > timeout) break; msleep(10); // Needs to be at least 10ms for some SD Cards } - return 0; + return 1; } static int _sd_storage_get_rca(sdmmc_storage_t *storage) @@ -1075,17 +1077,17 @@ static int _sd_storage_get_rca(sdmmc_storage_t *storage) while (true) { - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, NULL, NULL)) break; u32 resp = 0; - if (!sdmmc_get_cached_rsp(storage->sdmmc, &resp, SDMMC_RSP_TYPE_6)) + if (sdmmc_get_cached_rsp(storage->sdmmc, &resp, SDMMC_RSP_TYPE_6)) break; if (resp >> 16) { storage->rca = resp >> 16; - return 1; + return 0; } if (get_tmr_ms() > timeout) @@ -1093,7 +1095,7 @@ static int _sd_storage_get_rca(sdmmc_storage_t *storage) usleep(1000); } - return 0; + return 1; } static void _sd_storage_parse_scr(sdmmc_storage_t *storage) @@ -1123,8 +1125,10 @@ static void _sd_storage_parse_scr(sdmmc_storage_t *storage) } } -int sd_storage_get_scr(sdmmc_storage_t *storage, u8 *buf) +int sd_storage_get_scr(sdmmc_storage_t *storage) { + u8 buf[8] __attribute__ ((aligned(SDMMC_ADMA_ADDR_ALIGN))); + sdmmc_cmd_t cmdbuf; sdmmc_init_cmd(&cmdbuf, SD_APP_SEND_SCR, 0, SDMMC_RSP_TYPE_1, 0); @@ -1136,13 +1140,13 @@ int sd_storage_get_scr(sdmmc_storage_t *storage, u8 *buf) reqbuf.is_multi_block = 0; reqbuf.is_auto_stop_trn = 0; - if (!_sd_storage_execute_app_cmd(storage, R1_STATE_TRAN, 0, &cmdbuf, &reqbuf, NULL)) - return 0; + if (_sd_storage_execute_app_cmd(storage, R1_STATE_TRAN, 0, &cmdbuf, &reqbuf, NULL)) + return 1; u32 tmp = 0; sdmmc_get_cached_rsp(storage->sdmmc, &tmp, SDMMC_RSP_TYPE_1); //Prepare buffer for unstuff_bits - for (u32 i = 0; i < 8; i+=4) + for (u32 i = 0; i < 8; i += 4) { storage->raw_scr[i + 3] = buf[i]; storage->raw_scr[i + 2] = buf[i + 1]; @@ -1167,8 +1171,8 @@ static int _sd_storage_switch_get(sdmmc_storage_t *storage, void *buf) reqbuf.is_multi_block = 0; reqbuf.is_auto_stop_trn = 0; - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) + return 1; u32 tmp = 0; sdmmc_get_cached_rsp(storage->sdmmc, &tmp, SDMMC_RSP_TYPE_1); @@ -1191,8 +1195,8 @@ static int _sd_storage_switch(sdmmc_storage_t *storage, void *buf, int mode, int reqbuf.is_multi_block = 0; reqbuf.is_auto_stop_trn = 0; - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) - return 0; + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) + return 1; u32 tmp = 0; sdmmc_get_cached_rsp(storage->sdmmc, &tmp, SDMMC_RSP_TYPE_1); @@ -1237,26 +1241,26 @@ static void _sd_storage_set_power_limit(sdmmc_storage_t *storage, u16 power_limi } } -int _sd_storage_set_driver_type(sdmmc_storage_t *storage, u32 driver, u8 *buf) +__attribute__ ((unused)) static int _sd_storage_set_driver_type(sdmmc_storage_t *storage, u32 driver, u8 *buf) { - if (!_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, SD_SWITCH_GRP_DRVSTR, driver)) - return 0; + if (_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, SD_SWITCH_GRP_DRVSTR, driver)) + return 1; u32 driver_out = buf[15] & 0xF; if (driver_out != driver) - return 0; + return 1; DPRINTF("[SD] supports Driver Strength %d\n", driver); - if (!_sd_storage_switch(storage, buf, SD_SWITCH_SET, SD_SWITCH_GRP_DRVSTR, driver)) - return 0; + if (_sd_storage_switch(storage, buf, SD_SWITCH_SET, SD_SWITCH_GRP_DRVSTR, driver)) + return 1; if (driver_out != (buf[15] & 0xF)) - return 0; + return 1; DPRINTF("[SD] card accepted Driver Strength %d\n", driver); sdmmc_setup_drv_type(storage->sdmmc, driver); - return 1; + return 0; } /* @@ -1301,97 +1305,100 @@ int _sd_storage_set_driver_type(sdmmc_storage_t *storage, u32 driver, u8 *buf) static int _sd_storage_enable_DDR200(sdmmc_storage_t *storage, u8 *buf) { u32 cmd_system = UHS_DDR200_BUS_SPEED; - if (!_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, SD_SWITCH_GRP_CMDSYS, cmd_system)) - return 0; + if (_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, SD_SWITCH_GRP_CMDSYS, cmd_system)) + return 1; u32 system_out = (buf[16] >> 4) & 0xF; if (system_out != cmd_system) - return 0; + return 1; DPRINTF("[SD] supports DDR200 mode\n"); u16 total_pwr_consumption = ((u16)buf[0] << 8) | buf[1]; DPRINTF("[SD] max power: %d mW\n", total_pwr_consumption * 3600 / 1000); storage->max_power = total_pwr_consumption; + // Check if total is low than max and switch. if (total_pwr_consumption <= 800) { - if (!_sd_storage_switch(storage, buf, SD_SWITCH_SET, SD_SWITCH_GRP_CMDSYS, cmd_system)) - return 0; + if (_sd_storage_switch(storage, buf, SD_SWITCH_SET, SD_SWITCH_GRP_CMDSYS, cmd_system)) + return 1; if (system_out != ((buf[16] >> 4) & 0xF)) - return 0; + return 1; DPRINTF("[SD] card accepted DDR200\n"); - if (!sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_UHS_DDR200)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_UHS_DDR200)) + return 1; DPRINTF("[SD] after setup clock DDR200\n"); - if (!sdmmc_tuning_execute(storage->sdmmc, SDHCI_TIMING_UHS_DDR200, MMC_SEND_TUNING_BLOCK)) - return 0; + if (sdmmc_tuning_execute(storage->sdmmc, SDHCI_TIMING_UHS_DDR200, MMC_SEND_TUNING_BLOCK)) + return 1; DPRINTF("[SD] after tuning DDR200\n"); return _sdmmc_storage_check_status(storage); } DPRINTF("[SD] card max power over limit\n"); - return 0; + return 1; } #endif static int _sd_storage_set_card_bus_speed(sdmmc_storage_t *storage, u32 hs_type, u8 *buf) { - if (!_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, SD_SWITCH_GRP_ACCESS, hs_type)) - return 0; + if (_sd_storage_switch(storage, buf, SD_SWITCH_CHECK, SD_SWITCH_GRP_ACCESS, hs_type)) + return 1; u32 type_out = buf[16] & 0xF; if (type_out != hs_type) - return 0; + return 1; DPRINTF("[SD] supports selected (U)HS mode %d\n", buf[16] & 0xF); u16 total_pwr_consumption = ((u16)buf[0] << 8) | buf[1]; DPRINTF("[SD] max power: %d mW\n", total_pwr_consumption * 3600 / 1000); storage->max_power = total_pwr_consumption; + // Check if total is low than max and switch. if (total_pwr_consumption <= 800) { - if (!_sd_storage_switch(storage, buf, SD_SWITCH_SET, SD_SWITCH_GRP_ACCESS, hs_type)) - return 0; + if (_sd_storage_switch(storage, buf, SD_SWITCH_SET, SD_SWITCH_GRP_ACCESS, hs_type)) + return 1; if (type_out != (buf[16] & 0xF)) - return 0; + return 1; - return 1; + return 0; } DPRINTF("[SD] card max power over limit\n"); - return 0; + return 1; } int sd_storage_get_fmodes(sdmmc_storage_t *storage, u8 *buf, sd_func_modes_t *fmodes) { if (!buf) - buf = (u8 *)SDMMC_UPPER_BUFFER; + buf = (u8 *)SDMMC_ALT_DMA_BUFFER; - if (!_sd_storage_switch_get(storage, buf)) - return 0; + if (_sd_storage_switch_get(storage, buf)) + return 1; fmodes->access_mode = buf[13] | (buf[12] << 8); fmodes->cmd_system = buf[11] | (buf[10] << 8); fmodes->driver_strength = buf[9] | (buf[8] << 8); fmodes->power_limit = buf[7] | (buf[6] << 8); - return 1; + return 0; } -static int _sd_storage_enable_uhs_low_volt(sdmmc_storage_t *storage, u32 type, u8 *buf) +static int _sd_storage_enable_uhs_low_volt(sdmmc_storage_t *storage, u32 type) { sd_func_modes_t fmodes; + u8 *buf = storage->raw_ext_csd; if (sdmmc_get_bus_width(storage->sdmmc) != SDMMC_BUS_WIDTH_4) - return 0; + return 1; - if (!sd_storage_get_fmodes(storage, buf, &fmodes)) - return 0; + if (sd_storage_get_fmodes(storage, buf, &fmodes)) + return 1; #ifdef BDK_SDMMC_UHS_DDR200_SUPPORT DPRINTF("[SD] access: %02X, power: %02X, cmd: %02X\n", fmodes.access_mode, fmodes.power_limit, fmodes.cmd_system); @@ -1467,7 +1474,7 @@ static int _sd_storage_enable_uhs_low_volt(sdmmc_storage_t *storage, u32 type, u default: DPRINTF("[SD] bus speed defaulted to SDR12\n"); storage->csd.busspeed = 12; - return 1; + return 0; // Already set. } // Try to raise the power limit to let the card perform better. @@ -1475,38 +1482,40 @@ static int _sd_storage_enable_uhs_low_volt(sdmmc_storage_t *storage, u32 type, u _sd_storage_set_power_limit(storage, fmodes.power_limit, buf); // Setup and set selected card and bus speed. - if (!_sd_storage_set_card_bus_speed(storage, hs_type, buf)) - return 0; + if (_sd_storage_set_card_bus_speed(storage, hs_type, buf)) + return 1; DPRINTF("[SD] card accepted UHS\n"); - if (!sdmmc_setup_clock(storage->sdmmc, type)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, type)) + return 1; DPRINTF("[SD] after setup clock\n"); - if (!sdmmc_tuning_execute(storage->sdmmc, type, MMC_SEND_TUNING_BLOCK)) - return 0; + if (sdmmc_tuning_execute(storage->sdmmc, type, MMC_SEND_TUNING_BLOCK)) + return 1; DPRINTF("[SD] after tuning\n"); return _sdmmc_storage_check_status(storage); } -static int _sd_storage_enable_hs_high_volt(sdmmc_storage_t *storage, u8 *buf) +static int _sd_storage_enable_hs_high_volt(sdmmc_storage_t *storage) { sd_func_modes_t fmodes; + u8 *buf = storage->raw_ext_csd; - if (!sd_storage_get_fmodes(storage, buf, &fmodes)) - return 0; + if (sd_storage_get_fmodes(storage, buf, &fmodes)) + return 1; DPRINTF("[SD] access: %02X, power: %02X\n", fmodes.access_mode, fmodes.power_limit); + // No support, return success. if (!(fmodes.access_mode & SD_MODE_HIGH_SPEED)) + return 0; + + if (_sd_storage_set_card_bus_speed(storage, HIGH_SPEED_BUS_SPEED, buf)) return 1; - if (!_sd_storage_set_card_bus_speed(storage, HIGH_SPEED_BUS_SPEED, buf)) - return 0; - - if (!_sdmmc_storage_check_status(storage)) - return 0; + if (_sdmmc_storage_check_status(storage)) + return 1; return sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_SD_HS25); } @@ -1599,18 +1608,18 @@ int sd_storage_parse_perf_enhance(sdmmc_storage_t *storage, u8 fno, u8 page, u16 storage->ser.cache = (storage->ssr.perf_enhance >> 2) & BIT(0); storage->ser.cmdq = (storage->ssr.perf_enhance >> 3) & 0x1F; - if (!sd_storage_get_ext_reg(storage, fno, page, offset, 512, buf)) + if (sd_storage_get_ext_reg(storage, fno, page, offset, 512, buf)) { storage->ser.cache_ext = 0; storage->ser.cmdq_ext = 0; - return 0; + return 1; } storage->ser.cache_ext = buf[4] & BIT(0); storage->ser.cmdq_ext = buf[6] & 0x1F; - return 1; + return 0; } static void _sd_storage_parse_ext_reg(sdmmc_storage_t *storage, u8 *buf, u16 *addr_next) @@ -1660,7 +1669,7 @@ void sd_storage_get_ext_regs(sdmmc_storage_t *storage, u8 *buf) return; } - if (!sd_storage_get_ext_reg(storage, 0, 0, 0, 512, buf)) + if (sd_storage_get_ext_reg(storage, 0, 0, 0, 512, buf)) { DREGPRINTF("Failed to get general info!\n"); return; @@ -1673,9 +1682,11 @@ void sd_storage_get_ext_regs(sdmmc_storage_t *storage, u8 *buf) _sd_storage_parse_ext_reg(storage, buf, &addr_next); } -int sd_storage_get_ssr(sdmmc_storage_t *storage, u8 *buf) +int sd_storage_get_ssr(sdmmc_storage_t *storage) { sdmmc_cmd_t cmdbuf; + u8 *buf = storage->raw_ext_csd; + sdmmc_init_cmd(&cmdbuf, SD_APP_SD_STATUS, 0, SDMMC_RSP_TYPE_1, 0); sdmmc_req_t reqbuf; @@ -1689,11 +1700,11 @@ int sd_storage_get_ssr(sdmmc_storage_t *storage, u8 *buf) if (!(storage->csd.cmdclass & CCC_APP_SPEC)) { DPRINTF("[SD] ssr: Not supported\n"); - return 0; + return 1; } - if (!_sd_storage_execute_app_cmd(storage, R1_STATE_TRAN, 0, &cmdbuf, &reqbuf, NULL)) - return 0; + if (_sd_storage_execute_app_cmd(storage, R1_STATE_TRAN, 0, &cmdbuf, &reqbuf, NULL)) + return 1; u32 tmp = 0; sdmmc_get_cached_rsp(storage->sdmmc, &tmp, SDMMC_RSP_TYPE_1); @@ -1797,7 +1808,6 @@ int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_widt { u32 tmp = 0; bool is_sdsc = 0; - u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; bool bus_uhs_support = _sdmmc_storage_get_bus_uhs_support(bus_width, type); DPRINTF("[SD]-[init: bus: %d, type: %d]\n", bus_width, type); @@ -1808,68 +1818,68 @@ int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_widt memset(storage, 0, sizeof(sdmmc_storage_t)); storage->sdmmc = sdmmc; - if (!sdmmc_init(sdmmc, SDMMC_1, SDMMC_POWER_3_3, SDMMC_BUS_WIDTH_1, SDHCI_TIMING_SD_ID)) - return 0; + if (sdmmc_init(sdmmc, SDMMC_1, SDMMC_POWER_3_3, SDMMC_BUS_WIDTH_1, SDHCI_TIMING_SD_ID)) + return 1; DPRINTF("[SD] after init\n"); // Wait 1ms + 74 cycles. usleep(1000 + (74 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); - if (!_sdmmc_storage_go_idle_state(storage)) - return 0; + if (_sdmmc_storage_go_idle_state(storage)) + return 1; DPRINTF("[SD] went to idle state\n"); - if (!_sd_storage_send_if_cond(storage, &is_sdsc)) - return 0; + if (_sd_storage_send_if_cond(storage, &is_sdsc)) + return 1; DPRINTF("[SD] after send if cond\n"); - if (!_sd_storage_get_op_cond(storage, is_sdsc, bus_uhs_support)) - return 0; + if (_sd_storage_get_op_cond(storage, is_sdsc, bus_uhs_support)) + return 1; DPRINTF("[SD] got op cond\n"); - if (!_sdmmc_storage_get_cid(storage)) - return 0; + if (_sdmmc_storage_get_cid(storage)) + return 1; DPRINTF("[SD] got cid\n"); _sd_storage_parse_cid(storage); - if (!_sd_storage_get_rca(storage)) - return 0; + if (_sd_storage_get_rca(storage)) + return 1; DPRINTF("[SD] got rca (= %04X)\n", storage->rca); - if (!_sdmmc_storage_get_csd(storage)) - return 0; + if (_sdmmc_storage_get_csd(storage)) + return 1; DPRINTF("[SD] got csd\n"); _sd_storage_parse_csd(storage); if (!storage->is_low_voltage) { - if (!sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_SD_DS12)) - return 0; + if (sdmmc_setup_clock(storage->sdmmc, SDHCI_TIMING_SD_DS12)) + return 1; DPRINTF("[SD] after setup default clock\n"); } - if (!_sdmmc_storage_select_card(storage)) - return 0; + if (_sdmmc_storage_select_card(storage)) + return 1; DPRINTF("[SD] card selected\n"); - if (!_sdmmc_storage_set_blocklen(storage, SD_BLOCKSIZE)) - return 0; + if (_sdmmc_storage_set_blocklen(storage, SD_BLOCKSIZE)) + return 1; DPRINTF("[SD] set blocklen to SD_BLOCKSIZE\n"); // Disconnect Card Detect resistor from DAT3. - if (!_sd_storage_execute_app_cmd_type1(storage, &tmp, SD_APP_SET_CLR_CARD_DETECT, 0, 0, R1_STATE_TRAN)) - return 0; + if (_sd_storage_execute_app_cmd_type1(storage, &tmp, SD_APP_SET_CLR_CARD_DETECT, 0, 0, R1_STATE_TRAN)) + return 1; DPRINTF("[SD] cleared card detect\n"); - if (!sd_storage_get_scr(storage, buf)) - return 0; + if (sd_storage_get_scr(storage)) + return 1; DPRINTF("[SD] got scr\n"); // If card supports a wider bus and if it's not SD Version 1.0 switch bus width. if (bus_width == SDMMC_BUS_WIDTH_4 && (storage->scr.bus_widths & BIT(SD_BUS_WIDTH_4)) && storage->scr.sda_vsn) { - if (!_sd_storage_execute_app_cmd_type1(storage, &tmp, SD_APP_SET_BUS_WIDTH, SD_BUS_WIDTH_4, 0, R1_STATE_TRAN)) - return 0; + if (_sd_storage_execute_app_cmd_type1(storage, &tmp, SD_APP_SET_BUS_WIDTH, SD_BUS_WIDTH_4, 0, R1_STATE_TRAN)) + return 1; sdmmc_set_bus_width(storage->sdmmc, SDMMC_BUS_WIDTH_4); DPRINTF("[SD] switched to wide bus width\n"); @@ -1882,14 +1892,14 @@ int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_widt if (storage->is_low_voltage) { - if (!_sd_storage_enable_uhs_low_volt(storage, type, buf)) - return 0; + if (_sd_storage_enable_uhs_low_volt(storage, type)) + return 1; DPRINTF("[SD] enabled UHS\n"); } else if (type != SDHCI_TIMING_SD_DS12 && storage->scr.sda_vsn) // Not default speed and not SD Version 1.0. { - if (!_sd_storage_enable_hs_high_volt(storage, buf)) - return 0; + if (_sd_storage_enable_hs_high_volt(storage)) + return 1; DPRINTF("[SD] enabled HS\n"); switch (bus_width) @@ -1905,7 +1915,7 @@ int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_widt } // Parse additional card info from sd status. - if (sd_storage_get_ssr(storage, buf)) + if (!sd_storage_get_ssr(storage)) { DPRINTF("[SD] got sd status\n"); } @@ -1914,7 +1924,7 @@ int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_widt storage->initialized = 1; - return 1; + return 0; } /* @@ -1935,16 +1945,16 @@ int _gc_storage_custom_cmd(sdmmc_storage_t *storage, void *buf) reqbuf.is_multi_block = 0; reqbuf.is_auto_stop_trn = 0; - if (!sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) { sdmmc_stop_transmission(storage->sdmmc, &resp); - return 0; + return 1; } - if (!sdmmc_get_cached_rsp(storage->sdmmc, &resp, SDMMC_RSP_TYPE_1)) - return 0; - if (!_sdmmc_storage_check_card_status(resp)) - return 0; + if (sdmmc_get_cached_rsp(storage->sdmmc, &resp, SDMMC_RSP_TYPE_1)) + return 1; + if (_sdmmc_storage_check_card_status(resp)) + return 1; return _sdmmc_storage_check_status(storage); } @@ -1953,20 +1963,20 @@ int sdmmc_storage_init_gc(sdmmc_storage_t *storage, sdmmc_t *sdmmc) memset(storage, 0, sizeof(sdmmc_storage_t)); storage->sdmmc = sdmmc; - if (!sdmmc_init(sdmmc, SDMMC_2, SDMMC_POWER_1_8, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS100)) - return 0; + if (sdmmc_init(sdmmc, SDMMC_2, SDMMC_POWER_1_8, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS100)) + return 1; DPRINTF("[GC] after init\n"); // Wait 1ms + 10 clock cycles. usleep(1000 + (10 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); - if (!sdmmc_tuning_execute(storage->sdmmc, SDHCI_TIMING_MMC_HS100, MMC_SEND_TUNING_BLOCK_HS200)) - return 0; + if (sdmmc_tuning_execute(storage->sdmmc, SDHCI_TIMING_MMC_HS100, MMC_SEND_TUNING_BLOCK_HS200)) + return 1; DPRINTF("[GC] after tuning\n"); sdmmc_card_clock_powersave(sdmmc, SDMMC_POWER_SAVE_ENABLE); storage->initialized = 1; - return 1; + return 0; } diff --git a/bdk/storage/sdmmc.h b/bdk/storage/sdmmc.h index e1b3fcda..cb8c6d76 100644 --- a/bdk/storage/sdmmc.h +++ b/bdk/storage/sdmmc.h @@ -143,9 +143,8 @@ typedef struct _mmc_csd typedef struct _mmc_ext_csd { - //u8 bkops; /* background support bit */ - //u8 bkops_en; /* manual bkops enable bit */ - //u8 bkops_status; /* 246 */ + u8 bkops; /* background support bit */ + u8 bkops_en; /* manual bkops enable bit */ u8 rev; u8 ext_struct; /* 194 */ u8 card_type; /* 196 */ @@ -193,6 +192,7 @@ typedef struct _sd_ext_reg_t typedef struct _sdmmc_storage_t { sdmmc_t *sdmmc; + int initialized; int is_low_voltage; int has_sector_access; @@ -200,10 +200,11 @@ typedef struct _sdmmc_storage_t u32 sec_cnt; u32 partition; u32 max_power; - u8 raw_cid[0x10]; - u8 raw_csd[0x10]; - u8 raw_scr[8]; - u8 raw_ssr[0x40]; + u8 raw_cid[0x10] __attribute__((aligned(SDMMC_ADMA_ADDR_ALIGN))); + u8 raw_csd[0x10] __attribute__((aligned(SDMMC_ADMA_ADDR_ALIGN))); + u8 raw_scr[8] __attribute__((aligned(SDMMC_ADMA_ADDR_ALIGN))); + u8 raw_ssr[SDMMC_CMD_BLOCKSIZE] __attribute__((aligned(SDMMC_ADMA_ADDR_ALIGN))); + u8 raw_ext_csd[SDMMC_DAT_BLOCKSIZE] __attribute__((aligned(SDMMC_ADMA_ADDR_ALIGN))); mmc_cid_t cid; mmc_csd_t csd; mmc_ext_csd_t ext_csd; @@ -232,12 +233,12 @@ int sdmmc_storage_init_gc(sdmmc_storage_t *storage, sdmmc_t *sdmmc); int sdmmc_storage_execute_vendor_cmd(sdmmc_storage_t *storage, u32 arg); int sdmmc_storage_vendor_sandisk_report(sdmmc_storage_t *storage, void *buf); -int mmc_storage_get_ext_csd(sdmmc_storage_t *storage, void *buf); +int mmc_storage_get_ext_csd(sdmmc_storage_t *storage); int sd_storage_get_ext_reg(sdmmc_storage_t *storage, u8 fno, u8 page, u16 offset, u32 len, void *buf); int sd_storage_get_fmodes(sdmmc_storage_t *storage, u8 *buf, sd_func_modes_t *functions); -int sd_storage_get_scr(sdmmc_storage_t *storage, u8 *buf); -int sd_storage_get_ssr(sdmmc_storage_t *storage, u8 *buf); +int sd_storage_get_scr(sdmmc_storage_t *storage); +int sd_storage_get_ssr(sdmmc_storage_t *storage); u32 sd_storage_get_ssr_au(sdmmc_storage_t *storage); void sd_storage_get_ext_regs(sdmmc_storage_t *storage, u8 *buf); diff --git a/bdk/storage/sdmmc_driver.c b/bdk/storage/sdmmc_driver.c index c279ec86..d6bd4fc0 100644 --- a/bdk/storage/sdmmc_driver.c +++ b/bdk/storage/sdmmc_driver.c @@ -70,13 +70,13 @@ static int _sdmmc_set_io_power(sdmmc_t *sdmmc, u32 power) break; default: - return 0; + return 1; } if (power != SDMMC_POWER_OFF) sdmmc->regs->pwrcon |= SDHCI_POWER_ON; - return 1; + return 0; } u32 sdmmc_get_bus_width(sdmmc_t *sdmmc) @@ -121,8 +121,9 @@ static int _sdmmc_config_tap_val(sdmmc_t *sdmmc, u32 type) if (type == SDHCI_TIMING_MMC_HS400) { + // Tap is saved during HS200 switch. if (!sdmmc->venclkctl_set) - return 0; + return 1; tap_val = sdmmc->venclkctl_tap; } @@ -131,7 +132,7 @@ static int _sdmmc_config_tap_val(sdmmc_t *sdmmc, u32 type) sdmmc->regs->venclkctl = (sdmmc->regs->venclkctl & ~0xFF0000) | (tap_val << 16); - return 1; + return 0; } static void _sdmmc_commit_changes(sdmmc_t *sdmmc) @@ -236,7 +237,7 @@ static void _sdmmc_autocal_execute(sdmmc_t *sdmmc, u32 power) static int _sdmmc_dll_cal_execute(sdmmc_t *sdmmc) { - int result = 1, should_disable_sd_clock = 0; + int res = 0, should_disable_sd_clock = 0; if (!(sdmmc->regs->clkcon & SDHCI_CLOCK_CARD_EN)) { @@ -256,7 +257,7 @@ static int _sdmmc_dll_cal_execute(sdmmc_t *sdmmc) { if (get_tmr_ms() > timeout) { - result = 0; + res = 1; goto out; } } @@ -266,15 +267,16 @@ static int _sdmmc_dll_cal_execute(sdmmc_t *sdmmc) { if (get_tmr_ms() > timeout) { - result = 0; + res = 1; goto out; } } -out:; +out: if (should_disable_sd_clock) sdmmc->regs->clkcon &= ~SDHCI_CLOCK_CARD_EN; - return result; + + return res; } static void _sdmmc_reset_cmd_data(sdmmc_t *sdmmc) @@ -389,7 +391,7 @@ int sdmmc_setup_clock(sdmmc_t *sdmmc, u32 type) if (type == SDHCI_TIMING_MMC_HS400) return _sdmmc_dll_cal_execute(sdmmc); - return 1; + return 0; } static void _sdmmc_card_clock_enable(sdmmc_t *sdmmc) @@ -455,16 +457,16 @@ static int _sdmmc_cache_rsp(sdmmc_t *sdmmc, u32 *rsp, u32 type) break; default: - return 0; + return 1; } - return 1; + return 0; } int sdmmc_get_cached_rsp(sdmmc_t *sdmmc, u32 *rsp, u32 type) { - if (!rsp || sdmmc->expected_rsp_type != type) - return 0; + if (sdmmc->expected_rsp_type != type) + return 1; switch (type) { @@ -481,10 +483,10 @@ int sdmmc_get_cached_rsp(sdmmc_t *sdmmc, u32 *rsp, u32 type) break; default: - return 0; + return 1; } - return 1; + return 0; } static int _sdmmc_wait_cmd_data_inhibit(sdmmc_t *sdmmc, bool wait_dat) @@ -496,7 +498,7 @@ static int _sdmmc_wait_cmd_data_inhibit(sdmmc_t *sdmmc, bool wait_dat) if (get_tmr_ms() > timeout) { _sdmmc_reset_cmd_data(sdmmc); - return 0; + return 1; } if (wait_dat) @@ -506,11 +508,11 @@ static int _sdmmc_wait_cmd_data_inhibit(sdmmc_t *sdmmc, bool wait_dat) if (get_tmr_ms() > timeout) { _sdmmc_reset_cmd_data(sdmmc); - return 0; + return 1; } } - return 1; + return 0; } static int _sdmmc_wait_card_busy(sdmmc_t *sdmmc) @@ -522,10 +524,10 @@ static int _sdmmc_wait_card_busy(sdmmc_t *sdmmc) if (get_tmr_ms() > timeout) { _sdmmc_reset_cmd_data(sdmmc); - return 0; + return 1; } - return 1; + return 0; } static int _sdmmc_setup_read_small_block(sdmmc_t *sdmmc) @@ -533,7 +535,7 @@ static int _sdmmc_setup_read_small_block(sdmmc_t *sdmmc) switch (sdmmc_get_bus_width(sdmmc)) { case SDMMC_BUS_WIDTH_1: - return 0; + return 1; case SDMMC_BUS_WIDTH_4: sdmmc->regs->blksize = 64; @@ -547,7 +549,7 @@ static int _sdmmc_setup_read_small_block(sdmmc_t *sdmmc) sdmmc->regs->blkcnt = 1; sdmmc->regs->trnmod = SDHCI_TRNS_READ; - return 1; + return 0; } static int _sdmmc_send_cmd(sdmmc_t *sdmmc, const sdmmc_cmd_t *cmd, bool is_data_present) @@ -577,7 +579,7 @@ static int _sdmmc_send_cmd(sdmmc_t *sdmmc, const sdmmc_cmd_t *cmd, bool is_data_ break; default: - return 0; + return 1; } if (is_data_present) @@ -586,7 +588,7 @@ static int _sdmmc_send_cmd(sdmmc_t *sdmmc, const sdmmc_cmd_t *cmd, bool is_data_ sdmmc->regs->argument = cmd->arg; sdmmc->regs->cmdreg = SDHCI_CMD_IDX(cmd->cmd) | cmdflags; - return 1; + return 0; } static void _sdmmc_send_tuning_cmd(sdmmc_t *sdmmc, u32 cmd) @@ -601,8 +603,8 @@ static void _sdmmc_send_tuning_cmd(sdmmc_t *sdmmc, u32 cmd) static int _sdmmc_tuning_execute_once(sdmmc_t *sdmmc, u32 cmd, u32 tap) { - if (!_sdmmc_wait_cmd_data_inhibit(sdmmc, true)) - return 0; + if (_sdmmc_wait_cmd_data_inhibit(sdmmc, true)) + return 1; _sdmmc_setup_read_small_block(sdmmc); @@ -612,7 +614,7 @@ static int _sdmmc_tuning_execute_once(sdmmc_t *sdmmc, u32 cmd, u32 tap) #ifdef BDK_SDMMC_UHS_DDR200_SUPPORT // Set tap if manual tuning. - if (tap != HW_TAP_TUNING) + if (tap != SDMMC_HW_TAP_TUNING) { sdmmc->regs->ventunctl0 &= ~SDHCI_TEGRA_TUNING_TAP_HW_UPDATED; sdmmc->regs->venclkctl = (sdmmc->regs->venclkctl & 0xFF00FFFF) | (tap << 16); @@ -632,13 +634,15 @@ static int _sdmmc_tuning_execute_once(sdmmc_t *sdmmc, u32 cmd, u32 tap) u32 timeout = get_tmr_us() + 5000; while (get_tmr_us() < timeout) { + // Check if we got valid data. if (sdmmc->regs->norintsts & SDHCI_INT_DATA_AVAIL) { sdmmc->regs->norintsts = SDHCI_INT_DATA_AVAIL; sdmmc->regs->norintstsen &= ~SDHCI_INT_DATA_AVAIL; _sdmmc_commit_changes(sdmmc); usleep((8 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); // Wait 8 cycles. - return 1; + + return 0; } } @@ -648,7 +652,7 @@ static int _sdmmc_tuning_execute_once(sdmmc_t *sdmmc, u32 cmd, u32 tap) _sdmmc_commit_changes(sdmmc); usleep((8 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); // Wait 8 cycles. - return 0; + return 1; } #ifdef BDK_SDMMC_UHS_DDR200_SUPPORT @@ -662,7 +666,7 @@ typedef struct _sdmmc_manual_tuning_t static int _sdmmc_manual_tuning_set_tap(sdmmc_t *sdmmc, sdmmc_manual_tuning_t *tuning) { - u32 tap_start = INVALID_TAP; + u32 tap_start = SDMMC_INVALID_TAP; u32 win_size = 0; u32 best_tap = 0; u32 best_size = 0; @@ -673,14 +677,14 @@ static int _sdmmc_manual_tuning_set_tap(sdmmc_t *sdmmc, sdmmc_manual_tuning_t *t u32 stable = tuning->result[i / 32] & BIT(i % 32); if (stable && !iter_end) { - if (tap_start == INVALID_TAP) + if (tap_start == SDMMC_INVALID_TAP) tap_start = i; win_size++; } else { - if (tap_start != INVALID_TAP) + if (tap_start != SDMMC_INVALID_TAP) { u32 tap_end = !iter_end ? (i - 1) : i; @@ -691,7 +695,7 @@ static int _sdmmc_manual_tuning_set_tap(sdmmc_t *sdmmc, sdmmc_manual_tuning_t *t best_size = win_size + iter_end; } - tap_start = INVALID_TAP; + tap_start = SDMMC_INVALID_TAP; win_size = 0; } } @@ -699,8 +703,8 @@ static int _sdmmc_manual_tuning_set_tap(sdmmc_t *sdmmc, sdmmc_manual_tuning_t *t // Check if failed or window too small. - if (!best_tap || best_size < SAMPLING_WINDOW_SIZE_MIN) - return 0; + if (!best_tap || best_size < SDMMC_SAMPLE_WIN_SIZE_MIN) + return 1; sdmmc->regs->clkcon &= ~SDHCI_CLOCK_CARD_EN; sdmmc->regs->ventunctl0 &= ~SDHCI_TEGRA_TUNING_TAP_HW_UPDATED; @@ -711,7 +715,7 @@ static int _sdmmc_manual_tuning_set_tap(sdmmc_t *sdmmc, sdmmc_manual_tuning_t *t sdmmc->regs->ventunctl0 |= SDHCI_TEGRA_TUNING_TAP_HW_UPDATED; sdmmc->regs->clkcon |= SDHCI_CLOCK_CARD_EN; - return 1; + return 0; } /* @@ -758,7 +762,7 @@ int sdmmc_tuning_execute(sdmmc_t *sdmmc, u32 type, u32 cmd) u32 num_iter, flag; if (sdmmc->powersave_enabled) - return 0; + return 1; switch (type) { @@ -779,7 +783,7 @@ int sdmmc_tuning_execute(sdmmc_t *sdmmc, u32 type, u32 cmd) case SDHCI_TIMING_MMC_HS400: case SDHCI_TIMING_UHS_SDR12: case SDHCI_TIMING_UHS_SDR25: - return 1; + return 0; #ifdef BDK_SDMMC_UHS_DDR200_SUPPORT case SDHCI_TIMING_UHS_DDR200: @@ -787,7 +791,7 @@ int sdmmc_tuning_execute(sdmmc_t *sdmmc, u32 type, u32 cmd) #endif default: - return 0; + return 1; } sdmmc->regs->ventunctl1 = 0; // step_size 1. @@ -799,16 +803,16 @@ int sdmmc_tuning_execute(sdmmc_t *sdmmc, u32 type, u32 cmd) for (u32 i = 0; i < num_iter; i++) { - _sdmmc_tuning_execute_once(sdmmc, cmd, HW_TAP_TUNING); + _sdmmc_tuning_execute_once(sdmmc, cmd, SDMMC_HW_TAP_TUNING); if (!(sdmmc->regs->hostctl2 & SDHCI_CTRL_EXEC_TUNING)) break; } if (sdmmc->regs->hostctl2 & SDHCI_CTRL_TUNED_CLK) - return 1; + return 0; - return 0; + return 1; } static int _sdmmc_enable_internal_clock(sdmmc_t *sdmmc) @@ -820,7 +824,7 @@ static int _sdmmc_enable_internal_clock(sdmmc_t *sdmmc) while (!(sdmmc->regs->clkcon & SDHCI_CLOCK_INT_STABLE)) { if (get_tmr_ms() > timeout) - return 0; + return 1; } sdmmc->regs->hostctl2 &= ~SDHCI_CTRL_PRESET_VAL_EN; @@ -829,13 +833,13 @@ static int _sdmmc_enable_internal_clock(sdmmc_t *sdmmc) sdmmc->regs->hostctl2 |= SDHCI_HOST_VERSION_4_EN; if (!(sdmmc->regs->capareg & SDHCI_CAP_64BIT)) - return 0; + return 1; sdmmc->regs->hostctl2 |= SDHCI_ADDRESSING_64BIT_EN; sdmmc->regs->hostctl &= ~SDHCI_CTRL_DMA_MASK; // Use SDMA. Host V4 enabled so adma address regs in use. sdmmc->regs->timeoutcon = (sdmmc->regs->timeoutcon & 0xF0) | 14; // TMCLK * 2^27. - return 1; + return 0; } static int _sdmmc_autocal_config_offset(sdmmc_t *sdmmc, u32 power) @@ -848,7 +852,7 @@ static int _sdmmc_autocal_config_offset(sdmmc_t *sdmmc, u32 power) case SDMMC_2: case SDMMC_4: if (power != SDMMC_POWER_1_8) - return 0; + return 1; off_pd = 5; off_pu = 5; break; @@ -876,12 +880,12 @@ static int _sdmmc_autocal_config_offset(sdmmc_t *sdmmc, u32 power) } } else - return 0; + return 1; break; } sdmmc->regs->autocalcfg = (sdmmc->regs->autocalcfg & 0xFFFF8080) | (off_pd << 8) | off_pu; - return 1; + return 0; } static void _sdmmc_enable_interrupts(sdmmc_t *sdmmc) @@ -935,25 +939,25 @@ static int _sdmmc_wait_response(sdmmc_t *sdmmc) u32 timeout = get_tmr_ms() + 2000; while (true) { - u32 result = _sdmmc_check_mask_interrupt(sdmmc, NULL, SDHCI_INT_RESPONSE); - if (result == SDMMC_MASKINT_MASKED) + u32 res = _sdmmc_check_mask_interrupt(sdmmc, NULL, SDHCI_INT_RESPONSE); + if (res == SDMMC_MASKINT_MASKED) break; - if (result != SDMMC_MASKINT_NOERROR || get_tmr_ms() > timeout) + if (res != SDMMC_MASKINT_NOERROR || get_tmr_ms() > timeout) { _sdmmc_reset_cmd_data(sdmmc); - return 0; + return 1; } } - return 1; + return 0; } static int _sdmmc_stop_transmission_inner(sdmmc_t *sdmmc, u32 *rsp) { sdmmc_cmd_t cmd; - if (!_sdmmc_wait_cmd_data_inhibit(sdmmc, false)) - return 0; + if (_sdmmc_wait_cmd_data_inhibit(sdmmc, false)) + return 1; _sdmmc_enable_interrupts(sdmmc); @@ -964,11 +968,11 @@ static int _sdmmc_stop_transmission_inner(sdmmc_t *sdmmc, u32 *rsp) _sdmmc_send_cmd(sdmmc, &cmd, false); - int result = _sdmmc_wait_response(sdmmc); + int res = _sdmmc_wait_response(sdmmc); _sdmmc_mask_interrupts(sdmmc); - if (!result) - return 0; + if (res) + return 1; _sdmmc_cache_rsp(sdmmc, rsp, SDMMC_RSP_TYPE_1); @@ -978,7 +982,7 @@ static int _sdmmc_stop_transmission_inner(sdmmc_t *sdmmc, u32 *rsp) int sdmmc_stop_transmission(sdmmc_t *sdmmc, u32 *rsp) { if (!sdmmc->card_clock_enabled) - return 0; + return 1; // Recalibrate periodically if needed. if (sdmmc->periodic_calibration && sdmmc->powersave_enabled) @@ -993,35 +997,35 @@ int sdmmc_stop_transmission(sdmmc_t *sdmmc, u32 *rsp) usleep((8 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); // Wait 8 cycles. } - int result = _sdmmc_stop_transmission_inner(sdmmc, rsp); + int res = _sdmmc_stop_transmission_inner(sdmmc, rsp); usleep((8 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); // Wait 8 cycles. if (should_disable_sd_clock) sdmmc->regs->clkcon &= ~SDHCI_CLOCK_CARD_EN; - return result; + return res; } -static int _sdmmc_config_sdma(sdmmc_t *sdmmc, u32 *blkcnt_out, const sdmmc_req_t *req) +static int _sdmmc_config_sdma(sdmmc_t *sdmmc, u32 *blkcnt_out, const sdmmc_req_t *request) { - if (!req->blksize || !req->num_sectors) - return 0; + if (!request->blksize || !request->num_sectors) + return 1; - u32 blkcnt = req->num_sectors; + u32 blkcnt = request->num_sectors; if (blkcnt >= SDMMC_HMAX_BLOCKNUM) blkcnt = SDMMC_HMAX_BLOCKNUM; - u32 admaaddr = (u32)req->buf; + u32 admaaddr = (u32)request->buf; // Check alignment. if (admaaddr & 7) - return 0; + return 1; sdmmc->regs->admaaddr = admaaddr; sdmmc->regs->admaaddr_hi = 0; sdmmc->dma_addr_next = ALIGN_DOWN((admaaddr + SZ_512K), SZ_512K); - sdmmc->regs->blksize = req->blksize | (7u << 12); // SDMA DMA 512KB Boundary (Detects A18 carry out). + sdmmc->regs->blksize = request->blksize | (7u << 12); // SDMA DMA 512KB Boundary (Detects A18 carry out). sdmmc->regs->blkcnt = blkcnt; if (blkcnt_out) @@ -1030,22 +1034,22 @@ static int _sdmmc_config_sdma(sdmmc_t *sdmmc, u32 *blkcnt_out, const sdmmc_req_t u32 trnmode = SDHCI_TRNS_DMA | SDHCI_TRNS_RTYPE_R1; // Set multiblock request. - if (req->is_multi_block) + if (request->is_multi_block) trnmode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_BLK_CNT_EN; // Set request direction. - if (!req->is_write) + if (!request->is_write) trnmode |= SDHCI_TRNS_READ; // Automatic send of stop transmission or set block count cmd. - if (req->is_auto_stop_trn) + if (request->is_auto_stop_trn) trnmode |= SDHCI_TRNS_AUTO_CMD12; - //else if (req->is_auto_set_blkcnt) + //else if (request->is_auto_set_blkcnt) // trnmode |= SDHCI_TRNS_AUTO_CMD23; sdmmc->regs->trnmod = trnmode; - return 1; + return 0; } static int _sdmmc_update_sdma(sdmmc_t *sdmmc) @@ -1057,17 +1061,17 @@ static int _sdmmc_update_sdma(sdmmc_t *sdmmc) u32 timeout = get_tmr_ms() + 1500; do { - u32 result = SDMMC_MASKINT_MASKED; + u32 res = SDMMC_MASKINT_MASKED; while (true) { u16 intr = 0; - result = _sdmmc_check_mask_interrupt(sdmmc, &intr, + res = _sdmmc_check_mask_interrupt(sdmmc, &intr, SDHCI_INT_DATA_END | SDHCI_INT_DMA_END); - if (result != SDMMC_MASKINT_MASKED) + if (res != SDMMC_MASKINT_MASKED) break; if (intr & SDHCI_INT_DATA_END) - return 1; // Transfer complete. + return 0; // Transfer complete. if (intr & SDHCI_INT_DMA_END) { @@ -1078,39 +1082,39 @@ static int _sdmmc_update_sdma(sdmmc_t *sdmmc) } } - if (result != SDMMC_MASKINT_NOERROR) + if (res != SDMMC_MASKINT_NOERROR) { #ifdef ERROR_EXTRA_PRINTING EPRINTFARGS("SDMMC%d: int error!", sdmmc->id + 1); #endif _sdmmc_reset_cmd_data(sdmmc); - return 0; + return 1; } } while (get_tmr_ms() < timeout); } while (sdmmc->regs->blkcnt != blkcnt); _sdmmc_reset_cmd_data(sdmmc); - return 0; + return 1; } -static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *blkcnt_out) +static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *request, u32 *blkcnt_out) { - bool has_req_or_check_busy = req || cmd->check_busy; - if (!_sdmmc_wait_cmd_data_inhibit(sdmmc, has_req_or_check_busy)) - return 0; + bool has_req_or_check_busy = request || cmd->check_busy; + if (_sdmmc_wait_cmd_data_inhibit(sdmmc, has_req_or_check_busy)) + return 1; u32 blkcnt = 0; bool is_data_present = false; - if (req) + if (request) { - if (!_sdmmc_config_sdma(sdmmc, &blkcnt, req)) + if (_sdmmc_config_sdma(sdmmc, &blkcnt, request)) { #ifdef ERROR_EXTRA_PRINTING EPRINTFARGS("SDMMC%d: DMA Wrong cfg!", sdmmc->id + 1); #endif - return 0; + return 1; } // Flush cache before starting the transfer. @@ -1121,37 +1125,34 @@ static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_ _sdmmc_enable_interrupts(sdmmc); - if (!_sdmmc_send_cmd(sdmmc, cmd, is_data_present)) + if (_sdmmc_send_cmd(sdmmc, cmd, is_data_present)) { #ifdef ERROR_EXTRA_PRINTING EPRINTFARGS("SDMMC%d: Wrong Response type %08X!", sdmmc->id + 1, cmd->rsp_type); #endif - return 0; + return 1; } - int result = _sdmmc_wait_response(sdmmc); + int res = _sdmmc_wait_response(sdmmc); #ifdef ERROR_EXTRA_PRINTING - if (!result) + if (res) EPRINTFARGS("SDMMC%d: Transfer error!", sdmmc->id + 1); #endif - DPRINTF("rsp(%d): %08X, %08X, %08X, %08X\n", result, + DPRINTF("rsp(%d): %08X, %08X, %08X, %08X\n", res, sdmmc->regs->rspreg[0], sdmmc->regs->rspreg[1], sdmmc->regs->rspreg[2], sdmmc->regs->rspreg[3]); - if (result) + + if (!res) { if (cmd->rsp_type) { sdmmc->expected_rsp_type = cmd->rsp_type; - result = _sdmmc_cache_rsp(sdmmc, sdmmc->rsp, cmd->rsp_type); -#ifdef ERROR_EXTRA_PRINTING - if (!result) - EPRINTFARGS("SDMMC%d: Unknown response type!", sdmmc->id + 1); -#endif + res = _sdmmc_cache_rsp(sdmmc, sdmmc->rsp, cmd->rsp_type); } - if (req && result) + if (request && !res) { - result = _sdmmc_update_sdma(sdmmc); + res = _sdmmc_update_sdma(sdmmc); #ifdef ERROR_EXTRA_PRINTING - if (!result) + if (res) EPRINTFARGS("SDMMC%d: DMA Update failed!", sdmmc->id + 1); #endif } @@ -1159,9 +1160,9 @@ static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_ _sdmmc_mask_interrupts(sdmmc); - if (result) + if (!res) { - if (req) + if (request) { // Invalidate cache after transfer. bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); @@ -1169,22 +1170,21 @@ static int _sdmmc_execute_cmd_inner(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_ if (blkcnt_out) *blkcnt_out = blkcnt; - if (req->is_auto_stop_trn) + if (request->is_auto_stop_trn) sdmmc->stop_trn_rsp = sdmmc->regs->rspreg[3]; } if (has_req_or_check_busy) { - result = _sdmmc_wait_card_busy(sdmmc); + res = _sdmmc_wait_card_busy(sdmmc); #ifdef ERROR_EXTRA_PRINTING - if (!result) + if (res) EPRINTFARGS("SDMMC%d: Busy timeout!", sdmmc->id + 1); #endif - return result; } } - return result; + return res; } bool sdmmc_get_sd_inserted() @@ -1251,7 +1251,7 @@ static int _sdmmc_config_sdmmc1(bool t210b01) // Check if SD card is inserted. if (!sdmmc_get_sd_inserted()) - return 0; + return 1; // Enable deep loopback for SDMMC1 CLK pad so reads work. APB_MISC(APB_MISC_GP_SDMMC1_CLK_LPBK_CONTROL) = 1; @@ -1300,7 +1300,7 @@ static int _sdmmc_config_sdmmc1(bool t210b01) usleep(1000); } - return 1; + return 0; } static void _sdmmc_config_emmc(u32 id, bool t210b01) @@ -1342,7 +1342,7 @@ int sdmmc_init(sdmmc_t *sdmmc, u32 id, u32 power, u32 bus_width, u32 type) const u8 *trim_values; if (id > SDMMC_4 || id == SDMMC_3) - return 0; + return 1; memset(sdmmc, 0, sizeof(sdmmc_t)); @@ -1357,8 +1357,8 @@ int sdmmc_init(sdmmc_t *sdmmc, u32 id, u32 power, u32 bus_width, u32 type) switch (id) { case SDMMC_1: - if (!_sdmmc_config_sdmmc1(sdmmc->t210b01)) - return 0; + if (_sdmmc_config_sdmmc1(sdmmc->t210b01)) + return 1; if (sdmmc->t210b01) vref_sel = 0; else @@ -1393,8 +1393,8 @@ int sdmmc_init(sdmmc_t *sdmmc, u32 id, u32 power, u32 bus_width, u32 type) sdmmc->regs->sdmemcmppadctl = (sdmmc->regs->sdmemcmppadctl & ~SDHCI_TEGRA_PADCTRL_VREF_SEL_MASK) | vref_sel; // Configure auto calibration values. - if (!_sdmmc_autocal_config_offset(sdmmc, power)) - return 0; + if (_sdmmc_autocal_config_offset(sdmmc, power)) + return 1; _sdmmc_commit_changes(sdmmc); @@ -1402,22 +1402,23 @@ int sdmmc_init(sdmmc_t *sdmmc, u32 id, u32 power, u32 bus_width, u32 type) _sdmmc_autocal_execute(sdmmc, power); // Enable internal clock and power. - if (_sdmmc_enable_internal_clock(sdmmc)) + if (!_sdmmc_enable_internal_clock(sdmmc)) { sdmmc_set_bus_width(sdmmc, bus_width); _sdmmc_set_io_power(sdmmc, power); - if (sdmmc_setup_clock(sdmmc, type)) + if (!sdmmc_setup_clock(sdmmc, type)) { sdmmc_card_clock_powersave(sdmmc, SDMMC_POWER_SAVE_DISABLE); _sdmmc_card_clock_enable(sdmmc); _sdmmc_commit_changes(sdmmc); - return 1; + return 0; } } - return 0; + // Failed to enable clock. + return 1; } void sdmmc1_disable_power() @@ -1480,10 +1481,10 @@ void sdmmc_init_cmd(sdmmc_cmd_t *cmdbuf, u16 cmd, u32 arg, u32 rsp_type, u32 che cmdbuf->check_busy = check_busy; } -int sdmmc_execute_cmd(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *blkcnt_out) +int sdmmc_execute_cmd(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *request, u32 *blkcnt_out) { if (!sdmmc->card_clock_enabled) - return 0; + return 1; // Recalibrate periodically if needed. if (sdmmc->periodic_calibration && sdmmc->powersave_enabled) @@ -1498,19 +1499,19 @@ int sdmmc_execute_cmd(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *b usleep((8 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); // Wait 8 cycles. } - int result = _sdmmc_execute_cmd_inner(sdmmc, cmd, req, blkcnt_out); + int res = _sdmmc_execute_cmd_inner(sdmmc, cmd, request, blkcnt_out); usleep((8 * 1000 + sdmmc->card_clock - 1) / sdmmc->card_clock); // Wait 8 cycles. if (should_disable_sd_clock) sdmmc->regs->clkcon &= ~SDHCI_CLOCK_CARD_EN; - return result; + return res; } int sdmmc_enable_low_voltage(sdmmc_t *sdmmc) { if (sdmmc->id != SDMMC_1) - return 0; + return 1; _sdmmc_commit_changes(sdmmc); @@ -1538,8 +1539,8 @@ int sdmmc_enable_low_voltage(sdmmc_t *sdmmc) _sdmmc_commit_changes(sdmmc); usleep(1000); if ((sdmmc->regs->prnsts & SDHCI_DATA_LVL_MASK) == SDHCI_DATA_LVL_MASK) - return 1; + return 0; } - return 0; + return 1; } diff --git a/bdk/storage/sdmmc_driver.h b/bdk/storage/sdmmc_driver.h index 1ce5ffb8..b7a9d2bb 100644 --- a/bdk/storage/sdmmc_driver.h +++ b/bdk/storage/sdmmc_driver.h @@ -274,9 +274,11 @@ /*! Helper for SWITCH command argument. */ #define SDMMC_SWITCH(mode, index, value) (((mode) << 24) | ((index) << 16) | ((value) << 8)) -#define HW_TAP_TUNING 0x100 -#define INVALID_TAP 0x100 -#define SAMPLING_WINDOW_SIZE_MIN 8 +#define SDMMC_HW_TAP_TUNING 0x100 +#define SDMMC_INVALID_TAP 0x100 +#define SDMMC_SAMPLE_WIN_SIZE_MIN 8 + +#define SDMMC_ADMA_ADDR_ALIGN 8 /*! SDMMC controller context. */ typedef struct _sdmmc_t @@ -332,7 +334,7 @@ bool sdmmc_get_sd_inserted(); int sdmmc_init(sdmmc_t *sdmmc, u32 id, u32 power, u32 bus_width, u32 type); void sdmmc_end(sdmmc_t *sdmmc); void sdmmc_init_cmd(sdmmc_cmd_t *cmdbuf, u16 cmd, u32 arg, u32 rsp_type, u32 check_busy); -int sdmmc_execute_cmd(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *req, u32 *blkcnt_out); +int sdmmc_execute_cmd(sdmmc_t *sdmmc, sdmmc_cmd_t *cmd, sdmmc_req_t *request, u32 *blkcnt_out); int sdmmc_enable_low_voltage(sdmmc_t *sdmmc); #endif diff --git a/bdk/usb/usb_gadget_hid.c b/bdk/usb/usb_gadget_hid.c index 66c8eef2..b0604913 100644 --- a/bdk/usb/usb_gadget_hid.c +++ b/bdk/usb/usb_gadget_hid.c @@ -1,7 +1,7 @@ /* * USB Gadget HID driver for Tegra X1 * - * Copyright (c) 2019-2025 CTCaer + * Copyright (c) 2019-2026 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, @@ -315,33 +315,30 @@ typedef struct _touchpad_report_t static bool _fts_touch_read(touchpad_report_t *rpt) { - static touch_event touchpad; + static touch_event_t touchpad; - touch_poll(&touchpad); + if (touch_poll(&touchpad)) + return false; rpt->rpt_id = 5; rpt->count = 1; // Decide touch enable. - switch (touchpad.type & STMFTS_MASK_EVENT_ID) + if (touchpad.touch) { - //case STMFTS_EV_MULTI_TOUCH_ENTER: - case STMFTS_EV_MULTI_TOUCH_MOTION: rpt->x = touchpad.x; rpt->y = touchpad.y; //rpt->z = touchpad.z; - rpt->id = touchpad.fingers ? touchpad.fingers - 1 : 0; + rpt->id = touchpad.finger; rpt->tip_switch = 1; - break; - case STMFTS_EV_MULTI_TOUCH_LEAVE: + } + else + { rpt->x = touchpad.x; rpt->y = touchpad.y; //rpt->z = touchpad.z; - rpt->id = touchpad.fingers ? touchpad.fingers - 1 : 0; + rpt->id = touchpad.finger; rpt->tip_switch = 0; - break; - case STMFTS_EV_NO_EVENT: - return false; } return true; diff --git a/bdk/usb/usb_gadget_ums.c b/bdk/usb/usb_gadget_ums.c index 4b06ed67..a97e9c65 100644 --- a/bdk/usb/usb_gadget_ums.c +++ b/bdk/usb/usb_gadget_ums.c @@ -495,7 +495,7 @@ static int _scsi_read(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt) } // Do the SDMMC read. - if (!sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, sdmmc_buf)) + if (sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, sdmmc_buf)) amount = 0; // Wait for the async USB transfer to finish. @@ -650,7 +650,7 @@ static int _scsi_write(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt) goto empty_write; // Perform the write. - if (!sdmmc_storage_write(ums->lun.storage, ums->lun.offset + lba_offset, + if (sdmmc_storage_write(ums->lun.storage, ums->lun.offset + lba_offset, amount >> UMS_DISK_LBA_SHIFT, (u8 *)bulk_ctxt->bulk_out_buf)) amount = 0; @@ -722,7 +722,7 @@ static int _scsi_verify(usbd_gadget_ums_t *ums, bulk_ctxt_t *bulk_ctxt) break; } - if (!sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, bulk_ctxt->bulk_in_buf)) + if (sdmmc_storage_read(ums->lun.storage, ums->lun.offset + lba_offset, amount, bulk_ctxt->bulk_in_buf)) amount = 0; DPRINTF("File read %X @ %X\n", amount, lba_offset); @@ -1861,7 +1861,7 @@ int usb_device_gadget_ums(usb_ctxt_t *usbs) if (usbs->type == MMC_SD) { sd_end(); - if (!sd_mount()) + if (sd_mount()) { ums.set_text(ums.label, "#FFDD00 Failed to init SD!#"); res = 1; @@ -1874,7 +1874,7 @@ int usb_device_gadget_ums(usb_ctxt_t *usbs) } else { - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { ums.set_text(ums.label, "#FFDD00 Failed to init eMMC!#"); res = 1; diff --git a/bdk/usb/xusbd.c b/bdk/usb/xusbd.c index a4a47e60..bb8eeebf 100644 --- a/bdk/usb/xusbd.c +++ b/bdk/usb/xusbd.c @@ -931,7 +931,7 @@ int xusb_device_init() bpmp_clk_rate_relaxed(false); // Enable AHB redirect for access to IRAM for Event/EP ring buffers. - mc_enable_ahb_redirect(); + mc_enable_ahb_redirect(1); // Enable XUSB device IPFS. XUSB_DEV_DEV(XUSB_DEV_CONFIGURATION) |= DEV_CONFIGURATION_EN_FPCI; diff --git a/bdk/utils/dirlist.h b/bdk/utils/dirlist.h index cf702469..daec60a5 100644 --- a/bdk/utils/dirlist.h +++ b/bdk/utils/dirlist.h @@ -16,6 +16,9 @@ #include +#ifndef _DIRLIST_H_ +#define _DIRLIST_H_ + #define DIR_MAX_ENTRIES 64 #define DIR_SHOW_HIDDEN BIT(0) @@ -29,3 +32,5 @@ typedef struct _dirlist_t } dirlist_t; dirlist_t *dirlist(const char *directory, const char *pattern, u32 flags); + +#endif diff --git a/bdk/utils/ini.c b/bdk/utils/ini.c index b5a2df8a..54345b1b 100644 --- a/bdk/utils/ini.c +++ b/bdk/utils/ini.c @@ -74,7 +74,7 @@ int ini_parse(link_t *dst, const char *ini_path, bool is_dir) if (!filelist) { free(filename); - return 0; + return 1; } strcpy(filename + pathlen, "/"); pathlen++; @@ -100,7 +100,7 @@ int ini_parse(link_t *dst, const char *ini_path, bool is_dir) free(filelist); free(filename); - return 0; + return 1; } lbuf = malloc(512); @@ -170,7 +170,7 @@ int ini_parse(link_t *dst, const char *ini_path, bool is_dir) free(filename); free(filelist); - return 1; + return 0; } char *ini_check_special_section(ini_sec_t *cfg) diff --git a/bootloader/frontend/fe_info.c b/bootloader/frontend/fe_info.c index db1182af..546ba459 100644 --- a/bootloader/frontend/fe_info.c +++ b/bootloader/frontend/fe_info.c @@ -65,7 +65,7 @@ void print_mmc_info() static const u32 SECTORS_TO_MIB_COEFF = 11; - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { EPRINTF("Failed to init eMMC."); goto out; @@ -194,7 +194,7 @@ void print_sdcard_info() gfx_clear_partial_grey(0x1B, 0, 1256); gfx_con_setpos(0, 0); - if (sd_initialize(false)) + if (!sd_initialize(false)) { gfx_printf("%kCard IDentification:%k\n", TXT_CLR_CYAN_L, TXT_CLR_DEFAULT); gfx_printf( diff --git a/bootloader/frontend/fe_tools.c b/bootloader/frontend/fe_tools.c index 8c2231d8..9f72ac93 100644 --- a/bootloader/frontend/fe_tools.c +++ b/bootloader/frontend/fe_tools.c @@ -110,7 +110,7 @@ void menu_autorcm() return; } - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { EPRINTF("Failed to init eMMC."); btn_wait(); diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index 588be8db..c7344898 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -72,6 +72,7 @@ static const u8 master_kekseed_t210_tsec_v4[HOS_MKEY_VER_MAX - HOS_MKEY_VER_810 { 0xD7, 0x63, 0x74, 0x46, 0x4E, 0xBA, 0x78, 0x0A, 0x7C, 0x9D, 0xB3, 0xE8, 0x7A, 0x3D, 0x71, 0xE3 }, // 19.0.0. { 0xA1, 0x7D, 0x34, 0xDB, 0x2D, 0x9D, 0xDA, 0xE5, 0xF8, 0x15, 0x63, 0x4C, 0x8F, 0xE7, 0x6C, 0xD8 }, // 20.0.0. { 0x66, 0xC8, 0xCB, 0x3D, 0xEC, 0xF4, 0x59, 0x73, 0x54, 0x88, 0xE1, 0x2E, 0xE6, 0x3D, 0x68, 0x46 }, // 21.0.0. + { 0x15, 0xAC, 0x96, 0x34, 0xF5, 0x32, 0x56, 0x68, 0xFE, 0x5B, 0x9D, 0xD7, 0xED, 0x19, 0xB7, 0x8E }, // 22.0.0. }; //!TODO: Update on mkey changes. @@ -92,6 +93,7 @@ static const u8 master_kekseed_t210b01[HOS_MKEY_VER_MAX - HOS_MKEY_VER_600 + 1][ { 0x31, 0xBE, 0x25, 0xFB, 0xDB, 0xB4, 0xEE, 0x49, 0x5C, 0x77, 0x05, 0xC2, 0x36, 0x9F, 0x34, 0x80 }, // 19.0.0. { 0x1A, 0x31, 0x62, 0x87, 0xA8, 0x09, 0xCA, 0xF8, 0x69, 0x15, 0x45, 0xC2, 0x6B, 0xAA, 0x5A, 0x8A }, // 20.0.0. { 0xEB, 0xF3, 0x5B, 0x2D, 0x4A, 0x2D, 0xCE, 0x45, 0x3A, 0x6F, 0x61, 0x38, 0x0B, 0x00, 0x3B, 0x46 }, // 21.0.0. + { 0x82, 0xE2, 0x0A, 0x59, 0x67, 0xDF, 0xBF, 0x51, 0x47, 0x62, 0x11, 0xF2, 0x41, 0xD3, 0xEE, 0x13 }, // 22.0.0. }; static const u8 console_keyseed[SE_KEY_128_SIZE] = @@ -131,23 +133,23 @@ static void _se_lock(bool lock_se) SB(SB_CSR) = SB_CSR_PIROM_DISABLE; } -static bool _hos_eks_rw_try(u8 *buf, bool write) +static int _hos_eks_rw_try(u8 *buf, bool write) { for (u32 i = 0; i < 3; i++) { if (!write) { - if (sdmmc_storage_read(&sd_storage, 0, 1, buf)) - return true; + if (!sdmmc_storage_read(&sd_storage, 0, 1, buf)) + return 0; } else { - if (sdmmc_storage_write(&sd_storage, 0, 1, buf)) - return true; + if (!sdmmc_storage_write(&sd_storage, 0, 1, buf)) + return 0; } } - return false; + return 1; } static void _hos_eks_get() @@ -161,7 +163,7 @@ static void _hos_eks_get() { // Read EKS blob. u8 *mbr = malloc(SD_BLOCKSIZE); - if (!_hos_eks_rw_try(mbr, false)) + if (_hos_eks_rw_try(mbr, false)) goto out; // Decrypt EKS blob. @@ -199,7 +201,7 @@ static void _hos_eks_save() { // Read EKS blob. u8 *mbr = malloc(SD_BLOCKSIZE); - if (!_hos_eks_rw_try(mbr, false)) + if (_hos_eks_rw_try(mbr, false)) { if (new_eks) { @@ -253,7 +255,7 @@ static void _hos_eks_clear(u32 mkey) { // Read EKS blob. u8 *mbr = malloc(SD_BLOCKSIZE); - if (!_hos_eks_rw_try(mbr, false)) + if (_hos_eks_rw_try(mbr, false)) goto out; // Disable current Master key version. @@ -291,7 +293,7 @@ static int _hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt, bool s tsec_keys_t tsec_keys; if (mkey > HOS_MKEY_VER_MAX) - return 0; + return 1; // Do Mariko keygen. if (h_cfg.t210b01) @@ -306,7 +308,7 @@ static int _hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt, bool s // Derive latest pkg2 key. se_aes_unwrap_key(8, 7, package2_keyseed); - return 1; + return 0; } // Do Erista keygen. @@ -317,7 +319,7 @@ static int _hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt, bool s if (fuse_set_sbk()) sbk_is_set = true; else - return 1; // Continue with current SE keys. + return 0; // Continue with current SE keys. } // Use HOS EKS if it exists. @@ -354,7 +356,7 @@ static int _hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt, bool s if (!tsec_ctxt->fw) { _hos_crit_error("Failed to load thk.bin"); - return 0; + return 1; } tsec_ctxt->size = 0x1F00; @@ -378,7 +380,7 @@ static int _hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt, bool s if (retries > 15) { _hos_crit_error("Failed to get TSEC keys."); - return 0; + return 1; } } @@ -483,7 +485,7 @@ static int _hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt, bool s se_aes_unwrap_key(11, 13, cmac_keyseed); se_aes_hash_cmac(cmac, SE_KEY_128_SIZE, 11, (void *)eks->ctr, sizeof(eks->ctr) + sizeof(eks->keys)); if (!memcmp(eks->cmac, cmac, SE_KEY_128_SIZE)) - return 0; + return 1; */ se_aes_crypt_ecb(13, DECRYPT, tsec_keys.tsec, cmac_keyseed, SE_KEY_128_SIZE); @@ -537,7 +539,7 @@ static int _hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt, bool s se_aes_unwrap_key(8, !is_exo ? 12 : 13, package2_keyseed); } - return 1; + return 0; } static int _read_emmc_pkg1(launch_ctxt_t *ctxt) @@ -586,7 +588,7 @@ try_load: goto try_load; } - return 0; + return 1; } gfx_printf("Identified pkg1 and mkey %d\n\n", ctxt->pkg1_id->mkey); @@ -599,7 +601,7 @@ try_load: eks_size / EMMC_BLOCKSIZE, ctxt->eks); } - return 1; + return 0; } static u8 *_read_emmc_pkg2(launch_ctxt_t *ctxt) @@ -666,7 +668,7 @@ static bool _get_fs_exfat_compatible(link_t *info, u32 *hos_revision) if (strcmp((char *)ki->kip1->name, "FS")) continue; - if (!se_sha_hash_256_oneshot(sha_buf, ki->kip1, ki->size)) + if (se_sha_hash_256_oneshot(sha_buf, ki->kip1, ki->size)) break; pkg2_get_ids(&kip_ids, &fs_ids_cnt); @@ -734,14 +736,14 @@ void hos_launch(ini_sec_t *cfg) } // Try to parse config if present. - if (!parse_boot_config(&ctxt)) + if (hos_parse_boot_config(&ctxt)) { _hos_crit_error("Wrong ini cfg or missing/corrupt files!"); goto error; } // Read package1 and the correct eks. - if (!_read_emmc_pkg1(&ctxt)) + if (_read_emmc_pkg1(&ctxt)) { // Check if stock is enabled and device can boot in OFW. if (ctxt.stock && (h_cfg.t210b01 || !tools_autorcm_enabled())) @@ -770,7 +772,7 @@ void hos_launch(ini_sec_t *cfg) } ctxt.patch_krn_proc_id = true; // Set kernel process id patching in case of no pkg3. - config_kip1patch(&ctxt, "emummc"); + hos_config_kip1patch(&ctxt, "emummc"); } else if (!emu_cfg.enabled && ctxt.emummc_forced) { @@ -801,7 +803,7 @@ void hos_launch(ini_sec_t *cfg) ((fuses & BIT(14)) && (ctxt.pkg1_id->fuses <= 14)) // HOS 12.0.2+ fuses burnt. ) )) - config_kip1patch(&ctxt, "nogc"); + hos_config_kip1patch(&ctxt, "nogc"); } gfx_printf("Loaded config and pkg1\n%s mode\n", ctxt.stock ? "Stock" : "CFW"); @@ -821,7 +823,7 @@ void hos_launch(ini_sec_t *cfg) tsec_ctxt.pkg11_off = ctxt.pkg1_id->pkg11_off; // Generate keys. - if (!_hos_keygen(ctxt.eks, mkey, &tsec_ctxt, ctxt.stock, is_exo)) + if (_hos_keygen(ctxt.eks, mkey, &tsec_ctxt, ctxt.stock, is_exo)) goto error; gfx_puts("Generated keys\n"); @@ -871,7 +873,7 @@ void hos_launch(ini_sec_t *cfg) } // Configure and manage Warmboot binary. - if (!pkg1_warmboot_config(&ctxt, warmboot_base, ctxt.pkg1_id->fuses, mkey)) + if (pkg1_warmboot_config(&ctxt, warmboot_base, ctxt.pkg1_id->fuses, mkey)) { // Can only happen on T210B01. _hos_crit_error("\nFailed to match warmboot with fuses!\nIf you continue, sleep wont work!"); @@ -928,7 +930,7 @@ void hos_launch(ini_sec_t *cfg) } LIST_INIT(kip1_info); - if (!pkg2_parse_kips(&kip1_info, pkg2_hdr, &ctxt.new_pkg2)) + if (pkg2_parse_kips(&kip1_info, pkg2_hdr, &ctxt.new_pkg2)) { _hos_crit_error("INI1 parsing failed!"); goto error; diff --git a/bootloader/hos/hos.h b/bootloader/hos/hos.h index 8bce245c..a9ab15d7 100644 --- a/bootloader/hos/hos.h +++ b/bootloader/hos/hos.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -48,7 +48,8 @@ enum { HOS_MKEY_VER_1900 = 18, HOS_MKEY_VER_2000 = 19, HOS_MKEY_VER_2100 = 20, - HOS_MKEY_VER_MAX = HOS_MKEY_VER_2100 + HOS_MKEY_VER_2200 = 21, + HOS_MKEY_VER_MAX = HOS_MKEY_VER_2200 }; #define HOS_TSEC_VERSION 4 //! TODO: Update on TSEC Root Key changes. @@ -62,9 +63,10 @@ enum { typedef struct _exo_ctxt_t { - u32 hos_revision; - bool no_user_exceptions; - bool user_pmu; + u32 hos_revision; + bool no_user_exceptions; + bool user_pmu; + bool *force_mem_mode; bool *usb3_force; bool *cal0_blank; bool *cal0_allow_writes_sys; diff --git a/bootloader/hos/hos_config.c b/bootloader/hos/hos_config.c index eb64ae1f..6d9a7d11 100644 --- a/bootloader/hos/hos_config.c +++ b/bootloader/hos/hos_config.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -31,27 +31,27 @@ static int _config_warmboot(launch_ctxt_t *ctxt, const char *value) { ctxt->warmboot = sd_file_read(value, &ctxt->warmboot_size); if (!ctxt->warmboot) - return 0; + return 1; - return 1; + return 0; } static int _config_secmon(launch_ctxt_t *ctxt, const char *value) { ctxt->secmon = sd_file_read(value, &ctxt->secmon_size); if (!ctxt->secmon) - return 0; + return 1; - return 1; + return 0; } static int _config_kernel(launch_ctxt_t *ctxt, const char *value) { ctxt->kernel = sd_file_read(value, &ctxt->kernel_size); if (!ctxt->kernel) - return 0; + return 1; - return 1; + return 0; } static int _config_kip1(launch_ctxt_t *ctxt, const char *value) @@ -88,7 +88,7 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value) free(dir); free(filelist); - return 0; + return 1; } DPRINTF("Loaded kip1 from SD (size %08X)\n", size); list_append(&ctxt->kip1_list, &mkip1->link); @@ -108,20 +108,20 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value) { free(mkip1); - return 0; + return 1; } DPRINTF("Loaded kip1 from SD (size %08X)\n", size); list_append(&ctxt->kip1_list, &mkip1->link); } - return 1; + return 0; } -int config_kip1patch(launch_ctxt_t *ctxt, const char *value) +int hos_config_kip1patch(launch_ctxt_t *ctxt, const char *value) { int len = strlen(value); if (!len) - return 0; + return 1; if (ctxt->kip1_patches == NULL) { @@ -142,7 +142,8 @@ int config_kip1patch(launch_ctxt_t *ctxt, const char *value) memcpy(&ctxt->kip1_patches[old_len], value, len); ctxt->kip1_patches[old_len + len] = 0; } - return 1; + + return 0; } static int _config_svcperm(launch_ctxt_t *ctxt, const char *value) @@ -152,7 +153,8 @@ static int _config_svcperm(launch_ctxt_t *ctxt, const char *value) DPRINTF("Disabled SVC verification\n"); ctxt->svcperm = true; } - return 1; + + return 0; } static int _config_debugmode(launch_ctxt_t *ctxt, const char *value) @@ -162,7 +164,8 @@ static int _config_debugmode(launch_ctxt_t *ctxt, const char *value) DPRINTF("Enabled Debug mode\n"); ctxt->debugmode = true; } - return 1; + + return 0; } static int _config_stock(launch_ctxt_t *ctxt, const char *value) @@ -172,7 +175,8 @@ static int _config_stock(launch_ctxt_t *ctxt, const char *value) DPRINTF("Enabled stock mode\n"); ctxt->stock = true; } - return 1; + + return 0; } static int _config_emummc_forced(launch_ctxt_t *ctxt, const char *value) @@ -182,7 +186,8 @@ static int _config_emummc_forced(launch_ctxt_t *ctxt, const char *value) DPRINTF("Forced emuMMC\n"); ctxt->emummc_forced = true; } - return 1; + + return 0; } static int _config_kernel_proc_id(launch_ctxt_t *ctxt, const char *value) @@ -192,7 +197,8 @@ static int _config_kernel_proc_id(launch_ctxt_t *ctxt, const char *value) DPRINTF("Enabled kernel process id send/recv patching\n"); ctxt->patch_krn_proc_id = true; } - return 1; + + return 0; } static int _config_dis_exo_user_exceptions(launch_ctxt_t *ctxt, const char *value) @@ -202,7 +208,8 @@ static int _config_dis_exo_user_exceptions(launch_ctxt_t *ctxt, const char *valu DPRINTF("Disabled exosphere user exception handlers\n"); ctxt->exo_ctx.no_user_exceptions = true; } - return 1; + + return 0; } static int _config_exo_user_pmu_access(launch_ctxt_t *ctxt, const char *value) @@ -212,7 +219,22 @@ static int _config_exo_user_pmu_access(launch_ctxt_t *ctxt, const char *value) DPRINTF("Enabled user access to PMU\n"); ctxt->exo_ctx.user_pmu = true; } - return 1; + + return 0; +} + +static int _config_exo_force_mem_mode(launch_ctxt_t *ctxt, const char *value) +{ + // Override key found. + ctxt->exo_ctx.force_mem_mode = zalloc(sizeof(bool)); + + if (*value == '1') + { + DPRINTF("Enabled Auto Memory Mode\n"); + *ctxt->exo_ctx.force_mem_mode = true; + } + + return 0; } static int _config_exo_usb3_force(launch_ctxt_t *ctxt, const char *value) @@ -225,7 +247,8 @@ static int _config_exo_usb3_force(launch_ctxt_t *ctxt, const char *value) DPRINTF("Enabled USB 3.0\n"); *ctxt->exo_ctx.usb3_force = true; } - return 1; + + return 0; } static int _config_exo_cal0_blanking(launch_ctxt_t *ctxt, const char *value) @@ -238,7 +261,8 @@ static int _config_exo_cal0_blanking(launch_ctxt_t *ctxt, const char *value) DPRINTF("Enabled prodinfo blanking\n"); *ctxt->exo_ctx.cal0_blank = true; } - return 1; + + return 0; } static int _config_exo_cal0_writes_enable(launch_ctxt_t *ctxt, const char *value) @@ -252,7 +276,7 @@ static int _config_exo_cal0_writes_enable(launch_ctxt_t *ctxt, const char *value *ctxt->exo_ctx.cal0_allow_writes_sys = true; } - return 1; + return 0; } static int _config_pkg3(launch_ctxt_t *ctxt, const char *value) @@ -264,9 +288,9 @@ static int _config_exo_fatal_payload(launch_ctxt_t *ctxt, const char *value) { ctxt->exofatal = sd_file_read(value, &ctxt->exofatal_size); if (!ctxt->exofatal) - return 0; + return 1; - return 1; + return 0; } static int _config_ucid(launch_ctxt_t *ctxt, const char *value) @@ -274,7 +298,7 @@ static int _config_ucid(launch_ctxt_t *ctxt, const char *value) // Override uCID if set. ctxt->ucid = atoi(value); - return 1; + return 0; } typedef struct _cfg_handler_t @@ -289,7 +313,7 @@ static const cfg_handler_t _config_handlers[] = { { "secmon", _config_secmon }, { "kernel", _config_kernel }, { "kip1", _config_kip1 }, - { "kip1patch", config_kip1patch }, + { "kip1patch", hos_config_kip1patch }, { "fullsvcperm", _config_svcperm }, { "debugmode", _config_debugmode }, { "kernelprocid", _config_kernel_proc_id }, @@ -302,6 +326,7 @@ static const cfg_handler_t _config_handlers[] = { { "emummcforce", _config_emummc_forced }, { "nouserexceptions", _config_dis_exo_user_exceptions }, { "userpmu", _config_exo_user_pmu_access }, + { "memmode", _config_exo_force_mem_mode }, { "usb3force", _config_exo_usb3_force }, { "cal0blank", _config_exo_cal0_blanking }, { "cal0writesys", _config_exo_cal0_writes_enable }, @@ -309,10 +334,10 @@ static const cfg_handler_t _config_handlers[] = { { NULL, NULL }, }; -int parse_boot_config(launch_ctxt_t *ctxt) +int hos_parse_boot_config(launch_ctxt_t *ctxt) { if (!ctxt->cfg) - return 1; + return 0; // Check each config key. LIST_FOREACH_ENTRY(ini_kv_t, kv, &ctxt->cfg->kvs, link) @@ -322,12 +347,12 @@ int parse_boot_config(launch_ctxt_t *ctxt) // If key matches, call its handler. if (!strcmp(_config_handlers[i].key, kv->key)) { - if (!_config_handlers[i].handler(ctxt, kv->val)) + if (_config_handlers[i].handler(ctxt, kv->val)) { gfx_con.mute = false; EPRINTFARGS("Error while loading %s:\n%s", kv->key, kv->val); - return 0; + return 1; } break; @@ -335,5 +360,5 @@ int parse_boot_config(launch_ctxt_t *ctxt) } } - return 1; + return 0; } diff --git a/bootloader/hos/hos_config.h b/bootloader/hos/hos_config.h index f835302a..7b9a119e 100644 --- a/bootloader/hos/hos_config.h +++ b/bootloader/hos/hos_config.h @@ -19,8 +19,8 @@ #include "hos.h" -int parse_boot_config(launch_ctxt_t *ctxt); -int config_kip1patch(launch_ctxt_t *ctxt, const char *value); +int hos_parse_boot_config(launch_ctxt_t *ctxt); +int hos_config_kip1patch(launch_ctxt_t *ctxt, const char *value); #endif diff --git a/bootloader/hos/pkg1.c b/bootloader/hos/pkg1.c index 81ddfab6..9b1c8c93 100644 --- a/bootloader/hos/pkg1.c +++ b/bootloader/hos/pkg1.c @@ -171,7 +171,8 @@ static const pkg1_id_t _pkg1_ids[] = { { "20240207", 17, 19, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000, NULL }, // 18.0.0 - 18.1.0. { "20240808", 18, 20, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000, NULL }, // 19.0.0 - 19.0.1. { "20250206", 19, 21, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000, NULL }, // 20.0.0 - 20.5.0. - { "20251009", 20, 22, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000, NULL }, // 21.0.0+ + { "20251009", 20, 22, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000, NULL }, // 21.0.0 - 21.2.0. + { "20260123", 21, 23, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000, NULL }, // 22.0.0+ }; const pkg1_id_t *pkg1_get_latest() @@ -195,7 +196,7 @@ const pkg1_id_t *pkg1_identify(u8 *pkg1) return NULL; } -int pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1) +bool pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1) { pk11_hdr_t *hdr; @@ -344,7 +345,7 @@ void pkg1_warmboot_patch(void *hos_ctxt) int pkg1_warmboot_config(void *hos_ctxt, u32 warmboot_base, u32 fuses_fw, u8 mkey) { launch_ctxt_t *ctxt = (launch_ctxt_t *)hos_ctxt; - int res = 1; + int res = 0; if (h_cfg.t210b01) { @@ -374,7 +375,7 @@ int pkg1_warmboot_config(void *hos_ctxt, u32 warmboot_base, u32 fuses_fw, u8 mke // Check if high enough. if (!warmboot_fw || burnt_fuses > fuses_fw) - res = 0; + res = 1; else { ctxt->warmboot = warmboot_fw + sizeof(u32); diff --git a/bootloader/hos/pkg1.h b/bootloader/hos/pkg1.h index e810d6f4..375bf150 100644 --- a/bootloader/hos/pkg1.h +++ b/bootloader/hos/pkg1.h @@ -162,7 +162,7 @@ typedef struct _nx_bit_t const pkg1_id_t *pkg1_get_latest(); const pkg1_id_t *pkg1_identify(u8 *pkg1); -int pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1); +bool pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1); const u8 *pkg1_unpack(void *wm_dst, u32 *wb_sz, void *sm_dst, void *ldr_dst, const pkg1_id_t *id, u8 *pkg1); void pkg1_secmon_patch(void *hos_ctxt, u32 secmon_base, bool t210b01); void pkg1_warmboot_patch(void *hos_ctxt); diff --git a/bootloader/hos/pkg2.c b/bootloader/hos/pkg2.c index a6365e52..aa3044f0 100644 --- a/bootloader/hos/pkg2.c +++ b/bootloader/hos/pkg2.c @@ -63,101 +63,101 @@ static void parse_external_kip_patches() if (ext_patches_parsed) return; + ext_patches_parsed = true; + LIST_INIT(ini_kip_sections); if (ini_patch_parse(&ini_kip_sections, "bootloader/patches.ini")) + return; + + // Copy ids into a new patchset. + _kip_id_sets = zalloc(sizeof(kip1_id_t) * 256); // Max 256 kip ids. + memcpy(_kip_id_sets, _kip_ids, sizeof(_kip_ids)); + + // Parse patchsets and glue them together. + LIST_FOREACH_ENTRY(ini_kip_sec_t, ini_psec, &ini_kip_sections, link) { - // Copy ids into a new patchset. - _kip_id_sets = zalloc(sizeof(kip1_id_t) * 256); // Max 256 kip ids. - memcpy(_kip_id_sets, _kip_ids, sizeof(_kip_ids)); - - // Parse patchsets and glue them together. - LIST_FOREACH_ENTRY(ini_kip_sec_t, ini_psec, &ini_kip_sections, link) + kip1_id_t *kip = NULL; + bool found = false; + for (u32 kip_idx = 0; kip_idx < _kip_id_sets_cnt + 1; kip_idx++) { - kip1_id_t *kip = NULL; - bool found = false; - for (u32 kip_idx = 0; kip_idx < _kip_id_sets_cnt + 1; kip_idx++) + kip = &_kip_id_sets[kip_idx]; + + // Check if reached the end of predefined list. + if (!kip->name) + break; + + // Check if name and hash match. + if (!strcmp(kip->name, ini_psec->name) && !memcmp(kip->hash, ini_psec->hash, 8)) { - kip = &_kip_id_sets[kip_idx]; - - // Check if reached the end of predefined list. - if (!kip->name) - break; - - // Check if name and hash match. - if (!strcmp(kip->name, ini_psec->name) && !memcmp(kip->hash, ini_psec->hash, 8)) - { - found = true; - break; - } + found = true; + break; } - - if (!kip) - continue; - - // If not found, create a new empty entry. - if (!found) - { - kip->name = ini_psec->name; - memcpy(kip->hash, ini_psec->hash, 8); - kip->patchset = zalloc(sizeof(kip1_patchset_t)); - - _kip_id_sets_cnt++; - } - - kip1_patchset_t *patchsets = (kip1_patchset_t *)zalloc(sizeof(kip1_patchset_t) * 16); // Max 16 patchsets per kip. - - u32 patchset_idx; - for (patchset_idx = 0; kip->patchset[patchset_idx].name != NULL; patchset_idx++) - { - patchsets[patchset_idx].name = kip->patchset[patchset_idx].name; - patchsets[patchset_idx].patches = kip->patchset[patchset_idx].patches; - } - - kip->patchset = patchsets; - bool first_ext_patch = true; - u32 patch_idx = 0; - - // Parse patches and glue them together to a patchset. - kip1_patch_t *patches = zalloc(sizeof(kip1_patch_t) * 32); // Max 32 patches per set. - LIST_FOREACH_ENTRY(ini_patchset_t, pt, &ini_psec->pts, link) - { - if (first_ext_patch) - { - first_ext_patch = false; - patchsets[patchset_idx].name = pt->name; - patchsets[patchset_idx].patches = patches; - } - else if (strcmp(pt->name, patchsets[patchset_idx].name)) - { - // New patchset name found, create a new set. - patchset_idx++; - patch_idx = 0; - patches = zalloc(sizeof(kip1_patch_t) * 32); // Max 32 patches per set. - - patchsets[patchset_idx].name = pt->name; - patchsets[patchset_idx].patches = patches; - } - - if (pt->length) - { - patches[patch_idx].offset = pt->offset; - patches[patch_idx].length = pt->length; - - patches[patch_idx].src_data = (char *)pt->src_data; - patches[patch_idx].dst_data = (char *)pt->dst_data; - } - else - patches[patch_idx].src_data = malloc(1); // Empty patches check. Keep everything else as 0. - - patch_idx++; - } - patchset_idx++; - patchsets[patchset_idx].name = NULL; - patchsets[patchset_idx].patches = NULL; } - } - ext_patches_parsed = true; + if (!kip) + continue; + + // If not found, create a new empty entry. + if (!found) + { + kip->name = ini_psec->name; + memcpy(kip->hash, ini_psec->hash, 8); + kip->patchset = zalloc(sizeof(kip1_patchset_t)); + + _kip_id_sets_cnt++; + } + + kip1_patchset_t *patchsets = (kip1_patchset_t *)zalloc(sizeof(kip1_patchset_t) * 16); // Max 16 patchsets per kip. + + u32 patchset_idx; + for (patchset_idx = 0; kip->patchset[patchset_idx].name != NULL; patchset_idx++) + { + patchsets[patchset_idx].name = kip->patchset[patchset_idx].name; + patchsets[patchset_idx].patches = kip->patchset[patchset_idx].patches; + } + + kip->patchset = patchsets; + bool first_ext_patch = true; + u32 patch_idx = 0; + + // Parse patches and glue them together to a patchset. + kip1_patch_t *patches = zalloc(sizeof(kip1_patch_t) * 32); // Max 32 patches per set. + LIST_FOREACH_ENTRY(ini_patchset_t, pt, &ini_psec->pts, link) + { + if (first_ext_patch) + { + first_ext_patch = false; + patchsets[patchset_idx].name = pt->name; + patchsets[patchset_idx].patches = patches; + } + else if (strcmp(pt->name, patchsets[patchset_idx].name)) + { + // New patchset name found, create a new set. + patchset_idx++; + patch_idx = 0; + patches = zalloc(sizeof(kip1_patch_t) * 32); // Max 32 patches per set. + + patchsets[patchset_idx].name = pt->name; + patchsets[patchset_idx].patches = patches; + } + + if (pt->length) + { + patches[patch_idx].offset = pt->offset; + patches[patch_idx].length = pt->length; + + patches[patch_idx].src_data = (char *)pt->src_data; + patches[patch_idx].dst_data = (char *)pt->dst_data; + } + else + patches[patch_idx].src_data = malloc(1); // Empty patches check. Keep everything else as 0. + + patch_idx++; + } + patchset_idx++; + patchsets[patchset_idx].name = NULL; + patchsets[patchset_idx].patches = NULL; + } } const pkg2_kernel_id_t *pkg2_identify(const u8 *hash) @@ -226,7 +226,7 @@ static void _pkg2_get_newkern_info(u8 *kern_data) } } -bool pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2) +int pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2) { u8 *ptr; // Check for new pkg2 type. @@ -235,7 +235,7 @@ bool pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2) _pkg2_get_newkern_info(pkg2->data); if (!pkg2_newkern_ini1_start) - return false; + return 1; ptr = pkg2->data + pkg2_newkern_ini1_start; *new_pkg2 = true; @@ -257,15 +257,15 @@ bool pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2) DPRINTF(" kip1 %d:%s @ %08X (%08X)\n", i, kip1->name, (u32)kip1, ki->size); } - return true; + return 0; } -int pkg2_has_kip(link_t *info, u64 tid) +bool pkg2_has_kip(link_t *info, u64 tid) { LIST_FOREACH_ENTRY(pkg2_kip1_info_t, ki, info, link) if (ki->kip1->tid == tid) - return 1; - return 0; + return true; + return false; } void pkg2_replace_kip(link_t *info, u64 tid, pkg2_kip1_t *kip1) @@ -371,65 +371,63 @@ static int _decompress_kip(pkg2_kip1_info_t *ki, u32 sectsToDecomp) static int _kipm_inject(const char *kipm_path, char *target_name, pkg2_kip1_info_t *ki) { - if (!strcmp((char *)ki->kip1->name, target_name)) + if (strcmp((char *)ki->kip1->name, target_name)) + return 1; + + u32 size = 0; + u8 *kipm_data = (u8 *)sd_file_read(kipm_path, &size); + if (!kipm_data) + return 1; + + u32 inject_size = size - sizeof(ki->kip1->caps); + u8 *kip_patched_data = (u8 *)malloc(ki->size + inject_size); + + // Copy headers. + memcpy(kip_patched_data, ki->kip1, sizeof(pkg2_kip1_t)); + + pkg2_kip1_t *fs_kip = ki->kip1; + ki->kip1 = (pkg2_kip1_t *)kip_patched_data; + ki->size = ki->size + inject_size; + + // Patch caps. + memcpy(&ki->kip1->caps, kipm_data, sizeof(ki->kip1->caps)); + // Copy our .text data. + memcpy(&ki->kip1->data, kipm_data + sizeof(ki->kip1->caps), inject_size); + + u32 new_offset = 0; + + for (u32 section_idx = 0; section_idx < KIP1_NUM_SECTIONS - 2; section_idx++) { - u32 size = 0; - u8 *kipm_data = (u8 *)sd_file_read(kipm_path, &size); - if (!kipm_data) - return 1; - - u32 inject_size = size - sizeof(ki->kip1->caps); - u8 *kip_patched_data = (u8 *)malloc(ki->size + inject_size); - - // Copy headers. - memcpy(kip_patched_data, ki->kip1, sizeof(pkg2_kip1_t)); - - pkg2_kip1_t *fs_kip = ki->kip1; - ki->kip1 = (pkg2_kip1_t *)kip_patched_data; - ki->size = ki->size + inject_size; - - // Patch caps. - memcpy(&ki->kip1->caps, kipm_data, sizeof(ki->kip1->caps)); - // Copy our .text data. - memcpy(&ki->kip1->data, kipm_data + sizeof(ki->kip1->caps), inject_size); - - u32 new_offset = 0; - - for (u32 section_idx = 0; section_idx < KIP1_NUM_SECTIONS - 2; section_idx++) + if (!section_idx) // .text. { - if (!section_idx) // .text. - { - memcpy(ki->kip1->data + inject_size, fs_kip->data, fs_kip->sections[0].size_comp); - ki->kip1->sections[0].size_decomp += inject_size; - ki->kip1->sections[0].size_comp += inject_size; - } - else // Others. - { - if (section_idx < 3) - memcpy(ki->kip1->data + new_offset + inject_size, fs_kip->data + new_offset, fs_kip->sections[section_idx].size_comp); - ki->kip1->sections[section_idx].offset += inject_size; - } - new_offset += fs_kip->sections[section_idx].size_comp; + memcpy(ki->kip1->data + inject_size, fs_kip->data, fs_kip->sections[0].size_comp); + ki->kip1->sections[0].size_decomp += inject_size; + ki->kip1->sections[0].size_comp += inject_size; } - - // Patch PMC capabilities for 1.0.0. - if (!emu_cfg.fs_ver) + else // Others. { - for (u32 i = 0; i < 0x20; i++) - { - if (ki->kip1->caps[i] == 0xFFFFFFFF) - { - ki->kip1->caps[i] = 0x07000E7F; - break; - } - } + if (section_idx < 3) + memcpy(ki->kip1->data + new_offset + inject_size, fs_kip->data + new_offset, fs_kip->sections[section_idx].size_comp); + ki->kip1->sections[section_idx].offset += inject_size; } - - free(kipm_data); - return 0; + new_offset += fs_kip->sections[section_idx].size_comp; } - return 1; + // Patch PMC capabilities for 1.0.0. + if (!emu_cfg.fs_ver) + { + for (u32 i = 0; i < 0x20; i++) + { + if (ki->kip1->caps[i] == 0xFFFFFFFF) + { + ki->kip1->caps[i] = 0x07000E7F; + break; + } + } + } + + free(kipm_data); + return 0; } const char *pkg2_patch_kips(link_t *info, char *patch_names) @@ -544,7 +542,7 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names) // Check if current KIP not hashed and hash it. if (kip_hash[0] == 0) - if (!se_sha_hash_256_oneshot(kip_hash, ki->kip1, ki->size)) + if (se_sha_hash_256_oneshot(kip_hash, ki->kip1, ki->size)) memset(kip_hash, 0, sizeof(kip_hash)); // Check if kip is the expected version. diff --git a/bootloader/hos/pkg2.h b/bootloader/hos/pkg2.h index c6ee4dfb..5d6fbebf 100644 --- a/bootloader/hos/pkg2.h +++ b/bootloader/hos/pkg2.h @@ -208,8 +208,8 @@ typedef struct _nx_bc_t { u8 padding2[0xC0]; } nx_bc_t; -bool pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2); -int pkg2_has_kip(link_t *info, u64 tid); +int pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2); +bool pkg2_has_kip(link_t *info, u64 tid); void pkg2_replace_kip(link_t *info, u64 tid, pkg2_kip1_t *kip1); void pkg2_add_kip(link_t *info, pkg2_kip1_t *kip1); void pkg2_merge_kip(link_t *info, pkg2_kip1_t *kip1); diff --git a/bootloader/hos/pkg2_ini_kippatch.c b/bootloader/hos/pkg2_ini_kippatch.c index 9567eeff..579f2dc6 100644 --- a/bootloader/hos/pkg2_ini_kippatch.c +++ b/bootloader/hos/pkg2_ini_kippatch.c @@ -104,7 +104,7 @@ int ini_patch_parse(link_t *dst, const char *ini_path) // Open ini. if (f_open(&fp, ini_path, FA_READ) != FR_OK) - return 0; + return 1; lbuf = malloc(512); @@ -176,5 +176,5 @@ int ini_patch_parse(link_t *dst, const char *ini_path) free(lbuf); - return 1; + return 0; } diff --git a/bootloader/hos/pkg2_patches.inl b/bootloader/hos/pkg2_patches.inl index 3fa79107..39524c31 100644 --- a/bootloader/hos/pkg2_patches.inl +++ b/bootloader/hos/pkg2_patches.inl @@ -869,6 +869,30 @@ static const kip1_patchset_t _fs_patches_2100_exfat[] = { { NULL, NULL } }; +static const kip1_patch_t _fs_nogc_2200[] = { + { KPS(KIP_TEXT) | 0x182F60, 8, KIP1_PATCH_SRC_NO_CHECK, KIP1_FS_NOGC_PATCH_NOINIT }, + { KPS(KIP_TEXT) | 0x1B013D, 1, KIP1_PATCH_SRC_NO_CHECK, KIP1_FS_NOGC_PATCH_SDMMC3 }, + { KPS(KIP_TEXT) | 0x1B0155, 1, KIP1_PATCH_SRC_NO_CHECK, KIP1_FS_NOGC_PATCH_SDMMC3 }, + { 0, 0, NULL, NULL } +}; + +static const kip1_patchset_t _fs_patches_2200[] = { + { "nogc", _fs_nogc_2200 }, + { NULL, NULL } +}; + +static const kip1_patch_t _fs_nogc_2200_exfat[] = { + { KPS(KIP_TEXT) | 0x18E150, 8, KIP1_PATCH_SRC_NO_CHECK, KIP1_FS_NOGC_PATCH_NOINIT }, + { KPS(KIP_TEXT) | 0x1BB32D, 1, KIP1_PATCH_SRC_NO_CHECK, KIP1_FS_NOGC_PATCH_SDMMC3 }, + { KPS(KIP_TEXT) | 0x1BB345, 1, KIP1_PATCH_SRC_NO_CHECK, KIP1_FS_NOGC_PATCH_SDMMC3 }, + { 0, 0, NULL, NULL } +}; + +static const kip1_patchset_t _fs_patches_2200_exfat[] = { + { "nogc", _fs_nogc_2200_exfat }, + { NULL, NULL } +}; + // SHA256 hashes. static const kip1_id_t _kip_ids[] = { @@ -942,4 +966,6 @@ static const kip1_id_t _kip_ids[] = { "FS", "\x6E\x2B\xD9\xBA\xA3\xB9\x10\xF1", _fs_patches_2100_exfat }, // FS 21.0.0 exFAT { "FS", "\xAF\x1D\xBD\xC7\x82\x98\x3C\xBD", _fs_patches_2100 }, // FS 21.2.0 { "FS", "\x56\x25\x17\xA1\x92\xC3\xC8\xF0", _fs_patches_2100_exfat }, // FS 21.2.0 exFAT + { "FS", "\xB7\xA2\x97\x39\xB7\xED\xDE\xFC", _fs_patches_2200 }, // FS 22.0.0 + { "FS", "\xFB\x0B\x68\xDB\x24\x03\xD1\x19", _fs_patches_2200_exfat }, // FS 22.0.0 exFAT }; diff --git a/bootloader/hos/pkg3.c b/bootloader/hos/pkg3.c index 2dab4089..51907947 100644 --- a/bootloader/hos/pkg3.c +++ b/bootloader/hos/pkg3.c @@ -96,7 +96,7 @@ static int _pkg3_kip1_skip(char ***pkg3_kip1_skip, u32 *pkg3_kip1_skip_num, char { int len = strlen(value); if (!len || (*pkg3_kip1_skip_num) >= PKG3_KIP_SKIP_MAX) - return 0; + return 1; // Allocate pointer list memory. if (!(*pkg3_kip1_skip)) @@ -116,11 +116,11 @@ static int _pkg3_kip1_skip(char ***pkg3_kip1_skip, u32 *pkg3_kip1_skip_num, char (*pkg3_kip1_skip)[(*pkg3_kip1_skip_num)++] = c + 1; if ((*pkg3_kip1_skip_num) >= PKG3_KIP_SKIP_MAX) - return 0; + return 1; } } - return 1; + return 0; } int parse_pkg3(launch_ctxt_t *ctxt, const char *path) @@ -153,15 +153,15 @@ int parse_pkg3(launch_ctxt_t *ctxt, const char *path) #ifdef HOS_MARIKO_STOCK_SECMON if (stock && emummc_disabled && (pkg1_old || h_cfg.t210b01)) - return 1; + return 0; #else if (stock && emummc_disabled && pkg1_old) - return 1; + return 0; #endif // Try to open PKG3. if (f_open(&fp, path, FA_READ) != FR_OK) - return 0; + return 1; void *pkg3 = malloc(f_size(&fp)); @@ -268,7 +268,7 @@ int parse_pkg3(launch_ctxt_t *ctxt, const char *path) free(pkg3_kip1_skip); - return 1; + return 0; } // Failed. Close and free all. @@ -277,5 +277,5 @@ int parse_pkg3(launch_ctxt_t *ctxt, const char *path) free(pkg3_kip1_skip); free(pkg3); - return 0; + return 1; } diff --git a/bootloader/hos/secmon_exo.c b/bootloader/hos/secmon_exo.c index 80ae1ba2..2176c3fd 100644 --- a/bootloader/hos/secmon_exo.c +++ b/bootloader/hos/secmon_exo.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 CTCaer * Copyright (c) 2019 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it @@ -136,6 +136,7 @@ typedef struct _atm_fatal_error_ctx #define EXO_FLAG_CAL0_BLANKING BIT(5) #define EXO_FLAG_CAL0_WRITES_SYS BIT(6) #define EXO_FLAG_ENABLE_USB3 BIT(7) +#define EXO_FLAG_BC_MEM_MODE BIT(8) #define EXO_FW_VER(mj, mn) (((mj) << 24) | ((mn) << 16)) @@ -145,6 +146,7 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base) u32 exo_flags = 0; bool usb3_force = false; bool user_debug = false; + bool bc_mem_mode = false; bool cal0_blanking = false; bool cal0_allow_writes_sys = false; @@ -197,7 +199,7 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base) case 12: exo_fw_no = EXO_FW_VER(9, 1); break; - case 13 ... 24: //!TODO: Update on API changes. 24: 21.0.0. + case 13 ... 25: //!TODO: Update on API changes. 25: 22.0.0. exo_fw_no = EXO_FW_VER(exo_fw_no - 3, ctxt->exo_ctx.hos_revision); break; } @@ -206,7 +208,7 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base) if (!ctxt->stock) { LIST_INIT(ini_exo_sections); - if (ini_parse(&ini_exo_sections, "exosphere.ini", false)) + if (!ini_parse(&ini_exo_sections, "exosphere.ini", false)) { LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_exo_sections, link) { @@ -224,6 +226,8 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base) exo_cfg->uart_invert = atoi(kv->val); else if (!strcmp("log_baud_rate", kv->key)) exo_cfg->uart_baudrate = atoi(kv->val); + else if (!strcmp("enable_mem_mode", kv->key)) + bc_mem_mode = atoi(kv->val); else if (emu_cfg.enabled && !h_cfg.emummc_force_disable) { if (!strcmp("blank_prodinfo_emummc", kv->key)) @@ -245,7 +249,7 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base) if (!ctxt->exo_ctx.usb3_force) { LIST_INIT(ini_sys_sections); - if (ini_parse(&ini_sys_sections, "atmosphere/config/system_settings.ini", false)) + if (!ini_parse(&ini_sys_sections, "atmosphere/config/system_settings.ini", false)) { LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sys_sections, link) { @@ -283,6 +287,11 @@ void config_exosphere(launch_ctxt_t *ctxt, u32 warmboot_base) if (ctxt->exo_ctx.user_pmu) exo_flags |= EXO_FLAG_USER_PMU; + // Enable Boot Config Memory Mode. Check if system_settings ini value is overridden. If not, check if enabled in ini. + if ((ctxt->exo_ctx.force_mem_mode && *ctxt->exo_ctx.force_mem_mode) + || (!ctxt->exo_ctx.force_mem_mode && bc_mem_mode)) + exo_flags |= EXO_FLAG_BC_MEM_MODE; + // Enable USB 3.0. Check if system_settings ini value is overridden. If not, check if enabled in ini. if ((ctxt->exo_ctx.usb3_force && *ctxt->exo_ctx.usb3_force) || (!ctxt->exo_ctx.usb3_force && usb3_force)) diff --git a/bootloader/l4t/l4t.c b/bootloader/l4t/l4t.c index 72efd479..f4742965 100644 --- a/bootloader/l4t/l4t.c +++ b/bootloader/l4t/l4t.c @@ -19,7 +19,6 @@ #include #include -#include #include "../hos/hos.h" #include "../hos/pkg1.h" @@ -353,21 +352,21 @@ static int _l4t_sd_load(u32 idx) static void _l4t_sdram_lp0_save_params(bool t210b01) { - struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs *)PMC_BASE; + pmc_regs_t210_t *pmc = (pmc_regs_t210_t *)PMC_BASE; #define _REG_S(base, off) *(u32 *)((base) + (off)) #define MC_S(off) _REG_S(MC_BASE, off) #define pack(src, src_bits, dst, dst_bits) { \ - u32 mask = 0xffffffff >> (31 - ((1 ? src_bits) - (0 ? src_bits))); \ + u32 mask = 0xFFFFFFFF >> (31 - ((1 ? src_bits) - (0 ? src_bits))); \ dst &= ~(mask << (0 ? dst_bits)); \ dst |= ((src >> (0 ? src_bits)) & mask) << (0 ? dst_bits); } #define s(param, src_bits, pmcreg, dst_bits) \ - pack(MC_S(param), src_bits, pmc->pmcreg, dst_bits) + pack(MC_S(param), src_bits, pmc->pmc_ ## pmcreg, dst_bits) // 32 bits version of s macro. -#define s32(param, pmcreg) pmc->pmcreg = MC_S(param) +#define s32(param, pmcreg) pmc->pmc_ ## pmcreg = MC_S(param) // Only save changed carveout registers into PMC for SC7 Exit. @@ -702,7 +701,7 @@ static void _l4t_late_hw_config(bool t210b01) PMC(APBDEV_PMC_SCRATCH201) = BIT(1); // Clear PLLM override for SC7. - PMC(APBDEV_PMC_PLLP_WB0_OVERRIDE) &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE_ENABLE; + PMC(APBDEV_PMC_PLLP_WB0_OVERRIDE) &= ~PMC_PLLP_WB0_OVR_PLLM_OVR_ENABLE; // Set spare reg to 0xE0000 and clear everything else. if (t210b01 && (SYSREG(AHB_AHB_SPARE_REG) & 0xE0000000) != 0xE0000000) @@ -806,7 +805,7 @@ static void _l4t_bpmpfw_b01_config(l4t_ctxt_t *ctxt) // Save BPMP-FW entrypoint for TZ. PMC(APBDEV_PMC_SCRATCH39) = BPMPFW_B01_ENTRYPOINT; - PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE1) |= BIT(15); + PMC(APBDEV_PMC_SCRATCH_WRITE_DISABLE1_B01) |= BIT(15); } static int _l4t_sc7_exit_config(bool t210b01) @@ -825,7 +824,7 @@ static int _l4t_sc7_exit_config(bool t210b01) { // Get latest SC7-Exit if needed and setup PA id. launch_ctxt_t hos_ctxt = {0}; - if (!pkg1_warmboot_config(&hos_ctxt, 0, 0, 0)) + if (pkg1_warmboot_config(&hos_ctxt, 0, 0, 0)) { gfx_con.mute = false; gfx_wputs("\nFailed to match warmboot with fuses!\nIf you continue, sleep wont work!"); @@ -833,7 +832,7 @@ static int _l4t_sc7_exit_config(bool t210b01) gfx_puts("\nPress POWER to continue.\nPress VOL to go to the menu.\n"); if (!(btn_wait() & BTN_POWER)) - return 0; + return 1; } // Copy loaded warmboot fw to address if from storage. @@ -845,7 +844,7 @@ static int _l4t_sc7_exit_config(bool t210b01) PMC(APBDEV_PMC_SEC_DISABLE8) |= BIT(30); } - return 1; + return 0; } static void _l4t_bl33_cfg_set_key(char *env, const char *key, const char *val) @@ -1022,7 +1021,7 @@ void launch_l4t(const ini_sec_t *ini_sec, int entry_idx, int is_list, bool t210b } // Set SC7-Exit firmware address to PMC for bootrom and do further setup. - if (!_l4t_sc7_exit_config(t210b01)) + if (_l4t_sc7_exit_config(t210b01)) return; // Done loading bootloaders/firmware. diff --git a/bootloader/libs/fatfs/diskio.c b/bootloader/libs/fatfs/diskio.c index d207d968..965020f9 100644 --- a/bootloader/libs/fatfs/diskio.c +++ b/bootloader/libs/fatfs/diskio.c @@ -43,7 +43,7 @@ DRESULT disk_read ( UINT count /* Number of sectors to read */ ) { - return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; + return sdmmc_storage_read(&sd_storage, sector, count, buff); } /*-----------------------------------------------------------------------*/ @@ -56,7 +56,7 @@ DRESULT disk_write ( UINT count /* Number of sectors to write */ ) { - return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; + return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff); } /*-----------------------------------------------------------------------*/ diff --git a/bootloader/main.c b/bootloader/main.c index 774403a3..aa20ce87 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -228,7 +228,7 @@ static void _launch_payloads() gfx_clear_grey(0x1B); gfx_con_setpos(0, 0); - if (!sd_mount()) + if (sd_mount()) goto failed_sd_mount; ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3)); @@ -310,11 +310,11 @@ static void _launch_ini_list() gfx_clear_grey(0x1B); gfx_con_setpos(0, 0); - if (!sd_mount()) + if (sd_mount()) goto parse_failed; // Check that ini files exist and parse them. - if (!ini_parse(&ini_list_sections, "bootloader/ini", true)) + if (ini_parse(&ini_list_sections, "bootloader/ini", true)) { EPRINTF("No .ini files in bootloader/ini!"); goto parse_failed; @@ -440,7 +440,7 @@ static void _launch_config() gfx_clear_grey(0x1B); gfx_con_setpos(0, 0); - if (!sd_mount()) + if (sd_mount()) goto parse_failed; // Load emuMMC configuration. @@ -752,7 +752,7 @@ static void _auto_launch() emummc_load_cfg(); // Parse hekate main configuration. - if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) + if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) goto out; // Can't load hekate_ipl.ini. // Load configuration. @@ -839,7 +839,7 @@ static void _auto_launch() boot_entry_id = 1; bootlogoCustomEntry = NULL; - if (!ini_parse(&ini_list_sections, "bootloader/ini", true)) + if (ini_parse(&ini_list_sections, "bootloader/ini", true)) goto skip_list; LIST_FOREACH_ENTRY(ini_sec_t, ini_sec_list, &ini_list_sections, link) @@ -1015,15 +1015,15 @@ out: _nyx_load_run(); } -#define EXCP_EN_ADDR 0x4003FFFC +#define EXCP_EN_ADDR 0x4003FF1C #define EXCP_MAGIC 0x30505645 // "EVP0". -#define EXCP_TYPE_ADDR 0x4003FFF8 +#define EXCP_TYPE_ADDR 0x4003FF18 #define EXCP_TYPE_RESET 0x545352 // "RST". #define EXCP_TYPE_UNDEF 0x464455 // "UDF". #define EXCP_TYPE_PABRT 0x54424150 // "PABT". #define EXCP_TYPE_DABRT 0x54424144 // "DABT". #define EXCP_TYPE_WDT 0x544457 // "WDT". -#define EXCP_LR_ADDR 0x4003FFF4 +#define EXCP_LR_ADDR 0x4003FF14 #define PSTORE_LOG_OFFSET 0x180000 #define PSTORE_RAM_SIG 0x43474244 // "DBGC". @@ -1426,7 +1426,7 @@ ment_t ment_top[] = { MDEF_END() }; -menu_t menu_top = { ment_top, "hekate v6.5.1", 0, 0 }; +menu_t menu_top = { ment_top, "hekate v6.5.2", 0, 0 }; extern void pivot_stack(u32 stack_top); @@ -1466,7 +1466,8 @@ void ipl_main() bpmp_clk_rate_set(h_cfg.t210b01 ? ipl_ver.rcfg.bclk_t210b01 : ipl_ver.rcfg.bclk_t210); // Mount SD Card. - h_cfg.errors |= !sd_mount() ? ERR_SD_BOOT_EN : 0; + if (sd_mount()) + h_cfg.errors |= ERR_SD_BOOT_EN; // Check if watchdog was fired previously. if (watchdog_fired()) @@ -1477,7 +1478,7 @@ void ipl_main() // Save sdram lp0 config. void *sdram_params = h_cfg.t210b01 ? sdram_get_params_t210b01() : sdram_get_params_patched(); - if (!ianos_loader("bootloader/sys/libsys_lp0.bso", DRAM_LIB, sdram_params)) + if (!ianos_static_module("bootloader/sys/libsys_lp0.bso", sdram_params)) h_cfg.errors |= ERR_LIBSYS_LP0; // Train DRAM and switch to max frequency. diff --git a/bootloader/storage/emummc.c b/bootloader/storage/emummc.c index 82072441..7c889b73 100644 --- a/bootloader/storage/emummc.c +++ b/bootloader/storage/emummc.c @@ -43,7 +43,7 @@ void emummc_load_cfg() emu_cfg.emummc_file_based_path[0] = 0; LIST_INIT(ini_sections); - if (ini_parse(&ini_sections, "emuMMC/emummc.ini", false)) + if (!ini_parse(&ini_sections, "emuMMC/emummc.ini", false)) { LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) { @@ -137,13 +137,13 @@ int emummc_storage_init_mmc() emu_cfg.active_part = 0; // Always init eMMC even when in emuMMC. eMMC is needed from the emuMMC driver anyway. - if (!emmc_initialize(false)) + if (emmc_initialize(false)) return 2; if (!emu_cfg.enabled || h_cfg.emummc_force_disable) return 0; - if (!sd_mount()) + if (sd_mount()) goto out; if (!emu_cfg.sector) @@ -180,7 +180,7 @@ int emummc_storage_end() else sd_end(); - return 1; + return 0; } int emummc_storage_read(u32 sector, u32 num_sectors, void *buf) @@ -211,21 +211,19 @@ int emummc_storage_read(u32 sector, u32 num_sectors, void *buf) if (f_open(&fp, emu_cfg.emummc_file_based_path, FA_READ)) { EPRINTF("Failed to open emuMMC image."); - return 0; + return 1; } f_lseek(&fp, (u64)sector << 9); if (f_read(&fp, buf, (u64)num_sectors << 9, NULL)) { EPRINTF("Failed to read emuMMC image."); f_close(&fp); - return 0; + return 1; } f_close(&fp); - return 1; + return 0; } - - return 1; } int emummc_storage_write(u32 sector, u32 num_sectors, void *buf) @@ -255,17 +253,17 @@ int emummc_storage_write(u32 sector, u32 num_sectors, void *buf) } if (f_open(&fp, emu_cfg.emummc_file_based_path, FA_WRITE)) - return 0; + return 1; f_lseek(&fp, (u64)sector << 9); if (f_write(&fp, buf, (u64)num_sectors << 9, NULL)) { f_close(&fp); - return 0; + return 1; } f_close(&fp); - return 1; + return 0; } } @@ -275,7 +273,7 @@ int emummc_storage_set_mmc_partition(u32 partition) emmc_set_partition(partition); if (!emu_cfg.enabled || h_cfg.emummc_force_disable || emu_cfg.sector) - return 1; + return 0; else { strcpy(emu_cfg.emummc_file_based_path, emu_cfg.path); @@ -294,8 +292,6 @@ int emummc_storage_set_mmc_partition(u32 partition) break; } - return 1; + return 0; } - - return 1; } diff --git a/modules/hekate_libsys_lp0/Makefile b/modules/hekate_libsys_lp0/Makefile index 40111e53..68a0746b 100644 --- a/modules/hekate_libsys_lp0/Makefile +++ b/modules/hekate_libsys_lp0/Makefile @@ -20,7 +20,7 @@ OBJS = $(addprefix $(BUILDDIR)/,\ ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork CFLAGS = $(ARCH) -O2 -nostdlib -fpie -ffunction-sections -fdata-sections -fomit-frame-pointer -std=gnu11 -Wall -Wsign-compare $(CUSTOMDEFINES) -LDFLAGS = $(ARCH) -fpie -pie -nostartfiles -lgcc +LDFLAGS = $(ARCH) -fpie -pie -nostartfiles -lgcc -Wl,-z,max-page-size=256 .PHONY: all diff --git a/modules/hekate_libsys_lp0/pmc_lp0_t210.h b/modules/hekate_libsys_lp0/pmc_lp0_t210.h deleted file mode 100644 index c8a259ab..00000000 --- a/modules/hekate_libsys_lp0/pmc_lp0_t210.h +++ /dev/null @@ -1,564 +0,0 @@ -/* - * Copyright (c) 2010-2015, NVIDIA CORPORATION. All rights reserved. - * - * 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. - */ - -#ifndef _TEGRA210_PMC_H_ -#define _TEGRA210_PMC_H_ - -#include "types.h" - -struct tegra_pmc_regs -{ - u32 cntrl; - u32 sec_disable; - u32 pmc_swrst; - u32 wake_mask; - u32 wake_lvl; - u32 wake_status; - u32 sw_wake_status; - u32 dpd_pads_oride; - u32 dpd_sample; - u32 dpd_enable; - u32 pwrgate_timer_off; - u32 clamp_status; - u32 pwrgate_toggle; - u32 remove_clamping_cmd; - u32 pwrgate_status; - u32 pwrgood_timer; - u32 blink_timer; - u32 no_iopower; - u32 pwr_det; - u32 pwr_det_latch; - u32 scratch0; - u32 scratch1; - u32 scratch2; - u32 scratch3; - u32 scratch4; - u32 scratch5; - u32 scratch6; - u32 scratch7; - u32 scratch8; - u32 scratch9; - u32 scratch10; - u32 scratch11; - u32 scratch12; - u32 scratch13; - u32 scratch14; - u32 scratch15; - u32 scratch16; - u32 scratch17; - u32 scratch18; - u32 scratch19; - u32 odmdata; - u32 scratch21; - u32 scratch22; - u32 scratch23; - u32 secure_scratch0; - u32 secure_scratch1; - u32 secure_scratch2; - u32 secure_scratch3; - u32 secure_scratch4; - u32 secure_scratch5; - u32 cpupwrgood_timer; - u32 cpupwroff_timer; - u32 pg_mask; - u32 pg_mask_1; - u32 auto_wake_lvl; - u32 auto_wake_lvl_mask; - u32 wake_delay; - u32 pwr_det_val; - u32 ddr_pwr; - u32 usb_debounce_del; - u32 usb_a0; - u32 crypto_op; - u32 pllp_wb0_override; - u32 scratch24; - u32 scratch25; - u32 scratch26; - u32 scratch27; - u32 scratch28; - u32 scratch29; - u32 scratch30; - u32 scratch31; - u32 scratch32; - u32 scratch33; - u32 scratch34; - u32 scratch35; - u32 scratch36; - u32 scratch37; - u32 scratch38; - u32 scratch39; - u32 scratch40; - u32 scratch41; - u32 scratch42; - u32 bondout_mirror[3]; - u32 sys_33v_en; - u32 bondout_mirror_access; - u32 gate; - u32 wake2_mask; - u32 wake2_lvl; - u32 wake2_status; - u32 sw_wake2_status; - u32 auto_wake2_lvl_mask; - u32 pg_mask_2; - u32 pg_mask_ce1; - u32 pg_mask_ce2; - u32 pg_mask_ce3; - u32 pwrgate_timer_ce[7]; - u32 pcx_edpd_cntrl; - u32 osc_edpd_over; - u32 clk_out_cntrl; - u32 sata_pwrgt; - u32 sensor_ctrl; - u32 rst_status; - u32 io_dpd_req; - u32 io_dpd_status; - u32 io_dpd2_req; - u32 io_dpd2_status; - u32 sel_dpd_tim; - u32 vddp_sel; - u32 ddr_cfg; - u32 e_no_vttgen; - u8 _rsv0[4]; - u32 pllm_wb0_override_freq; - u32 test_pwrgate; - u32 pwrgate_timer_mult; - u32 dis_sel_dpd; - u32 utmip_uhsic_triggers; - u32 utmip_uhsic_saved_state; - u32 utmip_pad_cfg; - u32 utmip_term_pad_cfg; - u32 utmip_uhsic_sleep_cfg; - u32 utmip_uhsic_sleepwalk_cfg; - u32 utmip_sleepwalk_p[3]; - u32 uhsic_sleepwalk_p0; - u32 utmip_uhsic_status; - u32 utmip_uhsic_fake; - u32 bondout_mirror3[5 - 3]; - u32 secure_scratch6; - u32 secure_scratch7; - u32 scratch43; - u32 scratch44; - u32 scratch45; - u32 scratch46; - u32 scratch47; - u32 scratch48; - u32 scratch49; - u32 scratch50; - u32 scratch51; - u32 scratch52; - u32 scratch53; - u32 scratch54; - u32 scratch55; - u32 scratch0_eco; - u32 por_dpd_ctrl; - u32 scratch2_eco; - u32 utmip_uhsic_line_wakeup; - u32 utmip_bias_master_cntrl; - u32 utmip_master_config; - u32 td_pwrgate_inter_part_timer; - u32 utmip_uhsic2_triggers; - u32 utmip_uhsic2_saved_state; - u32 utmip_uhsic2_sleep_cfg; - u32 utmip_uhsic2_sleepwalk_cfg; - u32 uhsic2_sleepwalk_p1; - u32 utmip_uhsic2_status; - u32 utmip_uhsic2_fake; - u32 utmip_uhsic2_line_wakeup; - u32 utmip_master2_config; - u32 utmip_uhsic_rpd_cfg; - u32 pg_mask_ce0; - u32 pg_mask3[5 - 3]; - u32 pllm_wb0_override2; - u32 tsc_mult; - u32 cpu_vsense_override; - u32 glb_amap_cfg; - u32 sticky_bits; - u32 sec_disable2; - u32 weak_bias; - u32 reg_short; - u32 pg_mask_andor; - u8 _rsv1[0x2c]; - u32 secure_scratch8; /* offset 0x300 */ - u32 secure_scratch9; - u32 secure_scratch10; - u32 secure_scratch11; - u32 secure_scratch12; - u32 secure_scratch13; - u32 secure_scratch14; - u32 secure_scratch15; - u32 secure_scratch16; - u32 secure_scratch17; - u32 secure_scratch18; - u32 secure_scratch19; - u32 secure_scratch20; - u32 secure_scratch21; - u32 secure_scratch22; - u32 secure_scratch23; - u32 secure_scratch24; - u32 secure_scratch25; - u32 secure_scratch26; - u32 secure_scratch27; - u32 secure_scratch28; - u32 secure_scratch29; - u32 secure_scratch30; - u32 secure_scratch31; - u32 secure_scratch32; - u32 secure_scratch33; - u32 secure_scratch34; - u32 secure_scratch35; - u32 secure_scratch36; - u32 secure_scratch37; - u32 secure_scratch38; - u32 secure_scratch39; - u32 secure_scratch40; - u32 secure_scratch41; - u32 secure_scratch42; - u32 secure_scratch43; - u32 secure_scratch44; - u32 secure_scratch45; - u32 secure_scratch46; - u32 secure_scratch47; - u32 secure_scratch48; - u32 secure_scratch49; - u32 secure_scratch50; - u32 secure_scratch51; - u32 secure_scratch52; - u32 secure_scratch53; - u32 secure_scratch54; - u32 secure_scratch55; - u32 secure_scratch56; - u32 secure_scratch57; - u32 secure_scratch58; - u32 secure_scratch59; - u32 secure_scratch60; - u32 secure_scratch61; - u32 secure_scratch62; - u32 secure_scratch63; - u32 secure_scratch64; - u32 secure_scratch65; - u32 secure_scratch66; - u32 secure_scratch67; - u32 secure_scratch68; - u32 secure_scratch69; - u32 secure_scratch70; - u32 secure_scratch71; - u32 secure_scratch72; - u32 secure_scratch73; - u32 secure_scratch74; - u32 secure_scratch75; - u32 secure_scratch76; - u32 secure_scratch77; - u32 secure_scratch78; - u32 secure_scratch79; - u32 _rsv0x420[8]; - u32 cntrl2; /* 0x440 */ - u32 _rsv0x444[2]; - u32 event_counter; /* 0x44C */ - u32 fuse_control; - u32 scratch1_eco; - u32 _rsv0x458[1]; - u32 io_dpd3_req; /* 0x45C */ - u32 io_dpd3_status; - u32 io_dpd4_req; - u32 io_dpd4_status; - u32 _rsv0x46C[30]; - u32 ddr_cntrl; /* 0x4E4 */ - u32 _rsv0x4E8[70]; - u32 scratch56; /* 0x600 */ - u32 scratch57; - u32 scratch58; - u32 scratch59; - u32 scratch60; - u32 scratch61; - u32 scratch62; - u32 scratch63; - u32 scratch64; - u32 scratch65; - u32 scratch66; - u32 scratch67; - u32 scratch68; - u32 scratch69; - u32 scratch70; - u32 scratch71; - u32 scratch72; - u32 scratch73; - u32 scratch74; - u32 scratch75; - u32 scratch76; - u32 scratch77; - u32 scratch78; - u32 scratch79; - u32 scratch80; - u32 scratch81; - u32 scratch82; - u32 scratch83; - u32 scratch84; - u32 scratch85; - u32 scratch86; - u32 scratch87; - u32 scratch88; - u32 scratch89; - u32 scratch90; - u32 scratch91; - u32 scratch92; - u32 scratch93; - u32 scratch94; - u32 scratch95; - u32 scratch96; - u32 scratch97; - u32 scratch98; - u32 scratch99; - u32 scratch100; - u32 scratch101; - u32 scratch102; - u32 scratch103; - u32 scratch104; - u32 scratch105; - u32 scratch106; - u32 scratch107; - u32 scratch108; - u32 scratch109; - u32 scratch110; - u32 scratch111; - u32 scratch112; - u32 scratch113; - u32 scratch114; - u32 scratch115; - u32 scratch116; - u32 scratch117; - u32 scratch118; - u32 scratch119; - u32 scratch120; /* 0x700 */ - u32 scratch121; - u32 scratch122; - u32 scratch123; - u32 scratch124; - u32 scratch125; - u32 scratch126; - u32 scratch127; - u32 scratch128; - u32 scratch129; - u32 scratch130; - u32 scratch131; - u32 scratch132; - u32 scratch133; - u32 scratch134; - u32 scratch135; - u32 scratch136; - u32 scratch137; - u32 scratch138; - u32 scratch139; - u32 scratch140; - u32 scratch141; - u32 scratch142; - u32 scratch143; - u32 scratch144; - u32 scratch145; - u32 scratch146; - u32 scratch147; - u32 scratch148; - u32 scratch149; - u32 scratch150; - u32 scratch151; - u32 scratch152; - u32 scratch153; - u32 scratch154; - u32 scratch155; - u32 scratch156; - u32 scratch157; - u32 scratch158; - u32 scratch159; - u32 scratch160; - u32 scratch161; - u32 scratch162; - u32 scratch163; - u32 scratch164; - u32 scratch165; - u32 scratch166; - u32 scratch167; - u32 scratch168; - u32 scratch169; - u32 scratch170; - u32 scratch171; - u32 scratch172; - u32 scratch173; - u32 scratch174; - u32 scratch175; - u32 scratch176; - u32 scratch177; - u32 scratch178; - u32 scratch179; - u32 scratch180; - u32 scratch181; - u32 scratch182; - u32 scratch183; - u32 scratch184; - u32 scratch185; - u32 scratch186; - u32 scratch187; - u32 scratch188; - u32 scratch189; - u32 scratch190; - u32 scratch191; - u32 scratch192; - u32 scratch193; - u32 scratch194; - u32 scratch195; - u32 scratch196; - u32 scratch197; - u32 scratch198; - u32 scratch199; - u32 scratch200; - u32 scratch201; - u32 scratch202; - u32 scratch203; - u32 scratch204; - u32 scratch205; - u32 scratch206; - u32 scratch207; - u32 scratch208; - u32 scratch209; - u32 scratch210; - u32 scratch211; - u32 scratch212; - u32 scratch213; - u32 scratch214; - u32 scratch215; - u32 scratch216; - u32 scratch217; - u32 scratch218; - u32 scratch219; - u32 scratch220; - u32 scratch221; - u32 scratch222; - u32 scratch223; - u32 scratch224; - u32 scratch225; - u32 scratch226; - u32 scratch227; - u32 scratch228; - u32 scratch229; - u32 scratch230; - u32 scratch231; - u32 scratch232; - u32 scratch233; - u32 scratch234; - u32 scratch235; - u32 scratch236; - u32 scratch237; - u32 scratch238; - u32 scratch239; - u32 scratch240; - u32 scratch241; - u32 scratch242; - u32 scratch243; - u32 scratch244; - u32 scratch245; - u32 scratch246; - u32 scratch247; - u32 scratch248; - u32 scratch249; - u32 scratch250; - u32 scratch251; - u32 scratch252; - u32 scratch253; - u32 scratch254; - u32 scratch255; - u32 scratch256; - u32 scratch257; - u32 scratch258; - u32 scratch259; - u32 scratch260; - u32 scratch261; - u32 scratch262; - u32 scratch263; - u32 scratch264; - u32 scratch265; - u32 scratch266; - u32 scratch267; - u32 scratch268; - u32 scratch269; - u32 scratch270; - u32 scratch271; - u32 scratch272; - u32 scratch273; - u32 scratch274; - u32 scratch275; - u32 scratch276; - u32 scratch277; - u32 scratch278; - u32 scratch279; - u32 scratch280; - u32 scratch281; - u32 scratch282; - u32 scratch283; - u32 scratch284; - u32 scratch285; - u32 scratch286; - u32 scratch287; - u32 scratch288; - u32 scratch289; - u32 scratch290; - u32 scratch291; - u32 scratch292; - u32 scratch293; - u32 scratch294; - u32 scratch295; - u32 scratch296; - u32 scratch297; - u32 scratch298; - u32 scratch299; /* 0x9CC */ - u32 _rsv0x9D0[50]; - u32 secure_scratch80; /* 0xa98 */ - u32 secure_scratch81; - u32 secure_scratch82; - u32 secure_scratch83; - u32 secure_scratch84; - u32 secure_scratch85; - u32 secure_scratch86; - u32 secure_scratch87; - u32 secure_scratch88; - u32 secure_scratch89; - u32 secure_scratch90; - u32 secure_scratch91; - u32 secure_scratch92; - u32 secure_scratch93; - u32 secure_scratch94; - u32 secure_scratch95; - u32 secure_scratch96; - u32 secure_scratch97; - u32 secure_scratch98; - u32 secure_scratch99; - u32 secure_scratch100; - u32 secure_scratch101; - u32 secure_scratch102; - u32 secure_scratch103; - u32 secure_scratch104; - u32 secure_scratch105; - u32 secure_scratch106; - u32 secure_scratch107; - u32 secure_scratch108; - u32 secure_scratch109; - u32 secure_scratch110; - u32 secure_scratch111; - u32 secure_scratch112; - u32 secure_scratch113; - u32 secure_scratch114; - u32 secure_scratch115; - u32 secure_scratch116; - u32 secure_scratch117; - u32 secure_scratch118; - u32 secure_scratch119; -}; - -#endif /* _TEGRA210_PMC_H_ */ diff --git a/modules/hekate_libsys_lp0/pmc_t210.h b/modules/hekate_libsys_lp0/pmc_t210.h new file mode 100644 index 00000000..160225e4 --- /dev/null +++ b/modules/hekate_libsys_lp0/pmc_t210.h @@ -0,0 +1,671 @@ +/* + * Copyright (c) 2018-2026 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. + */ + +#ifndef _PMC_T210_H_ +#define _PMC_T210_H_ + +#include "types.h" + +typedef struct _pmc_regs_t210_t { +/* 0x000 */ u32 pmc_cntrl; +/* 0x004 */ u32 pmc_sec_disable; +/* 0x008 */ u32 pmc_pmc_swrst; +/* 0x00c */ u32 pmc_wake_mask; +/* 0x010 */ u32 pmc_wake_lvl; +/* 0x014 */ u32 pmc_wake_status; +/* 0x018 */ u32 pmc_sw_wake_status; +/* 0x01c */ u32 pmc_dpd_pads_oride; +/* 0x020 */ u32 pmc_dpd_sample; +/* 0x024 */ u32 pmc_dpd_enable; +/* 0x028 */ u32 pmc_pwrgate_timer_off; +/* 0x02c */ u32 pmc_clamp_status; +/* 0x030 */ u32 pmc_pwrgate_toggle; +/* 0x034 */ u32 pmc_remove_clamping_cmd; +/* 0x038 */ u32 pmc_pwrgate_status; +/* 0x03c */ u32 pmc_pwrgood_timer; +/* 0x040 */ u32 pmc_blink_timer; +/* 0x044 */ u32 pmc_no_iopower; +/* 0x048 */ u32 pmc_pwr_det; +/* 0x04c */ u32 pmc_pwr_det_latch; +/* 0x050 */ u32 pmc_scratch0; +/* 0x054 */ u32 pmc_scratch1; +/* 0x058 */ u32 pmc_scratch2; +/* 0x05c */ u32 pmc_scratch3; +/* 0x060 */ u32 pmc_scratch4; +/* 0x064 */ u32 pmc_scratch5; +/* 0x068 */ u32 pmc_scratch6; +/* 0x06c */ u32 pmc_scratch7; +/* 0x070 */ u32 pmc_scratch8; +/* 0x074 */ u32 pmc_scratch9; +/* 0x078 */ u32 pmc_scratch10; +/* 0x07c */ u32 pmc_scratch11; +/* 0x080 */ u32 pmc_scratch12; +/* 0x084 */ u32 pmc_scratch13; +/* 0x088 */ u32 pmc_scratch14; +/* 0x08c */ u32 pmc_scratch15; +/* 0x090 */ u32 pmc_scratch16; +/* 0x094 */ u32 pmc_scratch17; +/* 0x098 */ u32 pmc_scratch18; +/* 0x09c */ u32 pmc_scratch19; +/* 0x0a0 */ u32 pmc_scratch20; // ODM data/config scratch. +/* 0x0a4 */ u32 pmc_scratch21; +/* 0x0a8 */ u32 pmc_scratch22; +/* 0x0ac */ u32 pmc_scratch23; +/* 0x0b0 */ u32 pmc_secure_scratch0; +/* 0x0b4 */ u32 pmc_secure_scratch1; +/* 0x0b8 */ u32 pmc_secure_scratch2; +/* 0x0bc */ u32 pmc_secure_scratch3; +/* 0x0c0 */ u32 pmc_secure_scratch4; +/* 0x0c4 */ u32 pmc_secure_scratch5; +/* 0x0c8 */ u32 pmc_cpupwrgood_timer; +/* 0x0cc */ u32 pmc_cpupwroff_timer; +/* 0x0d0 */ u32 pmc_pg_mask; +/* 0x0d4 */ u32 pmc_pg_mask_1; +/* 0x0d8 */ u32 pmc_auto_wake_lvl; +/* 0x0dc */ u32 pmc_auto_wake_lvl_mask; +/* 0x0e0 */ u32 pmc_wake_delay; +/* 0x0e4 */ u32 pmc_pwr_det_val; +/* 0x0e8 */ u32 pmc_ddr_pwr; +/* 0x0ec */ u32 pmc_usb_debounce_del; +/* 0x0f0 */ u32 pmc_usb_ao; +/* 0x0f4 */ u32 pmc_crypto_op; +/* 0x0f8 */ u32 pmc_pllp_wb0_override; +/* 0x0fc */ u32 pmc_scratch24; +/* 0x100 */ u32 pmc_scratch25; +/* 0x104 */ u32 pmc_scratch26; +/* 0x108 */ u32 pmc_scratch27; +/* 0x10c */ u32 pmc_scratch28; +/* 0x110 */ u32 pmc_scratch29; +/* 0x114 */ u32 pmc_scratch30; +/* 0x118 */ u32 pmc_scratch31; +/* 0x11c */ u32 pmc_scratch32; +/* 0x120 */ u32 pmc_scratch33; +/* 0x124 */ u32 pmc_scratch34; +/* 0x128 */ u32 pmc_scratch35; +/* 0x12c */ u32 pmc_scratch36; +/* 0x130 */ u32 pmc_scratch37; +/* 0x134 */ u32 pmc_scratch38; +/* 0x138 */ u32 pmc_scratch39; +/* 0x13c */ u32 pmc_scratch40; +/* 0x140 */ u32 pmc_scratch41; +/* 0x144 */ u32 pmc_scratch42; +/* 0x148 */ u32 pmc_bondout_mirror0; +/* 0x14c */ u32 pmc_bondout_mirror1; +/* 0x150 */ u32 pmc_bondout_mirror2; +/* 0x154 */ u32 pmc_sys_33v_en; +/* 0x158 */ u32 pmc_bondout_mirror_access; +/* 0x15c */ u32 pmc_gate; +/* 0x160 */ u32 pmc_wake2_mask; +/* 0x164 */ u32 pmc_wake2_lvl; +/* 0x168 */ u32 pmc_wake2_status; +/* 0x16c */ u32 pmc_sw_wake2_status; +/* 0x170 */ u32 pmc_auto_wake2_lvl_mask; +/* 0x174 */ u32 pmc_pg_mask_2; +/* 0x178 */ u32 pmc_pg_mask_ce1; +/* 0x17c */ u32 pmc_pg_mask_ce2; +/* 0x180 */ u32 pmc_pg_mask_ce3; +/* 0x184 */ u32 pmc_pwrgate_timer_ce_0; +/* 0x188 */ u32 pmc_pwrgate_timer_ce_1; +/* 0x18c */ u32 pmc_pwrgate_timer_ce_2; +/* 0x190 */ u32 pmc_pwrgate_timer_ce_3; +/* 0x194 */ u32 pmc_pwrgate_timer_ce_4; +/* 0x198 */ u32 pmc_pwrgate_timer_ce_5; +/* 0x19c */ u32 pmc_pwrgate_timer_ce_6; +/* 0x1a0 */ u32 pmc_pcx_edpd_cntrl; +/* 0x1a4 */ u32 pmc_osc_edpd_over; +/* 0x1a8 */ u32 pmc_clk_out_cntrl; +/* 0x1ac */ u32 pmc_sata_pwrgt; +/* 0x1b0 */ u32 pmc_sensor_ctrl; +/* 0x1b4 */ u32 pmc_rst_status; +/* 0x1b8 */ u32 pmc_io_dpd_req; +/* 0x1bc */ u32 pmc_io_dpd_status; +/* 0x1c0 */ u32 pmc_io_dpd2_req; +/* 0x1c4 */ u32 pmc_io_dpd2_status; +/* 0x1c8 */ u32 pmc_sel_dpd_tim; +/* 0x1cc */ u32 pmc_vddp_sel; +/* 0x1d0 */ u32 pmc_ddr_cfg; +/* 0x1d4 */ u32 pmc_e_no_vttgen; +/* 0x1d8 */ u32 rsvd_1d8; +/* 0x1dc */ u32 pmc_pllm_wb0_override_freq; +/* 0x1e0 */ u32 pmc_test_pwrgate; +/* 0x1e4 */ u32 pmc_pwrgate_timer_mult; +/* 0x1e8 */ u32 pmc_dsi_sel_dpd; +/* 0x1ec */ u32 pmc_utmip_uhsic_triggers; +/* 0x1f0 */ u32 pmc_utmip_uhsic_saved_state; +/* 0x1f4 */ u32 rsvd_1f4; +/* 0x1f8 */ u32 pmc_utmip_term_pad_cfg; +/* 0x1fc */ u32 pmc_utmip_uhsic_sleep_cfg; +/* 0x200 */ u32 pmc_utmip_uhsic_sleepwalk_cfg; +/* 0x204 */ u32 pmc_utmip_sleepwalk_p0; +/* 0x208 */ u32 pmc_utmip_sleepwalk_p1; +/* 0x20c */ u32 pmc_utmip_sleepwalk_p2; +/* 0x210 */ u32 pmc_uhsic_sleepwalk_p0; +/* 0x214 */ u32 pmc_utmip_uhsic_status; +/* 0x218 */ u32 pmc_utmip_uhsic_fake; +/* 0x21c */ u32 pmc_bondout_mirror3; +/* 0x220 */ u32 pmc_bondout_mirror4; +/* 0x224 */ u32 pmc_secure_scratch6; +/* 0x228 */ u32 pmc_secure_scratch7; +/* 0x22c */ u32 pmc_scratch43; +/* 0x230 */ u32 pmc_scratch44; +/* 0x234 */ u32 pmc_scratch45; +/* 0x238 */ u32 pmc_scratch46; +/* 0x23c */ u32 pmc_scratch47; +/* 0x240 */ u32 pmc_scratch48; +/* 0x244 */ u32 pmc_scratch49; +/* 0x248 */ u32 pmc_scratch50; +/* 0x24c */ u32 pmc_scratch51; +/* 0x250 */ u32 pmc_scratch52; +/* 0x254 */ u32 pmc_scratch53; +/* 0x258 */ u32 pmc_scratch54; +/* 0x25c */ u32 pmc_scratch55; +/* 0x260 */ u32 pmc_scratch0_eco; +/* 0x264 */ u32 pmc_por_dpd_ctrl; +/* 0x268 */ u32 pmc_scratch2_eco; +/* 0x26c */ u32 pmc_utmip_uhsic_line_wakeup; +/* 0x270 */ u32 pmc_utmip_bias_master_cntrl; +/* 0x274 */ u32 pmc_utmip_master_config; +/* 0x278 */ u32 pmc_td_pwrgate_inter_part_timer; +/* 0x27c */ u32 pmc_utmip_uhsic2_triggers; +/* 0x280 */ u32 pmc_utmip_uhsic2_saved_state; +/* 0x284 */ u32 pmc_utmip_uhsic2_sleep_cfg; +/* 0x288 */ u32 pmc_utmip_uhsic2_sleepwalk_cfg; +/* 0x28c */ u32 pmc_uhsic2_sleepwalk_p1; +/* 0x290 */ u32 pmc_utmip_uhsic2_status; +/* 0x294 */ u32 pmc_utmip_uhsic2_fake; +/* 0x298 */ u32 pmc_utmip_uhsic2_line_wakeup; +/* 0x29c */ u32 pmc_utmip_master2_config; +/* 0x2a0 */ u32 pmc_utmip_uhsic_rpd_cfg; +/* 0x2a4 */ u32 pmc_pg_mask_ce0; +/* 0x2a8 */ u32 pmc_pg_mask_3; +/* 0x2ac */ u32 pmc_pg_mask_4; +/* 0x2b0 */ u32 pmc_pllm_wb0_override2; +/* 0x2b4 */ u32 pmc_tsc_mult; +/* 0x2b8 */ u32 pmc_cpu_vsense_override; +/* 0x2bc */ u32 pmc_glb_amap_cfg; +/* 0x2c0 */ u32 pmc_sticky_bits; +/* 0x2c4 */ u32 pmc_sec_disable2; +/* 0x2c8 */ u32 pmc_weak_bias; +/* 0x2cc */ u32 pmc_reg_short; +/* 0x2d0 */ u32 pmc_pg_mask_andor; +/* 0x2d4 */ u32 pmc_gpu_rg_cntrl; +/* 0x2d8 */ u32 pmc_sec_disable3; +/* 0x2dc */ u32 pmc_pg_mask_5; +/* 0x2e0 */ u32 pmc_pg_mask_6; +/* 0x2e4 */ u32 rsvd_2e4[7]; +/* 0x300 */ u32 pmc_secure_scratch8; +/* 0x304 */ u32 pmc_secure_scratch9; +/* 0x308 */ u32 pmc_secure_scratch10; +/* 0x30c */ u32 pmc_secure_scratch11; +/* 0x310 */ u32 pmc_secure_scratch12; +/* 0x314 */ u32 pmc_secure_scratch13; +/* 0x318 */ u32 pmc_secure_scratch14; +/* 0x31c */ u32 pmc_secure_scratch15; +/* 0x320 */ u32 pmc_secure_scratch16; +/* 0x324 */ u32 pmc_secure_scratch17; +/* 0x328 */ u32 pmc_secure_scratch18; +/* 0x32c */ u32 pmc_secure_scratch19; +/* 0x330 */ u32 pmc_secure_scratch20; +/* 0x334 */ u32 pmc_secure_scratch21; +/* 0x338 */ u32 pmc_secure_scratch22; // AArch32 reset address. +/* 0x33c */ u32 pmc_secure_scratch23; +/* 0x340 */ u32 pmc_secure_scratch24; +/* 0x344 */ u32 pmc_secure_scratch25; +/* 0x348 */ u32 pmc_secure_scratch26; +/* 0x34c */ u32 pmc_secure_scratch27; +/* 0x350 */ u32 pmc_secure_scratch28; +/* 0x354 */ u32 pmc_secure_scratch29; +/* 0x358 */ u32 pmc_secure_scratch30; +/* 0x35c */ u32 pmc_secure_scratch31; +/* 0x360 */ u32 pmc_secure_scratch32; +/* 0x364 */ u32 pmc_secure_scratch33; +/* 0x368 */ u32 pmc_secure_scratch34; // AArch64 reset address. +/* 0x36c */ u32 pmc_secure_scratch35; // AArch64 reset hi-address. +/* 0x370 */ u32 pmc_secure_scratch36; +/* 0x374 */ u32 pmc_secure_scratch37; +/* 0x378 */ u32 pmc_secure_scratch38; +/* 0x37c */ u32 pmc_secure_scratch39; +/* 0x380 */ u32 pmc_secure_scratch40; +/* 0x384 */ u32 pmc_secure_scratch41; +/* 0x388 */ u32 pmc_secure_scratch42; +/* 0x38c */ u32 pmc_secure_scratch43; +/* 0x390 */ u32 pmc_secure_scratch44; +/* 0x394 */ u32 pmc_secure_scratch45; +/* 0x398 */ u32 pmc_secure_scratch46; +/* 0x39c */ u32 pmc_secure_scratch47; +/* 0x3a0 */ u32 pmc_secure_scratch48; +/* 0x3a4 */ u32 pmc_secure_scratch49; +/* 0x3a8 */ u32 pmc_secure_scratch50; +/* 0x3ac */ u32 pmc_secure_scratch51; +/* 0x3b0 */ u32 pmc_secure_scratch52; +/* 0x3b4 */ u32 pmc_secure_scratch53; +/* 0x3b8 */ u32 pmc_secure_scratch54; +/* 0x3bc */ u32 pmc_secure_scratch55; +/* 0x3c0 */ u32 pmc_secure_scratch56; +/* 0x3c4 */ u32 pmc_secure_scratch57; +/* 0x3c8 */ u32 pmc_secure_scratch58; +/* 0x3cc */ u32 pmc_secure_scratch59; +/* 0x3d0 */ u32 pmc_secure_scratch60; +/* 0x3d4 */ u32 pmc_secure_scratch61; +/* 0x3d8 */ u32 pmc_secure_scratch62; +/* 0x3dc */ u32 pmc_secure_scratch63; +/* 0x3e0 */ u32 pmc_secure_scratch64; +/* 0x3e4 */ u32 pmc_secure_scratch65; +/* 0x3e8 */ u32 pmc_secure_scratch66; +/* 0x3ec */ u32 pmc_secure_scratch67; +/* 0x3f0 */ u32 pmc_secure_scratch68; +/* 0x3f4 */ u32 pmc_secure_scratch69; +/* 0x3f8 */ u32 pmc_secure_scratch70; +/* 0x3fc */ u32 pmc_secure_scratch71; +/* 0x400 */ u32 pmc_secure_scratch72; +/* 0x404 */ u32 pmc_secure_scratch73; +/* 0x408 */ u32 pmc_secure_scratch74; +/* 0x40c */ u32 pmc_secure_scratch75; +/* 0x410 */ u32 pmc_secure_scratch76; +/* 0x414 */ u32 pmc_secure_scratch77; +/* 0x418 */ u32 pmc_secure_scratch78; +/* 0x41c */ u32 pmc_secure_scratch79; +/* 0x420 */ u32 rsvd_420[8]; +/* 0x440 */ u32 pmc_cntrl2; +/* 0x444 */ u32 pmc_io_dpd_off_mask; +/* 0x448 */ u32 pmc_io_dpd2_off_mask; +/* 0x44c */ u32 pmc_event_counter; +/* 0x450 */ u32 pmc_fuse_control; +/* 0x454 */ u32 pmc_scratch1_eco; +/* 0x458 */ u32 rsvd_458; +/* 0x45c */ u32 pmc_io_dpd3_req; +/* 0x460 */ u32 pmc_io_dpd3_status; +/* 0x464 */ u32 pmc_io_dpd4_req; +/* 0x468 */ u32 pmc_io_dpd4_status; +/* 0x46c */ u32 rsvd_46c[2]; +/* 0x474 */ u32 pmc_direct_thermtrip_cfg; +/* 0x478 */ u32 pmc_tsosc_delay; +/* 0x47c */ u32 pmc_set_sw_clamp; +/* 0x480 */ u32 pmc_debug_authentication; +/* 0x484 */ u32 pmc_aotag_cfg; +/* 0x488 */ u32 pmc_aotag_thresh1_cfg; +/* 0x48c */ u32 pmc_aotag_thresh2_cfg; +/* 0x490 */ u32 pmc_aotag_thresh3_cfg; +/* 0x494 */ u32 pmc_aotag_status; +/* 0x498 */ u32 pmc_aotag_security; +/* 0x49c */ u32 pmc_tsensor_config0; +/* 0x4a0 */ u32 pmc_tsensor_config1; +/* 0x4a4 */ u32 pmc_tsensor_config2; +/* 0x4a8 */ u32 pmc_tsensor_status0; +/* 0x4ac */ u32 pmc_tsensor_status1; +/* 0x4b0 */ u32 pmc_tsensor_status2; +/* 0x4b4 */ u32 pmc_tsensor_pdiv; +/* 0x4b8 */ u32 pmc_aotag_intr_en; +/* 0x4bc */ u32 pmc_aotag_intr_dis; +/* 0x4c0 */ u32 pmc_utmip_pad_cfg0; +/* 0x4c4 */ u32 pmc_utmip_pad_cfg1; +/* 0x4c8 */ u32 pmc_utmip_pad_cfg2; +/* 0x4cc */ u32 pmc_utmip_pad_cfg3; +/* 0x4d0 */ u32 pmc_utmip_uhsic_sleep_cfg1; +/* 0x4d4 */ u32 pmc_cc4_hvc_control; +/* 0x4d8 */ u32 pmc_wake_debounce_en; +/* 0x4dc */ u32 pmc_ramdump_ctl_status; +/* 0x4e0 */ u32 pmc_utmip_sleepwalk_p3; +/* 0x4e4 */ u32 pmc_ddr_cntrl; +/* 0x4e8 */ u32 rsvd_4e8[50]; +/* 0x5b0 */ u32 pmc_sec_disable4; +/* 0x5b4 */ u32 pmc_sec_disable5; +/* 0x5b8 */ u32 pmc_sec_disable6; +/* 0x5bc */ u32 pmc_sec_disable7; +/* 0x5c0 */ u32 pmc_sec_disable8; +/* 0x5c4 */ u32 pmc_sec_disable9_b01; +/* 0x5c8 */ u32 pmc_sec_disable10_b01; +/* 0x5cc */ u32 rsvd_5cc[13]; +/* 0x600 */ u32 pmc_scratch56; +/* 0x604 */ u32 pmc_scratch57; +/* 0x608 */ u32 pmc_scratch58; +/* 0x60c */ u32 pmc_scratch59; +/* 0x610 */ u32 pmc_scratch60; +/* 0x614 */ u32 pmc_scratch61; +/* 0x618 */ u32 pmc_scratch62; +/* 0x61c */ u32 pmc_scratch63; +/* 0x620 */ u32 pmc_scratch64; +/* 0x624 */ u32 pmc_scratch65; +/* 0x628 */ u32 pmc_scratch66; +/* 0x62c */ u32 pmc_scratch67; +/* 0x630 */ u32 pmc_scratch68; +/* 0x634 */ u32 pmc_scratch69; +/* 0x638 */ u32 pmc_scratch70; +/* 0x63c */ u32 pmc_scratch71; +/* 0x640 */ u32 pmc_scratch72; +/* 0x644 */ u32 pmc_scratch73; +/* 0x648 */ u32 pmc_scratch74; +/* 0x64c */ u32 pmc_scratch75; +/* 0x650 */ u32 pmc_scratch76; +/* 0x654 */ u32 pmc_scratch77; +/* 0x658 */ u32 pmc_scratch78; +/* 0x65c */ u32 pmc_scratch79; +/* 0x660 */ u32 pmc_scratch80; +/* 0x664 */ u32 pmc_scratch81; +/* 0x668 */ u32 pmc_scratch82; +/* 0x66c */ u32 pmc_scratch83; +/* 0x670 */ u32 pmc_scratch84; +/* 0x674 */ u32 pmc_scratch85; +/* 0x678 */ u32 pmc_scratch86; +/* 0x67c */ u32 pmc_scratch87; +/* 0x680 */ u32 pmc_scratch88; +/* 0x684 */ u32 pmc_scratch89; +/* 0x688 */ u32 pmc_scratch90; +/* 0x68c */ u32 pmc_scratch91; +/* 0x690 */ u32 pmc_scratch92; +/* 0x694 */ u32 pmc_scratch93; +/* 0x698 */ u32 pmc_scratch94; +/* 0x69c */ u32 pmc_scratch95; +/* 0x6a0 */ u32 pmc_scratch96; +/* 0x6a4 */ u32 pmc_scratch97; +/* 0x6a8 */ u32 pmc_scratch98; +/* 0x6ac */ u32 pmc_scratch99; +/* 0x6b0 */ u32 pmc_scratch100; +/* 0x6b4 */ u32 pmc_scratch101; +/* 0x6b8 */ u32 pmc_scratch102; +/* 0x6bc */ u32 pmc_scratch103; +/* 0x6c0 */ u32 pmc_scratch104; +/* 0x6c4 */ u32 pmc_scratch105; +/* 0x6c8 */ u32 pmc_scratch106; +/* 0x6cc */ u32 pmc_scratch107; +/* 0x6d0 */ u32 pmc_scratch108; +/* 0x6d4 */ u32 pmc_scratch109; +/* 0x6d8 */ u32 pmc_scratch110; +/* 0x6dc */ u32 pmc_scratch111; +/* 0x6e0 */ u32 pmc_scratch112; +/* 0x6e4 */ u32 pmc_scratch113; +/* 0x6e8 */ u32 pmc_scratch114; +/* 0x6ec */ u32 pmc_scratch115; +/* 0x6f0 */ u32 pmc_scratch116; +/* 0x6f4 */ u32 pmc_scratch117; +/* 0x6f8 */ u32 pmc_scratch118; +/* 0x6fc */ u32 pmc_scratch119; +/* 0x700 */ u32 pmc_scratch120; +/* 0x704 */ u32 pmc_scratch121; +/* 0x708 */ u32 pmc_scratch122; +/* 0x70c */ u32 pmc_scratch123; +/* 0x710 */ u32 pmc_scratch124; +/* 0x714 */ u32 pmc_scratch125; +/* 0x718 */ u32 pmc_scratch126; +/* 0x71c */ u32 pmc_scratch127; +/* 0x720 */ u32 pmc_scratch128; +/* 0x724 */ u32 pmc_scratch129; +/* 0x728 */ u32 pmc_scratch130; +/* 0x72c */ u32 pmc_scratch131; +/* 0x730 */ u32 pmc_scratch132; +/* 0x734 */ u32 pmc_scratch133; +/* 0x738 */ u32 pmc_scratch134; +/* 0x73c */ u32 pmc_scratch135; +/* 0x740 */ u32 pmc_scratch136; +/* 0x744 */ u32 pmc_scratch137; +/* 0x748 */ u32 pmc_scratch138; +/* 0x74c */ u32 pmc_scratch139; +/* 0x750 */ u32 pmc_scratch140; +/* 0x754 */ u32 pmc_scratch141; +/* 0x758 */ u32 pmc_scratch142; +/* 0x75c */ u32 pmc_scratch143; +/* 0x760 */ u32 pmc_scratch144; +/* 0x764 */ u32 pmc_scratch145; +/* 0x768 */ u32 pmc_scratch146; +/* 0x76c */ u32 pmc_scratch147; +/* 0x770 */ u32 pmc_scratch148; +/* 0x774 */ u32 pmc_scratch149; +/* 0x778 */ u32 pmc_scratch150; +/* 0x77c */ u32 pmc_scratch151; +/* 0x780 */ u32 pmc_scratch152; +/* 0x784 */ u32 pmc_scratch153; +/* 0x788 */ u32 pmc_scratch154; +/* 0x78c */ u32 pmc_scratch155; +/* 0x790 */ u32 pmc_scratch156; +/* 0x794 */ u32 pmc_scratch157; +/* 0x798 */ u32 pmc_scratch158; +/* 0x79c */ u32 pmc_scratch159; +/* 0x7a0 */ u32 pmc_scratch160; +/* 0x7a4 */ u32 pmc_scratch161; +/* 0x7a8 */ u32 pmc_scratch162; +/* 0x7ac */ u32 pmc_scratch163; +/* 0x7b0 */ u32 pmc_scratch164; +/* 0x7b4 */ u32 pmc_scratch165; +/* 0x7b8 */ u32 pmc_scratch166; +/* 0x7bc */ u32 pmc_scratch167; +/* 0x7c0 */ u32 pmc_scratch168; +/* 0x7c4 */ u32 pmc_scratch169; +/* 0x7c8 */ u32 pmc_scratch170; +/* 0x7cc */ u32 pmc_scratch171; +/* 0x7d0 */ u32 pmc_scratch172; +/* 0x7d4 */ u32 pmc_scratch173; +/* 0x7d8 */ u32 pmc_scratch174; +/* 0x7dc */ u32 pmc_scratch175; +/* 0x7e0 */ u32 pmc_scratch176; +/* 0x7e4 */ u32 pmc_scratch177; +/* 0x7e8 */ u32 pmc_scratch178; +/* 0x7ec */ u32 pmc_scratch179; +/* 0x7f0 */ u32 pmc_scratch180; +/* 0x7f4 */ u32 pmc_scratch181; +/* 0x7f8 */ u32 pmc_scratch182; +/* 0x7fc */ u32 pmc_scratch183; +/* 0x800 */ u32 pmc_scratch184; +/* 0x804 */ u32 pmc_scratch185; +/* 0x808 */ u32 pmc_scratch186; +/* 0x80c */ u32 pmc_scratch187; +/* 0x810 */ u32 pmc_scratch188; +/* 0x814 */ u32 pmc_scratch189; +/* 0x818 */ u32 pmc_scratch190; +/* 0x81c */ u32 pmc_scratch191; +/* 0x820 */ u32 pmc_scratch192; +/* 0x824 */ u32 pmc_scratch193; +/* 0x828 */ u32 pmc_scratch194; +/* 0x82c */ u32 pmc_scratch195; +/* 0x830 */ u32 pmc_scratch196; +/* 0x834 */ u32 pmc_scratch197; +/* 0x838 */ u32 pmc_scratch198; +/* 0x83c */ u32 pmc_scratch199; +/* 0x840 */ u32 pmc_scratch200; +/* 0x844 */ u32 pmc_scratch201; +/* 0x848 */ u32 pmc_scratch202; +/* 0x84c */ u32 pmc_scratch203; +/* 0x850 */ u32 pmc_scratch204; +/* 0x854 */ u32 pmc_scratch205; +/* 0x858 */ u32 pmc_scratch206; +/* 0x85c */ u32 pmc_scratch207; +/* 0x860 */ u32 pmc_scratch208; +/* 0x864 */ u32 pmc_scratch209; +/* 0x868 */ u32 pmc_scratch210; +/* 0x86c */ u32 pmc_scratch211; +/* 0x870 */ u32 pmc_scratch212; +/* 0x874 */ u32 pmc_scratch213; +/* 0x878 */ u32 pmc_scratch214; +/* 0x87c */ u32 pmc_scratch215; +/* 0x880 */ u32 pmc_scratch216; +/* 0x884 */ u32 pmc_scratch217; +/* 0x888 */ u32 pmc_scratch218; +/* 0x88c */ u32 pmc_scratch219; +/* 0x890 */ u32 pmc_scratch220; +/* 0x894 */ u32 pmc_scratch221; +/* 0x898 */ u32 pmc_scratch222; +/* 0x89c */ u32 pmc_scratch223; +/* 0x8a0 */ u32 pmc_scratch224; +/* 0x8a4 */ u32 pmc_scratch225; +/* 0x8a8 */ u32 pmc_scratch226; +/* 0x8ac */ u32 pmc_scratch227; +/* 0x8b0 */ u32 pmc_scratch228; +/* 0x8b4 */ u32 pmc_scratch229; +/* 0x8b8 */ u32 pmc_scratch230; +/* 0x8bc */ u32 pmc_scratch231; +/* 0x8c0 */ u32 pmc_scratch232; +/* 0x8c4 */ u32 pmc_scratch233; +/* 0x8c8 */ u32 pmc_scratch234; +/* 0x8cc */ u32 pmc_scratch235; +/* 0x8d0 */ u32 pmc_scratch236; +/* 0x8d4 */ u32 pmc_scratch237; +/* 0x8d8 */ u32 pmc_scratch238; +/* 0x8dc */ u32 pmc_scratch239; +/* 0x8e0 */ u32 pmc_scratch240; +/* 0x8e4 */ u32 pmc_scratch241; +/* 0x8e8 */ u32 pmc_scratch242; +/* 0x8ec */ u32 pmc_scratch243; +/* 0x8f0 */ u32 pmc_scratch244; +/* 0x8f4 */ u32 pmc_scratch245; +/* 0x8f8 */ u32 pmc_scratch246; +/* 0x8fc */ u32 pmc_scratch247; +/* 0x900 */ u32 pmc_scratch248; +/* 0x904 */ u32 pmc_scratch249; +/* 0x908 */ u32 pmc_scratch250; +/* 0x90c */ u32 pmc_scratch251; +/* 0x910 */ u32 pmc_scratch252; +/* 0x914 */ u32 pmc_scratch253; +/* 0x918 */ u32 pmc_scratch254; +/* 0x91c */ u32 pmc_scratch255; +/* 0x920 */ u32 pmc_scratch256; +/* 0x924 */ u32 pmc_scratch257; +/* 0x928 */ u32 pmc_scratch258; +/* 0x92c */ u32 pmc_scratch259; +/* 0x930 */ u32 pmc_scratch260; +/* 0x934 */ u32 pmc_scratch261; +/* 0x938 */ u32 pmc_scratch262; +/* 0x93c */ u32 pmc_scratch263; +/* 0x940 */ u32 pmc_scratch264; +/* 0x944 */ u32 pmc_scratch265; +/* 0x948 */ u32 pmc_scratch266; +/* 0x94c */ u32 pmc_scratch267; +/* 0x950 */ u32 pmc_scratch268; +/* 0x954 */ u32 pmc_scratch269; +/* 0x958 */ u32 pmc_scratch270; +/* 0x95c */ u32 pmc_scratch271; +/* 0x960 */ u32 pmc_scratch272; +/* 0x964 */ u32 pmc_scratch273; +/* 0x968 */ u32 pmc_scratch274; +/* 0x96c */ u32 pmc_scratch275; +/* 0x970 */ u32 pmc_scratch276; +/* 0x974 */ u32 pmc_scratch277; +/* 0x978 */ u32 pmc_scratch278; +/* 0x97c */ u32 pmc_scratch279; +/* 0x980 */ u32 pmc_scratch280; +/* 0x984 */ u32 pmc_scratch281; +/* 0x988 */ u32 pmc_scratch282; +/* 0x98c */ u32 pmc_scratch283; +/* 0x990 */ u32 pmc_scratch284; +/* 0x994 */ u32 pmc_scratch285; +/* 0x998 */ u32 pmc_scratch286; +/* 0x99c */ u32 pmc_scratch287; +/* 0x9a0 */ u32 pmc_scratch288; +/* 0x9a4 */ u32 pmc_scratch289; +/* 0x9a8 */ u32 pmc_scratch290; +/* 0x9ac */ u32 pmc_scratch291; +/* 0x9b0 */ u32 pmc_scratch292; +/* 0x9b4 */ u32 pmc_scratch293; +/* 0x9b8 */ u32 pmc_scratch294; +/* 0x9bc */ u32 pmc_scratch295; +/* 0x9c0 */ u32 pmc_scratch296; +/* 0x9c4 */ u32 pmc_scratch297; +/* 0x9c8 */ u32 pmc_scratch298; +/* 0x9cc */ u32 pmc_scratch299; +/* 0x9d0 */ u32 rsvd_9d0[30]; +/* 0xa48 */ u32 pmc_scratch_write_disable0_b01; +/* 0xa4c */ u32 pmc_scratch_write_disable1_b01; +/* 0xa50 */ u32 pmc_scratch_write_disable2_b01; +/* 0xa54 */ u32 pmc_scratch_write_disable3_b01; +/* 0xa58 */ u32 pmc_scratch_write_disable4_b01; +/* 0xa5c */ u32 pmc_scratch_write_disable5_b01; +/* 0xa60 */ u32 pmc_scratch_write_disable6_b01; +/* 0xa64 */ u32 pmc_scratch_write_disable7_b01; +/* 0xa68 */ u32 pmc_scratch_write_disable8_b01; +/* 0xa6c */ u32 pmc_scratch_write_disable9_b01; +/* 0xa70 */ u32 pmc_scratch_write_disable10_b01; +/* 0xa74 */ u32 pmc_scratch_write_lock_disable_sticky_b01; +/* 0xa78 */ u32 rsvd_a78[8]; +/* 0xa98 */ u32 pmc_secure_scratch80; +/* 0xa9c */ u32 pmc_secure_scratch81; +/* 0xaa0 */ u32 pmc_secure_scratch82; +/* 0xaa4 */ u32 pmc_secure_scratch83; +/* 0xaa8 */ u32 pmc_secure_scratch84; +/* 0xaac */ u32 pmc_secure_scratch85; +/* 0xab0 */ u32 pmc_secure_scratch86; +/* 0xab4 */ u32 pmc_secure_scratch87; +/* 0xab8 */ u32 pmc_secure_scratch88; +/* 0xabc */ u32 pmc_secure_scratch89; +/* 0xac0 */ u32 pmc_secure_scratch90; +/* 0xac4 */ u32 pmc_secure_scratch91; +/* 0xac8 */ u32 pmc_secure_scratch92; +/* 0xacc */ u32 pmc_secure_scratch93; +/* 0xad0 */ u32 pmc_secure_scratch94; +/* 0xad4 */ u32 pmc_secure_scratch95; +/* 0xad8 */ u32 pmc_secure_scratch96; +/* 0xadc */ u32 pmc_secure_scratch97; +/* 0xae0 */ u32 pmc_secure_scratch98; +/* 0xae4 */ u32 pmc_secure_scratch99; +/* 0xae8 */ u32 pmc_secure_scratch100; +/* 0xaec */ u32 pmc_secure_scratch101; +/* 0xaf0 */ u32 pmc_secure_scratch102; +/* 0xaf4 */ u32 pmc_secure_scratch103; +/* 0xaf8 */ u32 pmc_secure_scratch104; +/* 0xafc */ u32 pmc_secure_scratch105; +/* 0xb00 */ u32 pmc_secure_scratch106; +/* 0xb04 */ u32 pmc_secure_scratch107; +/* 0xb08 */ u32 pmc_secure_scratch108; +/* 0xb0c */ u32 pmc_secure_scratch109; +/* 0xb10 */ u32 pmc_secure_scratch110; +/* 0xb14 */ u32 pmc_secure_scratch111; +/* 0xb18 */ u32 pmc_secure_scratch112; +/* 0xb1c */ u32 pmc_secure_scratch113; +/* 0xb20 */ u32 pmc_secure_scratch114; +/* 0xb24 */ u32 pmc_secure_scratch115; +/* 0xb28 */ u32 pmc_secure_scratch116; +/* 0xb2c */ u32 pmc_secure_scratch117; +/* 0xb30 */ u32 pmc_secure_scratch118; +/* 0xb34 */ u32 pmc_secure_scratch119; +/* 0xb38 */ u32 pmc_secure_scratch120_b01; +/* 0xb3c */ u32 pmc_secure_scratch121_b01; +/* 0xb40 */ u32 pmc_secure_scratch122_b01; +/* 0xb44 */ u32 pmc_secure_scratch123_b01; +/* 0xb48 */ u32 pmc_led_breathing_ctrl_b01; +/* 0xb4c */ u32 pmc_led_breathing_counter0_b01; // Slope Steps. +/* 0xb50 */ u32 pmc_led_breathing_counter1_b01; // ON counter. +/* 0xb54 */ u32 pmc_led_breathing_counter2_b01; // OFF counter1. +/* 0xb58 */ u32 pmc_led_breathing_counter3_b01; // OFF counter0. +/* 0xb5c */ u32 pmc_led_breathing_status_b01; +/* 0xb60 */ u32 rsvd_b60[2]; +/* 0xb68 */ u32 pmc_secure_scratch124_b01; +/* 0xb6c */ u32 pmc_secure_scratch125_b01; +/* 0xb70 */ u32 pmc_secure_scratch126_b01; +/* 0xb74 */ u32 pmc_secure_scratch127_b01; +/* 0xb78 */ u32 pmc_secure_scratch128_b01; +/* 0xb7c */ u32 pmc_secure_scratch129_b01; +/* 0xb80 */ u32 pmc_secure_scratch130_b01; +/* 0xb84 */ u32 pmc_secure_scratch131_b01; +/* 0xb88 */ u32 pmc_secure_scratch132_b01; +/* 0xb8c */ u32 pmc_secure_scratch133_b01; +/* 0xb90 */ u32 pmc_secure_scratch134_b01; +/* 0xb94 */ u32 pmc_secure_scratch135_b01; +/* 0xb98 */ u32 pmc_secure_scratch136_b01; +/* 0xb9c */ u32 pmc_secure_scratch137_b01; +/* 0xba0 */ u32 pmc_secure_scratch138_b01; +/* 0xba4 */ u32 pmc_secure_scratch139_b01; +/* 0xba8 */ u32 rsvd_ba8[2]; +/* 0xbb0 */ u32 pmc_sec_disable_ns_b01; +/* 0xbb4 */ u32 pmc_sec_disable2_ns_b01; +/* 0xbb8 */ u32 pmc_sec_disable3_ns_b01; +/* 0xbbc */ u32 pmc_sec_disable4_ns_b01; +/* 0xbc0 */ u32 pmc_sec_disable5_ns_b01; +/* 0xbc4 */ u32 pmc_sec_disable6_ns_b01; +/* 0xbc8 */ u32 pmc_sec_disable7_ns_b01; +/* 0xbcc */ u32 pmc_sec_disable8_ns_b01; +/* 0xbd0 */ u32 pmc_sec_disable9_ns_b01; +/* 0xbd4 */ u32 pmc_sec_disable10_ns_b01; +/* 0xbd8 */ u32 rsvd_bd8[4]; +/* 0xbe8 */ u32 pmc_tzram_pwr_cntrl_b01; +/* 0xbec */ u32 pmc_tzram_sec_disable_b01; +/* 0xbf0 */ u32 pmc_tzram_non_sec_disable_b01; +} pmc_regs_t210_t; + +#endif /* _PMC_T210_H_ */ diff --git a/modules/hekate_libsys_lp0/sdram_lp0_param_t210.h b/modules/hekate_libsys_lp0/sdram_lp0_param_t210.h index fc4688a5..2af48ffc 100644 --- a/modules/hekate_libsys_lp0/sdram_lp0_param_t210.h +++ b/modules/hekate_libsys_lp0/sdram_lp0_param_t210.h @@ -57,7 +57,7 @@ enum /** * Defines the SDRAM parameter structure */ -struct sdram_params_t210 +typedef struct _sdram_params_t210_t { /* Specifies the type of memory device */ @@ -959,6 +959,6 @@ struct sdram_params_t210 u32 McMtsCarveoutRegCtrl; /* End */ -}; +} sdram_params_t210_t; #endif /* __SOC_NVIDIA_TEGRA210_SDRAM_PARAM_H__ */ diff --git a/modules/hekate_libsys_lp0/sdram_lp0_param_t210b01.h b/modules/hekate_libsys_lp0/sdram_lp0_param_t210b01.h index 924c766d..59a63901 100644 --- a/modules/hekate_libsys_lp0/sdram_lp0_param_t210b01.h +++ b/modules/hekate_libsys_lp0/sdram_lp0_param_t210b01.h @@ -16,7 +16,7 @@ #include "types.h" -struct sdram_params_t210b01 +typedef struct _sdram_params_t210b01_t { /* Specifies the type of memory device */ u32 memory_type; @@ -986,6 +986,6 @@ struct sdram_params_t210b01 /* Just a place holder for special usage when there is no BCT for certain registers */ u32 bct_na; -}; +} sdram_params_t210b01_t; #endif diff --git a/modules/hekate_libsys_lp0/sys_sdramlp0.c b/modules/hekate_libsys_lp0/sys_sdramlp0.c index ddc09800..b69508d7 100644 --- a/modules/hekate_libsys_lp0/sys_sdramlp0.c +++ b/modules/hekate_libsys_lp0/sys_sdramlp0.c @@ -2,7 +2,7 @@ * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved. * Copyright 2014 Google Inc. * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2020 CTCaer + * Copyright (c) 2018-2026 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, @@ -15,114 +15,39 @@ */ #include "t210.h" -#include "pmc_lp0_t210.h" +#include "pmc_t210.h" #include "sdram_lp0_param_t210.h" #include "sdram_lp0_param_t210b01.h" #include #define pack(src, src_bits, dst, dst_bits) { \ - u32 mask = 0xffffffff >> (31 - ((1 ? src_bits) - (0 ? src_bits))); \ + u32 mask = 0xFFFFFFFF >> (31 - ((1 ? src_bits) - (0 ? src_bits))); \ dst &= ~(mask << (0 ? dst_bits)); \ dst |= ((src >> (0 ? src_bits)) & mask) << (0 ? dst_bits); \ } #define s(param, src_bits, pmcreg, dst_bits) \ - pack(sdram->param, src_bits, pmc->pmcreg, dst_bits) + pack(sdram->param, src_bits, pmc->pmc_ ## pmcreg, dst_bits) #define c(value, pmcreg, dst_bits) \ - pack(value, (1 ? dst_bits) - (0 ? dst_bits) : 0, pmc->pmcreg, dst_bits) + pack(value, (1 ? dst_bits) - (0 ? dst_bits) : 0, pmc->pmc_ ## pmcreg, dst_bits) /* 32 bits version of s macro */ -#define s32(param, pmcreg) pmc->pmcreg = sdram->param +#define s32(param, pmcreg) pmc->pmc_ ## pmcreg = sdram->param /* 32 bits version c macro */ -#define c32(value, pmcreg) pmc->pmcreg = value +#define c32(value, pmcreg) pmc->pmc_ ## pmcreg = value /* * This function reads SDRAM parameters from the common BCT format and * writes them into PMC scratch registers (where the BootROM expects them * on LP0 resume). */ -static void _sdram_lp0_save_params_t210(const void *params) +static void _sdram_lp0_save_params_t210(sdram_params_t210_t *sdram) { - struct sdram_params_t210 *sdram = (struct sdram_params_t210 *)params; - struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs *)PMC_BASE; + pmc_regs_t210_t *pmc = (pmc_regs_t210_t *)PMC_BASE; - //TODO: pkg1.1 (1.X - 3.X) reads them from MC. - // Patch carveout parameters. - /*sdram->McGeneralizedCarveout1Bom = 0; - sdram->McGeneralizedCarveout1BomHi = 0; - sdram->McGeneralizedCarveout1Size128kb = 0; - sdram->McGeneralizedCarveout1Access0 = 0; - sdram->McGeneralizedCarveout1Access1 = 0; - sdram->McGeneralizedCarveout1Access2 = 0; - sdram->McGeneralizedCarveout1Access3 = 0; - sdram->McGeneralizedCarveout1Access4 = 0; - sdram->McGeneralizedCarveout1ForceInternalAccess0 = 0; - sdram->McGeneralizedCarveout1ForceInternalAccess1 = 0; - sdram->McGeneralizedCarveout1ForceInternalAccess2 = 0; - sdram->McGeneralizedCarveout1ForceInternalAccess3 = 0; - sdram->McGeneralizedCarveout1ForceInternalAccess4 = 0; - sdram->McGeneralizedCarveout1Cfg0 = 0; - sdram->McGeneralizedCarveout2Bom = 0x80020000; - sdram->McGeneralizedCarveout2BomHi = 0; - sdram->McGeneralizedCarveout2Size128kb = 2; - sdram->McGeneralizedCarveout2Access0 = 0; - sdram->McGeneralizedCarveout2Access1 = 0; - sdram->McGeneralizedCarveout2Access2 = 0x3000000; - sdram->McGeneralizedCarveout2Access3 = 0; - sdram->McGeneralizedCarveout2Access4 = 0x300; - sdram->McGeneralizedCarveout2ForceInternalAccess0 = 0; - sdram->McGeneralizedCarveout2ForceInternalAccess1 = 0; - sdram->McGeneralizedCarveout2ForceInternalAccess2 = 0; - sdram->McGeneralizedCarveout2ForceInternalAccess3 = 0; - sdram->McGeneralizedCarveout2ForceInternalAccess4 = 0; - sdram->McGeneralizedCarveout2Cfg0 = 0x440167E; - sdram->McGeneralizedCarveout3Bom = 0; - sdram->McGeneralizedCarveout3BomHi = 0; - sdram->McGeneralizedCarveout3Size128kb = 0; - sdram->McGeneralizedCarveout3Access0 = 0; - sdram->McGeneralizedCarveout3Access1 = 0; - sdram->McGeneralizedCarveout3Access2 = 0x3000000; - sdram->McGeneralizedCarveout3Access3 = 0; - sdram->McGeneralizedCarveout3Access4 = 0x300; - sdram->McGeneralizedCarveout3ForceInternalAccess0 = 0; - sdram->McGeneralizedCarveout3ForceInternalAccess1 = 0; - sdram->McGeneralizedCarveout3ForceInternalAccess2 = 0; - sdram->McGeneralizedCarveout3ForceInternalAccess3 = 0; - sdram->McGeneralizedCarveout3ForceInternalAccess4 = 0; - sdram->McGeneralizedCarveout3Cfg0 = 0x4401E7E; - sdram->McGeneralizedCarveout4Bom = 0; - sdram->McGeneralizedCarveout4BomHi = 0; - sdram->McGeneralizedCarveout4Size128kb = 0; - sdram->McGeneralizedCarveout4Access0 = 0; - sdram->McGeneralizedCarveout4Access1 = 0; - sdram->McGeneralizedCarveout4Access2 = 0; - sdram->McGeneralizedCarveout4Access3 = 0; - sdram->McGeneralizedCarveout4Access4 = 0; - sdram->McGeneralizedCarveout4ForceInternalAccess0 = 0; - sdram->McGeneralizedCarveout4ForceInternalAccess1 = 0; - sdram->McGeneralizedCarveout4ForceInternalAccess2 = 0; - sdram->McGeneralizedCarveout4ForceInternalAccess3 = 0; - sdram->McGeneralizedCarveout4ForceInternalAccess4 = 0; - sdram->McGeneralizedCarveout4Cfg0 = 0x8F; - sdram->McGeneralizedCarveout5Bom = 0; - sdram->McGeneralizedCarveout5BomHi = 0; - sdram->McGeneralizedCarveout5Size128kb = 0; - sdram->McGeneralizedCarveout5Access0 = 0; - sdram->McGeneralizedCarveout5Access1 = 0; - sdram->McGeneralizedCarveout5Access2 = 0; - sdram->McGeneralizedCarveout5Access3 = 0; - sdram->McGeneralizedCarveout5Access4 = 0; - sdram->McGeneralizedCarveout5ForceInternalAccess0 = 0; - sdram->McGeneralizedCarveout5ForceInternalAccess1 = 0; - sdram->McGeneralizedCarveout5ForceInternalAccess2 = 0; - sdram->McGeneralizedCarveout5ForceInternalAccess3 = 0; - sdram->McGeneralizedCarveout5ForceInternalAccess4 = 0; - sdram->McGeneralizedCarveout5Cfg0 = 0x8F;*/ - - //TODO: this is 4.X+ behaviour which seems to work fine for < 4.X. - // Patch carveout parameters. + // Patch full access to carveout parameters and unprotect their regions. sdram->McGeneralizedCarveout1Cfg0 = 0; sdram->McGeneralizedCarveout2Cfg0 = 0; sdram->McGeneralizedCarveout3Cfg0 = 0; @@ -130,14 +55,14 @@ static void _sdram_lp0_save_params_t210(const void *params) sdram->McGeneralizedCarveout5Cfg0 = 0; // Patch SDRAM parameters. - u32 t0 = sdram->EmcSwizzleRank0Byte0 << 5 >> 29 > sdram->EmcSwizzleRank0Byte0 << 1 >> 29; - u32 t1 = (t0 & 0xFFFFFFEF) | ((sdram->EmcSwizzleRank1Byte0 << 5 >> 29 > sdram->EmcSwizzleRank1Byte0 << 1 >> 29) << 4); - u32 t2 = (t1 & 0xFFFFFFFD) | ((sdram->EmcSwizzleRank0Byte1 << 5 >> 29 > sdram->EmcSwizzleRank0Byte1 << 1 >> 29) << 1); - u32 t3 = (t2 & 0xFFFFFFDF) | ((sdram->EmcSwizzleRank1Byte1 << 5 >> 29 > sdram->EmcSwizzleRank1Byte1 << 1 >> 29) << 5); - u32 t4 = (t3 & 0xFFFFFFFB) | ((sdram->EmcSwizzleRank0Byte2 << 5 >> 29 > sdram->EmcSwizzleRank0Byte2 << 1 >> 29) << 2); - u32 t5 = (t4 & 0xFFFFFFBF) | ((sdram->EmcSwizzleRank1Byte2 << 5 >> 29 > sdram->EmcSwizzleRank1Byte2 << 1 >> 29) << 6); - u32 t6 = (t5 & 0xFFFFFFF7) | ((sdram->EmcSwizzleRank0Byte3 << 5 >> 29 > sdram->EmcSwizzleRank0Byte3 << 1 >> 29) << 3); - u32 t7 = (t6 & 0xFFFFFF7F) | ((sdram->EmcSwizzleRank1Byte3 << 5 >> 29 > sdram->EmcSwizzleRank1Byte3 << 1 >> 29) << 7); + u32 t0 = (sdram->EmcSwizzleRank0Byte0 << 5 >> 29) > (sdram->EmcSwizzleRank0Byte0 << 1 >> 29); + u32 t1 = (t0 & 0xFFFFFFEF) | (((sdram->EmcSwizzleRank1Byte0 << 5 >> 29) > (sdram->EmcSwizzleRank1Byte0 << 1 >> 29)) << 4); + u32 t2 = (t1 & 0xFFFFFFFD) | (((sdram->EmcSwizzleRank0Byte1 << 5 >> 29) > (sdram->EmcSwizzleRank0Byte1 << 1 >> 29)) << 1); + u32 t3 = (t2 & 0xFFFFFFDF) | (((sdram->EmcSwizzleRank1Byte1 << 5 >> 29) > (sdram->EmcSwizzleRank1Byte1 << 1 >> 29)) << 5); + u32 t4 = (t3 & 0xFFFFFFFB) | (((sdram->EmcSwizzleRank0Byte2 << 5 >> 29) > (sdram->EmcSwizzleRank0Byte2 << 1 >> 29)) << 2); + u32 t5 = (t4 & 0xFFFFFFBF) | (((sdram->EmcSwizzleRank1Byte2 << 5 >> 29) > (sdram->EmcSwizzleRank1Byte2 << 1 >> 29)) << 6); + u32 t6 = (t5 & 0xFFFFFFF7) | (((sdram->EmcSwizzleRank0Byte3 << 5 >> 29) > (sdram->EmcSwizzleRank0Byte3 << 1 >> 29)) << 3); + u32 t7 = (t6 & 0xFFFFFF7F) | (((sdram->EmcSwizzleRank1Byte3 << 5 >> 29) > (sdram->EmcSwizzleRank1Byte3 << 1 >> 29)) << 7); sdram->SwizzleRankByteEncode = t7; sdram->EmcBctSpare2 = 0x40000DD8; sdram->EmcBctSpare3 = t7; @@ -839,80 +764,49 @@ static void _sdram_lp0_save_params_t210(const void *params) s(EmcAutoCalWait, 9:0, scratch101, 31:22); s(SwizzleRankByteEncode, 15:0, scratch190, 15:0); - switch (sdram->MemoryType) - { - case NvBootMemoryType_LpDdr2: - case NvBootMemoryType_LpDdr4: - s(EmcMrwLpddr2ZcalWarmBoot, 23:16, scratch5, 7:0); - s(EmcMrwLpddr2ZcalWarmBoot, 7:0, scratch5, 15:8); - s(EmcWarmBootMrwExtra, 23:16, scratch5, 23:16); - s(EmcWarmBootMrwExtra, 7:0, scratch5, 31:24); - s(EmcMrwLpddr2ZcalWarmBoot, 31:30, scratch6, 1:0); - s(EmcWarmBootMrwExtra, 31:30, scratch6, 3:2); - s(EmcMrwLpddr2ZcalWarmBoot, 27:26, scratch6, 5:4); - s(EmcWarmBootMrwExtra, 27:26, scratch6, 7:6); - s(EmcMrw6, 27:0, scratch8, 27:0); - s(EmcMrw6, 31:30, scratch8, 29:28); - s(EmcMrw8, 27:0, scratch9, 27:0); - s(EmcMrw8, 31:30, scratch9, 29:28); - s(EmcMrw9, 27:0, scratch10, 27:0); - s(EmcMrw9, 31:30, scratch10, 29:28); - s(EmcMrw10, 27:0, scratch11, 27:0); - s(EmcMrw10, 31:30, scratch11, 29:28); - s(EmcMrw12, 27:0, scratch12, 27:0); - s(EmcMrw12, 31:30, scratch12, 29:28); - s(EmcMrw13, 27:0, scratch13, 27:0); - s(EmcMrw13, 31:30, scratch13, 29:28); - s(EmcMrw14, 27:0, scratch14, 27:0); - s(EmcMrw14, 31:30, scratch14, 29:28); - s(EmcMrw1, 7:0, scratch15, 7:0); - s(EmcMrw1, 23:16, scratch15, 15:8); - s(EmcMrw1, 27:26, scratch15, 17:16); - s(EmcMrw1, 31:30, scratch15, 19:18); - s(EmcWarmBootMrwExtra, 7:0, scratch16, 7:0); - s(EmcWarmBootMrwExtra, 23:16, scratch16, 15:8); - s(EmcWarmBootMrwExtra, 27:26, scratch16, 17:16); - s(EmcWarmBootMrwExtra, 31:30, scratch16, 19:18); - s(EmcMrw2, 7:0, scratch17, 7:0); - s(EmcMrw2, 23:16, scratch17, 15:8); - s(EmcMrw2, 27:26, scratch17, 17:16); - s(EmcMrw2, 31:30, scratch17, 19:18); - s(EmcMrw3, 7:0, scratch18, 7:0); - s(EmcMrw3, 23:16, scratch18, 15:8); - s(EmcMrw3, 27:26, scratch18, 17:16); - s(EmcMrw3, 31:30, scratch18, 19:18); - s(EmcMrw4, 7:0, scratch19, 7:0); - s(EmcMrw4, 23:16, scratch19, 15:8); - s(EmcMrw4, 27:26, scratch19, 17:16); - s(EmcMrw4, 31:30, scratch19, 19:18); - break; - case NvBootMemoryType_Ddr3: - s(EmcMrs, 13:0, scratch5, 13:0); - s(EmcEmrs, 13:0, scratch5, 27:14); - s(EmcMrs, 21:20, scratch5, 29:28); - s(EmcMrs, 31:30, scratch5, 31:30); - s(EmcEmrs2, 13:0, scratch8, 13:0); - s(EmcEmrs3, 13:0, scratch8, 27:14); - s(EmcEmrs, 21:20, scratch8, 29:28); - s(EmcWarmBootMrsExtra, 13:0, scratch9, 13:0); - s(EmcEmrs, 31:30, scratch9, 15:14); - s(EmcEmrs2, 21:20, scratch9, 17:16); - s(EmcEmrs2, 31:30, scratch9, 19:18); - s(EmcEmrs3, 21:20, scratch9, 21:20); - s(EmcEmrs3, 31:30, scratch9, 23:22); - s(EmcWarmBootMrsExtra, 31:30, scratch9, 25:24); - s(EmcWarmBootMrsExtra, 21:20, scratch9, 27:26); - s(EmcZqCalDdr3WarmBoot, 31:30, scratch9, 29:28); - s(EmcMrs, 27:26, scratch10, 1:0); - s(EmcEmrs, 27:26, scratch10, 3:2); - s(EmcEmrs2, 27:26, scratch10, 5:4); - s(EmcEmrs3, 27:26, scratch10, 7:6); - s(EmcWarmBootMrsExtra, 27:27, scratch10, 8:8); - s(EmcWarmBootMrsExtra, 26:26, scratch10, 9:9); - s(EmcZqCalDdr3WarmBoot, 0:0, scratch10, 10:10); - s(EmcZqCalDdr3WarmBoot, 4:4, scratch10, 11:11); - break; - } + // LPDDR4 MRW. + s(EmcMrwLpddr2ZcalWarmBoot, 23:16, scratch5, 7:0); + s(EmcMrwLpddr2ZcalWarmBoot, 7:0, scratch5, 15:8); + s(EmcWarmBootMrwExtra, 23:16, scratch5, 23:16); + s(EmcWarmBootMrwExtra, 7:0, scratch5, 31:24); + s(EmcMrwLpddr2ZcalWarmBoot, 31:30, scratch6, 1:0); + s(EmcWarmBootMrwExtra, 31:30, scratch6, 3:2); + s(EmcMrwLpddr2ZcalWarmBoot, 27:26, scratch6, 5:4); + s(EmcWarmBootMrwExtra, 27:26, scratch6, 7:6); + s(EmcMrw6, 27:0, scratch8, 27:0); + s(EmcMrw6, 31:30, scratch8, 29:28); + s(EmcMrw8, 27:0, scratch9, 27:0); + s(EmcMrw8, 31:30, scratch9, 29:28); + s(EmcMrw9, 27:0, scratch10, 27:0); + s(EmcMrw9, 31:30, scratch10, 29:28); + s(EmcMrw10, 27:0, scratch11, 27:0); + s(EmcMrw10, 31:30, scratch11, 29:28); + s(EmcMrw12, 27:0, scratch12, 27:0); + s(EmcMrw12, 31:30, scratch12, 29:28); + s(EmcMrw13, 27:0, scratch13, 27:0); + s(EmcMrw13, 31:30, scratch13, 29:28); + s(EmcMrw14, 27:0, scratch14, 27:0); + s(EmcMrw14, 31:30, scratch14, 29:28); + s(EmcMrw1, 7:0, scratch15, 7:0); + s(EmcMrw1, 23:16, scratch15, 15:8); + s(EmcMrw1, 27:26, scratch15, 17:16); + s(EmcMrw1, 31:30, scratch15, 19:18); + s(EmcWarmBootMrwExtra, 7:0, scratch16, 7:0); + s(EmcWarmBootMrwExtra, 23:16, scratch16, 15:8); + s(EmcWarmBootMrwExtra, 27:26, scratch16, 17:16); + s(EmcWarmBootMrwExtra, 31:30, scratch16, 19:18); + s(EmcMrw2, 7:0, scratch17, 7:0); + s(EmcMrw2, 23:16, scratch17, 15:8); + s(EmcMrw2, 27:26, scratch17, 17:16); + s(EmcMrw2, 31:30, scratch17, 19:18); + s(EmcMrw3, 7:0, scratch18, 7:0); + s(EmcMrw3, 23:16, scratch18, 15:8); + s(EmcMrw3, 27:26, scratch18, 17:16); + s(EmcMrw3, 31:30, scratch18, 19:18); + s(EmcMrw4, 7:0, scratch19, 7:0); + s(EmcMrw4, 23:16, scratch19, 15:8); + s(EmcMrw4, 27:26, scratch19, 17:16); + s(EmcMrw4, 31:30, scratch19, 19:18); s32(EmcCmdMappingByte, secure_scratch8); s32(EmcPmacroBrickMapping0, secure_scratch9); @@ -1103,6 +997,7 @@ static void _sdram_lp0_save_params_t210(const void *params) s32(McGeneralizedCarveout5ForceInternalAccess2, secure_scratch106); s32(McGeneralizedCarveout5ForceInternalAccess3, secure_scratch107); + // PLLM. c32(0, scratch2); s(PllMInputDivider, 7:0, scratch2, 7:0); s(PllMFeedbackDivider, 7:0, scratch2, 15:8); @@ -1113,30 +1008,33 @@ static void _sdram_lp0_save_params_t210(const void *params) c32(0, scratch35); s(PllMSetupControl, 15:0, scratch35, 15:0); + // PLLX. c32(0, scratch3); s(PllMInputDivider, 7:0, scratch3, 7:0); - c(0x3E, scratch3, 15:8); - c(0, scratch3, 20:16); + c(62, scratch3, 15:8); // 62 divn. + c(0, scratch3, 20:16); // 0 divp. s(PllMKVCO, 0:0, scratch3, 21:21); s(PllMKCP, 1:0, scratch3, 23:22); c32(0, scratch36); s(PllMSetupControl, 23:0, scratch36, 23:0); + // PLLM/PLLX. c32(0, scratch4); s(PllMStableTime, 9:0, scratch4, 9:0); s(PllMStableTime, 9:0, scratch4, 19:10); } -#pragma GCC diagnostic ignored "-Wparentheses" - -static void _sdram_lp0_save_params_t210b01(const void *params) +/* + * This function reads SDRAM parameters from the common BCT format and + * writes them into PMC scratch registers (where the BootROM expects them + * on LP0 resume). + */ +static void _sdram_lp0_save_params_t210b01(sdram_params_t210b01_t *sdram) { - struct sdram_params_t210b01 *sdram = (struct sdram_params_t210b01 *)params; - struct tegra_pmc_regs *pmc = (struct tegra_pmc_regs *)PMC_BASE; - - u32 tmp = 0; + pmc_regs_t210_t *pmc = (pmc_regs_t210_t *)PMC_BASE; + // Patch full access to carveout parameters and unprotect their regions. sdram->mc_generalized_carveout1_cfg0 = 0; sdram->mc_generalized_carveout2_cfg0 = 0; sdram->mc_generalized_carveout3_cfg0 = 0; @@ -1144,201 +1042,756 @@ static void _sdram_lp0_save_params_t210b01(const void *params) sdram->mc_generalized_carveout5_cfg0 = 0; // Patch SDRAM parameters. - u32 t0 = 32 * sdram->emc_swizzle_rank0_byte0 >> 29 > 2 * sdram->emc_swizzle_rank0_byte0 >> 29; - u32 t1 = t0 & 0xFFFFFFEF | 16 * (32 * sdram->emc_swizzle_rank1_byte0 >> 29 > 2 * sdram->emc_swizzle_rank1_byte0 >> 29); - u32 t2 = t1 & 0xFFFFFFFD | 2 * (32 * sdram->emc_swizzle_rank0_byte1 >> 29 > 2 * sdram->emc_swizzle_rank0_byte1 >> 29); - u32 t3 = t2 & 0xFFFFFFDF | 32 * (32 * sdram->emc_swizzle_rank1_byte1 >> 29 > 2 * sdram->emc_swizzle_rank1_byte1 >> 29); - u32 t4 = t3 & 0xFFFFFFFB | 4 * (32 * sdram->emc_swizzle_rank0_byte2 >> 29 > 2 * sdram->emc_swizzle_rank0_byte2 >> 29); - u32 t5 = t4 & 0xFFFFFFBF | ((32 * sdram->emc_swizzle_rank1_byte2 >> 29 > 2 * sdram->emc_swizzle_rank1_byte2 >> 29) << 6); - u32 t6 = t5 & 0xFFFFFFF7 | 8 * (32 * sdram->emc_swizzle_rank0_byte3 >> 29 > 2 * sdram->emc_swizzle_rank0_byte3 >> 29); - u32 t7 = t6 & 0xFFFFFF7F | ((32 * sdram->emc_swizzle_rank1_byte3 >> 29 > 2 * sdram->emc_swizzle_rank1_byte3 >> 29) << 7); + u32 t0 = (sdram->emc_swizzle_rank0_byte0 << 5 >> 29) > (sdram->emc_swizzle_rank0_byte0 << 1 >> 29); + u32 t1 = (t0 & 0xFFFFFFEF) | (((sdram->emc_swizzle_rank1_byte0 << 5 >> 29) > (sdram->emc_swizzle_rank1_byte0 << 1 >> 29)) << 4); + u32 t2 = (t1 & 0xFFFFFFFD) | (((sdram->emc_swizzle_rank0_byte1 << 5 >> 29) > (sdram->emc_swizzle_rank0_byte1 << 1 >> 29)) << 1); + u32 t3 = (t2 & 0xFFFFFFDF) | (((sdram->emc_swizzle_rank1_byte1 << 5 >> 29) > (sdram->emc_swizzle_rank1_byte1 << 1 >> 29)) << 5); + u32 t4 = (t3 & 0xFFFFFFFB) | (((sdram->emc_swizzle_rank0_byte2 << 5 >> 29) > (sdram->emc_swizzle_rank0_byte2 << 1 >> 29)) << 2); + u32 t5 = (t4 & 0xFFFFFFBF) | (((sdram->emc_swizzle_rank1_byte2 << 5 >> 29) > (sdram->emc_swizzle_rank1_byte2 << 1 >> 29)) << 6); + u32 t6 = (t5 & 0xFFFFFFF7) | (((sdram->emc_swizzle_rank0_byte3 << 5 >> 29) > (sdram->emc_swizzle_rank0_byte3 << 1 >> 29)) << 3); + u32 t7 = (t6 & 0xFFFFFF7F) | (((sdram->emc_swizzle_rank1_byte3 << 5 >> 29) > (sdram->emc_swizzle_rank1_byte3 << 1 >> 29)) << 7); sdram->swizzle_rank_byte_encode = t7; sdram->emc_bct_spare2 = 0x40000DD8; sdram->emc_bct_spare3 = t7; - pmc->scratch6 = (sdram->emc_clock_source_dll << 20 >> 30 << 30) | (4 * ((sdram->emc_clock_source_dll >> 29 << 27) | ((sdram->emc_clock_source >> 29 << 24) | ((sdram->emc_clock_source_dll << 16) & 0xFFFFFF | ((sdram->emc_clock_source << 8) & 0xFFFF | pmc->scratch6 & 0xFFFF00FF) & 0xFF00FFFF) & 0xF8FFFFFF) & 0xC7FFFFFF) >> 2); - pmc->scratch7 = (sdram->emc_rc << 24) | ((sdram->emc_zqcal_lpddr4_warm_boot << 27 >> 31 << 23) | ((sdram->emc_zqcal_lpddr4_warm_boot << 30 >> 31 << 22) | ((sdram->emc_zqcal_lpddr4_warm_boot << 21) & 0x3FFFFF | ((sdram->clk_rst_pllm_misc20_override << 20) & 0x1FFFFF | ((sdram->clk_rst_pllm_misc20_override << 28 >> 31 << 19) | ((sdram->clk_rst_pllm_misc20_override << 27 >> 31 << 18) | ((sdram->clk_rst_pllm_misc20_override << 26 >> 31 << 17) | ((sdram->clk_rst_pllm_misc20_override << 21 >> 31 << 16) | ((sdram->clk_rst_pllm_misc20_override << 20 >> 31 << 15) | ((sdram->clk_rst_pllm_misc20_override << 19 >> 31 << 14) | ((sdram->clk_rst_pllm_misc20_override << 18 >> 31 << 13) | ((sdram->emc_clock_source << 15 >> 31 << 12) | ((sdram->emc_clock_source << 11 >> 31 << 11) | ((sdram->emc_clock_source << 12 >> 31 << 10) | ((sdram->emc_clock_source << 6 >> 31 << 9) | ((sdram->emc_clock_source << 16 >> 31 << 8) | ((32 * sdram->emc_clock_source >> 31 << 7) | ((16 * sdram->emc_clock_source >> 31 << 6) | (16 * (sdram->emc_zqcal_lpddr4_warm_boot >> 30) | (4 * (sdram->clk_rst_pllm_misc20_override << 29 >> 30) | ((sdram->clk_rst_pllm_misc20_override << 22 >> 30) | 4 * (pmc->scratch7 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFFFFFF; - pmc->scratch8 = (sdram->emc_pmacro_bg_bias_ctrl0 << 18 >> 30 << 30) | ((4 * pmc->scratch8) >> 2); - pmc->scratch14 = ((u8)(sdram->emc_cfg_pipe_clk) << 31) | (2 * (((u8)(sdram->emc_fdpd_ctrl_cmd_no_ramp) << 30) | pmc->scratch14 & 0xBFFFFFFF) >> 1); - pmc->scratch15 = (sdram->emc_qrst << 11 >> 27 << 27) | ((sdram->emc_qrst << 20) | pmc->scratch15 & 0xF80FFFFF) & 0x7FFFFFF; - pmc->scratch16 = ((u16)(sdram->emc_pmacro_cmd_tx_drive) << 18 >> 26 << 26) | (((u16)(sdram->emc_pmacro_cmd_tx_drive) << 20) | pmc->scratch16 & 0xFC0FFFFF) & 0x3FFFFFF; - pmc->scratch17 = (16 * sdram->emc_fbio_cfg8 >> 31 << 31) | (2 * ((32 * sdram->emc_fbio_cfg8 >> 31 << 30) | ((sdram->emc_fbio_cfg8 << 6 >> 31 << 29) | ((sdram->emc_fbio_cfg8 << 7 >> 31 << 28) | ((sdram->emc_fbio_cfg8 << 8 >> 31 << 27) | ((sdram->emc_fbio_cfg8 << 9 >> 31 << 26) | ((sdram->emc_fbio_cfg8 << 10 >> 31 << 25) | ((sdram->emc_fbio_cfg8 << 11 >> 31 << 24) | ((sdram->emc_fbio_cfg8 << 12 >> 31 << 23) | ((sdram->emc_fbio_cfg8 << 13 >> 31 << 22) | ((sdram->emc_fbio_cfg8 << 14 >> 31 << 21) | ((sdram->emc_fbio_cfg8 << 15 >> 31 << 20) | pmc->scratch17 & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch18 = ((u16)(sdram->emc_txsr_dll) << 20) | pmc->scratch18 & 0xFFFFF; - pmc->scratch19 = (sdram->emc_txdsrvttgen << 20) | pmc->scratch19 & 0xFFFFF; - pmc->scratch22 = (sdram->emc_cfg_rsv >> 24 << 24) | ((sdram->emc_cfg_rsv >> 16 << 16) | ((sdram->emc_cfg_rsv << 16 >> 24 << 8) | (sdram->emc_cfg_rsv & 0xFF | (pmc->scratch22 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFFFFFF; - pmc->scratch23 = (sdram->emc_auto_cal_config >> 31 << 31) | (2 * ((2 * sdram->emc_auto_cal_config >> 31 << 30) | ((4 * sdram->emc_auto_cal_config >> 31 << 29) | ((8 * sdram->emc_auto_cal_config >> 28 << 25) | ((sdram->emc_auto_cal_config << 7 >> 31 << 24) | ((sdram->emc_auto_cal_config << 8 >> 27 << 19) | ((sdram->emc_auto_cal_config << 13 >> 29 << 16) | ((sdram->emc_auto_cal_config << 16 >> 27 << 11) | ((sdram->emc_auto_cal_config << 21 >> 31 << 10) | ((sdram->emc_auto_cal_config << 22 >> 31 << 9) | ((sdram->emc_auto_cal_config << 23 >> 31 << 8) | ((sdram->emc_auto_cal_config << 24 >> 31 << 7) | ((sdram->emc_auto_cal_config << 25 >> 31 << 6) | (32 * (sdram->emc_auto_cal_config << 26 >> 31) | (16 * (sdram->emc_auto_cal_config << 27 >> 31) | (8 * (sdram->emc_auto_cal_config << 28 >> 31) | (4 * (sdram->emc_auto_cal_config << 29 >> 31) | (2 * (sdram->emc_auto_cal_config << 30 >> 31) | (sdram->emc_auto_cal_config & 1 | 2 * (pmc->scratch23 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFF07FF) & 0xFFF8FFFF) & 0xFF07FFFF) & 0xFEFFFFFF) & 0xE1FFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch24 = (sdram->emc_auto_cal_vref_sel0 >> 31 << 31) | (2 * ((2 * sdram->emc_auto_cal_vref_sel0 >> 25 << 24) | ((sdram->emc_auto_cal_vref_sel0 << 8 >> 31 << 23) | ((sdram->emc_auto_cal_vref_sel0 << 9 >> 25 << 16) | ((sdram->emc_auto_cal_vref_sel0 << 16 >> 31 << 15) | ((sdram->emc_auto_cal_vref_sel0 << 17 >> 25 << 8) | ((sdram->emc_auto_cal_vref_sel0 << 24 >> 31 << 7) | (sdram->emc_auto_cal_vref_sel0 & 0x7F | (pmc->scratch24 >> 7 << 7)) & 0xFFFFFF7F) & 0xFFFF80FF) & 0xFFFF7FFF) & 0xFF80FFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch25 = (sdram->emc_pmacro_brick_ctrl_rfu1 >> 16 << 16) | sdram->emc_pmacro_brick_ctrl_rfu1 & 0xFFFF; - pmc->scratch26 = (sdram->emc_pmacro_brick_ctrl_rfu2 >> 16 << 16) | sdram->emc_pmacro_brick_ctrl_rfu2 & 0xFFFF; + s(emc_clock_source, 7:0, scratch6, 15:8); + s(emc_clock_source_dll, 7:0, scratch6, 23:16); + s(emc_clock_source, 31:29, scratch6, 26:24); + s(emc_clock_source_dll, 31:29, scratch6, 29:27); + s(emc_clock_source_dll, 11:10, scratch6, 31:30); + s(clk_rst_pllm_misc20_override, 9:8, scratch7, 1:0); + s(clk_rst_pllm_misc20_override, 2:1, scratch7, 3:2); + s(emc_zqcal_lpddr4_warm_boot, 31:30, scratch7, 5:4); + s(emc_clock_source, 27:27, scratch7, 6:6); + s(emc_clock_source, 26:26, scratch7, 7:7); + s(emc_clock_source, 15:15, scratch7, 8:8); + s(emc_clock_source, 25:25, scratch7, 9:9); + s(emc_clock_source, 20:19, scratch7, 11:10); + s(emc_clock_source, 16:16, scratch7, 12:12); + s(clk_rst_pllm_misc20_override, 13:13, scratch7, 13:13); + s(clk_rst_pllm_misc20_override, 12:12, scratch7, 14:14); + s(clk_rst_pllm_misc20_override, 11:11, scratch7, 15:15); + s(clk_rst_pllm_misc20_override, 10:10, scratch7, 16:16); + s(clk_rst_pllm_misc20_override, 5:5, scratch7, 17:17); + s(clk_rst_pllm_misc20_override, 4:4, scratch7, 18:18); + s(clk_rst_pllm_misc20_override, 3:3, scratch7, 19:19); + s(clk_rst_pllm_misc20_override, 0:0, scratch7, 20:20); + s(emc_zqcal_lpddr4_warm_boot, 1:0, scratch7, 22:21); + s(emc_zqcal_lpddr4_warm_boot, 4:4, scratch7, 23:23); + s(emc_rc, 7:0, scratch7, 31:24); + s(emc_pmacro_bg_bias_ctrl0, 13:12, scratch8, 31:30); + s(emc_fdpd_ctrl_cmd_no_ramp, 0:0, scratch14, 30:30); + s(emc_cfg_pipe_clk, 0:0, scratch14, 31:31); + s(emc_qrst, 6:0, scratch15, 26:20); + s(emc_qrst, 20:16, scratch15, 31:27); + s(emc_pmacro_cmd_tx_drive, 5:0, scratch16, 25:20); + s(emc_pmacro_cmd_tx_drive, 13:8, scratch16, 31:26); + s(emc_fbio_cfg8, 27:16, scratch17, 31:20); + s(emc_txsr_dll, 11:0, scratch18, 31:20); + s(emc_txdsrvttgen, 11:0, scratch19, 31:20); + s32(emc_cfg_rsv, scratch22); + s32(emc_auto_cal_config, scratch23); + s32(emc_auto_cal_vref_sel0, scratch24); + s32(emc_pmacro_brick_ctrl_rfu1, scratch25); + s32(emc_pmacro_brick_ctrl_rfu2, scratch26); s32(emc_pmc_scratch1, scratch27); s32(emc_pmc_scratch2, scratch28); s32(emc_pmc_scratch3, scratch29); - pmc->scratch30 = (sdram->emc_pmacro_perbit_rfu_ctrl0 >> 30 << 30) | (4 * ((4 * sdram->emc_pmacro_perbit_rfu_ctrl0 >> 30 << 28) | ((16 * sdram->emc_pmacro_perbit_rfu_ctrl0 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 6 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 8 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 10 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 12 >> 30 << 18) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 14 >> 30 << 16) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 16 >> 30 << 14) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 18 >> 30 << 12) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 20 >> 30 << 10) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 22 >> 30 << 8) | ((sdram->emc_pmacro_perbit_rfu_ctrl0 << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_perbit_rfu_ctrl0 << 26 >> 30) | (4 * (sdram->emc_pmacro_perbit_rfu_ctrl0 << 28 >> 30) | (sdram->emc_pmacro_perbit_rfu_ctrl0 & 3 | 4 * (pmc->scratch30 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch31 = (sdram->emc_pmacro_perbit_rfu_ctrl1 >> 30 << 30) | (4 * ((4 * sdram->emc_pmacro_perbit_rfu_ctrl1 >> 30 << 28) | ((16 * sdram->emc_pmacro_perbit_rfu_ctrl1 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 6 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 8 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 10 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 12 >> 30 << 18) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 14 >> 30 << 16) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 16 >> 30 << 14) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 18 >> 30 << 12) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 20 >> 30 << 10) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 22 >> 30 << 8) | ((sdram->emc_pmacro_perbit_rfu_ctrl1 << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_perbit_rfu_ctrl1 << 26 >> 30) | (4 * (sdram->emc_pmacro_perbit_rfu_ctrl1 << 28 >> 30) | (sdram->emc_pmacro_perbit_rfu_ctrl1 & 3 | 4 * (pmc->scratch31 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch32 = (sdram->emc_pmacro_perbit_rfu_ctrl2 >> 30 << 30) | (4 * ((4 * sdram->emc_pmacro_perbit_rfu_ctrl2 >> 30 << 28) | ((16 * sdram->emc_pmacro_perbit_rfu_ctrl2 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 6 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 8 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 10 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 12 >> 30 << 18) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 14 >> 30 << 16) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 16 >> 30 << 14) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 18 >> 30 << 12) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 20 >> 30 << 10) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 22 >> 30 << 8) | ((sdram->emc_pmacro_perbit_rfu_ctrl2 << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_perbit_rfu_ctrl2 << 26 >> 30) | (4 * (sdram->emc_pmacro_perbit_rfu_ctrl2 << 28 >> 30) | (sdram->emc_pmacro_perbit_rfu_ctrl2 & 3 | 4 * (pmc->scratch32 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch33 = (sdram->emc_pmacro_perbit_rfu_ctrl3 >> 30 << 30) | (4 * ((4 * sdram->emc_pmacro_perbit_rfu_ctrl3 >> 30 << 28) | ((16 * sdram->emc_pmacro_perbit_rfu_ctrl3 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 6 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 8 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 10 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 12 >> 30 << 18) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 14 >> 30 << 16) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 16 >> 30 << 14) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 18 >> 30 << 12) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 20 >> 30 << 10) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 22 >> 30 << 8) | ((sdram->emc_pmacro_perbit_rfu_ctrl3 << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_perbit_rfu_ctrl3 << 26 >> 30) | (4 * (sdram->emc_pmacro_perbit_rfu_ctrl3 << 28 >> 30) | (sdram->emc_pmacro_perbit_rfu_ctrl3 & 3 | 4 * (pmc->scratch33 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch40 = (sdram->emc_pmacro_perbit_rfu_ctrl4 >> 30 << 30) | (4 * ((4 * sdram->emc_pmacro_perbit_rfu_ctrl4 >> 30 << 28) | ((16 * sdram->emc_pmacro_perbit_rfu_ctrl4 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 6 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 8 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 10 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 12 >> 30 << 18) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 14 >> 30 << 16) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 16 >> 30 << 14) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 18 >> 30 << 12) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 20 >> 30 << 10) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 22 >> 30 << 8) | ((sdram->emc_pmacro_perbit_rfu_ctrl4 << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_perbit_rfu_ctrl4 << 26 >> 30) | (4 * (sdram->emc_pmacro_perbit_rfu_ctrl4 << 28 >> 30) | (sdram->emc_pmacro_perbit_rfu_ctrl4 & 3 | 4 * (pmc->scratch40 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch42 = (sdram->emc_pmacro_perbit_rfu_ctrl5 >> 30 << 30) | (4 * ((4 * sdram->emc_pmacro_perbit_rfu_ctrl5 >> 30 << 28) | ((16 * sdram->emc_pmacro_perbit_rfu_ctrl5 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 6 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 8 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 10 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 12 >> 30 << 18) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 14 >> 30 << 16) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 16 >> 30 << 14) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 18 >> 30 << 12) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 20 >> 30 << 10) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 22 >> 30 << 8) | ((sdram->emc_pmacro_perbit_rfu_ctrl5 << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_perbit_rfu_ctrl5 << 26 >> 30) | (4 * (sdram->emc_pmacro_perbit_rfu_ctrl5 << 28 >> 30) | (sdram->emc_pmacro_perbit_rfu_ctrl5 & 3 | 4 * (pmc->scratch42 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch44 = (sdram->mc_emem_arb_da_turns >> 24 << 24) | ((sdram->mc_emem_arb_da_turns >> 16 << 16) | ((sdram->mc_emem_arb_da_turns << 16 >> 24 << 8) | (sdram->mc_emem_arb_da_turns & 0xFF | (pmc->scratch44 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFFFFFF; - pmc->scratch64 = ((u16)(sdram->mc_emem_arb_misc2) << 31) | (2 * ((sdram->emc_fbio_spare << 30) | ((sdram->emc_fbio_spare << 24 >> 26 << 24) | ((sdram->emc_fbio_spare << 16 >> 24 << 16) | ((sdram->emc_fbio_spare << 8 >> 24 << 8) | ((sdram->emc_fbio_spare >> 24) | (pmc->scratch64 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xC0FFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch65 = ((u16)(sdram->mc_da_cfg0) << 31 >> 1) | ((2 * sdram->mc_emem_arb_misc0 >> 29 << 27) | ((16 * sdram->mc_emem_arb_misc0 >> 31 << 26) | ((32 * sdram->mc_emem_arb_misc0 >> 26 << 20) | ((sdram->mc_emem_arb_misc0 << 11 >> 27 << 15) | ((sdram->mc_emem_arb_misc0 << 17 >> 25 << 8) | ((u8)sdram->mc_emem_arb_misc0 | (pmc->scratch65 >> 8 << 8)) & 0xFFFF80FF) & 0xFFF07FFF) & 0xFC0FFFFF) & 0xFBFFFFFF) & 0xC7FFFFFF) & 0xBFFFFFFF; - pmc->scratch66 = (sdram->emc_fdpd_ctrl_cmd >> 30 << 27) | ((4 * sdram->emc_fdpd_ctrl_cmd >> 31 << 26) | ((8 * sdram->emc_fdpd_ctrl_cmd >> 27 << 21) | ((sdram->emc_fdpd_ctrl_cmd << 8 >> 28 << 17) | ((sdram->emc_fdpd_ctrl_cmd << 15 >> 27 << 12) | ((sdram->emc_fdpd_ctrl_cmd << 20 >> 28 << 8) | ((u8)sdram->emc_fdpd_ctrl_cmd | (pmc->scratch66 >> 8 << 8)) & 0xFFFFF0FF) & 0xFFFE0FFF) & 0xFFE1FFFF) & 0xFC1FFFFF) & 0xFBFFFFFF) & 0xE7FFFFFF; - pmc->scratch67 = ((u8)(sdram->emc_burst_refresh_num) << 28) | ((16 * sdram->emc_auto_cal_config2 >> 30 << 26) | ((sdram->emc_auto_cal_config2 << 6 >> 30 << 24) | ((sdram->emc_auto_cal_config2 << 8 >> 30 << 22) | ((sdram->emc_auto_cal_config2 << 10 >> 30 << 20) | ((sdram->emc_auto_cal_config2 << 12 >> 30 << 18) | ((sdram->emc_auto_cal_config2 << 14 >> 30 << 16) | ((sdram->emc_auto_cal_config2 << 16 >> 30 << 14) | ((sdram->emc_auto_cal_config2 << 18 >> 30 << 12) | ((sdram->emc_auto_cal_config2 << 20 >> 30 << 10) | ((sdram->emc_auto_cal_config2 << 22 >> 30 << 8) | ((sdram->emc_auto_cal_config2 << 24 >> 30 << 6) | (16 * (sdram->emc_auto_cal_config2 << 26 >> 30) | (4 * (sdram->emc_auto_cal_config2 << 28 >> 30) | (sdram->emc_auto_cal_config2 & 3 | 4 * (pmc->scratch67 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xFFFFFFF; - pmc->scratch68 = ((u8)(sdram->emc_tppd) << 28) | ((sdram->emc_cfg_dig_dll >> 31 << 27) | ((2 * sdram->emc_cfg_dig_dll >> 31 << 26) | ((16 * sdram->emc_cfg_dig_dll >> 31 << 25) | ((sdram->emc_cfg_dig_dll << 6 >> 22 << 15) | ((sdram->emc_cfg_dig_dll << 16 >> 31 << 14) | ((sdram->emc_cfg_dig_dll << 17 >> 31 << 13) | ((sdram->emc_cfg_dig_dll << 18 >> 30 << 11) | ((sdram->emc_cfg_dig_dll << 21 >> 29 << 8) | ((sdram->emc_cfg_dig_dll << 24 >> 30 << 6) | (32 * (sdram->emc_cfg_dig_dll << 26 >> 31) | (16 * (sdram->emc_cfg_dig_dll << 27 >> 31) | (8 * (sdram->emc_cfg_dig_dll << 28 >> 31) | (4 * (sdram->emc_cfg_dig_dll << 29 >> 31) | (2 * (sdram->emc_cfg_dig_dll << 30 >> 31) | (sdram->emc_cfg_dig_dll & 1 | 2 * (pmc->scratch68 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFF3F) & 0xFFFFF8FF) & 0xFFFFE7FF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFE007FFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xFFFFFFF; - pmc->scratch69 = (sdram->emc_r2r << 28) | ((sdram->emc_fdpd_ctrl_dq >> 30 << 26) | ((8 * sdram->emc_fdpd_ctrl_dq >> 27 << 21) | ((sdram->emc_fdpd_ctrl_dq << 8 >> 28 << 17) | ((sdram->emc_fdpd_ctrl_dq << 15 >> 27 << 12) | ((sdram->emc_fdpd_ctrl_dq << 20 >> 28 << 8) | ((u8)sdram->emc_fdpd_ctrl_dq | (pmc->scratch69 >> 8 << 8)) & 0xFFFFF0FF) & 0xFFFE0FFF) & 0xFFE1FFFF) & 0xFC1FFFFF) & 0xF3FFFFFF) & 0xFFFFFFF; - pmc->scratch70 = (sdram->emc_w2w << 28) | ((2 * sdram->emc_pmacro_ib_vref_dq_0 >> 25 << 21) | ((sdram->emc_pmacro_ib_vref_dq_0 << 9 >> 25 << 14) | ((sdram->emc_pmacro_ib_vref_dq_0 << 17 >> 25 << 7) | (sdram->emc_pmacro_ib_vref_dq_0 & 0x7F | (pmc->scratch70 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xFFFFFFF; - pmc->scratch71 = (sdram->emc_pmacro_vttgen_ctrl0 << 12 >> 28 << 28) | ((2 * sdram->emc_pmacro_ib_vref_dq_1 >> 25 << 21) | ((sdram->emc_pmacro_ib_vref_dq_1 << 9 >> 25 << 14) | ((sdram->emc_pmacro_ib_vref_dq_1 << 17 >> 25 << 7) | ((pmc->scratch71 >> 7 << 7) | sdram->emc_pmacro_ib_vref_dq_1 & 0x7F) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xFFFFFFF; - pmc->scratch72 = (((sdram->emc_pmacro_ib_vref_dqs_0 << 17 >> 25 << 7) | ((pmc->scratch72 >> 7 << 7) | sdram->emc_pmacro_ib_vref_dqs_0 & 0x7F) & 0xFFFFC07F) & 0xFFE03FFF | (sdram->emc_pmacro_ib_vref_dqs_0 << 9 >> 25 << 14)) & 0xF01FFFFF | (2 * sdram->emc_pmacro_ib_vref_dqs_0 >> 25 << 21); - pmc->scratch73 = (2 * sdram->emc_pmacro_ib_vref_dqs_1 >> 25 << 21) | ((sdram->emc_pmacro_ib_vref_dqs_1 << 9 >> 25 << 14) | ((sdram->emc_pmacro_ib_vref_dqs_1 << 17 >> 25 << 7) | ((pmc->scratch73 >> 7 << 7) | sdram->emc_pmacro_ib_vref_dqs_1 & 0x7F) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF; - pmc->scratch74 = (2 * sdram->emc_pmacro_ddll_short_cmd_0 >> 25 << 21) | ((sdram->emc_pmacro_ddll_short_cmd_0 << 9 >> 25 << 14) | ((sdram->emc_pmacro_ddll_short_cmd_0 << 17 >> 25 << 7) | (sdram->emc_pmacro_ddll_short_cmd_0 & 0x7F | (pmc->scratch74 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF; - pmc->scratch75 = (2 * sdram->emc_pmacro_ddll_short_cmd_1 >> 25 << 21) | ((sdram->emc_pmacro_ddll_short_cmd_1 << 9 >> 25 << 14) | ((sdram->emc_pmacro_ddll_short_cmd_1 << 17 >> 25 << 7) | (sdram->emc_pmacro_ddll_short_cmd_1 & 0x7F | (pmc->scratch75 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF; - pmc->scratch76 = (sdram->emc_rp << 26) | ((4 * sdram->emc_dll_cfg0 >> 31 << 25) | ((8 * sdram->emc_dll_cfg0 >> 31 << 24) | ((16 * sdram->emc_dll_cfg0 >> 28 << 20) | ((sdram->emc_dll_cfg0 << 8 >> 28 << 16) | ((sdram->emc_dll_cfg0 << 12 >> 28 << 12) | ((sdram->emc_dll_cfg0 << 16 >> 28 << 8) | ((sdram->emc_dll_cfg0 << 20 >> 24) | (pmc->scratch76 >> 8 << 8)) & 0xFFFFF0FF) & 0xFFFF0FFF) & 0xFFF0FFFF) & 0xFF0FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0x3FFFFFF; - tmp = (sdram->emc_pmacro_tx_pwrd0 << 12 >> 31 << 16) | ((sdram->emc_pmacro_tx_pwrd0 << 13 >> 31 << 15) | ((sdram->emc_pmacro_tx_pwrd0 << 14 >> 31 << 14) | ((sdram->emc_pmacro_tx_pwrd0 << 15 >> 31 << 13) | ((sdram->emc_pmacro_tx_pwrd0 << 18 >> 31 << 12) | ((sdram->emc_pmacro_tx_pwrd0 << 19 >> 31 << 11) | ((sdram->emc_pmacro_tx_pwrd0 << 21 >> 31 << 10) | ((sdram->emc_pmacro_tx_pwrd0 << 22 >> 31 << 9) | ((sdram->emc_pmacro_tx_pwrd0 << 23 >> 31 << 8) | ((sdram->emc_pmacro_tx_pwrd0 << 24 >> 31 << 7) | ((sdram->emc_pmacro_tx_pwrd0 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_tx_pwrd0 << 26 >> 31) | (16 * (sdram->emc_pmacro_tx_pwrd0 << 27 >> 31) | (8 * (sdram->emc_pmacro_tx_pwrd0 << 28 >> 31) | (4 * (sdram->emc_pmacro_tx_pwrd0 << 29 >> 31) | (2 * (sdram->emc_pmacro_tx_pwrd0 << 30 >> 31) | (sdram->emc_pmacro_tx_pwrd0 & 1 | 2 * (pmc->scratch77 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF; - pmc->scratch77 = (sdram->emc_r2w << 26) | ((4 * sdram->emc_pmacro_tx_pwrd0 >> 31 << 25) | ((8 * sdram->emc_pmacro_tx_pwrd0 >> 31 << 24) | ((32 * sdram->emc_pmacro_tx_pwrd0 >> 31 << 23) | ((sdram->emc_pmacro_tx_pwrd0 << 6 >> 31 << 22) | ((sdram->emc_pmacro_tx_pwrd0 << 7 >> 31 << 21) | ((sdram->emc_pmacro_tx_pwrd0 << 8 >> 31 << 20) | ((sdram->emc_pmacro_tx_pwrd0 << 9 >> 31 << 19) | ((sdram->emc_pmacro_tx_pwrd0 << 10 >> 31 << 18) | ((sdram->emc_pmacro_tx_pwrd0 << 11 >> 31 << 17) | tmp & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0x3FFFFFF; - tmp = ((8 * sdram->emc_pmacro_tx_pwrd1 >> 31 << 24) | ((32 * sdram->emc_pmacro_tx_pwrd1 >> 31 << 23) | ((sdram->emc_pmacro_tx_pwrd1 << 6 >> 31 << 22) | ((sdram->emc_pmacro_tx_pwrd1 << 7 >> 31 << 21) | ((sdram->emc_pmacro_tx_pwrd1 << 8 >> 31 << 20) | ((sdram->emc_pmacro_tx_pwrd1 << 9 >> 31 << 19) | ((sdram->emc_pmacro_tx_pwrd1 << 10 >> 31 << 18) | ((sdram->emc_pmacro_tx_pwrd1 << 11 >> 31 << 17) | ((sdram->emc_pmacro_tx_pwrd1 << 12 >> 31 << 16) | ((sdram->emc_pmacro_tx_pwrd1 << 13 >> 31 << 15) | ((sdram->emc_pmacro_tx_pwrd1 << 14 >> 31 << 14) | ((sdram->emc_pmacro_tx_pwrd1 << 15 >> 31 << 13) | ((sdram->emc_pmacro_tx_pwrd1 << 18 >> 31 << 12) | ((sdram->emc_pmacro_tx_pwrd1 << 19 >> 31 << 11) | ((sdram->emc_pmacro_tx_pwrd1 << 21 >> 31 << 10) | ((sdram->emc_pmacro_tx_pwrd1 << 22 >> 31 << 9) | ((sdram->emc_pmacro_tx_pwrd1 << 23 >> 31 << 8) | ((sdram->emc_pmacro_tx_pwrd1 << 24 >> 31 << 7) | ((sdram->emc_pmacro_tx_pwrd1 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_tx_pwrd1 << 26 >> 31) | (16 * (sdram->emc_pmacro_tx_pwrd1 << 27 >> 31) | (8 * (sdram->emc_pmacro_tx_pwrd1 << 28 >> 31) | (4 * (sdram->emc_pmacro_tx_pwrd1 << 29 >> 31) | (2 * (sdram->emc_pmacro_tx_pwrd1 << 30 >> 31) | (sdram->emc_pmacro_tx_pwrd1 & 1 | 2 * (pmc->scratch78 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF; - pmc->scratch78 = (sdram->emc_w2r << 26) | ((4 * sdram->emc_pmacro_tx_pwrd1 >> 31 << 25) | tmp) & 0x3FFFFFF; - tmp = ((8 * sdram->emc_pmacro_tx_pwrd2 >> 31 << 24) | ((32 * sdram->emc_pmacro_tx_pwrd2 >> 31 << 23) | ((sdram->emc_pmacro_tx_pwrd2 << 6 >> 31 << 22) | ((sdram->emc_pmacro_tx_pwrd2 << 7 >> 31 << 21) | ((sdram->emc_pmacro_tx_pwrd2 << 8 >> 31 << 20) | ((sdram->emc_pmacro_tx_pwrd2 << 9 >> 31 << 19) | ((sdram->emc_pmacro_tx_pwrd2 << 10 >> 31 << 18) | ((sdram->emc_pmacro_tx_pwrd2 << 11 >> 31 << 17) | ((sdram->emc_pmacro_tx_pwrd2 << 12 >> 31 << 16) | ((sdram->emc_pmacro_tx_pwrd2 << 13 >> 31 << 15) | ((sdram->emc_pmacro_tx_pwrd2 << 14 >> 31 << 14) | ((sdram->emc_pmacro_tx_pwrd2 << 15 >> 31 << 13) | ((sdram->emc_pmacro_tx_pwrd2 << 18 >> 31 << 12) | ((sdram->emc_pmacro_tx_pwrd2 << 19 >> 31 << 11) | ((sdram->emc_pmacro_tx_pwrd2 << 21 >> 31 << 10) | ((sdram->emc_pmacro_tx_pwrd2 << 22 >> 31 << 9) | ((sdram->emc_pmacro_tx_pwrd2 << 23 >> 31 << 8) | ((sdram->emc_pmacro_tx_pwrd2 << 24 >> 31 << 7) | ((sdram->emc_pmacro_tx_pwrd2 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_tx_pwrd2 << 26 >> 31) | (16 * (sdram->emc_pmacro_tx_pwrd2 << 27 >> 31) | (8 * (sdram->emc_pmacro_tx_pwrd2 << 28 >> 31) | (4 * (sdram->emc_pmacro_tx_pwrd2 << 29 >> 31) | (2 * (sdram->emc_pmacro_tx_pwrd2 << 30 >> 31) | (sdram->emc_pmacro_tx_pwrd2 & 1 | 2 * (pmc->scratch79 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF; - pmc->scratch79 = (sdram->emc_r2p << 26) | ((4 * sdram->emc_pmacro_tx_pwrd2 >> 31 << 25) | tmp) & 0x3FFFFFF; - tmp = (sdram->emc_pmacro_tx_pwrd3 << 23 >> 31 << 8) | ((sdram->emc_pmacro_tx_pwrd3 << 24 >> 31 << 7) | ((sdram->emc_pmacro_tx_pwrd3 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_tx_pwrd3 << 26 >> 31) | (16 * (sdram->emc_pmacro_tx_pwrd3 << 27 >> 31) | (8 * (sdram->emc_pmacro_tx_pwrd3 << 28 >> 31) | (4 * (sdram->emc_pmacro_tx_pwrd3 << 29 >> 31) | (2 * (sdram->emc_pmacro_tx_pwrd3 << 30 >> 31) | (sdram->emc_pmacro_tx_pwrd3 & 1 | 2 * (pmc->scratch80 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF; - pmc->scratch80 = ((u8)(sdram->emc_ccdmw) << 26) | ((4 * sdram->emc_pmacro_tx_pwrd3 >> 31 << 25) | ((8 * sdram->emc_pmacro_tx_pwrd3 >> 31 << 24) | ((32 * sdram->emc_pmacro_tx_pwrd3 >> 31 << 23) | ((sdram->emc_pmacro_tx_pwrd3 << 6 >> 31 << 22) | ((sdram->emc_pmacro_tx_pwrd3 << 7 >> 31 << 21) | ((sdram->emc_pmacro_tx_pwrd3 << 8 >> 31 << 20) | ((sdram->emc_pmacro_tx_pwrd3 << 9 >> 31 << 19) | ((sdram->emc_pmacro_tx_pwrd3 << 10 >> 31 << 18) | ((sdram->emc_pmacro_tx_pwrd3 << 11 >> 31 << 17) | ((sdram->emc_pmacro_tx_pwrd3 << 12 >> 31 << 16) | ((sdram->emc_pmacro_tx_pwrd3 << 13 >> 31 << 15) | ((sdram->emc_pmacro_tx_pwrd3 << 14 >> 31 << 14) | ((sdram->emc_pmacro_tx_pwrd3 << 15 >> 31 << 13) | ((sdram->emc_pmacro_tx_pwrd3 << 18 >> 31 << 12) | ((sdram->emc_pmacro_tx_pwrd3 << 19 >> 31 << 11) | ((sdram->emc_pmacro_tx_pwrd3 << 21 >> 31 << 10) | ((sdram->emc_pmacro_tx_pwrd3 << 22 >> 31 << 9) | tmp & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0x3FFFFFF; - tmp = ((8 * sdram->emc_pmacro_tx_pwrd4 >> 31 << 24) | ((32 * sdram->emc_pmacro_tx_pwrd4 >> 31 << 23) | ((sdram->emc_pmacro_tx_pwrd4 << 6 >> 31 << 22) | ((sdram->emc_pmacro_tx_pwrd4 << 7 >> 31 << 21) | ((sdram->emc_pmacro_tx_pwrd4 << 8 >> 31 << 20) | ((sdram->emc_pmacro_tx_pwrd4 << 9 >> 31 << 19) | ((sdram->emc_pmacro_tx_pwrd4 << 10 >> 31 << 18) | ((sdram->emc_pmacro_tx_pwrd4 << 11 >> 31 << 17) | ((sdram->emc_pmacro_tx_pwrd4 << 12 >> 31 << 16) | ((sdram->emc_pmacro_tx_pwrd4 << 13 >> 31 << 15) | ((sdram->emc_pmacro_tx_pwrd4 << 14 >> 31 << 14) | ((sdram->emc_pmacro_tx_pwrd4 << 15 >> 31 << 13) | ((sdram->emc_pmacro_tx_pwrd4 << 18 >> 31 << 12) | ((sdram->emc_pmacro_tx_pwrd4 << 19 >> 31 << 11) | ((sdram->emc_pmacro_tx_pwrd4 << 21 >> 31 << 10) | ((sdram->emc_pmacro_tx_pwrd4 << 22 >> 31 << 9) | ((sdram->emc_pmacro_tx_pwrd4 << 23 >> 31 << 8) | ((sdram->emc_pmacro_tx_pwrd4 << 24 >> 31 << 7) | ((sdram->emc_pmacro_tx_pwrd4 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_tx_pwrd4 << 26 >> 31) | (16 * (sdram->emc_pmacro_tx_pwrd4 << 27 >> 31) | (8 * (sdram->emc_pmacro_tx_pwrd4 << 28 >> 31) | (4 * (sdram->emc_pmacro_tx_pwrd4 << 29 >> 31) | (2 * (sdram->emc_pmacro_tx_pwrd4 << 30 >> 31) | (sdram->emc_pmacro_tx_pwrd4 & 1 | 2 * (pmc->scratch81 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF; - pmc->scratch81 = ((u8)(sdram->emc_rd_rcd) << 26) | ((4 * sdram->emc_pmacro_tx_pwrd4 >> 31 << 25) | tmp) & 0x3FFFFFF; - tmp = ((8 * sdram->emc_pmacro_tx_pwrd5 >> 31 << 24) | ((32 * sdram->emc_pmacro_tx_pwrd5 >> 31 << 23) | ((sdram->emc_pmacro_tx_pwrd5 << 6 >> 31 << 22) | ((sdram->emc_pmacro_tx_pwrd5 << 7 >> 31 << 21) | ((sdram->emc_pmacro_tx_pwrd5 << 8 >> 31 << 20) | ((sdram->emc_pmacro_tx_pwrd5 << 9 >> 31 << 19) | ((sdram->emc_pmacro_tx_pwrd5 << 10 >> 31 << 18) | ((sdram->emc_pmacro_tx_pwrd5 << 11 >> 31 << 17) | ((sdram->emc_pmacro_tx_pwrd5 << 12 >> 31 << 16) | ((sdram->emc_pmacro_tx_pwrd5 << 13 >> 31 << 15) | ((sdram->emc_pmacro_tx_pwrd5 << 14 >> 31 << 14) | ((sdram->emc_pmacro_tx_pwrd5 << 15 >> 31 << 13) | ((sdram->emc_pmacro_tx_pwrd5 << 18 >> 31 << 12) | ((sdram->emc_pmacro_tx_pwrd5 << 19 >> 31 << 11) | ((sdram->emc_pmacro_tx_pwrd5 << 21 >> 31 << 10) | ((sdram->emc_pmacro_tx_pwrd5 << 22 >> 31 << 9) | ((sdram->emc_pmacro_tx_pwrd5 << 23 >> 31 << 8) | ((sdram->emc_pmacro_tx_pwrd5 << 24 >> 31 << 7) | ((sdram->emc_pmacro_tx_pwrd5 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_tx_pwrd5 << 26 >> 31) | (16 * (sdram->emc_pmacro_tx_pwrd5 << 27 >> 31) | (8 * (sdram->emc_pmacro_tx_pwrd5 << 28 >> 31) | (4 * (sdram->emc_pmacro_tx_pwrd5 << 29 >> 31) | (2 * (sdram->emc_pmacro_tx_pwrd5 << 30 >> 31) | (sdram->emc_pmacro_tx_pwrd5 & 1 | 2 * (pmc->scratch82 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF; - pmc->scratch82 = ((u16)(sdram->emc_wr_rcd) << 26) | ((4 * sdram->emc_pmacro_tx_pwrd5 >> 31 << 25) | tmp) & 0x3FFFFFF; - pmc->scratch83 = ((u8)(sdram->emc_config_sample_delay) << 25) | ((sdram->emc_auto_cal_channel >> 31 << 24) | ((2 * sdram->emc_auto_cal_channel >> 31 << 23) | ((4 * sdram->emc_auto_cal_channel >> 31 << 22) | ((16 * sdram->emc_auto_cal_channel >> 25 << 15) | ((sdram->emc_auto_cal_channel << 11 >> 27 << 10) | ((sdram->emc_auto_cal_channel << 20 >> 28 << 6) | (sdram->emc_auto_cal_channel & 0x3F | (pmc->scratch83 >> 6 << 6)) & 0xFFFFFC3F) & 0xFFFF83FF) & 0xFFC07FFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0x1FFFFFF; - pmc->scratch84 = (sdram->emc_sel_dpd_ctrl << 13 >> 29 << 29) | ((sdram->emc_sel_dpd_ctrl << 23 >> 31 << 28) | ((sdram->emc_sel_dpd_ctrl << 26 >> 31 << 27) | ((sdram->emc_sel_dpd_ctrl << 27 >> 31 << 26) | ((sdram->emc_sel_dpd_ctrl << 28 >> 31 << 25) | ((sdram->emc_sel_dpd_ctrl << 29 >> 31 << 24) | ((4 * sdram->emc_pmacro_rx_term >> 26 << 18) | ((sdram->emc_pmacro_rx_term << 10 >> 26 << 12) | ((sdram->emc_pmacro_rx_term << 18 >> 26 << 6) | (sdram->emc_pmacro_rx_term & 0x3F | (pmc->scratch84 >> 6 << 6)) & 0xFFFFF03F) & 0xFFFC0FFF) & 0xFF03FFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0x1FFFFFFF; - pmc->scratch85 = (4 * sdram->emc_obdly >> 30 << 30) | (4 * ((sdram->emc_obdly << 24) | ((4 * sdram->emc_pmacro_dq_tx_drive >> 26 << 18) | ((sdram->emc_pmacro_dq_tx_drive << 10 >> 26 << 12) | ((sdram->emc_pmacro_dq_tx_drive << 18 >> 26 << 6) | (sdram->emc_pmacro_dq_tx_drive & 0x3F | (pmc->scratch85 >> 6 << 6)) & 0xFFFFF03F) & 0xFFFC0FFF) & 0xFF03FFFF) & 0xC0FFFFFF) >> 2); - pmc->scratch86 = (sdram->emc_pmacro_vttgen_ctrl1 << 10 >> 30 << 30) | (4 * ((sdram->emc_pmacro_vttgen_ctrl1 << 16 >> 26 << 24) | ((4 * sdram->emc_pmacro_ca_tx_drive >> 26 << 18) | ((sdram->emc_pmacro_ca_tx_drive << 10 >> 26 << 12) | ((sdram->emc_pmacro_ca_tx_drive << 18 >> 26 << 6) | (sdram->emc_pmacro_ca_tx_drive & 0x3F | (pmc->scratch86 >> 6 << 6)) & 0xFFFFF03F) & 0xFFFC0FFF) & 0xFF03FFFF) & 0xC0FFFFFF) >> 2); - pmc->scratch87 = (sdram->emc_pmacro_vttgen_ctrl2 >> 16 << 24) | ((16 * sdram->emc_pmacro_zcrtl >> 30 << 22) | ((sdram->emc_pmacro_zcrtl << 6 >> 30 << 20) | ((sdram->emc_pmacro_zcrtl << 8 >> 30 << 18) | ((sdram->emc_pmacro_zcrtl << 10 >> 30 << 16) | ((sdram->emc_pmacro_zcrtl << 12 >> 30 << 14) | ((sdram->emc_pmacro_zcrtl << 14 >> 30 << 12) | ((sdram->emc_pmacro_zcrtl << 16 >> 30 << 10) | ((sdram->emc_pmacro_zcrtl << 18 >> 30 << 8) | ((sdram->emc_pmacro_zcrtl << 20 >> 30 << 6) | (16 * (sdram->emc_pmacro_zcrtl << 22 >> 30) | (4 * (sdram->emc_pmacro_zcrtl << 24 >> 30) | ((sdram->emc_pmacro_zcrtl << 26 >> 30) | 4 * (pmc->scratch87 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFFFFFF; - pmc->scratch88 = (sdram->mc_emem_arb_timing_rc << 24) | ((sdram->emc_zcal_interval << 14) | ((sdram->emc_zcal_interval << 8 >> 18) | (pmc->scratch88 >> 14 << 14)) & 0xFF003FFF) & 0xFFFFFF; - pmc->scratch89 = ((u16)(sdram->mc_emem_arb_rsv) << 24) | ((sdram->emc_data_brlshft0 << 8 >> 29 << 21) | ((sdram->emc_data_brlshft0 << 11 >> 29 << 18) | ((sdram->emc_data_brlshft0 << 14 >> 29 << 15) | ((sdram->emc_data_brlshft0 << 17 >> 29 << 12) | ((sdram->emc_data_brlshft0 << 20 >> 29 << 9) | ((sdram->emc_data_brlshft0 << 23 >> 29 << 6) | (8 * (sdram->emc_data_brlshft0 << 26 >> 29) | (sdram->emc_data_brlshft0 & 7 | 8 * (pmc->scratch89 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF) & 0xFFFFFF; - pmc->scratch90 = (sdram->emc_data_brlshft1 << 8 >> 29 << 21) | ((sdram->emc_data_brlshft1 << 11 >> 29 << 18) | ((sdram->emc_data_brlshft1 << 14 >> 29 << 15) | ((sdram->emc_data_brlshft1 << 17 >> 29 << 12) | ((sdram->emc_data_brlshft1 << 20 >> 29 << 9) | ((sdram->emc_data_brlshft1 << 23 >> 29 << 6) | (8 * (sdram->emc_data_brlshft1 << 26 >> 29) | (sdram->emc_data_brlshft1 & 7 | 8 * (pmc->scratch90 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF; - pmc->scratch91 = (sdram->emc_dqs_brlshft0 << 8 >> 29 << 21) | ((sdram->emc_dqs_brlshft0 << 11 >> 29 << 18) | ((sdram->emc_dqs_brlshft0 << 14 >> 29 << 15) | ((sdram->emc_dqs_brlshft0 << 17 >> 29 << 12) | ((sdram->emc_dqs_brlshft0 << 20 >> 29 << 9) | ((sdram->emc_dqs_brlshft0 << 23 >> 29 << 6) | (8 * (sdram->emc_dqs_brlshft0 << 26 >> 29) | (sdram->emc_dqs_brlshft0 & 7 | 8 * (pmc->scratch91 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF; - pmc->scratch92 = (sdram->emc_dqs_brlshft1 << 8 >> 29 << 21) | ((sdram->emc_dqs_brlshft1 << 11 >> 29 << 18) | ((sdram->emc_dqs_brlshft1 << 14 >> 29 << 15) | ((sdram->emc_dqs_brlshft1 << 17 >> 29 << 12) | ((sdram->emc_dqs_brlshft1 << 20 >> 29 << 9) | ((sdram->emc_dqs_brlshft1 << 23 >> 29 << 6) | (8 * (sdram->emc_dqs_brlshft1 << 26 >> 29) | (sdram->emc_dqs_brlshft1 & 7 | 8 * (pmc->scratch92 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF; - pmc->scratch93 = (2 * sdram->emc_swizzle_rank0_byte0 >> 29 << 21) | ((32 * sdram->emc_swizzle_rank0_byte0 >> 29 << 18) | ((sdram->emc_swizzle_rank0_byte0 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank0_byte0 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank0_byte0 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank0_byte0 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank0_byte0 << 25 >> 29) | (sdram->emc_swizzle_rank0_byte0 & 7 | 8 * (pmc->scratch93 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF; - pmc->scratch94 = ((u8)(sdram->emc_cfg) << 27 >> 31 << 31) | (2 * ((sdram->emc_ras << 24) | ((2 * sdram->emc_swizzle_rank0_byte1 >> 29 << 21) | ((32 * sdram->emc_swizzle_rank0_byte1 >> 29 << 18) | ((sdram->emc_swizzle_rank0_byte1 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank0_byte1 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank0_byte1 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank0_byte1 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank0_byte1 << 25 >> 29) | (sdram->emc_swizzle_rank0_byte1 & 7 | 8 * (pmc->scratch94 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch95 = ((u8)(sdram->emc_cfg) << 26 >> 31 << 31) | (2 * ((sdram->emc_w2p << 24) | ((2 * sdram->emc_swizzle_rank0_byte2 >> 29 << 21) | ((32 * sdram->emc_swizzle_rank0_byte2 >> 29 << 18) | ((sdram->emc_swizzle_rank0_byte2 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank0_byte2 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank0_byte2 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank0_byte2 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank0_byte2 << 25 >> 29) | (sdram->emc_swizzle_rank0_byte2 & 7 | 8 * (pmc->scratch95 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch96 = ((u8)(sdram->emc_cfg) << 25 >> 31 << 31) | (2 * ((sdram->emc_qsafe << 24) | ((2 * sdram->emc_swizzle_rank0_byte3 >> 29 << 21) | (((sdram->emc_swizzle_rank0_byte3 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank0_byte3 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank0_byte3 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank0_byte3 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank0_byte3 << 25 >> 29) | (sdram->emc_swizzle_rank0_byte3 & 7 | 8 * (pmc->scratch96 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF | (32 * sdram->emc_swizzle_rank0_byte3 >> 29 << 18)) & 0xFF1FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch97 = ((u8)(sdram->emc_cfg) << 24 >> 31 << 31) | (2 * ((sdram->emc_rdv << 24) | ((2 * sdram->emc_swizzle_rank1_byte0 >> 29 << 21) | (((sdram->emc_swizzle_rank1_byte0 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank1_byte0 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank1_byte0 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank1_byte0 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank1_byte0 << 25 >> 29) | (sdram->emc_swizzle_rank1_byte0 & 7 | 8 * (pmc->scratch97 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF | (32 * sdram->emc_swizzle_rank1_byte0 >> 29 << 18)) & 0xFF1FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch98 = ((u16)(sdram->emc_cfg) << 23 >> 31 << 31) | (2 * (((u16)(sdram->emc_rw2pden) << 24) | ((2 * sdram->emc_swizzle_rank1_byte1 >> 29 << 21) | ((32 * sdram->emc_swizzle_rank1_byte1 >> 29 << 18) | ((sdram->emc_swizzle_rank1_byte1 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank1_byte1 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank1_byte1 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank1_byte1 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank1_byte1 << 25 >> 29) | (sdram->emc_swizzle_rank1_byte1 & 7 | 8 * (pmc->scratch98 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch99 = ((u16)(sdram->emc_cfg) << 22 >> 31 << 31) | (2 * ((sdram->emc_tfaw << 24) | ((2 * sdram->emc_swizzle_rank1_byte2 >> 29 << 21) | ((32 * sdram->emc_swizzle_rank1_byte2 >> 29 << 18) | ((sdram->emc_swizzle_rank1_byte2 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank1_byte2 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank1_byte2 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank1_byte2 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank1_byte2 << 25 >> 29) | (sdram->emc_swizzle_rank1_byte2 & 7 | 8 * (pmc->scratch99 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch100 = (sdram->emc_cfg << 13 >> 31 << 31) | (2 * ((sdram->emc_tclkstable << 24) | ((2 * sdram->emc_swizzle_rank1_byte3 >> 29 << 21) | ((32 * sdram->emc_swizzle_rank1_byte3 >> 29 << 18) | ((sdram->emc_swizzle_rank1_byte3 << 9 >> 29 << 15) | ((sdram->emc_swizzle_rank1_byte3 << 13 >> 29 << 12) | ((sdram->emc_swizzle_rank1_byte3 << 17 >> 29 << 9) | ((sdram->emc_swizzle_rank1_byte3 << 21 >> 29 << 6) | (8 * (sdram->emc_swizzle_rank1_byte3 << 25 >> 29) | (sdram->emc_swizzle_rank1_byte3 & 7 | 8 * (pmc->scratch100 >> 3)) & 0xFFFFFFC7) & 0xFFFFFE3F) & 0xFFFFF1FF) & 0xFFFF8FFF) & 0xFFFC7FFF) & 0xFFE3FFFF) & 0xFF1FFFFF) & 0x80FFFFFF) >> 1); - tmp = 2 * (((u8)(sdram->emc_trtm) << 24) | ((16 * sdram->emc_cfg_pipe2 >> 31 << 23) | ((32 * sdram->emc_cfg_pipe2 >> 31 << 22) | ((sdram->emc_cfg_pipe2 << 6 >> 31 << 21) | ((sdram->emc_cfg_pipe2 << 7 >> 31 << 20) | ((sdram->emc_cfg_pipe2 << 8 >> 31 << 19) | ((sdram->emc_cfg_pipe2 << 9 >> 31 << 18) | ((sdram->emc_cfg_pipe2 << 10 >> 31 << 17) | ((sdram->emc_cfg_pipe2 << 11 >> 31 << 16) | ((sdram->emc_cfg_pipe2 << 12 >> 31 << 15) | ((sdram->emc_cfg_pipe2 << 13 >> 31 << 14) | ((sdram->emc_cfg_pipe2 << 14 >> 31 << 13) | ((sdram->emc_cfg_pipe2 << 15 >> 31 << 12) | ((sdram->emc_cfg_pipe2 << 20 >> 31 << 11) | ((sdram->emc_cfg_pipe2 << 21 >> 31 << 10) | ((sdram->emc_cfg_pipe2 << 22 >> 31 << 9) | ((sdram->emc_cfg_pipe2 << 23 >> 31 << 8) | ((sdram->emc_cfg_pipe2 << 24 >> 31 << 7) | ((sdram->emc_cfg_pipe2 << 25 >> 31 << 6) | (32 * (sdram->emc_cfg_pipe2 << 26 >> 31) | (16 * (sdram->emc_cfg_pipe2 << 27 >> 31) | (8 * (sdram->emc_cfg_pipe2 << 28 >> 31) | (4 * (sdram->emc_cfg_pipe2 << 29 >> 31) | (2 * (sdram->emc_cfg_pipe2 << 30 >> 31) | (sdram->emc_cfg_pipe2 & 1 | 2 * (pmc->scratch101 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1; - pmc->scratch101 = (sdram->emc_cfg << 10 >> 31 << 31) | tmp; - tmp = (2 * (pmc->scratch102 >> 1) | sdram->emc_cfg_pipe1 & 1) & 0xFFFFFFFD; - pmc->scratch102 = (sdram->emc_cfg << 9 >> 31 << 31) | (2 * (((u8)(sdram->emc_twtm) << 24) | ((16 * sdram->emc_cfg_pipe1 >> 31 << 23) | ((32 * sdram->emc_cfg_pipe1 >> 31 << 22) | ((sdram->emc_cfg_pipe1 << 6 >> 31 << 21) | ((sdram->emc_cfg_pipe1 << 7 >> 31 << 20) | ((sdram->emc_cfg_pipe1 << 8 >> 31 << 19) | ((sdram->emc_cfg_pipe1 << 9 >> 31 << 18) | ((sdram->emc_cfg_pipe1 << 10 >> 31 << 17) | ((sdram->emc_cfg_pipe1 << 11 >> 31 << 16) | ((sdram->emc_cfg_pipe1 << 12 >> 31 << 15) | ((sdram->emc_cfg_pipe1 << 13 >> 31 << 14) | ((sdram->emc_cfg_pipe1 << 14 >> 31 << 13) | ((sdram->emc_cfg_pipe1 << 15 >> 31 << 12) | ((sdram->emc_cfg_pipe1 << 20 >> 31 << 11) | ((sdram->emc_cfg_pipe1 << 21 >> 31 << 10) | ((sdram->emc_cfg_pipe1 << 22 >> 31 << 9) | ((sdram->emc_cfg_pipe1 << 23 >> 31 << 8) | ((sdram->emc_cfg_pipe1 << 24 >> 31 << 7) | ((sdram->emc_cfg_pipe1 << 25 >> 31 << 6) | (32 * (sdram->emc_cfg_pipe1 << 26 >> 31) | (16 * (sdram->emc_cfg_pipe1 << 27 >> 31) | (8 * (sdram->emc_cfg_pipe1 << 28 >> 31) | (4 * (sdram->emc_cfg_pipe1 << 29 >> 31) | (2 * (sdram->emc_cfg_pipe1 << 30 >> 31) | tmp) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1); - tmp = 2 * (((u8)(sdram->emc_tratm) << 24) | ((sdram->emc_pmacro_ddll_pwrd0 >> 31 << 23) | ((2 * sdram->emc_pmacro_ddll_pwrd0 >> 31 << 22) | ((8 * sdram->emc_pmacro_ddll_pwrd0 >> 31 << 21) | ((16 * sdram->emc_pmacro_ddll_pwrd0 >> 31 << 20) | ((32 * sdram->emc_pmacro_ddll_pwrd0 >> 31 << 19) | ((sdram->emc_pmacro_ddll_pwrd0 << 6 >> 31 << 18) | ((sdram->emc_pmacro_ddll_pwrd0 << 8 >> 31 << 17) | ((sdram->emc_pmacro_ddll_pwrd0 << 9 >> 31 << 16) | ((sdram->emc_pmacro_ddll_pwrd0 << 11 >> 31 << 15) | ((sdram->emc_pmacro_ddll_pwrd0 << 12 >> 31 << 14) | ((sdram->emc_pmacro_ddll_pwrd0 << 13 >> 31 << 13) | ((sdram->emc_pmacro_ddll_pwrd0 << 14 >> 31 << 12) | ((sdram->emc_pmacro_ddll_pwrd0 << 16 >> 31 << 11) | ((sdram->emc_pmacro_ddll_pwrd0 << 17 >> 31 << 10) | ((sdram->emc_pmacro_ddll_pwrd0 << 19 >> 31 << 9) | ((sdram->emc_pmacro_ddll_pwrd0 << 20 >> 31 << 8) | ((sdram->emc_pmacro_ddll_pwrd0 << 21 >> 31 << 7) | ((sdram->emc_pmacro_ddll_pwrd0 << 22 >> 31 << 6) | (32 * (sdram->emc_pmacro_ddll_pwrd0 << 24 >> 31) | (16 * (sdram->emc_pmacro_ddll_pwrd0 << 25 >> 31) | (8 * (sdram->emc_pmacro_ddll_pwrd0 << 27 >> 31) | (4 * (sdram->emc_pmacro_ddll_pwrd0 << 28 >> 31) | (2 * (sdram->emc_pmacro_ddll_pwrd0 << 29 >> 31) | ((sdram->emc_pmacro_ddll_pwrd0 << 30 >> 31) | 2 * (pmc->scratch103 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1; - pmc->scratch103 = (sdram->emc_cfg << 8 >> 31 << 31) | tmp; - tmp = 2 * (((u8)(sdram->emc_twatm) << 24) | ((sdram->emc_pmacro_ddll_pwrd1 >> 31 << 23) | ((2 * sdram->emc_pmacro_ddll_pwrd1 >> 31 << 22) | ((8 * sdram->emc_pmacro_ddll_pwrd1 >> 31 << 21) | ((16 * sdram->emc_pmacro_ddll_pwrd1 >> 31 << 20) | ((32 * sdram->emc_pmacro_ddll_pwrd1 >> 31 << 19) | ((sdram->emc_pmacro_ddll_pwrd1 << 6 >> 31 << 18) | ((sdram->emc_pmacro_ddll_pwrd1 << 8 >> 31 << 17) | ((sdram->emc_pmacro_ddll_pwrd1 << 9 >> 31 << 16) | ((sdram->emc_pmacro_ddll_pwrd1 << 11 >> 31 << 15) | ((sdram->emc_pmacro_ddll_pwrd1 << 12 >> 31 << 14) | ((sdram->emc_pmacro_ddll_pwrd1 << 13 >> 31 << 13) | ((sdram->emc_pmacro_ddll_pwrd1 << 14 >> 31 << 12) | ((sdram->emc_pmacro_ddll_pwrd1 << 16 >> 31 << 11) | ((sdram->emc_pmacro_ddll_pwrd1 << 17 >> 31 << 10) | ((sdram->emc_pmacro_ddll_pwrd1 << 19 >> 31 << 9) | ((sdram->emc_pmacro_ddll_pwrd1 << 20 >> 31 << 8) | ((sdram->emc_pmacro_ddll_pwrd1 << 21 >> 31 << 7) | ((sdram->emc_pmacro_ddll_pwrd1 << 22 >> 31 << 6) | (32 * (sdram->emc_pmacro_ddll_pwrd1 << 24 >> 31) | (16 * (sdram->emc_pmacro_ddll_pwrd1 << 25 >> 31) | (8 * (sdram->emc_pmacro_ddll_pwrd1 << 27 >> 31) | (4 * (sdram->emc_pmacro_ddll_pwrd1 << 28 >> 31) | (2 * (sdram->emc_pmacro_ddll_pwrd1 << 29 >> 31) | ((sdram->emc_pmacro_ddll_pwrd1 << 30 >> 31) | 2 * (pmc->scratch104 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1; - pmc->scratch104 = (sdram->emc_cfg << 7 >> 31 << 31) | tmp; - tmp = (sdram->emc_pmacro_ddll_pwrd2 << 22 >> 31 << 6) | (32 * (sdram->emc_pmacro_ddll_pwrd2 << 24 >> 31) | (16 * (sdram->emc_pmacro_ddll_pwrd2 << 25 >> 31) | (8 * (sdram->emc_pmacro_ddll_pwrd2 << 27 >> 31) | (4 * (sdram->emc_pmacro_ddll_pwrd2 << 28 >> 31) | (2 * (sdram->emc_pmacro_ddll_pwrd2 << 29 >> 31) | ((sdram->emc_pmacro_ddll_pwrd2 << 30 >> 31) | 2 * (pmc->scratch105 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF; - pmc->scratch105 = (sdram->emc_cfg << 6 >> 31 << 31) | (2 * (((u8)(sdram->emc_tr2ref) << 24) | ((sdram->emc_pmacro_ddll_pwrd2 >> 31 << 23) | ((2 * sdram->emc_pmacro_ddll_pwrd2 >> 31 << 22) | ((8 * sdram->emc_pmacro_ddll_pwrd2 >> 31 << 21) | ((16 * sdram->emc_pmacro_ddll_pwrd2 >> 31 << 20) | ((32 * sdram->emc_pmacro_ddll_pwrd2 >> 31 << 19) | ((sdram->emc_pmacro_ddll_pwrd2 << 6 >> 31 << 18) | ((sdram->emc_pmacro_ddll_pwrd2 << 8 >> 31 << 17) | ((sdram->emc_pmacro_ddll_pwrd2 << 9 >> 31 << 16) | ((sdram->emc_pmacro_ddll_pwrd2 << 11 >> 31 << 15) | ((sdram->emc_pmacro_ddll_pwrd2 << 12 >> 31 << 14) | ((sdram->emc_pmacro_ddll_pwrd2 << 13 >> 31 << 13) | ((sdram->emc_pmacro_ddll_pwrd2 << 14 >> 31 << 12) | ((sdram->emc_pmacro_ddll_pwrd2 << 16 >> 31 << 11) | ((sdram->emc_pmacro_ddll_pwrd2 << 17 >> 31 << 10) | ((sdram->emc_pmacro_ddll_pwrd2 << 19 >> 31 << 9) | ((sdram->emc_pmacro_ddll_pwrd2 << 20 >> 31 << 8) | ((sdram->emc_pmacro_ddll_pwrd2 << 21 >> 31 << 7) | tmp & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch106 = (32 * sdram->emc_cfg >> 31 << 31) | (2 * (((u16)(sdram->emc_pdex2mrr) << 24) | ((8 * sdram->emc_pmacro_ddll_periodic_offset >> 31 << 23) | ((16 * sdram->emc_pmacro_ddll_periodic_offset >> 31 << 22) | ((32 * sdram->emc_pmacro_ddll_periodic_offset >> 31 << 21) | ((sdram->emc_pmacro_ddll_periodic_offset << 6 >> 31 << 20) | ((sdram->emc_pmacro_ddll_periodic_offset << 7 >> 31 << 19) | ((sdram->emc_pmacro_ddll_periodic_offset << 8 >> 31 << 18) | ((sdram->emc_pmacro_ddll_periodic_offset << 9 >> 31 << 17) | ((sdram->emc_pmacro_ddll_periodic_offset << 10 >> 31 << 16) | ((sdram->emc_pmacro_ddll_periodic_offset << 11 >> 31 << 15) | ((sdram->emc_pmacro_ddll_periodic_offset << 15 >> 31 << 14) | ((sdram->emc_pmacro_ddll_periodic_offset << 16 >> 31 << 13) | ((sdram->emc_pmacro_ddll_periodic_offset << 17 >> 31 << 12) | ((sdram->emc_pmacro_ddll_periodic_offset << 18 >> 31 << 11) | ((sdram->emc_pmacro_ddll_periodic_offset << 19 >> 31 << 10) | ((sdram->emc_pmacro_ddll_periodic_offset << 20 >> 31 << 9) | ((sdram->emc_pmacro_ddll_periodic_offset << 21 >> 31 << 8) | ((sdram->emc_pmacro_ddll_periodic_offset << 22 >> 31 << 7) | ((sdram->emc_pmacro_ddll_periodic_offset << 23 >> 31 << 6) | (sdram->emc_pmacro_ddll_periodic_offset & 0x3F | (pmc->scratch106 >> 6 << 6)) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1); - pmc->scratch107 = (8 * sdram->emc_cfg >> 31 << 31) | (2 * ((sdram->emc_clken_override << 15 >> 31 << 30) | ((sdram->emc_clken_override << 23 >> 31 << 29) | ((sdram->emc_clken_override << 24 >> 31 << 28) | ((sdram->emc_clken_override << 25 >> 31 << 27) | ((sdram->emc_clken_override << 28 >> 31 << 26) | ((sdram->emc_clken_override << 29 >> 31 << 25) | ((sdram->emc_clken_override << 30 >> 31 << 24) | ((sdram->mc_emem_arb_da_covers << 8 >> 24 << 16) | ((sdram->mc_emem_arb_da_covers << 16 >> 24 << 8) | (sdram->mc_emem_arb_da_covers & 0xFF | (pmc->scratch107 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch108 = (sdram->emc_rfc_pb << 23) | ((sdram->emc_xm2_comp_pad_ctrl >> 24 << 15) | ((sdram->emc_xm2_comp_pad_ctrl << 12 >> 24 << 7) | ((sdram->emc_xm2_comp_pad_ctrl << 20 >> 31 << 6) | (32 * (sdram->emc_xm2_comp_pad_ctrl << 22 >> 31) | (4 * (sdram->emc_xm2_comp_pad_ctrl << 25 >> 29) | (sdram->emc_xm2_comp_pad_ctrl & 3 | 4 * (pmc->scratch108 >> 2)) & 0xFFFFFFE3) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFF807F) & 0xFF807FFF) & 0x7FFFFF; - pmc->scratch109 = (sdram->emc_cfg_update >> 31 << 31) | (2 * ((2 * sdram->emc_cfg_update >> 31 << 30) | ((4 * sdram->emc_cfg_update >> 31 << 29) | ((8 * sdram->emc_cfg_update >> 31 << 28) | ((sdram->emc_cfg_update << 21 >> 30 << 26) | ((sdram->emc_cfg_update << 23 >> 31 << 25) | ((sdram->emc_cfg_update << 29 >> 30 << 23) | ((sdram->emc_cfg_update << 22) & 0x7FFFFF | ((sdram->emc_auto_cal_config3 << 8 >> 28 << 18) | ((sdram->emc_auto_cal_config3 << 12 >> 28 << 14) | ((sdram->emc_auto_cal_config3 << 17 >> 25 << 7) | ((pmc->scratch109 >> 7 << 7) | sdram->emc_auto_cal_config3 & 0x7F) & 0xFFFFC07F) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0xFFBFFFFF) & 0xFE7FFFFF) & 0xFDFFFFFF) & 0xF3FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch110 = (sdram->emc_rfc << 22) | ((sdram->emc_auto_cal_config4 << 8 >> 28 << 18) | ((sdram->emc_auto_cal_config4 << 12 >> 28 << 14) | ((sdram->emc_auto_cal_config4 << 17 >> 25 << 7) | (sdram->emc_auto_cal_config4 & 0x7F | (pmc->scratch110 >> 7 << 7)) & 0xFFFFC07F) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0x3FFFFF; - pmc->scratch111 = ((u16)(sdram->emc_txsr) << 22) | ((sdram->emc_auto_cal_config5 << 8 >> 28 << 18) | ((sdram->emc_auto_cal_config5 << 12 >> 28 << 14) | ((sdram->emc_auto_cal_config5 << 17 >> 25 << 7) | ((pmc->scratch111 >> 7 << 7) | sdram->emc_auto_cal_config5 & 0x7F) & 0xFFFFC07F) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0x3FFFFF; - pmc->scratch112 = (16 * sdram->emc_mc2emc_q >> 28 << 28) | ((sdram->emc_mc2emc_q << 21 >> 29 << 25) | ((sdram->emc_mc2emc_q << 22) & 0x1FFFFFF | ((sdram->emc_auto_cal_config6 << 8 >> 28 << 18) | ((sdram->emc_auto_cal_config6 << 12 >> 28 << 14) | ((sdram->emc_auto_cal_config6 << 17 >> 25 << 7) | (sdram->emc_auto_cal_config6 & 0x7F | (pmc->scratch112 >> 7 << 7)) & 0xFFFFC07F) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0xFE3FFFFF) & 0xF1FFFFFF) & 0xFFFFFFF; - pmc->scratch113 = (sdram->mc_emem_arb_ring1_throttle << 11 >> 27 << 27) | ((sdram->mc_emem_arb_ring1_throttle << 22) | ((sdram->emc_auto_cal_config7 << 8 >> 28 << 18) | ((sdram->emc_auto_cal_config7 << 12 >> 28 << 14) | ((sdram->emc_auto_cal_config7 << 17 >> 25 << 7) | (sdram->emc_auto_cal_config7 & 0x7F | (pmc->scratch113 >> 7 << 7)) & 0xFFFFC07F) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0xF83FFFFF) & 0x7FFFFFF; - pmc->scratch114 = (sdram->emc_auto_cal_config8 << 8 >> 28 << 18) | ((sdram->emc_auto_cal_config8 << 12 >> 28 << 14) | ((sdram->emc_auto_cal_config8 << 17 >> 25 << 7) | (sdram->emc_auto_cal_config8 & 0x7F | (pmc->scratch114 >> 7 << 7)) & 0xFFFFC07F) & 0xFFFC3FFF) & 0xFFC3FFFF; - pmc->scratch115 = (4 * sdram->emc_cfg >> 31 << 31) | (2 * (((u16)(sdram->emc_ar2pden) << 22) | ((sdram->emc_fbio_cfg7 << 10 >> 30 << 20) | ((sdram->emc_fbio_cfg7 << 12 >> 31 << 19) | ((sdram->emc_fbio_cfg7 << 13 >> 31 << 18) | ((sdram->emc_fbio_cfg7 << 14 >> 31 << 17) | ((sdram->emc_fbio_cfg7 << 15 >> 31 << 16) | ((sdram->emc_fbio_cfg7 << 16 >> 31 << 15) | ((sdram->emc_fbio_cfg7 << 17 >> 31 << 14) | ((sdram->emc_fbio_cfg7 << 18 >> 31 << 13) | ((sdram->emc_fbio_cfg7 << 19 >> 31 << 12) | ((sdram->emc_fbio_cfg7 << 20 >> 31 << 11) | ((sdram->emc_fbio_cfg7 << 21 >> 31 << 10) | ((sdram->emc_fbio_cfg7 << 22 >> 31 << 9) | ((sdram->emc_fbio_cfg7 << 23 >> 31 << 8) | ((sdram->emc_fbio_cfg7 << 24 >> 31 << 7) | ((sdram->emc_fbio_cfg7 << 25 >> 31 << 6) | (32 * (sdram->emc_fbio_cfg7 << 26 >> 31) | (16 * (sdram->emc_fbio_cfg7 << 27 >> 31) | (8 * (sdram->emc_fbio_cfg7 << 28 >> 31) | (4 * (sdram->emc_fbio_cfg7 << 29 >> 31) | (2 * (sdram->emc_fbio_cfg7 << 30 >> 31) | (sdram->emc_fbio_cfg7 & 1 | 2 * (pmc->scratch115 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFCFFFFF) & 0x803FFFFF) >> 1); - pmc->scratch123 = (2 * sdram->emc_cfg >> 31 << 31) | (2 * ((sdram->emc_rfc_slr << 22) | ((32 * sdram->emc_pmacro_quse_ddll_rank0_0 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank0_0 & 0x7FF | (pmc->scratch123 >> 11 << 11)) & 0xFFC007FF) & 0x803FFFFF) >> 1); - pmc->scratch124 = (sdram->emc_cfg >> 31 << 31) | (2 * ((4 * sdram->emc_ibdly >> 30 << 29) | ((sdram->emc_ibdly << 22) & 0x1FFFFFFF | ((32 * sdram->emc_pmacro_quse_ddll_rank0_1 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank0_1 & 0x7FF | (pmc->scratch124 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x9FFFFFFF) >> 1); - pmc->scratch125 = (sdram->emc_fbio_cfg5 << 27 >> 31 << 31) | (2 * (((u16)(sdram->mc_emem_arb_timing_rfcpb) << 22) | ((32 * sdram->emc_pmacro_quse_ddll_rank0_2 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank0_2 & 0x7FF | (pmc->scratch125 >> 11 << 11)) & 0xFFC007FF) & 0x803FFFFF) >> 1); - pmc->scratch126 = (sdram->emc_fbio_cfg5 << 16 >> 29 << 29) | ((sdram->emc_auto_cal_config9 << 25 >> 31 << 28) | ((sdram->emc_auto_cal_config9 << 26 >> 31 << 27) | ((sdram->emc_auto_cal_config9 << 27 >> 31 << 26) | ((sdram->emc_auto_cal_config9 << 28 >> 31 << 25) | ((sdram->emc_auto_cal_config9 << 29 >> 31 << 24) | ((sdram->emc_auto_cal_config9 << 30 >> 31 << 23) | ((sdram->emc_auto_cal_config9 << 22) & 0x7FFFFF | ((32 * sdram->emc_pmacro_quse_ddll_rank0_3 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank0_3 & 0x7FF | (pmc->scratch126 >> 11 << 11)) & 0xFFC007FF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0x1FFFFFFF; - pmc->scratch127 = ((u8)(sdram->emc_cfg2) << 26 >> 29 << 29) | ((sdram->emc_rdv_mask << 22) | ((32 * sdram->emc_pmacro_quse_ddll_rank0_4 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank0_4 & 0x7FF | (pmc->scratch127 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x1FFFFFFF; - pmc->scratch128 = (sdram->emc_pmacro_cmd_pad_tx_ctrl << 27 >> 29 << 29) | (((u8)(sdram->emc_rdv_early_mask) << 22) | ((32 * sdram->emc_pmacro_quse_ddll_rank0_5 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank0_5 & 0x7FF | (pmc->scratch128 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x1FFFFFFF; - pmc->scratch129 = (sdram->emc_pmacro_cmd_pad_tx_ctrl << 22 >> 29 << 29) | ((sdram->emc_rdv_early << 22) | ((32 * sdram->emc_pmacro_quse_ddll_rank1_0 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank1_0 & 0x7FF | (pmc->scratch129 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x1FFFFFFF; - pmc->scratch130 = (sdram->emc_pmacro_cmd_pad_tx_ctrl << 17 >> 29 << 29) | ((4 * sdram->emc_quse_width >> 31 << 28) | ((8 * sdram->emc_quse_width >> 31 << 27) | ((sdram->emc_quse_width << 22) & 0x7FFFFFF | ((32 * sdram->emc_pmacro_quse_ddll_rank1_1 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank1_1 & 0x7FF | (pmc->scratch130 >> 11 << 11)) & 0xFFC007FF) & 0xF83FFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0x1FFFFFFF; - pmc->scratch131 = (sdram->emc_pmacro_cmd_pad_tx_ctrl << 12 >> 29 << 29) | (((u16)(sdram->emc_pmacro_ddll_short_cmd_2) << 22) | ((32 * sdram->emc_pmacro_quse_ddll_rank1_2 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank1_2 & 0x7FF | (pmc->scratch131 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x1FFFFFFF; - pmc->scratch132 = (sdram->emc_pmacro_data_pad_tx_ctrl << 27 >> 29 << 29) | ((sdram->emc_pmacro_cmd_rx_term_mode << 18 >> 31 << 28) | ((sdram->emc_pmacro_cmd_rx_term_mode << 22 >> 30 << 26) | ((sdram->emc_pmacro_cmd_rx_term_mode << 26 >> 30 << 24) | ((sdram->emc_pmacro_cmd_rx_term_mode << 22) & 0xFFFFFF | ((32 * sdram->emc_pmacro_quse_ddll_rank1_3 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank1_3 & 0x7FF | (pmc->scratch132 >> 11 << 11)) & 0xFFC007FF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xEFFFFFFF) & 0x1FFFFFFF; - pmc->scratch133 = (sdram->emc_pmacro_data_pad_tx_ctrl << 22 >> 29 << 29) | ((sdram->emc_pmacro_data_rx_term_mode << 18 >> 31 << 28) | ((sdram->emc_pmacro_data_rx_term_mode << 22 >> 30 << 26) | ((sdram->emc_pmacro_data_rx_term_mode << 26 >> 30 << 24) | ((sdram->emc_pmacro_data_rx_term_mode << 22) & 0xFFFFFF | ((32 * sdram->emc_pmacro_quse_ddll_rank1_4 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank1_4 & 0x7FF | (pmc->scratch133 >> 11 << 11)) & 0xFFC007FF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xEFFFFFFF) & 0x1FFFFFFF; - pmc->scratch134 = (sdram->emc_pmacro_data_pad_tx_ctrl << 17 >> 29 << 29) | ((sdram->mc_emem_arb_timing_rp << 22) | ((32 * sdram->emc_pmacro_quse_ddll_rank1_5 >> 21 << 11) | (sdram->emc_pmacro_quse_ddll_rank1_5 & 0x7FF | (pmc->scratch134 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x1FFFFFFF; - pmc->scratch135 = (sdram->emc_pmacro_data_pad_tx_ctrl << 12 >> 29 << 29) | ((sdram->mc_emem_arb_timing_ras << 22) | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank0_0 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank0_0 & 0x7FF | (pmc->scratch135 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x1FFFFFFF; - pmc->scratch136 = (sdram->emc_fbio_cfg5 << 23 >> 31 << 31) | (2 * ((sdram->emc_cfg << 14 >> 30 << 29) | ((sdram->mc_emem_arb_timing_faw << 22) & 0x1FFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank0_1 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank0_1 & 0x7FF | (pmc->scratch136 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x9FFFFFFF) >> 1); - pmc->scratch137 = (sdram->emc_fbio_cfg5 << 21 >> 31 << 31) | (2 * ((sdram->emc_fbio_cfg5 << 29) | ((sdram->mc_emem_arb_timing_rap2pre << 22) & 0x1FFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank0_2 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank0_2 & 0x7FF | (pmc->scratch137 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x9FFFFFFF) >> 1); - pmc->scratch138 = (sdram->emc_fbio_cfg5 << 19 >> 31 << 31) | (2 * ((sdram->emc_fbio_cfg5 << 28 >> 30 << 29) | ((sdram->mc_emem_arb_timing_wap2pre << 22) & 0x1FFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank0_3 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank0_3 & 0x7FF | (pmc->scratch138 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x9FFFFFFF) >> 1); - pmc->scratch139 = (sdram->emc_fbio_cfg5 << 7 >> 31 << 31) | (2 * ((16 * sdram->emc_cfg2 >> 30 << 29) | (((u8)(sdram->mc_emem_arb_timing_r2w) << 22) & 0x1FFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank0_4 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank0_4 & 0x7FF | (pmc->scratch139 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0x9FFFFFFF) >> 1); - pmc->scratch140 = (16 * sdram->emc_fbio_cfg5 >> 31 << 31) | (2 * ((32 * sdram->emc_fbio_cfg5 >> 31 << 30) | ((sdram->emc_fbio_cfg5 << 6 >> 31 << 29) | (((u8)(sdram->mc_emem_arb_timing_w2r) << 22) & 0x1FFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank0_5 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank0_5 & 0x7FF | (pmc->scratch140 >> 11 << 11)) & 0xFFC007FF) & 0xE03FFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch141 = (sdram->emc_fbio_cfg5 << 8 >> 28 << 28) | (((u16)(sdram->emc_wdv) << 22) | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank1_0 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank1_0 & 0x7FF | (pmc->scratch141 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xFFFFFFF; - pmc->scratch142 = ((u8)(sdram->emc_cfg2) << 31) | (2 * ((sdram->emc_fbio_cfg5 >> 31 << 30) | ((2 * sdram->emc_fbio_cfg5 >> 31 << 29) | ((8 * sdram->emc_fbio_cfg5 >> 31 << 28) | ((sdram->emc_quse << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank1_1 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank1_1 & 0x7FF | (pmc->scratch142 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch143 = (((u16)(sdram->emc_cfg2) << 21) >> 31 << 31) | (2 * ((((u16)(sdram->emc_cfg2) << 24) >> 31 << 30) | ((((u16)(sdram->emc_cfg2) << 29) >> 31 << 29) | ((((u16)(sdram->emc_cfg2) << 30) >> 31 << 28) | (((u8)(sdram->emc_pdex2wr) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank1_2 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank1_2 & 0x7FF | (pmc->scratch143 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch144 = (sdram->emc_cfg2 << 15 >> 31 << 31) | (2 * ((sdram->emc_cfg2 << 16 >> 31 << 30) | ((sdram->emc_cfg2 << 17 >> 31 << 29) | ((sdram->emc_cfg2 << 20 >> 31 << 28) | (((u8)(sdram->emc_pdex2rd) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank1_3 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank1_3 & 0x7FF | (pmc->scratch144 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch145 = (sdram->emc_cfg2 << 7 >> 31 << 31) | (2 * ((sdram->emc_cfg2 << 8 >> 31 << 30) | ((sdram->emc_cfg2 << 9 >> 31 << 29) | ((sdram->emc_cfg2 << 11 >> 31 << 28) | (((u16)(sdram->emc_pdex2che) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank1_4 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank1_4 & 0x7FF | (pmc->scratch145 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch146 = (2 * sdram->emc_cfg2 >> 31 << 31) | (2 * ((4 * sdram->emc_cfg2 >> 31 << 30) | (((sdram->emc_cfg2 << 6 >> 31 << 28) | (((u8)(sdram->emc_pchg2pden) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dq_rank1_5 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dq_rank1_5 & 0x7FF | (pmc->scratch146 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF | (8 * sdram->emc_cfg2 >> 31 << 29)) & 0xBFFFFFFF) >> 1); - pmc->scratch147 = (((u8)(sdram->emc_cfg_pipe) << 29) >> 31 << 31) | (2 * ((((u8)(sdram->emc_cfg_pipe) << 30) >> 31 << 30) | ((((u8)(sdram->emc_cfg_pipe) << 31) >> 2) | ((sdram->emc_cfg2 >> 31 << 28) | (((u16)(sdram->emc_act2pden) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank0_0 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank0_0 & 0x7FF | (pmc->scratch147 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch148 = (((u8)(sdram->emc_cfg_pipe) << 25) >> 31 << 31) | (2 * ((((u8)(sdram->emc_cfg_pipe) << 26) >> 31 << 30) | ((((u8)(sdram->emc_cfg_pipe) << 27) >> 31 << 29) | ((((u8)(sdram->emc_cfg_pipe) << 28) >> 31 << 28) | (((u16)(sdram->emc_cke2pden) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank0_1 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank0_1 & 0x7FF | (pmc->scratch148 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch149 = (((u16)(sdram->emc_cfg_pipe) << 21) >> 31 << 31) | (2 * ((((u16)(sdram->emc_cfg_pipe) << 22) >> 31 << 30) | ((((u16)(sdram->emc_cfg_pipe) << 23) >> 31 << 29) | ((((u16)(sdram->emc_cfg_pipe) << 24) >> 31 << 28) | ((sdram->emc_tcke << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank0_2 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank0_2 & 0x7FF | (pmc->scratch149 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch150 = (sdram->emc_cfg_pipe << 13 >> 31 << 31) | (2 * ((sdram->emc_cfg_pipe << 14 >> 31 << 30) | (((sdram->emc_cfg_pipe << 20 >> 31 << 28) | ((sdram->emc_trpab << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank0_3 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank0_3 & 0x7FF | (pmc->scratch150 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF | (sdram->emc_cfg_pipe << 15 >> 31 << 29)) & 0xBFFFFFFF) >> 1); - pmc->scratch151 = (sdram->emc_cfg_pipe << 9 >> 31 << 31) | (2 * ((sdram->emc_cfg_pipe << 10 >> 31 << 30) | ((sdram->emc_cfg_pipe << 11 >> 31 << 29) | ((sdram->emc_cfg_pipe << 12 >> 31 << 28) | ((sdram->emc_einput << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank0_4 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank0_4 & 0x7FF | (pmc->scratch151 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch152 = (32 * sdram->emc_cfg_pipe >> 31 << 31) | (2 * ((sdram->emc_cfg_pipe << 6 >> 31 << 30) | ((sdram->emc_cfg_pipe << 7 >> 31 << 29) | ((sdram->emc_cfg_pipe << 8 >> 31 << 28) | ((sdram->emc_einput_duration << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank0_5 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank0_5 & 0x7FF | (pmc->scratch152 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch153 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 29) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 30) >> 31 << 30) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 31) >> 2) | ((16 * sdram->emc_cfg_pipe >> 31 << 28) | ((sdram->emc_puterm_extra << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank1_0 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank1_0 & 0x7FF | (pmc->scratch153 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch154 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 25) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 26) >> 31 << 30) | (((((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 28) >> 31 << 28) | ((sdram->emc_tckesr << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank1_1 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank1_1 & 0x7FF | (pmc->scratch154 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF | (((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 27) >> 31 << 29)) & 0xBFFFFFFF) >> 1); - pmc->scratch155 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 21) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 22) >> 31 << 30) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 23) >> 31 << 29) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src0) << 24) >> 31 << 28) | ((sdram->emc_tpd << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank1_2 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank1_2 & 0x7FF | (pmc->scratch155 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch156 = (sdram->emc_pmacro_tx_sel_clk_src0 << 12 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src0 << 13 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src0 << 14 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src0 << 15 >> 31 << 28) | ((sdram->emc_wdv_mask << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank1_3 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank1_3 & 0x7FF | (pmc->scratch156 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch157 = (sdram->emc_pmacro_tx_sel_clk_src0 << 8 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src0 << 9 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src0 << 10 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src0 << 11 >> 31 << 28) | (((u16)(sdram->emc_wdv_chk) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank1_4 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank1_4 & 0x7FF | (pmc->scratch157 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch158 = ((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 31) | (2 * ((32 * sdram->emc_pmacro_tx_sel_clk_src0 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src0 << 6 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src0 << 7 >> 31 << 28) | (((u8)(sdram->emc_cmd_brlshft0) << 26 >> 29 << 25) | (((u8)(sdram->emc_cmd_brlshft0) << 22) & 0x1FFFFFF | ((32 * sdram->emc_pmacro_ob_ddll_long_dqs_rank1_5 >> 21 << 11) | (sdram->emc_pmacro_ob_ddll_long_dqs_rank1_5 & 0x7FF | (pmc->scratch158 >> 11 << 11)) & 0xFFC007FF) & 0xFE3FFFFF) & 0xF1FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch159 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 27) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 28) >> 31 << 30) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 29) >> 31 << 29) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 30) >> 31 << 28) | (((u8)(sdram->emc_cmd_brlshft1) << 26 >> 29 << 25) | (((u8)(sdram->emc_cmd_brlshft1) << 22) & 0x1FFFFFF | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank0_0 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank0_0 & 0x7FF | (pmc->scratch159 >> 11 << 11)) & 0xFFC007FF) & 0xFE3FFFFF) & 0xF1FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch160 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 23) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 24) >> 31 << 30) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 25) >> 31 << 29) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src1) << 26) >> 31 << 28) | (((u8)(sdram->emc_cmd_brlshft2) << 26 >> 29 << 25) | (((u8)(sdram->emc_cmd_brlshft2) << 22) & 0x1FFFFFF | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank0_1 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank0_1 & 0x7FF | (pmc->scratch160 >> 11 << 11)) & 0xFFC007FF) & 0xFE3FFFFF) & 0xF1FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch161 = (sdram->emc_pmacro_tx_sel_clk_src1 << 14 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src1 << 15 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src1 << 21 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src1 << 22 >> 31 << 28) | (((u8)(sdram->emc_cmd_brlshft3) << 26 >> 29 << 25) | (((u8)(sdram->emc_cmd_brlshft3) << 22) & 0x1FFFFFF | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank0_2 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank0_2 & 0x7FF | (pmc->scratch161 >> 11 << 11)) & 0xFFC007FF) & 0xFE3FFFFF) & 0xF1FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch162 = (sdram->emc_pmacro_tx_sel_clk_src1 << 10 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src1 << 11 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src1 << 12 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src1 << 13 >> 31 << 28) | (((u16)(sdram->emc_wev) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank0_3 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank0_3 & 0x7FF | (pmc->scratch162 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch163 = (sdram->emc_pmacro_tx_sel_clk_src1 << 6 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src1 << 7 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src1 << 8 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src1 << 9 >> 31 << 28) | (((u16)(sdram->emc_wsv) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank1_0 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank1_0 & 0x7FF | (pmc->scratch163 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch164 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 29) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 30) >> 31 << 30) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 31) >> 2) | ((32 * sdram->emc_pmacro_tx_sel_clk_src1 >> 31 << 28) | (((u8)(sdram->emc_cfg3) << 25 >> 29 << 25) | (((u8)(sdram->emc_cfg3) << 22) & 0x1FFFFFF | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank1_1 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank1_1 & 0x7FF | (pmc->scratch164 >> 11 << 11)) & 0xFFC007FF) & 0xFE3FFFFF) & 0xF1FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch165 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 25) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 26) >> 31 << 30) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 27) >> 31 << 29) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 28) >> 31 << 28) | ((sdram->emc_puterm_width << 23) & 0xFFFFFFF | ((sdram->emc_puterm_width >> 31 << 22) | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank1_2 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank1_2 & 0x7FF | (pmc->scratch165 >> 11 << 11)) & 0xFFC007FF) & 0xFFBFFFFF) & 0xF07FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch166 = (((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 21) >> 31 << 31) | (2 * ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 22) >> 31 << 30) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 23) >> 31 << 29) | ((((u16)(sdram->emc_pmacro_tx_sel_clk_src3) << 24) >> 31 << 28) | ((sdram->mc_emem_arb_timing_rcd << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ib_ddll_long_dqs_rank1_3 >> 21 << 11) | (sdram->emc_pmacro_ib_ddll_long_dqs_rank1_3 & 0x7FF | (pmc->scratch166 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch167 = (sdram->emc_pmacro_tx_sel_clk_src3 << 12 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src3 << 13 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src3 << 14 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src3 << 15 >> 31 << 28) | (((u16)(sdram->mc_emem_arb_timing_ccdmw) << 22) & 0xFFFFFFF | ((32 * sdram->emc_pmacro_ddll_long_cmd_0 >> 21 << 11) | (sdram->emc_pmacro_ddll_long_cmd_0 & 0x7FF | (pmc->scratch167 >> 11 << 11)) & 0xFFC007FF) & 0xF03FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch168 = (sdram->emc_pmacro_tx_sel_clk_src3 << 8 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src3 << 9 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src3 << 10 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src3 << 11 >> 31 << 28) | ((sdram->mc_emem_arb_override << 28 >> 31 << 27) | (((sdram->mc_emem_arb_override << 21 >> 31 << 25) | ((sdram->mc_emem_arb_override << 15 >> 31 << 24) | ((32 * sdram->mc_emem_arb_override >> 31 << 23) | ((16 * sdram->mc_emem_arb_override >> 31 << 22) | ((32 * sdram->emc_pmacro_ddll_long_cmd_1 >> 21 << 11) | (sdram->emc_pmacro_ddll_long_cmd_1 & 0x7FF | (pmc->scratch168 >> 11 << 11)) & 0xFFC007FF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF | (sdram->mc_emem_arb_override << 27 >> 31 << 26)) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch169 = ((u16)(sdram->emc_rext) << 27) | (((u16)(sdram->emc_rrd) << 22) | ((32 * sdram->emc_pmacro_ddll_long_cmd_2 >> 21 << 11) | (sdram->emc_pmacro_ddll_long_cmd_2 & 0x7FF | (pmc->scratch169 >> 11 << 11)) & 0xFFC007FF) & 0xF83FFFFF) & 0x7FFFFFF; - pmc->scratch170 = ((u16)(sdram->emc_wext) << 27) | ((sdram->emc_tclkstop << 22) | ((32 * sdram->emc_pmacro_ddll_long_cmd_3 >> 21 << 11) | (sdram->emc_pmacro_ddll_long_cmd_3 & 0x7FF | (pmc->scratch170 >> 11 << 11)) & 0xFFC007FF) & 0xF83FFFFF) & 0x7FFFFFF; - tmp = (32 * sdram->emc_pmacro_perbit_fgcg_ctrl0 >> 31 << 21) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 6 >> 31 << 20) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 7 >> 31 << 19) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 8 >> 31 << 18) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 9 >> 31 << 17) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 10 >> 31 << 16) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 11 >> 31 << 15) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 12 >> 31 << 14) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 13 >> 31 << 13) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 14 >> 31 << 12) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 15 >> 31 << 11) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 21 >> 31 << 10) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 22 >> 31 << 9) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 23 >> 31 << 8) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 24 >> 31 << 7) | ((sdram->emc_pmacro_perbit_fgcg_ctrl0 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_perbit_fgcg_ctrl0 << 26 >> 31) | (16 * (sdram->emc_pmacro_perbit_fgcg_ctrl0 << 27 >> 31) | (8 * (sdram->emc_pmacro_perbit_fgcg_ctrl0 << 28 >> 31) | (4 * (sdram->emc_pmacro_perbit_fgcg_ctrl0 << 29 >> 31) | (2 * (sdram->emc_pmacro_perbit_fgcg_ctrl0 << 30 >> 31) | (sdram->emc_pmacro_perbit_fgcg_ctrl0 & 1 | 2 * (pmc->scratch171 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF; - pmc->scratch171 = (sdram->emc_we_duration << 27) | ((sdram->emc_ref_ctrl2 >> 31 << 26) | ((32 * sdram->emc_ref_ctrl2 >> 29 << 23) | ((sdram->emc_ref_ctrl2 << 22) & 0x7FFFFF | tmp & 0xFFBFFFFF) & 0xFC7FFFFF) & 0xFBFFFFFF) & 0x7FFFFFF; - tmp = (sdram->emc_pmacro_pad_cfg_ctrl << 22 >> 31 << 28) | ((sdram->emc_pmacro_pad_cfg_ctrl << 27) & 0xFFFFFFF | ((sdram->emc_ws_duration << 22) & 0x7FFFFFF | ((32 * sdram->emc_pmacro_perbit_fgcg_ctrl1 >> 31 << 21) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 6 >> 31 << 20) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 7 >> 31 << 19) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 8 >> 31 << 18) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 9 >> 31 << 17) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 10 >> 31 << 16) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 11 >> 31 << 15) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 12 >> 31 << 14) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 13 >> 31 << 13) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 14 >> 31 << 12) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 15 >> 31 << 11) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 21 >> 31 << 10) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 22 >> 31 << 9) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 23 >> 31 << 8) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 24 >> 31 << 7) | ((sdram->emc_pmacro_perbit_fgcg_ctrl1 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_perbit_fgcg_ctrl1 << 26 >> 31) | (16 * (sdram->emc_pmacro_perbit_fgcg_ctrl1 << 27 >> 31) | (8 * (sdram->emc_pmacro_perbit_fgcg_ctrl1 << 28 >> 31) | (4 * (sdram->emc_pmacro_perbit_fgcg_ctrl1 << 29 >> 31) | (2 * (sdram->emc_pmacro_perbit_fgcg_ctrl1 << 30 >> 31) | (sdram->emc_pmacro_perbit_fgcg_ctrl1 & 1 | 2 * (pmc->scratch172 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xF83FFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF; - pmc->scratch172 = (sdram->emc_pmacro_pad_cfg_ctrl << 14 >> 30 << 30) | (4 * ((sdram->emc_pmacro_pad_cfg_ctrl << 18 >> 31 << 29) | tmp & 0xDFFFFFFF) >> 2); - pmc->scratch173 = ((u8)(sdram->mc_emem_arb_timing_r2r) << 27) | ((sdram->mc_emem_arb_timing_rrd << 22) | ((32 * sdram->emc_pmacro_perbit_fgcg_ctrl2 >> 31 << 21) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 6 >> 31 << 20) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 7 >> 31 << 19) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 8 >> 31 << 18) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 9 >> 31 << 17) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 10 >> 31 << 16) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 11 >> 31 << 15) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 12 >> 31 << 14) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 13 >> 31 << 13) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 14 >> 31 << 12) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 15 >> 31 << 11) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 21 >> 31 << 10) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 22 >> 31 << 9) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 23 >> 31 << 8) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 24 >> 31 << 7) | ((sdram->emc_pmacro_perbit_fgcg_ctrl2 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_perbit_fgcg_ctrl2 << 26 >> 31) | (16 * (sdram->emc_pmacro_perbit_fgcg_ctrl2 << 27 >> 31) | (8 * (sdram->emc_pmacro_perbit_fgcg_ctrl2 << 28 >> 31) | (4 * (sdram->emc_pmacro_perbit_fgcg_ctrl2 << 29 >> 31) | (2 * (sdram->emc_pmacro_perbit_fgcg_ctrl2 << 30 >> 31) | (sdram->emc_pmacro_perbit_fgcg_ctrl2 & 1 | 2 * (pmc->scratch173 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xF83FFFFF) & 0x7FFFFFF; - tmp = 32 * (sdram->emc_pmacro_perbit_fgcg_ctrl3 << 26 >> 31) | (16 * (sdram->emc_pmacro_perbit_fgcg_ctrl3 << 27 >> 31) | (8 * (sdram->emc_pmacro_perbit_fgcg_ctrl3 << 28 >> 31) | (4 * (sdram->emc_pmacro_perbit_fgcg_ctrl3 << 29 >> 31) | (2 * (sdram->emc_pmacro_perbit_fgcg_ctrl3 << 30 >> 31) | (sdram->emc_pmacro_perbit_fgcg_ctrl3 & 1 | 2 * (pmc->scratch174 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF; - pmc->scratch174 = ((u16)(sdram->emc_pmacro_tx_sel_clk_src2) << 30 >> 31 << 31) | (2 * (((u16)(sdram->emc_pmacro_tx_sel_clk_src2) << 30) | ((32 * sdram->emc_pmacro_tx_sel_clk_src3 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src3 << 6 >> 31 << 28) | ((sdram->emc_pmacro_tx_sel_clk_src3 << 7 >> 31 << 27) | (((u8)(sdram->mc_emem_arb_timing_w2w) << 22) & 0x7FFFFFF | ((32 * sdram->emc_pmacro_perbit_fgcg_ctrl3 >> 31 << 21) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 6 >> 31 << 20) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 7 >> 31 << 19) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 8 >> 31 << 18) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 9 >> 31 << 17) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 10 >> 31 << 16) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 11 >> 31 << 15) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 12 >> 31 << 14) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 13 >> 31 << 13) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 14 >> 31 << 12) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 15 >> 31 << 11) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 21 >> 31 << 10) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 22 >> 31 << 9) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 23 >> 31 << 8) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 24 >> 31 << 7) | ((sdram->emc_pmacro_perbit_fgcg_ctrl3 << 25 >> 31 << 6) | tmp & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xF83FFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - tmp = (sdram->emc_pmacro_tx_sel_clk_src2 << 28 >> 31 << 23) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 29 >> 31 << 22) | ((32 * sdram->emc_pmacro_perbit_fgcg_ctrl4 >> 31 << 21) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 6 >> 31 << 20) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 7 >> 31 << 19) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 8 >> 31 << 18) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 9 >> 31 << 17) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 10 >> 31 << 16) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 11 >> 31 << 15) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 12 >> 31 << 14) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 13 >> 31 << 13) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 14 >> 31 << 12) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 15 >> 31 << 11) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 21 >> 31 << 10) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 22 >> 31 << 9) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 23 >> 31 << 8) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 24 >> 31 << 7) | ((sdram->emc_pmacro_perbit_fgcg_ctrl4 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_perbit_fgcg_ctrl4 << 26 >> 31) | (16 * (sdram->emc_pmacro_perbit_fgcg_ctrl4 << 27 >> 31) | (8 * (sdram->emc_pmacro_perbit_fgcg_ctrl4 << 28 >> 31) | (4 * (sdram->emc_pmacro_perbit_fgcg_ctrl4 << 29 >> 31) | (2 * (sdram->emc_pmacro_perbit_fgcg_ctrl4 << 30 >> 31) | (sdram->emc_pmacro_perbit_fgcg_ctrl4 & 1 | 2 * (pmc->scratch175 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF; - pmc->scratch175 = (sdram->emc_pmacro_tx_sel_clk_src2 << 15 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src2 << 21 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 22 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 23 >> 31 << 28) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 24 >> 31 << 27) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 25 >> 31 << 26) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 26 >> 31 << 25) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 27 >> 31 << 24) | tmp & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - tmp = (sdram->emc_pmacro_tx_sel_clk_src2 << 12 >> 31 << 24) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 13 >> 31 << 23) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 14 >> 31 << 22) | ((32 * sdram->emc_pmacro_perbit_fgcg_ctrl5 >> 31 << 21) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 6 >> 31 << 20) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 7 >> 31 << 19) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 8 >> 31 << 18) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 9 >> 31 << 17) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 10 >> 31 << 16) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 11 >> 31 << 15) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 12 >> 31 << 14) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 13 >> 31 << 13) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 14 >> 31 << 12) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 15 >> 31 << 11) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 21 >> 31 << 10) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 22 >> 31 << 9) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 23 >> 31 << 8) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 24 >> 31 << 7) | ((sdram->emc_pmacro_perbit_fgcg_ctrl5 << 25 >> 31 << 6) | (32 * (sdram->emc_pmacro_perbit_fgcg_ctrl5 << 26 >> 31) | (16 * (sdram->emc_pmacro_perbit_fgcg_ctrl5 << 27 >> 31) | (8 * (sdram->emc_pmacro_perbit_fgcg_ctrl5 << 28 >> 31) | (4 * (sdram->emc_pmacro_perbit_fgcg_ctrl5 << 29 >> 31) | (2 * (sdram->emc_pmacro_perbit_fgcg_ctrl5 << 30 >> 31) | (sdram->emc_pmacro_perbit_fgcg_ctrl5 & 1 | 2 * (pmc->scratch176 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF; - pmc->scratch176 = (32 * sdram->emc_pmacro_tx_sel_clk_src2 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src2 << 6 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 7 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 8 >> 31 << 28) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 9 >> 31 << 27) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 10 >> 31 << 26) | ((sdram->emc_pmacro_tx_sel_clk_src2 << 11 >> 31 << 25) | tmp & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch177 = (sdram->emc_pmacro_tx_sel_clk_src4 << 22 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src4 << 23 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 24 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 25 >> 31 << 28) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 26 >> 31 << 27) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 27 >> 31 << 26) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 28 >> 31 << 25) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 29 >> 31 << 24) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 30 >> 31 << 23) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 22) & 0x7FFFFF | ((sdram->mc_emem_arb_cfg >> 28 << 18) | ((16 * sdram->mc_emem_arb_cfg >> 28 << 14) | ((sdram->mc_emem_arb_cfg << 11 >> 27 << 9) | (sdram->mc_emem_arb_cfg & 0x1FF | (pmc->scratch177 >> 9 << 9)) & 0xFFFFC1FF) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch178 = (sdram->emc_pmacro_tx_sel_clk_src4 << 7 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src4 << 8 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 9 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 10 >> 31 << 28) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 11 >> 31 << 27) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 12 >> 31 << 26) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 13 >> 31 << 25) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 14 >> 31 << 24) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 15 >> 31 << 23) | ((sdram->emc_pmacro_tx_sel_clk_src4 << 21 >> 31 << 22) | ((sdram->mc_emem_arb_misc1 >> 28 << 18) | ((sdram->mc_emem_arb_misc1 << 6 >> 30 << 16) | ((sdram->mc_emem_arb_misc1 << 8 >> 29 << 13) | (16 * (sdram->mc_emem_arb_misc1 << 19 >> 23) | (8 * (sdram->mc_emem_arb_misc1 << 28 >> 31) | (4 * (sdram->mc_emem_arb_misc1 << 29 >> 31) | (2 * (sdram->mc_emem_arb_misc1 << 30 >> 31) | (sdram->mc_emem_arb_misc1 & 1 | 2 * (pmc->scratch178 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFE00F) & 0xFFFF1FFF) & 0xFFFCFFFF) & 0xFFC3FFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch179 = (sdram->emc_odt_write >> 31 << 31) | (2 * ((sdram->emc_odt_write << 20 >> 28 << 27) | ((sdram->emc_odt_write << 26 >> 31 << 26) | ((sdram->emc_odt_write << 27 >> 31 << 25) | ((sdram->emc_odt_write << 21) & 0x1FFFFFF | ((32 * sdram->emc_mrs_wait_cnt2 >> 21 << 10) | (sdram->emc_mrs_wait_cnt2 & 0x3FF | (pmc->scratch179 >> 10 << 10)) & 0xFFE003FF) & 0xFE1FFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0x87FFFFFF) >> 1); - pmc->scratch180 = (sdram->emc_pmacro_ib_rxrt << 21) | ((32 * sdram->emc_mrs_wait_cnt >> 21 << 10) | (sdram->emc_mrs_wait_cnt & 0x3FF | (pmc->scratch180 >> 10 << 10)) & 0xFFE003FF) & 0x1FFFFF; - pmc->scratch181 = ((u16)(sdram->emc_pmacro_ddll_long_cmd_4) << 21) | sdram->emc_auto_cal_interval & 0x1FFFFF; - pmc->scratch182 = (sdram->mc_emem_arb_outstanding_req >> 31 << 31) | (2 * ((2 * sdram->mc_emem_arb_outstanding_req >> 31 << 30) | ((sdram->mc_emem_arb_outstanding_req << 23 >> 2) | ((sdram->emc_emem_arb_refpb_hp_ctrl << 9 >> 25 << 14) | ((sdram->emc_emem_arb_refpb_hp_ctrl << 17 >> 25 << 7) | (sdram->emc_emem_arb_refpb_hp_ctrl & 0x7F | (pmc->scratch182 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xC01FFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch183 = (4 * sdram->emc_pmacro_cmd_ctrl0 >> 31 << 31) | (2 * ((8 * sdram->emc_pmacro_cmd_ctrl0 >> 31 << 30) | ((sdram->emc_pmacro_cmd_ctrl0 << 7 >> 31 << 29) | ((sdram->emc_pmacro_cmd_ctrl0 << 10 >> 31 << 28) | ((sdram->emc_pmacro_cmd_ctrl0 << 11 >> 31 << 27) | ((sdram->emc_pmacro_cmd_ctrl0 << 15 >> 31 << 26) | ((sdram->emc_pmacro_cmd_ctrl0 << 18 >> 31 << 25) | ((sdram->emc_pmacro_cmd_ctrl0 << 19 >> 31 << 24) | ((sdram->emc_pmacro_cmd_ctrl0 << 23 >> 31 << 23) | ((sdram->emc_pmacro_cmd_ctrl0 << 26 >> 31 << 22) | ((sdram->emc_pmacro_cmd_ctrl0 << 27 >> 31 << 21) | ((sdram->emc_pmacro_cmd_ctrl0 << 20) & 0x1FFFFF | ((4 * sdram->emc_xm2_comp_pad_ctrl2 >> 26 << 14) | ((sdram->emc_xm2_comp_pad_ctrl2 << 10 >> 30 << 12) | ((sdram->emc_xm2_comp_pad_ctrl2 << 14 >> 31 << 11) | ((sdram->emc_xm2_comp_pad_ctrl2 << 15 >> 31 << 10) | ((sdram->emc_xm2_comp_pad_ctrl2 << 16 >> 30 << 8) | ((sdram->emc_xm2_comp_pad_ctrl2 << 18 >> 30 << 6) | (4 * (sdram->emc_xm2_comp_pad_ctrl2 << 26 >> 28) | (sdram->emc_xm2_comp_pad_ctrl2 & 3 | 4 * (pmc->scratch183 >> 2)) & 0xFFFFFFC3) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFCFFF) & 0xFFF03FFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch184 = (4 * sdram->emc_pmacro_cmd_ctrl1 >> 31 << 31) | (2 * ((8 * sdram->emc_pmacro_cmd_ctrl1 >> 31 << 30) | ((sdram->emc_pmacro_cmd_ctrl1 << 7 >> 31 << 29) | ((sdram->emc_pmacro_cmd_ctrl1 << 10 >> 31 << 28) | ((sdram->emc_pmacro_cmd_ctrl1 << 11 >> 31 << 27) | ((sdram->emc_pmacro_cmd_ctrl1 << 15 >> 31 << 26) | ((sdram->emc_pmacro_cmd_ctrl1 << 18 >> 31 << 25) | ((sdram->emc_pmacro_cmd_ctrl1 << 19 >> 31 << 24) | ((sdram->emc_pmacro_cmd_ctrl1 << 23 >> 31 << 23) | ((sdram->emc_pmacro_cmd_ctrl1 << 26 >> 31 << 22) | ((sdram->emc_pmacro_cmd_ctrl1 << 27 >> 31 << 21) | ((sdram->emc_pmacro_cmd_ctrl1 << 20) & 0x1FFFFF | ((sdram->emc_cfg_dig_dll_1 << 12 >> 28 << 16) | ((sdram->emc_cfg_dig_dll_1 << 16 >> 28 << 12) | ((sdram->emc_cfg_dig_dll_1 << 20 >> 26 << 6) | (2 * (sdram->emc_cfg_dig_dll_1 << 26 >> 27) | (sdram->emc_cfg_dig_dll_1 & 1 | 2 * (pmc->scratch184 >> 1)) & 0xFFFFFFC1) & 0xFFFFF03F) & 0xFFFF0FFF) & 0xFFF0FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch185 = (4 * sdram->emc_pmacro_cmd_ctrl2 >> 31 << 31) | (2 * ((8 * sdram->emc_pmacro_cmd_ctrl2 >> 31 << 30) | ((sdram->emc_pmacro_cmd_ctrl2 << 7 >> 31 << 29) | ((sdram->emc_pmacro_cmd_ctrl2 << 10 >> 31 << 28) | ((sdram->emc_pmacro_cmd_ctrl2 << 11 >> 31 << 27) | ((sdram->emc_pmacro_cmd_ctrl2 << 15 >> 31 << 26) | ((sdram->emc_pmacro_cmd_ctrl2 << 18 >> 31 << 25) | ((sdram->emc_pmacro_cmd_ctrl2 << 19 >> 31 << 24) | ((sdram->emc_pmacro_cmd_ctrl2 << 23 >> 31 << 23) | ((sdram->emc_pmacro_cmd_ctrl2 << 26 >> 31 << 22) | ((sdram->emc_pmacro_cmd_ctrl2 << 27 >> 31 << 21) | ((sdram->emc_pmacro_cmd_ctrl2 << 20) & 0x1FFFFF | ((sdram->emc_quse_brlshft0 << 12 >> 27 << 15) | ((sdram->emc_quse_brlshft0 << 17 >> 27 << 10) | (32 * (sdram->emc_quse_brlshft0 << 22 >> 27) | (sdram->emc_quse_brlshft0 & 0x1F | 32 * (pmc->scratch185 >> 5)) & 0xFFFFFC1F) & 0xFFFF83FF) & 0xFFF07FFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch186 = (sdram->emc_pmacro_dsr_vttgen_ctrl0 >> 8 << 24) | ((sdram->emc_pmacro_dsr_vttgen_ctrl0 << 20) | ((sdram->emc_quse_brlshft1 << 12 >> 27 << 15) | ((sdram->emc_quse_brlshft1 << 17 >> 27 << 10) | (32 * (sdram->emc_quse_brlshft1 << 22 >> 27) | (sdram->emc_quse_brlshft1 & 0x1F | 32 * (pmc->scratch186 >> 5)) & 0xFFFFFC1F) & 0xFFFF83FF) & 0xFFF07FFF) & 0xFF0FFFFF) & 0xFFFFFF; - pmc->scratch187 = (sdram->emc_pmacro_perbit_rfu1_ctrl0 << 10 >> 30 << 30) | (4 * ((sdram->emc_pmacro_perbit_rfu1_ctrl0 << 12 >> 30 << 28) | ((sdram->emc_pmacro_perbit_rfu1_ctrl0 << 14 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu1_ctrl0 << 26 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu1_ctrl0 << 28 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu1_ctrl0 << 20) & 0x3FFFFF | ((sdram->emc_quse_brlshft2 << 12 >> 27 << 15) | ((sdram->emc_quse_brlshft2 << 17 >> 27 << 10) | (32 * (sdram->emc_quse_brlshft2 << 22 >> 27) | (sdram->emc_quse_brlshft2 & 0x1F | 32 * (pmc->scratch187 >> 5)) & 0xFFFFFC1F) & 0xFFFF83FF) & 0xFFF07FFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch188 = (sdram->emc_pmacro_perbit_rfu1_ctrl1 << 10 >> 30 << 30) | (4 * ((sdram->emc_pmacro_perbit_rfu1_ctrl1 << 12 >> 30 << 28) | ((sdram->emc_pmacro_perbit_rfu1_ctrl1 << 14 >> 30 << 26) | ((sdram->emc_pmacro_perbit_rfu1_ctrl1 << 26 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu1_ctrl1 << 28 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu1_ctrl1 << 20) & 0x3FFFFF | ((sdram->emc_quse_brlshft3 << 12 >> 27 << 15) | ((sdram->emc_quse_brlshft3 << 17 >> 27 << 10) | (32 * (sdram->emc_quse_brlshft3 << 22 >> 27) | (sdram->emc_quse_brlshft3 & 0x1F | 32 * (pmc->scratch188 >> 5)) & 0xFFFFFC1F) & 0xFFFF83FF) & 0xFFF07FFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF) & 0xCFFFFFFF) >> 2); - pmc->scratch189 = (sdram->emc_trefbw << 18) | ((sdram->emc_dbg >> 31 << 17) | ((2 * sdram->emc_dbg >> 31 << 16) | ((4 * sdram->emc_dbg >> 31 << 15) | ((8 * sdram->emc_dbg >> 31 << 14) | ((16 * sdram->emc_dbg >> 30 << 12) | ((sdram->emc_dbg << 6 >> 31 << 11) | ((sdram->emc_dbg << 7 >> 31 << 10) | ((sdram->emc_dbg << 18 >> 31 << 9) | ((sdram->emc_dbg << 19 >> 31 << 8) | ((sdram->emc_dbg << 20 >> 31 << 7) | ((sdram->emc_dbg << 21 >> 31 << 6) | (32 * (sdram->emc_dbg << 22 >> 31) | (16 * (sdram->emc_dbg << 27 >> 31) | (8 * (sdram->emc_dbg << 28 >> 31) | (4 * (sdram->emc_dbg << 29 >> 31) | (2 * (sdram->emc_dbg << 30 >> 31) | (sdram->emc_dbg & 1 | 2 * (pmc->scratch189 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFCFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0x3FFFF; - pmc->scratch191 = (sdram->emc_qpop << 9 >> 25 << 25) | ((sdram->emc_qpop << 18) | ((sdram->emc_zcal_wait_cnt >> 31 << 17) | ((sdram->emc_zcal_wait_cnt << 10 >> 26 << 11) | (sdram->emc_zcal_wait_cnt & 0x7FF | (pmc->scratch191 >> 11 << 11)) & 0xFFFE07FF) & 0xFFFDFFFF) & 0xFE03FFFF) & 0x1FFFFFF; - pmc->scratch192 = (sdram->emc_pmacro_tx_sel_clk_src4 << 6 >> 31 << 31) | (2 * ((sdram->emc_pmacro_auto_cal_common << 15 >> 31 << 30) | ((sdram->emc_pmacro_auto_cal_common << 18 >> 26 << 24) | ((sdram->emc_pmacro_auto_cal_common << 18) & 0xFFFFFF | ((sdram->emc_zcal_mrw_cmd >> 30 << 16) | ((sdram->emc_zcal_mrw_cmd << 8 >> 24 << 8) | (sdram->emc_zcal_mrw_cmd & 0xFF | (pmc->scratch192 >> 8 << 8)) & 0xFFFF00FF) & 0xFFFCFFFF) & 0xFF03FFFF) & 0xC0FFFFFF) & 0xBFFFFFFF) >> 1); - tmp = (sdram->emc_dll_cfg1 << 7 >> 31 << 17) | ((sdram->emc_dll_cfg1 << 10 >> 31 << 16) | ((sdram->emc_dll_cfg1 << 11 >> 31 << 15) | ((sdram->emc_dll_cfg1 << 14 >> 30 << 13) | ((sdram->emc_dll_cfg1 << 18 >> 31 << 12) | ((sdram->emc_dll_cfg1 << 19 >> 31 << 11) | ((pmc->scratch193 >> 11 << 11) | sdram->emc_dll_cfg1 & 0x7FF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFF9FFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF; - pmc->scratch193 = (sdram->emc_pmacro_tx_sel_clk_src5 << 31) | (2 * ((32 * sdram->emc_pmacro_tx_sel_clk_src4 >> 31 << 30) | ((sdram->emc_pmacro_perbit_rfu1_ctrl2 << 10 >> 30 << 28) | (((sdram->emc_pmacro_perbit_rfu1_ctrl2 << 14 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu1_ctrl2 << 26 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu1_ctrl2 << 28 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu1_ctrl2 << 18) & 0xFFFFF | tmp & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF | (sdram->emc_pmacro_perbit_rfu1_ctrl2 << 12 >> 30 << 26)) & 0xCFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch194 = (sdram->emc_pmacro_tx_sel_clk_src5 << 29 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src5 << 30 >> 31 << 30) | ((sdram->emc_pmacro_perbit_rfu1_ctrl3 << 10 >> 30 << 28) | (((sdram->emc_pmacro_perbit_rfu1_ctrl3 << 14 >> 30 << 24) | (((sdram->emc_pmacro_perbit_rfu1_ctrl3 << 28 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu1_ctrl3 << 18) & 0xFFFFF | ((sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 14 >> 30 << 16) | ((sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 16 >> 30 << 14) | ((sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 18 >> 30 << 12) | ((sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 20 >> 30 << 10) | ((sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 22 >> 30 << 8) | ((sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 26 >> 30) | (4 * (sdram->emc_pmacro_cmd_brick_ctrl_fdpd << 28 >> 30) | (sdram->emc_pmacro_cmd_brick_ctrl_fdpd & 3 | 4 * (pmc->scratch194 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF | (sdram->emc_pmacro_perbit_rfu1_ctrl3 << 26 >> 30 << 22)) & 0xFCFFFFFF) & 0xF3FFFFFF | (sdram->emc_pmacro_perbit_rfu1_ctrl3 << 12 >> 30 << 26)) & 0xCFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch195 = (sdram->emc_pmacro_tx_sel_clk_src5 << 27 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src5 << 28 >> 31 << 30) | ((sdram->emc_pmacro_perbit_rfu1_ctrl4 << 10 >> 30 << 28) | (((sdram->emc_pmacro_perbit_rfu1_ctrl4 << 14 >> 30 << 24) | ((sdram->emc_pmacro_perbit_rfu1_ctrl4 << 26 >> 30 << 22) | ((sdram->emc_pmacro_perbit_rfu1_ctrl4 << 28 >> 30 << 20) | ((sdram->emc_pmacro_perbit_rfu1_ctrl4 << 18) & 0xFFFFF | ((sdram->emc_pmacro_data_brick_ctrl_fdpd << 14 >> 30 << 16) | ((sdram->emc_pmacro_data_brick_ctrl_fdpd << 16 >> 30 << 14) | ((sdram->emc_pmacro_data_brick_ctrl_fdpd << 18 >> 30 << 12) | ((sdram->emc_pmacro_data_brick_ctrl_fdpd << 20 >> 30 << 10) | ((sdram->emc_pmacro_data_brick_ctrl_fdpd << 22 >> 30 << 8) | ((sdram->emc_pmacro_data_brick_ctrl_fdpd << 24 >> 30 << 6) | (16 * (sdram->emc_pmacro_data_brick_ctrl_fdpd << 26 >> 30) | (4 * (sdram->emc_pmacro_data_brick_ctrl_fdpd << 28 >> 30) | (sdram->emc_pmacro_data_brick_ctrl_fdpd & 3 | 4 * (pmc->scratch195 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFCF) & 0xFFFFFF3F) & 0xFFFFFCFF) & 0xFFFFF3FF) & 0xFFFFCFFF) & 0xFFFF3FFF) & 0xFFFCFFFF) & 0xFFF3FFFF) & 0xFFCFFFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xF3FFFFFF | (sdram->emc_pmacro_perbit_rfu1_ctrl4 << 12 >> 30 << 26)) & 0xCFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch196 = (sdram->emc_emem_arb_refpb_bank_ctrl >> 31 << 31) | (2 * ((sdram->emc_emem_arb_refpb_bank_ctrl << 17 >> 25 << 24) | ((sdram->emc_emem_arb_refpb_bank_ctrl << 17) & 0xFFFFFF | ((sdram->emc_dyn_self_ref_control >> 31 << 16) | (sdram->emc_dyn_self_ref_control & 0xFFFF | (pmc->scratch196 >> 16 << 16)) & 0xFFFEFFFF) & 0xFF01FFFF) & 0x80FFFFFF) >> 1); - pmc->scratch197 = (sdram->emc_pmacro_tx_sel_clk_src5 << 24 >> 31 << 31) | (2 * ((sdram->emc_pmacro_tx_sel_clk_src5 << 25 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 26 >> 31 << 29) | ((sdram->emc_pmacro_perbit_rfu1_ctrl5 << 10 >> 30 << 27) | (((sdram->emc_pmacro_perbit_rfu1_ctrl5 << 14 >> 30 << 23) | ((sdram->emc_pmacro_perbit_rfu1_ctrl5 << 26 >> 30 << 21) | ((sdram->emc_pmacro_perbit_rfu1_ctrl5 << 28 >> 30 << 19) | ((sdram->emc_pmacro_perbit_rfu1_ctrl5 << 17) & 0x7FFFF | ((16 * sdram->emc_pmacro_cmd_pad_rx_ctrl >> 28 << 13) | ((sdram->emc_pmacro_cmd_pad_rx_ctrl << 8 >> 31 << 12) | ((sdram->emc_pmacro_cmd_pad_rx_ctrl << 9 >> 31 << 11) | ((sdram->emc_pmacro_cmd_pad_rx_ctrl << 10 >> 31 << 10) | ((sdram->emc_pmacro_cmd_pad_rx_ctrl << 12 >> 28 << 6) | (32 * (sdram->emc_pmacro_cmd_pad_rx_ctrl << 16 >> 31) | (16 * (sdram->emc_pmacro_cmd_pad_rx_ctrl << 19 >> 31) | (4 * (sdram->emc_pmacro_cmd_pad_rx_ctrl << 26 >> 30) | (sdram->emc_pmacro_cmd_pad_rx_ctrl & 3 | 4 * (pmc->scratch197 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFC3F) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFE1FFF) & 0xFFF9FFFF) & 0xFFE7FFFF) & 0xFF9FFFFF) & 0xFE7FFFFF) & 0xF9FFFFFF | (sdram->emc_pmacro_perbit_rfu1_ctrl5 << 12 >> 30 << 25)) & 0xE7FFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch198 = (sdram->emc_pmacro_cmd_pad_tx_ctrl << 31) | (2 * ((32 * sdram->emc_pmacro_tx_sel_clk_src5 >> 31 << 30) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 6 >> 31 << 29) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 7 >> 31 << 28) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 8 >> 31 << 27) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 9 >> 31 << 26) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 10 >> 31 << 25) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 11 >> 31 << 24) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 12 >> 31 << 23) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 13 >> 31 << 22) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 14 >> 31 << 21) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 15 >> 31 << 20) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 21 >> 31 << 19) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 22 >> 31 << 18) | ((sdram->emc_pmacro_tx_sel_clk_src5 << 23 >> 31 << 17) | ((16 * sdram->emc_pmacro_data_pad_rx_ctrl >> 28 << 13) | ((sdram->emc_pmacro_data_pad_rx_ctrl << 8 >> 31 << 12) | ((sdram->emc_pmacro_data_pad_rx_ctrl << 9 >> 31 << 11) | ((sdram->emc_pmacro_data_pad_rx_ctrl << 10 >> 31 << 10) | ((sdram->emc_pmacro_data_pad_rx_ctrl << 12 >> 28 << 6) | (32 * (sdram->emc_pmacro_data_pad_rx_ctrl << 16 >> 31) | (16 * (sdram->emc_pmacro_data_pad_rx_ctrl << 19 >> 31) | (4 * (sdram->emc_pmacro_data_pad_rx_ctrl << 26 >> 30) | (sdram->emc_pmacro_data_pad_rx_ctrl & 3 | 4 * (pmc->scratch198 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFC3F) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFE1FFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch199 = (8 * sdram->emc_cmd_q >> 27 << 27) | ((sdram->emc_cmd_q << 17 >> 29 << 24) | ((sdram->emc_cmd_q << 21 >> 29 << 21) | ((sdram->emc_cmd_q << 16) & 0x1FFFFF | (((u16)(sdram->emc_refresh) << 16 >> 22 << 6) | (sdram->emc_refresh & 0x3F | (pmc->scratch199 >> 6 << 6)) & 0xFFFF003F) & 0xFFE0FFFF) & 0xFF1FFFFF) & 0xF8FFFFFF) & 0x7FFFFFF; - pmc->scratch210 = (sdram->emc_auto_cal_vref_sel1 << 16 >> 31 << 31) | (2 * ((sdram->emc_auto_cal_vref_sel1 << 17 >> 25 << 24) | ((sdram->emc_auto_cal_vref_sel1 << 24 >> 31 << 23) | ((sdram->emc_auto_cal_vref_sel1 << 16) & 0x7FFFFF | (sdram->emc_acpd_control & 0xFFFF | (pmc->scratch210 >> 16 << 16)) & 0xFF80FFFF) & 0xFF7FFFFF) & 0x80FFFFFF) >> 1); - tmp = 8 * (sdram->emc_pmacro_auto_cal_cfg0 << 28 >> 31) | (4 * (sdram->emc_pmacro_auto_cal_cfg0 << 29 >> 31) | (2 * (sdram->emc_pmacro_auto_cal_cfg0 << 30 >> 31) | (sdram->emc_pmacro_auto_cal_cfg0 & 1 | 2 * (pmc->scratch211 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7; - tmp = (sdram->emc_pmacro_auto_cal_cfg1 << 7 >> 31 << 28) | ((sdram->emc_pmacro_auto_cal_cfg1 << 12 >> 31 << 27) | ((sdram->emc_pmacro_auto_cal_cfg1 << 13 >> 31 << 26) | ((sdram->emc_pmacro_auto_cal_cfg1 << 14 >> 31 << 25) | ((sdram->emc_pmacro_auto_cal_cfg1 << 15 >> 31 << 24) | ((sdram->emc_pmacro_auto_cal_cfg1 << 20 >> 31 << 23) | ((sdram->emc_pmacro_auto_cal_cfg1 << 21 >> 31 << 22) | ((sdram->emc_pmacro_auto_cal_cfg1 << 22 >> 31 << 21) | ((sdram->emc_pmacro_auto_cal_cfg1 << 23 >> 31 << 20) | ((sdram->emc_pmacro_auto_cal_cfg1 << 28 >> 31 << 19) | ((sdram->emc_pmacro_auto_cal_cfg1 << 29 >> 31 << 18) | ((sdram->emc_pmacro_auto_cal_cfg1 << 30 >> 31 << 17) | ((sdram->emc_pmacro_auto_cal_cfg1 << 16) & 0x1FFFF | ((16 * sdram->emc_pmacro_auto_cal_cfg0 >> 31 << 15) | ((32 * sdram->emc_pmacro_auto_cal_cfg0 >> 31 << 14) | ((sdram->emc_pmacro_auto_cal_cfg0 << 6 >> 31 << 13) | ((sdram->emc_pmacro_auto_cal_cfg0 << 7 >> 31 << 12) | ((sdram->emc_pmacro_auto_cal_cfg0 << 12 >> 31 << 11) | ((sdram->emc_pmacro_auto_cal_cfg0 << 13 >> 31 << 10) | ((sdram->emc_pmacro_auto_cal_cfg0 << 14 >> 31 << 9) | ((sdram->emc_pmacro_auto_cal_cfg0 << 15 >> 31 << 8) | ((sdram->emc_pmacro_auto_cal_cfg0 << 20 >> 31 << 7) | ((sdram->emc_pmacro_auto_cal_cfg0 << 21 >> 31 << 6) | (32 * (sdram->emc_pmacro_auto_cal_cfg0 << 22 >> 31) | (16 * (sdram->emc_pmacro_auto_cal_cfg0 << 23 >> 31) | tmp & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF; - pmc->scratch211 = (16 * sdram->emc_pmacro_auto_cal_cfg1 >> 31 << 31) | (2 * ((32 * sdram->emc_pmacro_auto_cal_cfg1 >> 31 << 30) | ((sdram->emc_pmacro_auto_cal_cfg1 << 6 >> 31 << 29) | tmp & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->scratch212 = (sdram->emc_xm2_comp_pad_ctrl3 << 8 >> 28 << 28) | ((sdram->emc_xm2_comp_pad_ctrl3 << 14 >> 31 << 27) | ((sdram->emc_xm2_comp_pad_ctrl3 << 15 >> 31 << 26) | ((sdram->emc_xm2_comp_pad_ctrl3 << 16 >> 30 << 24) | ((sdram->emc_xm2_comp_pad_ctrl3 << 18 >> 30 << 22) | ((sdram->emc_xm2_comp_pad_ctrl3 << 26 >> 28 << 18) | ((sdram->emc_xm2_comp_pad_ctrl3 << 16) & 0x3FFFF | ((16 * sdram->emc_pmacro_auto_cal_cfg2 >> 31 << 15) | ((32 * sdram->emc_pmacro_auto_cal_cfg2 >> 31 << 14) | ((sdram->emc_pmacro_auto_cal_cfg2 << 6 >> 31 << 13) | ((sdram->emc_pmacro_auto_cal_cfg2 << 7 >> 31 << 12) | ((sdram->emc_pmacro_auto_cal_cfg2 << 12 >> 31 << 11) | ((sdram->emc_pmacro_auto_cal_cfg2 << 13 >> 31 << 10) | ((sdram->emc_pmacro_auto_cal_cfg2 << 14 >> 31 << 9) | ((sdram->emc_pmacro_auto_cal_cfg2 << 15 >> 31 << 8) | ((sdram->emc_pmacro_auto_cal_cfg2 << 20 >> 31 << 7) | ((sdram->emc_pmacro_auto_cal_cfg2 << 21 >> 31 << 6) | (32 * (sdram->emc_pmacro_auto_cal_cfg2 << 22 >> 31) | (16 * (sdram->emc_pmacro_auto_cal_cfg2 << 23 >> 31) | (8 * (sdram->emc_pmacro_auto_cal_cfg2 << 28 >> 31) | (4 * (sdram->emc_pmacro_auto_cal_cfg2 << 29 >> 31) | (2 * (sdram->emc_pmacro_auto_cal_cfg2 << 30 >> 31) | (sdram->emc_pmacro_auto_cal_cfg2 & 1 | 2 * (pmc->scratch212 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFCFFFF) & 0xFFC3FFFF) & 0xFF3FFFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xFFFFFFF; - pmc->scratch213 = ((u16)(sdram->emc_prerefresh_req_cnt) << 16) | (u16)(sdram->emc_cfg_dig_dll_period); - pmc->scratch214 = (sdram->emc_pmacro_data_pi_ctrl << 10 >> 26 << 26) | ((sdram->emc_pmacro_data_pi_ctrl << 19 >> 31 << 25) | ((sdram->emc_pmacro_data_pi_ctrl << 20 >> 28 << 21) | ((sdram->emc_pmacro_data_pi_ctrl << 27 >> 31 << 20) | ((sdram->emc_pmacro_data_pi_ctrl << 16) & 0xFFFFF | ((sdram->emc_pmacro_ddll_bypass >> 31 << 15) | ((2 * sdram->emc_pmacro_ddll_bypass >> 31 << 14) | ((4 * sdram->emc_pmacro_ddll_bypass >> 31 << 13) | ((16 * sdram->emc_pmacro_ddll_bypass >> 31 << 12) | ((32 * sdram->emc_pmacro_ddll_bypass >> 31 << 11) | ((sdram->emc_pmacro_ddll_bypass << 6 >> 31 << 10) | ((sdram->emc_pmacro_ddll_bypass << 7 >> 31 << 9) | ((sdram->emc_pmacro_ddll_bypass << 15 >> 31 << 8) | ((sdram->emc_pmacro_ddll_bypass << 16 >> 31 << 7) | ((sdram->emc_pmacro_ddll_bypass << 17 >> 31 << 6) | (32 * (sdram->emc_pmacro_ddll_bypass << 18 >> 31) | (16 * (sdram->emc_pmacro_ddll_bypass << 20 >> 31) | (8 * (sdram->emc_pmacro_ddll_bypass << 21 >> 31) | (4 * (sdram->emc_pmacro_ddll_bypass << 22 >> 31) | (2 * (sdram->emc_pmacro_ddll_bypass << 23 >> 31) | (sdram->emc_pmacro_ddll_bypass & 1 | 2 * (pmc->scratch214 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFF0FFFF) & 0xFFEFFFFF) & 0xFE1FFFFF) & 0xFDFFFFFF) & 0x3FFFFFF; - pmc->scratch215 = (sdram->emc_pmacro_cmd_pi_ctrl << 10 >> 26 << 10) | ((sdram->emc_pmacro_cmd_pi_ctrl << 19 >> 31 << 9) | (32 * (sdram->emc_pmacro_cmd_pi_ctrl << 20 >> 28) | (16 * (sdram->emc_pmacro_cmd_pi_ctrl << 27 >> 31) | (sdram->emc_pmacro_cmd_pi_ctrl & 0xF | 16 * (pmc->scratch215 >> 4)) & 0xFFFFFFEF) & 0xFFFFFE1F) & 0xFFFFFDFF) & 0xFFFF03FF; - tmp = (sdram->emc_pmacro_data_pad_tx_ctrl << 7 >> 31 << 24) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 8 >> 31 << 23) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 9 >> 31 << 22) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 10 >> 31 << 21) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 15 >> 31 << 20) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 16 >> 31 << 19) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 21 >> 31 << 18) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 25 >> 31 << 17) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 26 >> 31 << 16) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 15) & 0xFFFF | ((2 * sdram->emc_pmacro_cmd_pad_tx_ctrl >> 31 << 14) | ((4 * sdram->emc_pmacro_cmd_pad_tx_ctrl >> 31 << 13) | ((8 * sdram->emc_pmacro_cmd_pad_tx_ctrl >> 31 << 12) | ((16 * sdram->emc_pmacro_cmd_pad_tx_ctrl >> 31 << 11) | ((32 * sdram->emc_pmacro_cmd_pad_tx_ctrl >> 31 << 10) | ((sdram->emc_pmacro_cmd_pad_tx_ctrl << 6 >> 31 << 9) | ((sdram->emc_pmacro_cmd_pad_tx_ctrl << 7 >> 31 << 8) | ((sdram->emc_pmacro_cmd_pad_tx_ctrl << 8 >> 31 << 7) | ((sdram->emc_pmacro_cmd_pad_tx_ctrl << 9 >> 31 << 6) | (32 * (sdram->emc_pmacro_cmd_pad_tx_ctrl << 10 >> 31) | (16 * (sdram->emc_pmacro_cmd_pad_tx_ctrl << 15 >> 31) | (8 * (sdram->emc_pmacro_cmd_pad_tx_ctrl << 16 >> 31) | (4 * (sdram->emc_pmacro_cmd_pad_tx_ctrl << 21 >> 31) | (2 * (sdram->emc_pmacro_cmd_pad_tx_ctrl << 25 >> 31) | ((sdram->emc_pmacro_cmd_pad_tx_ctrl << 26 >> 31) | 2 * (pmc->scratch216 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F) & 0xFFFFFEFF) & 0xFFFFFDFF) & 0xFFFFFBFF) & 0xFFFFF7FF) & 0xFFFFEFFF) & 0xFFFFDFFF) & 0xFFFFBFFF) & 0xFFFF7FFF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFFBFFFF) & 0xFFF7FFFF) & 0xFFEFFFFF) & 0xFFDFFFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF; - pmc->scratch9 = ((4 * pmc->scratch9) >> 2) | (sdram->emc_pin_gpio << 30); - pmc->scratch10 = ((4 * pmc->scratch10) >> 2) | (sdram->emc_pin_gpio_enable << 30); - pmc->scratch11 = ((4 * pmc->scratch11) >> 2) | (sdram->emc_dev_select << 30); - pmc->scratch12 = ((4 * pmc->scratch12) >> 2) | (sdram->emc_zcal_warm_cold_boot_enables << 30); - pmc->scratch13 = ((4 * pmc->scratch13) >> 2) | ((u16)(sdram->emc_cfg_dig_dll_period_warm_boot) << 30); + s32(emc_pmacro_perbit_rfu_ctrl0, scratch30); + s32(emc_pmacro_perbit_rfu_ctrl1, scratch31); + s32(emc_pmacro_perbit_rfu_ctrl2, scratch32); + s32(emc_pmacro_perbit_rfu_ctrl3, scratch33); + s32(emc_pmacro_perbit_rfu_ctrl4, scratch40); + s32(emc_pmacro_perbit_rfu_ctrl5, scratch42); + s32(mc_emem_arb_da_turns, scratch44); + s(emc_fbio_spare, 31:24, scratch64, 7:0); + s(emc_fbio_spare, 23:16, scratch64, 15:8); + s(emc_fbio_spare, 15:8, scratch64, 23:16); + s(emc_fbio_spare, 7:2, scratch64, 29:24); + s(emc_fbio_spare, 0:0, scratch64, 30:30); + s(mc_emem_arb_misc2, 0:0, scratch64, 31:31); + s(mc_emem_arb_misc0, 14:0, scratch65, 14:0); + s(mc_emem_arb_misc0, 30:16, scratch65, 29:15); + s(mc_da_cfg0, 0:0, scratch65, 30:30); + s(emc_fdpd_ctrl_cmd, 16:0, scratch66, 16:0); + s(emc_fdpd_ctrl_cmd, 31:20, scratch66, 28:17); + s(emc_auto_cal_config2, 27:0, scratch67, 27:0); + s(emc_burst_refresh_num, 3:0, scratch67, 31:28); + s(emc_cfg_dig_dll, 10:0, scratch68, 10:0); + s(emc_cfg_dig_dll, 25:12, scratch68, 24:11); + s(emc_cfg_dig_dll, 27:27, scratch68, 25:25); + s(emc_cfg_dig_dll, 31:30, scratch68, 27:26); + s(emc_tppd, 3:0, scratch68, 31:28); + s(emc_fdpd_ctrl_dq, 16:0, scratch69, 16:0); + s(emc_fdpd_ctrl_dq, 28:20, scratch69, 25:17); + s(emc_fdpd_ctrl_dq, 31:30, scratch69, 27:26); + s(emc_r2r, 3:0, scratch69, 31:28); + s(emc_pmacro_ib_vref_dq_0, 6:0, scratch70, 6:0); + s(emc_pmacro_ib_vref_dq_0, 14:8, scratch70, 13:7); + s(emc_pmacro_ib_vref_dq_0, 22:16, scratch70, 20:14); + s(emc_pmacro_ib_vref_dq_0, 30:24, scratch70, 27:21); + s(emc_w2w, 3:0, scratch70, 31:28); + s(emc_pmacro_ib_vref_dq_1, 6:0, scratch71, 6:0); + s(emc_pmacro_ib_vref_dq_1, 14:8, scratch71, 13:7); + s(emc_pmacro_ib_vref_dq_1, 22:16, scratch71, 20:14); + s(emc_pmacro_ib_vref_dq_1, 30:24, scratch71, 27:21); + s(emc_pmacro_vttgen_ctrl0, 19:16, scratch71, 31:28); + s(emc_pmacro_ib_vref_dqs_0, 6:0, scratch72, 6:0); + s(emc_pmacro_ib_vref_dqs_0, 14:8, scratch72, 13:7); + s(emc_pmacro_ib_vref_dqs_0, 22:16, scratch72, 20:14); + s(emc_pmacro_ib_vref_dqs_0, 30:24, scratch72, 27:21); + s(emc_pmacro_ib_vref_dqs_1, 6:0, scratch73, 6:0); + s(emc_pmacro_ib_vref_dqs_1, 14:8, scratch73, 13:7); + s(emc_pmacro_ib_vref_dqs_1, 22:16, scratch73, 20:14); + s(emc_pmacro_ib_vref_dqs_1, 30:24, scratch73, 27:21); + s(emc_pmacro_ddll_short_cmd_0, 6:0, scratch74, 6:0); + s(emc_pmacro_ddll_short_cmd_0, 14:8, scratch74, 13:7); + s(emc_pmacro_ddll_short_cmd_0, 22:16, scratch74, 20:14); + s(emc_pmacro_ddll_short_cmd_0, 30:24, scratch74, 27:21); + s(emc_pmacro_ddll_short_cmd_1, 6:0, scratch75, 6:0); + s(emc_pmacro_ddll_short_cmd_1, 14:8, scratch75, 13:7); + s(emc_pmacro_ddll_short_cmd_1, 22:16, scratch75, 20:14); + s(emc_pmacro_ddll_short_cmd_1, 30:24, scratch75, 27:21); + s(emc_dll_cfg0, 29:4, scratch76, 25:0); + s(emc_rp, 5:0, scratch76, 31:26); + s(emc_pmacro_tx_pwrd0, 10:0, scratch77, 10:0); + s(emc_pmacro_tx_pwrd0, 13:12, scratch77, 12:11); + s(emc_pmacro_tx_pwrd0, 26:16, scratch77, 23:13); + s(emc_pmacro_tx_pwrd0, 29:28, scratch77, 25:24); + s(emc_r2w, 5:0, scratch77, 31:26); + s(emc_pmacro_tx_pwrd1, 10:0, scratch78, 10:0); + s(emc_pmacro_tx_pwrd1, 13:12, scratch78, 12:11); + s(emc_pmacro_tx_pwrd1, 26:16, scratch78, 23:13); + s(emc_pmacro_tx_pwrd1, 29:28, scratch78, 25:24); + s(emc_w2r, 5:0, scratch78, 31:26); + s(emc_pmacro_tx_pwrd2, 10:0, scratch79, 10:0); + s(emc_pmacro_tx_pwrd2, 13:12, scratch79, 12:11); + s(emc_pmacro_tx_pwrd2, 26:16, scratch79, 23:13); + s(emc_pmacro_tx_pwrd2, 29:28, scratch79, 25:24); + s(emc_r2p, 5:0, scratch79, 31:26); + s(emc_pmacro_tx_pwrd3, 10:0, scratch80, 10:0); + s(emc_pmacro_tx_pwrd3, 13:12, scratch80, 12:11); + s(emc_pmacro_tx_pwrd3, 26:16, scratch80, 23:13); + s(emc_pmacro_tx_pwrd3, 29:28, scratch80, 25:24); + s(emc_ccdmw, 5:0, scratch80, 31:26); + s(emc_pmacro_tx_pwrd4, 10:0, scratch81, 10:0); + s(emc_pmacro_tx_pwrd4, 13:12, scratch81, 12:11); + s(emc_pmacro_tx_pwrd4, 26:16, scratch81, 23:13); + s(emc_pmacro_tx_pwrd4, 29:28, scratch81, 25:24); + s(emc_rd_rcd, 5:0, scratch81, 31:26); + s(emc_pmacro_tx_pwrd5, 10:0, scratch82, 10:0); + s(emc_pmacro_tx_pwrd5, 13:12, scratch82, 12:11); + s(emc_pmacro_tx_pwrd5, 26:16, scratch82, 23:13); + s(emc_pmacro_tx_pwrd5, 29:28, scratch82, 25:24); + s(emc_wr_rcd, 5:0, scratch82, 31:26); + s(emc_auto_cal_channel, 5:0, scratch83, 5:0); + s(emc_auto_cal_channel, 11:8, scratch83, 9:6); + s(emc_auto_cal_channel, 27:16, scratch83, 21:10); + s(emc_auto_cal_channel, 31:29, scratch83, 24:22); + s(emc_config_sample_delay, 6:0, scratch83, 31:25); + s(emc_pmacro_rx_term, 5:0, scratch84, 5:0); + s(emc_pmacro_rx_term, 13:8, scratch84, 11:6); + s(emc_pmacro_rx_term, 21:16, scratch84, 17:12); + s(emc_pmacro_rx_term, 29:24, scratch84, 23:18); + s(emc_sel_dpd_ctrl, 5:2, scratch84, 27:24); + s(emc_sel_dpd_ctrl, 8:8, scratch84, 28:28); + s(emc_sel_dpd_ctrl, 18:16, scratch84, 31:29); + s(emc_pmacro_dq_tx_drive, 5:0, scratch85, 5:0); + s(emc_pmacro_dq_tx_drive, 13:8, scratch85, 11:6); + s(emc_pmacro_dq_tx_drive, 21:16, scratch85, 17:12); + s(emc_pmacro_dq_tx_drive, 29:24, scratch85, 23:18); + s(emc_obdly, 5:0, scratch85, 29:24); + s(emc_obdly, 29:28, scratch85, 31:30); + s(emc_pmacro_ca_tx_drive, 5:0, scratch86, 5:0); + s(emc_pmacro_ca_tx_drive, 13:8, scratch86, 11:6); + s(emc_pmacro_ca_tx_drive, 21:16, scratch86, 17:12); + s(emc_pmacro_ca_tx_drive, 29:24, scratch86, 23:18); + s(emc_pmacro_vttgen_ctrl1, 15:10, scratch86, 29:24); + s(emc_pmacro_vttgen_ctrl1, 21:20, scratch86, 31:30); + s(emc_pmacro_zcrtl, 27:4, scratch87, 23:0); + s(emc_pmacro_vttgen_ctrl2, 23:16, scratch87, 31:24); + s(emc_zcal_interval, 23:10, scratch88, 13:0); + s(emc_zcal_interval, 9:0, scratch88, 23:14); + s(mc_emem_arb_timing_rc, 7:0, scratch88, 31:24); + s(emc_data_brlshft0, 23:0, scratch89, 23:0); + s(mc_emem_arb_rsv, 7:0, scratch89, 31:24); + s(emc_data_brlshft1, 23:0, scratch90, 23:0); + s(emc_dqs_brlshft0, 23:0, scratch91, 23:0); + s(emc_dqs_brlshft1, 23:0, scratch92, 23:0); + s(emc_swizzle_rank0_byte0, 2:0, scratch93, 2:0); + s(emc_swizzle_rank0_byte0, 6:4, scratch93, 5:3); + s(emc_swizzle_rank0_byte0, 10:8, scratch93, 8:6); + s(emc_swizzle_rank0_byte0, 14:12, scratch93, 11:9); + s(emc_swizzle_rank0_byte0, 18:16, scratch93, 14:12); + s(emc_swizzle_rank0_byte0, 22:20, scratch93, 17:15); + s(emc_swizzle_rank0_byte0, 26:24, scratch93, 20:18); + s(emc_swizzle_rank0_byte0, 30:28, scratch93, 23:21); + s(emc_swizzle_rank0_byte1, 2:0, scratch94, 2:0); + s(emc_swizzle_rank0_byte1, 6:4, scratch94, 5:3); + s(emc_swizzle_rank0_byte1, 10:8, scratch94, 8:6); + s(emc_swizzle_rank0_byte1, 14:12, scratch94, 11:9); + s(emc_swizzle_rank0_byte1, 18:16, scratch94, 14:12); + s(emc_swizzle_rank0_byte1, 22:20, scratch94, 17:15); + s(emc_swizzle_rank0_byte1, 26:24, scratch94, 20:18); + s(emc_swizzle_rank0_byte1, 30:28, scratch94, 23:21); + s(emc_ras, 6:0, scratch94, 30:24); + s(emc_cfg, 4:4, scratch94, 31:31); + s(emc_swizzle_rank0_byte2, 2:0, scratch95, 2:0); + s(emc_swizzle_rank0_byte2, 6:4, scratch95, 5:3); + s(emc_swizzle_rank0_byte2, 10:8, scratch95, 8:6); + s(emc_swizzle_rank0_byte2, 14:12, scratch95, 11:9); + s(emc_swizzle_rank0_byte2, 18:16, scratch95, 14:12); + s(emc_swizzle_rank0_byte2, 22:20, scratch95, 17:15); + s(emc_swizzle_rank0_byte2, 26:24, scratch95, 20:18); + s(emc_swizzle_rank0_byte2, 30:28, scratch95, 23:21); + s(emc_w2p, 6:0, scratch95, 30:24); + s(emc_cfg, 5:5, scratch95, 31:31); + s(emc_swizzle_rank0_byte3, 2:0, scratch96, 2:0); + s(emc_swizzle_rank0_byte3, 6:4, scratch96, 5:3); + s(emc_swizzle_rank0_byte3, 10:8, scratch96, 8:6); + s(emc_swizzle_rank0_byte3, 14:12, scratch96, 11:9); + s(emc_swizzle_rank0_byte3, 18:16, scratch96, 14:12); + s(emc_swizzle_rank0_byte3, 22:20, scratch96, 17:15); + s(emc_swizzle_rank0_byte3, 26:24, scratch96, 20:18); + s(emc_swizzle_rank0_byte3, 30:28, scratch96, 23:21); + s(emc_qsafe, 6:0, scratch96, 30:24); + s(emc_cfg, 6:6, scratch96, 31:31); + s(emc_swizzle_rank1_byte0, 2:0, scratch97, 2:0); + s(emc_swizzle_rank1_byte0, 6:4, scratch97, 5:3); + s(emc_swizzle_rank1_byte0, 10:8, scratch97, 8:6); + s(emc_swizzle_rank1_byte0, 14:12, scratch97, 11:9); + s(emc_swizzle_rank1_byte0, 18:16, scratch97, 14:12); + s(emc_swizzle_rank1_byte0, 22:20, scratch97, 17:15); + s(emc_swizzle_rank1_byte0, 26:24, scratch97, 20:18); + s(emc_swizzle_rank1_byte0, 30:28, scratch97, 23:21); + s(emc_rdv, 6:0, scratch97, 30:24); + s(emc_cfg, 7:7, scratch97, 31:31); + s(emc_swizzle_rank1_byte1, 2:0, scratch98, 2:0); + s(emc_swizzle_rank1_byte1, 6:4, scratch98, 5:3); + s(emc_swizzle_rank1_byte1, 10:8, scratch98, 8:6); + s(emc_swizzle_rank1_byte1, 14:12, scratch98, 11:9); + s(emc_swizzle_rank1_byte1, 18:16, scratch98, 14:12); + s(emc_swizzle_rank1_byte1, 22:20, scratch98, 17:15); + s(emc_swizzle_rank1_byte1, 26:24, scratch98, 20:18); + s(emc_swizzle_rank1_byte1, 30:28, scratch98, 23:21); + s(emc_rw2pden, 6:0, scratch98, 30:24); + s(emc_cfg, 8:8, scratch98, 31:31); + s(emc_swizzle_rank1_byte2, 2:0, scratch99, 2:0); + s(emc_swizzle_rank1_byte2, 6:4, scratch99, 5:3); + s(emc_swizzle_rank1_byte2, 10:8, scratch99, 8:6); + s(emc_swizzle_rank1_byte2, 14:12, scratch99, 11:9); + s(emc_swizzle_rank1_byte2, 18:16, scratch99, 14:12); + s(emc_swizzle_rank1_byte2, 22:20, scratch99, 17:15); + s(emc_swizzle_rank1_byte2, 26:24, scratch99, 20:18); + s(emc_swizzle_rank1_byte2, 30:28, scratch99, 23:21); + s(emc_tfaw, 6:0, scratch99, 30:24); + s(emc_cfg, 9:9, scratch99, 31:31); + s(emc_swizzle_rank1_byte3, 2:0, scratch100, 2:0); + s(emc_swizzle_rank1_byte3, 6:4, scratch100, 5:3); + s(emc_swizzle_rank1_byte3, 10:8, scratch100, 8:6); + s(emc_swizzle_rank1_byte3, 14:12, scratch100, 11:9); + s(emc_swizzle_rank1_byte3, 18:16, scratch100, 14:12); + s(emc_swizzle_rank1_byte3, 22:20, scratch100, 17:15); + s(emc_swizzle_rank1_byte3, 26:24, scratch100, 20:18); + s(emc_swizzle_rank1_byte3, 30:28, scratch100, 23:21); + s(emc_tclkstable, 6:0, scratch100, 30:24); + s(emc_cfg, 18:18, scratch100, 31:31); + s(emc_cfg_pipe2, 11:0, scratch101, 11:0); + s(emc_cfg_pipe2, 27:16, scratch101, 23:12); + s(emc_trtm, 6:0, scratch101, 30:24); + s(emc_cfg, 21:21, scratch101, 31:31); + s(emc_cfg_pipe1, 11:0, scratch102, 11:0); + s(emc_cfg_pipe1, 27:16, scratch102, 23:12); + s(emc_twtm, 6:0, scratch102, 30:24); + s(emc_cfg, 22:22, scratch102, 31:31); + s(emc_pmacro_ddll_pwrd0, 4:1, scratch103, 3:0); + s(emc_pmacro_ddll_pwrd0, 7:6, scratch103, 5:4); + s(emc_pmacro_ddll_pwrd0, 12:9, scratch103, 9:6); + s(emc_pmacro_ddll_pwrd0, 15:14, scratch103, 11:10); + s(emc_pmacro_ddll_pwrd0, 20:17, scratch103, 15:12); + s(emc_pmacro_ddll_pwrd0, 23:22, scratch103, 17:16); + s(emc_pmacro_ddll_pwrd0, 28:25, scratch103, 21:18); + s(emc_pmacro_ddll_pwrd0, 31:30, scratch103, 23:22); + s(emc_tratm, 6:0, scratch103, 30:24); + s(emc_cfg, 23:23, scratch103, 31:31); + s(emc_pmacro_ddll_pwrd1, 4:1, scratch104, 3:0); + s(emc_pmacro_ddll_pwrd1, 7:6, scratch104, 5:4); + s(emc_pmacro_ddll_pwrd1, 12:9, scratch104, 9:6); + s(emc_pmacro_ddll_pwrd1, 15:14, scratch104, 11:10); + s(emc_pmacro_ddll_pwrd1, 20:17, scratch104, 15:12); + s(emc_pmacro_ddll_pwrd1, 23:22, scratch104, 17:16); + s(emc_pmacro_ddll_pwrd1, 28:25, scratch104, 21:18); + s(emc_pmacro_ddll_pwrd1, 31:30, scratch104, 23:22); + s(emc_twatm, 6:0, scratch104, 30:24); + s(emc_cfg, 24:24, scratch104, 31:31); + s(emc_pmacro_ddll_pwrd2, 4:1, scratch105, 3:0); + s(emc_pmacro_ddll_pwrd2, 7:6, scratch105, 5:4); + s(emc_pmacro_ddll_pwrd2, 12:9, scratch105, 9:6); + s(emc_pmacro_ddll_pwrd2, 15:14, scratch105, 11:10); + s(emc_pmacro_ddll_pwrd2, 20:17, scratch105, 15:12); + s(emc_pmacro_ddll_pwrd2, 23:22, scratch105, 17:16); + s(emc_pmacro_ddll_pwrd2, 28:25, scratch105, 21:18); + s(emc_pmacro_ddll_pwrd2, 31:30, scratch105, 23:22); + s(emc_tr2ref, 6:0, scratch105, 30:24); + s(emc_cfg, 25:25, scratch105, 31:31); + s(emc_pmacro_ddll_periodic_offset, 5:0, scratch106, 5:0); + s(emc_pmacro_ddll_periodic_offset, 16:8, scratch106, 14:6); + s(emc_pmacro_ddll_periodic_offset, 28:20, scratch106, 23:15); + s(emc_pdex2mrr, 6:0, scratch106, 30:24); + s(emc_cfg, 26:26, scratch106, 31:31); + s(mc_emem_arb_da_covers, 23:0, scratch107, 23:0); + s(emc_clken_override, 3:1, scratch107, 26:24); + s(emc_clken_override, 8:6, scratch107, 29:27); + s(emc_clken_override, 16:16, scratch107, 30:30); + s(emc_cfg, 28:28, scratch107, 31:31); + s(emc_xm2_comp_pad_ctrl, 1:0, scratch108, 1:0); + s(emc_xm2_comp_pad_ctrl, 6:4, scratch108, 4:2); + s(emc_xm2_comp_pad_ctrl, 9:9, scratch108, 5:5); + s(emc_xm2_comp_pad_ctrl, 19:11, scratch108, 14:6); + s(emc_xm2_comp_pad_ctrl, 31:24, scratch108, 22:15); + s(emc_rfc_pb, 8:0, scratch108, 31:23); + s(emc_auto_cal_config3, 6:0, scratch109, 6:0); + s(emc_auto_cal_config3, 14:8, scratch109, 13:7); + s(emc_auto_cal_config3, 23:16, scratch109, 21:14); + s(emc_cfg_update, 2:0, scratch109, 24:22); + s(emc_cfg_update, 10:8, scratch109, 27:25); + s(emc_cfg_update, 31:28, scratch109, 31:28); + s(emc_auto_cal_config4, 6:0, scratch110, 6:0); + s(emc_auto_cal_config4, 14:8, scratch110, 13:7); + s(emc_auto_cal_config4, 23:16, scratch110, 21:14); + s(emc_rfc, 9:0, scratch110, 31:22); + s(emc_auto_cal_config5, 6:0, scratch111, 6:0); + s(emc_auto_cal_config5, 14:8, scratch111, 13:7); + s(emc_auto_cal_config5, 23:16, scratch111, 21:14); + s(emc_txsr, 9:0, scratch111, 31:22); + s(emc_auto_cal_config6, 6:0, scratch112, 6:0); + s(emc_auto_cal_config6, 14:8, scratch112, 13:7); + s(emc_auto_cal_config6, 23:16, scratch112, 21:14); + s(emc_mc2emc_q, 2:0, scratch112, 24:22); + s(emc_mc2emc_q, 10:8, scratch112, 27:25); + s(emc_mc2emc_q, 27:24, scratch112, 31:28); + s(emc_auto_cal_config7, 6:0, scratch113, 6:0); + s(emc_auto_cal_config7, 14:8, scratch113, 13:7); + s(emc_auto_cal_config7, 23:16, scratch113, 21:14); + s(mc_emem_arb_ring1_throttle, 4:0, scratch113, 26:22); + s(mc_emem_arb_ring1_throttle, 20:16, scratch113, 31:27); + s(emc_auto_cal_config8, 6:0, scratch114, 6:0); + s(emc_auto_cal_config8, 14:8, scratch114, 13:7); + s(emc_auto_cal_config8, 23:16, scratch114, 21:14); + s(emc_fbio_cfg7, 21:0, scratch115, 21:0); + s(emc_ar2pden, 8:0, scratch115, 30:22); + s(emc_cfg, 29:29, scratch115, 31:31); + s(emc_pmacro_quse_ddll_rank0_0, 10:0, scratch123, 10:0); + s(emc_pmacro_quse_ddll_rank0_0, 26:16, scratch123, 21:11); + s(emc_rfc_slr, 8:0, scratch123, 30:22); + s(emc_cfg, 30:30, scratch123, 31:31); + s(emc_pmacro_quse_ddll_rank0_1, 10:0, scratch124, 10:0); + s(emc_pmacro_quse_ddll_rank0_1, 26:16, scratch124, 21:11); + s(emc_ibdly, 6:0, scratch124, 28:22); + s(emc_ibdly, 29:28, scratch124, 30:29); + s(emc_cfg, 31:31, scratch124, 31:31); + s(emc_pmacro_quse_ddll_rank0_2, 10:0, scratch125, 10:0); + s(emc_pmacro_quse_ddll_rank0_2, 26:16, scratch125, 21:11); + s(mc_emem_arb_timing_rfcpb, 8:0, scratch125, 30:22); + s(emc_fbio_cfg5, 4:4, scratch125, 31:31); + s(emc_pmacro_quse_ddll_rank0_3, 10:0, scratch126, 10:0); + s(emc_pmacro_quse_ddll_rank0_3, 26:16, scratch126, 21:11); + s(emc_auto_cal_config9, 6:0, scratch126, 28:22); + s(emc_fbio_cfg5, 15:13, scratch126, 31:29); + s(emc_pmacro_quse_ddll_rank0_4, 10:0, scratch127, 10:0); + s(emc_pmacro_quse_ddll_rank0_4, 26:16, scratch127, 21:11); + s(emc_rdv_mask, 6:0, scratch127, 28:22); + s(emc_cfg2, 5:3, scratch127, 31:29); + s(emc_pmacro_quse_ddll_rank0_5, 10:0, scratch128, 10:0); + s(emc_pmacro_quse_ddll_rank0_5, 26:16, scratch128, 21:11); + s(emc_rdv_early_mask, 6:0, scratch128, 28:22); + s(emc_pmacro_cmd_pad_tx_ctrl, 4:2, scratch128, 31:29); + s(emc_pmacro_quse_ddll_rank1_0, 10:0, scratch129, 10:0); + s(emc_pmacro_quse_ddll_rank1_0, 26:16, scratch129, 21:11); + s(emc_rdv_early, 6:0, scratch129, 28:22); + s(emc_pmacro_cmd_pad_tx_ctrl, 9:7, scratch129, 31:29); + s(emc_pmacro_quse_ddll_rank1_1, 10:0, scratch130, 10:0); + s(emc_pmacro_quse_ddll_rank1_1, 26:16, scratch130, 21:11); + s(emc_quse_width, 4:0, scratch130, 26:22); + s(emc_quse_width, 29:28, scratch130, 28:27); + s(emc_pmacro_cmd_pad_tx_ctrl, 14:12, scratch130, 31:29); + s(emc_pmacro_quse_ddll_rank1_2, 10:0, scratch131, 10:0); + s(emc_pmacro_quse_ddll_rank1_2, 26:16, scratch131, 21:11); + s(emc_pmacro_ddll_short_cmd_2, 6:0, scratch131, 28:22); + s(emc_pmacro_cmd_pad_tx_ctrl, 19:17, scratch131, 31:29); + s(emc_pmacro_quse_ddll_rank1_3, 10:0, scratch132, 10:0); + s(emc_pmacro_quse_ddll_rank1_3, 26:16, scratch132, 21:11); + s(emc_pmacro_cmd_rx_term_mode, 1:0, scratch132, 23:22); + s(emc_pmacro_cmd_rx_term_mode, 5:4, scratch132, 25:24); + s(emc_pmacro_cmd_rx_term_mode, 9:8, scratch132, 27:26); + s(emc_pmacro_cmd_rx_term_mode, 13:13, scratch132, 28:28); + s(emc_pmacro_data_pad_tx_ctrl, 4:2, scratch132, 31:29); + s(emc_pmacro_quse_ddll_rank1_4, 10:0, scratch133, 10:0); + s(emc_pmacro_quse_ddll_rank1_4, 26:16, scratch133, 21:11); + s(emc_pmacro_data_rx_term_mode, 1:0, scratch133, 23:22); + s(emc_pmacro_data_rx_term_mode, 5:4, scratch133, 25:24); + s(emc_pmacro_data_rx_term_mode, 9:8, scratch133, 27:26); + s(emc_pmacro_data_rx_term_mode, 13:13, scratch133, 28:28); + s(emc_pmacro_data_pad_tx_ctrl, 9:7, scratch133, 31:29); + s(emc_pmacro_quse_ddll_rank1_5, 10:0, scratch134, 10:0); + s(emc_pmacro_quse_ddll_rank1_5, 26:16, scratch134, 21:11); + s(mc_emem_arb_timing_rp, 6:0, scratch134, 28:22); + s(emc_pmacro_data_pad_tx_ctrl, 14:12, scratch134, 31:29); + s(emc_pmacro_ob_ddll_long_dq_rank0_0, 10:0, scratch135, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank0_0, 26:16, scratch135, 21:11); + s(mc_emem_arb_timing_ras, 6:0, scratch135, 28:22); + s(emc_pmacro_data_pad_tx_ctrl, 19:17, scratch135, 31:29); + s(emc_pmacro_ob_ddll_long_dq_rank0_1, 10:0, scratch136, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank0_1, 26:16, scratch136, 21:11); + s(mc_emem_arb_timing_faw, 6:0, scratch136, 28:22); + s(emc_cfg, 17:16, scratch136, 30:29); + s(emc_fbio_cfg5, 8:8, scratch136, 31:31); + s(emc_pmacro_ob_ddll_long_dq_rank0_2, 10:0, scratch137, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank0_2, 26:16, scratch137, 21:11); + s(mc_emem_arb_timing_rap2pre, 6:0, scratch137, 28:22); + s(emc_fbio_cfg5, 1:0, scratch137, 30:29); + s(emc_fbio_cfg5, 10:10, scratch137, 31:31); + s(emc_pmacro_ob_ddll_long_dq_rank0_3, 10:0, scratch138, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank0_3, 26:16, scratch138, 21:11); + s(mc_emem_arb_timing_wap2pre, 6:0, scratch138, 28:22); + s(emc_fbio_cfg5, 3:2, scratch138, 30:29); + s(emc_fbio_cfg5, 12:12, scratch138, 31:31); + s(emc_pmacro_ob_ddll_long_dq_rank0_4, 10:0, scratch139, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank0_4, 26:16, scratch139, 21:11); + s(mc_emem_arb_timing_r2w, 6:0, scratch139, 28:22); + s(emc_cfg2, 27:26, scratch139, 30:29); + s(emc_fbio_cfg5, 24:24, scratch139, 31:31); + s(emc_pmacro_ob_ddll_long_dq_rank0_5, 10:0, scratch140, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank0_5, 26:16, scratch140, 21:11); + s(mc_emem_arb_timing_w2r, 6:0, scratch140, 28:22); + s(emc_fbio_cfg5, 27:25, scratch140, 31:29); + s(emc_pmacro_ob_ddll_long_dq_rank1_0, 10:0, scratch141, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank1_0, 26:16, scratch141, 21:11); + s(emc_wdv, 5:0, scratch141, 27:22); + s(emc_fbio_cfg5, 23:20, scratch141, 31:28); + s(emc_pmacro_ob_ddll_long_dq_rank1_1, 10:0, scratch142, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank1_1, 26:16, scratch142, 21:11); + s(emc_quse, 5:0, scratch142, 27:22); + s(emc_fbio_cfg5, 28:28, scratch142, 28:28); + s(emc_fbio_cfg5, 31:30, scratch142, 30:29); + s(emc_cfg2, 0:0, scratch142, 31:31); + s(emc_pmacro_ob_ddll_long_dq_rank1_2, 10:0, scratch143, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank1_2, 26:16, scratch143, 21:11); + s(emc_pdex2wr, 5:0, scratch143, 27:22); + s(emc_cfg2, 2:1, scratch143, 29:28); + s(emc_cfg2, 7:7, scratch143, 30:30); + s(emc_cfg2, 10:10, scratch143, 31:31); + s(emc_pmacro_ob_ddll_long_dq_rank1_3, 10:0, scratch144, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank1_3, 26:16, scratch144, 21:11); + s(emc_pdex2rd, 5:0, scratch144, 27:22); + s(emc_cfg2, 11:11, scratch144, 28:28); + s(emc_cfg2, 16:14, scratch144, 31:29); + s(emc_pmacro_ob_ddll_long_dq_rank1_4, 10:0, scratch145, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank1_4, 26:16, scratch145, 21:11); + s(emc_pdex2che, 5:0, scratch145, 27:22); + s(emc_cfg2, 20:20, scratch145, 28:28); + s(emc_cfg2, 24:22, scratch145, 31:29); + s(emc_pmacro_ob_ddll_long_dq_rank1_5, 10:0, scratch146, 10:0); + s(emc_pmacro_ob_ddll_long_dq_rank1_5, 26:16, scratch146, 21:11); + s(emc_pchg2pden, 5:0, scratch146, 27:22); + s(emc_cfg2, 25:25, scratch146, 28:28); + s(emc_cfg2, 30:28, scratch146, 31:29); + s(emc_pmacro_ob_ddll_long_dqs_rank0_0, 10:0, scratch147, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank0_0, 26:16, scratch147, 21:11); + s(emc_act2pden, 5:0, scratch147, 27:22); + s(emc_cfg2, 31:31, scratch147, 28:28); + s(emc_cfg_pipe, 2:0, scratch147, 31:29); + s(emc_pmacro_ob_ddll_long_dqs_rank0_1, 10:0, scratch148, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank0_1, 26:16, scratch148, 21:11); + s(emc_cke2pden, 5:0, scratch148, 27:22); + s(emc_cfg_pipe, 6:3, scratch148, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank0_2, 10:0, scratch149, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank0_2, 26:16, scratch149, 21:11); + s(emc_tcke, 5:0, scratch149, 27:22); + s(emc_cfg_pipe, 10:7, scratch149, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank0_3, 10:0, scratch150, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank0_3, 26:16, scratch150, 21:11); + s(emc_trpab, 5:0, scratch150, 27:22); + s(emc_cfg_pipe, 11:11, scratch150, 28:28); + s(emc_cfg_pipe, 18:16, scratch150, 31:29); + s(emc_pmacro_ob_ddll_long_dqs_rank0_4, 10:0, scratch151, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank0_4, 26:16, scratch151, 21:11); + s(emc_einput, 5:0, scratch151, 27:22); + s(emc_cfg_pipe, 22:19, scratch151, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank0_5, 10:0, scratch152, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank0_5, 26:16, scratch152, 21:11); + s(emc_einput_duration, 5:0, scratch152, 27:22); + s(emc_cfg_pipe, 26:23, scratch152, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank1_0, 10:0, scratch153, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank1_0, 26:16, scratch153, 21:11); + s(emc_puterm_extra, 5:0, scratch153, 27:22); + s(emc_cfg_pipe, 27:27, scratch153, 28:28); + s(emc_pmacro_tx_sel_clk_src0, 2:0, scratch153, 31:29); + s(emc_pmacro_ob_ddll_long_dqs_rank1_1, 10:0, scratch154, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank1_1, 26:16, scratch154, 21:11); + s(emc_tckesr, 5:0, scratch154, 27:22); + s(emc_pmacro_tx_sel_clk_src0, 6:3, scratch154, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank1_2, 10:0, scratch155, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank1_2, 26:16, scratch155, 21:11); + s(emc_tpd, 5:0, scratch155, 27:22); + s(emc_pmacro_tx_sel_clk_src0, 10:7, scratch155, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank1_3, 10:0, scratch156, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank1_3, 26:16, scratch156, 21:11); + s(emc_wdv_mask, 5:0, scratch156, 27:22); + s(emc_pmacro_tx_sel_clk_src0, 19:16, scratch156, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank1_4, 10:0, scratch157, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank1_4, 26:16, scratch157, 21:11); + s(emc_wdv_chk, 5:0, scratch157, 27:22); + s(emc_pmacro_tx_sel_clk_src0, 23:20, scratch157, 31:28); + s(emc_pmacro_ob_ddll_long_dqs_rank1_5, 10:0, scratch158, 10:0); + s(emc_pmacro_ob_ddll_long_dqs_rank1_5, 26:16, scratch158, 21:11); + s(emc_cmd_brlshft0, 5:0, scratch158, 27:22); + s(emc_pmacro_tx_sel_clk_src0, 26:24, scratch158, 30:28); + s(emc_pmacro_tx_sel_clk_src1, 0:0, scratch158, 31:31); + s(emc_pmacro_ib_ddll_long_dqs_rank0_0, 10:0, scratch159, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank0_0, 26:16, scratch159, 21:11); + s(emc_cmd_brlshft1, 5:0, scratch159, 27:22); + s(emc_pmacro_tx_sel_clk_src1, 4:1, scratch159, 31:28); + s(emc_pmacro_ib_ddll_long_dqs_rank0_1, 10:0, scratch160, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank0_1, 26:16, scratch160, 21:11); + s(emc_cmd_brlshft2, 5:0, scratch160, 27:22); + s(emc_pmacro_tx_sel_clk_src1, 8:5, scratch160, 31:28); + s(emc_pmacro_ib_ddll_long_dqs_rank0_2, 10:0, scratch161, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank0_2, 26:16, scratch161, 21:11); + s(emc_cmd_brlshft3, 5:0, scratch161, 27:22); + s(emc_pmacro_tx_sel_clk_src1, 10:9, scratch161, 29:28); + s(emc_pmacro_tx_sel_clk_src1, 17:16, scratch161, 31:30); + s(emc_pmacro_ib_ddll_long_dqs_rank0_3, 10:0, scratch162, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank0_3, 26:16, scratch162, 21:11); + s(emc_wev, 5:0, scratch162, 27:22); + s(emc_pmacro_tx_sel_clk_src1, 21:18, scratch162, 31:28); + s(emc_pmacro_ib_ddll_long_dqs_rank1_0, 10:0, scratch163, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank1_0, 26:16, scratch163, 21:11); + s(emc_wsv, 5:0, scratch163, 27:22); + s(emc_pmacro_tx_sel_clk_src1, 25:22, scratch163, 31:28); + s(emc_pmacro_ib_ddll_long_dqs_rank1_1, 10:0, scratch164, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank1_1, 26:16, scratch164, 21:11); + s(emc_cfg3, 2:0, scratch164, 24:22); + s(emc_cfg3, 6:4, scratch164, 27:25); + s(emc_pmacro_tx_sel_clk_src1, 26:26, scratch164, 28:28); + s(emc_pmacro_tx_sel_clk_src3, 2:0, scratch164, 31:29); + s(emc_pmacro_ib_ddll_long_dqs_rank1_2, 10:0, scratch165, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank1_2, 26:16, scratch165, 21:11); + s(emc_puterm_width, 31:31, scratch165, 22:22); + s(emc_puterm_width, 4:0, scratch165, 27:23); + s(emc_pmacro_tx_sel_clk_src3, 6:3, scratch165, 31:28); + s(emc_pmacro_ib_ddll_long_dqs_rank1_3, 10:0, scratch166, 10:0); + s(emc_pmacro_ib_ddll_long_dqs_rank1_3, 26:16, scratch166, 21:11); + s(mc_emem_arb_timing_rcd, 5:0, scratch166, 27:22); + s(emc_pmacro_tx_sel_clk_src3, 10:7, scratch166, 31:28); + s(emc_pmacro_ddll_long_cmd_0, 10:0, scratch167, 10:0); + s(emc_pmacro_ddll_long_cmd_0, 26:16, scratch167, 21:11); + s(mc_emem_arb_timing_ccdmw, 5:0, scratch167, 27:22); + s(emc_pmacro_tx_sel_clk_src3, 19:16, scratch167, 31:28); + s(emc_pmacro_ddll_long_cmd_1, 10:0, scratch168, 10:0); + s(emc_pmacro_ddll_long_cmd_1, 26:16, scratch168, 21:11); + s(mc_emem_arb_override, 27:27, scratch168, 22:22); + s(mc_emem_arb_override, 26:26, scratch168, 23:23); + s(mc_emem_arb_override, 16:16, scratch168, 24:24); + s(mc_emem_arb_override, 10:10, scratch168, 25:25); + s(mc_emem_arb_override, 4:4, scratch168, 26:26); + s(mc_emem_arb_override, 3:3, scratch168, 27:27); + s(emc_pmacro_tx_sel_clk_src3, 23:20, scratch168, 31:28); + s(emc_pmacro_ddll_long_cmd_2, 10:0, scratch169, 10:0); + s(emc_pmacro_ddll_long_cmd_2, 26:16, scratch169, 21:11); + s(emc_rrd, 4:0, scratch169, 26:22); + s(emc_rext, 4:0, scratch169, 31:27); + s(emc_pmacro_ddll_long_cmd_3, 10:0, scratch170, 10:0); + s(emc_pmacro_ddll_long_cmd_3, 26:16, scratch170, 21:11); + s(emc_tclkstop, 4:0, scratch170, 26:22); + s(emc_wext, 4:0, scratch170, 31:27); + s(emc_pmacro_perbit_fgcg_ctrl0, 10:0, scratch171, 10:0); + s(emc_pmacro_perbit_fgcg_ctrl0, 26:16, scratch171, 21:11); + s(emc_ref_ctrl2, 0:0, scratch171, 22:22); + s(emc_ref_ctrl2, 26:24, scratch171, 25:23); + s(emc_ref_ctrl2, 31:31, scratch171, 26:26); + s(emc_we_duration, 4:0, scratch171, 31:27); + s(emc_pmacro_perbit_fgcg_ctrl1, 10:0, scratch172, 10:0); + s(emc_pmacro_perbit_fgcg_ctrl1, 26:16, scratch172, 21:11); + s(emc_ws_duration, 4:0, scratch172, 26:22); + s(emc_pmacro_pad_cfg_ctrl, 0:0, scratch172, 27:27); + s(emc_pmacro_pad_cfg_ctrl, 9:9, scratch172, 28:28); + s(emc_pmacro_pad_cfg_ctrl, 13:13, scratch172, 29:29); + s(emc_pmacro_pad_cfg_ctrl, 17:16, scratch172, 31:30); + s(emc_pmacro_perbit_fgcg_ctrl2, 10:0, scratch173, 10:0); + s(emc_pmacro_perbit_fgcg_ctrl2, 26:16, scratch173, 21:11); + s(mc_emem_arb_timing_rrd, 4:0, scratch173, 26:22); + s(mc_emem_arb_timing_r2r, 4:0, scratch173, 31:27); + s(emc_pmacro_perbit_fgcg_ctrl3, 10:0, scratch174, 10:0); + s(emc_pmacro_perbit_fgcg_ctrl3, 26:16, scratch174, 21:11); + s(mc_emem_arb_timing_w2w, 4:0, scratch174, 26:22); + s(emc_pmacro_tx_sel_clk_src3, 26:24, scratch174, 29:27); + s(emc_pmacro_tx_sel_clk_src2, 1:0, scratch174, 31:30); + s(emc_pmacro_perbit_fgcg_ctrl4, 10:0, scratch175, 10:0); + s(emc_pmacro_perbit_fgcg_ctrl4, 26:16, scratch175, 21:11); + s(emc_pmacro_tx_sel_clk_src2, 10:2, scratch175, 30:22); + s(emc_pmacro_tx_sel_clk_src2, 16:16, scratch175, 31:31); + s(emc_pmacro_perbit_fgcg_ctrl5, 10:0, scratch176, 10:0); + s(emc_pmacro_perbit_fgcg_ctrl5, 26:16, scratch176, 21:11); + s(emc_pmacro_tx_sel_clk_src2, 26:17, scratch176, 31:22); + s(mc_emem_arb_cfg, 8:0, scratch177, 8:0); + s(mc_emem_arb_cfg, 20:16, scratch177, 13:9); + s(mc_emem_arb_cfg, 31:24, scratch177, 21:14); + s(emc_pmacro_tx_sel_clk_src4, 9:0, scratch177, 31:22); + s(mc_emem_arb_misc1, 12:0, scratch178, 12:0); + s(mc_emem_arb_misc1, 25:21, scratch178, 17:13); + s(mc_emem_arb_misc1, 31:28, scratch178, 21:18); + s(emc_pmacro_tx_sel_clk_src4, 10:10, scratch178, 22:22); + s(emc_pmacro_tx_sel_clk_src4, 24:16, scratch178, 31:23); + s(emc_mrs_wait_cnt2, 9:0, scratch179, 9:0); + s(emc_mrs_wait_cnt2, 26:16, scratch179, 20:10); + s(emc_odt_write, 5:0, scratch179, 26:21); + s(emc_odt_write, 11:8, scratch179, 30:27); + s(emc_odt_write, 31:31, scratch179, 31:31); + s(emc_mrs_wait_cnt, 9:0, scratch180, 9:0); + s(emc_mrs_wait_cnt, 26:16, scratch180, 20:10); + s(emc_pmacro_ib_rxrt, 10:0, scratch180, 31:21); + s(emc_auto_cal_interval, 20:0, scratch181, 20:0); + s(emc_pmacro_ddll_long_cmd_4, 10:0, scratch181, 31:21); + s(emc_emem_arb_refpb_hp_ctrl, 6:0, scratch182, 6:0); + s(emc_emem_arb_refpb_hp_ctrl, 14:8, scratch182, 13:7); + s(emc_emem_arb_refpb_hp_ctrl, 22:16, scratch182, 20:14); + s(mc_emem_arb_outstanding_req, 8:0, scratch182, 29:21); + s(mc_emem_arb_outstanding_req, 31:30, scratch182, 31:30); + s(emc_xm2_comp_pad_ctrl2, 5:0, scratch183, 5:0); + s(emc_xm2_comp_pad_ctrl2, 17:12, scratch183, 11:6); + s(emc_xm2_comp_pad_ctrl2, 21:20, scratch183, 13:12); + s(emc_xm2_comp_pad_ctrl2, 29:24, scratch183, 19:14); + s(emc_pmacro_cmd_ctrl0, 0:0, scratch183, 20:20); + s(emc_pmacro_cmd_ctrl0, 5:4, scratch183, 22:21); + s(emc_pmacro_cmd_ctrl0, 8:8, scratch183, 23:23); + s(emc_pmacro_cmd_ctrl0, 13:12, scratch183, 25:24); + s(emc_pmacro_cmd_ctrl0, 16:16, scratch183, 26:26); + s(emc_pmacro_cmd_ctrl0, 21:20, scratch183, 28:27); + s(emc_pmacro_cmd_ctrl0, 24:24, scratch183, 29:29); + s(emc_pmacro_cmd_ctrl0, 29:28, scratch183, 31:30); + s(emc_cfg_dig_dll_1, 19:0, scratch184, 19:0); + s(emc_pmacro_cmd_ctrl1, 0:0, scratch184, 20:20); + s(emc_pmacro_cmd_ctrl1, 5:4, scratch184, 22:21); + s(emc_pmacro_cmd_ctrl1, 8:8, scratch184, 23:23); + s(emc_pmacro_cmd_ctrl1, 13:12, scratch184, 25:24); + s(emc_pmacro_cmd_ctrl1, 16:16, scratch184, 26:26); + s(emc_pmacro_cmd_ctrl1, 21:20, scratch184, 28:27); + s(emc_pmacro_cmd_ctrl1, 24:24, scratch184, 29:29); + s(emc_pmacro_cmd_ctrl1, 29:28, scratch184, 31:30); + s(emc_quse_brlshft0, 19:0, scratch185, 19:0); + s(emc_pmacro_cmd_ctrl2, 0:0, scratch185, 20:20); + s(emc_pmacro_cmd_ctrl2, 5:4, scratch185, 22:21); + s(emc_pmacro_cmd_ctrl2, 8:8, scratch185, 23:23); + s(emc_pmacro_cmd_ctrl2, 13:12, scratch185, 25:24); + s(emc_pmacro_cmd_ctrl2, 16:16, scratch185, 26:26); + s(emc_pmacro_cmd_ctrl2, 21:20, scratch185, 28:27); + s(emc_pmacro_cmd_ctrl2, 24:24, scratch185, 29:29); + s(emc_pmacro_cmd_ctrl2, 29:28, scratch185, 31:30); + s(emc_quse_brlshft1, 19:0, scratch186, 19:0); + s(emc_pmacro_dsr_vttgen_ctrl0, 3:0, scratch186, 23:20); + s(emc_pmacro_dsr_vttgen_ctrl0, 15:8, scratch186, 31:24); + s(emc_quse_brlshft2, 19:0, scratch187, 19:0); + s(emc_pmacro_perbit_rfu1_ctrl0, 5:0, scratch187, 25:20); + s(emc_pmacro_perbit_rfu1_ctrl0, 21:16, scratch187, 31:26); + s(emc_quse_brlshft3, 19:0, scratch188, 19:0); + s(emc_pmacro_perbit_rfu1_ctrl1, 5:0, scratch188, 25:20); + s(emc_pmacro_perbit_rfu1_ctrl1, 21:16, scratch188, 31:26); + s(emc_dbg, 4:0, scratch189, 4:0); + s(emc_dbg, 13:9, scratch189, 9:5); + s(emc_dbg, 31:24, scratch189, 17:10); + s(emc_trefbw, 13:0, scratch189, 31:18); + s(emc_zcal_wait_cnt, 10:0, scratch191, 10:0); + s(emc_zcal_wait_cnt, 21:16, scratch191, 16:11); + s(emc_zcal_wait_cnt, 31:31, scratch191, 17:17); + s(emc_qpop, 6:0, scratch191, 24:18); + s(emc_qpop, 22:16, scratch191, 31:25); + s(emc_zcal_mrw_cmd, 7:0, scratch192, 7:0); + s(emc_zcal_mrw_cmd, 23:16, scratch192, 15:8); + s(emc_zcal_mrw_cmd, 31:30, scratch192, 17:16); + s(emc_pmacro_auto_cal_common, 5:0, scratch192, 23:18); + s(emc_pmacro_auto_cal_common, 13:8, scratch192, 29:24); + s(emc_pmacro_auto_cal_common, 16:16, scratch192, 30:30); + s(emc_pmacro_tx_sel_clk_src4, 25:25, scratch192, 31:31); + s(emc_dll_cfg1, 10:0, scratch193, 10:0); + s(emc_dll_cfg1, 13:12, scratch193, 12:11); + s(emc_dll_cfg1, 17:16, scratch193, 14:13); + s(emc_dll_cfg1, 21:20, scratch193, 16:15); + s(emc_dll_cfg1, 24:24, scratch193, 17:17); + s(emc_pmacro_perbit_rfu1_ctrl2, 5:0, scratch193, 23:18); + s(emc_pmacro_perbit_rfu1_ctrl2, 21:16, scratch193, 29:24); + s(emc_pmacro_tx_sel_clk_src4, 26:26, scratch193, 30:30); + s(emc_pmacro_tx_sel_clk_src5, 0:0, scratch193, 31:31); + s(emc_pmacro_cmd_brick_ctrl_fdpd, 17:0, scratch194, 17:0); + s(emc_pmacro_perbit_rfu1_ctrl3, 5:0, scratch194, 23:18); + s(emc_pmacro_perbit_rfu1_ctrl3, 21:16, scratch194, 29:24); + s(emc_pmacro_tx_sel_clk_src5, 2:1, scratch194, 31:30); + s(emc_pmacro_data_brick_ctrl_fdpd, 17:0, scratch195, 17:0); + s(emc_pmacro_perbit_rfu1_ctrl4, 5:0, scratch195, 23:18); + s(emc_pmacro_perbit_rfu1_ctrl4, 21:16, scratch195, 29:24); + s(emc_pmacro_tx_sel_clk_src5, 4:3, scratch195, 31:30); + s(emc_dyn_self_ref_control, 15:0, scratch196, 15:0); + s(emc_dyn_self_ref_control, 31:31, scratch196, 16:16); + s(emc_emem_arb_refpb_bank_ctrl, 6:0, scratch196, 23:17); + s(emc_emem_arb_refpb_bank_ctrl, 14:8, scratch196, 30:24); + s(emc_emem_arb_refpb_bank_ctrl, 31:31, scratch196, 31:31); + s(emc_pmacro_cmd_pad_rx_ctrl, 1:0, scratch197, 1:0); + s(emc_pmacro_cmd_pad_rx_ctrl, 5:4, scratch197, 3:2); + s(emc_pmacro_cmd_pad_rx_ctrl, 12:12, scratch197, 4:4); + s(emc_pmacro_cmd_pad_rx_ctrl, 19:15, scratch197, 9:5); + s(emc_pmacro_cmd_pad_rx_ctrl, 27:21, scratch197, 16:10); + s(emc_pmacro_perbit_rfu1_ctrl5, 5:0, scratch197, 22:17); + s(emc_pmacro_perbit_rfu1_ctrl5, 21:16, scratch197, 28:23); + s(emc_pmacro_tx_sel_clk_src5, 7:5, scratch197, 31:29); + s(emc_pmacro_data_pad_rx_ctrl, 1:0, scratch198, 1:0); + s(emc_pmacro_data_pad_rx_ctrl, 5:4, scratch198, 3:2); + s(emc_pmacro_data_pad_rx_ctrl, 12:12, scratch198, 4:4); + s(emc_pmacro_data_pad_rx_ctrl, 19:15, scratch198, 9:5); + s(emc_pmacro_data_pad_rx_ctrl, 27:21, scratch198, 16:10); + s(emc_pmacro_tx_sel_clk_src5, 10:8, scratch198, 19:17); + s(emc_pmacro_tx_sel_clk_src5, 26:16, scratch198, 30:20); + s(emc_pmacro_cmd_pad_tx_ctrl, 0:0, scratch198, 31:31); + s(emc_refresh, 15:0, scratch199, 15:0); + s(emc_cmd_q, 4:0, scratch199, 20:16); + s(emc_cmd_q, 10:8, scratch199, 23:21); + s(emc_cmd_q, 14:12, scratch199, 26:24); + s(emc_cmd_q, 28:24, scratch199, 31:27); + s(emc_acpd_control, 15:0, scratch210, 15:0); + s(emc_auto_cal_vref_sel1, 15:0, scratch210, 31:16); + s(emc_pmacro_auto_cal_cfg0, 3:0, scratch211, 3:0); + s(emc_pmacro_auto_cal_cfg0, 11:8, scratch211, 7:4); + s(emc_pmacro_auto_cal_cfg0, 19:16, scratch211, 11:8); + s(emc_pmacro_auto_cal_cfg0, 27:24, scratch211, 15:12); + s(emc_pmacro_auto_cal_cfg1, 3:0, scratch211, 19:16); + s(emc_pmacro_auto_cal_cfg1, 11:8, scratch211, 23:20); + s(emc_pmacro_auto_cal_cfg1, 19:16, scratch211, 27:24); + s(emc_pmacro_auto_cal_cfg1, 27:24, scratch211, 31:28); + s(emc_pmacro_auto_cal_cfg2, 3:0, scratch212, 3:0); + s(emc_pmacro_auto_cal_cfg2, 11:8, scratch212, 7:4); + s(emc_pmacro_auto_cal_cfg2, 19:16, scratch212, 11:8); + s(emc_pmacro_auto_cal_cfg2, 27:24, scratch212, 15:12); + s(emc_xm2_comp_pad_ctrl3, 5:0, scratch212, 21:16); + s(emc_xm2_comp_pad_ctrl3, 17:12, scratch212, 27:22); + s(emc_xm2_comp_pad_ctrl3, 23:20, scratch212, 31:28); + s(emc_cfg_dig_dll_period, 15:0, scratch213, 15:0); + s(emc_prerefresh_req_cnt, 15:0, scratch213, 31:16); + s(emc_pmacro_ddll_bypass, 0:0, scratch214, 0:0); + s(emc_pmacro_ddll_bypass, 11:8, scratch214, 4:1); + s(emc_pmacro_ddll_bypass, 16:13, scratch214, 8:5); + s(emc_pmacro_ddll_bypass, 27:24, scratch214, 12:9); + s(emc_pmacro_ddll_bypass, 31:29, scratch214, 15:13); + s(emc_pmacro_data_pi_ctrl, 4:0, scratch214, 20:16); + s(emc_pmacro_data_pi_ctrl, 12:8, scratch214, 25:21); + s(emc_pmacro_data_pi_ctrl, 21:16, scratch214, 31:26); + s(emc_pmacro_cmd_pi_ctrl, 4:0, scratch215, 4:0); + s(emc_pmacro_cmd_pi_ctrl, 12:8, scratch215, 9:5); + s(emc_pmacro_cmd_pi_ctrl, 21:16, scratch215, 15:10); + + s(emc_pin_gpio, 1:0, scratch9, 31:30); + s(emc_pin_gpio_enable, 1:0, scratch10, 31:30); + s(emc_dev_select, 1:0, scratch11, 31:30); + s(emc_zcal_warm_cold_boot_enables, 1:0, scratch12, 31:30); + s(emc_cfg_dig_dll_period_warm_boot, 1:0, scratch13, 31:30); s32(emc_bct_spare13, scratch45); s32(emc_bct_spare12, scratch46); s32(emc_bct_spare7, scratch47); @@ -1353,71 +1806,224 @@ static void _sdram_lp0_save_params_t210b01(const void *params) s32(emc_bct_spare8, scratch61); s32(boot_rom_patch_data, scratch62); s32(boot_rom_patch_control, scratch63); - pmc->scratch65 = ((2 * pmc->scratch65) >> 1) | ((u16)(sdram->mc_clken_override_allwarm_boot) << 31); - pmc->scratch66 = pmc->scratch66 & 0x1FFFFFFF | ((u8)(sdram->emc_extra_refresh_num) << 29); - pmc->scratch72 = pmc->scratch72 & 0x8FFFFFFF | ((u16)(sdram->pmc_io_dpd3_req_wait) << 28) & 0x70000000; - pmc->scratch72 = ((2 * pmc->scratch72) >> 1) | ((u16)(sdram->emc_clken_override_allwarm_boot) << 31); - pmc->scratch73 = pmc->scratch73 & 0x8FFFFFFF | ((u8)(sdram->memory_type) << 28) & 0x70000000; - pmc->scratch73 = ((2 * pmc->scratch73) >> 1) | (sdram->emc_mrs_warm_boot_enable << 31); - pmc->scratch74 = pmc->scratch74 & 0x8FFFFFFF | (sdram->pmc_io_dpd4_req_wait << 28) & 0x70000000; - pmc->scratch74 = ((2 * pmc->scratch74) >> 1) | (sdram->clear_clock2_mc1 << 31); - pmc->scratch75 = pmc->scratch75 & 0xEFFFFFFF | (sdram->emc_warm_boot_extramode_reg_write_enable << 28) & 0x10000000; - pmc->scratch75 = pmc->scratch75 & 0xDFFFFFFF | (sdram->clk_rst_pllm_misc20_override_enable << 29) & 0x20000000; - pmc->scratch75 = pmc->scratch75 & 0xBFFFFFFF | ((u16)(sdram->emc_dbg_write_mux) << 30) & 0x40000000; - pmc->scratch75 = ((2 * pmc->scratch75) >> 1) | ((u16)(sdram->ahb_arbitration_xbar_ctrl_meminit_done) << 31); - pmc->scratch90 = pmc->scratch90 & 0xFFFFFF | (sdram->emc_timing_control_wait << 24); - pmc->scratch91 = pmc->scratch91 & 0xFFFFFF | (sdram->emc_zcal_warm_boot_wait << 24); - pmc->scratch92 = pmc->scratch92 & 0xFFFFFF | (sdram->warm_boot_wait << 24); - pmc->scratch93 = pmc->scratch93 & 0xFFFFFF | ((u16)(sdram->emc_pin_program_wait) << 24); - pmc->scratch114 = pmc->scratch114 & 0x3FFFFF | ((u16)(sdram->emc_auto_cal_wait) << 22); - pmc->scratch215 = (u16)pmc->scratch215 | ((u16)(sdram->swizzle_rank_byte_encode) << 16); - pmc->scratch216 = (2 * sdram->emc_pmacro_data_pad_tx_ctrl >> 31 << 30) | ((4 * sdram->emc_pmacro_data_pad_tx_ctrl >> 31 << 29) | ((8 * sdram->emc_pmacro_data_pad_tx_ctrl >> 31 << 28) | ((16 * sdram->emc_pmacro_data_pad_tx_ctrl >> 31 << 27) | ((32 * sdram->emc_pmacro_data_pad_tx_ctrl >> 31 << 26) | ((sdram->emc_pmacro_data_pad_tx_ctrl << 6 >> 31 << 25) | tmp & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF; - pmc->scratch5 = (sdram->emc_warm_boot_mrw_extra << 24) | ((sdram->emc_warm_boot_mrw_extra >> 16 << 16) | ((sdram->emc_mrw_lpddr2zcal_warm_boot << 8) & 0xFFFF | ((sdram->emc_mrw_lpddr2zcal_warm_boot << 8 >> 24) | (pmc->scratch5 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFFFFFF; - pmc->scratch6 = (16 * sdram->emc_warm_boot_mrw_extra >> 31 << 7) | ((32 * sdram->emc_warm_boot_mrw_extra >> 31 << 6) | (32 * (16 * sdram->emc_mrw_lpddr2zcal_warm_boot >> 31) | (16 * (32 * sdram->emc_mrw_lpddr2zcal_warm_boot >> 31) | (4 * (sdram->emc_warm_boot_mrw_extra >> 30) | ((sdram->emc_mrw_lpddr2zcal_warm_boot >> 30) | 4 * (pmc->scratch6 >> 2)) & 0xFFFFFFF3) & 0xFFFFFFEF) & 0xFFFFFFDF) & 0xFFFFFFBF) & 0xFFFFFF7F; - pmc->scratch8 = (sdram->emc_mrw6 >> 30 << 28) | ((16 * sdram->emc_mrw6 >> 31 << 27) | ((32 * sdram->emc_mrw6 >> 31 << 26) | ((sdram->emc_mrw6 << 6 >> 30 << 24) | ((sdram->emc_mrw6 << 8 >> 24 << 16) | ((sdram->emc_mrw6 << 16 >> 24 << 8) | ((u8)sdram->emc_mrw6 | (pmc->scratch8 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xCFFFFFFF; - pmc->scratch9 = (sdram->emc_mrw8 >> 30 << 28) | ((16 * sdram->emc_mrw8 >> 31 << 27) | ((32 * sdram->emc_mrw8 >> 31 << 26) | ((sdram->emc_mrw8 << 6 >> 30 << 24) | ((sdram->emc_mrw8 << 8 >> 24 << 16) | ((sdram->emc_mrw8 << 16 >> 24 << 8) | ((u8)sdram->emc_mrw8 | (pmc->scratch9 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xCFFFFFFF; - pmc->scratch10 = (sdram->emc_mrw9 >> 30 << 28) | ((16 * sdram->emc_mrw9 >> 31 << 27) | ((32 * sdram->emc_mrw9 >> 31 << 26) | ((sdram->emc_mrw9 << 6 >> 30 << 24) | ((sdram->emc_mrw9 << 8 >> 24 << 16) | ((sdram->emc_mrw9 << 16 >> 24 << 8) | ((u8)sdram->emc_mrw9 | (pmc->scratch10 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xCFFFFFFF; - pmc->scratch11 = (sdram->emc_mrw10 >> 30 << 28) | ((16 * sdram->emc_mrw10 >> 31 << 27) | ((32 * sdram->emc_mrw10 >> 31 << 26) | ((sdram->emc_mrw10 << 6 >> 30 << 24) | ((sdram->emc_mrw10 << 8 >> 24 << 16) | ((sdram->emc_mrw10 << 16 >> 24 << 8) | ((u8)sdram->emc_mrw10 | (pmc->scratch11 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xCFFFFFFF; - pmc->scratch12 = (sdram->emc_mrw12 >> 30 << 28) | ((16 * sdram->emc_mrw12 >> 31 << 27) | ((32 * sdram->emc_mrw12 >> 31 << 26) | ((sdram->emc_mrw12 << 6 >> 30 << 24) | ((sdram->emc_mrw12 << 8 >> 24 << 16) | ((sdram->emc_mrw12 << 16 >> 24 << 8) | ((u8)sdram->emc_mrw12 | (pmc->scratch12 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xCFFFFFFF; - pmc->scratch13 = (sdram->emc_mrw13 >> 30 << 28) | ((16 * sdram->emc_mrw13 >> 31 << 27) | ((32 * sdram->emc_mrw13 >> 31 << 26) | ((sdram->emc_mrw13 << 6 >> 30 << 24) | ((sdram->emc_mrw13 << 8 >> 24 << 16) | ((sdram->emc_mrw13 << 16 >> 24 << 8) | ((u8)sdram->emc_mrw13 | (pmc->scratch13 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xCFFFFFFF; - pmc->scratch14 = (sdram->emc_mrw14 >> 30 << 28) | ((16 * sdram->emc_mrw14 >> 31 << 27) | ((32 * sdram->emc_mrw14 >> 31 << 26) | ((sdram->emc_mrw14 << 6 >> 30 << 24) | ((sdram->emc_mrw14 << 8 >> 24 << 16) | ((sdram->emc_mrw14 << 16 >> 24 << 8) | ((u8)sdram->emc_mrw14 | (pmc->scratch14 >> 8 << 8)) & 0xFFFF00FF) & 0xFF00FFFF) & 0xFCFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xCFFFFFFF; - pmc->scratch15 = (sdram->emc_mrw1 >> 30 << 18) | ((16 * sdram->emc_mrw1 >> 31 << 17) | ((32 * sdram->emc_mrw1 >> 31 << 16) | ((sdram->emc_mrw1 << 8 >> 24 << 8) | ((u8)sdram->emc_mrw1 | (pmc->scratch15 >> 8 << 8)) & 0xFFFF00FF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFF3FFFF; - pmc->scratch16 = (sdram->emc_warm_boot_mrw_extra >> 30 << 18) | ((16 * sdram->emc_warm_boot_mrw_extra >> 31 << 17) | ((32 * sdram->emc_warm_boot_mrw_extra >> 31 << 16) | ((sdram->emc_warm_boot_mrw_extra << 8 >> 24 << 8) | ((u8)sdram->emc_warm_boot_mrw_extra | (pmc->scratch16 >> 8 << 8)) & 0xFFFF00FF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFF3FFFF; - pmc->scratch17 = (sdram->emc_mrw2 >> 30 << 18) | ((16 * sdram->emc_mrw2 >> 31 << 17) | ((32 * sdram->emc_mrw2 >> 31 << 16) | ((sdram->emc_mrw2 << 8 >> 24 << 8) | ((u8)sdram->emc_mrw2 | (pmc->scratch17 >> 8 << 8)) & 0xFFFF00FF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFF3FFFF; - pmc->scratch18 = (sdram->emc_mrw3 >> 30 << 18) | ((16 * sdram->emc_mrw3 >> 31 << 17) | ((32 * sdram->emc_mrw3 >> 31 << 16) | ((sdram->emc_mrw3 << 8 >> 24 << 8) | ((u8)sdram->emc_mrw3 | (pmc->scratch18 >> 8 << 8)) & 0xFFFF00FF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFF3FFFF; - pmc->scratch19 = (sdram->emc_mrw4 >> 30 << 18) | ((16 * sdram->emc_mrw4 >> 31 << 17) | ((32 * sdram->emc_mrw4 >> 31 << 16) | ((sdram->emc_mrw4 << 8 >> 24 << 8) | ((u8)sdram->emc_mrw4 | (pmc->scratch19 >> 8 << 8)) & 0xFFFF00FF) & 0xFFFEFFFF) & 0xFFFDFFFF) & 0xFFF3FFFF; - pmc->secure_scratch8 = (sdram->emc_cmd_mapping_byte >> 28 << 28) | ((16 * sdram->emc_cmd_mapping_byte >> 28 << 24) | ((sdram->emc_cmd_mapping_byte << 8 >> 28 << 20) | ((sdram->emc_cmd_mapping_byte << 12 >> 28 << 16) | ((sdram->emc_cmd_mapping_byte << 16 >> 28 << 12) | ((sdram->emc_cmd_mapping_byte << 20 >> 28 << 8) | (16 * (sdram->emc_cmd_mapping_byte << 24 >> 28) | (sdram->emc_cmd_mapping_byte & 0xF | 16 * (pmc->secure_scratch8 >> 4)) & 0xFFFFFF0F) & 0xFFFFF0FF) & 0xFFFF0FFF) & 0xFFF0FFFF) & 0xFF0FFFFF) & 0xF0FFFFFF) & 0xFFFFFFF; - pmc->secure_scratch9 = (sdram->emc_pmacro_brick_mapping0 >> 28 << 28) | ((16 * sdram->emc_pmacro_brick_mapping0 >> 28 << 24) | ((sdram->emc_pmacro_brick_mapping0 << 8 >> 28 << 20) | ((sdram->emc_pmacro_brick_mapping0 << 12 >> 28 << 16) | ((sdram->emc_pmacro_brick_mapping0 << 16 >> 28 << 12) | ((sdram->emc_pmacro_brick_mapping0 << 20 >> 28 << 8) | (16 * (sdram->emc_pmacro_brick_mapping0 << 24 >> 28) | (sdram->emc_pmacro_brick_mapping0 & 0xF | 16 * (pmc->secure_scratch9 >> 4)) & 0xFFFFFF0F) & 0xFFFFF0FF) & 0xFFFF0FFF) & 0xFFF0FFFF) & 0xFF0FFFFF) & 0xF0FFFFFF) & 0xFFFFFFF; - pmc->secure_scratch10 = (sdram->emc_pmacro_brick_mapping1 >> 28 << 28) | ((16 * sdram->emc_pmacro_brick_mapping1 >> 28 << 24) | ((sdram->emc_pmacro_brick_mapping1 << 8 >> 28 << 20) | ((sdram->emc_pmacro_brick_mapping1 << 12 >> 28 << 16) | ((sdram->emc_pmacro_brick_mapping1 << 16 >> 28 << 12) | ((sdram->emc_pmacro_brick_mapping1 << 20 >> 28 << 8) | (16 * (sdram->emc_pmacro_brick_mapping1 << 24 >> 28) | (sdram->emc_pmacro_brick_mapping1 & 0xF | 16 * (pmc->secure_scratch10 >> 4)) & 0xFFFFFF0F) & 0xFFFFF0FF) & 0xFFFF0FFF) & 0xFFF0FFFF) & 0xFF0FFFFF) & 0xF0FFFFFF) & 0xFFFFFFF; - pmc->secure_scratch11 = (sdram->emc_pmacro_brick_mapping2 >> 28 << 28) | ((16 * sdram->emc_pmacro_brick_mapping2 >> 28 << 24) | ((sdram->emc_pmacro_brick_mapping2 << 8 >> 28 << 20) | ((sdram->emc_pmacro_brick_mapping2 << 12 >> 28 << 16) | ((sdram->emc_pmacro_brick_mapping2 << 16 >> 28 << 12) | ((sdram->emc_pmacro_brick_mapping2 << 20 >> 28 << 8) | (16 * (sdram->emc_pmacro_brick_mapping2 << 24 >> 28) | (sdram->emc_pmacro_brick_mapping2 & 0xF | 16 * (pmc->secure_scratch11 >> 4)) & 0xFFFFFF0F) & 0xFFFFF0FF) & 0xFFFF0FFF) & 0xFFF0FFFF) & 0xFF0FFFFF) & 0xF0FFFFFF) & 0xFFFFFFF; + s(mc_clken_override_allwarm_boot, 0:0, scratch65, 31:31); + s(emc_extra_refresh_num, 2:0, scratch66, 31:29); + s(pmc_io_dpd3_req_wait, 2:0, scratch72, 30:28); + s(emc_clken_override_allwarm_boot, 0:0, scratch72, 31:31); + s(memory_type, 2:0, scratch73, 30:28); + s(emc_mrs_warm_boot_enable, 0:0, scratch73, 31:31); + s(pmc_io_dpd4_req_wait, 2:0, scratch74, 30:28); + s(clear_clock2_mc1, 0:0, scratch74, 31:31); + s(emc_warm_boot_extramode_reg_write_enable, 0:0, scratch75, 28:28); + s(clk_rst_pllm_misc20_override_enable, 0:0, scratch75, 29:29); + s(emc_dbg_write_mux, 0:0, scratch75, 30:30); + s(ahb_arbitration_xbar_ctrl_meminit_done, 0:0, scratch75, 31:31); + s(emc_timing_control_wait, 7:0, scratch90, 31:24); + s(emc_zcal_warm_boot_wait, 7:0, scratch91, 31:24); + s(warm_boot_wait, 7:0, scratch92, 31:24); + s(emc_pin_program_wait, 7:0, scratch93, 31:24); + s(emc_auto_cal_wait, 9:0, scratch114, 31:22); + s(swizzle_rank_byte_encode, 15:0, scratch215, 31:16); + s(emc_pmacro_cmd_pad_tx_ctrl, 6:5, scratch216, 1:0); + s(emc_pmacro_cmd_pad_tx_ctrl, 10:10, scratch216, 2:2); + s(emc_pmacro_cmd_pad_tx_ctrl, 16:15, scratch216, 4:3); + s(emc_pmacro_cmd_pad_tx_ctrl, 30:21, scratch216, 14:5); + s(emc_pmacro_data_pad_tx_ctrl, 0:0, scratch216, 15:15); + s(emc_pmacro_data_pad_tx_ctrl, 6:5, scratch216, 17:16); + s(emc_pmacro_data_pad_tx_ctrl, 10:10, scratch216, 18:18); + s(emc_pmacro_data_pad_tx_ctrl, 16:15, scratch216, 20:19); + s(emc_pmacro_data_pad_tx_ctrl, 30:21, scratch216, 30:21); + + // LPDDR4 MRW. + s(emc_mrw_lpddr2zcal_warm_boot, 23:16, scratch5, 7:0); + s(emc_mrw_lpddr2zcal_warm_boot, 7:0, scratch5, 15:8); + s(emc_warm_boot_mrw_extra, 23:16, scratch5, 23:16); + s(emc_warm_boot_mrw_extra, 7:0, scratch5, 31:24); + s(emc_mrw_lpddr2zcal_warm_boot, 31:30, scratch6, 1:0); + s(emc_warm_boot_mrw_extra, 31:30, scratch6, 3:2); + s(emc_mrw_lpddr2zcal_warm_boot, 27:26, scratch6, 5:4); + s(emc_warm_boot_mrw_extra, 27:26, scratch6, 7:6); + s(emc_mrw6, 27:0, scratch8, 27:0); + s(emc_mrw6, 31:30, scratch8, 29:28); + s(emc_mrw8, 27:0, scratch9, 27:0); + s(emc_mrw8, 31:30, scratch9, 29:28); + s(emc_mrw9, 27:0, scratch10, 27:0); + s(emc_mrw9, 31:30, scratch10, 29:28); + s(emc_mrw10, 27:0, scratch11, 27:0); + s(emc_mrw10, 31:30, scratch11, 29:28); + s(emc_mrw12, 27:0, scratch12, 27:0); + s(emc_mrw12, 31:30, scratch12, 29:28); + s(emc_mrw13, 27:0, scratch13, 27:0); + s(emc_mrw13, 31:30, scratch13, 29:28); + s(emc_mrw14, 27:0, scratch14, 27:0); + s(emc_mrw14, 31:30, scratch14, 29:28); + s(emc_mrw1, 7:0, scratch15, 7:0); + s(emc_mrw1, 23:16, scratch15, 15:8); + s(emc_mrw1, 27:26, scratch15, 17:16); + s(emc_mrw1, 31:30, scratch15, 19:18); + s(emc_warm_boot_mrw_extra, 7:0, scratch16, 7:0); + s(emc_warm_boot_mrw_extra, 23:16, scratch16, 15:8); + s(emc_warm_boot_mrw_extra, 27:26, scratch16, 17:16); + s(emc_warm_boot_mrw_extra, 31:30, scratch16, 19:18); + s(emc_mrw2, 7:0, scratch17, 7:0); + s(emc_mrw2, 23:16, scratch17, 15:8); + s(emc_mrw2, 27:26, scratch17, 17:16); + s(emc_mrw2, 31:30, scratch17, 19:18); + s(emc_mrw3, 7:0, scratch18, 7:0); + s(emc_mrw3, 23:16, scratch18, 15:8); + s(emc_mrw3, 27:26, scratch18, 17:16); + s(emc_mrw3, 31:30, scratch18, 19:18); + s(emc_mrw4, 7:0, scratch19, 7:0); + s(emc_mrw4, 23:16, scratch19, 15:8); + s(emc_mrw4, 27:26, scratch19, 17:16); + s(emc_mrw4, 31:30, scratch19, 19:18); + + s32(emc_cmd_mapping_byte, secure_scratch8); + s32(emc_pmacro_brick_mapping0, secure_scratch9); + s32(emc_pmacro_brick_mapping1, secure_scratch10); + s32(emc_pmacro_brick_mapping2, secure_scratch11); s32(mc_video_protect_gpu_override0, secure_scratch12); - pmc->secure_scratch13 = ((u16)(sdram->emc_adr_cfg) << 31) | (2 * ((((u16)(sdram->mc_untranslated_region_check) << 22) >> 31 << 30) | ((((u16)(sdram->mc_untranslated_region_check) << 23) >> 31 << 29) | (((u16)(sdram->mc_untranslated_region_check) << 28) & 0x1FFFFFFF | ((2 * sdram->emc_cmd_mapping_cmd0_0 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd0_0 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd0_0 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd0_0 & 0x7F | (pmc->secure_scratch13 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch14 = (sdram->mc_video_protect_write_access << 30 >> 31 << 31) | (2 * ((sdram->mc_video_protect_write_access << 30) | ((sdram->mc_video_protect_bom_adr_hi << 30 >> 2) | ((2 * sdram->emc_cmd_mapping_cmd0_1 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd0_1 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd0_1 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd0_1 & 0x7F | (pmc->secure_scratch14 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xCFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch15 = ((u16)(sdram->mc_mts_carveout_adr_hi) << 30) | (4 * ((sdram->mc_sec_carveout_adr_hi << 28) | ((2 * sdram->emc_cmd_mapping_cmd1_0 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd1_0 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd1_0 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd1_0 & 0x7F | (pmc->secure_scratch15 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xCFFFFFFF) >> 2); - pmc->secure_scratch16 = (sdram->mc_generalized_carveout3_bom_hi << 30) | (4 * ((sdram->mc_generalized_carveout5_bom_hi << 28) | ((2 * sdram->emc_cmd_mapping_cmd1_1 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd1_1 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd1_1 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd1_1 & 0x7F | (pmc->secure_scratch16 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xCFFFFFFF) >> 2); - pmc->secure_scratch17 = ((u16)(sdram->mc_generalized_carveout4_bom_hi) << 30) | (4 * (((u16)(sdram->mc_generalized_carveout2_bom_hi) << 28) | ((2 * sdram->emc_cmd_mapping_cmd2_0 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd2_0 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd2_0 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd2_0 & 0x7F | (pmc->secure_scratch17 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xCFFFFFFF) >> 2); - pmc->secure_scratch18 = (sdram->emc_fbio_cfg8 << 16 >> 31 << 31) | (2 * (((u16)(sdram->emc_fbio_spare) << 30 >> 31 << 30) | ((sdram->mc_generalized_carveout1_bom_hi << 30 >> 2) | ((2 * sdram->emc_cmd_mapping_cmd2_1 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd2_1 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd2_1 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd2_1 & 0x7F | (pmc->secure_scratch18 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xCFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch19 = (sdram->mc_video_protect_vpr_override << 31) | (2 * (((u16)(sdram->mc_mts_carveout_reg_ctrl) << 30) | ((sdram->mc_sec_carveout_protect_write_access << 31 >> 2) | (((u16)(sdram->mc_emem_adr_cfg) << 28) & 0x1FFFFFFF | ((2 * sdram->emc_cmd_mapping_cmd3_0 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd3_0 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd3_0 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd3_0 & 0x7F | (pmc->secure_scratch19 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch20 = (sdram->mc_generalized_carveout2_cfg0 << 25 >> 28 << 28) | ((2 * sdram->emc_cmd_mapping_cmd3_1 >> 25 << 21) | ((sdram->emc_cmd_mapping_cmd3_1 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd3_1 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd3_1 & 0x7F | (pmc->secure_scratch20 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xF01FFFFF) & 0xFFFFFFF; - pmc->secure_scratch39 = (sdram->mc_video_protect_vpr_override << 30 >> 31 << 31) | (2 * ((sdram->mc_generalized_carveout2_cfg0 << 21 >> 28 << 27) | ((32 * sdram->mc_generalized_carveout4_cfg0 >> 31 << 26) | ((sdram->mc_generalized_carveout4_cfg0 << 6 >> 31 << 25) | ((sdram->mc_generalized_carveout4_cfg0 << 7 >> 31 << 24) | ((sdram->mc_generalized_carveout4_cfg0 << 8 >> 31 << 23) | ((sdram->mc_generalized_carveout4_cfg0 << 9 >> 31 << 22) | ((sdram->mc_generalized_carveout4_cfg0 << 10 >> 28 << 18) | ((sdram->mc_generalized_carveout4_cfg0 << 14 >> 28 << 14) | ((sdram->mc_generalized_carveout4_cfg0 << 18 >> 29 << 11) | ((sdram->mc_generalized_carveout4_cfg0 << 21 >> 28 << 7) | (8 * (sdram->mc_generalized_carveout4_cfg0 << 25 >> 28) | (4 * (sdram->mc_generalized_carveout4_cfg0 << 29 >> 31) | (2 * (sdram->mc_generalized_carveout4_cfg0 << 30 >> 31) | (sdram->mc_generalized_carveout4_cfg0 & 1 | 2 * (pmc->secure_scratch39 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFF87) & 0xFFFFF87F) & 0xFFFFC7FF) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0x87FFFFFF) >> 1); - pmc->secure_scratch40 = (sdram->mc_video_protect_vpr_override << 29 >> 31 << 31) | (2 * ((sdram->mc_generalized_carveout2_cfg0 << 14 >> 28 << 27) | ((32 * sdram->mc_generalized_carveout5_cfg0 >> 31 << 26) | ((sdram->mc_generalized_carveout5_cfg0 << 6 >> 31 << 25) | ((sdram->mc_generalized_carveout5_cfg0 << 7 >> 31 << 24) | ((sdram->mc_generalized_carveout5_cfg0 << 8 >> 31 << 23) | ((sdram->mc_generalized_carveout5_cfg0 << 9 >> 31 << 22) | ((sdram->mc_generalized_carveout5_cfg0 << 10 >> 28 << 18) | ((sdram->mc_generalized_carveout5_cfg0 << 14 >> 28 << 14) | ((sdram->mc_generalized_carveout5_cfg0 << 18 >> 29 << 11) | ((sdram->mc_generalized_carveout5_cfg0 << 21 >> 28 << 7) | (8 * (sdram->mc_generalized_carveout5_cfg0 << 25 >> 28) | (4 * (sdram->mc_generalized_carveout5_cfg0 << 29 >> 31) | (2 * (sdram->mc_generalized_carveout5_cfg0 << 30 >> 31) | (sdram->mc_generalized_carveout5_cfg0 & 1 | 2 * (pmc->secure_scratch40 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFF87) & 0xFFFFF87F) & 0xFFFFC7FF) & 0xFFFC3FFF) & 0xFFC3FFFF) & 0xFFBFFFFF) & 0xFF7FFFFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0x87FFFFFF) >> 1); - pmc->secure_scratch41 = (sdram->mc_generalized_carveout2_cfg0 << 18 >> 29 << 29) | ((sdram->mc_generalized_carveout2_cfg0 << 10 >> 28 << 25) | ((16 * sdram->emc_cmd_mapping_cmd0_2 >> 28 << 21) | ((sdram->emc_cmd_mapping_cmd0_2 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd0_2 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd0_2 & 0x7F | (pmc->secure_scratch41 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xFE1FFFFF) & 0xE1FFFFFF) & 0x1FFFFFFF; - pmc->secure_scratch42 = ((u16)(sdram->mc_generalized_carveout1_cfg0) << 18 >> 29 << 29) | (((u16)(sdram->mc_generalized_carveout1_cfg0) << 25 >> 28 << 25) | ((16 * sdram->emc_cmd_mapping_cmd1_2 >> 28 << 21) | ((sdram->emc_cmd_mapping_cmd1_2 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd1_2 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd1_2 & 0x7F | (pmc->secure_scratch42 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xFE1FFFFF) & 0xE1FFFFFF) & 0x1FFFFFFF; - pmc->secure_scratch43 = ((u16)(sdram->mc_generalized_carveout3_cfg0) << 18 >> 29 << 29) | (((u16)(sdram->mc_generalized_carveout1_cfg0) << 21 >> 28 << 25) | ((16 * sdram->emc_cmd_mapping_cmd2_2 >> 28 << 21) | ((sdram->emc_cmd_mapping_cmd2_2 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd2_2 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd2_2 & 0x7F | (pmc->secure_scratch43 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xFE1FFFFF) & 0xE1FFFFFF) & 0x1FFFFFFF; - pmc->secure_scratch44 = (sdram->mc_video_protect_vpr_override << 24 >> 31 << 31) | (2 * ((sdram->mc_video_protect_vpr_override << 25 >> 31 << 30) | ((sdram->mc_video_protect_vpr_override << 28 >> 31 << 29) | ((sdram->mc_generalized_carveout1_cfg0 << 14 >> 28 << 25) | ((16 * sdram->emc_cmd_mapping_cmd3_2 >> 28 << 21) | ((sdram->emc_cmd_mapping_cmd3_2 << 9 >> 25 << 14) | ((sdram->emc_cmd_mapping_cmd3_2 << 17 >> 25 << 7) | (sdram->emc_cmd_mapping_cmd3_2 & 0x7F | (pmc->secure_scratch44 >> 7 << 7)) & 0xFFFFC07F) & 0xFFE03FFF) & 0xFE1FFFFF) & 0xE1FFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch45 = (sdram->mc_emem_adr_cfg_dev0 << 12 >> 28 << 28) | ((sdram->mc_emem_adr_cfg_dev0 << 22 >> 30 << 26) | ((sdram->mc_emem_adr_cfg_dev0 << 23) & 0x3FFFFFF | ((sdram->mc_emem_adr_cfg_channel_mask >> 9) | (pmc->secure_scratch45 >> 23 << 23)) & 0xFC7FFFFF) & 0xF3FFFFFF) & 0xFFFFFFF; - pmc->secure_scratch46 = (sdram->mc_video_protect_vpr_override << 23 >> 31 << 31) | (2 * ((sdram->mc_emem_adr_cfg_dev1 << 12 >> 28 << 27) | ((sdram->mc_emem_adr_cfg_dev1 << 22 >> 30 << 25) | ((sdram->mc_emem_adr_cfg_dev1 << 22) & 0x1FFFFFF | ((sdram->mc_emem_adr_cfg_bank_mask0 >> 10) | (pmc->secure_scratch46 >> 22 << 22)) & 0xFE3FFFFF) & 0xF9FFFFFF) & 0x87FFFFFF) >> 1); - pmc->secure_scratch47 = (sdram->mc_video_protect_vpr_override << 20 >> 31 << 31) | (2 * ((sdram->mc_video_protect_vpr_override << 22 >> 31 << 30) | (((u8)(sdram->mc_generalized_carveout3_cfg0) << 25 >> 28 << 26) | ((sdram->mc_generalized_carveout1_cfg0 << 10 >> 28 << 22) | ((sdram->mc_emem_adr_cfg_bank_mask1 >> 10) | (pmc->secure_scratch47 >> 22 << 22)) & 0xFC3FFFFF) & 0xC3FFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch48 = (sdram->mc_video_protect_vpr_override << 16 >> 31 << 31) | (2 * ((sdram->mc_video_protect_vpr_override << 17 >> 31 << 30) | ((sdram->mc_generalized_carveout3_cfg0 << 14 >> 28 << 26) | ((sdram->mc_generalized_carveout3_cfg0 << 21 >> 28 << 22) | ((sdram->mc_emem_adr_cfg_bank_mask2 >> 10) | (pmc->secure_scratch48 >> 22 << 22)) & 0xFC3FFFFF) & 0xC3FFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch49 = (sdram->mc_video_protect_vpr_override << 14 >> 31 << 31) | (2 * ((sdram->mc_emem_cfg >> 31 << 30) | ((sdram->mc_emem_cfg << 18 >> 2) | (sdram->mc_video_protect_gpu_override1 & 0xFFFF | (pmc->secure_scratch49 >> 16 << 16)) & 0xC000FFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch50 = (sdram->mc_video_protect_vpr_override << 12 >> 31 << 31) | (2 * ((sdram->mc_video_protect_vpr_override << 13 >> 31 << 30) | ((sdram->mc_generalized_carveout1_bom >> 17 << 15) | ((sdram->mc_generalized_carveout3_bom >> 17) | (pmc->secure_scratch50 >> 15 << 15)) & 0xC0007FFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch51 = (sdram->mc_video_protect_vpr_override << 10 >> 31 << 31) | (2 * ((sdram->mc_video_protect_vpr_override << 11 >> 31 << 30) | ((sdram->mc_generalized_carveout2_bom >> 17 << 15) | ((sdram->mc_generalized_carveout4_bom >> 17) | (pmc->secure_scratch51 >> 15 << 15)) & 0xC0007FFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch52 = (sdram->mc_video_protect_vpr_override << 9 >> 31 << 31) | (2 * ((sdram->mc_generalized_carveout3_cfg0 << 10 >> 28 << 27) | ((sdram->mc_video_protect_bom >> 20 << 15) | ((sdram->mc_generalized_carveout5_bom >> 17) | (pmc->secure_scratch52 >> 15 << 15)) & 0xF8007FFF) & 0x87FFFFFF) >> 1); - pmc->secure_scratch53 = (sdram->mc_video_protect_vpr_override1 << 27 >> 31 << 31) | (2 * ((sdram->mc_video_protect_vpr_override1 << 30 >> 31 << 30) | ((sdram->mc_video_protect_vpr_override1 << 31 >> 2) | ((sdram->mc_video_protect_vpr_override >> 31 << 28) | ((2 * sdram->mc_video_protect_vpr_override >> 31 << 27) | ((4 * sdram->mc_video_protect_vpr_override >> 31 << 26) | ((32 * sdram->mc_video_protect_vpr_override >> 31 << 25) | ((sdram->mc_video_protect_vpr_override << 8 >> 31 << 24) | ((sdram->mc_sec_carveout_bom >> 20 << 12) | (sdram->mc_video_protect_size_mb & 0xFFF | (pmc->secure_scratch53 >> 12 << 12)) & 0xFF000FFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch54 = (sdram->mc_video_protect_vpr_override1 << 19 >> 31 << 31) | (2 * ((sdram->mc_video_protect_vpr_override1 << 20 >> 31 << 30) | ((sdram->mc_video_protect_vpr_override1 << 21 >> 31 << 29) | ((sdram->mc_video_protect_vpr_override1 << 22 >> 31 << 28) | ((sdram->mc_video_protect_vpr_override1 << 23 >> 31 << 27) | ((sdram->mc_video_protect_vpr_override1 << 24 >> 31 << 26) | ((sdram->mc_video_protect_vpr_override1 << 25 >> 31 << 25) | ((sdram->mc_video_protect_vpr_override1 << 26 >> 31 << 24) | ((sdram->mc_mts_carveout_bom >> 20 << 12) | (sdram->mc_sec_carveout_size_mb & 0xFFF | (pmc->secure_scratch54 >> 12 << 12)) & 0xFF000FFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch55 = (sdram->mc_generalized_carveout2_cfg0 << 30 >> 31 << 31) | (2 * ((sdram->mc_generalized_carveout2_cfg0 << 30) | ((32 * sdram->mc_video_protect_vpr_override1 >> 31 << 29) | ((sdram->mc_video_protect_vpr_override1 << 6 >> 31 << 28) | ((sdram->mc_video_protect_vpr_override1 << 15 >> 31 << 27) | ((sdram->mc_video_protect_vpr_override1 << 16 >> 31 << 26) | ((sdram->mc_video_protect_vpr_override1 << 17 >> 31 << 25) | ((sdram->mc_video_protect_vpr_override1 << 18 >> 31 << 24) | (((u16)(sdram->mc_generalized_carveout4_size_128kb) << 12) & 0xFFFFFF | (sdram->mc_mts_carveout_size_mb & 0xFFF | (pmc->secure_scratch55 >> 12 << 12)) & 0xFF000FFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch56 = ((u16)(sdram->mc_generalized_carveout1_cfg0) << 30 >> 31 << 31) | (2 * (((u16)(sdram->mc_generalized_carveout1_cfg0) << 30) | ((32 * sdram->mc_generalized_carveout2_cfg0 >> 31 << 29) | ((sdram->mc_generalized_carveout2_cfg0 << 6 >> 31 << 28) | ((sdram->mc_generalized_carveout2_cfg0 << 7 >> 31 << 27) | ((sdram->mc_generalized_carveout2_cfg0 << 8 >> 31 << 26) | ((sdram->mc_generalized_carveout2_cfg0 << 9 >> 31 << 25) | ((sdram->mc_generalized_carveout2_cfg0 << 29 >> 31 << 24) | (((u16)(sdram->mc_generalized_carveout2_size_128kb) << 12) & 0xFFFFFF | (sdram->mc_generalized_carveout3_size_128kb & 0xFFF | (pmc->secure_scratch56 >> 12 << 12)) & 0xFF000FFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); - pmc->secure_scratch57 = ((u8)(sdram->mc_generalized_carveout3_cfg0) << 30 >> 31 << 31) | (2 * (((u8)(sdram->mc_generalized_carveout3_cfg0) << 30) | ((32 * sdram->mc_generalized_carveout1_cfg0 >> 31 << 29) | ((sdram->mc_generalized_carveout1_cfg0 << 6 >> 31 << 28) | ((sdram->mc_generalized_carveout1_cfg0 << 7 >> 31 << 27) | ((sdram->mc_generalized_carveout1_cfg0 << 8 >> 31 << 26) | ((sdram->mc_generalized_carveout1_cfg0 << 9 >> 31 << 25) | ((sdram->mc_generalized_carveout1_cfg0 << 29 >> 31 << 24) | ((sdram->mc_generalized_carveout5_size_128kb << 12) & 0xFFFFFF | (sdram->mc_generalized_carveout1_size_128kb & 0xFFF | (pmc->secure_scratch57 >> 12 << 12)) & 0xFF000FFF) & 0xFEFFFFFF) & 0xFDFFFFFF) & 0xFBFFFFFF) & 0xF7FFFFFF) & 0xEFFFFFFF) & 0xDFFFFFFF) & 0xBFFFFFFF) >> 1); + s(emc_cmd_mapping_cmd0_0, 6:0, secure_scratch13, 6:0); + s(emc_cmd_mapping_cmd0_0, 14:8, secure_scratch13, 13:7); + s(emc_cmd_mapping_cmd0_0, 22:16, secure_scratch13, 20:14); + s(emc_cmd_mapping_cmd0_0, 30:24, secure_scratch13, 27:21); + s(mc_untranslated_region_check, 0:0, secure_scratch13, 28:28); + s(mc_untranslated_region_check, 9:8, secure_scratch13, 30:29); + s(emc_adr_cfg, 0:0, secure_scratch13, 31:31); + s(emc_cmd_mapping_cmd0_1, 6:0, secure_scratch14, 6:0); + s(emc_cmd_mapping_cmd0_1, 14:8, secure_scratch14, 13:7); + s(emc_cmd_mapping_cmd0_1, 22:16, secure_scratch14, 20:14); + s(emc_cmd_mapping_cmd0_1, 30:24, secure_scratch14, 27:21); + s(mc_video_protect_bom_adr_hi, 1:0, secure_scratch14, 29:28); + s(mc_video_protect_write_access, 1:0, secure_scratch14, 31:30); + s(emc_cmd_mapping_cmd1_0, 6:0, secure_scratch15, 6:0); + s(emc_cmd_mapping_cmd1_0, 14:8, secure_scratch15, 13:7); + s(emc_cmd_mapping_cmd1_0, 22:16, secure_scratch15, 20:14); + s(emc_cmd_mapping_cmd1_0, 30:24, secure_scratch15, 27:21); + s(mc_sec_carveout_adr_hi, 1:0, secure_scratch15, 29:28); + s(mc_mts_carveout_adr_hi, 1:0, secure_scratch15, 31:30); + s(emc_cmd_mapping_cmd1_1, 6:0, secure_scratch16, 6:0); + s(emc_cmd_mapping_cmd1_1, 14:8, secure_scratch16, 13:7); + s(emc_cmd_mapping_cmd1_1, 22:16, secure_scratch16, 20:14); + s(emc_cmd_mapping_cmd1_1, 30:24, secure_scratch16, 27:21); + s(mc_generalized_carveout5_bom_hi, 1:0, secure_scratch16, 29:28); + s(mc_generalized_carveout3_bom_hi, 1:0, secure_scratch16, 31:30); + s(emc_cmd_mapping_cmd2_0, 6:0, secure_scratch17, 6:0); + s(emc_cmd_mapping_cmd2_0, 14:8, secure_scratch17, 13:7); + s(emc_cmd_mapping_cmd2_0, 22:16, secure_scratch17, 20:14); + s(emc_cmd_mapping_cmd2_0, 30:24, secure_scratch17, 27:21); + s(mc_generalized_carveout2_bom_hi, 1:0, secure_scratch17, 29:28); + s(mc_generalized_carveout4_bom_hi, 1:0, secure_scratch17, 31:30); + s(emc_cmd_mapping_cmd2_1, 6:0, secure_scratch18, 6:0); + s(emc_cmd_mapping_cmd2_1, 14:8, secure_scratch18, 13:7); + s(emc_cmd_mapping_cmd2_1, 22:16, secure_scratch18, 20:14); + s(emc_cmd_mapping_cmd2_1, 30:24, secure_scratch18, 27:21); + s(mc_generalized_carveout1_bom_hi, 1:0, secure_scratch18, 29:28); + s(emc_fbio_spare, 1:1, secure_scratch18, 30:30); + s(emc_fbio_cfg8, 15:15, secure_scratch18, 31:31); + s(emc_cmd_mapping_cmd3_0, 6:0, secure_scratch19, 6:0); + s(emc_cmd_mapping_cmd3_0, 14:8, secure_scratch19, 13:7); + s(emc_cmd_mapping_cmd3_0, 22:16, secure_scratch19, 20:14); + s(emc_cmd_mapping_cmd3_0, 30:24, secure_scratch19, 27:21); + s(mc_emem_adr_cfg, 0:0, secure_scratch19, 28:28); + s(mc_sec_carveout_protect_write_access, 0:0, secure_scratch19, 29:29); + s(mc_mts_carveout_reg_ctrl, 0:0, secure_scratch19, 30:30); + s(mc_video_protect_vpr_override, 0:0, secure_scratch19, 31:31); + s(emc_cmd_mapping_cmd3_1, 6:0, secure_scratch20, 6:0); + s(emc_cmd_mapping_cmd3_1, 14:8, secure_scratch20, 13:7); + s(emc_cmd_mapping_cmd3_1, 22:16, secure_scratch20, 20:14); + s(emc_cmd_mapping_cmd3_1, 30:24, secure_scratch20, 27:21); + s(mc_generalized_carveout2_cfg0, 6:3, secure_scratch20, 31:28); + s(mc_generalized_carveout4_cfg0, 26:0, secure_scratch39, 26:0); + s(mc_generalized_carveout2_cfg0, 10:7, secure_scratch39, 30:27); + s(mc_video_protect_vpr_override, 1:1, secure_scratch39, 31:31); + s(mc_generalized_carveout5_cfg0, 26:0, secure_scratch40, 26:0); + s(mc_generalized_carveout2_cfg0, 17:14, secure_scratch40, 30:27); + s(mc_video_protect_vpr_override, 2:2, secure_scratch40, 31:31); + s(emc_cmd_mapping_cmd0_2, 6:0, secure_scratch41, 6:0); + s(emc_cmd_mapping_cmd0_2, 14:8, secure_scratch41, 13:7); + s(emc_cmd_mapping_cmd0_2, 22:16, secure_scratch41, 20:14); + s(emc_cmd_mapping_cmd0_2, 27:24, secure_scratch41, 24:21); + s(mc_generalized_carveout2_cfg0, 21:18, secure_scratch41, 28:25); + s(mc_generalized_carveout2_cfg0, 13:11, secure_scratch41, 31:29); + s(emc_cmd_mapping_cmd1_2, 6:0, secure_scratch42, 6:0); + s(emc_cmd_mapping_cmd1_2, 14:8, secure_scratch42, 13:7); + s(emc_cmd_mapping_cmd1_2, 22:16, secure_scratch42, 20:14); + s(emc_cmd_mapping_cmd1_2, 27:24, secure_scratch42, 24:21); + s(mc_generalized_carveout1_cfg0, 6:3, secure_scratch42, 28:25); + s(mc_generalized_carveout1_cfg0, 13:11, secure_scratch42, 31:29); + s(emc_cmd_mapping_cmd2_2, 6:0, secure_scratch43, 6:0); + s(emc_cmd_mapping_cmd2_2, 14:8, secure_scratch43, 13:7); + s(emc_cmd_mapping_cmd2_2, 22:16, secure_scratch43, 20:14); + s(emc_cmd_mapping_cmd2_2, 27:24, secure_scratch43, 24:21); + s(mc_generalized_carveout1_cfg0, 10:7, secure_scratch43, 28:25); + s(mc_generalized_carveout3_cfg0, 13:11, secure_scratch43, 31:29); + s(emc_cmd_mapping_cmd3_2, 6:0, secure_scratch44, 6:0); + s(emc_cmd_mapping_cmd3_2, 14:8, secure_scratch44, 13:7); + s(emc_cmd_mapping_cmd3_2, 22:16, secure_scratch44, 20:14); + s(emc_cmd_mapping_cmd3_2, 27:24, secure_scratch44, 24:21); + s(mc_generalized_carveout1_cfg0, 17:14, secure_scratch44, 28:25); + s(mc_video_protect_vpr_override, 3:3, secure_scratch44, 29:29); + s(mc_video_protect_vpr_override, 7:6, secure_scratch44, 31:30); + s(mc_emem_adr_cfg_channel_mask, 31:9, secure_scratch45, 22:0); + s(mc_emem_adr_cfg_dev0, 2:0, secure_scratch45, 25:23); + s(mc_emem_adr_cfg_dev0, 9:8, secure_scratch45, 27:26); + s(mc_emem_adr_cfg_dev0, 19:16, secure_scratch45, 31:28); + s(mc_emem_adr_cfg_bank_mask0, 31:10, secure_scratch46, 21:0); + s(mc_emem_adr_cfg_dev1, 2:0, secure_scratch46, 24:22); + s(mc_emem_adr_cfg_dev1, 9:8, secure_scratch46, 26:25); + s(mc_emem_adr_cfg_dev1, 19:16, secure_scratch46, 30:27); + s(mc_video_protect_vpr_override, 8:8, secure_scratch46, 31:31); + s(mc_emem_adr_cfg_bank_mask1, 31:10, secure_scratch47, 21:0); + s(mc_generalized_carveout1_cfg0, 21:18, secure_scratch47, 25:22); + s(mc_generalized_carveout3_cfg0, 6:3, secure_scratch47, 29:26); + s(mc_video_protect_vpr_override, 9:9, secure_scratch47, 30:30); + s(mc_video_protect_vpr_override, 11:11, secure_scratch47, 31:31); + s(mc_emem_adr_cfg_bank_mask2, 31:10, secure_scratch48, 21:0); + s(mc_generalized_carveout3_cfg0, 10:7, secure_scratch48, 25:22); + s(mc_generalized_carveout3_cfg0, 17:14, secure_scratch48, 29:26); + s(mc_video_protect_vpr_override, 15:14, secure_scratch48, 31:30); + s(mc_video_protect_gpu_override1, 15:0, secure_scratch49, 15:0); + s(mc_emem_cfg, 13:0, secure_scratch49, 29:16); + s(mc_emem_cfg, 31:31, secure_scratch49, 30:30); + s(mc_video_protect_vpr_override, 17:17, secure_scratch49, 31:31); + s(mc_generalized_carveout3_bom, 31:17, secure_scratch50, 14:0); + s(mc_generalized_carveout1_bom, 31:17, secure_scratch50, 29:15); + s(mc_video_protect_vpr_override, 19:18, secure_scratch50, 31:30); + s(mc_generalized_carveout4_bom, 31:17, secure_scratch51, 14:0); + s(mc_generalized_carveout2_bom, 31:17, secure_scratch51, 29:15); + s(mc_video_protect_vpr_override, 21:20, secure_scratch51, 31:30); + s(mc_generalized_carveout5_bom, 31:17, secure_scratch52, 14:0); + s(mc_video_protect_bom, 31:20, secure_scratch52, 26:15); + s(mc_generalized_carveout3_cfg0, 21:18, secure_scratch52, 30:27); + s(mc_video_protect_vpr_override, 22:22, secure_scratch52, 31:31); + s(mc_video_protect_size_mb, 11:0, secure_scratch53, 11:0); + s(mc_sec_carveout_bom, 31:20, secure_scratch53, 23:12); + s(mc_video_protect_vpr_override, 23:23, secure_scratch53, 24:24); + s(mc_video_protect_vpr_override, 26:26, secure_scratch53, 25:25); + s(mc_video_protect_vpr_override, 31:29, secure_scratch53, 28:26); + s(mc_video_protect_vpr_override1, 1:0, secure_scratch53, 30:29); + s(mc_video_protect_vpr_override1, 4:4, secure_scratch53, 31:31); + s(mc_sec_carveout_size_mb, 11:0, secure_scratch54, 11:0); + s(mc_mts_carveout_bom, 31:20, secure_scratch54, 23:12); + s(mc_video_protect_vpr_override1, 12:5, secure_scratch54, 31:24); + s(mc_mts_carveout_size_mb, 11:0, secure_scratch55, 11:0); + s(mc_generalized_carveout4_size_128kb, 11:0, secure_scratch55, 23:12); + s(mc_video_protect_vpr_override1, 16:13, secure_scratch55, 27:24); + s(mc_video_protect_vpr_override1, 26:25, secure_scratch55, 29:28); + s(mc_generalized_carveout2_cfg0, 1:0, secure_scratch55, 31:30); + s(mc_generalized_carveout3_size_128kb, 11:0, secure_scratch56, 11:0); + s(mc_generalized_carveout2_size_128kb, 11:0, secure_scratch56, 23:12); + s(mc_generalized_carveout2_cfg0, 2:2, secure_scratch56, 24:24); + s(mc_generalized_carveout2_cfg0, 26:22, secure_scratch56, 29:25); + s(mc_generalized_carveout1_cfg0, 1:0, secure_scratch56, 31:30); + s(mc_generalized_carveout1_size_128kb, 11:0, secure_scratch57, 11:0); + s(mc_generalized_carveout5_size_128kb, 11:0, secure_scratch57, 23:12); + s(mc_generalized_carveout1_cfg0, 2:2, secure_scratch57, 24:24); + s(mc_generalized_carveout1_cfg0, 26:22, secure_scratch57, 29:25); + s(mc_generalized_carveout3_cfg0, 1:0, secure_scratch57, 31:30); + s(mc_generalized_carveout3_cfg0, 2:2, secure_scratch58, 0:0); + s(mc_generalized_carveout3_cfg0, 26:22, secure_scratch58, 5:1); s32(mc_generalized_carveout1_access0, secure_scratch59); s32(mc_generalized_carveout1_access1, secure_scratch60); @@ -1468,17 +2074,34 @@ static void _sdram_lp0_save_params_t210b01(const void *params) s32(mc_generalized_carveout5_force_internal_access2, secure_scratch106); s32(mc_generalized_carveout5_force_internal_access3, secure_scratch107); - pmc->secure_scratch58 = 32 * (32 * sdram->mc_generalized_carveout3_cfg0 >> 31) | (16 * (sdram->mc_generalized_carveout3_cfg0 << 6 >> 31) | (8 * (sdram->mc_generalized_carveout3_cfg0 << 7 >> 31) | (4 * (sdram->mc_generalized_carveout3_cfg0 << 8 >> 31) | (2 * (sdram->mc_generalized_carveout3_cfg0 << 9 >> 31) | ((sdram->mc_generalized_carveout3_cfg0 << 29 >> 31) | 2 * (pmc->secure_scratch58 >> 1)) & 0xFFFFFFFD) & 0xFFFFFFFB) & 0xFFFFFFF7) & 0xFFFFFFEF) & 0xFFFFFFDF; - pmc->scratch2 = (sdram->pllm_feedback_divider << 8) | ((u16)(sdram->pllm_post_divider) << 16) | sdram->pllm_input_divider | ((u16)(sdram->pllm_kvco) << 17) | ((u16)(sdram->pllm_kcp) << 18); - pmc->scratch35 = sdram->pllm_setup_control; - pmc->scratch3 = sdram->pllm_input_divider | ((u16)(sdram->pllm_kvco) << 21) | ((u16)(sdram->pllm_kcp) << 22) | 0x3E00; - pmc->scratch36 = sdram->pllm_setup_control; - pmc->scratch4 = (sdram->pllm_stable_time << 10) | sdram->pllm_stable_time; + // PLLM. Unused, BCT is used for PLLM. + c32(0, scratch2); + s(pllm_input_divider, 7:0, scratch2, 7:0); + s(pllm_feedback_divider, 7:0, scratch2, 15:8); + s(pllm_post_divider, 0:0, scratch2, 16:16); + s(pllm_kvco, 0:0, scratch2, 17:17); + s(pllm_kcp, 1:0, scratch2, 19:18); + + c32(0, scratch35); + s(pllm_setup_control, 27:0, scratch35, 27:0); + + // PLLX. + s(pllm_input_divider, 7:0, scratch3, 7:0); + c(62, scratch3, 15:8); // 62 divn. + c(0, scratch3, 20:16); // 0 divp. + s(pllm_kvco, 0:0, scratch3, 21:21); + s(pllm_kcp, 1:0, scratch3, 23:22); + // s(pllm_kcp, 9:0, scratch3, 31:22); + + c32(0, scratch36); + s(pllm_setup_control, 23:0, scratch36, 23:0); + + // PLLM/PLLX. + s(pllm_stable_time, 9:0, scratch4, 9:0); + s(pllm_stable_time, 9:0, scratch4, 19:10); } -#pragma GCC diagnostic pop - -void sdram_lp0_entry(void *sdram_config, bdkParams_t bp) +void sdram_lp0_entry(void *sdram_config, bdk_params_t *bp) { u32 chip_id = (APB_MISC(APB_MISC_GP_HIDREV) >> 4) & 0xF; diff --git a/modules/hekate_libsys_minerva/Makefile b/modules/hekate_libsys_minerva/Makefile index 4c5de590..e50bc364 100644 --- a/modules/hekate_libsys_minerva/Makefile +++ b/modules/hekate_libsys_minerva/Makefile @@ -20,7 +20,7 @@ OBJS = $(addprefix $(BUILDDIR)/,\ ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork CFLAGS = $(ARCH) -O2 -nostdlib -fpie -ffunction-sections -fdata-sections -fomit-frame-pointer -std=gnu11 -Wall -Wsign-compare $(CUSTOMDEFINES) -LDFLAGS = $(ARCH) -fpie -pie -nostartfiles -lgcc +LDFLAGS = $(ARCH) -fpie -pie -nostartfiles -lgcc -Wl,-z,max-page-size=256 .PHONY: all diff --git a/modules/hekate_libsys_minerva/sys_sdrammtc.c b/modules/hekate_libsys_minerva/sys_sdrammtc.c index ba3925b1..f535b0de 100644 --- a/modules/hekate_libsys_minerva/sys_sdrammtc.c +++ b/modules/hekate_libsys_minerva/sys_sdrammtc.c @@ -25,7 +25,7 @@ #include "types.h" #include -#define DVFS_T21X_CC_VERSION "Minerva Training Cell v0.1_T21X" +#define DVFS_T21X_CC_VERSION "Minerva Training Cell v0.2_T21X" #define DVFS_T210_CC_VERSION "Minerva Training Cell v1.6_T210" #define EPRINTF(...) @@ -3758,7 +3758,7 @@ static int _minerva_set_ir_boost(mtc_config_t *mtc_cfg) MC(MC_EMEM_ARB_TIMING_FAW) = 4; MC(MC_EMEM_ARB_TIMING_RFCPB) = 0xE; MC(MC_EMEM_ARB_DA_COVERS) = 0x30203; - MC(MC_EMEM_ARB_MISC0) = 0x73C30507; + MC(MC_EMEM_ARB_MISC0) = 0x71E30507; // Program base timings. EMC(EMC_RP) = 8; @@ -4012,7 +4012,7 @@ error: return; } -void minerva_entry(mtc_config_t *mtc_cfg, bdkParams_t bp) +void minerva_entry(mtc_config_t *mtc_cfg, bdk_params_t *bp) { EPRINTF("-- Minerva Training Cell --"); diff --git a/modules/simple_sample/Makefile b/modules/simple_sample/Makefile index 2e090dba..75ea4698 100644 --- a/modules/simple_sample/Makefile +++ b/modules/simple_sample/Makefile @@ -27,7 +27,7 @@ CUSTOMDEFINES := -DGFX_INC=$(GFX_INC) ARCH := -march=armv4t -mtune=arm7tdmi -mthumb-interwork CFLAGS = $(ARCH) -O2 -nostdlib -fpie -ffunction-sections -fdata-sections -fomit-frame-pointer -std=gnu11 -Wall -Wsign-compare $(CUSTOMDEFINES) -LDFLAGS = $(ARCH) -fpie -pie -nostartfiles -lgcc +LDFLAGS = $(ARCH) -fpie -pie -nostartfiles -lgcc -Wl,-z,max-page-size=256 .PHONY: clean all diff --git a/modules/simple_sample/module_sample.c b/modules/simple_sample/module_sample.c index d2bbfed8..3cc8d39c 100644 --- a/modules/simple_sample/module_sample.c +++ b/modules/simple_sample/module_sample.c @@ -6,13 +6,13 @@ #include #include -void mod_entry(void *moduleConfig, bdkParams_t bp) +void mod_entry(void *moduleConfig, bdk_params_t *bp) { - memcpy(&gfx_con, bp->gfxCon, sizeof(gfx_con_t)); - memcpy(&gfx_ctxt, bp->gfxCtx, sizeof(gfx_ctxt_t)); + memcpy(&gfx_con, bp->gfx_con, sizeof(gfx_con_t)); + memcpy(&gfx_ctxt, bp->gfx_ctx, sizeof(gfx_ctxt_t)); gfx_puts("Hello World!"); - memcpy(bp->gfxCon, &gfx_con, sizeof(gfx_con_t)); - memcpy(bp->gfxCtx, &gfx_ctxt, sizeof(gfx_ctxt_t)); + memcpy(bp->gfx_con, &gfx_con, sizeof(gfx_con_t)); + memcpy(bp->gfx_ctx, &gfx_ctxt, sizeof(gfx_ctxt_t)); } diff --git a/nyx/Makefile b/nyx/Makefile index 24c75b3e..e7b3fa9b 100644 --- a/nyx/Makefile +++ b/nyx/Makefile @@ -73,7 +73,7 @@ CUSTOMDEFINES := -DNYX_LOAD_ADDR=$(NYX_LOAD_ADDR) -DNYX_MAGIC=$(NYX_MAGIC) CUSTOMDEFINES += -DNYX_VER_MJ=$(NYXVERSION_MAJOR) -DNYX_VER_MN=$(NYXVERSION_MINOR) -DNYX_VER_HF=$(NYXVERSION_HOTFX) -DNYX_VER_RL=$(NYXVERSION_REL) # BDK defines. -CUSTOMDEFINES += -DBDK_MC_ENABLE_AHB_REDIRECT -DBDK_MINERVA_CFG_FROM_RAM -DBDK_HW_EXTRA_DEINIT -DBDK_SDMMC_EXTRA_PRINT +CUSTOMDEFINES += -DBDK_MINERVA_CFG_FROM_RAM -DBDK_HW_EXTRA_DEINIT -DBDK_SDMMC_EXTRA_PRINT CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC) #CUSTOMDEFINES += -DDEBUG diff --git a/nyx/nyx_gui/config.c b/nyx/nyx_gui/config.c index 3474350b..e5fc541c 100644 --- a/nyx/nyx_gui/config.c +++ b/nyx/nyx_gui/config.c @@ -65,12 +65,12 @@ int create_config_entry() { char lbuf[64]; FIL fp; - bool mainIniFound = false; + bool ini_found = false; LIST_INIT(ini_sections); - if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) - mainIniFound = true; + if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) + ini_found = true; else { u8 res = f_open(&fp, "bootloader/hekate_ipl.ini", FA_READ); @@ -137,7 +137,7 @@ int create_config_entry() f_puts("\n", &fp); - if (mainIniFound) + if (ini_found) { // Re-construct existing entries. LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) @@ -188,7 +188,7 @@ int create_nyx_config_entry(bool force_unmount) { bool sd_mounted = sd_get_card_mounted(); - if (!sd_mount()) + if (sd_mount()) return 1; char lbuf[64]; diff --git a/nyx/nyx_gui/config.h b/nyx/nyx_gui/config.h index 8f846f19..d37e38ec 100644 --- a/nyx/nyx_gui/config.h +++ b/nyx/nyx_gui/config.h @@ -45,7 +45,7 @@ typedef struct _hekate_config typedef struct _nyx_config { - u32 theme_bg; + u32 theme_bg; // COLOR_BG_BASE_MIN - COLOR_BG_BASE_MAX. u32 theme_color; u32 entries_5_col; u32 timeoffset; diff --git a/nyx/nyx_gui/frontend/fe_emmc_tools.c b/nyx/nyx_gui/frontend/fe_emmc_tools.c index 98ed370a..7685598d 100644 --- a/nyx/nyx_gui/frontend/fe_emmc_tools.c +++ b/nyx/nyx_gui/frontend/fe_emmc_tools.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018 naehrwert * Copyright (c) 2018 Rajko Stojadinovic - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -122,7 +122,7 @@ static lv_obj_t *create_mbox_text(const char *text, bool button_ok) lv_mbox_set_text(mbox, text); if (button_ok) - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -211,7 +211,7 @@ static int _emmc_sd_copy_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage, // Full provides all that, plus protection from extremely rare I/O corruption. if ((n_cfg.verification >= 2) || !(sparseShouldVerify % 4)) { - if (!sdmmc_storage_read(storage, lba_curr, num, bufEm)) + if (sdmmc_storage_read(storage, lba_curr, num, bufEm)) { s_printf(gui->txt_buf, "\n#FF0000 Failed to read %d blocks (@LBA %08X),#\n" @@ -380,7 +380,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } sd_sector_off = sector_start + (0x2000 * active_part); if (active_part == 2) @@ -424,7 +424,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } } // Check if we are continuing a previous raw eMMC or USER partition backup in progress. @@ -447,7 +447,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } // Increase maxSplitParts to accommodate previously backed up parts. @@ -485,7 +485,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, if (!(btn_wait() & BTN_POWER)) { lv_obj_del(warn_mbox_bg); - return 0; + return 1; } lv_obj_del(warn_mbox_bg); } @@ -502,7 +502,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } u8 *buf = (u8 *)MIXD_BUF_ALIGNED; @@ -553,7 +553,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, strcpy(gui->txt_buf, "\n#FFDD00 Please try again...#\n"); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; case VERIF_STATUS_ABORT: verification = 0; break; @@ -580,7 +580,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } // More parts to backup that do not currently fit the sd card free space or fatal error. @@ -596,7 +596,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, partial_sd_full_unmount = true; - return 1; + return 0; } } @@ -615,7 +615,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } bytesWritten = 0; @@ -629,9 +629,9 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, int res_read; if (!gui->raw_emummc) - res_read = !sdmmc_storage_read(storage, lba_curr, num, buf); + res_read = sdmmc_storage_read(storage, lba_curr, num, buf); else - res_read = !sdmmc_storage_read(&sd_storage, lba_curr + sd_sector_off, num, buf); + res_read = sdmmc_storage_read(&sd_storage, lba_curr + sd_sector_off, num, buf); while (res_read) { @@ -663,7 +663,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, free(clmt); f_unlink(outFilename); - return 0; + return 1; } else { @@ -671,8 +671,13 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); } + + if (!gui->raw_emummc) + res_read = sdmmc_storage_read(storage, lba_curr, num, buf); + else + res_read = sdmmc_storage_read(&sd_storage, lba_curr + sd_sector_off, num, buf); + manual_system_maintenance(false); } - manual_system_maintenance(false); res = f_write_fast(&fp, buf, EMMC_BLOCKSIZE * num); @@ -686,7 +691,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, free(clmt); f_unlink(outFilename); - return 0; + return 1; } manual_system_maintenance(false); @@ -725,7 +730,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, free(clmt); f_unlink(outFilename); - return 0; + return 1; } } lv_bar_set_value(gui->bar, 100); @@ -745,7 +750,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } lv_bar_set_value(gui->bar, 100); lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); @@ -764,12 +769,12 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part, partial_sd_full_unmount = true; } - return 1; + return 0; } void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) { - int res = 0; + int res = 1; u32 timer = 0; char *txt_buf = (char *)malloc(SZ_16K); @@ -781,7 +786,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) lv_label_set_text(gui->label_info, "Checking for available free space..."); manual_system_maintenance(true); - if (!sd_mount()) + if (sd_mount()) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init SD!#"); goto out; @@ -790,7 +795,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) // Get SD Card free space for Partial Backup. f_getfree("", &sd_fs.free_clst, NULL); - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); goto out; @@ -844,7 +849,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) res = _dump_emmc_part(gui, sdPath, i, &emmc_storage, &bootPart); - if (!res) + if (res) strcpy(txt_buf, "#FFDD00 Failed!#\n"); else strcpy(txt_buf, "Done!\n"); @@ -884,7 +889,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) emmcsn_path_impl(sdPath, "/partitions", part->name, &emmc_storage); res = _dump_emmc_part(gui, sdPath, 0, &emmc_storage, part); // If a part failed, don't continue. - if (!res) + if (res) { strcpy(txt_buf, "#FFDD00 Failed!#\n"); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); @@ -927,7 +932,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) res = _dump_emmc_part(gui, sdPath, 2, &emmc_storage, &rawPart); - if (!res) + if (res) strcpy(txt_buf, "#FFDD00 Failed!#\n"); else strcpy(txt_buf, "Done!\n"); @@ -941,9 +946,9 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui) timer = get_tmr_s() - timer; emmc_end(); - if (res && n_cfg.verification && !gui->raw_emummc) + if (!res && n_cfg.verification && !gui->raw_emummc) s_printf(txt_buf, "Time taken: %dm %ds.\n#96FF00 Finished and verified!#", timer / 60, timer % 60); - else if (res) + else if (!res) s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); else s_printf(txt_buf, "Time taken: %dm %ds.", timer / 60, timer % 60); @@ -1027,13 +1032,13 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } else if (f_stat(outFilename, &fno)) { if (!gui->raw_emummc) { - s_printf(gui->txt_buf, "\n#FFDD00 Error (%d) file not found#\n#FFDD00 %s.#\n\n", res, outFilename); + s_printf(gui->txt_buf, "\n#FFDD00 Error file not found#\n#FFDD00 %s.#\n\n", outFilename); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); @@ -1056,7 +1061,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } } else @@ -1069,7 +1074,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } check_4MB_aligned = false; @@ -1097,7 +1102,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } lv_obj_del(warn_mbox_bg); @@ -1143,7 +1148,7 @@ multipart_not_allowed: manual_system_maintenance(true); } - return -1; + return 2; } else if (!use_multipart && (((u32)((u64)f_size(&fp) >> (u64)9)) != totalSectors)) // Check total restore size vs emmc size. { @@ -1155,7 +1160,7 @@ multipart_not_allowed: f_close(&fp); - return 0; + return 1; } else if (!gui->raw_emummc) { @@ -1174,7 +1179,7 @@ multipart_not_allowed: f_close(&fp); - return 0; + return 1; } lv_obj_del(warn_mbox_bg); } @@ -1216,7 +1221,7 @@ multipart_not_allowed: lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } sd_sector_off = sector_start + (0x2000 * active_part); } @@ -1246,7 +1251,7 @@ multipart_not_allowed: strcpy(gui->txt_buf, "\n#FFDD00 Please try again...#\n"); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; case VERIF_STATUS_ABORT: verification = 0; break; @@ -1275,7 +1280,7 @@ multipart_not_allowed: lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } fileSize = (u64)f_size(&fp); bytesWritten = 0; @@ -1299,12 +1304,12 @@ multipart_not_allowed: f_close(&fp); free(clmt); - return 0; + return 1; } if (!gui->raw_emummc) - res = !sdmmc_storage_write(storage, lba_curr, num, buf); + res = sdmmc_storage_write(storage, lba_curr, num, buf); else - res = !sdmmc_storage_write(&sd_storage, lba_curr + sd_sector_off, num, buf); + res = sdmmc_storage_write(&sd_storage, lba_curr + sd_sector_off, num, buf); manual_system_maintenance(false); @@ -1328,7 +1333,7 @@ multipart_not_allowed: f_close(&fp); free(clmt); - return 0; + return 1; } else { @@ -1337,9 +1342,9 @@ multipart_not_allowed: manual_system_maintenance(true); } if (!gui->raw_emummc) - res = !sdmmc_storage_write(storage, lba_curr, num, buf); + res = sdmmc_storage_write(storage, lba_curr, num, buf); else - res = !sdmmc_storage_write(&sd_storage, lba_curr + sd_sector_off, num, buf); + res = sdmmc_storage_write(&sd_storage, lba_curr + sd_sector_off, num, buf); manual_system_maintenance(false); } pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(lba_end - part->lba_start); @@ -1373,7 +1378,7 @@ multipart_not_allowed: lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } lv_bar_set_value(gui->bar, 100); lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%"); @@ -1397,7 +1402,7 @@ multipart_not_allowed: save_emummc_cfg(part_idx, sector_start, sdPath); } - return 1; + return 0; } void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui) @@ -1457,13 +1462,13 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui) lv_obj_del(warn_mbox_bg); manual_system_maintenance(true); - if (!sd_mount()) + if (sd_mount()) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init SD!#"); goto out; } - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); goto out; @@ -1512,15 +1517,14 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui) emmcsn_path_impl(sdPath, "/restore/emummc", bootPart.name, &emmc_storage); res = _restore_emmc_part(gui, sdPath, i, &emmc_storage, &bootPart, false); - if (!res) + if (res == 1) strcpy(txt_buf, "#FFDD00 Failed!#\n"); - else if (res > 0) + else if (!res) strcpy(txt_buf, "Done!\n"); - if (res >= 0) + if (res <= 1) lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); - else - res = 0; + manual_system_maintenance(true); } } @@ -1548,15 +1552,14 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui) emmcsn_path_impl(sdPath, "/restore/partitions", part->name, &emmc_storage); res = _restore_emmc_part(gui, sdPath, 0, &emmc_storage, part, false); - if (!res) + if (res == 1) strcpy(txt_buf, "#FFDD00 Failed!#\n"); - else if (res > 0) + else if (!res) strcpy(txt_buf, "Done!\n"); - if (res >= 0) + if (res <= 1) lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); - else - res = 0; + manual_system_maintenance(true); } emmc_gpt_free(&gpt); @@ -1587,15 +1590,14 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui) emmcsn_path_impl(sdPath, "/restore/emummc", rawPart.name, &emmc_storage); res = _restore_emmc_part(gui, sdPath, 2, &emmc_storage, &rawPart, true); - if (!res) + if (res == 1) strcpy(txt_buf, "#FFDD00 Failed!#\n"); - else if (res > 0) + else if (!res) strcpy(txt_buf, "Done!\n"); - if (res >= 0) + if (res <= 1) lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); - else - res = 0; + manual_system_maintenance(true); } } @@ -1603,9 +1605,9 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui) timer = get_tmr_s() - timer; emmc_end(); - if (res && n_cfg.verification && !gui->raw_emummc) + if (!res && n_cfg.verification && !gui->raw_emummc) s_printf(txt_buf, "Time taken: %dm %ds.\n#96FF00 Finished and verified!#", timer / 60, timer % 60); - else if (res) + else if (!res) s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); else s_printf(txt_buf, "Time taken: %dm %ds.", timer / 60, timer % 60); diff --git a/nyx/nyx_gui/frontend/fe_emummc_tools.c b/nyx/nyx_gui/frontend/fe_emummc_tools.c index d44e724c..bd317459 100644 --- a/nyx/nyx_gui/frontend/fe_emummc_tools.c +++ b/nyx/nyx_gui/frontend/fe_emummc_tools.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018 naehrwert * Copyright (c) 2018 Rajko Stojadinovic - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -33,15 +33,13 @@ #define OUT_FILENAME_SZ 128 #define NUM_SECTORS_PER_ITER 8192 // 4MB Cache. -extern volatile boot_cfg_t *b_cfg; - void load_emummc_cfg(emummc_cfg_t *emu_info) { memset(emu_info, 0, sizeof(emummc_cfg_t)); // Parse emuMMC configuration. LIST_INIT(ini_sections); - if (!ini_parse(&ini_sections, "emuMMC/emummc.ini", false)) + if (ini_parse(&ini_sections, "emuMMC/emummc.ini", false)) return; LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) @@ -172,7 +170,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } // Check if filesystem is FAT32 or the free space is smaller and dump in parts. @@ -198,7 +196,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } u8 *buf = (u8 *)MIXD_BUF_ALIGNED; @@ -244,7 +242,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } bytesWritten = 0; @@ -266,13 +264,13 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto msleep(1000); - return 0; + return 1; } retryCount = 0; num = MIN(totalSectors, NUM_SECTORS_PER_ITER); - while (!sdmmc_storage_read(storage, lba_curr, num, buf)) + while (sdmmc_storage_read(storage, lba_curr, num, buf)) { s_printf(gui->txt_buf, "\n#FFDD00 Error reading %d blocks @ LBA %08X,#\n" @@ -292,7 +290,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto free(clmt); f_unlink(outFilename); - return 0; + return 1; } else { @@ -318,7 +316,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto free(clmt); f_unlink(outFilename); - return 0; + return 1; } pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); if (pct != prevPct) @@ -352,12 +350,12 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto f_close(&fp); free(clmt); - return 1; + return 0; } void dump_emummc_file(emmc_tool_gui_t *gui) { - int res = 0; + int res = 1; int base_len = 0; u32 timer = 0; @@ -370,7 +368,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui) manual_system_maintenance(true); - if (!sd_mount()) + if (sd_mount()) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init SD!#"); goto out; @@ -382,7 +380,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui) // Get SD Card free space for file based emuMMC. f_getfree("", &sd_fs.free_clst, NULL); - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); goto out; @@ -434,7 +432,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui) strcat(sdPath, bootPart.name); res = _dump_emummc_file_part(gui, sdPath, &emmc_storage, &bootPart); - if (!res) + if (res) { s_printf(txt_buf, "#FFDD00 Failed!#\n"); goto out_failed; @@ -469,7 +467,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui) res = _dump_emummc_file_part(gui, sdPath, &emmc_storage, &rawPart); - if (!res) + if (res) s_printf(txt_buf, "#FFDD00 Failed!#\n"); else s_printf(txt_buf, "Done!\n"); @@ -481,7 +479,7 @@ out_failed: timer = get_tmr_s() - timer; emmc_end(); - if (res) + if (!res) { s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); gui->base_path[strlen(gui->base_path) - 5] = '\0'; @@ -545,7 +543,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } user_offset = user_part->lba_start; @@ -559,20 +557,20 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part // Check for cancellation combo. if (btn_read_vol() == (BTN_VOL_UP | BTN_VOL_DOWN)) { - s_printf(gui->txt_buf, "\n#FFDD00 The emuMMC was cancelled!#\n"); + s_printf(gui->txt_buf, "\n#FFDD00 emuMMC creation was cancelled!#\n"); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); msleep(1000); - return 0; + return 1; } retryCount = 0; num = MIN(totalSectors, NUM_SECTORS_PER_ITER); // Read data from eMMC. - while (!sdmmc_storage_read(&emmc_storage, lba_curr, num, buf)) + while (sdmmc_storage_read(&emmc_storage, lba_curr, num, buf)) { s_printf(gui->txt_buf, "\n#FFDD00 Error reading %d blocks @LBA %08X,#\n" @@ -588,7 +586,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } else { @@ -602,7 +600,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part // Write data to SD card. retryCount = 0; - while (!sdmmc_storage_write(&sd_storage, sd_sector_off + lba_curr, num, buf)) + while (sdmmc_storage_write(&sd_storage, sd_sector_off + lba_curr, num, buf)) { s_printf(gui->txt_buf, "\n#FFDD00 Error writing %d blocks @LBA %08X,#\n" @@ -618,7 +616,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); manual_system_maintenance(true); - return 0; + return 1; } else { @@ -690,7 +688,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part s_printf(gui->txt_buf, "#FF0000 Failed (%d)!#\nPlease try again...\n", mkfs_error); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); - return 0; + return 1; } lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, "Done!\n"); @@ -722,7 +720,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf); free(gpt); - return 0; + return 1; } // Set new emuMMC size and USER size. @@ -763,16 +761,17 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part free(gpt); } - return 1; + return 0; } int emummc_raw_derive_bis_keys() { - // Generate BIS keys. - hos_bis_keygen(); - u8 *cal0_buff = malloc(SZ_64K); + // Generate BIS keys. + if (hos_bis_keygen()) + goto error; + // Read and decrypt CAL0 for validation of working BIS keys. emmc_set_partition(EMMC_GPP); LIST_INIT(gpt); @@ -788,6 +787,7 @@ int emummc_raw_derive_bis_keys() // Check keys validity. if (memcmp(&cal0->magic, "CAL0", 4)) { +error: // Clear EKS keys. hos_eks_clear(HOS_MKEY_VER_MAX); @@ -809,7 +809,7 @@ int emummc_raw_derive_bis_keys() lv_obj_set_width(lb_desc, LV_HOR_RES / 9 * 4); lv_label_set_text(lb_desc, "#FFDD00 BIS keys validation failed!#\n"); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -825,7 +825,7 @@ int emummc_raw_derive_bis_keys() void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 resized_count) { - int res = 0; + int res = 1; u32 timer = 0; char *txt_buf = (char *)malloc(SZ_16K); @@ -837,13 +837,13 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r manual_system_maintenance(true); - if (!sd_mount()) + if (sd_mount()) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init SD!#"); goto out; } - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#"); goto out; @@ -896,7 +896,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r strcat(sdPath, bootPart.name); res = _dump_emummc_raw_part(gui, i, part_idx, sector_start, &bootPart, 0); - if (!res) + if (res) { s_printf(txt_buf, "#FFDD00 Failed!#\n"); goto out_failed; @@ -930,7 +930,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r res = _dump_emummc_raw_part(gui, 2, part_idx, sector_start, &rawPart, resized_count); - if (!res) + if (res) s_printf(txt_buf, "#FFDD00 Failed!#\n"); else s_printf(txt_buf, "Done!\n"); @@ -943,7 +943,7 @@ out_failed: timer = get_tmr_s() - timer; emmc_end(); - if (res) + if (!res) { s_printf(txt_buf, "Time taken: %dm %ds.\nFinished!", timer / 60, timer % 60); strcpy(sdPath, gui->base_path); diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 2bb2b3e4..ba3056a4 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -53,7 +53,7 @@ lv_img_dsc_t *icon_lakka; lv_img_dsc_t *hekate_bg; lv_img_dsc_t *hekate_bg_etc; -lv_style_t btn_transp_rel, btn_transp_pr, btn_transp_tgl_rel, btn_transp_tgl_pr; +lv_style_t btn_transp_rel, btn_transp_pr, btn_transp_tgl_rel, btn_transp_tgl_pr, btn_transp_ina; lv_style_t ddlist_transp_bg, ddlist_transp_sel; lv_style_t tabview_btn_pr, tabview_btn_tgl_pr; @@ -105,6 +105,7 @@ static void _nyx_disp_init() // Rotate and copy the first frame. vic_compose(); + vic_wait_idle(); // Switch to new window configuration. display_init_window_a_pitch_vic(); @@ -328,19 +329,19 @@ static void _disp_fb_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_flush_ready(); } -static touch_event touchpad; +static touch_event_t touchpad; static bool touch_enabled; static bool console_enabled = false; static bool _fts_touch_read(lv_indev_data_t *data) { - if (touch_enabled) - touch_poll(&touchpad); - else + if (!touch_enabled) return false; - // Take a screenshot if 3 fingers. - if (touchpad.fingers > 2) + int res = touch_poll(&touchpad); + + // Take a screenshot if 3rd finger. + if (touchpad.finger > 2) { _save_fb_to_bmp(); @@ -350,14 +351,18 @@ static bool _fts_touch_read(lv_indev_data_t *data) if (console_enabled) { + // If no event, keep last debug message. + if (res) + return false; + // Print input debugging in console. gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy, &gfx_con.savedcol); gfx_con_setpos(32, 638, GFX_COL_AUTO); gfx_con.fntsz = 8; gfx_printf("x: %4d, y: %4d | z: %3d | ", touchpad.x, touchpad.y, touchpad.z); - gfx_printf("1: %02X, 2: %02X, 3: %02X, ", touchpad.raw[1], touchpad.raw[2], touchpad.raw[3]); - gfx_printf("4: %02X, 5: %02X, 6: %02X, 7: %02X", - touchpad.raw[4], touchpad.raw[5], touchpad.raw[6], touchpad.raw[7]); + gfx_printf("0: %02X, 1: %02X, 2: %02X, ", touchpad.raw[0], touchpad.raw[1], touchpad.raw[2]); + gfx_printf("3: %02X, 4: %02X, 5: %02X, 6: %02X", + touchpad.raw[3], touchpad.raw[4], touchpad.raw[5], touchpad.raw[6]); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy, gfx_con.savedcol); gfx_con.fntsz = 16; @@ -369,23 +374,10 @@ static bool _fts_touch_read(lv_indev_data_t *data) data->point.y = touchpad.y; // Decide touch enable. - switch (touchpad.type & STMFTS_MASK_EVENT_ID) - { - case STMFTS_EV_MULTI_TOUCH_ENTER: - case STMFTS_EV_MULTI_TOUCH_MOTION: + if (touchpad.touch) data->state = LV_INDEV_STATE_PR; - break; - case STMFTS_EV_MULTI_TOUCH_LEAVE: + else data->state = LV_INDEV_STATE_REL; - break; - case STMFTS_EV_NO_EVENT: - default: - if (touchpad.touch) - data->state = LV_INDEV_STATE_PR; - else - data->state = LV_INDEV_STATE_REL; - break; - } return false; // No buffering so no more data read. } @@ -702,7 +694,7 @@ lv_img_dsc_t *bmp_to_lvimg_obj(const char *path) } lv_img_dsc_t *img_desc = (lv_img_dsc_t *)bitmap; - u32 offset_copy = ALIGN((u32)bitmap + sizeof(lv_img_dsc_t), 0x10); + uptr offset_copy = ALIGN((uptr)bitmap + sizeof(lv_img_dsc_t), 0x10); img_desc->header.always_zero = 0; img_desc->header.w = bmpData.size_x; @@ -782,7 +774,7 @@ lv_res_t nyx_generic_onoff_toggle(lv_obj_t *btn) return LV_RES_OK; } -lv_res_t mbox_action(lv_obj_t *btns, const char *txt) +lv_res_t nyx_mbox_action(lv_obj_t *btns, const char *txt) { lv_obj_t *mbox = lv_mbox_get_from_btn(btns); lv_obj_t *dark_bg = lv_obj_get_parent(mbox); @@ -817,7 +809,7 @@ bool nyx_emmc_check_battery_enough() "#FFDD00 with selected operation!#\n\n" "Charge to at least #C7EA46 3650 mV#, and try again!"); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -844,7 +836,7 @@ static void _nyx_sd_card_issues_warning(void *param) "#FFDD00 This might mean detached or broken connector!#\n\n" "You might want to check\n#C7EA46 Console Info# -> #C7EA46 microSD#"); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -879,14 +871,14 @@ void nyx_window_toggle_buttons(lv_obj_t *win, bool disable) } } -lv_res_t nyx_win_close_action_custom(lv_obj_t * btn) +lv_res_t nyx_win_close_action(lv_obj_t * btn) { close_btn = NULL; return lv_win_close_action(btn); } -lv_obj_t *nyx_create_standard_window(const char *win_title) +lv_obj_t *nyx_create_standard_window(const char *win_title, lv_action_t close_action) { static lv_style_t win_bg_style; @@ -899,25 +891,10 @@ lv_obj_t *nyx_create_standard_window(const char *win_title) lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style); lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES); - close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", nyx_win_close_action_custom); - - return win; -} - -lv_obj_t *nyx_create_window_custom_close_btn(const char *win_title, lv_action_t rel_action) -{ - static lv_style_t win_bg_style; - - lv_style_copy(&win_bg_style, &lv_style_plain); - win_bg_style.body.main_color = lv_theme_get_current()->bg->body.main_color; - win_bg_style.body.grad_color = win_bg_style.body.main_color; - - lv_obj_t *win = lv_win_create(lv_scr_act(), NULL); - lv_win_set_title(win, win_title); - lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style); - lv_obj_set_size(win, LV_HOR_RES, LV_VER_RES); - - close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", rel_action); + if (!close_action) + close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", nyx_win_close_action); + else + close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", close_action); return win; } @@ -981,7 +958,7 @@ static lv_res_t reload_action(lv_obj_t *btns, const char *txt) if (!lv_btnm_get_pressed(btns)) reload_nyx(NULL, false); - return mbox_action(btns, txt); + return nyx_mbox_action(btns, txt); } static lv_res_t _removed_sd_action(lv_obj_t *btns, const char *txt) @@ -1005,7 +982,7 @@ static lv_res_t _removed_sd_action(lv_obj_t *btns, const char *txt) break; } - return mbox_action(btns, txt); + return nyx_mbox_action(btns, txt); } static void _check_sd_card_removed(void *params) @@ -1063,7 +1040,7 @@ static void _nyx_emmc_issues_warning(void *params) "#FFDD00 This might mean hardware issues!#\n\n" "You might want to check\n#C7EA46 Console Info# -> #C7EA46 eMMC#"); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -1075,7 +1052,7 @@ static lv_res_t _reboot_ofw_action(lv_obj_t *btns, const char *txt) if (!lv_btnm_get_pressed(btns)) power_set_state(REBOOT_BYPASS_FUSES); - return mbox_action(btns, txt); + return nyx_mbox_action(btns, txt); } static lv_res_t _create_mbox_reboot_ofw() @@ -1133,7 +1110,7 @@ static lv_res_t _reboot_action(lv_obj_t *btns, const char *txt) break; } - return mbox_action(btns, txt); + return nyx_mbox_action(btns, txt); } static lv_res_t _poweroff_action(lv_obj_t *btns, const char *txt) @@ -1141,7 +1118,7 @@ static lv_res_t _poweroff_action(lv_obj_t *btns, const char *txt) if (!lv_btnm_get_pressed(btns)) power_set_state(POWER_OFF_RESET); - return mbox_action(btns, txt); + return nyx_mbox_action(btns, txt); } static lv_res_t _create_mbox_reload(lv_obj_t *btn) @@ -1236,7 +1213,7 @@ void nyx_create_onoff_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, co btn_onoff_pr_hos_style.body.opa = 35; } else - btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x101010) : 0x2D2D2D); + btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x101010) : 0x2D2D2D); // COLOR_HOS_BG_LIGHT. btn_onoff_pr_hos_style.body.grad_color = btn_onoff_pr_hos_style.body.main_color; btn_onoff_pr_hos_style.text.color = th->btn.pr->text.color; btn_onoff_pr_hos_style.body.empty = 0; @@ -1286,7 +1263,7 @@ static void _create_text_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, btn_onoff_pr_hos_style.body.opa = 35; } else - btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x101010) : 0x2D2D2D); + btn_onoff_pr_hos_style.body.main_color = LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x101010) : 0x2D2D2D); // COLOR_HOS_BG_LIGHT btn_onoff_pr_hos_style.body.grad_color = btn_onoff_pr_hos_style.body.main_color; btn_onoff_pr_hos_style.text.color = th->btn.pr->text.color; btn_onoff_pr_hos_style.body.empty = 0; @@ -1472,7 +1449,7 @@ static lv_res_t _create_mbox_payloads(lv_obj_t *btn) lv_obj_set_size(list, LV_HOR_RES * 3 / 7, LV_VER_RES * 3 / 7); lv_list_set_single_mode(list, true); - if (!sd_mount()) + if (sd_mount()) { lv_mbox_set_text(mbox, "#FFDD00 Failed to init SD!#"); @@ -1496,7 +1473,7 @@ static lv_res_t _create_mbox_payloads(lv_obj_t *btn) } out_end: - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -1736,7 +1713,7 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn) lv_obj_t *boot_entry_label; bool no_boot_entries = false; - // Create CFW buttons. + // Create Boot Entry buttons. // Buttons are 200 x 200 with 4 pixel borders. // Icons must be <= 192 x 192. // Create first Button. @@ -1776,7 +1753,7 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn) // Create colorized icon style based on its parent style. static lv_style_t img_style; lv_style_copy(&img_style, &lv_style_plain); - img_style.image.color = lv_color_hsv_to_rgb(n_cfg.theme_color, 100, 100); + img_style.image.color = COLOR_HOS_TURQUOISE_EX(n_cfg.theme_color); img_style.image.intense = LV_OPA_COVER; // Parse ini boot entries and set buttons/icons. @@ -1784,7 +1761,7 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn) u32 curr_btn_idx = 0; // Active buttons. LIST_INIT(ini_sections); - if (!sd_mount()) + if (sd_mount()) goto failed_sd_mount; // Check if we use custom system icons. @@ -1794,15 +1771,15 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn) // Choose what to parse. bool ini_parse_success = false; if (!more_cfg) - ini_parse_success = ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false); + ini_parse_success = !ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false); else - ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true); + ini_parse_success = !ini_parse(&ini_sections, "bootloader/ini", true); if (combined_cfg && !ini_parse_success) { ini_parsing: list_init(&ini_sections); - ini_parse_success = ini_parse(&ini_sections, "bootloader/ini", true); + ini_parse_success = !ini_parse(&ini_sections, "bootloader/ini", true); more_cfg = true; } @@ -1931,11 +1908,20 @@ ini_parsing: btn_height = 200; lv_btn_set_style(launch_ctxt.btn[curr_btn_idx], LV_BTN_STYLE_REL, &btn_home_noborder_rel); - lv_btn_set_style(launch_ctxt.btn[curr_btn_idx], LV_BTN_STYLE_PR, &btn_home_noborder_rel); + lv_btn_set_style(launch_ctxt.btn[curr_btn_idx], LV_BTN_STYLE_PR, &btn_home_noborder_rel); } lv_obj_set_size(btns, btn_width, btn_height); lv_btn_set_style(btns, LV_BTN_STYLE_REL, img_noborder ? &btn_home_noborder_rel : &btn_home_transp_rel); lv_btn_set_style(btns, LV_BTN_STYLE_PR, &btn_home_transp_pr); + + // Button transparency if custom background, but loses color. + // if (!btn && hekate_bg && !img_noborder) + // { + // lv_btn_set_style(launch_ctxt.btn[curr_btn_idx], LV_BTN_STYLE_REL, &btn_transp_rel); + // lv_btn_set_style(launch_ctxt.btn[curr_btn_idx], LV_BTN_STYLE_PR, &btn_transp_pr); + // lv_btn_set_style(btns, LV_BTN_STYLE_REL, &btn_home_noborder_rel); + // } + if (img) lv_obj_align(img, NULL, LV_ALIGN_CENTER, 0, 0); if (img_noborder) @@ -1957,9 +1943,13 @@ ini_parsing: lv_label_set_text(launch_ctxt.label[curr_btn_idx], ini_sec->name); lv_obj_set_opa_scale(launch_ctxt.label[curr_btn_idx], LV_OPA_COVER); - // Set rolling text if name is big. - if (strlen(ini_sec->name) > 22) + // Set rolling text if name is too big. + int max_label_size = 238 - (n_cfg.entries_5_col ? 12 : 0); + if (lv_obj_get_width(launch_ctxt.label[curr_btn_idx]) > max_label_size) + { lv_label_set_long_mode(launch_ctxt.label[curr_btn_idx], LV_LABEL_LONG_ROLL); + lv_obj_set_width(launch_ctxt.label[curr_btn_idx], max_label_size); + } entry_idx++; curr_btn_idx++; @@ -2115,6 +2105,12 @@ static void _create_tab_home(lv_theme_t *th, lv_obj_t *parent) // lv_obj_set_width(btn_quick_launch, 256); // lv_obj_set_pos(btn_quick_launch, 343, 448); // lv_btn_set_action(btn_quick_launch, LV_BTN_ACTION_CLICK, NULL); + // if (hekate_bg) + // { + // lv_btn_set_style(btn_quick_launch, LV_BTN_STYLE_REL, &btn_transp_rel); + // lv_btn_set_style(btn_quick_launch, LV_BTN_STYLE_PR, &btn_transp_pr); + // lv_btn_set_style(btn_quick_launch, LV_BTN_STYLE_INA, &btn_transp_ina); + // } lv_obj_t *btn_nyx_options = lv_btn_create(parent, NULL); _create_text_button(th, NULL, btn_nyx_options, SYMBOL_SETTINGS" Nyx Settings", NULL); @@ -2179,10 +2175,10 @@ static lv_res_t _save_options_action(lv_obj_t *btn) int res = 0; - if (sd_mount()) - res = !create_config_entry(); + if (!sd_mount()) + res = create_config_entry(); - if (res) + if (!res) lv_mbox_set_text(mbox, "#FF8000 hekate Configuration#\n\n#96FF00 The configuration was saved to sd card!#"); else lv_mbox_set_text(mbox, "#FF8000 hekate Configuration#\n\n#FFDD00 Failed to save the configuration#\n#FFDD00 to sd card!#"); @@ -2250,7 +2246,7 @@ static void _create_status_bar(lv_theme_t * th) lv_obj_t *btn_mid = lv_btn_create(status_bar_bg, NULL); lv_obj_t *lbl_mid = lv_label_create(btn_mid, NULL); lv_label_set_static_text(lbl_mid, "Save Options"); - lv_obj_set_size(btn_mid, LV_DPI * 5 / 2, LV_DPI / 2); + lv_obj_set_size(btn_mid, LV_DPI * 17 / 8, LV_DPI / 2); lv_obj_align(btn_mid, NULL, LV_ALIGN_CENTER, 0, 0); status_bar.mid = btn_mid; lv_obj_set_opa_scale(btn_mid, LV_OPA_0); @@ -2263,7 +2259,7 @@ static lv_res_t _create_mbox_save_changes_action(lv_obj_t *btns, const char * tx { int btn_idx = lv_btnm_get_pressed(btns); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); if (!btn_idx) _save_options_action(NULL); @@ -2342,9 +2338,9 @@ static void _nyx_set_default_styles(lv_theme_t * th) hint_small_style_white.text.font = &interui_20; lv_style_copy(&monospace_text, &lv_style_plain); - monospace_text.body.main_color = LV_COLOR_HEX(0x1B1B1B); - monospace_text.body.grad_color = LV_COLOR_HEX(0x1B1B1B); - monospace_text.body.border.color = LV_COLOR_HEX(0x1B1B1B); + monospace_text.body.main_color = COLOR_HOS_BG_DARKER; + monospace_text.body.grad_color = COLOR_HOS_BG_DARKER; + monospace_text.body.border.color = COLOR_HOS_BG_DARKER; monospace_text.body.border.width = 0; monospace_text.body.opa = LV_OPA_TRANSP; monospace_text.text.color = LV_COLOR_HEX(0xD8D8D8); @@ -2355,44 +2351,55 @@ static void _nyx_set_default_styles(lv_theme_t * th) lv_style_copy(&btn_transp_rel, th->btn.rel); btn_transp_rel.body.main_color = LV_COLOR_HEX(0x444444); btn_transp_rel.body.grad_color = btn_transp_rel.body.main_color; + btn_transp_rel.body.shadow.color = LV_COLOR_HEX(0x0F0F0F); btn_transp_rel.body.opa = LV_OPA_50; lv_style_copy(&btn_transp_pr, th->btn.pr); btn_transp_pr.body.main_color = LV_COLOR_HEX(0x888888); btn_transp_pr.body.grad_color = btn_transp_pr.body.main_color; + btn_transp_pr.body.shadow.color = LV_COLOR_HEX(0x0F0F0F); btn_transp_pr.body.opa = LV_OPA_50; lv_style_copy(&btn_transp_tgl_rel, th->btn.tgl_rel); btn_transp_tgl_rel.body.main_color = LV_COLOR_HEX(0x444444); btn_transp_tgl_rel.body.grad_color = btn_transp_tgl_rel.body.main_color; + btn_transp_tgl_rel.body.shadow.color = LV_COLOR_HEX(0x0F0F0F); btn_transp_tgl_rel.body.opa = LV_OPA_50; lv_style_copy(&btn_transp_tgl_pr, th->btn.tgl_pr); btn_transp_tgl_pr.body.main_color = LV_COLOR_HEX(0x888888); btn_transp_tgl_pr.body.grad_color = btn_transp_tgl_pr.body.main_color; + btn_transp_tgl_pr.body.shadow.color = LV_COLOR_HEX(0x0F0F0F); btn_transp_tgl_pr.body.opa = LV_OPA_50; + lv_style_copy(&btn_transp_ina, th->btn.ina); + btn_transp_ina.body.main_color = LV_COLOR_HEX(0x292929); + btn_transp_ina.body.grad_color = btn_transp_ina.body.main_color; + btn_transp_ina.body.border.color = LV_COLOR_HEX(0x444444); + btn_transp_ina.body.shadow.color = LV_COLOR_HEX(0x0F0F0F); + btn_transp_ina.body.opa = LV_OPA_50; + lv_style_copy(&ddlist_transp_bg, th->ddlist.bg); ddlist_transp_bg.body.main_color = LV_COLOR_HEX(0x2D2D2D); ddlist_transp_bg.body.grad_color = ddlist_transp_bg.body.main_color; - ddlist_transp_bg.body.opa = 180; + ddlist_transp_bg.body.opa = 180; // 70.6%. lv_style_copy(&ddlist_transp_sel, th->ddlist.sel); ddlist_transp_sel.body.main_color = LV_COLOR_HEX(0x4D4D4D); ddlist_transp_sel.body.grad_color = ddlist_transp_sel.body.main_color; - ddlist_transp_sel.body.opa = 180; + ddlist_transp_sel.body.opa = 180; // 70.6%. lv_style_copy(&tabview_btn_pr, th->tabview.btn.pr); tabview_btn_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF); tabview_btn_pr.body.grad_color = tabview_btn_pr.body.main_color; - tabview_btn_pr.body.opa = 35; + tabview_btn_pr.body.opa = 35; // 13.7%. lv_style_copy(&tabview_btn_tgl_pr, th->tabview.btn.tgl_pr); tabview_btn_tgl_pr.body.main_color = LV_COLOR_HEX(0xFFFFFF); tabview_btn_tgl_pr.body.grad_color = tabview_btn_tgl_pr.body.main_color; - tabview_btn_tgl_pr.body.opa = 35; + tabview_btn_tgl_pr.body.opa = 35; // 13.7%. - lv_color_t tmp_color = lv_color_hsv_to_rgb(n_cfg.theme_color, 100, 100); + lv_color_t tmp_color = COLOR_HOS_TURQUOISE_EX(n_cfg.theme_color); text_color = malloc(32); s_printf(text_color, "#%06X", (u32)(tmp_color.full & 0xFFFFFF)); } @@ -2451,8 +2458,9 @@ static void _nyx_main_menu(lv_theme_t * th) // Add all tabs content. char version[32]; char rel = (nyx_str->version >> 24) & 0xFF; - s_printf(version, "hekate %s%d.%d.%d%c", - rel ? "v" : "", nyx_str->version & 0xFF, (nyx_str->version >> 8) & 0xFF, (nyx_str->version >> 16) & 0xFF, rel > 'A' ? rel : 0); + s_printf(version, "hekate %s%d.%d.%d%c%c", + rel ? "v" : "", nyx_str->version & 0xFF, (nyx_str->version >> 8) & 0xFF, (nyx_str->version >> 16) & 0xFF, rel > 'a' ? rel : 0, + (nyx_str->info_ex.rsvd_flags & RSVD_FLAG_DRAM_8GB) ? '*' : 0); lv_obj_t *tab_about = lv_tabview_add_tab(tv, version); lv_obj_t *tab_home = lv_tabview_add_tab(tv, SYMBOL_HOME" Home"); @@ -2561,7 +2569,7 @@ void nyx_load_and_run() close_btn = NULL; // Initialize touch. - touch_enabled = touch_power_on(); + touch_enabled = !touch_power_on(); lv_indev_drv_t indev_drv_touch; lv_indev_drv_init(&indev_drv_touch); indev_drv_touch.type = LV_INDEV_TYPE_POINTER; diff --git a/nyx/nyx_gui/frontend/gui.h b/nyx/nyx_gui/frontend/gui.h index 2db45c52..c55d7adc 100644 --- a/nyx/nyx_gui/frontend/gui.h +++ b/nyx/nyx_gui/frontend/gui.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -63,7 +63,7 @@ extern lv_img_dsc_t *icon_lakka; extern lv_img_dsc_t *hekate_bg; extern lv_img_dsc_t *hekate_bg_etc; -extern lv_style_t btn_transp_rel, btn_transp_pr, btn_transp_tgl_rel, btn_transp_tgl_pr; +extern lv_style_t btn_transp_rel, btn_transp_pr, btn_transp_tgl_rel, btn_transp_tgl_pr, btn_transp_ina; extern lv_style_t ddlist_transp_bg, ddlist_transp_sel; extern lv_style_t tabview_btn_pr, tabview_btn_tgl_pr; @@ -73,14 +73,13 @@ extern char *text_color; extern gui_status_bar_ctx status_bar; -void reload_nyx(); +void reload_nyx(lv_obj_t *obj, bool force); lv_img_dsc_t *bmp_to_lvimg_obj(const char *path); -lv_res_t mbox_action(lv_obj_t * btns, const char * txt); bool nyx_emmc_check_battery_enough(); -lv_res_t nyx_win_close_action_custom(lv_obj_t * btn); +lv_res_t nyx_mbox_action(lv_obj_t * btns, const char * txt); +lv_res_t nyx_win_close_action(lv_obj_t * btn); void nyx_window_toggle_buttons(lv_obj_t *win, bool disable); -lv_obj_t *nyx_create_standard_window(const char *win_title); -lv_obj_t *nyx_create_window_custom_close_btn(const char *win_title, lv_action_t rel_action); +lv_obj_t *nyx_create_standard_window(const char *win_title, lv_action_t close_action); void nyx_create_onoff_button(lv_theme_t *th, lv_obj_t *parent, lv_obj_t *btn, const char *btn_name, lv_action_t action, bool transparent); lv_res_t nyx_generic_onoff_toggle(lv_obj_t *btn); void manual_system_maintenance(bool refresh); diff --git a/nyx/nyx_gui/frontend/gui_emmc_tools.c b/nyx/nyx_gui/frontend/gui_emmc_tools.c index 775002fc..d1ca05f3 100644 --- a/nyx/nyx_gui/frontend/gui_emmc_tools.c +++ b/nyx/nyx_gui/frontend/gui_emmc_tools.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -28,8 +28,6 @@ #include "../hos/hos.h" #include -extern boot_cfg_t b_cfg; - extern char *emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); typedef struct _emmc_backup_buttons_t @@ -54,7 +52,7 @@ static void _create_window_backup_restore(emmcPartType_t type, const char* win_l s_printf(win_label_full, "%s%s", emmc_btn_ctxt.restore ? SYMBOL_DOWNLOAD" Restore " : SYMBOL_UPLOAD" Backup ", win_label+3); - lv_obj_t *win = nyx_create_standard_window(win_label_full); + lv_obj_t *win = nyx_create_standard_window(win_label_full, NULL); //Disable buttons. nyx_window_toggle_buttons(win, true); @@ -285,9 +283,9 @@ lv_res_t create_window_backup_restore_tool(lv_obj_t *btn) emmc_btn_ctxt.restore = true; if (!emmc_btn_ctxt.restore) - win = nyx_create_standard_window(SYMBOL_SD" Backup"); + win = nyx_create_standard_window(SYMBOL_SD" Backup", NULL); else - win = nyx_create_standard_window(SYMBOL_SD" Restore"); + win = nyx_create_standard_window(SYMBOL_SD" Restore", NULL); static lv_style_t h_style; lv_style_copy(&h_style, &lv_style_transp); diff --git a/nyx/nyx_gui/frontend/gui_emummc_tools.c b/nyx/nyx_gui/frontend/gui_emummc_tools.c index efa17c53..a8805f63 100644 --- a/nyx/nyx_gui/frontend/gui_emummc_tools.c +++ b/nyx/nyx_gui/frontend/gui_emummc_tools.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2025 CTCaer + * Copyright (c) 2019-2026 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,7 +42,7 @@ static lv_res_t (*emummc_tools)(lv_obj_t *btn); static lv_res_t _action_emummc_window_close(lv_obj_t *btn) { - nyx_win_close_action_custom(btn); + nyx_win_close_action(btn); // Delete and relaunch main emuMMC window. lv_obj_del(emummc_manage_window); @@ -57,9 +57,9 @@ static void _create_window_emummc() lv_obj_t *win; if (!mbr_ctx.part_idx) - win = nyx_create_window_custom_close_btn(SYMBOL_DRIVE" Create SD File emuMMC", _action_emummc_window_close); + win = nyx_create_standard_window(SYMBOL_DRIVE" Create SD File emuMMC", _action_emummc_window_close); else - win = nyx_create_window_custom_close_btn(SYMBOL_DRIVE" Create SD Partition emuMMC", _action_emummc_window_close); + win = nyx_create_standard_window(SYMBOL_DRIVE" Create SD Partition emuMMC", _action_emummc_window_close); //Disable buttons. nyx_window_toggle_buttons(win, true); @@ -144,7 +144,7 @@ static lv_res_t _create_emummc_raw_format(lv_obj_t * btns, const char * txt) int btn_idx = lv_btnm_get_pressed(btns); // Delete parent mbox. - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); // Create partition window. if (!btn_idx) @@ -190,7 +190,7 @@ static lv_res_t _create_emummc_raw_action(lv_obj_t * btns, const char * txt) mbr_ctx.part_idx = 0; mbr_ctx.sector_start = 0; - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -328,7 +328,7 @@ static lv_res_t _create_emummc_action(lv_obj_t * btns, const char * txt) break; } - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -374,7 +374,7 @@ static lv_res_t _save_emummc_cfg_mig_mbox_action(lv_obj_t *btns, const char *txt { // Delete main emuMMC and popup windows and relaunch main emuMMC window. lv_obj_del(emummc_manage_window); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); (*emummc_tools)(NULL); @@ -402,25 +402,6 @@ static void _create_emummc_migrated_mbox() lv_obj_set_top(mbox, true); } -static void _migrate_sd_raw_based() -{ - mbr_ctx.sector_start = 2; - - sd_mount(); - f_mkdir("emuMMC"); - f_mkdir("emuMMC/ER00"); - - f_rename("Emutendo", "emuMMC/ER00/Nintendo"); - FIL fp; - f_open(&fp, "emuMMC/ER00/raw_based", FA_CREATE_ALWAYS | FA_WRITE); - f_write(&fp, &mbr_ctx.sector_start, 4, NULL); - f_close(&fp); - - save_emummc_cfg(1, mbr_ctx.sector_start, "emuMMC/ER00"); - _create_emummc_migrated_mbox(); - sd_unmount(); -} - static void _migrate_sd_raw_emummc_based() { char *tmp = (char *)malloc(0x80); @@ -449,43 +430,6 @@ static void _migrate_sd_raw_emummc_based() sd_unmount(); } -static void _migrate_sd_file_based() -{ - sd_mount(); - f_mkdir("emuMMC"); - f_mkdir("emuMMC/EF00"); - - f_rename("Emutendo", "emuMMC/EF00/Nintendo"); - FIL fp; - f_open(&fp, "emuMMC/EF00/file_based", FA_CREATE_ALWAYS | FA_WRITE); - f_close(&fp); - - char *path = (char *)malloc(128); - char *path2 = (char *)malloc(128); - s_printf(path, "%c%c%c%c%s", 's', 'x', 'o', 's', "/emunand"); - f_rename(path, "emuMMC/EF00/eMMC"); - - for (int i = 0; i < 2; i++) - { - s_printf(path, "emuMMC/EF00/eMMC/boot%d.bin", i); - s_printf(path2, "emuMMC/EF00/eMMC/BOOT%d", i); - f_rename(path, path2); - } - for (int i = 0; i < 8; i++) - { - s_printf(path, "emuMMC/EF00/eMMC/full.%02d.bin", i); - s_printf(path2, "emuMMC/EF00/eMMC/%02d", i); - f_rename(path, path2); - } - - free(path); - free(path2); - - save_emummc_cfg(0, 0, "emuMMC/EF00"); - _create_emummc_migrated_mbox(); - sd_unmount(); -} - static void _migrate_sd_backup_file_based() { char *emu_path = (char *)malloc(128); @@ -566,61 +510,7 @@ static void _migrate_sd_backup_file_based() sd_unmount(); } -static lv_res_t _create_emummc_mig1_action(lv_obj_t * btns, const char * txt) -{ - switch (lv_btnm_get_pressed(btns)) - { - case 0: - _migrate_sd_file_based(); - break; - case 1: - _migrate_sd_raw_based(); - break; - } - - mbr_ctx.part_idx = 0; - mbr_ctx.sector_start = 0; - - mbox_action(btns, txt); - - return LV_RES_INV; -} - static lv_res_t _create_emummc_mig0_action(lv_obj_t * btns, const char * txt) -{ - switch (lv_btnm_get_pressed(btns)) - { - case 0: - _migrate_sd_file_based(); - break; - } - - mbr_ctx.part_idx = 0; - mbr_ctx.sector_start = 0; - - mbox_action(btns, txt); - - return LV_RES_INV; -} - -static lv_res_t _create_emummc_mig2_action(lv_obj_t * btns, const char * txt) -{ - switch (lv_btnm_get_pressed(btns)) - { - case 0: - _migrate_sd_raw_based(); - break; - } - - mbr_ctx.part_idx = 0; - mbr_ctx.sector_start = 0; - - mbox_action(btns, txt); - - return LV_RES_INV; -} - -static lv_res_t _create_emummc_mig3_action(lv_obj_t * btns, const char * txt) { switch (lv_btnm_get_pressed(btns)) { @@ -632,12 +522,12 @@ static lv_res_t _create_emummc_mig3_action(lv_obj_t * btns, const char * txt) mbr_ctx.part_idx = 0; mbr_ctx.sector_start = 0; - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } -static lv_res_t _create_emummc_mig4_action(lv_obj_t * btns, const char * txt) +static lv_res_t _create_emummc_mig1_action(lv_obj_t * btns, const char * txt) { switch (lv_btnm_get_pressed(btns)) { @@ -649,13 +539,11 @@ static lv_res_t _create_emummc_mig4_action(lv_obj_t * btns, const char * txt) mbr_ctx.part_idx = 0; mbr_ctx.sector_start = 0; - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } -bool em_raw; -bool em_file; static lv_res_t _create_emummc_migrate_action(lv_obj_t * btns, const char * txt) { bool backup = false; @@ -670,9 +558,7 @@ static lv_res_t _create_emummc_migrate_action(lv_obj_t * btns, const char * txt) emummc = true; break; case 2: - break; - case 3: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -681,8 +567,7 @@ static lv_res_t _create_emummc_migrate_action(lv_obj_t * btns, const char * txt) lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); static const char *mbox_btn_map[] = { "\222Continue", "\222Cancel", "" }; - static const char *mbox_btn_map1[] = { "\222SD File", "\222SD Partition", "\222Cancel", "" }; - static const char *mbox_btn_map3[] = { "\251", "OK", "\251", "" }; + static const char *mbox_btn_map1[] = { "\251", "OK", "\251", "" }; lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); lv_mbox_set_recolor_text(mbox, true); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 6); @@ -699,40 +584,19 @@ static lv_res_t _create_emummc_migrate_action(lv_obj_t * btns, const char * txt) s_printf(txt_buf, "#C7EA46 Found suitable emuMMC backup!#\n\n" "#FF8000 Do you want to migrate it?#\n"); - lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig4_action); + lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig1_action); } else if (emummc) { s_printf(txt_buf, "#C7EA46 Found SD Partition based emuMMC!#\n\n" "#FF8000 Do you want to repair the config and partition type for it?#\n"); - lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig3_action); - } - else if (em_raw && em_file) - { - s_printf(txt_buf, - "#C7EA46 Found both foreign SD File and Partition emunand!#\n\n" - "#FF8000 Choose what to migrate:#\n"); - lv_mbox_add_btns(mbox, mbox_btn_map1, _create_emummc_mig1_action); - } - else if (em_raw) - { - s_printf(txt_buf, - "#C7EA46 Found foreign SD Partition emunand!#\n\n" - "#FF8000 Do you want to migrate it?#\n"); - lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig2_action); - } - else if (em_file) - { - s_printf(txt_buf, - "#C7EA46 Found foreign SD File emunand!#\n\n" - "#FF8000 Do you want to migrate it?#\n"); lv_mbox_add_btns(mbox, mbox_btn_map, _create_emummc_mig0_action); } else { - s_printf(txt_buf, "No emuMMC or foreign emunand found!\n"); - lv_mbox_add_btns(mbox, mbox_btn_map3, mbox_action); + s_printf(txt_buf, "No emuMMC found!\n"); + lv_mbox_add_btns(mbox, mbox_btn_map1, nyx_mbox_action); } lv_mbox_set_text(mbox, txt_buf); @@ -741,7 +605,7 @@ static lv_res_t _create_emummc_migrate_action(lv_obj_t * btns, const char * txt) lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -762,7 +626,7 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn) lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); - static char *mbox_btn_map[] = { "\262Backup", "\262Fix RAW", "\262Emunand", "\222Cancel", "" }; + static char *mbox_btn_map[] = { "\262Backup", "\262Fix RAW", "\222Cancel", "" }; lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); lv_mbox_set_recolor_text(mbox, true); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 6); @@ -781,8 +645,6 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn) emmc_initialize(false); - em_raw = false; - em_file = false; bool backup = false; bool emummc = false; bool rawnand_backup = false; @@ -818,18 +680,6 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn) } } - if (!mbr_ctx.part_idx) - { - sdmmc_storage_read(&sd_storage, 0x4003, 1, efi_part); - if (!memcmp(efi_part, "EFI PART", 8)) - em_raw = true; - } - - s_printf(path_buf, "%c%c%c%c%s", 's', 'x', 'o','s', "/emunand/boot0.bin"); - - if (!f_stat(path_buf, NULL)) - em_file = true; - emummc_backup = false; emmcsn_path_impl(path_buf, "", "BOOT0", &emmc_storage); @@ -878,10 +728,6 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn) mbox_btn_map[1][0] = '\222'; else mbox_btn_map[1][0] = '\262'; - if (em_raw || em_file) - mbox_btn_map[2][0] = '\222'; - else - mbox_btn_map[2][0] = '\262'; free(path_buf); free(mbr); @@ -905,7 +751,7 @@ static lv_res_t _save_emummc_cfg_mbox_action(lv_obj_t *btns, const char *txt) free(emummc_img->dirlist); free(emummc_img); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); (*emummc_tools)(NULL); @@ -978,12 +824,12 @@ static lv_res_t _action_win_change_emummc_close(lv_obj_t *btn) free(emummc_img->dirlist); free(emummc_img); - return nyx_win_close_action_custom(btn); + return nyx_win_close_action(btn); } static lv_res_t _create_change_emummc_window(lv_obj_t *btn_caller) { - lv_obj_t *win = nyx_create_window_custom_close_btn(SYMBOL_SETTINGS" Change emuMMC", _action_win_change_emummc_close); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_SETTINGS" Change emuMMC", _action_win_change_emummc_close); lv_win_add_btn(win, NULL, SYMBOL_POWER" Disable", _save_disable_emummc_cfg_action); sd_mount(); @@ -1204,7 +1050,7 @@ out1: lv_res_t create_win_emummc_tools(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_EDIT" emuMMC Manage"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_EDIT" emuMMC Manage", NULL); // Set resources to be managed by other windows. emummc_manage_window = win; @@ -1237,7 +1083,7 @@ lv_res_t create_win_emummc_tools(lv_obj_t *btn) lv_obj_t *label_txt = lv_label_create(h1, NULL); lv_label_set_static_text(label_txt, "emuMMC Info & Selection"); lv_obj_set_style(label_txt, lv_theme_get_current()->label.prim); - lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, -LV_DPI / 9); + lv_obj_align(label_txt, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 11); lv_obj_t *line_sep = lv_line_create(h1, NULL); static const lv_point_t line_pp[] = { {0, 0}, { LV_HOR_RES - (LV_DPI - (LV_DPI / 4)) * 2, 0} }; @@ -1258,17 +1104,17 @@ lv_res_t create_win_emummc_tools(lv_obj_t *btn) if (emu_info.enabled) { if (emu_info.sector) - s_printf(txt_buf, "#00DDFF Type:# SD Raw Partition\n#00DDFF Sector:# 0x%08X\n#00DDFF Nintendo folder:# %s", + s_printf(txt_buf, "#00DDFF Type:# SD Raw Partition\n#00DDFF Sector:# 0x%08X\n#00DDFF Nintendo folder:# %s\n", emu_info.sector, emu_info.nintendo_path ? emu_info.nintendo_path : ""); else - s_printf(txt_buf, "#00DDFF Type:# SD File\n#00DDFF Base folder:# %s\n#00DDFF Nintendo folder:# %s", + s_printf(txt_buf, "#00DDFF Type:# SD File\n#00DDFF Base folder:# %s\n#00DDFF Nintendo folder:# %s\n", emu_info.path ? emu_info.path : "", emu_info.nintendo_path ? emu_info.nintendo_path : ""); lv_label_set_text(label_txt2, txt_buf); } else { - lv_label_set_static_text(label_txt2, "emuMMC is disabled and eMMC will be used for boot.\n\n"); + lv_label_set_static_text(label_txt2, "emuMMC is disabled and eMMC will be used for boot.\n\n\n"); } if (emu_info.path) @@ -1313,7 +1159,7 @@ lv_res_t create_win_emummc_tools(lv_obj_t *btn) lv_obj_t *label_txt3 = lv_label_create(h2, NULL); lv_label_set_static_text(label_txt3, "emuMMC Tools"); lv_obj_set_style(label_txt3, lv_theme_get_current()->label.prim); - lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, 0); + lv_obj_align(label_txt3, label_sep, LV_ALIGN_OUT_BOTTOM_LEFT, LV_DPI / 4, LV_DPI / 5); line_sep = lv_line_create(h2, line_sep); lv_obj_align(line_sep, label_txt3, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 8); @@ -1330,7 +1176,7 @@ lv_res_t create_win_emummc_tools(lv_obj_t *btn) lv_label_set_recolor(label_txt4, true); lv_label_set_static_text(label_txt4, "Allows you to create a new #C7EA46 SD File# or #C7EA46 SD Raw Partition#\n" - "emuMMC. You can create it from eMMC or a eMMC Backup."); + "emuMMC. You can create it from eMMC or a eMMC Backup.\n"); lv_obj_set_style(label_txt4, &hint_small_style); lv_obj_align(label_txt4, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); @@ -1346,8 +1192,7 @@ lv_res_t create_win_emummc_tools(lv_obj_t *btn) label_txt4 = lv_label_create(h2, NULL); lv_label_set_recolor(label_txt4, true); lv_label_set_static_text(label_txt4, - "Migrate a backup to a #C7EA46 SD File# or repair existing #C7EA46 SD Raw Partition#.\n" - "Additionally it allows you to migrate from other emunand\nsolutions."); + "Migrate a backup to a #C7EA46 SD File emuMMC# or repair an existing\n#C7EA46 SD Raw Partition emuMMC#.\n"); lv_obj_set_style(label_txt4, &hint_small_style); lv_obj_align(label_txt4, btn4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); diff --git a/nyx/nyx_gui/frontend/gui_info.c b/nyx/nyx_gui/frontend/gui_info.c index 0b4241f6..85e8d686 100644 --- a/nyx/nyx_gui/frontend/gui_info.c +++ b/nyx/nyx_gui/frontend/gui_info.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 CTCaer * Copyright (c) 2018 balika011 * * This program is free software; you can redistribute it and/or modify it @@ -30,7 +30,6 @@ static const char base36[37] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -extern volatile boot_cfg_t *b_cfg; extern volatile nyx_storage_t *nyx_str; extern lv_res_t launch_payload(lv_obj_t *list); @@ -59,7 +58,7 @@ static lv_res_t _create_window_dump_done(int error, char *dump_filenames) lv_mbox_set_text(mbox, txt_buf); free(txt_buf); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text. + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); // Important. After set_text. lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -71,11 +70,11 @@ static lv_res_t _cal0_dump_window_action(lv_obj_t *btns, const char * txt) { int btn_idx = lv_btnm_get_pressed(btns); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); if (btn_idx == 1) { - int error = !sd_mount(); + int error = sd_mount(); if (!error) { @@ -95,7 +94,7 @@ static lv_res_t _cal0_dump_window_action(lv_obj_t *btns, const char * txt) static lv_res_t _battery_dump_window_action(lv_obj_t * btn) { - int error = !sd_mount(); + int error = sd_mount(); if (!error) { @@ -119,7 +118,7 @@ static lv_res_t _bootrom_dump_window_action(lv_obj_t * btn) { static const u32 BOOTROM_SIZE = 0x18000; - int error = !sd_mount(); + int error = sd_mount(); if (!error) { char path[64]; @@ -180,7 +179,7 @@ static void _unlock_reserved_odm_fuses(bool lock) static lv_res_t _fuse_dump_window_action(lv_obj_t * btn) { - int error = !sd_mount(); + int error = sd_mount(); if (!error) { char path[128]; @@ -228,10 +227,10 @@ static lv_res_t _fuse_dump_window_action(lv_obj_t * btn) static lv_res_t _kfuse_dump_window_action(lv_obj_t * btn) { u32 buf[KFUSE_NUM_WORDS]; - int error = !kfuse_read(buf); + int error = kfuse_read(buf); if (!error) - error = !sd_mount(); + error = sd_mount(); if (!error) { @@ -388,7 +387,7 @@ u32 wafer16nm[] = 0x1FFFFFFF, 0x1FFFFFFF, 0x0FFFFFFE, 0x0FFFFFFE, 0x0FFFFFFE, 0x07FFFFFC, 0x07FFFFFC, 0x03FFFFF8, 0x01FFFFF0, 0x00FFFFE0, 0x007FFFC0, 0x001FFF00, - 0x00000000 + 0x0000E000 }; u32 wafer20nm[] = @@ -422,7 +421,7 @@ hw_info_t *hw_info = NULL; #define WAFER_16NM_X_MIN -11 #define WAFER_16NM_X_MAX 17 #define WAFER_16NM_Y_MIN 0 -#define WAFER_16NM_Y_MAX 27 +#define WAFER_16NM_Y_MAX 28 void _hw_info_wafer(int die_x, int die_y) { @@ -470,8 +469,8 @@ void _hw_info_wafer(int die_x, int die_y) int pos_y = y * die_line * die_side + die_line; for (int x = 0; x < diameter; x++) { + bool in_wafer = wafer_row & (1u << x); bool die_found = x == die_x && die_y == y; - bool in_wafer = wafer_row & (1u << x); u32 die_column = x * die_side; // Paint street rows; @@ -542,14 +541,14 @@ static lv_res_t _action_win_hw_info_status_close(lv_obj_t *btn) hw_info = NULL; } - return nyx_win_close_action_custom(btn); + return nyx_win_close_action(btn); } static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) { u32 uptime_s = get_tmr_s(); - lv_obj_t *win = nyx_create_window_custom_close_btn(SYMBOL_CHIP" HW & Fuses Info", _action_win_hw_info_status_close); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" HW & Fuses Info", _action_win_hw_info_status_close); lv_win_add_btn(win, NULL, SYMBOL_DOWNLOAD" Dump fuses", _fuse_dump_window_action); lv_win_add_btn(win, NULL, SYMBOL_INFO" CAL0 Info", _create_mbox_cal0); @@ -562,7 +561,7 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) lv_label_set_style(lb_desc, &monospace_text); char version[32]; - s_printf(version, "%s%d.%d.%d%c", NYX_VER_RL ? "v" : "", NYX_VER_MJ, NYX_VER_MN, NYX_VER_HF, NYX_VER_RL > 'A' ? NYX_VER_RL : 0); + s_printf(version, "%s%d.%d.%d%c", NYX_VER_RL ? "v" : "", NYX_VER_MJ, NYX_VER_MN, NYX_VER_HF, NYX_VER_RL > 'a' ? NYX_VER_RL : 0); lv_obj_t * lbl_ver = lv_label_create(lv_scr_act(), NULL); lv_label_set_style(lbl_ver, &hint_small_style_white); lv_label_set_text(lbl_ver, version); @@ -808,7 +807,10 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) strcpy(fuses_hos_version, "20.0.0 - 20.5.0"); break; case 22: - strcpy(fuses_hos_version, "21.0.0+"); + strcpy(fuses_hos_version, "21.0.0 - 21.2.0"); + break; + case 23: + strcpy(fuses_hos_version, "22.0.0+"); break; case 255: strcpy(fuses_hos_version, "#FFD000 Overburnt#"); @@ -1090,6 +1092,12 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) u8 display_rev = (nyx_str->info.panel_id >> 8) & 0xFF; u32 display_id = ((nyx_str->info.panel_id >> 8) & 0xFF00) | (nyx_str->info.panel_id & 0xFF); + // For OLED LCD 7" OEM clone use touch to identify it. + touch_info_t *touch_info = touch_get_chip_info(); + bool touch_clone_oled = touch_info->chip_id == FTS4_I2C_CHIP_ID && touch_info->clone; + if (touch_clone_oled) + display_id = 0x10000; + strcat(txt_buf, "#00DDFF Display Panel:#\n#FF8000 Model:# "); switch (display_id) @@ -1097,9 +1105,11 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) case PANEL_JDI_LAM062M109A: strcat(txt_buf, "JDI LAM062M109A"); break; + case PANEL_JDI_LPM062M326A: strcat(txt_buf, "JDI LPM062M326A"); break; + case PANEL_INL_P062CCA_AZ1: strcat(txt_buf, "InnoLux P062CCA"); switch (display_rev) @@ -1127,6 +1137,7 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) break; } break; + case PANEL_AUO_A062TAN01: strcat(txt_buf, "AUO A062TAN"); switch (display_rev) @@ -1154,31 +1165,44 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) break; } break; + case PANEL_INL_2J055IA_27A: strcat(txt_buf, "InnoLux 2J055IA-27A"); break; + case PANEL_AUO_A055TAN01: strcat(txt_buf, "AUO A055TAN"); s_printf(txt_buf + strlen(txt_buf), "%02d", display_rev - 0x92); break; + case PANEL_SHP_LQ055T1SW10: strcat(txt_buf, "Sharp LQ055T1SW10"); break; + case PANEL_SAM_AMS699VC01: strcat(txt_buf, "Samsung AMS699VC01"); break; + case PANEL_OEM_CLONE_6_2: strcat(txt_buf, "#FFDD00 OEM Clone 6.2\"#"); break; + case PANEL_OEM_CLONE_5_5: strcat(txt_buf, "#FFDD00 OEM Clone 5.5\"#"); break; + case PANEL_OEM_CLONE: strcat(txt_buf, "#FFDD00 OEM Clone#"); break; + case 0xCCCC: strcat(txt_buf, "#FFDD00 Failed to get info!#"); break; + + case 0x10000: // Custom ID for LCD OEM Clone for Switch OLED. + strcat(txt_buf, "#FFDD00 LCD OEM Clone 7\"#"); + break; + default: switch (display_id & 0xFF) { @@ -1202,17 +1226,16 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) s_printf(txt_buf + strlen(txt_buf), "\n#FF8000 ID:# #96FF00 %02X# %02X #96FF00 %02X#", nyx_str->info.panel_id & 0xFF, (nyx_str->info.panel_id >> 8) & 0xFF, (nyx_str->info.panel_id >> 16) & 0xFF); - touch_fw_info_t touch_fw; - touch_panel_info_t *touch_panel; - bool panel_ic_paired = false; - // Prepare touch panel/ic info. + touch_fw_info_t touch_fw; if (!touch_get_fw_info(&touch_fw)) { strcat(txt_buf, "\n\n#00DDFF Touch Panel:#\n#FF8000 Model:# "); - touch_panel = touch_get_panel_vendor(); - if (touch_panel) + touch_panel_info_t *touch_panel = touch_get_panel_vendor(); + if (touch_clone_oled) + strcat(txt_buf, "#FFDD00 OEM Clone TSP#"); + else if (touch_panel) { if ((u8)touch_panel->idx == (u8)-2) // Touch panel not found, print gpios. { @@ -1229,7 +1252,11 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) s_printf(txt_buf + strlen(txt_buf), "\n#FF8000 ID:# %02X.%02X.%02X.%02X (", (touch_fw.fw_id >> 24) & 0xFF, (touch_fw.fw_id >> 16) & 0xFF, (touch_fw.fw_id >> 8) & 0xFF, touch_fw.fw_id & 0xFF); + if (touch_clone_oled) + touch_fw.fw_id = 0xFFFFFFFF; + // Check panel pair info. + bool panel_ic_paired = false; switch (touch_fw.fw_id) { case 0x00100100: @@ -1237,6 +1264,7 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) if (touch_panel) panel_ic_paired = (u8)touch_panel->idx == (u8)-1; break; + case 0x00100200: // 4CD 1602. case 0x00120100: case 0x32000001: @@ -1244,6 +1272,7 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) if (touch_panel) panel_ic_paired = touch_panel->idx == 0; // NISSHA NFT-K12D. break; + // case 0x98000004: // New 6.2" panel? // case 0x50000001: // case 0x50000002: @@ -1251,24 +1280,28 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) // if (touch_panel) // panel_ic_paired = touch_panel->idx == 0; // break; + case 0x001A0300: case 0x32000102: strcat(txt_buf, "4CD60D/2"); if (touch_panel) panel_ic_paired = touch_panel->idx == 1; // GiS GGM6 B2X. break; + case 0x00290100: case 0x32000302: strcat(txt_buf, "4CD60D/3"); if (touch_panel) panel_ic_paired = touch_panel->idx == 2; // NISSHA NBF-K9A. break; + case 0x31051820: case 0x32000402: strcat(txt_buf, "4CD60D/4"); if (touch_panel) panel_ic_paired = touch_panel->idx == 3; // GiS 5.5". break; + case 0x32000501: case 0x33000502: case 0x33000503: @@ -1277,6 +1310,12 @@ static lv_res_t _create_window_hw_info_status(lv_obj_t *btn) if (touch_panel) panel_ic_paired = touch_panel->idx == 4; // Samsung BH2109. break; + + case 0xFFFFFFFF: // Custom for OLED clone. + strcat(txt_buf, "Clone"); + panel_ic_paired = true; + break; + default: strcat(txt_buf, "#FF8000 Contact me#"); break; @@ -1328,7 +1367,7 @@ static void _ipatch_process(u32 offset, u32 value) static lv_res_t _create_window_bootrom_info_status(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" Bootrom Info"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" Bootrom Info", NULL); lv_win_add_btn(win, NULL, SYMBOL_DOWNLOAD" Dump Bootrom", _bootrom_dump_window_action); lv_obj_t *desc = lv_cont_create(win, NULL); @@ -1360,7 +1399,7 @@ static lv_res_t _launch_lockpick_action(lv_obj_t *btns, const char * txt) { int btn_idx = lv_btnm_get_pressed(btns); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); if (btn_idx == 1) { @@ -1445,7 +1484,7 @@ static lv_res_t _create_mbox_emmc_sandisk_report(lv_obj_t * btn) lv_obj_align(lb_desc2, lb_desc, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#"); @@ -1455,7 +1494,7 @@ static lv_res_t _create_mbox_emmc_sandisk_report(lv_obj_t * btn) int res = sdmmc_storage_vendor_sandisk_report(&emmc_storage, buf); emmc_end(); - if (!res) + if (res) { lv_label_set_text(lb_desc, "#FFDD00 Device Report not supported!#"); lv_label_set_text(lb_desc2, " "); @@ -1582,7 +1621,7 @@ out: free (txt_buf); free (txt_buf2); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text. + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); // Important. After set_text. lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -1639,12 +1678,12 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench) // Re-initialize to update trimmers. sd_end(); - res = !sd_mount(); + res = sd_mount(); } else { storage = &emmc_storage; - res = !emmc_initialize(false); + res = emmc_initialize(false); if (!res) emmc_set_partition(EMMC_GPP); } @@ -1708,7 +1747,7 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench) while (data_remaining) { u32 time_taken = get_tmr_us(); - error = !sdmmc_storage_read(storage, sector_off + lba_curr, sector_num, (u8 *)MIXD_BUF_ALIGNED); + error = sdmmc_storage_read(storage, sector_off + lba_curr, sector_num, (u8 *)MIXD_BUF_ALIGNED); time_taken = get_tmr_us() - time_taken; timer += time_taken; @@ -1755,7 +1794,7 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench) while (data_remaining) { u32 time_taken = get_tmr_us(); - error = !sdmmc_storage_read(storage, sector_off + lba_curr, sector_num, (u8 *)MIXD_BUF_ALIGNED); + error = sdmmc_storage_read(storage, sector_off + lba_curr, sector_num, (u8 *)MIXD_BUF_ALIGNED); time_taken = get_tmr_us() - time_taken; timer += time_taken; @@ -1811,7 +1850,7 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench) for (u32 i = 0; i < rnd_off_cnt; i += 4) { // Generate new random numbers. - while (!se_rng_pseudo(random_numbers, SE_RNG_BLOCK_SIZE)) + while (se_rng_pseudo(random_numbers, SE_RNG_BLOCK_SIZE)) ; // Clamp offsets to 256MB range. random_offsets[i + 0] = random_numbers[0] % sct_rem_4kb; @@ -1830,7 +1869,7 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench) while (data_remaining) { u32 time_taken = get_tmr_us(); - error = !sdmmc_storage_read(storage, sector_off + random_offsets[lba_idx], sector_num, (u8 *)MIXD_BUF_ALIGNED); + error = sdmmc_storage_read(storage, sector_off + random_offsets[lba_idx], sector_num, (u8 *)MIXD_BUF_ALIGNED); time_taken = get_tmr_us() - time_taken; timer += time_taken; @@ -1890,9 +1929,9 @@ error: if (error) { if (error == -1) - s_printf(txt_buf + strlen(txt_buf), "\n#FFDD00 Aborted!#"); + s_printf(txt_buf + strlen(txt_buf), "\n#FFDD00 Aborted! #"); else - s_printf(txt_buf + strlen(txt_buf), "\n#FFDD00 IO Error occurred!#"); + s_printf(txt_buf + strlen(txt_buf), "\n#FFDD00 IO Error occurred! #"); lv_label_set_text(lbl_status, txt_buf); lv_obj_align(lbl_status, NULL, LV_ALIGN_CENTER, 0, 0); @@ -1929,7 +1968,7 @@ out: free(txt_buf); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text. + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); // Important. After set_text. lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); return LV_RES_OK; @@ -1951,7 +1990,7 @@ static lv_res_t _create_mbox_sd_bench(lv_obj_t * btn) static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" Internal eMMC Info"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" Internal eMMC Info", NULL); lv_win_add_btn(win, NULL, SYMBOL_CHIP" Benchmark", _create_mbox_emmc_bench); lv_obj_t *desc = lv_cont_create(win, NULL); @@ -1966,7 +2005,7 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) txt_buf[1] = 0; u16 *emmc_errors; - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#"); lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); @@ -1975,16 +2014,16 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) goto out_error; } - u32 speed = 0; + u32 bus_clock = 0; char *rsvd_blocks; char life_a_txt[8]; char life_b_txt[8]; + char bkops[64]; u32 cache = emmc_storage.ext_csd.cache_size; u32 life_a = emmc_storage.ext_csd.dev_life_est_a; u32 life_b = emmc_storage.ext_csd.dev_life_est_b; u16 card_type = emmc_storage.ext_csd.card_type; - char card_type_support[96]; - card_type_support[0] = 0; + char *max_bus_support = "Unknown"; // Identify manufacturer. Only official eMMCs. switch (emmc_storage.cid.manfid) @@ -2018,50 +2057,69 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) emmc_storage.cid.prv & 0xF, emmc_storage.cid.prv >> 4, emmc_storage.cid.serial, emmc_storage.cid.month, emmc_storage.cid.year); - if (card_type & EXT_CSD_CARD_TYPE_HS_26) - { - strcat(card_type_support, "HS26"); - speed = (26 << 16) | 26; - } - if (card_type & EXT_CSD_CARD_TYPE_HS_52) - { - strcat(card_type_support, ", HS52"); - speed = (52 << 16) | 52; - } - if (card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) - { - strcat(card_type_support, ", DDR52 1.8V"); - speed = (52 << 16) | 104; - } - if (card_type & EXT_CSD_CARD_TYPE_HS200_1_8V) - { - strcat(card_type_support, ", HS200 1.8V"); - speed = (200 << 16) | 200; - } if (card_type & EXT_CSD_CARD_TYPE_HS400_1_8V) + max_bus_support = "HS400"; + else if (card_type & EXT_CSD_CARD_TYPE_HS200_1_8V) + max_bus_support = "HS200"; + else if (card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) + max_bus_support = "DDR52"; + else if (card_type & EXT_CSD_CARD_TYPE_HS_52) + max_bus_support = "HS52"; + else if (card_type & EXT_CSD_CARD_TYPE_HS_26) + max_bus_support = "HS26"; + + if (emmc_storage.csd.busspeed == 400) + bus_clock = 200; + else + bus_clock = emmc_storage.csd.busspeed; // Except DDR52 where it's 26 MHz. + + strcpy(bkops, "-"); + if (emmc_storage.ext_csd.bkops) { - strcat(card_type_support, ", HS400 1.8V"); - speed = (200 << 16) | 400; + if (emmc_storage.ext_csd.bkops_en & EXT_CSD_BKOPS_AUTO) + { + strcpy(bkops, "Auto"); + if (emmc_storage.ext_csd.bkops_en & EXT_CSD_BKOPS_MANUAL) + strcat(bkops, " + Manual"); + } + else + strcpy(bkops, "Off"); + strcat(bkops, ": "); + + switch (emmc_storage.raw_ext_csd[EXT_CSD_BKOPS_STATUS]) + { + case 0: + strcat(bkops, "OK"); + break; + case 1: + strcat(bkops, "Minor"); + break; + case 2: + strcat(bkops, "#FFDD00 Degraded#"); + break; + case 3: + strcat(bkops, "#FFDD00 Critical#"); + break; + } } strcpy(life_a_txt, "-"); strcpy(life_b_txt, "-"); - // Normalize cells life. - if (life_a) // SK Hynix is 0 (undefined). + // Normalize cells life (Used -> Left). + if (life_a) // If 0 no NAND Type A. { - life_a--; - life_a = (10 - life_a) * 10; + life_a = (10 - (life_a - 1)) * 10; s_printf(life_a_txt, "%d%%", life_a); } - if (life_b) // Toshiba is 0 (undefined). + if (life_b) // If 0 no NAND Type B. { - life_b--; - life_b = (10 - life_b) * 10; + life_b = (10 - (life_b - 1)) * 10; s_printf(life_b_txt, "%d%%", life_b); } + // Reserved blocks used. switch (emmc_storage.ext_csd.pre_eol_info) { case 1: @@ -2079,12 +2137,13 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) } s_printf(txt_buf + strlen(txt_buf), - "#00DDFF V1.%d (rev 1.%d)#\n%02X\n%d MB/s (%d MHz)\n%d MB/s\n%s\n%d %s\n%d MiB\nA: %s, B: %s\n%s", + "#00DDFF V1.%d (rev 1.%d)#\n%02X\n%s\n%d MB/s (%d MHz)\n%d MiB\n%d %s\n\n%s\nA: %s, B: %s\n%s", emmc_storage.ext_csd.ext_struct, emmc_storage.ext_csd.rev, - emmc_storage.csd.cmdclass, speed & 0xFFFF, (speed >> 16) & 0xFFFF, - emmc_storage.csd.busspeed, card_type_support, - !(cache % 1024) ? (cache / 1024) : cache, !(cache % 1024) ? "MiB" : "KiB", + emmc_storage.csd.cmdclass, max_bus_support, + emmc_storage.csd.busspeed, bus_clock, emmc_storage.ext_csd.max_enh_mult * EMMC_BLOCKSIZE / 1024, + !(cache % 1024) ? (cache / 1024) : cache, !(cache % 1024) ? "MiB" : "KiB", + bkops, life_a_txt, life_b_txt, rsvd_blocks); lv_label_set_static_text(lb_desc, @@ -2096,25 +2155,25 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) "Month/Year:\n\n" "#00DDFF Ext CSD:#\n" "Cmd Classes:\n" - "Max Rate:\n" + "Max Bus Rate:\n" "Current Rate:\n" - "Type Support:\n\n" - "Write Cache:\n" "Enhanced Area:\n" + "Write Cache:\n\n" + "Maintenance:\n" "Estimated Life:\n" "Reserved Used:" ); lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); - lv_obj_t *val = lv_cont_create(win, NULL); - lv_obj_set_size(val, LV_HOR_RES / 11 * 3, LV_VER_RES - (LV_DPI * 11 / 7) - 5); + lv_obj_t *info = lv_cont_create(win, NULL); + lv_obj_set_size(info, LV_HOR_RES / 11 * 3, LV_VER_RES - (LV_DPI * 11 / 7) - 5); - lv_obj_t * lb_val = lv_label_create(val, lb_desc); + lv_obj_t * lb_val = lv_label_create(info, lb_desc); lv_label_set_text(lb_val, txt_buf); - lv_obj_set_width(lb_val, lv_obj_get_width(val)); - lv_obj_align(val, desc, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + lv_obj_set_width(lb_val, lv_obj_get_width(info)); + lv_obj_align(info, desc, LV_ALIGN_OUT_RIGHT_MID, 0, 0); lv_obj_t *desc2 = lv_cont_create(win, NULL); lv_obj_set_size(desc2, LV_HOR_RES / 2 / 4 * 4, LV_VER_RES - (LV_DPI * 11 / 7) - 5); @@ -2170,7 +2229,7 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn) lv_label_set_text(lb_desc2, txt_buf); lv_obj_set_width(lb_desc2, lv_obj_get_width(desc2)); - lv_obj_align(desc2, val, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 6, 0); + lv_obj_align(desc2, info, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 6, 0); emmc_errors = emmc_get_error_count(); if (emmc_get_mode() < EMMC_MMC_HS400 || @@ -2203,7 +2262,7 @@ out_error: emmc_errors[EMMC_ERROR_RW_RETRY]); lv_mbox_set_text(mbox, txt_buf); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -2217,7 +2276,7 @@ out_error: static lv_res_t _create_window_sdcard_info_status(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_SD" microSD Card Info"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_SD" microSD Card Info", NULL); lv_win_add_btn(win, NULL, SYMBOL_SD" Benchmark", _create_mbox_sd_bench); lv_obj_t *desc = lv_cont_create(win, NULL); @@ -2235,7 +2294,7 @@ static lv_res_t _create_window_sdcard_info_status(lv_obj_t *btn) manual_system_maintenance(true); - if (!sd_mount()) + if (sd_mount()) { lv_label_set_text(lb_desc, "#FFDD00 Failed to init SD!#"); goto failed; @@ -2622,7 +2681,7 @@ failed: static lv_res_t _create_window_battery_status(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_BATTERY_FULL" Battery Info"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_BATTERY_FULL" Battery Info", NULL); lv_win_add_btn(win, NULL, SYMBOL_DOWNLOAD" Dump Fuel Regs", _battery_dump_window_action); lv_obj_t *desc = lv_cont_create(win, NULL); @@ -2834,7 +2893,7 @@ static lv_res_t _create_window_battery_status(lv_obj_t *btn) bool inserted; u32 wattage = 0; usb_pd_objects_t usb_pd; - bm92t36_get_sink_info(&inserted, &usb_pd); + bm92t36_get_source_info(&inserted, &usb_pd); strcat(txt_buf, inserted ? "Connected" : "Disconnected"); // Select 5V is no PD contract. @@ -2845,9 +2904,8 @@ static lv_res_t _create_window_battery_status(lv_obj_t *btn) if (!usb_pd.pdo_no) strcat(txt_buf, "\nNon PD"); - // Limit to 6 profiles so it can fit. + // Show 6 profiles max so they can fit. usb_pd.pdo_no = MIN(usb_pd.pdo_no, 6); - for (u32 i = 0; i < usb_pd.pdo_no; i++) { bool selected = @@ -2881,7 +2939,7 @@ static bool _lockpick_exists_check() bool found = false; void *buf = malloc(0x200); - if (sd_mount()) + if (!sd_mount()) { FIL fp; if (f_open(&fp, "bootloader/payloads/Lockpick_RCM.bin", FA_READ)) @@ -2948,7 +3006,8 @@ void create_tab_info(lv_theme_t *th, lv_obj_t *parent) if (hekate_bg || hekate_bg_etc) { lv_btn_set_style(btn, LV_BTN_STYLE_REL, &btn_transp_rel); - lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_transp_pr); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, &btn_transp_pr); + lv_btn_set_style(btn, LV_BTN_STYLE_INA, &btn_transp_ina); } lv_obj_t *label_btn = lv_label_create(btn, NULL); lv_btn_set_fit(btn, true, true); @@ -2988,13 +3047,13 @@ void create_tab_info(lv_theme_t *th, lv_obj_t *parent) static lv_style_t line_style; lv_style_copy(&line_style, th->line.decor); - line_style.line.color = LV_COLOR_HEX(0x444444); + line_style.line.color = LV_COLOR_HEX(theme_bg_color ? (theme_bg_color + 0x171717) : 0x343434); line_sep = lv_line_create(h1, line_sep); lv_obj_align(line_sep, label_txt2, LV_ALIGN_OUT_BOTTOM_LEFT, -(LV_DPI / 4), LV_DPI / 16); lv_line_set_style(line_sep, &line_style); - // Create Fuses button. + // Create HW info button. lv_obj_t *btn3 = lv_btn_create(h1, btn); label_btn = lv_label_create(btn3, NULL); lv_btn_set_fit(btn3, true, true); diff --git a/nyx/nyx_gui/frontend/gui_options.c b/nyx/nyx_gui/frontend/gui_options.c index 983639c8..31cd927c 100644 --- a/nyx/nyx_gui/frontend/gui_options.c +++ b/nyx/nyx_gui/frontend/gui_options.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -228,7 +228,7 @@ static void _create_autoboot_window() // Parse hekate main configuration. LIST_INIT(ini_sections); - if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) + if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) { LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) { @@ -272,7 +272,7 @@ static void _create_autoboot_window() // Parse all .ini files in ini folder. LIST_INIT(ini_list_sections); - if (ini_parse(&ini_list_sections, "bootloader/ini", true)) + if (!ini_parse(&ini_list_sections, "bootloader/ini", true)) { LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_list_sections, link) { @@ -373,31 +373,40 @@ static lv_res_t _save_nyx_options_action(lv_obj_t *btn) return LV_RES_OK; } -void create_flat_button(lv_obj_t *parent, lv_obj_t *btn, lv_color_t color, lv_action_t action) +void create_flat_button(lv_obj_t *btn, int color_idx, lv_action_t action) { + lv_color_t color = color_idx ? lv_color_hsv_to_rgb(color_idx, 100, 100) : lv_color_hsv_to_rgb(53, 8, 90); lv_style_t *btn_onoff_rel_hos_style = malloc(sizeof(lv_style_t)); - lv_style_t *btn_onoff_pr_hos_style = malloc(sizeof(lv_style_t)); + lv_style_t *btn_onoff_pr_hos_style = malloc(sizeof(lv_style_t)); lv_style_copy(btn_onoff_rel_hos_style, lv_theme_get_current()->btn.rel); - btn_onoff_rel_hos_style->body.main_color = color; - btn_onoff_rel_hos_style->body.grad_color = btn_onoff_rel_hos_style->body.main_color; + btn_onoff_rel_hos_style->body.main_color = color; + btn_onoff_rel_hos_style->body.grad_color = btn_onoff_rel_hos_style->body.main_color; btn_onoff_rel_hos_style->body.padding.hor = 0; - btn_onoff_rel_hos_style->body.radius = 0; + btn_onoff_rel_hos_style->body.radius = 0; + + if (color_idx == 167) + { + btn_onoff_rel_hos_style->body.border.color = LV_COLOR_HEX(0x000000); + btn_onoff_rel_hos_style->body.border.opa = LV_OPA_20; + btn_onoff_rel_hos_style->body.border.width = 3; + } lv_style_copy(btn_onoff_pr_hos_style, lv_theme_get_current()->btn.pr); - btn_onoff_pr_hos_style->body.main_color = color; - btn_onoff_pr_hos_style->body.grad_color = btn_onoff_pr_hos_style->body.main_color; - btn_onoff_pr_hos_style->body.padding.hor = 0; - btn_onoff_pr_hos_style->body.border.color = LV_COLOR_GRAY; + btn_onoff_pr_hos_style->body.main_color = color; + btn_onoff_pr_hos_style->body.grad_color = btn_onoff_pr_hos_style->body.main_color; + btn_onoff_pr_hos_style->body.padding.hor = 0; + btn_onoff_pr_hos_style->body.border.color = LV_COLOR_HEX(0xFFFFFF); + btn_onoff_pr_hos_style->body.border.opa = LV_OPA_50; btn_onoff_pr_hos_style->body.border.width = 4; - btn_onoff_pr_hos_style->body.radius = 0; + btn_onoff_pr_hos_style->body.radius = 0; - lv_btn_set_style(btn, LV_BTN_STYLE_REL, btn_onoff_rel_hos_style); - lv_btn_set_style(btn, LV_BTN_STYLE_PR, btn_onoff_pr_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_REL, btn_onoff_rel_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_PR, btn_onoff_pr_hos_style); lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, btn_onoff_rel_hos_style); - lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, btn_onoff_pr_hos_style); + lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, btn_onoff_pr_hos_style); - lv_btn_set_fit(btn, false, true); - lv_obj_set_width(btn, lv_obj_get_height(btn)); + lv_btn_set_fit(btn, false, false); + lv_obj_set_size(btn, LV_DPI * 7 / 11, LV_DPI * 7 / 11); lv_btn_set_toggle(btn, true); if (action) @@ -408,6 +417,10 @@ typedef struct _color_test_ctxt { u32 bg; u16 hue; + u8 r; + u8 g; + u8 b; + lv_obj_t *window; lv_obj_t *header1; lv_obj_t *header2; @@ -417,11 +430,25 @@ typedef struct _color_test_ctxt lv_obj_t *button; lv_obj_t *hue_slider; lv_obj_t *hue_label; + + lv_obj_t *r_slider; + lv_obj_t *r_label; + lv_obj_t *g_slider; + lv_obj_t *g_label; + lv_obj_t *b_slider; + lv_obj_t *b_label; + + lv_style_t box_style; + lv_obj_t *box; + + lv_obj_t *btn_reset; + lv_obj_t *btn_apply; + lv_obj_t *btn_black; } color_test_ctxt; color_test_ctxt color_test; -static lv_res_t _save_theme_color_action(lv_obj_t *btn) +static lv_res_t _action_win_nyx_colors_save(lv_obj_t *btn) { n_cfg.theme_bg = color_test.bg; n_cfg.theme_color = color_test.hue; @@ -434,12 +461,23 @@ static lv_res_t _save_theme_color_action(lv_obj_t *btn) return LV_RES_OK; } -static void _show_new_nyx_color(u32 bg, u16 hue, bool update_bg) +static void _show_new_nyx_color(bool update_bg) { - lv_color_t bgc = LV_COLOR_HEX(bg); - lv_color_t bgc_light = LV_COLOR_HEX(bg ? (bg + 0x101010) : 0x2D2D2D); - lv_color_t bg_border = LV_COLOR_HEX(bg ? (bg + 0x202020) : 0x3D3D3D); - lv_color_t color = lv_color_hsv_to_rgb(hue, 100, 100); + u32 bg = color_test.bg; + u16 hue = color_test.hue; + + lv_color_t bgc = LV_COLOR_HEX(bg); // COLOR_HOS_BG. + lv_color_t bgc_light = LV_COLOR_HEX(bg ? (bg + 0x101010) : 0x2D2D2D); // COLOR_HOS_BG_LIGHT. + lv_color_t bgc_press = LV_COLOR_HEX(bg ? (bg + 0x232323) : 0x404040); // 0x505050. + lv_color_t bg_border = LV_COLOR_HEX(bg ? (bg + 0x202020) : 0x3D3D3D); // COLOR_HOS_BG_LIGHTER. + lv_color_t color = hue ? lv_color_hsv_to_rgb(hue, 100, 100) : lv_color_hsv_to_rgb(53, 8, 90); + + static lv_style_t btn_tgl_pr_test; + lv_style_copy(&btn_tgl_pr_test, lv_btn_get_style(color_test.button, LV_BTN_STATE_TGL_PR)); + btn_tgl_pr_test.body.main_color = bgc_press; + btn_tgl_pr_test.body.grad_color = btn_tgl_pr_test.body.main_color; + btn_tgl_pr_test.body.border.color = color; + btn_tgl_pr_test.text.color = color; if (update_bg) { @@ -466,6 +504,27 @@ static void _show_new_nyx_color(u32 bg, u16 hue, bool update_bg) hdr2_bg_test.body.main_color = bgc; hdr2_bg_test.body.grad_color = hdr2_bg_test.body.main_color; lv_cont_set_style(color_test.header2, &hdr2_bg_test); + + static lv_style_t btn_tgl_rel_test; + lv_style_copy(&btn_tgl_rel_test, lv_btn_get_style(color_test.btn_reset, LV_BTN_STATE_REL)); + btn_tgl_rel_test.body.main_color = bgc_light; + btn_tgl_rel_test.body.grad_color = btn_tgl_rel_test.body.main_color; + lv_btn_set_style(color_test.btn_reset, LV_BTN_STATE_REL, &btn_tgl_rel_test); + lv_btn_set_style(color_test.btn_reset, LV_BTN_STATE_PR, &btn_tgl_pr_test); + lv_btn_set_style(color_test.btn_apply, LV_BTN_STATE_REL, &btn_tgl_rel_test); + lv_btn_set_style(color_test.btn_apply, LV_BTN_STATE_PR, &btn_tgl_pr_test); + lv_btn_set_style(color_test.btn_black, LV_BTN_STATE_REL, &btn_tgl_rel_test); + lv_btn_set_style(color_test.btn_black, LV_BTN_STATE_PR, &btn_tgl_pr_test); + + static lv_style_t slider_bg; + lv_style_copy(&slider_bg, lv_slider_get_style(color_test.slider, LV_SLIDER_STYLE_BG)); + slider_bg.body.main_color = bg_border; + slider_bg.body.grad_color = slider_bg.body.main_color; + lv_slider_set_style(color_test.hue_slider, LV_SLIDER_STYLE_BG, &slider_bg); + lv_slider_set_style(color_test.slider, LV_SLIDER_STYLE_BG, &slider_bg); + lv_slider_set_style(color_test.r_slider, LV_SLIDER_STYLE_BG, &slider_bg); + lv_slider_set_style(color_test.g_slider, LV_SLIDER_STYLE_BG, &slider_bg); + lv_slider_set_style(color_test.b_slider, LV_SLIDER_STYLE_BG, &slider_bg); } else { @@ -474,29 +533,29 @@ static void _show_new_nyx_color(u32 bg, u16 hue, bool update_bg) txt_test.text.color = color; lv_obj_set_style(color_test.label, &txt_test); lv_obj_set_style(color_test.icons, &txt_test); + + static lv_style_t slider_knb; + lv_style_copy(&slider_knb, lv_slider_get_style(color_test.slider, LV_SLIDER_STYLE_KNOB)); + slider_knb.body.main_color = color; + slider_knb.body.grad_color = slider_knb.body.main_color; + lv_slider_set_style(color_test.hue_slider, LV_SLIDER_STYLE_KNOB, &slider_knb); + lv_slider_set_style(color_test.slider, LV_SLIDER_STYLE_KNOB, &slider_knb); + lv_slider_set_style(color_test.r_slider, LV_SLIDER_STYLE_KNOB, &slider_knb); + lv_slider_set_style(color_test.g_slider, LV_SLIDER_STYLE_KNOB, &slider_knb); + lv_slider_set_style(color_test.b_slider, LV_SLIDER_STYLE_KNOB, &slider_knb); + + static lv_style_t slider_ind; + lv_style_copy(&slider_ind, lv_slider_get_style(color_test.slider, LV_SLIDER_STYLE_INDIC)); + slider_ind.body.main_color = hue ? lv_color_hsv_to_rgb(hue, 100, 72) : lv_color_hsv_to_rgb(53, 8, 65); + slider_ind.body.grad_color = slider_ind.body.main_color; + lv_slider_set_style(color_test.hue_slider, LV_SLIDER_STYLE_INDIC, &slider_ind); + lv_slider_set_style(color_test.slider, LV_SLIDER_STYLE_INDIC, &slider_ind); + lv_slider_set_style(color_test.r_slider, LV_SLIDER_STYLE_INDIC, &slider_ind); + lv_slider_set_style(color_test.g_slider, LV_SLIDER_STYLE_INDIC, &slider_ind); + lv_slider_set_style(color_test.b_slider, LV_SLIDER_STYLE_INDIC, &slider_ind); } - static lv_style_t btn_tgl_pr_test; - lv_style_copy(&btn_tgl_pr_test, lv_btn_get_style(color_test.button, LV_BTN_STATE_TGL_PR)); - btn_tgl_pr_test.body.main_color = bgc_light; - btn_tgl_pr_test.body.grad_color = btn_tgl_pr_test.body.main_color; - btn_tgl_pr_test.body.border.color = color; - btn_tgl_pr_test.text.color = color; lv_btn_set_style(color_test.button, LV_BTN_STATE_TGL_PR, &btn_tgl_pr_test); - - static lv_style_t slider_bg, slider_test, slider_ind; - lv_style_copy(&slider_bg, lv_slider_get_style(color_test.slider, LV_SLIDER_STYLE_BG)); - lv_style_copy(&slider_test, lv_slider_get_style(color_test.slider, LV_SLIDER_STYLE_KNOB)); - lv_style_copy(&slider_ind, lv_slider_get_style(color_test.slider, LV_SLIDER_STYLE_INDIC)); - slider_bg.body.main_color = bg_border; - slider_bg.body.grad_color = slider_bg.body.main_color; - slider_test.body.main_color = color; - slider_test.body.grad_color = slider_test.body.main_color; - slider_ind.body.main_color = lv_color_hsv_to_rgb(hue, 100, 72); - slider_ind.body.grad_color = slider_ind.body.main_color; - lv_slider_set_style(color_test.slider, LV_SLIDER_STYLE_BG, &slider_bg); - lv_slider_set_style(color_test.slider, LV_SLIDER_STYLE_KNOB, &slider_test); - lv_slider_set_style(color_test.slider, LV_SLIDER_STYLE_INDIC, &slider_ind); } static lv_res_t _slider_hue_action(lv_obj_t *slider) @@ -504,7 +563,9 @@ static lv_res_t _slider_hue_action(lv_obj_t *slider) if (color_test.hue != lv_slider_get_value(slider)) { color_test.hue = lv_slider_get_value(slider); - _show_new_nyx_color(color_test.bg, color_test.hue, false); + + _show_new_nyx_color(false); + char hue[8]; s_printf(hue, "%03d", color_test.hue); lv_label_set_text(color_test.hue_label, hue); @@ -513,14 +574,97 @@ static lv_res_t _slider_hue_action(lv_obj_t *slider) return LV_RES_OK; } -static lv_res_t _preset_bg_action(lv_obj_t *btn) +static lv_res_t _slider_r_action(lv_obj_t *slider) { - //! TODO: Support a range? - if (color_test.bg) - color_test.bg = 0; - else - color_test.bg = COLOR_HOS_BG; - _show_new_nyx_color(color_test.bg, color_test.hue, true); + if (color_test.r != lv_slider_get_value(slider)) + { + color_test.r = lv_slider_get_value(slider); + color_test.box_style.body.main_color = LV_COLOR_HEX((color_test.r << 16) | (color_test.g << 8) | color_test.b); + color_test.box_style.body.grad_color = color_test.box_style.body.main_color; + lv_obj_set_style(color_test.box, &color_test.box_style); + + char shade[8]; + s_printf(shade, "%03d", color_test.r); + lv_label_set_text(color_test.r_label, shade); + } + + return LV_RES_OK; +} + +static lv_res_t _slider_g_action(lv_obj_t *slider) +{ + if (color_test.g != lv_slider_get_value(slider)) + { + color_test.g = lv_slider_get_value(slider); + color_test.box_style.body.main_color = LV_COLOR_HEX((color_test.r << 16) | (color_test.g << 8) | color_test.b); + color_test.box_style.body.grad_color = color_test.box_style.body.main_color; + lv_obj_set_style(color_test.box, &color_test.box_style); + + char shade[8]; + s_printf(shade, "%03d", color_test.g); + lv_label_set_text(color_test.g_label, shade); + } + + return LV_RES_OK; +} + +static lv_res_t _slider_b_action(lv_obj_t *slider) +{ + if (color_test.b != lv_slider_get_value(slider)) + { + color_test.b = lv_slider_get_value(slider); + color_test.box_style.body.main_color = LV_COLOR_HEX((color_test.r << 16) | (color_test.g << 8) | color_test.b); + color_test.box_style.body.grad_color = color_test.box_style.body.main_color; + lv_obj_set_style(color_test.box, &color_test.box_style); + + char shade[8]; + s_printf(shade, "%03d", color_test.b); + lv_label_set_text(color_test.b_label, shade); + } + + return LV_RES_OK; +} + +static lv_res_t _preset_bg_apply(lv_obj_t *btn) +{ + color_test.bg = (color_test.r << 16) | (color_test.g << 8) | color_test.b; + + _show_new_nyx_color(true); + + return LV_RES_OK; +} + +static lv_res_t _preset_bg_black(lv_obj_t *btn) +{ + color_test.bg = 0; + + _show_new_nyx_color(true); + + return LV_RES_OK; +} + +static lv_res_t _preset_bg_reset(lv_obj_t *btn) +{ + color_test.r = 0x2D; + color_test.g = 0x2D; + color_test.b = 0x2D; + color_test.bg = 0x2D2D2D; + + color_test.box_style.body.main_color = LV_COLOR_HEX(color_test.bg); + color_test.box_style.body.grad_color = color_test.box_style.body.main_color; + lv_obj_set_style(color_test.box, &color_test.box_style); + + lv_bar_set_value(color_test.r_slider, color_test.r); + lv_bar_set_value(color_test.g_slider, color_test.g); + lv_bar_set_value(color_test.b_slider, color_test.b); + + char shade[8]; + s_printf(shade, "%03d", color_test.r); + lv_label_set_text(color_test.r_label, shade); + lv_label_set_text(color_test.g_label, shade); + lv_label_set_text(color_test.b_label, shade); + + _show_new_nyx_color(true); return LV_RES_OK; } @@ -532,95 +676,194 @@ static lv_res_t _preset_hue_action(lv_obj_t *btn) if (color_test.hue != ext->idx) { color_test.hue = ext->idx; - _show_new_nyx_color(color_test.bg, color_test.hue, false); + char hue[8]; s_printf(hue, "%03d", color_test.hue); lv_label_set_text(color_test.hue_label, hue); lv_bar_set_value(color_test.hue_slider, color_test.hue); + + _show_new_nyx_color(false); } return LV_RES_OK; } -static const u16 theme_colors[17] = { - 4, 13, 23, 33, 43, 54, 66, 89, 124, 167, 187, 200, 208, 231, 261, 291, 341 +static const u16 theme_colors[18] = { + 0, 4, 13, 23, 33, 43, 54, 66, 89, 124, 167, 187, 200, 208, 231, 261, 291, 341 }; +lv_res_t _action_win_nyx_colors_close(lv_obj_t * btn) +{ + lv_obj_set_opa_scale(status_bar.mid, LV_OPA_COVER); + lv_obj_set_click(status_bar.mid, true); + + return nyx_win_close_action(btn); +} + static lv_res_t _create_window_nyx_colors(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_COPY" Nyx Color Theme"); - lv_win_add_btn(win, NULL, SYMBOL_HINT" Toggle Background", _preset_bg_action); - lv_win_add_btn(win, NULL, SYMBOL_SAVE" Save & Reload", _save_theme_color_action); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_COPY" Nyx Color Theme", _action_win_nyx_colors_close); + lv_win_add_btn(win, NULL, SYMBOL_SAVE" Save & Reload", _action_win_nyx_colors_save); color_test.window = win; // Set current theme colors. color_test.bg = n_cfg.theme_bg; color_test.hue = n_cfg.theme_color; + u32 bg = n_cfg.theme_bg ? n_cfg.theme_bg : 0x2D2D2D; + color_test.r = (bg >> 16) & 0xFF; + color_test.g = (bg >> 8) & 0xFF; + color_test.b = (bg >> 0) & 0xFF; - lv_obj_t *sep = lv_label_create(win, NULL); - lv_label_set_static_text(sep, ""); - lv_obj_align(sep, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); + lv_style_copy(&color_test.box_style, &lv_style_plain_color); + color_test.box_style.body.main_color = LV_COLOR_HEX(color_test.bg); + color_test.box_style.body.grad_color = color_test.box_style.body.main_color; + color_test.box_style.body.border.color = LV_COLOR_HEX(0xFFFFFF); + color_test.box_style.body.border.opa = LV_OPA_20; + color_test.box_style.body.border.width = 2; // Create container to keep content inside. lv_obj_t *h1 = lv_cont_create(win, NULL); - lv_obj_set_size(h1, LV_HOR_RES - (LV_DPI * 8 / 10), LV_VER_RES / 7); + lv_obj_set_size(h1, LV_DPI * 299 / 25, LV_DPI * 27 / 26); color_test.header1 = h1; + lv_obj_t *acc_label = lv_label_create(h1, NULL); + lv_label_set_static_text(acc_label, "Accent color:"); + // Create color preset buttons. lv_obj_t *color_btn = lv_btn_create(h1, NULL); lv_btn_ext_t *ext = lv_obj_get_ext_attr(color_btn); ext->idx = theme_colors[0]; - create_flat_button(h1, color_btn, lv_color_hsv_to_rgb(theme_colors[0], 100, 100), _preset_hue_action); + create_flat_button(color_btn, ext->idx, _preset_hue_action); + lv_obj_align(color_btn, acc_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 10); lv_obj_t *color_btn2; - for (u32 i = 1; i < 17; i++) + for (u32 i = 1; i < ARRAY_SIZE(theme_colors); i++) { color_btn2 = lv_btn_create(h1, NULL); ext = lv_obj_get_ext_attr(color_btn2); ext->idx = theme_colors[i]; - create_flat_button(h1, color_btn2, lv_color_hsv_to_rgb(theme_colors[i], 100, 100), _preset_hue_action); + create_flat_button(color_btn2, ext->idx, _preset_hue_action); lv_obj_align(color_btn2, color_btn, LV_ALIGN_OUT_RIGHT_MID, 0, 0); color_btn = color_btn2; } - lv_obj_align(h1, sep, LV_ALIGN_OUT_BOTTOM_MID, 0, LV_DPI / 4); + lv_obj_align(h1, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 5); // Create hue slider. - lv_obj_t * slider = lv_slider_create(win, NULL); - lv_obj_set_width(slider, 1070); - lv_obj_set_height(slider, LV_DPI * 4 / 10); - lv_bar_set_range(slider, 0, 359); - lv_bar_set_value(slider, color_test.hue); - lv_slider_set_action(slider, _slider_hue_action); - lv_obj_align(slider, h1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); - color_test.hue_slider = slider; + lv_obj_t *h_slider = lv_slider_create(win, NULL); + lv_obj_set_width(h_slider, LV_DPI * 213 / 20); + lv_obj_set_height(h_slider, LV_DPI * 4 / 10); + lv_bar_set_range(h_slider, 0, 359); + lv_bar_set_value(h_slider, color_test.hue); + lv_slider_set_action(h_slider, _slider_hue_action); + lv_obj_align(h_slider, h1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 5); + color_test.hue_slider = h_slider; // Create hue label. lv_obj_t *hue_text_label = lv_label_create(win, NULL); - lv_obj_align(hue_text_label, slider, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 24 / 100, 0); - char hue[8]; - s_printf(hue, "%03d", color_test.hue); - lv_label_set_text(hue_text_label, hue); + lv_obj_align(hue_text_label, h_slider, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 24 / 100, 0); + char txt[8]; + s_printf(txt, "%03d", color_test.hue); + lv_label_set_text(hue_text_label, txt); color_test.hue_label = hue_text_label; + lv_obj_t *bg_label = lv_label_create(win, NULL); + lv_label_set_static_text(bg_label, "Theme color:"); + lv_obj_align(bg_label, h_slider, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 6 / 25); + + // Create red slider. + lv_obj_t *r_slider = lv_slider_create(win, NULL); + lv_obj_set_width(r_slider, LV_DPI * 85 / 16); + lv_obj_set_height(r_slider, LV_DPI * 4 / 10); + lv_bar_set_range(r_slider, 11, 100); + lv_bar_set_value(r_slider, color_test.r); + lv_slider_set_action(r_slider, _slider_r_action); + lv_obj_align(r_slider, bg_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 21); + color_test.r_slider = r_slider; + + // Create red label. + lv_obj_t *r_text_label = lv_label_create(win, NULL); + lv_obj_align(r_text_label, r_slider, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 24 / 100, 0); + s_printf(txt, "%03d", color_test.r); + lv_label_set_text(r_text_label, txt); + color_test.r_label = r_text_label; + + // Create green slider. + lv_obj_t *g_slider = lv_slider_create(win, r_slider); + lv_bar_set_value(g_slider, color_test.g); + lv_slider_set_action(g_slider, _slider_g_action); + lv_obj_align(g_slider, r_slider, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 7); + color_test.g_slider = g_slider; + + // Create green label. + lv_obj_t *g_text_label = lv_label_create(win, NULL); + lv_obj_align(g_text_label, g_slider, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 24 / 100, 0); + s_printf(txt, "%03d", color_test.g); + lv_label_set_text(g_text_label, txt); + color_test.g_label = g_text_label; + + // Create blue slider. + lv_obj_t *b_slider = lv_slider_create(win, r_slider); + lv_bar_set_value(b_slider, color_test.b); + lv_slider_set_action(b_slider, _slider_b_action); + lv_obj_align(b_slider, g_slider, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 7); + color_test.b_slider = b_slider; + + // Create blue label. + lv_obj_t *b_text_label = lv_label_create(win, NULL); + lv_obj_align(b_text_label, b_slider, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 24 / 100, 0); + s_printf(txt, "%03d", color_test.b); + lv_label_set_text(b_text_label, txt); + color_test.b_label = b_text_label; + + // Create theme color box. + lv_obj_t * bg_box = lv_obj_create(win, NULL); + lv_obj_set_size(bg_box, LV_DPI * 10 / 7, LV_DPI * 18 / 13); + lv_obj_align(bg_box, r_text_label, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI / 4, 0); + lv_obj_set_style(bg_box, &color_test.box_style); + color_test.box = bg_box; + + // Create theme color buttons. + lv_obj_t *btn_reset = lv_btn_create(win, NULL); + lv_obj_t *label_btn = lv_label_create(btn_reset, NULL); + lv_label_set_static_text(label_btn, SYMBOL_REFRESH" Grey"); + lv_btn_set_fit(btn_reset, false, true); + lv_obj_set_width(btn_reset, LV_DPI * 5 / 3); + lv_btn_set_action(btn_reset, LV_BTN_ACTION_CLICK, _preset_bg_reset); + lv_obj_align(btn_reset, bg_box, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI / 5, 0); + color_test.btn_reset = btn_reset; + + lv_obj_t *btn_black = lv_btn_create(win, btn_reset); + label_btn = lv_label_create(btn_black, NULL); + lv_label_set_static_text(label_btn, SYMBOL_BRIGHTNESS" Black"); + lv_btn_set_action(btn_black, LV_BTN_ACTION_CLICK, _preset_bg_black); + lv_obj_align(btn_black, btn_reset, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI / 5, 0); + color_test.btn_black = btn_black; + + lv_obj_t *btn_apply = lv_btn_create(win, btn_reset); + label_btn = lv_label_create(btn_apply, NULL); + lv_label_set_static_text(label_btn, SYMBOL_LIST" Custom Color"); + lv_obj_set_width(btn_apply, LV_DPI * 10 / 3 + LV_DPI / 5); + lv_btn_set_action(btn_apply, LV_BTN_ACTION_CLICK, _preset_bg_apply); + lv_obj_align(btn_apply, btn_reset, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 7); + color_test.btn_apply = btn_apply; + // Create sample text. lv_obj_t *h2 = lv_cont_create(win, NULL); - lv_obj_set_size(h2, LV_HOR_RES - (LV_DPI * 8 / 10), LV_VER_RES / 3); - lv_obj_align(h2, slider, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI); + lv_obj_set_size(h2, LV_DPI * 12, LV_DPI * 18 / 10); + lv_obj_align(h2, b_slider, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 6 / 25); color_test.header2 = h2; lv_obj_t *lbl_sample = lv_label_create(h2, NULL); - lv_label_set_static_text(lbl_sample, "Sample:"); + lv_label_set_static_text(lbl_sample, "Accent sample:"); lv_obj_t *lbl_test = lv_label_create(h2, NULL); lv_label_set_long_mode(lbl_test, LV_LABEL_LONG_BREAK); lv_label_set_static_text(lbl_test, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " - "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " - "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris " - "nisi ut aliquip ex ea commodo consequat."); - lv_obj_set_width(lbl_test, lv_obj_get_width(h2) - LV_DPI * 6 / 10); - lv_obj_align(lbl_test, lbl_sample, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 5); + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); + lv_obj_set_width(lbl_test, LV_DPI * 261 / 23); + lv_obj_align(lbl_test, lbl_sample, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 34); color_test.label = lbl_test; // Create sample icons. @@ -628,12 +871,12 @@ static lv_res_t _create_window_nyx_colors(lv_obj_t *btn) lv_label_set_static_text(lbl_icons, SYMBOL_BRIGHTNESS SYMBOL_CHARGE SYMBOL_FILE SYMBOL_DRIVE SYMBOL_FILE_CODE SYMBOL_EDIT SYMBOL_HINT SYMBOL_DRIVE SYMBOL_KEYBOARD SYMBOL_POWER); - lv_obj_align(lbl_icons, lbl_test, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 2 / 5); + lv_obj_align(lbl_icons, lbl_test, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 5); color_test.icons = lbl_icons; // Create sample slider. lv_obj_t *slider_test = lv_slider_create(h2, NULL); - lv_obj_align(slider_test, lbl_test, LV_ALIGN_OUT_BOTTOM_MID, 0, LV_DPI * 2 / 5); + lv_obj_align(slider_test, lbl_test, LV_ALIGN_OUT_BOTTOM_MID, 0, LV_DPI / 5); lv_obj_set_click(slider_test, false); lv_bar_set_value(slider_test, 60); color_test.slider = slider_test; @@ -641,12 +884,17 @@ static lv_res_t _create_window_nyx_colors(lv_obj_t *btn) // Create sample button. lv_obj_t *btn_test = lv_btn_create(h2, NULL); lv_btn_set_state(btn_test, LV_BTN_STATE_TGL_PR); - lv_obj_align(btn_test, lbl_test, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, LV_DPI / 5); lv_label_create(btn_test, NULL); + lv_btn_set_fit(btn_test, false, true); + lv_obj_set_width(btn_test, LV_DPI * 5 / 3); + lv_obj_align(btn_test, lbl_test, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, LV_DPI / 20); lv_obj_set_click(btn_test, false); color_test.button = btn_test; - _show_new_nyx_color(color_test.bg, color_test.hue, false); + _show_new_nyx_color(false); + + lv_obj_set_opa_scale(status_bar.mid, LV_OPA_0); + lv_obj_set_click(status_bar.mid, false); return LV_RES_OK; } @@ -722,7 +970,7 @@ static lv_res_t _action_clock_edit(lv_obj_t *btns, const char * txt) nyx_changes_made = true; } - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -944,7 +1192,7 @@ static lv_res_t _joycon_info_dump_action(lv_obj_t * btn) jc_pad->bt_conn_r.type = is_r_hos ? jc_pad->bt_conn_r.type : 0; save_data: - error = !sd_mount() ? 5 : 0; + error = sd_mount() ? 5 : 0; if (!error) { @@ -1157,7 +1405,7 @@ disabled_or_cal0_issue:; lv_mbox_set_text(mbox, txt_buf); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text. + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); // Important. After set_text. lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -1184,7 +1432,7 @@ static lv_res_t _action_nyx_options_save(lv_obj_t *btns, const char * txt) { int btn_idx = lv_btnm_get_pressed(btns); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); if (!btn_idx) _save_nyx_options_action(NULL); @@ -1224,7 +1472,7 @@ static lv_res_t _action_win_nyx_options_close(lv_obj_t *btn) lv_obj_set_opa_scale(status_bar.mid, LV_OPA_0); lv_obj_set_click(status_bar.mid, false); - lv_res_t res = nyx_win_close_action_custom(btn); + lv_res_t res = nyx_win_close_action(btn); _check_nyx_changes(); @@ -1235,7 +1483,7 @@ lv_res_t create_win_nyx_options(lv_obj_t *parrent_btn) { lv_theme_t *th = lv_theme_get_current(); - lv_obj_t *win = nyx_create_window_custom_close_btn(SYMBOL_HOME" Nyx Settings", _action_win_nyx_options_close); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_HOME" Nyx Settings", _action_win_nyx_options_close); static lv_style_t h_style; lv_style_copy(&h_style, &lv_style_transp); @@ -1279,7 +1527,7 @@ lv_res_t create_win_nyx_options(lv_obj_t *parrent_btn) lv_obj_t *label_txt2 = lv_label_create(sw_h2, NULL); lv_label_set_recolor(label_txt2, true); - lv_label_set_static_text(label_txt2, "Select a color for all #00FFC8 highlights# in Nyx.\n"); + lv_label_set_static_text(label_txt2, "Customize #C7EA46 Theme# and #C7EA46 Accent# colors in Nyx.\n"); lv_obj_set_style(label_txt2, &hint_small_style); lv_obj_align(label_txt2, btn, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3 - 8); diff --git a/nyx/nyx_gui/frontend/gui_tools.c b/nyx/nyx_gui/frontend/gui_tools.c index 113a03eb..b8e62ed0 100644 --- a/nyx/nyx_gui/frontend/gui_tools.c +++ b/nyx/nyx_gui/frontend/gui_tools.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 naehrwert - * Copyright (c) 2018-2025 CTCaer + * Copyright (c) 2018-2026 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, @@ -31,8 +31,6 @@ #include #include -extern volatile boot_cfg_t *b_cfg; - lv_obj_t *ums_mbox; extern char *emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); @@ -158,7 +156,7 @@ static lv_res_t _create_mbox_autorcm_status(lv_obj_t *btn) "The boot process is now normal and you need the #FF8000 VOL+# + #FF8000 HOME# (jig) combo to enter RCM.\n"); } - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -178,8 +176,8 @@ static lv_res_t _create_mbox_hid(usb_ctxt_t *usbs) lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); - static const char *mbox_btn_map[] = { "\251", "\262Close", "\251", "" }; - static const char *mbox_btn_map2[] = { "\251", "\222Close", "\251", "" }; + static const char *mbox_btn_map_dis[] = { "\251", "\262Close", "\251", "" }; + static const char *mbox_btn_map[] = { "\251", "\222Close", "\251", "" }; lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); lv_mbox_set_recolor_text(mbox, true); @@ -205,14 +203,14 @@ static lv_res_t _create_mbox_hid(usb_ctxt_t *usbs) lv_label_set_static_text(lbl_tip, "Note: To end it, press #C7EA46 L3# + #C7EA46 HOME# or remove the cable."); lv_obj_set_style(lbl_tip, &hint_small_style); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map_dis, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); usb_device_gadget_hid(usbs); - lv_mbox_add_btns(mbox, mbox_btn_map2, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); return LV_RES_OK; } @@ -223,8 +221,8 @@ static lv_res_t _create_mbox_ums(usb_ctxt_t *usbs) lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); - static const char *mbox_btn_map[] = { "\251", "\262Close", "\251", "" }; - static const char *mbox_btn_map2[] = { "\251", "\222Close", "\251", "" }; + static const char *mbox_btn_map_dis[] = { "\251", "\262Close", "\251", "" }; + static const char *mbox_btn_map[] = { "\251", "\222Close", "\251", "" }; lv_obj_t *mbox = lv_mbox_create(dark_bg, NULL); lv_mbox_set_recolor_text(mbox, true); @@ -299,7 +297,7 @@ static lv_res_t _create_mbox_ums(usb_ctxt_t *usbs) } lv_obj_set_style(lbl_tip, &hint_small_style); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map_dis, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -312,7 +310,7 @@ static lv_res_t _create_mbox_ums(usb_ctxt_t *usbs) // Restore backlight. display_backlight_brightness(h_cfg.backlight - 20, 1000); - lv_mbox_add_btns(mbox, mbox_btn_map2, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); ums_mbox = dark_bg; @@ -342,7 +340,7 @@ static lv_res_t _create_mbox_ums_error(int error) break; } - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -485,7 +483,7 @@ static lv_res_t _action_ums_emuemmc_boot0(lv_obj_t *btn) usb_ctxt_t usbs; - int error = !sd_mount(); + int error = sd_mount(); if (!error) { emummc_cfg_t emu_info; @@ -532,7 +530,7 @@ static lv_res_t _action_ums_emuemmc_boot1(lv_obj_t *btn) usb_ctxt_t usbs; - int error = !sd_mount(); + int error = sd_mount(); if (!error) { emummc_cfg_t emu_info; @@ -579,7 +577,7 @@ static lv_res_t _action_ums_emuemmc_gpp(lv_obj_t *btn) usb_ctxt_t usbs; - int error = !sd_mount(); + int error = sd_mount(); if (!error) { emummc_cfg_t emu_info; @@ -595,7 +593,7 @@ static lv_res_t _action_ums_emuemmc_gpp(lv_obj_t *btn) usbs.offset = emu_info.sector + 0x4000; u8 *gpt = malloc(SD_BLOCKSIZE); - if (sdmmc_storage_read(&sd_storage, usbs.offset + 1, 1, gpt)) + if (!sdmmc_storage_read(&sd_storage, usbs.offset + 1, 1, gpt)) { if (!memcmp(gpt, "EFI PART", 8)) { @@ -675,7 +673,7 @@ static lv_res_t _emmc_read_only_toggle(lv_obj_t *btn) static lv_res_t _create_window_usb_tools(lv_obj_t *parent) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_USB" USB Tools"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_USB" USB Tools", NULL); static lv_style_t h_style; lv_style_copy(&h_style, &lv_style_transp); @@ -928,7 +926,7 @@ out: static lv_res_t _create_window_unset_abit_tool(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_COPY" Fix Archive Bit (All folders)"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_COPY" Fix Archive Bit (All folders)", NULL); // Disable buttons. nyx_window_toggle_buttons(win, true); @@ -940,7 +938,7 @@ static lv_res_t _create_window_unset_abit_tool(lv_obj_t *btn) lv_label_set_long_mode(lb_desc, LV_LABEL_LONG_BREAK); lv_label_set_recolor(lb_desc, true); - if (!sd_mount()) + if (sd_mount()) { lv_label_set_text(lb_desc, "#FFDD00 Failed to init SD!#"); lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); @@ -1001,7 +999,7 @@ static lv_res_t _create_window_unset_abit_tool(lv_obj_t *btn) static lv_res_t _create_mbox_fix_touchscreen(lv_obj_t *btn) { - int res = 0; + int res = 1; lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); @@ -1041,13 +1039,13 @@ static lv_res_t _create_mbox_fix_touchscreen(lv_obj_t *btn) } u8 err[2]; - if (!touch_panel_ito_test(err)) + if (touch_panel_ito_test(err)) goto ito_failed; if (!err[0] && !err[1]) { res = touch_execute_autotune(); - if (res) + if (!res) goto out; } else @@ -1105,13 +1103,13 @@ ito_failed: touch_sense_enable(); out: - if (res) + if (!res) lv_mbox_set_text(mbox, "#C7EA46 The touchscreen calibration finished!"); else lv_mbox_set_text(mbox, "#FFFF00 The touchscreen calibration failed!"); out2: - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); free(txt_buf); @@ -1120,7 +1118,7 @@ out2: static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn) { - lv_obj_t *win = nyx_create_standard_window(SYMBOL_MODULES" Dump package1/2"); + lv_obj_t *win = nyx_create_standard_window(SYMBOL_MODULES" Dump package1/2", NULL); // Disable buttons. nyx_window_toggle_buttons(win, true); @@ -1143,7 +1141,7 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn) lv_obj_align(lb_desc2, lb_desc, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); - if (!sd_mount()) + if (sd_mount()) { lv_label_set_text(lb_desc, "#FFDD00 Failed to init SD!#"); @@ -1161,7 +1159,7 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn) char *txt_buf = (char *)malloc(SZ_16K); - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#"); @@ -1515,7 +1513,7 @@ out_end: return LV_RES_OK; } -static void _create_tab_tools_emmc_pkg12(lv_theme_t *th, lv_obj_t *parent) +static void _create_tab_tools_emmc_sd_usb(lv_theme_t *th, lv_obj_t *parent) { lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); @@ -1613,10 +1611,6 @@ static void _create_tab_tools_emmc_pkg12(lv_theme_t *th, lv_obj_t *parent) lv_obj_set_style(label_txt4, &hint_small_style); lv_obj_align(label_txt4, btn3, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); - label_sep = lv_label_create(h2, NULL); - lv_label_set_static_text(label_sep, ""); - lv_obj_align(label_sep, label_txt4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI * 11 / 7); - // Create USB Tools button. lv_obj_t *btn4 = lv_btn_create(h2, btn3); label_btn = lv_label_create(btn4, NULL); @@ -1634,7 +1628,7 @@ static void _create_tab_tools_emmc_pkg12(lv_theme_t *th, lv_obj_t *parent) lv_obj_align(label_txt4, btn4, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); } -static void _create_tab_tools_arc_autorcm(lv_theme_t *th, lv_obj_t *parent) +static void _create_tab_tools_arc_rcm_pkg12(lv_theme_t *th, lv_obj_t *parent) { lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); @@ -1671,8 +1665,8 @@ static void _create_tab_tools_arc_autorcm(lv_theme_t *th, lv_obj_t *parent) lv_obj_t *label_txt2 = lv_label_create(h1, NULL); lv_label_set_recolor(label_txt2, true); lv_label_set_static_text(label_txt2, - "Allows you to fix the archive bit for all folders including\n" - "the root and emuMMC \'Nintendo\' folders.\n" + "Allows you to fix the archive bit for all folders including the\n" + "root and emuMMC \'Nintendo\' folders.\n" "#C7EA46 It sets the archive bit to folders named with ##FF8000 .[ext]#\n" "#FF8000 Use that option when you have corruption messages.#"); lv_obj_set_style(label_txt2, &hint_small_style); @@ -1689,7 +1683,7 @@ static void _create_tab_tools_arc_autorcm(lv_theme_t *th, lv_obj_t *parent) lv_label_set_recolor(label_txt2, true); lv_label_set_static_text(label_txt2, "Allows you to calibrate the touchscreen module.\n" - "#FF8000 This fixes any issues with touchscreen in Nyx and HOS.#"); + "#FF8000 This can fix any issues with touchscreen in Nyx and HOS.#"); lv_obj_set_style(label_txt2, &hint_small_style); lv_obj_align(label_txt2, btn2, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 3); @@ -1712,10 +1706,11 @@ static void _create_tab_tools_arc_autorcm(lv_theme_t *th, lv_obj_t *parent) lv_obj_t *btn3 = lv_btn_create(h2, NULL); if (hekate_bg || hekate_bg_etc) { - lv_btn_set_style(btn3, LV_BTN_STYLE_REL, &btn_transp_rel); - lv_btn_set_style(btn3, LV_BTN_STYLE_PR, &btn_transp_pr); + lv_btn_set_style(btn3, LV_BTN_STYLE_REL, &btn_transp_rel); + lv_btn_set_style(btn3, LV_BTN_STYLE_PR, &btn_transp_pr); lv_btn_set_style(btn3, LV_BTN_STYLE_TGL_REL, &btn_transp_tgl_rel); - lv_btn_set_style(btn3, LV_BTN_STYLE_TGL_PR, &btn_transp_tgl_pr); + lv_btn_set_style(btn3, LV_BTN_STYLE_TGL_PR, &btn_transp_tgl_pr); + lv_btn_set_style(btn3, LV_BTN_STYLE_INA, &btn_transp_ina); } label_btn = lv_label_create(btn3, NULL); lv_btn_set_fit(btn3, true, true); @@ -1806,8 +1801,8 @@ void create_tab_tools(lv_theme_t *th, lv_obj_t *parent) lv_line_set_style(line_sep, lv_theme_get_current()->line.decor); lv_obj_align(line_sep, tv, LV_ALIGN_IN_BOTTOM_MID, -1, -LV_DPI * 2 / 12); - _create_tab_tools_emmc_pkg12(th, tab1); - _create_tab_tools_arc_autorcm(th, tab2); + _create_tab_tools_emmc_sd_usb(th, tab1); + _create_tab_tools_arc_rcm_pkg12(th, tab2); lv_tabview_set_tab_act(tv, 0, false); } diff --git a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c index 7c475654..c9e2b2ff 100644 --- a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c +++ b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c @@ -317,7 +317,7 @@ static void _create_gpt_partition(gpt_t *gpt, u8 *gpt_idx, u32 *curr_part_lba, u memcpy(gpt->entries[*gpt_idx].name, name_utf16, name_lenth * sizeof(u16)); // Wipe the first 1MB to sanitize it as raw-empty partition. - sdmmc_storage_write(part_info.storage, *curr_part_lba, 0x800, (void *)SDMMC_UPPER_BUFFER); + sdmmc_storage_write(part_info.storage, *curr_part_lba, 0x800, (void *)SDMMC_ALT_DMA_BUFFER); // Prepare for next. (*curr_part_lba) += size_lba; @@ -339,8 +339,8 @@ static void _sd_prepare_and_flash_mbr_gpt() memcpy(&mbr.bootstrap[0xE0], &part_info.mbr_old.bootstrap[0xE0], 208); // Clear the first 16MB. - memset((void *)SDMMC_UPPER_BUFFER, 0, AU_ALIGN_BYTES); - sdmmc_storage_write(&sd_storage, 0, AU_ALIGN_SECTORS, (void *)SDMMC_UPPER_BUFFER); + memset((void *)SDMMC_ALT_DMA_BUFFER, 0, AU_ALIGN_BYTES); + sdmmc_storage_write(&sd_storage, 0, AU_ALIGN_SECTORS, (void *)SDMMC_ALT_DMA_BUFFER); // Set disk signature. se_rng_pseudo(random_number, sizeof(u32)); @@ -355,7 +355,7 @@ static void _sd_prepare_and_flash_mbr_gpt() mbr.partitions[mbr_idx].type = 0x83; // Linux system partition. mbr.partitions[mbr_idx].start_sct = AU_ALIGN_SECTORS + ((u32)part_info.hos_size << 11); mbr.partitions[mbr_idx].size_sct = part_info.l4t_size << 11; - sdmmc_storage_write(&sd_storage, mbr.partitions[mbr_idx].start_sct, 0x800, (void *)SDMMC_UPPER_BUFFER); // Clear the first 1MB. + sdmmc_storage_write(&sd_storage, mbr.partitions[mbr_idx].start_sct, 0x800, (void *)SDMMC_ALT_DMA_BUFFER); // Clear the first 1MB. mbr_idx++; } @@ -471,7 +471,7 @@ static void _sd_prepare_and_flash_mbr_gpt() // Android Encryption partition. 16MB. // Note: 16MB size is for aligning UDA. If any other tiny partition must be added, it should split the MDA one. - sdmmc_storage_write(&sd_storage, curr_part_lba, 0x8000, (void *)SDMMC_UPPER_BUFFER); // Clear the whole of it. + sdmmc_storage_write(&sd_storage, curr_part_lba, 0x8000, (void *)SDMMC_ALT_DMA_BUFFER); // Clear the whole of it. _create_gpt_partition(gpt, &gpt_idx, &curr_part_lba, 0x8000, "MDA", 6); // Android Cache partition. 700MB. @@ -552,6 +552,8 @@ static int _emmc_prepare_and_flash_mbr_gpt() gpt_t *gpt = zalloc(sizeof(gpt_t)); gpt_header_t gpt_hdr_backup = { 0 }; + memset((void *)SDMMC_ALT_DMA_BUFFER, 0, AU_ALIGN_BYTES); + // Read main GPT. sdmmc_storage_read(&emmc_storage, 1, sizeof(gpt_t) >> 9, gpt); @@ -638,7 +640,7 @@ static int _emmc_prepare_and_flash_mbr_gpt() // Android Encryption partition. 16MB. // Note: 16MB size is for aligning UDA. If any other tiny partition must be added, it should split the MDA one. - sdmmc_storage_write(&emmc_storage, curr_part_lba, 0x8000, (void *)SDMMC_UPPER_BUFFER); // Clear the whole of it. + sdmmc_storage_write(&emmc_storage, curr_part_lba, 0x8000, (void *)SDMMC_ALT_DMA_BUFFER); // Clear the whole of it. _create_gpt_partition(gpt, &gpt_idx, &curr_part_lba, 0x8000, "MDA", 6); // Android Cache partition. 700MB. @@ -711,7 +713,7 @@ static lv_res_t _action_delete_linux_installer_files(lv_obj_t * btns, const char int btn_idx = lv_btnm_get_pressed(btns); // Delete parent mbox. - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); // Flash Linux. if (!btn_idx) @@ -755,7 +757,7 @@ static lv_res_t _action_flash_linux_data(lv_obj_t * btns, const char * txt) int btn_idx = lv_btnm_get_pressed(btns); // Delete parent mbox. - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); bool succeeded = false; @@ -885,7 +887,7 @@ static lv_res_t _action_flash_linux_data(lv_obj_t * btns, const char * txt) } // Write data block to L4T partition. - res = !sdmmc_storage_write(part_info.storage, lba_curr + l4t_flash_ctxt.offset_sct, num, buf); + res = sdmmc_storage_write(part_info.storage, lba_curr + l4t_flash_ctxt.offset_sct, num, buf); manual_system_maintenance(false); @@ -905,7 +907,7 @@ static lv_res_t _action_flash_linux_data(lv_obj_t * btns, const char * txt) goto exit; } - res = !sdmmc_storage_write(part_info.storage, lba_curr + l4t_flash_ctxt.offset_sct, num, buf); + res = sdmmc_storage_write(part_info.storage, lba_curr + l4t_flash_ctxt.offset_sct, num, buf); manual_system_maintenance(false); } @@ -939,7 +941,7 @@ exit: free(txt_buf); if (!succeeded) - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); else lv_mbox_add_btns(mbox, mbox_btn_map2, _action_delete_linux_installer_files); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); @@ -1141,7 +1143,7 @@ static lv_res_t _action_check_flash_linux(lv_obj_t *btn) goto exit; error: - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); exit: lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); @@ -1158,7 +1160,7 @@ static lv_res_t _action_reboot_recovery(lv_obj_t * btns, const char * txt) int btn_idx = lv_btnm_get_pressed(btns); // Delete parent mbox. - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); if (!btn_idx) { @@ -1190,7 +1192,7 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt) bool boot_recovery = false; // Delete parent mbox. - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); if (btn_idx) return LV_RES_INV; @@ -1436,7 +1438,7 @@ error: lv_mbox_add_btns(mbox, mbox_btn_map2, _action_reboot_recovery); } else - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); @@ -1480,6 +1482,8 @@ static lv_res_t _action_flash_android(lv_obj_t *btn) static lv_res_t _action_part_manager_flash_options0(lv_obj_t *btns, const char *txt) { int btn_idx = lv_btnm_get_pressed(btns); + if (part_info.emmc) + btn_idx++; switch (btn_idx) { @@ -1494,7 +1498,7 @@ static lv_res_t _action_part_manager_flash_options0(lv_obj_t *btns, const char * _action_flash_android(NULL); break; case 3: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -1504,6 +1508,8 @@ static lv_res_t _action_part_manager_flash_options0(lv_obj_t *btns, const char * static lv_res_t _action_part_manager_flash_options1(lv_obj_t *btns, const char *txt) { int btn_idx = lv_btnm_get_pressed(btns); + if (part_info.emmc) + btn_idx++; switch (btn_idx) { @@ -1512,11 +1518,11 @@ static lv_res_t _action_part_manager_flash_options1(lv_obj_t *btns, const char * lv_obj_del(ums_mbox); break; case 1: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); _action_check_flash_linux(NULL); return LV_RES_INV; case 2: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -1526,6 +1532,8 @@ static lv_res_t _action_part_manager_flash_options1(lv_obj_t *btns, const char * static lv_res_t _action_part_manager_flash_options2(lv_obj_t *btns, const char *txt) { int btn_idx = lv_btnm_get_pressed(btns); + if (part_info.emmc) + btn_idx++; switch (btn_idx) { @@ -1534,11 +1542,11 @@ static lv_res_t _action_part_manager_flash_options2(lv_obj_t *btns, const char * lv_obj_del(ums_mbox); break; case 1: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); _action_flash_android(NULL); return LV_RES_INV; case 2: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -1844,7 +1852,7 @@ out: lv_obj_del(lbl_paths[1]); exit: if (!buttons_set) - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -1920,7 +1928,7 @@ static lv_res_t _emmc_create_mbox_start_partitioning() lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); manual_system_maintenance(true); - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_label_set_text(lbl_extra, "#FFDD00 Failed to init eMMC!#"); goto exit; @@ -2044,7 +2052,7 @@ exit: free(txt_buf); if (!buttons_set) - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -2065,11 +2073,11 @@ static lv_res_t _create_mbox_partitioning_option0(lv_obj_t *btns, const char *tx action_ums_sd(NULL); return LV_RES_OK; case 1: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); _sd_create_mbox_start_partitioning(); break; case 2: - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); break; } @@ -2080,11 +2088,10 @@ static lv_res_t _create_mbox_partitioning_option1(lv_obj_t *btns, const char *tx { int btn_idx = lv_btnm_get_pressed(btns); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); if (!btn_idx) { - mbox_action(btns, txt); if (!part_info.emmc) _sd_create_mbox_start_partitioning(); else @@ -2102,7 +2109,7 @@ static lv_res_t _create_mbox_partitioning_warn() lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); static const char *mbox_btn_map[] = { "\222SD UMS", "\222Start", "\222Cancel", "" }; - static const char *mbox_btn_map2[] = { "\222Start", "\222Cancel", "" }; + static const char *mbox_btn_map1[] = { "\222Start", "\222Cancel", "" }; lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); lv_mbox_set_recolor_text(mbox, true); @@ -2132,7 +2139,7 @@ static lv_res_t _create_mbox_partitioning_warn() lv_label_set_text(lbl_status, txt_buf); if (part_info.backup_possible) - lv_mbox_add_btns(mbox, mbox_btn_map2, _create_mbox_partitioning_option1); + lv_mbox_add_btns(mbox, mbox_btn_map1, _create_mbox_partitioning_option1); else lv_mbox_add_btns(mbox, mbox_btn_map, _create_mbox_partitioning_option0); } @@ -2141,7 +2148,7 @@ static lv_res_t _create_mbox_partitioning_warn() s_printf(txt_buf, "#FFDD00 Warning: This will partition the eMMC!#\n\n" "#FFDD00 The USER partition will also be formatted!#"); lv_label_set_text(lbl_status, txt_buf); - lv_mbox_add_btns(mbox, mbox_btn_map2, _create_mbox_partitioning_option1); + lv_mbox_add_btns(mbox, mbox_btn_map1, _create_mbox_partitioning_option1); } lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); @@ -2154,11 +2161,10 @@ static lv_res_t _create_mbox_partitioning_warn() static lv_res_t _create_mbox_partitioning_android(lv_obj_t *btns, const char *txt) { - int btn_idx = lv_btnm_get_pressed(btns); + part_info.and_dynamic = lv_btnm_get_pressed(btns); - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); - part_info.and_dynamic = !btn_idx; _create_mbox_partitioning_warn(); return LV_RES_INV; @@ -2170,7 +2176,7 @@ static lv_res_t _create_mbox_partitioning_andr_part() lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); - static const char *mbox_btn_map[] = { "\222Dynamic", "\222Legacy", "" }; + static const char *mbox_btn_map[] = { "\222Legacy", "\222Dynamic", "" }; lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); lv_mbox_set_recolor_text(mbox, true); @@ -2182,8 +2188,8 @@ static lv_res_t _create_mbox_partitioning_andr_part() lv_label_set_text(lbl_status, "Please select a partition scheme:\n\n" - "#C7EA46 Dynamic:# Android 13+\n" - "#C7EA46 Legacy:# Android 10-11\n"); + "#C7EA46 Dynamic:# Android 13+ (Preferred)\n" + "#C7EA46 Legacy:# Android 11\n"); lv_mbox_add_btns(mbox, mbox_btn_map, _create_mbox_partitioning_android); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); @@ -2445,7 +2451,7 @@ static lv_res_t _mbox_check_files_total_size_option(lv_obj_t *btns, const char * if (!lv_btnm_get_pressed(btns)) part_info.backup_possible = false; - mbox_action(btns, txt); + nyx_mbox_action(btns, txt); return LV_RES_INV; } @@ -2624,7 +2630,7 @@ static void _create_mbox_check_files_total_size() lv_obj_align(lbl_table, h1, LV_ALIGN_IN_TOP_MID, 0, LV_DPI); if (!part_info.backup_possible) - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); else lv_mbox_add_btns(mbox, mbox_btn_map2, _mbox_check_files_total_size_option); @@ -2661,7 +2667,7 @@ static lv_res_t _action_fix_mbr_gpt(lv_obj_t *btn) int gpt_emummc_migrate_no = 0; // Try to init sd card. No need for valid MBR. - if (!sd_mount() && !sd_get_card_initialized()) + if (sd_mount() && !sd_get_card_initialized()) { lv_label_set_text(lbl_status, "#FFDD00 Failed to init SD!#"); goto out; @@ -2957,7 +2963,7 @@ check_changes: out: free(gpt); - lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); + lv_mbox_add_btns(mbox, mbox_btn_map, nyx_mbox_action); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); @@ -2971,11 +2977,11 @@ lv_res_t create_window_partition_manager(bool emmc) if (!emmc) { - win = nyx_create_standard_window(SYMBOL_SD" SD Partition Manager"); + win = nyx_create_standard_window(SYMBOL_SD" SD Partition Manager", NULL); lv_win_add_btn(win, NULL, SYMBOL_MODULES_ALT" Fix Hybrid MBR/GPT", _action_fix_mbr_gpt); } else - win = nyx_create_standard_window(SYMBOL_CHIP" eMMC Partition Manager"); + win = nyx_create_standard_window(SYMBOL_CHIP" eMMC Partition Manager", NULL); static lv_style_t bar_hos_bg, bar_emu_bg, bar_l4t_bg, bar_and_bg; static lv_style_t bar_hos_ind, bar_emu_ind, bar_l4t_ind, bar_and_ind; @@ -3044,7 +3050,7 @@ lv_res_t create_window_partition_manager(bool emmc) u32 emmc_size = 0; if (!emmc) { - if (!sd_mount()) + if (sd_mount()) { lv_obj_t *lbl = lv_label_create(h1, NULL); lv_label_set_recolor(lbl, true); @@ -3052,7 +3058,7 @@ lv_res_t create_window_partition_manager(bool emmc) return LV_RES_OK; } - if (emmc_initialize(false)) + if (!emmc_initialize(false)) { emmc_set_partition(EMMC_GPP); emmc_size = emmc_storage.sec_cnt >> 11; @@ -3061,7 +3067,7 @@ lv_res_t create_window_partition_manager(bool emmc) } else { - if (!emmc_initialize(false)) + if (emmc_initialize(false)) { lv_obj_t *lbl = lv_label_create(h1, NULL); lv_label_set_recolor(lbl, true); @@ -3342,8 +3348,8 @@ lv_res_t create_window_partition_manager(bool emmc) lv_obj_set_click(btn_flash_android, false); lv_btn_set_state(btn_flash_android, LV_BTN_STATE_INA); break; - case 1: // Android 10/11. - lv_label_set_static_text(label_btn, SYMBOL_DOWNLOAD" Flash Android 10/11"); + case 1: // Android 11. + lv_label_set_static_text(label_btn, SYMBOL_DOWNLOAD" Flash Android 11"); break; case 2: // Android 13+ lv_label_set_static_text(label_btn, SYMBOL_DOWNLOAD" Flash Android 13+"); diff --git a/nyx/nyx_gui/hos/hos.c b/nyx/nyx_gui/hos/hos.c index e08db65f..6e826143 100644 --- a/nyx/nyx_gui/hos/hos.c +++ b/nyx/nyx_gui/hos/hos.c @@ -26,7 +26,6 @@ #include "../config.h" u8 *cal0_buf = NULL; -static u8 *bis_keys = NULL; static const u8 eks_keyseeds[HOS_MKEY_VER_600 - HOS_MKEY_VER_100 + 1][SE_KEY_128_SIZE] = { { 0xDF, 0x20, 0x6F, 0x59, 0x44, 0x54, 0xEF, 0xDC, 0x70, 0x74, 0x48, 0x3B, 0x0D, 0xED, 0x9F, 0xD3 }, // 1.0.0. @@ -52,7 +51,7 @@ static const u8 master_kekseed_620[SE_KEY_128_SIZE] = //!TODO: Update on mkey changes. static const u8 master_kekseed_t210_max[SE_KEY_128_SIZE] = - { 0x66, 0xC8, 0xCB, 0x3D, 0xEC, 0xF4, 0x59, 0x73, 0x54, 0x88, 0xE1, 0x2E, 0xE6, 0x3D, 0x68, 0x46 }; // 21.0.0. + { 0x15, 0xAC, 0x96, 0x34, 0xF5, 0x32, 0x56, 0x68, 0xFE, 0x5B, 0x9D, 0xD7, 0xED, 0x19, 0xB7, 0x8E }; // 22.0.0. //!TODO: Update on mkey changes. static const u8 master_kekseed_t210b01[HOS_MKEY_VER_MAX - HOS_MKEY_VER_600 + 1][SE_KEY_128_SIZE] = { @@ -72,6 +71,7 @@ static const u8 master_kekseed_t210b01[HOS_MKEY_VER_MAX - HOS_MKEY_VER_600 + 1][ { 0x31, 0xBE, 0x25, 0xFB, 0xDB, 0xB4, 0xEE, 0x49, 0x5C, 0x77, 0x05, 0xC2, 0x36, 0x9F, 0x34, 0x80 }, // 19.0.0. { 0x1A, 0x31, 0x62, 0x87, 0xA8, 0x09, 0xCA, 0xF8, 0x69, 0x15, 0x45, 0xC2, 0x6B, 0xAA, 0x5A, 0x8A }, // 20.0.0. { 0xEB, 0xF3, 0x5B, 0x2D, 0x4A, 0x2D, 0xCE, 0x45, 0x3A, 0x6F, 0x61, 0x38, 0x0B, 0x00, 0x3B, 0x46 }, // 21.0.0. + { 0x82, 0xE2, 0x0A, 0x59, 0x67, 0xDF, 0xBF, 0x51, 0x47, 0x62, 0x11, 0xF2, 0x41, 0xD3, 0xEE, 0x13 }, // 22.0.0. }; static const u8 console_keyseed[SE_KEY_128_SIZE] = @@ -106,6 +106,7 @@ static const u8 mkey_vectors[HOS_MKEY_VER_MAX + 1][SE_KEY_128_SIZE] = { { 0x4A, 0x01, 0x3B, 0xC7, 0x44, 0x6E, 0x45, 0xBD, 0xE6, 0x5E, 0x2B, 0xEC, 0x07, 0x37, 0x52, 0x86 }, // Mkey 17 encrypted with mkey 18. { 0x97, 0xE4, 0x11, 0xAB, 0x22, 0x72, 0x1A, 0x1F, 0x70, 0x5C, 0x00, 0xB3, 0x96, 0x30, 0x05, 0x28 }, // Mkey 18 encrypted with mkey 19. { 0xF7, 0x92, 0xC0, 0xEC, 0xF3, 0xA4, 0x8C, 0xB7, 0x0D, 0xB3, 0xF3, 0xAB, 0x10, 0x9B, 0x18, 0xBA }, // Mkey 19 encrypted with mkey 20. + { 0x14, 0xCB, 0x60, 0x29, 0x3D, 0xE0, 0xFB, 0xF2, 0x5B, 0x60, 0xB6, 0xC5, 0x2E, 0x77, 0x8F, 0x98 }, // Mkey 20 encrypted with mkey 21. }; //!TODO: Update on mkey changes. @@ -128,6 +129,7 @@ static const u8 new_console_keyseed[HOS_MKEY_VER_MAX - HOS_MKEY_VER_400 + 1][SE_ { 0x07, 0x38, 0x9A, 0xEC, 0x9C, 0xBD, 0x50, 0x4A, 0x4C, 0x1F, 0x04, 0xDA, 0x40, 0x68, 0x29, 0xE3 }, // 19.0.0 New Device Key Source. { 0xA3, 0x6B, 0x0A, 0xB5, 0x6F, 0x57, 0x4C, 0x5E, 0x00, 0xFD, 0x56, 0x21, 0xF5, 0x06, 0x6B, 0xD1 }, // 20.0.0 New Device Key Source. { 0xF9, 0x62, 0x05, 0x99, 0xE0, 0xB9, 0xA6, 0x9B, 0x9D, 0xAA, 0xB4, 0x12, 0x0B, 0x0F, 0xF5, 0x8F }, // 21.0.0 New Device Key Source. + { 0xF8, 0xF4, 0x22, 0xA4, 0x34, 0xAE, 0x0E, 0x0C, 0x4D, 0x5C, 0x5B, 0xA1, 0x1B, 0x46, 0x1C, 0x78 }, // 22.0.0 New Device Key Source. }; //!TODO: Update on mkey changes. @@ -150,6 +152,7 @@ static const u8 new_console_kekseed[HOS_MKEY_VER_MAX - HOS_MKEY_VER_400 + 1][SE_ { 0x9B, 0xA5, 0xFD, 0x74, 0x7F, 0xCD, 0x23, 0xD1, 0xD9, 0xBD, 0x6C, 0x51, 0x72, 0x5F, 0x3D, 0x1F }, // 19.0.0 New Device Keygen Source. { 0xDA, 0xFB, 0x61, 0x39, 0x48, 0x2D, 0xC2, 0x7E, 0x0D, 0x8E, 0x8F, 0x98, 0x57, 0x20, 0xB8, 0x15 }, // 20.0.0 New Device Keygen Source. { 0x92, 0xBF, 0x37, 0x80, 0x0E, 0x79, 0x56, 0x8C, 0x57, 0x75, 0x72, 0x0A, 0x48, 0xD8, 0x15, 0x39 }, // 21.0.0 New Device Keygen Source. + { 0xC4, 0x6F, 0x0E, 0x72, 0x43, 0xCE, 0x87, 0xFC, 0x38, 0x95, 0x9B, 0xC9, 0x31, 0x44, 0x97, 0x63 }, // 22.0.0 New Device Keygen Source. }; static const u8 gen_keyseed[SE_KEY_128_SIZE] = @@ -173,23 +176,23 @@ static const u8 bis_keyseed[][SE_KEY_128_SIZE] = { { 0x4D, 0x12, 0xE1, 0x4B, 0x2A, 0x47, 0x4C, 0x1C, 0x09, 0xCB, 0x03, 0x59, 0xF0, 0x15, 0xF4, 0xE4 } // BIS 2/3 Tweak seed. }; -bool hos_eks_rw_try(u8 *buf, bool write) +static int _hos_eks_rw_try(u8 *buf, bool write) { for (u32 i = 0; i < 3; i++) { if (!write) { - if (sdmmc_storage_read(&sd_storage, 0, 1, buf)) - return true; + if (!sdmmc_storage_read(&sd_storage, 0, 1, buf)) + return 0; } else { - if (sdmmc_storage_write(&sd_storage, 0, 1, buf)) - return true; + if (!sdmmc_storage_write(&sd_storage, 0, 1, buf)) + return 0; } } - return false; + return 1; } static void _hos_eks_get() @@ -203,7 +206,7 @@ static void _hos_eks_get() { // Read EKS blob. u8 *mbr = malloc(SD_BLOCKSIZE); - if (!hos_eks_rw_try(mbr, false)) + if (_hos_eks_rw_try(mbr, false)) goto out; // Decrypt EKS blob. @@ -241,7 +244,7 @@ static void _hos_eks_save() { // Read EKS blob. u8 *mbr = malloc(SD_BLOCKSIZE); - if (!hos_eks_rw_try(mbr, false)) + if (_hos_eks_rw_try(mbr, false)) { if (new_eks) { @@ -273,7 +276,7 @@ static void _hos_eks_save() // Write EKS blob to SD. memcpy(mbr + 0x80, eks, sizeof(hos_eks_mbr_t)); - hos_eks_rw_try(mbr, true); + _hos_eks_rw_try(mbr, true); free(eks); free(keys); @@ -295,7 +298,7 @@ void hos_eks_clear(u32 mkey) { // Read EKS blob. u8 *mbr = malloc(SD_BLOCKSIZE); - if (!hos_eks_rw_try(mbr, false)) + if (_hos_eks_rw_try(mbr, false)) goto out; // Disable current Master key version. @@ -308,7 +311,7 @@ void hos_eks_clear(u32 mkey) // Write EKS blob to SD. memcpy(mbr + 0x80, eks, sizeof(hos_eks_mbr_t)); - hos_eks_rw_try(mbr, true); + _hos_eks_rw_try(mbr, true); free(eks); out: @@ -331,7 +334,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt) tsec_keys_t tsec_keys; if (mkey > HOS_MKEY_VER_MAX) - return 0; + return 1; // Do Mariko keygen. if (h_cfg.t210b01) @@ -346,7 +349,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt) // Derive latest pkg2 key. se_aes_unwrap_key(8, 7, package2_keyseed); - return 1; + return 0; } // Do Erista keygen. @@ -385,7 +388,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt) if (!tsec_ctxt->fw) { EPRINTF("\nFailed to load thk.bin"); - return 0; + return 1; } tsec_ctxt->size = 0x1F00; @@ -409,7 +412,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt) if (retries > 15) { EPRINTF("\nFailed to get TSEC keys. Please try again."); - return 0; + return 1; } } @@ -480,7 +483,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt) se_aes_unwrap_key(11, 13, cmac_keyseed); se_aes_hash_cmac(cmac, SE_KEY_128_SIZE, 11, (void *)eks->ctr, sizeof(eks->ctr) + sizeof(eks->keys)); if (!memcmp(eks->cmac, cmac, SE_KEY_128_SIZE)) - return 0; + return 1; */ se_aes_crypt_ecb(13, DECRYPT, tsec_keys.tsec, cmac_keyseed, SE_KEY_128_SIZE); @@ -521,7 +524,7 @@ int hos_keygen(pkg1_eks_t *eks, u32 mkey, tsec_ctxt_t *tsec_ctxt) se_aes_unwrap_key(8, 12, package2_keyseed); } - return 1; + return 0; } static void _hos_validate_mkey() @@ -568,11 +571,9 @@ int hos_bis_keygen() u32 console_key_slot = 15; // HOS_MKEY_VER_MAX. Only for Erista. tsec_ctxt_t tsec_ctxt = {0}; - if (!bis_keys) - bis_keys = malloc(SE_KEY_128_SIZE * 6); - // Run initial keygen. - hos_keygen(NULL, HOS_MKEY_VER_MAX, &tsec_ctxt); + if (hos_keygen(NULL, HOS_MKEY_VER_MAX, &tsec_ctxt)) + return 1; // All Mariko use new device keygen. New keygen was introduced in 4.0.0. // We check unconditionally in order to support downgrades. @@ -613,6 +614,7 @@ int hos_bis_keygen() se_aes_unwrap_key(2, console_key_slot, gen_keyseed_retail); // Clear bis keys storage. + u8 *bis_keys = malloc(SE_KEY_128_SIZE * 6); memset(bis_keys, 0, SE_KEY_128_SIZE * 6); // Generate BIS 0 Keys. @@ -655,7 +657,7 @@ int hos_bis_keygen() se_aes_key_set(4, bis_keys + (4 * SE_KEY_128_SIZE), SE_KEY_128_SIZE); se_aes_key_set(5, bis_keys + (5 * SE_KEY_128_SIZE), SE_KEY_128_SIZE); - return 1; + return 0; } void hos_bis_keys_clear() @@ -668,11 +670,12 @@ void hos_bis_keys_clear() int hos_dump_cal0() { // Init eMMC. - if (!emmc_initialize(false)) + if (emmc_initialize(false)) return 1; // Generate BIS keys - hos_bis_keygen(); + if (hos_bis_keygen()) + return 2; if (!cal0_buf) cal0_buf = malloc(SZ_64K); diff --git a/nyx/nyx_gui/hos/hos.h b/nyx/nyx_gui/hos/hos.h index fd329721..7abaa389 100644 --- a/nyx/nyx_gui/hos/hos.h +++ b/nyx/nyx_gui/hos/hos.h @@ -48,7 +48,8 @@ enum { HOS_MKEY_VER_1900 = 18, HOS_MKEY_VER_2000 = 19, HOS_MKEY_VER_2100 = 20, - HOS_MKEY_VER_MAX = HOS_MKEY_VER_2100 + HOS_MKEY_VER_2200 = 21, + HOS_MKEY_VER_MAX = HOS_MKEY_VER_2200 }; #define HOS_TSEC_VERSION 4 //! TODO: Update on TSEC Root Key changes. diff --git a/nyx/nyx_gui/hos/pkg1.c b/nyx/nyx_gui/hos/pkg1.c index 5d52300e..1f1292ad 100644 --- a/nyx/nyx_gui/hos/pkg1.c +++ b/nyx/nyx_gui/hos/pkg1.c @@ -67,7 +67,8 @@ static const pkg1_id_t _pkg1_ids[] = { { "20240207", 17, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000 }, // 18.0.0 - 18.1.0. { "20240808", 18, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000 }, // 19.0.0 - 19.0.1. { "20250206", 19, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000 }, // 20.0.0 - 20.5.0. - { "20251009", 20, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000 }, // 21.0.0+ + { "20251009", 20, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000 }, // 21.0.0 - 21.2.0. + { "20260123", 21, 0x0E00, 0x6FE0, 0x40030000, 0x4003E000 }, // 22.0.0+ }; const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date) @@ -86,7 +87,7 @@ const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date) return NULL; } -int pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1) +bool pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1) { pk11_hdr_t *hdr; diff --git a/nyx/nyx_gui/hos/pkg1.h b/nyx/nyx_gui/hos/pkg1.h index 4d3ab894..44b7aa10 100644 --- a/nyx/nyx_gui/hos/pkg1.h +++ b/nyx/nyx_gui/hos/pkg1.h @@ -94,7 +94,7 @@ typedef struct _pk11_hdr_t } pk11_hdr_t; const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date); -int pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1); +bool pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1); const u8 *pkg1_unpack(void *wm_dst, void *sm_dst, void *ldr_dst, const pkg1_id_t *id, u8 *pkg1); #endif diff --git a/nyx/nyx_gui/hos/pkg2.c b/nyx/nyx_gui/hos/pkg2.c index 6bc6faa5..31b9b475 100644 --- a/nyx/nyx_gui/hos/pkg2.c +++ b/nyx/nyx_gui/hos/pkg2.c @@ -118,6 +118,8 @@ static const u8 mkey_vector_7xx[HOS_MKEY_VER_MAX - HOS_MKEY_VER_810 + 1][SE_KEY_ { 0x97, 0xE4, 0x11, 0xAB, 0x22, 0x72, 0x1A, 0x1F, 0x70, 0x5C, 0x00, 0xB3, 0x96, 0x30, 0x05, 0x28 }, // Master key 19 encrypted with 20. (20.0.0 with 21.0.0) { 0xF7, 0x92, 0xC0, 0xEC, 0xF3, 0xA4, 0x8C, 0xB7, 0x0D, 0xB3, 0xF3, 0xAB, 0x10, 0x9B, 0x18, 0xBA }, + // Master key 20 encrypted with 21. (21.0.0 with 22.0.0) + { 0x14, 0xCB, 0x60, 0x29, 0x3D, 0xE0, 0xFB, 0xF2, 0x5B, 0x60, 0xB6, 0xC5, 0x2E, 0x77, 0x8F, 0x98 }, }; static bool _pkg2_key_unwrap_validate(pkg2_hdr_t *tmp_test, pkg2_hdr_t *hdr, u8 src_slot, u8 *mkey, const u8 *key_seed) diff --git a/nyx/nyx_gui/libs/fatfs/diskio.c b/nyx/nyx_gui/libs/fatfs/diskio.c index 1eb38924..b2c47ac3 100644 --- a/nyx/nyx_gui/libs/fatfs/diskio.c +++ b/nyx/nyx_gui/libs/fatfs/diskio.c @@ -55,14 +55,14 @@ DRESULT disk_read ( switch (pdrv) { case DRIVE_SD: - return sdmmc_storage_read(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; + return sdmmc_storage_read(&sd_storage, sector, count, (void *)buff); case DRIVE_RAM: return ram_disk_read(sector, count, (void *)buff); case DRIVE_EMMC: - return sdmmc_storage_read(&emmc_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; + return sdmmc_storage_read(&emmc_storage, sector, count, (void *)buff); case DRIVE_BIS: case DRIVE_EMU: - return nx_emmc_bis_read(sector, count, (void *)buff) ? RES_OK : RES_ERROR; + return nx_emmc_bis_read(sector, count, (void *)buff); } return RES_ERROR; @@ -81,7 +81,7 @@ DRESULT disk_write ( switch (pdrv) { case DRIVE_SD: - return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; + return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff); case DRIVE_RAM: return ram_disk_write(sector, count, (void *)buff); case DRIVE_EMMC: @@ -90,7 +90,7 @@ DRESULT disk_write ( case DRIVE_EMU: if (pdrv == DRIVE_BIS && !bis_write_allowed) return RES_WRPRT; - return nx_emmc_bis_write(sector, count, (void *)buff) ? RES_OK : RES_ERROR; + return nx_emmc_bis_write(sector, count, (void *)buff); } return RES_ERROR; diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index a5cc7855..f18f6932 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -52,7 +52,7 @@ char *emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_ // Get actual eMMC S/N. if (!storage) { - if (!emmc_initialize(false)) + if (emmc_initialize(false)) strcpy(emmc_sn, "00000000"); else { @@ -121,7 +121,7 @@ lv_res_t launch_payload(lv_obj_t *list) strcpy(path,"bootloader/payloads/"); strcat(path, filename); - if (!sd_mount()) + if (sd_mount()) goto out; // Read payload. @@ -167,7 +167,7 @@ static void _load_saved_configuration() LIST_INIT(ini_sections); LIST_INIT(ini_nyx_sections); - if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) + if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) { create_config_entry(); goto skip_main_cfg_parse; @@ -212,7 +212,7 @@ static void _load_saved_configuration() ini_free(&ini_sections); skip_main_cfg_parse: - if (!ini_parse(&ini_nyx_sections, "bootloader/nyx.ini", false)) + if (ini_parse(&ini_nyx_sections, "bootloader/nyx.ini", false)) return; // Load Nyx configuration. @@ -306,14 +306,14 @@ static void nyx_load_bg_icons() hekate_bg_etc = bmp_to_lvimg_obj("bootloader/res/background_etc.bmp"); } -#define EXCP_EN_ADDR 0x4003FFFC +#define EXCP_EN_ADDR 0x4003FF1C #define EXCP_MAGIC 0x30505645 // EVP0 -#define EXCP_TYPE_ADDR 0x4003FFF8 +#define EXCP_TYPE_ADDR 0x4003FF18 #define EXCP_TYPE_RESET 0x545352 // RST #define EXCP_TYPE_UNDEF 0x464455 // UDF #define EXCP_TYPE_PABRT 0x54424150 // PABT #define EXCP_TYPE_DABRT 0x54424144 // DABT -#define EXCP_LR_ADDR 0x4003FFF4 +#define EXCP_LR_ADDR 0x4003FF14 enum { SD_NO_ERROR = 0, @@ -427,13 +427,13 @@ void nyx_init_load_res() _show_errors(SD_NO_ERROR); // Try 2 times to mount SD card. - if (!sd_mount()) + if (sd_mount()) { // Restore speed to SDR104. sd_end(); // Retry. - if (!sd_mount()) + if (sd_mount()) _show_errors(SD_MOUNT_ERROR); // Fatal. }