Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mtd/nand/au1550nd.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Embedded Edge, LLC |
| 5 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 6 | * $Id: au1550nd.c,v 1.13 2005/11/07 11:14:30 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/mtd/mtd.h> |
| 18 | #include <linux/mtd/nand.h> |
| 19 | #include <linux/mtd/partitions.h> |
Olaf Hering | 733482e | 2005-11-08 21:34:55 -0800 | [diff] [blame] | 20 | #include <linux/version.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/io.h> |
| 22 | |
| 23 | /* fixme: this is ugly */ |
| 24 | #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 0) |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 25 | #include <asm/mach-au1x00/au1xxx.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #else |
| 27 | #include <asm/au1000.h> |
| 28 | #ifdef CONFIG_MIPS_PB1550 |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 29 | #include <asm/pb1550.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #endif |
| 31 | #ifdef CONFIG_MIPS_DB1550 |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 32 | #include <asm/db1x00.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #endif |
| 34 | #endif |
| 35 | |
| 36 | /* |
| 37 | * MTD structure for NAND controller |
| 38 | */ |
| 39 | static struct mtd_info *au1550_mtd = NULL; |
| 40 | static void __iomem *p_nand; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 41 | static int nand_width = 1; /* default x8 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* |
| 44 | * Define partitions for flash device |
| 45 | */ |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 46 | static const struct mtd_partition partition_info[] = { |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 47 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 48 | .name = "NAND FS 0", |
| 49 | .offset = 0, |
| 50 | .size = 8 * 1024 * 1024}, |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 51 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 52 | .name = "NAND FS 1", |
| 53 | .offset = MTDPART_OFS_APPEND, |
| 54 | .size = MTDPART_SIZ_FULL} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * au_read_byte - read one byte from the chip |
| 59 | * @mtd: MTD device structure |
| 60 | * |
| 61 | * read function for 8bit buswith |
| 62 | */ |
| 63 | static u_char au_read_byte(struct mtd_info *mtd) |
| 64 | { |
| 65 | struct nand_chip *this = mtd->priv; |
| 66 | u_char ret = readb(this->IO_ADDR_R); |
| 67 | au_sync(); |
| 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * au_write_byte - write one byte to the chip |
| 73 | * @mtd: MTD device structure |
| 74 | * @byte: pointer to data byte to write |
| 75 | * |
| 76 | * write function for 8it buswith |
| 77 | */ |
| 78 | static void au_write_byte(struct mtd_info *mtd, u_char byte) |
| 79 | { |
| 80 | struct nand_chip *this = mtd->priv; |
| 81 | writeb(byte, this->IO_ADDR_W); |
| 82 | au_sync(); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * au_read_byte16 - read one byte endianess aware from the chip |
| 87 | * @mtd: MTD device structure |
| 88 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 89 | * read function for 16bit buswith with |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * endianess conversion |
| 91 | */ |
| 92 | static u_char au_read_byte16(struct mtd_info *mtd) |
| 93 | { |
| 94 | struct nand_chip *this = mtd->priv; |
| 95 | u_char ret = (u_char) cpu_to_le16(readw(this->IO_ADDR_R)); |
| 96 | au_sync(); |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * au_write_byte16 - write one byte endianess aware to the chip |
| 102 | * @mtd: MTD device structure |
| 103 | * @byte: pointer to data byte to write |
| 104 | * |
| 105 | * write function for 16bit buswith with |
| 106 | * endianess conversion |
| 107 | */ |
| 108 | static void au_write_byte16(struct mtd_info *mtd, u_char byte) |
| 109 | { |
| 110 | struct nand_chip *this = mtd->priv; |
| 111 | writew(le16_to_cpu((u16) byte), this->IO_ADDR_W); |
| 112 | au_sync(); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * au_read_word - read one word from the chip |
| 117 | * @mtd: MTD device structure |
| 118 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 119 | * read function for 16bit buswith without |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | * endianess conversion |
| 121 | */ |
| 122 | static u16 au_read_word(struct mtd_info *mtd) |
| 123 | { |
| 124 | struct nand_chip *this = mtd->priv; |
| 125 | u16 ret = readw(this->IO_ADDR_R); |
| 126 | au_sync(); |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * au_write_word - write one word to the chip |
| 132 | * @mtd: MTD device structure |
| 133 | * @word: data word to write |
| 134 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 135 | * write function for 16bit buswith without |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | * endianess conversion |
| 137 | */ |
| 138 | static void au_write_word(struct mtd_info *mtd, u16 word) |
| 139 | { |
| 140 | struct nand_chip *this = mtd->priv; |
| 141 | writew(word, this->IO_ADDR_W); |
| 142 | au_sync(); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * au_write_buf - write buffer to chip |
| 147 | * @mtd: MTD device structure |
| 148 | * @buf: data buffer |
| 149 | * @len: number of bytes to write |
| 150 | * |
| 151 | * write function for 8bit buswith |
| 152 | */ |
| 153 | static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len) |
| 154 | { |
| 155 | int i; |
| 156 | struct nand_chip *this = mtd->priv; |
| 157 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 158 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | writeb(buf[i], this->IO_ADDR_W); |
| 160 | au_sync(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /** |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 165 | * au_read_buf - read chip data into buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | * @mtd: MTD device structure |
| 167 | * @buf: buffer to store date |
| 168 | * @len: number of bytes to read |
| 169 | * |
| 170 | * read function for 8bit buswith |
| 171 | */ |
| 172 | static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len) |
| 173 | { |
| 174 | int i; |
| 175 | struct nand_chip *this = mtd->priv; |
| 176 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 177 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | buf[i] = readb(this->IO_ADDR_R); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 179 | au_sync(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | /** |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 184 | * au_verify_buf - Verify chip data against buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | * @mtd: MTD device structure |
| 186 | * @buf: buffer containing the data to compare |
| 187 | * @len: number of bytes to compare |
| 188 | * |
| 189 | * verify function for 8bit buswith |
| 190 | */ |
| 191 | static int au_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) |
| 192 | { |
| 193 | int i; |
| 194 | struct nand_chip *this = mtd->priv; |
| 195 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 196 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | if (buf[i] != readb(this->IO_ADDR_R)) |
| 198 | return -EFAULT; |
| 199 | au_sync(); |
| 200 | } |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * au_write_buf16 - write buffer to chip |
| 207 | * @mtd: MTD device structure |
| 208 | * @buf: data buffer |
| 209 | * @len: number of bytes to write |
| 210 | * |
| 211 | * write function for 16bit buswith |
| 212 | */ |
| 213 | static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) |
| 214 | { |
| 215 | int i; |
| 216 | struct nand_chip *this = mtd->priv; |
| 217 | u16 *p = (u16 *) buf; |
| 218 | len >>= 1; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 219 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 220 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | writew(p[i], this->IO_ADDR_W); |
| 222 | au_sync(); |
| 223 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 228 | * au_read_buf16 - read chip data into buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | * @mtd: MTD device structure |
| 230 | * @buf: buffer to store date |
| 231 | * @len: number of bytes to read |
| 232 | * |
| 233 | * read function for 16bit buswith |
| 234 | */ |
| 235 | static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len) |
| 236 | { |
| 237 | int i; |
| 238 | struct nand_chip *this = mtd->priv; |
| 239 | u16 *p = (u16 *) buf; |
| 240 | len >>= 1; |
| 241 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 242 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | p[i] = readw(this->IO_ADDR_R); |
| 244 | au_sync(); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 249 | * au_verify_buf16 - Verify chip data against buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | * @mtd: MTD device structure |
| 251 | * @buf: buffer containing the data to compare |
| 252 | * @len: number of bytes to compare |
| 253 | * |
| 254 | * verify function for 16bit buswith |
| 255 | */ |
| 256 | static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len) |
| 257 | { |
| 258 | int i; |
| 259 | struct nand_chip *this = mtd->priv; |
| 260 | u16 *p = (u16 *) buf; |
| 261 | len >>= 1; |
| 262 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 263 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | if (p[i] != readw(this->IO_ADDR_R)) |
| 265 | return -EFAULT; |
| 266 | au_sync(); |
| 267 | } |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | |
| 272 | static void au1550_hwcontrol(struct mtd_info *mtd, int cmd) |
| 273 | { |
| 274 | register struct nand_chip *this = mtd->priv; |
| 275 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 276 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 278 | case NAND_CTL_SETCLE: |
| 279 | this->IO_ADDR_W = p_nand + MEM_STNAND_CMD; |
| 280 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 282 | case NAND_CTL_CLRCLE: |
| 283 | this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; |
| 284 | break; |
| 285 | |
| 286 | case NAND_CTL_SETALE: |
| 287 | this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR; |
| 288 | break; |
| 289 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 290 | case NAND_CTL_CLRALE: |
| 291 | this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 292 | /* FIXME: Nobody knows why this is necessary, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | * but it works only that way */ |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 294 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | break; |
| 296 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 297 | case NAND_CTL_SETNCE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* assert (force assert) chip enable */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 299 | au_writel((1 << (4 + NAND_CS)), MEM_STNDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | break; |
| 301 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 302 | case NAND_CTL_CLRNCE: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 303 | /* deassert chip enable */ |
| 304 | au_writel(0, MEM_STNDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | break; |
| 306 | } |
| 307 | |
| 308 | this->IO_ADDR_R = this->IO_ADDR_W; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | /* Drain the writebuffer */ |
| 311 | au_sync(); |
| 312 | } |
| 313 | |
| 314 | int au1550_device_ready(struct mtd_info *mtd) |
| 315 | { |
| 316 | int ret = (au_readl(MEM_STSTAT) & 0x1) ? 1 : 0; |
| 317 | au_sync(); |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * Main initialization routine |
| 323 | */ |
David Woodhouse | cead4db | 2006-05-16 13:54:50 +0100 | [diff] [blame] | 324 | static int __init au1xxx_nand_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | struct nand_chip *this; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 327 | u16 boot_swapboot = 0; /* default value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | int retval; |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 329 | u32 mem_staddr; |
| 330 | u32 nand_phys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | /* Allocate memory for MTD device structure and private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 333 | au1550_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | if (!au1550_mtd) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 335 | printk("Unable to allocate NAND MTD dev structure.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return -ENOMEM; |
| 337 | } |
| 338 | |
| 339 | /* Get pointer to private data */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 340 | this = (struct nand_chip *)(&au1550_mtd[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* Initialize structures */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 343 | memset(au1550_mtd, 0, sizeof(struct mtd_info)); |
| 344 | memset(this, 0, sizeof(struct nand_chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | /* Link the private data with the MTD structure */ |
| 347 | au1550_mtd->priv = this; |
David Woodhouse | 552d920 | 2006-05-14 01:20:46 +0100 | [diff] [blame] | 348 | au1550_mtd->owner = THIS_MODULE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 350 | |
Sergei Shtylyov | 155285c | 2006-05-16 20:16:41 +0400 | [diff] [blame^] | 351 | /* MEM_STNDCTL: disable ints, disable nand boot */ |
| 352 | au_writel(0, MEM_STNDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | #ifdef CONFIG_MIPS_PB1550 |
| 355 | /* set gpio206 high */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 356 | au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 358 | boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr->status >> 6) & 0x1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | switch (boot_swapboot) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 360 | case 0: |
| 361 | case 2: |
| 362 | case 8: |
| 363 | case 0xC: |
| 364 | case 0xD: |
| 365 | /* x16 NAND Flash */ |
| 366 | nand_width = 0; |
| 367 | break; |
| 368 | case 1: |
| 369 | case 9: |
| 370 | case 3: |
| 371 | case 0xE: |
| 372 | case 0xF: |
| 373 | /* x8 NAND Flash */ |
| 374 | nand_width = 1; |
| 375 | break; |
| 376 | default: |
| 377 | printk("Pb1550 NAND: bad boot:swap\n"); |
| 378 | retval = -EINVAL; |
| 379 | goto outmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | #endif |
| 382 | |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 383 | /* Configure chip-select; normally done by boot code, e.g. YAMON */ |
| 384 | #ifdef NAND_STCFG |
| 385 | if (NAND_CS == 0) { |
| 386 | au_writel(NAND_STCFG, MEM_STCFG0); |
| 387 | au_writel(NAND_STTIME, MEM_STTIME0); |
| 388 | au_writel(NAND_STADDR, MEM_STADDR0); |
| 389 | } |
| 390 | if (NAND_CS == 1) { |
| 391 | au_writel(NAND_STCFG, MEM_STCFG1); |
| 392 | au_writel(NAND_STTIME, MEM_STTIME1); |
| 393 | au_writel(NAND_STADDR, MEM_STADDR1); |
| 394 | } |
| 395 | if (NAND_CS == 2) { |
| 396 | au_writel(NAND_STCFG, MEM_STCFG2); |
| 397 | au_writel(NAND_STTIME, MEM_STTIME2); |
| 398 | au_writel(NAND_STADDR, MEM_STADDR2); |
| 399 | } |
| 400 | if (NAND_CS == 3) { |
| 401 | au_writel(NAND_STCFG, MEM_STCFG3); |
| 402 | au_writel(NAND_STTIME, MEM_STTIME3); |
| 403 | au_writel(NAND_STADDR, MEM_STADDR3); |
| 404 | } |
| 405 | #endif |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 406 | |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 407 | /* Locate NAND chip-select in order to determine NAND phys address */ |
| 408 | mem_staddr = 0x00000000; |
| 409 | if (((au_readl(MEM_STCFG0) & 0x7) == 0x5) && (NAND_CS == 0)) |
| 410 | mem_staddr = au_readl(MEM_STADDR0); |
| 411 | else if (((au_readl(MEM_STCFG1) & 0x7) == 0x5) && (NAND_CS == 1)) |
| 412 | mem_staddr = au_readl(MEM_STADDR1); |
| 413 | else if (((au_readl(MEM_STCFG2) & 0x7) == 0x5) && (NAND_CS == 2)) |
| 414 | mem_staddr = au_readl(MEM_STADDR2); |
| 415 | else if (((au_readl(MEM_STCFG3) & 0x7) == 0x5) && (NAND_CS == 3)) |
| 416 | mem_staddr = au_readl(MEM_STADDR3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 418 | if (mem_staddr == 0x00000000) { |
| 419 | printk("Au1xxx NAND: ERROR WITH NAND CHIP-SELECT\n"); |
| 420 | kfree(au1550_mtd); |
| 421 | return 1; |
| 422 | } |
| 423 | nand_phys = (mem_staddr << 4) & 0xFFFC0000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 425 | p_nand = (void __iomem *)ioremap(nand_phys, 0x1000); |
| 426 | |
| 427 | /* make controller and MTD agree */ |
| 428 | if (NAND_CS == 0) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 429 | nand_width = au_readl(MEM_STCFG0) & (1 << 22); |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 430 | if (NAND_CS == 1) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 431 | nand_width = au_readl(MEM_STCFG1) & (1 << 22); |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 432 | if (NAND_CS == 2) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 433 | nand_width = au_readl(MEM_STCFG2) & (1 << 22); |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 434 | if (NAND_CS == 3) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 435 | nand_width = au_readl(MEM_STCFG3) & (1 << 22); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | /* Set address of hardware control function */ |
| 438 | this->hwcontrol = au1550_hwcontrol; |
| 439 | this->dev_ready = au1550_device_ready; |
| 440 | /* 30 us command delay time */ |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 441 | this->chip_delay = 30; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | this->eccmode = NAND_ECC_SOFT; |
| 443 | |
| 444 | this->options = NAND_NO_AUTOINCR; |
| 445 | |
| 446 | if (!nand_width) |
| 447 | this->options |= NAND_BUSWIDTH_16; |
| 448 | |
| 449 | this->read_byte = (!nand_width) ? au_read_byte16 : au_read_byte; |
| 450 | this->write_byte = (!nand_width) ? au_write_byte16 : au_write_byte; |
| 451 | this->write_word = au_write_word; |
| 452 | this->read_word = au_read_word; |
| 453 | this->write_buf = (!nand_width) ? au_write_buf16 : au_write_buf; |
| 454 | this->read_buf = (!nand_width) ? au_read_buf16 : au_read_buf; |
| 455 | this->verify_buf = (!nand_width) ? au_verify_buf16 : au_verify_buf; |
| 456 | |
| 457 | /* Scan to find existence of the device */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 458 | if (nand_scan(au1550_mtd, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | retval = -ENXIO; |
| 460 | goto outio; |
| 461 | } |
| 462 | |
| 463 | /* Register the partitions */ |
Tobias Klauser | 87d10f3 | 2006-03-31 02:29:45 -0800 | [diff] [blame] | 464 | add_mtd_partitions(au1550_mtd, partition_info, ARRAY_SIZE(partition_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | return 0; |
| 467 | |
| 468 | outio: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 469 | iounmap((void *)p_nand); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | outmem: |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 472 | kfree(au1550_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | return retval; |
| 474 | } |
| 475 | |
Pete Popov | ef6f0d1 | 2005-09-23 02:44:58 +0100 | [diff] [blame] | 476 | module_init(au1xxx_nand_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
| 478 | /* |
| 479 | * Clean up routine |
| 480 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 481 | static void __exit au1550_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 483 | struct nand_chip *this = (struct nand_chip *)&au1550_mtd[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | /* Release resources, unregister device */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 486 | nand_release(au1550_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
| 488 | /* Free the MTD device structure */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 489 | kfree(au1550_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | /* Unmap */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 492 | iounmap((void *)p_nand); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | module_exit(au1550_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | MODULE_LICENSE("GPL"); |
| 498 | MODULE_AUTHOR("Embedded Edge, LLC"); |
| 499 | MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on Pb1550 board"); |