Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 34 | static __inline__ int erase_block_49fl004(volatile unsigned char *bios, |
| 35 | unsigned long address) |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 36 | { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 37 | volatile unsigned char *Temp; |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 38 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 39 | Temp = bios + 0x5555; /* set up address to be C000:5555h */ |
| 40 | *Temp = 0xAA; /* write data 0xAA to the address */ |
| 41 | myusec_delay(10); |
| 42 | Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */ |
| 43 | *Temp = 0x55; /* write data 0x55 to the address */ |
| 44 | myusec_delay(10); |
| 45 | Temp = bios + 0x5555; /* set up address to be C000:5555h */ |
| 46 | *Temp = 0x80; /* write data 0x80 to the address */ |
| 47 | myusec_delay(10); |
| 48 | Temp = bios + 0x5555; /* set up address to be C000:5555h */ |
| 49 | *Temp = 0xAA; /* write data 0xAA to the address */ |
| 50 | myusec_delay(10); |
| 51 | Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */ |
| 52 | *Temp = 0x55; /* write data 0x55 to the address */ |
| 53 | myusec_delay(10); |
| 54 | Temp = bios + address; /* set up address to be C000:5555h */ |
| 55 | *Temp = 0x50; /* write data 0x50 to the address */ |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 56 | |
| 57 | /* wait for Toggle bit ready */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 58 | toggle_ready_jedec(bios); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 59 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 60 | return (0); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 61 | } |
Ollie Lho | 856943d | 2004-03-18 20:35:33 +0000 | [diff] [blame] | 62 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 63 | static __inline__ int write_block_49fl004(volatile char *bios, |
| 64 | unsigned char *src, |
| 65 | volatile unsigned char *dst, |
Ollie Lho | 856943d | 2004-03-18 20:35:33 +0000 | [diff] [blame] | 66 | unsigned int page_size) |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 67 | { |
| 68 | int i; |
| 69 | volatile char *Temp; |
| 70 | |
| 71 | for (i = 0; i < page_size; i++) { |
| 72 | if (*dst != 0xff) { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 73 | printf("FATAL: dst %p not erased (val 0x%x\n", dst, |
| 74 | *dst); |
| 75 | return (-1); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 76 | } |
| 77 | /* transfer data from source to destination */ |
| 78 | if (*src == 0xFF) { |
| 79 | dst++, src++; |
| 80 | /* If the data is 0xFF, don't program it */ |
| 81 | continue; |
| 82 | } |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 83 | Temp = (bios + 0x5555); |
| 84 | *Temp = 0xAA; |
| 85 | Temp = bios + 0x2AAA; |
| 86 | *Temp = 0x55; |
| 87 | Temp = bios + 0x5555; |
| 88 | *Temp = 0xA0; |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 89 | *dst = *src; |
| 90 | toggle_ready_jedec(bios); |
| 91 | if (*dst != *src) |
| 92 | printf("BAD! dst 0x%lx val 0x%x src 0x%x\n", |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 93 | (unsigned long) dst, *dst, *src); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 94 | dst++, src++; |
| 95 | } |
| 96 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 97 | return (0); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 100 | int write_49fl004(struct flashchip *flash, unsigned char *buf) |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 101 | { |
| 102 | int i; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 103 | int total_size = flash->total_size * 1024, page_size = |
| 104 | flash->page_size; |
| 105 | volatile char *bios = flash->virt_addr; |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 106 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 107 | printf("Programming Page: "); |
| 108 | for (i = 0; i < total_size / page_size; i++) { |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 109 | /* erase the page before programming */ |
| 110 | erase_block_49fl004(bios, i * page_size); |
| 111 | |
| 112 | /* write to the sector */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 113 | printf("%04d at address: 0x%08x", i, i * page_size); |
| 114 | write_block_49fl004(bios, buf + i * page_size, |
| 115 | bios + i * page_size, page_size); |
| 116 | printf |
| 117 | ("\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"); |
| 118 | fflush(stdout); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 119 | } |
| 120 | printf("\n"); |
| 121 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 122 | return (0); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 123 | } |