xref: /rk3399_rockchip-uboot/arch/arm/include/asm/arch-mx7/mx7_plugin.S (revision 4f892924d238cc415891dbea336a0fdaff2f853b)
1*ac1475aeSPeng Fan/*
2*ac1475aeSPeng Fan * Copyright (C) 2016 Freescale Semiconductor, Inc.
3*ac1475aeSPeng Fan *
4*ac1475aeSPeng Fan * SPDX-License-Identifier:	GPL-2.0+
5*ac1475aeSPeng Fan */
6*ac1475aeSPeng Fan
7*ac1475aeSPeng Fan#include <config.h>
8*ac1475aeSPeng Fan
9*ac1475aeSPeng Fan#define ROM_API_TABLE_BASE_ADDR_LEGACY		0x180
10*ac1475aeSPeng Fan#define ROM_VERSION_OFFSET               	0x80
11*ac1475aeSPeng Fan#define ROM_API_HWCNFG_SETUP_OFFSET		0x08
12*ac1475aeSPeng Fan
13*ac1475aeSPeng Fanplugin_start:
14*ac1475aeSPeng Fan
15*ac1475aeSPeng Fan	push    {r0-r4, lr}
16*ac1475aeSPeng Fan
17*ac1475aeSPeng Fan	imx7_ddr_setting
18*ac1475aeSPeng Fan	imx7_clock_gating
19*ac1475aeSPeng Fan	imx7_qos_setting
20*ac1475aeSPeng Fan
21*ac1475aeSPeng Fan/*
22*ac1475aeSPeng Fan * Check if we are in USB serial download mode and immediately return to ROM
23*ac1475aeSPeng Fan * Need to check USB CTRL clock firstly, then check the USBx_nASYNCLISTADDR
24*ac1475aeSPeng Fan */
25*ac1475aeSPeng Fan	ldr r0, =0x30384680
26*ac1475aeSPeng Fan	ldr r1, [r0]
27*ac1475aeSPeng Fan	cmp r1, #0
28*ac1475aeSPeng Fan	beq normal_boot
29*ac1475aeSPeng Fan
30*ac1475aeSPeng Fan	ldr r0, =0x30B10158
31*ac1475aeSPeng Fan	ldr r1, [r0]
32*ac1475aeSPeng Fan	cmp r1, #0
33*ac1475aeSPeng Fan	beq normal_boot
34*ac1475aeSPeng Fan
35*ac1475aeSPeng Fan	pop {r0-r4, lr}
36*ac1475aeSPeng Fan	bx lr
37*ac1475aeSPeng Fan
38*ac1475aeSPeng Fannormal_boot:
39*ac1475aeSPeng Fan
40*ac1475aeSPeng Fan/*
41*ac1475aeSPeng Fan * The following is to fill in those arguments for this ROM function
42*ac1475aeSPeng Fan * pu_irom_hwcnfg_setup(void **start, size_t *bytes, const void *boot_data)
43*ac1475aeSPeng Fan * This function is used to copy data from the storage media into DDR.
44*ac1475aeSPeng Fan * start - Initial (possibly partial) image load address on entry.
45*ac1475aeSPeng Fan *         Final image load address on exit.
46*ac1475aeSPeng Fan * bytes - Initial (possibly partial) image size on entry.
47*ac1475aeSPeng Fan *         Final image size on exit.
48*ac1475aeSPeng Fan * boot_data - Initial @ref ivt Boot Data load address.
49*ac1475aeSPeng Fan */
50*ac1475aeSPeng Fan	adr r0, boot_data2
51*ac1475aeSPeng Fan	adr r1, image_len2
52*ac1475aeSPeng Fan	adr r2, boot_data2
53*ac1475aeSPeng Fan
54*ac1475aeSPeng Fan/*
55*ac1475aeSPeng Fan * check the _pu_irom_api_table for the address
56*ac1475aeSPeng Fan */
57*ac1475aeSPeng Fanbefore_calling_rom___pu_irom_hwcnfg_setup:
58*ac1475aeSPeng Fan	ldr r3, =ROM_VERSION_OFFSET
59*ac1475aeSPeng Fan	ldr r4, [r3]
60*ac1475aeSPeng Fan	ldr r3, =ROM_API_TABLE_BASE_ADDR_LEGACY
61*ac1475aeSPeng Fan	ldr r4, [r3, #ROM_API_HWCNFG_SETUP_OFFSET]
62*ac1475aeSPeng Fan	blx r4
63*ac1475aeSPeng Fanafter_calling_rom___pu_irom_hwcnfg_setup:
64*ac1475aeSPeng Fan
65*ac1475aeSPeng Fan
66*ac1475aeSPeng Fan/* To return to ROM from plugin, we need to fill in these argument.
67*ac1475aeSPeng Fan * Here is what need to do:
68*ac1475aeSPeng Fan * Need to construct the paramters for this function before return to ROM:
69*ac1475aeSPeng Fan * plugin_download(void **start, size_t *bytes, UINT32 *ivt_offset)
70*ac1475aeSPeng Fan */
71*ac1475aeSPeng Fan	pop {r0-r4, lr}
72*ac1475aeSPeng Fan	push {r5}
73*ac1475aeSPeng Fan	ldr r5, boot_data2
74*ac1475aeSPeng Fan	str r5, [r0]
75*ac1475aeSPeng Fan	ldr r5, image_len2
76*ac1475aeSPeng Fan	str r5, [r1]
77*ac1475aeSPeng Fan	ldr r5, second_ivt_offset
78*ac1475aeSPeng Fan	str r5, [r2]
79*ac1475aeSPeng Fan	mov r0, #1
80*ac1475aeSPeng Fan	pop {r5}
81*ac1475aeSPeng Fan
82*ac1475aeSPeng Fan	/* return back to ROM code */
83*ac1475aeSPeng Fan	bx lr
84*ac1475aeSPeng Fan
85*ac1475aeSPeng Fan/* make the following data right in the end of the output*/
86*ac1475aeSPeng Fan.ltorg
87*ac1475aeSPeng Fan
88*ac1475aeSPeng Fan#define FLASH_OFFSET 0x400
89*ac1475aeSPeng Fan
90*ac1475aeSPeng Fan/*
91*ac1475aeSPeng Fan * second_ivt_offset is the offset from the "second_ivt_header" to
92*ac1475aeSPeng Fan * "image_copy_start", which involves FLASH_OFFSET, plus the first
93*ac1475aeSPeng Fan * ivt_header, the plugin code size itself recorded by "ivt2_header"
94*ac1475aeSPeng Fan */
95*ac1475aeSPeng Fan
96*ac1475aeSPeng Fansecond_ivt_offset:      .long (ivt2_header + 0x2C + FLASH_OFFSET)
97*ac1475aeSPeng Fan
98*ac1475aeSPeng Fan/*
99*ac1475aeSPeng Fan * The following is the second IVT header plus the second boot data
100*ac1475aeSPeng Fan */
101*ac1475aeSPeng Fanivt2_header:            .long 0x0
102*ac1475aeSPeng Fanapp2_code_jump_v:       .long 0x0
103*ac1475aeSPeng Fanreserv3:                .long 0x0
104*ac1475aeSPeng Fandcd2_ptr:               .long 0x0
105*ac1475aeSPeng Fanboot_data2_ptr:         .long 0x0
106*ac1475aeSPeng Fanself_ptr2:              .long 0x0
107*ac1475aeSPeng Fanapp_code_csf2:          .long 0x0
108*ac1475aeSPeng Fanreserv4:                .long 0x0
109*ac1475aeSPeng Fanboot_data2:             .long 0x0
110*ac1475aeSPeng Fanimage_len2:             .long 0x0
111*ac1475aeSPeng Fanplugin2:                .long 0x0
112