blob: 263b592448fc063e5611af14f990c3e898666bc3 [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 *
25 * $Id$
26 */
27
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000028#include <stdio.h>
Ollie Lho184a4042005-11-26 21:55:36 +000029#include <stdint.h>
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000030#include "flash.h"
31#include "jedec.h"
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000032#include "mx29f002.h"
Ollie Lho184a4042005-11-26 21:55:36 +000033#include "debug.h"
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000034
Ollie Lho761bf1b2004-03-20 16:46:10 +000035int probe_29f002(struct flashchip *flash)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000036{
Ollie Lho184a4042005-11-26 21:55:36 +000037 volatile uint8_t *bios = flash->virt_addr;
38 uint8_t id1, id2;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000039
40 *(bios + 0x5555) = 0xAA;
41 *(bios + 0x2AAA) = 0x55;
42 *(bios + 0x5555) = 0x90;
Ollie Lho761bf1b2004-03-20 16:46:10 +000043
Ollie Lho184a4042005-11-26 21:55:36 +000044 id1 = *(volatile uint8_t *) bios;
45 id2 = *(volatile uint8_t *) (bios + 0x01);
Ollie Lho761bf1b2004-03-20 16:46:10 +000046
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000047 *bios = 0xF0;
48
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000049 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000050
Ollie Lho184a4042005-11-26 21:55:36 +000051 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000052 if (id1 == flash->manufacture_id && id2 == flash->model_id)
53 return 1;
54
55 return 0;
56}
57
Ollie Lho761bf1b2004-03-20 16:46:10 +000058int erase_29f002(struct flashchip *flash)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000059{
Ollie Lho184a4042005-11-26 21:55:36 +000060 volatile uint8_t *bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000061
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000062 *(bios + 0x555) = 0xF0;
63 *(bios + 0x555) = 0xAA;
64 *(bios + 0x2AA) = 0x55;
65 *(bios + 0x555) = 0x80;
66 *(bios + 0x555) = 0xAA;
67 *(bios + 0x2AA) = 0x55;
68 *(bios + 0x555) = 0x10;
69
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000070 myusec_delay(100);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000071 toggle_ready_jedec(bios);
72
73 // while ((*bios & 0x40) != 0x40)
74 //;
75
76#if 0
77 toggle_ready_jedec(bios);
78 *(bios + 0x0ffff) = 0x30;
79 *(bios + 0x1ffff) = 0x30;
80 *(bios + 0x2ffff) = 0x30;
81 *(bios + 0x37fff) = 0x30;
82 *(bios + 0x39fff) = 0x30;
83 *(bios + 0x3bfff) = 0x30;
84#endif
85
Ollie Lho761bf1b2004-03-20 16:46:10 +000086 return (0);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000087}
88
Ollie Lho184a4042005-11-26 21:55:36 +000089int write_29f002(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000090{
Ollie Lho761bf1b2004-03-20 16:46:10 +000091 int i;
92 int total_size = flash->total_size * 1024;
Ollie Lho184a4042005-11-26 21:55:36 +000093 volatile uint8_t *bios = flash->virt_addr;
94 volatile uint8_t *dst = bios;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000095
Ollie Lho761bf1b2004-03-20 16:46:10 +000096 *bios = 0xF0;
97 myusec_delay(10);
98 erase_29f002(flash);
99 //*bios = 0xF0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000100#if 1
Ollie Lho761bf1b2004-03-20 16:46:10 +0000101 printf("Programming Page: ");
102 for (i = 0; i < total_size; i++) {
103 /* write to the sector */
104 if ((i & 0xfff) == 0)
105 printf("address: 0x%08lx", (unsigned long) i);
106 *(bios + 0x5555) = 0xAA;
107 *(bios + 0x2AAA) = 0x55;
108 *(bios + 0x5555) = 0xA0;
109 *dst++ = *buf++;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000110
Ollie Lho761bf1b2004-03-20 16:46:10 +0000111 /* wait for Toggle bit ready */
112 toggle_ready_jedec(dst);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000113
Ollie Lho761bf1b2004-03-20 16:46:10 +0000114 if ((i & 0xfff) == 0)
115 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
116 }
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000117#endif
Ollie Lho761bf1b2004-03-20 16:46:10 +0000118 printf("\n");
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000119
Ollie Lho761bf1b2004-03-20 16:46:10 +0000120 return (0);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000121}