1 /***************************************************************************
2 * Copyright (C) 2010 by Spencer Oliver *
3 * spen@spen-soft.co.uk *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 * $a0 src adr - ram + result
27 * $a1 dest adr - flash
28 * $a2 count (32bit words)
32 * $t0, $t1, $t2, $t3, $t4, $t5
33 * $s0, $s1, $s3, $s4, $s5
43 ori $t0
, 0x6655 /* NVMKEY1 */
45 ori $t1
, 0x99AA /* NVMKEY2 */
47 ori $t2
, 0xF400 /* NVMCON */
48 ori $t3
, $zero
, 0x4003 /* NVMCON row write cmd */
49 ori $t4
, $zero
, 0x8000 /* NVMCON start cmd */
52 /* can we perform a row write: 128 32bit words */
54 bne $s3
, $zero
, write_word
55 ori $t5
, $zero
, 0x4000 /* NVMCON clear cmd */
57 /* perform row write 512 bytes */
58 sw $a1
, 32($t2
) /* set NVMADDR with dest addr - real addr */
59 sw $a0
, 64($t2
) /* set NVMSRCADDR with src addr - real addr */
64 beq $zero
, $zero
, write_row
68 /* write 32bit words */
71 or $a0
, $a0
, $s5
/* convert to virtual addr */
73 beq $zero
, $zero
, next_word
74 ori $t3
, $zero
, 0x4001 /* NVMCON word write cmd */
77 lw $s4
, 0($a0
) /* load data - from virtual addr */
78 sw $s4
, 48($t2
) /* set NVMDATA with data */
79 sw $a1
, 32($t2
) /* set NVMADDR with dest addr - real addr */
86 bne $a2
, $zero
, prog_word
90 beq $zero
, $zero
, exit
94 /* save result to $a0 */
101 .type progflash, @function
106 sw $t3
, 0($t2
) /* set NVMWREN */
107 sw $t0
, 16($t2
) /* write NVMKEY1 */
108 sw $t1
, 16($t2
) /* write NVMKEY2 */
109 sw $t4
, 8($t2
) /* start operation */
114 bne $s0
, $zero
, waitflash
117 /* following is to comply with errata #34
118 * 500ns delay required */
123 /* check for errors */
125 andi $s1
, $zero
, 0x3000
126 bne $s1
, $zero
, error
127 sw $t5
, 4($t2
) /* clear NVMWREN */