1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) ASPEED Technology Inc.
4 * Chia-Wei Wang <chiawei_wang@aspeedtech.com>
5 */
6
7#include <config.h>
8#include <asm/armv7.h>
9#include <linux/linkage.h>
10
11#define AST_SCU_BASE		(0x1E6E2000)
12#define AST_SCU_HW_STRAP1	(AST_SCU_BASE + 0x500)
13
14#define AST_FMC_BASE		(0x1E620000)
15#define AST_FMC_INT_CTRL_STAT	(AST_FMC_BASE + 0x008)
16#define AST_FMC_DMA_CTRL	(AST_FMC_BASE + 0x080)
17#define AST_FMC_DMA_FLASH_ADDR	(AST_FMC_BASE + 0x084)
18#define AST_FMC_DMA_DRAM_ADDR	(AST_FMC_BASE + 0x088)
19#define AST_FMC_DMA_LENGTH	(AST_FMC_BASE + 0x08C)
20
21/*
22 * void aspeed_bootmode(void)
23 *
24 * return the boot mode according to the HW strap information
25 */
26ENTRY(aspeed_bootmode)
27	ldr	r1, =AST_SCU_HW_STRAP1
28	ldr	r0, [r1]
29	tst	r0, #0x4
30	moveq	r0, #0x0	@; AST_BOOTMODE_SPI
31	movne	r0, #0x1	@; AST_BOOTMODE_EMMC
32	mov	pc, lr
33ENDPROC(aspeed_bootmode)
34
35/*
36 * void aspeed_spi_fastcpy(u32 mem_addr, u32 spi_addr, u32 count)
37 *
38 * perform FMC SPI DMA to speed up flash copy.
39 * @dst: destination memory address
40 * @src: source SPI address
41 * @count: number of bytes to be copied, 4-byte aligned
42 *
43 * NOTE that the caller must ensure the validity of parameters.
44 */
45ENTRY(aspeed_spi_fastcpy)
46	ldr	r3, =AST_FMC_DMA_DRAM_ADDR
47	str	r0, [r3]
48
49	ldr	r3, =AST_FMC_DMA_FLASH_ADDR
50	str	r1, [r3]
51
52	ldr	r3, =AST_FMC_DMA_LENGTH
53	str	r2, [r3]
54
55	ldr	r0, =AST_FMC_DMA_CTRL
56	mov	r1, #1
57	str	r1, [r0]
58
59	ldr	r0, =AST_FMC_INT_CTRL_STAT
60polling:
61	ldr	r1, [r0]
62	tst	r1, #(1 << 11)
63	beq	polling
64
65	ldr	r0, =AST_FMC_DMA_CTRL
66	mov	r1, #0
67	str	r1, [r0]
68
69	mov	pc, lr
70ENDPROC(aspeed_spi_fastcpy)
71