Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * am29f040.c: driver for programming AMD am29f040b 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 | * AMD Am29F040B data sheet |
| 24 | * $Id$ |
| 25 | */ |
| 26 | |
| 27 | #include "flash.h" |
| 28 | #include "jedec.h" |
| 29 | |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 30 | static __inline__ erase_sector_29f040b (volatile char * bios, unsigned long address) |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 31 | { |
| 32 | *(bios + 0x555) = 0xAA; |
| 33 | *(bios + 0x2AA) = 0x55; |
| 34 | *(bios + 0x555) = 0x80; |
| 35 | *(bios + 0x555) = 0xAA; |
| 36 | *(bios + 0x2AA) = 0x55; |
| 37 | *(bios + address) = 0x30; |
| 38 | |
| 39 | sleep(2); |
| 40 | |
| 41 | /* wait for Toggle bit ready */ |
| 42 | toggle_ready_jedec(bios + address); |
| 43 | } |
| 44 | |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 45 | static __inline__ write_sector_29f040b(volatile char * bios, unsigned char * src, |
| 46 | volatile unsigned char * dst, unsigned int page_size) |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 47 | { |
| 48 | int i; |
| 49 | |
| 50 | for (i = 0; i < page_size; i++) { |
| 51 | printf("0x%08x", (unsigned long) dst - (unsigned long) bios); |
| 52 | |
| 53 | *(bios + 0x555) = 0xAA; |
| 54 | *(bios + 0x2AA) = 0x55; |
| 55 | *(bios + 0x555) = 0xA0; |
| 56 | *dst++ = *src++; |
| 57 | |
| 58 | /* wait for Toggle bit ready */ |
| 59 | toggle_ready_jedec(bios); |
| 60 | |
| 61 | printf("\b\b\b\b\b\b\b\b\b\b"); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | int probe_29f040b (struct flashchip * flash) |
| 66 | { |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 67 | volatile char * bios = flash->virt_addr; |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 68 | unsigned char id1, id2; |
| 69 | |
| 70 | *(bios + 0x555) = 0xAA; |
| 71 | *(bios + 0x2AA) = 0x55; |
| 72 | *(bios + 0x555) = 0x90; |
| 73 | |
| 74 | id1 = *(unsigned char *) bios; |
| 75 | id2 = *(unsigned char *) (bios + 0x01); |
| 76 | |
| 77 | *bios = 0xF0; |
| 78 | |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 79 | myusec_delay(10); |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 80 | |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 81 | printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2); |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 82 | if (id1 == flash->manufacture_id && id2 == flash->model_id) |
| 83 | return 1; |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | int erase_29f040b (struct flashchip * flash) |
| 89 | { |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 90 | volatile char * bios = flash->virt_addr; |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 91 | |
| 92 | *(bios + 0x555) = 0xAA; |
| 93 | *(bios + 0x2AA) = 0x55; |
| 94 | *(bios + 0x555) = 0x80; |
| 95 | *(bios + 0x555) = 0xAA; |
| 96 | *(bios + 0x2AA) = 0x55; |
| 97 | *(bios + 0x555) = 0x10; |
| 98 | |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 99 | myusec_delay(10); |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 100 | toggle_ready_jedec(bios); |
| 101 | } |
| 102 | |
| 103 | int write_29f040b (struct flashchip * flash, char * buf) |
| 104 | { |
| 105 | int i; |
| 106 | int total_size = flash->total_size * 1024, page_size = flash->page_size; |
Ronald G. Minnich | ef5779d | 2002-01-29 20:18:02 +0000 | [diff] [blame^] | 107 | volatile char * bios = flash->virt_addr; |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 108 | |
| 109 | printf ("Programming Page: "); |
| 110 | for (i = 0; i < total_size/page_size; i++) { |
| 111 | /* erase the page before programming */ |
| 112 | erase_sector_29f040b(bios, i * page_size); |
| 113 | |
| 114 | /* write to the sector */ |
| 115 | printf ("%04d at address: ", i); |
| 116 | write_sector_29f040b(bios, buf + i * page_size, bios + i * page_size, |
| 117 | page_size); |
| 118 | printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); |
| 119 | } |
| 120 | printf("\n"); |
| 121 | } |