Commit ff4735cf authored by Lin Huang's avatar Lin Huang
Browse files

rockchip/rk3399: Split M0 binary into two



All the m0 code run in SRAM before, but we need to watch PMU_POWER_ST
when SOC enter into FSM, and SRAM will shutdown during this time, so
this code need run in PMUSRAM. But PMUSRAM only 8K space, we can not
put all the m0 binary into PMUSRAM, Split the M0 binary into two, dram
part still run in SRAM, and suspend part run in PMUSRAM.

Change-Id: Ie08bdf3e2b8838f12b9297fe60ab0aad219684b1
Signed-off-by: default avatarLin Huang <hl@rock-chips.com>
parent 133598cb
...@@ -1964,9 +1964,6 @@ uint32_t dram_set_odt_pd(uint32_t arg0, uint32_t arg1, uint32_t arg2) ...@@ -1964,9 +1964,6 @@ uint32_t dram_set_odt_pd(uint32_t arg0, uint32_t arg1, uint32_t arg2)
static void m0_configure_ddr(struct pll_div pll_div, uint32_t ddr_index) static void m0_configure_ddr(struct pll_div pll_div, uint32_t ddr_index)
{ {
/* set PARAM to M0_FUNC_DRAM */
mmio_write_32(M0_PARAM_ADDR + PARAM_M0_FUNC, M0_FUNC_DRAM);
mmio_write_32(M0_PARAM_ADDR + PARAM_DPLL_CON0, FBDIV(pll_div.fbdiv)); mmio_write_32(M0_PARAM_ADDR + PARAM_DPLL_CON0, FBDIV(pll_div.fbdiv));
mmio_write_32(M0_PARAM_ADDR + PARAM_DPLL_CON1, mmio_write_32(M0_PARAM_ADDR + PARAM_DPLL_CON1,
POSTDIV2(pll_div.postdiv2) | POSTDIV1(pll_div.postdiv1) | POSTDIV2(pll_div.postdiv2) | POSTDIV1(pll_div.postdiv1) |
...@@ -1976,6 +1973,7 @@ static void m0_configure_ddr(struct pll_div pll_div, uint32_t ddr_index) ...@@ -1976,6 +1973,7 @@ static void m0_configure_ddr(struct pll_div pll_div, uint32_t ddr_index)
mmio_write_32(M0_PARAM_ADDR + PARAM_FREQ_SELECT, ddr_index << 4); mmio_write_32(M0_PARAM_ADDR + PARAM_FREQ_SELECT, ddr_index << 4);
dmbst(); dmbst();
m0_configure_execute_addr(M0_BINCODE_BASE);
} }
static uint32_t prepare_ddr_timing(uint32_t mhz) static uint32_t prepare_ddr_timing(uint32_t mhz)
......
...@@ -12,6 +12,7 @@ ARCH := cortex-m0 ...@@ -12,6 +12,7 @@ ARCH := cortex-m0
# Build platform # Build platform
PLAT_M0 ?= rk3399m0 PLAT_M0 ?= rk3399m0
PLAT_M0_PMU ?= rk3399m0pmu
ifeq (${V},0) ifeq (${V},0)
Q=@ Q=@
...@@ -26,11 +27,10 @@ INCLUDES += -Iinclude/ \ ...@@ -26,11 +27,10 @@ INCLUDES += -Iinclude/ \
-I../../include/shared/ -I../../include/shared/
# NOTE: Add C source files here # NOTE: Add C source files here
C_SOURCES := src/startup.c \ C_SOURCES_COMMON := src/startup.c
src/main.c \ C_SOURCES := src/dram.c \
src/suspend.c \
src/dram.c \
src/stopwatch.c src/stopwatch.c
C_SOURCES_PMU := src/suspend.c
# Flags definition # Flags definition
COMMON_FLAGS := -g -mcpu=$(ARCH) -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft COMMON_FLAGS := -g -mcpu=$(ARCH) -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft
...@@ -54,12 +54,19 @@ define SOURCES_TO_OBJS ...@@ -54,12 +54,19 @@ define SOURCES_TO_OBJS
$(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
endef endef
SOURCES_COMMON := $(C_SOURCES_COMMON)
SOURCES := $(C_SOURCES) SOURCES := $(C_SOURCES)
SOURCES_PMU := $(C_SOURCES_PMU)
OBJS_COMMON := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_COMMON)))
OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES))) OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES)))
OBJS_PMU := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_PMU)))
LINKERFILE := $(BUILD)/$(PLAT_M0).ld LINKERFILE := $(BUILD)/$(PLAT_M0).ld
MAPFILE := $(BUILD)/$(PLAT_M0).map MAPFILE := $(BUILD)/$(PLAT_M0).map
MAPFILE_PMU := $(BUILD)/$(PLAT_M0_PMU).map
ELF := $(BUILD)/$(PLAT_M0).elf ELF := $(BUILD)/$(PLAT_M0).elf
ELF_PMU := $(BUILD)/$(PLAT_M0_PMU).elf
BIN := $(BUILD)/$(PLAT_M0).bin BIN := $(BUILD)/$(PLAT_M0).bin
BIN_PMU := $(BUILD)/$(PLAT_M0_PMU).bin
LINKERFILE_SRC := src/$(PLAT_M0).ld.S LINKERFILE_SRC := src/$(PLAT_M0).ld.S
# Function definition related compilation # Function definition related compilation
...@@ -92,18 +99,27 @@ define MAKE_OBJS ...@@ -92,18 +99,27 @@ define MAKE_OBJS
$(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
endef endef
.DEFAULT_GOAL := $(BIN) .PHONY: all
all: $(BIN) $(BIN_PMU)
.DEFAULT_GOAL := all
$(LINKERFILE): $(LINKERFILE_SRC) $(LINKERFILE): $(LINKERFILE_SRC)
$(CC) $(COMMON_FLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $< $(CC) $(COMMON_FLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $<
-include $(LINKERFILE).d -include $(LINKERFILE).d
$(ELF) : $(OBJS) $(LINKERFILE) $(ELF) : $(OBJS) $(OBJS_COMMON) $(LINKERFILE)
@echo " LD $@" @echo " LD $@"
$(Q)$(CC) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) $(OBJS) $(Q)$(CC) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) $(OBJS) $(OBJS_COMMON)
$(BIN) : $(ELF) %.bin : %.elf
@echo " BIN $@" @echo " BIN $@"
$(Q)$(OC) -O binary $< $@ $(Q)$(OC) -O binary $< $@
$(ELF_PMU) : $(OBJS_COMMON) $(OBJS_PMU) $(LINKERFILE)
@echo " LD $@"
$(Q)$(CC) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE_PMU) -Wl,-T$(LINKERFILE) $(OBJS_PMU) $(OBJS_COMMON)
$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_COMMON),$(1)))
$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1))) $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1)))
$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_PMU),$(1)))
...@@ -25,8 +25,6 @@ typedef unsigned int uint32_t; ...@@ -25,8 +25,6 @@ typedef unsigned int uint32_t;
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
void handle_suspend(void);
void handle_dram(void);
void stopwatch_init_usecs_expire(unsigned int usecs); void stopwatch_init_usecs_expire(unsigned int usecs);
int stopwatch_expired(void); int stopwatch_expired(void);
void stopwatch_reset(void); void stopwatch_reset(void);
......
...@@ -55,7 +55,7 @@ static void ddr_set_pll(void) ...@@ -55,7 +55,7 @@ static void ddr_set_pll(void)
mmio_write_32(CRU_BASE + CRU_DPLL_CON3, PLL_MODE(PLL_NORMAL_MODE)); mmio_write_32(CRU_BASE + CRU_DPLL_CON3, PLL_MODE(PLL_NORMAL_MODE));
} }
void handle_dram(void) __attribute__((noreturn)) void main(void)
{ {
mmio_setbits_32(PHY_REG(0, 927), (1 << 22)); mmio_setbits_32(PHY_REG(0, 927), (1 << 22));
mmio_setbits_32(PHY_REG(1, 927), (1 << 22)); mmio_setbits_32(PHY_REG(1, 927), (1 << 22));
...@@ -76,4 +76,9 @@ void handle_dram(void) ...@@ -76,4 +76,9 @@ void handle_dram(void)
deidle_port(); deidle_port();
mmio_clrbits_32(PHY_REG(0, 927), (1 << 22)); mmio_clrbits_32(PHY_REG(0, 927), (1 << 22));
mmio_clrbits_32(PHY_REG(1, 927), (1 << 22)); mmio_clrbits_32(PHY_REG(1, 927), (1 << 22));
mmio_write_32(PARAM_ADDR + PARAM_M0_DONE, M0_DONE_FLAG);
for (;;)
__asm__ volatile ("wfi");
} }
/*
* Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <m0_param.h>
#include "rk3399_mcu.h"
__attribute__((noreturn)) void main(void)
{
switch (mmio_read_32(PARAM_ADDR + PARAM_M0_FUNC)) {
case M0_FUNC_SUSPEND:
handle_suspend();
break;
case M0_FUNC_DRAM:
handle_dram();
break;
default:
break;
}
mmio_write_32(PARAM_ADDR + PARAM_M0_DONE, M0_DONE_FLAG);
for (;;)
__asm__ volatile ("wfi");
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "rk3399_mcu.h" #include "rk3399_mcu.h"
/* Stack configuration */ /* Stack configuration */
#define STACK_SIZE 0x00000100 #define STACK_SIZE 0x00000040
__attribute__ ((section(".co_stack"))) __attribute__ ((section(".co_stack")))
unsigned long pstack[STACK_SIZE]; unsigned long pstack[STACK_SIZE];
......
...@@ -11,18 +11,52 @@ ...@@ -11,18 +11,52 @@
#define SCR_SLEEPDEEP_SHIFT (1 << 2) #define SCR_SLEEPDEEP_SHIFT (1 << 2)
void handle_suspend(void) __attribute__((noreturn)) void main(void)
{ {
unsigned int status_value; unsigned int status_value;
/*
* PMU sometimes doesn't clear power mode bit as it's supposed to due
* to a hardware bug. Make the M0 clear it manually to be sure,
* otherwise interrupts some cases with concurrent wake interrupts
* we stay asleep forever.
*/
while (1) { while (1) {
status_value = mmio_read_32(PMU_BASE + PMU_POWER_ST); status_value = mmio_read_32(PMU_BASE + PMU_POWER_ST);
if (status_value) { if (status_value) {
mmio_clrbits_32(PMU_BASE + PMU_PWRMODE_CON, 0x01); mmio_clrbits_32(PMU_BASE + PMU_PWRMODE_CON, 0x01);
return; break;
} }
} }
/* m0 enter deep sleep mode */ /*
mmio_setbits_32(M0_SCR, SCR_SLEEPDEEP_SHIFT); * FSM power secquence is .. -> ST_INPUT_CLAMP(step.17) -> .. ->
* ST_WAKEUP_RESET -> ST_EXT_PWRUP-> ST_RELEASE_CLAMP ->
* ST_24M_OSC_EN -> .. -> ST_WAKEUP_RESET_CLR(step.26) -> ..,
* INPUT_CLAMP and WAKEUP_RESET will hold the SOC not affect by
* power or other single glitch, but WAKEUP_RESET need work with 24MHz,
* so between RELEASE_CLAMP and 24M_OSC_EN, there have a chance
* that glitch will affect SOC, and mess up SOC status, so we
* addressmap_shared software clamp between ST_INPUT_CLAMP and
* ST_WAKEUP_RESET_CLR to avoid this happen.
*/
while (1) {
status_value = mmio_read_32(PMU_BASE + PMU_POWER_ST);
if (status_value >= 17) {
mmio_setbits_32(PMU_BASE + PMU_SFT_CON, 0x02);
break;
}
}
while (1) {
status_value = mmio_read_32(PMU_BASE + PMU_POWER_ST);
if (status_value >= 26) {
mmio_clrbits_32(PMU_BASE + PMU_SFT_CON, 0x02);
break;
}
}
for (;;)
__asm__ volatile ("wfi");
} }
...@@ -21,14 +21,6 @@ void m0_init(void) ...@@ -21,14 +21,6 @@ void m0_init(void)
mmio_write_32(SGRF_BASE + SGRF_PMU_CON(0), WMSK_BIT(7)); mmio_write_32(SGRF_BASE + SGRF_PMU_CON(0), WMSK_BIT(7));
mmio_write_32(SGRF_BASE + SGRF_SOC_CON(6), WMSK_BIT(12)); mmio_write_32(SGRF_BASE + SGRF_SOC_CON(6), WMSK_BIT(12));
/* set the execute address for M0 */
mmio_write_32(SGRF_BASE + SGRF_PMU_CON(3),
BITS_WITH_WMASK((M0_BINCODE_BASE >> 12) & 0xffff,
0xffff, 0));
mmio_write_32(SGRF_BASE + SGRF_PMU_CON(7),
BITS_WITH_WMASK((M0_BINCODE_BASE >> 28) & 0xf,
0xf, 0));
/* document is wrong, PMU_CRU_GATEDIS_CON0 do not need set MASK BIT */ /* document is wrong, PMU_CRU_GATEDIS_CON0 do not need set MASK BIT */
mmio_setbits_32(PMUCRU_BASE + PMUCRU_GATEDIS_CON0, 0x02); mmio_setbits_32(PMUCRU_BASE + PMUCRU_GATEDIS_CON0, 0x02);
...@@ -46,6 +38,17 @@ void m0_init(void) ...@@ -46,6 +38,17 @@ void m0_init(void)
mmio_write_32(PMUCRU_BASE + PMUCRU_CLKGATE_CON2, WMSK_BIT(5)); mmio_write_32(PMUCRU_BASE + PMUCRU_CLKGATE_CON2, WMSK_BIT(5));
} }
void m0_configure_execute_addr(uintptr_t addr)
{
/* set the execute address for M0 */
mmio_write_32(SGRF_BASE + SGRF_PMU_CON(3),
BITS_WITH_WMASK((addr >> 12) & 0xffff,
0xffff, 0));
mmio_write_32(SGRF_BASE + SGRF_PMU_CON(7),
BITS_WITH_WMASK((addr >> 28) & 0xf,
0xf, 0));
}
void m0_start(void) void m0_start(void)
{ {
/* enable clocks for M0 */ /* enable clocks for M0 */
......
...@@ -11,13 +11,18 @@ ...@@ -11,13 +11,18 @@
#define M0_BINCODE_BASE ((uintptr_t)rk3399m0_bin) #define M0_BINCODE_BASE ((uintptr_t)rk3399m0_bin)
#define M0_PARAM_ADDR (M0_BINCODE_BASE + PARAM_ADDR) #define M0_PARAM_ADDR (M0_BINCODE_BASE + PARAM_ADDR)
#define M0PMU_BINCODE_BASE ((uintptr_t)rk3399m0pmu_bin)
/* pmu_fw.c */ /* pmu_fw.c */
extern char rk3399m0_bin[]; extern char rk3399m0_bin[];
extern char rk3399m0_bin_end[]; extern char rk3399m0_bin_end[];
extern char rk3399m0pmu_bin[];
extern char rk3399m0pmu_bin_end[];
extern void m0_init(void); extern void m0_init(void);
extern void m0_start(void); extern void m0_start(void);
extern void m0_stop(void); extern void m0_stop(void);
extern void m0_wait_done(void); extern void m0_wait_done(void);
extern void m0_configure_execute_addr(uintptr_t addr);
#endif /* __M0_CTL_H__ */ #endif /* __M0_CTL_H__ */
...@@ -1064,12 +1064,6 @@ static void resume_gpio(void) ...@@ -1064,12 +1064,6 @@ static void resume_gpio(void)
} }
} }
static void m0_configure_suspend(void)
{
/* set PARAM to M0_FUNC_SUSPEND */
mmio_write_32(M0_PARAM_ADDR + PARAM_M0_FUNC, M0_FUNC_SUSPEND);
}
void sram_save(void) void sram_save(void)
{ {
size_t text_size = (char *)&__bl31_sram_text_real_end - size_t text_size = (char *)&__bl31_sram_text_real_end -
...@@ -1344,7 +1338,7 @@ int rockchip_soc_sys_pwr_dm_suspend(void) ...@@ -1344,7 +1338,7 @@ int rockchip_soc_sys_pwr_dm_suspend(void)
set_pmu_rsthold(); set_pmu_rsthold();
sys_slp_config(); sys_slp_config();
m0_configure_suspend(); m0_configure_execute_addr(M0PMU_BINCODE_BASE);
m0_start(); m0_start();
pmu_sgrf_rst_hld(); pmu_sgrf_rst_hld();
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
*/ */
/* convoluted way to make sure that the define is pasted just the right way */ /* convoluted way to make sure that the define is pasted just the right way */
#define _INCBIN(file, sym) \ #define _INCBIN(file, sym, sec) \
__asm__( \ __asm__( \
".section .sram.incbin\n" \ ".section " #sec "\n" \
".global " #sym "\n" \ ".global " #sym "\n" \
".type " #sym ", %object\n" \ ".type " #sym ", %object\n" \
".align 4\n" \ ".align 4\n" \
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#sym "_end:\n" \ #sym "_end:\n" \
) )
#define INCBIN(file, sym) _INCBIN(file, sym) #define INCBIN(file, sym, sec) _INCBIN(file, sym, sec)
INCBIN(RK3399M0FW, rk3399m0_bin); INCBIN(RK3399M0FW, rk3399m0_bin, ".sram.incbin");
INCBIN(RK3399M0PMUFW, rk3399m0pmu_bin, ".pmusram.incbin");
...@@ -77,14 +77,21 @@ SECTIONS ...@@ -77,14 +77,21 @@ SECTIONS
ASSERT(. == ALIGN(64 * 1024), ASSERT(. == ALIGN(64 * 1024),
".pmusram.entry request 64K aligned."); ".pmusram.entry request 64K aligned.");
*(.pmusram.entry) *(.pmusram.entry)
__bl31_pmusram_text_start = .; __bl31_pmusram_text_start = .;
*(.pmusram.text) *(.pmusram.text)
*(.pmusram.rodata) *(.pmusram.rodata)
__bl31_pmusram_text_end = .; __bl31_pmusram_text_end = .;
/* M0 start address request 4K align */
. = ALIGN(4096);
__pmusram_incbin_start = .;
*(.pmusram.incbin)
__pmusram_incbin_end = .;
__bl31_pmusram_data_start = .; __bl31_pmusram_data_start = .;
*(.pmusram.data) *(.pmusram.data)
__bl31_pmusram_data_end = .; __bl31_pmusram_data_end = .;
} >PMUSRAM } >PMUSRAM
} }
......
...@@ -7,13 +7,6 @@ ...@@ -7,13 +7,6 @@
#ifndef __M0_PARAM_H__ #ifndef __M0_PARAM_H__
#define __M0_PARAM_H__ #define __M0_PARAM_H__
#ifndef __LINKER__
enum {
M0_FUNC_SUSPEND = 0,
M0_FUNC_DRAM = 1,
};
#endif /* __LINKER__ */
#define PARAM_ADDR 0xc0 #define PARAM_ADDR 0xc0
#define PARAM_M0_FUNC 0x00 #define PARAM_M0_FUNC 0x00
......
...@@ -82,12 +82,15 @@ BUILD_M0 := ${BUILD_PLAT}/m0 ...@@ -82,12 +82,15 @@ BUILD_M0 := ${BUILD_PLAT}/m0
RK3399M0FW=${BUILD_M0}/${PLAT_M0}.bin RK3399M0FW=${BUILD_M0}/${PLAT_M0}.bin
$(eval $(call add_define,RK3399M0FW)) $(eval $(call add_define,RK3399M0FW))
RK3399M0PMUFW=${BUILD_M0}/${PLAT_M0}pmu.bin
$(eval $(call add_define,RK3399M0PMUFW))
HDCPFW=${RK_PLAT_SOC}/drivers/dp/hdcp.bin HDCPFW=${RK_PLAT_SOC}/drivers/dp/hdcp.bin
$(eval $(call add_define,HDCPFW)) $(eval $(call add_define,HDCPFW))
# CCACHE_EXTRAFILES is needed because ccache doesn't handle .incbin # CCACHE_EXTRAFILES is needed because ccache doesn't handle .incbin
export CCACHE_EXTRAFILES export CCACHE_EXTRAFILES
${BUILD_PLAT}/bl31/pmu_fw.o: CCACHE_EXTRAFILES=$(RK3399M0FW) ${BUILD_PLAT}/bl31/pmu_fw.o: CCACHE_EXTRAFILES=$(RK3399M0FW):$(RK3399M0PMUFW)
${RK_PLAT_SOC}/drivers/pmu/pmu_fw.c: $(RK3399M0FW) ${RK_PLAT_SOC}/drivers/pmu/pmu_fw.c: $(RK3399M0FW)
${BUILD_PLAT}/bl31/cdn_dp.o: CCACHE_EXTRAFILES=$(HDCPFW) ${BUILD_PLAT}/bl31/cdn_dp.o: CCACHE_EXTRAFILES=$(HDCPFW)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment