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 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 29 | static __inline__ int erase_block_49fl004(volatile unsigned char *bios, |
| 30 | unsigned long address) |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 31 | { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 32 | volatile unsigned char *Temp; |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 33 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 34 | Temp = bios + 0x5555; /* set up address to be C000:5555h */ |
| 35 | *Temp = 0xAA; /* write data 0xAA to the address */ |
| 36 | myusec_delay(10); |
| 37 | Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */ |
| 38 | *Temp = 0x55; /* write data 0x55 to the address */ |
| 39 | myusec_delay(10); |
| 40 | Temp = bios + 0x5555; /* set up address to be C000:5555h */ |
| 41 | *Temp = 0x80; /* write data 0x80 to the address */ |
| 42 | myusec_delay(10); |
| 43 | Temp = bios + 0x5555; /* set up address to be C000:5555h */ |
| 44 | *Temp = 0xAA; /* write data 0xAA to the address */ |
| 45 | myusec_delay(10); |
| 46 | Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */ |
| 47 | *Temp = 0x55; /* write data 0x55 to the address */ |
| 48 | myusec_delay(10); |
| 49 | Temp = bios + address; /* set up address to be C000:5555h */ |
| 50 | *Temp = 0x50; /* write data 0x50 to the address */ |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 51 | |
| 52 | /* wait for Toggle bit ready */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 53 | toggle_ready_jedec(bios); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 54 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 55 | return (0); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 56 | } |
Ollie Lho | 856943d | 2004-03-18 20:35:33 +0000 | [diff] [blame] | 57 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 58 | int write_49fl004(struct flashchip *flash, unsigned char *buf) |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 59 | { |
| 60 | int i; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 61 | int total_size = flash->total_size * 1024, page_size = |
| 62 | flash->page_size; |
| 63 | volatile char *bios = flash->virt_addr; |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 64 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 65 | printf("Programming Page: "); |
| 66 | for (i = 0; i < total_size / page_size; i++) { |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 67 | /* erase the page before programming */ |
| 68 | erase_block_49fl004(bios, i * page_size); |
| 69 | |
| 70 | /* write to the sector */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 71 | printf("%04d at address: 0x%08x", i, i * page_size); |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame^] | 72 | write_sector_jedec(bios, buf + i * page_size, |
| 73 | bios + i * page_size, page_size); |
| 74 | 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"); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 75 | fflush(stdout); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 76 | } |
| 77 | printf("\n"); |
| 78 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 79 | return (0); |
Ronald G. Minnich | e3dad01 | 2004-02-10 21:34:18 +0000 | [diff] [blame] | 80 | } |