1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2010 by Spencer Oliver *
5 * spen@spen-soft.co.uk *
6 ***************************************************************************/
14 * $a0 src adr - ram + result
15 * $a1 dest adr - flash
16 * $a2 count (32bit words)
20 * $t0, $t1, $t2, $t3, $t4, $t5
21 * $s0, $s1, $s3, $s4, $s5
31 ori $t0
, 0x6655 /* NVMKEY1 */
33 ori $t1
, 0x99AA /* NVMKEY2 */
35 ori $t2
, 0xF400 /* NVMCON */
36 ori $t3
, $zero
, 0x4003 /* NVMCON row write cmd */
37 ori $t4
, $zero
, 0x8000 /* NVMCON start cmd */
40 /* can we perform a row write: 128 32bit words */
42 bne $s3
, $zero
, write_word
43 ori $t5
, $zero
, 0x4000 /* NVMCON clear cmd */
45 /* perform row write 512 bytes */
46 sw $a1
, 32($t2
) /* set NVMADDR with dest addr - real addr */
47 sw $a0
, 64($t2
) /* set NVMSRCADDR with src addr - real addr */
52 beq $zero
, $zero
, write_row
56 /* write 32bit words */
59 or $a0
, $a0
, $s5
/* convert to virtual addr */
61 beq $zero
, $zero
, next_word
62 ori $t3
, $zero
, 0x4001 /* NVMCON word write cmd */
65 lw $s4
, 0($a0
) /* load data - from virtual addr */
66 sw $s4
, 48($t2
) /* set NVMDATA with data */
67 sw $a1
, 32($t2
) /* set NVMADDR with dest addr - real addr */
74 bne $a2
, $zero
, prog_word
78 beq $zero
, $zero
, exit
82 /* save result to $a0 */
89 .type progflash, @function
94 sw $t3
, 0($t2
) /* set NVMWREN */
95 sw $t0
, 16($t2
) /* write NVMKEY1 */
96 sw $t1
, 16($t2
) /* write NVMKEY2 */
97 sw $t4
, 8($t2
) /* start operation */
102 bne $s0
, $zero
, waitflash
105 /* following is to comply with errata #34
106 * 500ns delay required */
111 /* check for errors */
113 andi $s1
, $zero
, 0x3000
114 bne $s1
, $zero
, error
115 sw $t5
, 4($t2
) /* clear NVMWREN */