1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2015 by Bogdan Kolbov *
6 ***************************************************************************/
14 /* K1921VK01T has 128-bitwidth flash, so it`s able to load 4x32-bit words at the time.
15 * And only after all words loaded we can start write
18 /* Registers addresses */
19 #define FLASH_FMA 0x00 /* Address reg */
20 #define FLASH_FMD1 0x04 /* Data1 reg */
21 #define FLASH_FMC 0x08 /* Command reg */
22 #define FLASH_FCIS 0x0C /* Operation Status reg */
23 #define FLASH_FCIC 0x14 /* Operation Status Clear reg */
24 #define FLASH_FMD2 0x50 /* Data2 reg */
25 #define FLASH_FMD3 0x54 /* Data3 reg */
26 #define FLASH_FMD4 0x58 /* Data4 reg*/
29 * r0 - write cmd (in), status (out)
40 ldr r7, =#0xA001C000 /* Flash reg base*/
43 ldr r6, [r2, #0] /* read wp */
44 cmp r6, #0 /* abort if wp == 0 */
46 ldr r5, [r2, #4] /* read rp */
47 cmp r5, r6 /* wait until rp != wp */
52 ldr r6, [r5] /* read data1 */
53 str r6, [r7, #FLASH_FMD1]
56 ldr r6, [r5] /* read data2 */
57 str r6, [r7, #FLASH_FMD2]
60 ldr r6, [r5] /* read data3 */
61 str r6, [r7, #FLASH_FMD3]
64 ldr r6, [r5] /* read data4 */
65 str r6, [r7, #FLASH_FMD4]
69 str r4, [r7, #FLASH_FMA] /* set addr */
71 str r0, [r7, #FLASH_FMC] /* write cmd */
74 ldr r6, [r7, #FLASH_FCIS] /* wait until flag set */
78 cmp r6, #2 /* check the error bit */
81 movs r6, #1 /* clear flags */
82 str r6, [r7, #FLASH_FCIC]
84 cmp r5, r3 /* wrap rp at end of buffer */
89 str r5, [r2, #4] /* store rp */
90 subs r1, r1, #1 /* decrement 16-byte block count */
92 beq exit /* loop if not done */
97 str r0, [r2, #4] /* set rp = 0 on error */
99 mov r0, r6 /* return status in r0 */