blob: ac363efd65ec1a898a24ad9a80ba407aee5cfbc2 [file] [log] [blame]
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +00001/*
2 * mx29f002.c: driver for MXIC MX29F002 flash models
3 *
4 *
5 * Copyright 2000 Silicon Integrated System Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 *
22 * Reference:
23 * MX29F002/002N data sheet
24 *
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000025 */
26
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000027#include <stdio.h>
Ollie Lho184a4042005-11-26 21:55:36 +000028#include <stdint.h>
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000029#include "flash.h"
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000030
Ollie Lho761bf1b2004-03-20 16:46:10 +000031int probe_29f002(struct flashchip *flash)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000032{
Stefan Reinauerce532972007-05-23 17:20:56 +000033 volatile uint8_t *bios = flash->virtual_memory;
Ollie Lho184a4042005-11-26 21:55:36 +000034 uint8_t id1, id2;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000035
36 *(bios + 0x5555) = 0xAA;
37 *(bios + 0x2AAA) = 0x55;
38 *(bios + 0x5555) = 0x90;
Ollie Lho761bf1b2004-03-20 16:46:10 +000039
Uwe Hermann0b7afe62007-04-01 19:44:21 +000040 id1 = *(volatile uint8_t *)bios;
41 id2 = *(volatile uint8_t *)(bios + 0x01);
Ollie Lho761bf1b2004-03-20 16:46:10 +000042
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000043 *bios = 0xF0;
44
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000045 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000046
Ollie Lho184a4042005-11-26 21:55:36 +000047 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000048 if (id1 == flash->manufacture_id && id2 == flash->model_id)
49 return 1;
50
51 return 0;
52}
53
Ollie Lho761bf1b2004-03-20 16:46:10 +000054int erase_29f002(struct flashchip *flash)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000055{
Stefan Reinauerce532972007-05-23 17:20:56 +000056 volatile uint8_t *bios = flash->virtual_memory;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000057
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000058 *(bios + 0x555) = 0xF0;
59 *(bios + 0x555) = 0xAA;
60 *(bios + 0x2AA) = 0x55;
61 *(bios + 0x555) = 0x80;
62 *(bios + 0x555) = 0xAA;
63 *(bios + 0x2AA) = 0x55;
64 *(bios + 0x555) = 0x10;
65
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000066 myusec_delay(100);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000067 toggle_ready_jedec(bios);
68
69 // while ((*bios & 0x40) != 0x40)
70 //;
71
72#if 0
73 toggle_ready_jedec(bios);
74 *(bios + 0x0ffff) = 0x30;
75 *(bios + 0x1ffff) = 0x30;
76 *(bios + 0x2ffff) = 0x30;
77 *(bios + 0x37fff) = 0x30;
78 *(bios + 0x39fff) = 0x30;
79 *(bios + 0x3bfff) = 0x30;
80#endif
81
Uwe Hermannffec5f32007-08-23 16:08:21 +000082 return 0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000083}
84
Ollie Lho184a4042005-11-26 21:55:36 +000085int write_29f002(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000086{
Ollie Lho761bf1b2004-03-20 16:46:10 +000087 int i;
88 int total_size = flash->total_size * 1024;
Stefan Reinauerce532972007-05-23 17:20:56 +000089 volatile uint8_t *bios = flash->virtual_memory;
Ollie Lho184a4042005-11-26 21:55:36 +000090 volatile uint8_t *dst = bios;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000091
Ollie Lho761bf1b2004-03-20 16:46:10 +000092 *bios = 0xF0;
93 myusec_delay(10);
94 erase_29f002(flash);
95 //*bios = 0xF0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000096#if 1
Ollie Lho761bf1b2004-03-20 16:46:10 +000097 printf("Programming Page: ");
98 for (i = 0; i < total_size; i++) {
99 /* write to the sector */
100 if ((i & 0xfff) == 0)
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000101 printf("address: 0x%08lx", (unsigned long)i);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000102 *(bios + 0x5555) = 0xAA;
103 *(bios + 0x2AAA) = 0x55;
104 *(bios + 0x5555) = 0xA0;
105 *dst++ = *buf++;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000106
Ollie Lho761bf1b2004-03-20 16:46:10 +0000107 /* wait for Toggle bit ready */
108 toggle_ready_jedec(dst);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000109
Ollie Lho761bf1b2004-03-20 16:46:10 +0000110 if ((i & 0xfff) == 0)
111 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
112 }
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000113#endif
Ollie Lho761bf1b2004-03-20 16:46:10 +0000114 printf("\n");
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000115
Uwe Hermannffec5f32007-08-23 16:08:21 +0000116 return 0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000117}