contrib: add GPL license tag on files that miss it
[fw/openocd] / contrib / loaders / flash / fm4 / erase.S
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /*
4  * Spansion FM4 flash sector erase algorithm
5  *
6  * Copyright (c) 2015 Andreas Färber
7  *
8  * Based on S6E2CC_MN709-00007 for S6E2CC/C5/C4/C3/C2/C1 series
9  */
10
11 #include "fm4.h"
12
13 #define RESULT_OKAY     0
14 #define RESULT_NONE     1
15 #define RESULT_TIMEOUT  2
16
17         .macro busy_wait, res, addr, tmp1, tmp2, tmp3
18
19         ldrb    \tmp1, [\addr] /* ignore */
20 1001:
21         ldrb    \tmp1, [\addr]
22         ldrb    \tmp2, [\addr]
23
24         and     \tmp3, \tmp1, #FLASH_TOGG
25         and     \tmp2, \tmp2, #FLASH_TOGG
26         cmp     \tmp3, \tmp2
27         beq     1010f
28
29         and     \tmp2, \tmp1, #FLASH_TLOV
30         cmp     \tmp2, #0
31         beq     1001b
32
33         ldrb    \tmp1, [\addr]
34         ldrb    \tmp2, [\addr]
35
36         and     \tmp3, \tmp1, #FLASH_TOGG
37         and     \tmp2, \tmp2, #FLASH_TOGG
38         cmp     \tmp3, \tmp2
39         beq     1010f
40
41         mov     \res, #RESULT_TIMEOUT
42         bkpt    #0
43 1010:
44         mov     \res, #RESULT_OKAY
45
46         .endm
47
48
49         .macro erase, cmdseqaddr1, cmdseqaddr2, sa, res, tmp1, tmp2, tmp3
50
51         mov     \res, #RESULT_NONE
52
53         mov     \tmp1, #0xAA
54         strh    \tmp1, [\cmdseqaddr1]
55         mov     \tmp2, #0x55
56         strh    \tmp2, [\cmdseqaddr2]
57         mov     \tmp3, #0x80
58         strh    \tmp3, [\cmdseqaddr1]
59         strh    \tmp1, [\cmdseqaddr1]
60         strh    \tmp2, [\cmdseqaddr2]
61         mov     \tmp3, #0x30
62         strh    \tmp3, [\sa]
63
64         busy_wait \res, \sa, \tmp1, \tmp2, \tmp3
65
66         .endm
67
68
69         /* r0 = 0xAA8
70          * r1 = 0x554
71          * r2 = SA
72          * r3 = result
73          */
74 erase:
75         erase r0, r1, r2, r3, r4, r5, r6
76
77         bkpt    #0
78
79 data: