Pete Popov | 002fa30 | 2005-02-27 21:50:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Flash memory access on AMD Alchemy evaluation boards |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame^] | 3 | * |
| 4 | * $Id: alchemy-flash.c,v 1.2 2005/11/07 11:14:26 gleixner Exp $ |
Pete Popov | 002fa30 | 2005-02-27 21:50:25 +0000 | [diff] [blame] | 5 | * |
| 6 | * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com> |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame^] | 7 | * |
Pete Popov | 002fa30 | 2005-02-27 21:50:25 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/config.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/kernel.h> |
| 15 | |
| 16 | #include <linux/mtd/mtd.h> |
| 17 | #include <linux/mtd/map.h> |
| 18 | #include <linux/mtd/partitions.h> |
| 19 | |
| 20 | #include <asm/io.h> |
| 21 | |
| 22 | #ifdef DEBUG_RW |
| 23 | #define DBG(x...) printk(x) |
| 24 | #else |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame^] | 25 | #define DBG(x...) |
Pete Popov | 002fa30 | 2005-02-27 21:50:25 +0000 | [diff] [blame] | 26 | #endif |
| 27 | |
| 28 | #ifdef CONFIG_MIPS_PB1000 |
| 29 | #define BOARD_MAP_NAME "Pb1000 Flash" |
| 30 | #define BOARD_FLASH_SIZE 0x00800000 /* 8MB */ |
| 31 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 32 | #endif |
| 33 | |
| 34 | #ifdef CONFIG_MIPS_PB1500 |
| 35 | #define BOARD_MAP_NAME "Pb1500 Flash" |
| 36 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ |
| 37 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 38 | #endif |
| 39 | |
| 40 | #ifdef CONFIG_MIPS_PB1100 |
| 41 | #define BOARD_MAP_NAME "Pb1100 Flash" |
| 42 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ |
| 43 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 44 | #endif |
| 45 | |
| 46 | #ifdef CONFIG_MIPS_PB1550 |
| 47 | #define BOARD_MAP_NAME "Pb1550 Flash" |
| 48 | #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ |
| 49 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 50 | #endif |
| 51 | |
| 52 | #ifdef CONFIG_MIPS_PB1200 |
| 53 | #define BOARD_MAP_NAME "Pb1200 Flash" |
| 54 | #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ |
| 55 | #define BOARD_FLASH_WIDTH 2 /* 16-bits */ |
| 56 | #endif |
| 57 | |
| 58 | #ifdef CONFIG_MIPS_DB1000 |
| 59 | #define BOARD_MAP_NAME "Db1000 Flash" |
| 60 | #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ |
| 61 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 62 | #endif |
| 63 | |
| 64 | #ifdef CONFIG_MIPS_DB1500 |
| 65 | #define BOARD_MAP_NAME "Db1500 Flash" |
| 66 | #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ |
| 67 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 68 | #endif |
| 69 | |
| 70 | #ifdef CONFIG_MIPS_DB1100 |
| 71 | #define BOARD_MAP_NAME "Db1100 Flash" |
| 72 | #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ |
| 73 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 74 | #endif |
| 75 | |
| 76 | #ifdef CONFIG_MIPS_DB1550 |
| 77 | #define BOARD_MAP_NAME "Db1550 Flash" |
| 78 | #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ |
| 79 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 80 | #endif |
| 81 | |
| 82 | #ifdef CONFIG_MIPS_DB1200 |
| 83 | #define BOARD_MAP_NAME "Db1200 Flash" |
| 84 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ |
| 85 | #define BOARD_FLASH_WIDTH 2 /* 16-bits */ |
| 86 | #endif |
| 87 | |
| 88 | #ifdef CONFIG_MIPS_HYDROGEN3 |
| 89 | #define BOARD_MAP_NAME "Hydrogen3 Flash" |
| 90 | #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ |
| 91 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 92 | #define USE_LOCAL_ACCESSORS /* why? */ |
| 93 | #endif |
| 94 | |
| 95 | #ifdef CONFIG_MIPS_BOSPORUS |
| 96 | #define BOARD_MAP_NAME "Bosporus Flash" |
| 97 | #define BOARD_FLASH_SIZE 0x01000000 /* 16MB */ |
| 98 | #define BOARD_FLASH_WIDTH 2 /* 16-bits */ |
| 99 | #endif |
| 100 | |
| 101 | #ifdef CONFIG_MIPS_MIRAGE |
| 102 | #define BOARD_MAP_NAME "Mirage Flash" |
| 103 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ |
| 104 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ |
| 105 | #define USE_LOCAL_ACCESSORS /* why? */ |
| 106 | #endif |
| 107 | |
| 108 | static struct map_info alchemy_map = { |
| 109 | .name = BOARD_MAP_NAME, |
| 110 | }; |
| 111 | |
| 112 | static struct mtd_partition alchemy_partitions[] = { |
| 113 | { |
| 114 | .name = "User FS", |
| 115 | .size = BOARD_FLASH_SIZE - 0x00400000, |
| 116 | .offset = 0x0000000 |
| 117 | },{ |
| 118 | .name = "YAMON", |
| 119 | .size = 0x0100000, |
| 120 | .offset = MTDPART_OFS_APPEND, |
| 121 | .mask_flags = MTD_WRITEABLE |
| 122 | },{ |
| 123 | .name = "raw kernel", |
| 124 | .size = (0x300000 - 0x40000), /* last 256KB is yamon env */ |
| 125 | .offset = MTDPART_OFS_APPEND, |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | #define NB_OF(x) (sizeof(x)/sizeof(x[0])) |
| 130 | |
| 131 | static struct mtd_info *mymtd; |
| 132 | |
| 133 | int __init alchemy_mtd_init(void) |
| 134 | { |
| 135 | struct mtd_partition *parts; |
| 136 | int nb_parts = 0; |
| 137 | unsigned long window_addr; |
| 138 | unsigned long window_size; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame^] | 139 | |
Pete Popov | 002fa30 | 2005-02-27 21:50:25 +0000 | [diff] [blame] | 140 | /* Default flash buswidth */ |
| 141 | alchemy_map.bankwidth = BOARD_FLASH_WIDTH; |
| 142 | |
| 143 | window_addr = 0x20000000 - BOARD_FLASH_SIZE; |
| 144 | window_size = BOARD_FLASH_SIZE; |
| 145 | #ifdef CONFIG_MIPS_MIRAGE_WHY |
| 146 | /* Boot ROM flash bank only; no user bank */ |
| 147 | window_addr = 0x1C000000; |
| 148 | window_size = 0x04000000; |
| 149 | /* USERFS from 0x1C00 0000 to 0x1FC00000 */ |
| 150 | alchemy_partitions[0].size = 0x03C00000; |
| 151 | #endif |
| 152 | |
| 153 | /* |
| 154 | * Static partition definition selection |
| 155 | */ |
| 156 | parts = alchemy_partitions; |
| 157 | nb_parts = NB_OF(alchemy_partitions); |
| 158 | alchemy_map.size = window_size; |
| 159 | |
| 160 | /* |
| 161 | * Now let's probe for the actual flash. Do it here since |
| 162 | * specific machine settings might have been set above. |
| 163 | */ |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame^] | 164 | printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n", |
Pete Popov | 002fa30 | 2005-02-27 21:50:25 +0000 | [diff] [blame] | 165 | alchemy_map.bankwidth*8); |
| 166 | alchemy_map.virt = ioremap(window_addr, window_size); |
| 167 | mymtd = do_map_probe("cfi_probe", &alchemy_map); |
| 168 | if (!mymtd) { |
| 169 | iounmap(alchemy_map.virt); |
| 170 | return -ENXIO; |
| 171 | } |
| 172 | mymtd->owner = THIS_MODULE; |
| 173 | |
| 174 | add_mtd_partitions(mymtd, parts, nb_parts); |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static void __exit alchemy_mtd_cleanup(void) |
| 179 | { |
| 180 | if (mymtd) { |
| 181 | del_mtd_partitions(mymtd); |
| 182 | map_destroy(mymtd); |
| 183 | iounmap(alchemy_map.virt); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | module_init(alchemy_mtd_init); |
| 188 | module_exit(alchemy_mtd_cleanup); |
| 189 | |
| 190 | MODULE_AUTHOR("Embedded Alley Solutions, Inc"); |
| 191 | MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver"); |
| 192 | MODULE_LICENSE("GPL"); |