xref: /openbmc/u-boot/arch/arm/include/asm/arch-mx6/mx6_plugin.S (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */
2a45eb267SPeng Fan/*
3a45eb267SPeng Fan * Copyright (C) 2016 Freescale Semiconductor, Inc.
4a45eb267SPeng Fan */
5a45eb267SPeng Fan
6a45eb267SPeng Fan#include <config.h>
7a45eb267SPeng Fan
8a45eb267SPeng Fan#ifdef CONFIG_ROM_UNIFIED_SECTIONS
9a45eb267SPeng Fan#define ROM_API_TABLE_BASE_ADDR_LEGACY		0x180
10a45eb267SPeng Fan#define ROM_VERSION_OFFSET               	0x80
11a45eb267SPeng Fan#else
12a45eb267SPeng Fan#define ROM_API_TABLE_BASE_ADDR_LEGACY		0xC0
13a45eb267SPeng Fan#define ROM_VERSION_OFFSET               	0x48
14a45eb267SPeng Fan#endif
15a45eb267SPeng Fan#define ROM_API_TABLE_BASE_ADDR_MX6DQ_TO15	0xC4
16a45eb267SPeng Fan#define ROM_API_TABLE_BASE_ADDR_MX6DL_TO12	0xC4
17a45eb267SPeng Fan#define ROM_API_HWCNFG_SETUP_OFFSET		0x08
18a45eb267SPeng Fan#define ROM_VERSION_TO10			0x10
19a45eb267SPeng Fan#define ROM_VERSION_TO12			0x12
20a45eb267SPeng Fan#define ROM_VERSION_TO15			0x15
21a45eb267SPeng Fan
22a45eb267SPeng Fanplugin_start:
23a45eb267SPeng Fan
24a45eb267SPeng Fan	push    {r0-r4, lr}
25a45eb267SPeng Fan
26a45eb267SPeng Fan	imx6_ddr_setting
27a45eb267SPeng Fan	imx6_clock_gating
28a45eb267SPeng Fan	imx6_qos_setting
29a45eb267SPeng Fan
30a45eb267SPeng Fan/*
31a45eb267SPeng Fan * The following is to fill in those arguments for this ROM function
32a45eb267SPeng Fan * pu_irom_hwcnfg_setup(void **start, size_t *bytes, const void *boot_data)
33a45eb267SPeng Fan * This function is used to copy data from the storage media into DDR.
34a45eb267SPeng Fan * start - Initial (possibly partial) image load address on entry.
35a45eb267SPeng Fan *         Final image load address on exit.
36a45eb267SPeng Fan * bytes - Initial (possibly partial) image size on entry.
37a45eb267SPeng Fan *         Final image size on exit.
38a45eb267SPeng Fan * boot_data - Initial @ref ivt Boot Data load address.
39a45eb267SPeng Fan */
40a45eb267SPeng Fan	adr r0, boot_data2
41a45eb267SPeng Fan	adr r1, image_len2
42a45eb267SPeng Fan	adr r2, boot_data2
43a45eb267SPeng Fan
44a45eb267SPeng Fan#ifdef CONFIG_NOR_BOOT
45a45eb267SPeng Fan#ifdef CONFIG_MX6SX
46a45eb267SPeng Fan	ldr r3, =ROM_VERSION_OFFSET
47a45eb267SPeng Fan	ldr r4, [r3]
48a45eb267SPeng Fan	cmp r4, #ROM_VERSION_TO10
49a45eb267SPeng Fan	bgt before_calling_rom___pu_irom_hwcnfg_setup
50a45eb267SPeng Fan	ldr r3, =0x00900b00
51a45eb267SPeng Fan	ldr r4, =0x50000000
52a45eb267SPeng Fan	str r4, [r3, #0x5c]
53a45eb267SPeng Fan#else
54a45eb267SPeng Fan	ldr r3, =0x00900800
55a45eb267SPeng Fan	ldr r4, =0x08000000
56a45eb267SPeng Fan	str r4, [r3, #0xc0]
57a45eb267SPeng Fan#endif
58a45eb267SPeng Fan#endif
59a45eb267SPeng Fan
60a45eb267SPeng Fan/*
61a45eb267SPeng Fan * check the _pu_irom_api_table for the address
62a45eb267SPeng Fan */
63a45eb267SPeng Fanbefore_calling_rom___pu_irom_hwcnfg_setup:
64a45eb267SPeng Fan	ldr r3, =ROM_VERSION_OFFSET
65a45eb267SPeng Fan	ldr r4, [r3]
66a45eb267SPeng Fan#if defined(CONFIG_MX6SOLO) || defined(CONFIG_MX6DL)
67a45eb267SPeng Fan	ldr r3, =ROM_VERSION_TO12
68a45eb267SPeng Fan	cmp r4, r3
69a45eb267SPeng Fan	ldrge r3, =ROM_API_TABLE_BASE_ADDR_MX6DL_TO12
70a45eb267SPeng Fan	ldrlt r3, =ROM_API_TABLE_BASE_ADDR_LEGACY
71a45eb267SPeng Fan#elif defined(CONFIG_MX6Q)
72a45eb267SPeng Fan	ldr r3, =ROM_VERSION_TO15
73a45eb267SPeng Fan	cmp r4, r3
74a45eb267SPeng Fan	ldrge r3, =ROM_API_TABLE_BASE_ADDR_MX6DQ_TO15
75a45eb267SPeng Fan	ldrlt r3, =ROM_API_TABLE_BASE_ADDR_LEGACY
76a45eb267SPeng Fan#else
77a45eb267SPeng Fan	ldr r3, =ROM_API_TABLE_BASE_ADDR_LEGACY
78a45eb267SPeng Fan#endif
79a45eb267SPeng Fan	ldr r4, [r3, #ROM_API_HWCNFG_SETUP_OFFSET]
80a45eb267SPeng Fan	blx r4
81a45eb267SPeng Fanafter_calling_rom___pu_irom_hwcnfg_setup:
82a45eb267SPeng Fan
83a45eb267SPeng Fan/*
84a45eb267SPeng Fan * ROM_API_HWCNFG_SETUP function enables MMU & Caches.
85a45eb267SPeng Fan * Thus disable MMU & Caches.
86a45eb267SPeng Fan */
87a45eb267SPeng Fan
88a45eb267SPeng Fan	mrc     p15, 0, r0, c1, c0, 0   /* read CP15 register 1 into r0*/
89a45eb267SPeng Fan	ands    r0, r0, #0x1            /* check if MMU is enabled */
90a45eb267SPeng Fan	beq     mmu_disable_notreq      /* exit if MMU is already disabled */
91a45eb267SPeng Fan
92a45eb267SPeng Fan	/* Disable caches, MMU */
93a45eb267SPeng Fan	mrc     p15, 0, r0, c1, c0, 0	/* read CP15 register 1 into r0 */
94a45eb267SPeng Fan	bic     r0, r0, #(1 << 2)	/* disable D Cache */
95a45eb267SPeng Fan	bic     r0, r0, #0x1		/* clear bit 0 ; MMU off */
96a45eb267SPeng Fan
97a45eb267SPeng Fan	bic     r0, r0, #(0x1 << 11)	/* disable Z, branch prediction */
98a45eb267SPeng Fan	bic     r0, r0, #(0x1 << 1)	/* disable A, Strict alignment */
99a45eb267SPeng Fan					/* check enabled. */
100a45eb267SPeng Fan	mcr     p15, 0, r0, c1, c0, 0	/* write CP15 register 1 */
101a45eb267SPeng Fan	mov     r0, r0
102a45eb267SPeng Fan	mov     r0, r0
103a45eb267SPeng Fan	mov     r0, r0
104a45eb267SPeng Fan	mov     r0, r0
105a45eb267SPeng Fan
106a45eb267SPeng Fanmmu_disable_notreq:
107a45eb267SPeng Fan    NOP
108a45eb267SPeng Fan
109a45eb267SPeng Fan/* To return to ROM from plugin, we need to fill in these argument.
110a45eb267SPeng Fan * Here is what need to do:
111a45eb267SPeng Fan * Need to construct the paramters for this function before return to ROM:
112a45eb267SPeng Fan * plugin_download(void **start, size_t *bytes, UINT32 *ivt_offset)
113a45eb267SPeng Fan */
114a45eb267SPeng Fan	pop {r0-r4, lr}
115a45eb267SPeng Fan	push {r5}
116a45eb267SPeng Fan	ldr r5, boot_data2
117a45eb267SPeng Fan	str r5, [r0]
118a45eb267SPeng Fan	ldr r5, image_len2
119a45eb267SPeng Fan	str r5, [r1]
120a45eb267SPeng Fan	ldr r5, second_ivt_offset
121a45eb267SPeng Fan	str r5, [r2]
122a45eb267SPeng Fan	mov r0, #1
123a45eb267SPeng Fan	pop {r5}
124a45eb267SPeng Fan
125a45eb267SPeng Fan	/* return back to ROM code */
126a45eb267SPeng Fan	bx lr
127a45eb267SPeng Fan
128a45eb267SPeng Fan/* make the following data right in the end of the output*/
129a45eb267SPeng Fan.ltorg
130a45eb267SPeng Fan
131a45eb267SPeng Fan#if (defined(CONFIG_NOR_BOOT) || defined(CONFIG_QSPI_BOOT))
132a45eb267SPeng Fan#define FLASH_OFFSET 0x1000
133a45eb267SPeng Fan#else
134a45eb267SPeng Fan#define FLASH_OFFSET 0x400
135a45eb267SPeng Fan#endif
136a45eb267SPeng Fan
137a45eb267SPeng Fan/*
138a45eb267SPeng Fan * second_ivt_offset is the offset from the "second_ivt_header" to
139a45eb267SPeng Fan * "image_copy_start", which involves FLASH_OFFSET, plus the first
140a45eb267SPeng Fan * ivt_header, the plugin code size itself recorded by "ivt2_header"
141a45eb267SPeng Fan */
142a45eb267SPeng Fan
143a45eb267SPeng Fansecond_ivt_offset:      .long (ivt2_header + 0x2C + FLASH_OFFSET)
144a45eb267SPeng Fan
145a45eb267SPeng Fan/*
146a45eb267SPeng Fan * The following is the second IVT header plus the second boot data
147a45eb267SPeng Fan */
148a45eb267SPeng Fanivt2_header:            .long 0x0
149a45eb267SPeng Fanapp2_code_jump_v:       .long 0x0
150a45eb267SPeng Fanreserv3:                .long 0x0
151a45eb267SPeng Fandcd2_ptr:               .long 0x0
152a45eb267SPeng Fanboot_data2_ptr:         .long 0x0
153a45eb267SPeng Fanself_ptr2:              .long 0x0
154a45eb267SPeng Fanapp_code_csf2:          .long 0x0
155a45eb267SPeng Fanreserv4:                .long 0x0
156a45eb267SPeng Fanboot_data2:             .long 0x0
157a45eb267SPeng Fanimage_len2:             .long 0x0
158a45eb267SPeng Fanplugin2:                .long 0x0
159