blob: 25921c64268d71d3116a45c63f80297755bb0d27 [file] [log] [blame]
Ronald G. Minniche3dad012004-02-10 21:34:18 +00001/*
2 * pm49fl004.c: driver for Pm49FL004 flash models.
3 *
4 *
5 * Copyright 2004 Tyan 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 */
23
24#include <stdio.h>
25#include "flash.h"
26#include "jedec.h"
27#include "pm49fl004.h"
28
29#define AUTO_PGRM 0x10
30#define CHIP_ERASE 0x30
31#define RESET 0xFF
32#define READ_ID 0x90
33
Ronald G. Minniche3dad012004-02-10 21:34:18 +000034static __inline__ int erase_block_49fl004 ( volatile unsigned char * bios ,unsigned long address)
35{
36 volatile unsigned char *Temp;
37
Ollie Lho73eca802004-03-19 22:10:07 +000038 Temp = bios + 0x5555; /* set up address to be C000:5555h */
39 *Temp = 0xAA; /* write data 0xAA to the address */
Ronald G. Minniche3dad012004-02-10 21:34:18 +000040 myusec_delay(10);
Ollie Lho73eca802004-03-19 22:10:07 +000041 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
42 *Temp = 0x55; /* write data 0x55 to the address */
Ronald G. Minniche3dad012004-02-10 21:34:18 +000043 myusec_delay(10);
Ollie Lho73eca802004-03-19 22:10:07 +000044 Temp = bios + 0x5555; /* set up address to be C000:5555h */
45 *Temp = 0x80; /* write data 0x80 to the address */
Ronald G. Minniche3dad012004-02-10 21:34:18 +000046 myusec_delay(10);
Ollie Lho73eca802004-03-19 22:10:07 +000047 Temp = bios + 0x5555; /* set up address to be C000:5555h */
48 *Temp = 0xAA; /* write data 0xAA to the address */
Ronald G. Minniche3dad012004-02-10 21:34:18 +000049 myusec_delay(10);
Ollie Lho73eca802004-03-19 22:10:07 +000050 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
51 *Temp = 0x55; /* write data 0x55 to the address */
Ronald G. Minniche3dad012004-02-10 21:34:18 +000052 myusec_delay(10);
Ollie Lho73eca802004-03-19 22:10:07 +000053 Temp = bios + address; /* set up address to be C000:5555h */
54 *Temp = 0x50; /* write data 0x50 to the address */
Ronald G. Minniche3dad012004-02-10 21:34:18 +000055
56 /* wait for Toggle bit ready */
57 toggle_ready_jedec(bios);
58
59 return(0);
60}
Ollie Lho856943d2004-03-18 20:35:33 +000061
Ronald G. Minniche3dad012004-02-10 21:34:18 +000062static __inline__ int write_block_49fl004(volatile char * bios,
Ollie Lho856943d2004-03-18 20:35:33 +000063 unsigned char * src,
64 volatile unsigned char * dst,
65 unsigned int page_size)
Ronald G. Minniche3dad012004-02-10 21:34:18 +000066{
67 int i;
68 volatile char *Temp;
69
70 for (i = 0; i < page_size; i++) {
71 if (*dst != 0xff) {
72 printf("FATAL: dst %p not erased (val 0x%x\n", dst, *dst);
73 return(-1);
74 }
75 /* transfer data from source to destination */
76 if (*src == 0xFF) {
77 dst++, src++;
78 /* If the data is 0xFF, don't program it */
79 continue;
80 }
81 Temp = (bios + 0x5555);
82 *Temp = 0xAA;
83 Temp = bios + 0x2AAA;
84 *Temp = 0x55;
85 Temp = bios + 0x5555;
86 *Temp = 0xA0;
87 *dst = *src;
88 toggle_ready_jedec(bios);
89 if (*dst != *src)
90 printf("BAD! dst 0x%lx val 0x%x src 0x%x\n",
91 (unsigned long)dst, *dst, *src);
92 dst++, src++;
93 }
94
95 return(0);
96}
97
Ronald G. Minniche3dad012004-02-10 21:34:18 +000098int write_49fl004 (struct flashchip * flash, unsigned char * buf)
99{
100 int i;
101 int total_size = flash->total_size * 1024, page_size = flash->page_size;
102 volatile char * bios = flash->virt_addr;
103
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000104 printf ("Programming Page: ");
105 for (i = 0; i < total_size/page_size; i++) {
106 /* erase the page before programming */
107 erase_block_49fl004(bios, i * page_size);
108
109 /* write to the sector */
110 printf ("%04d at address: 0x%08x", i, i * page_size);
111 write_block_49fl004(bios, buf + i * page_size, bios + i * page_size,
Ollie Lhof36ad4f2004-03-18 20:31:54 +0000112 page_size);
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000113 printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
114 fflush(stdout);
115 }
116 printf("\n");
117
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000118 return(0);
119}