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