au1550nd.c (7e534323c416216e8ac45b5633fb0a5e5137e5b5) | au1550nd.c (c0739d85723a381302907f9613392d7ac8515176) |
---|---|
1/* 2 * Copyright (C) 2004 Embedded Edge, LLC 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 2 as 6 * published by the Free Software Foundation. 7 * 8 */ --- 10 unchanged lines hidden (view full) --- 19#include <asm/mach-au1x00/au1550nd.h> 20 21 22struct au1550nd_ctx { 23 struct nand_chip chip; 24 25 int cs; 26 void __iomem *base; | 1/* 2 * Copyright (C) 2004 Embedded Edge, LLC 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 2 as 6 * published by the Free Software Foundation. 7 * 8 */ --- 10 unchanged lines hidden (view full) --- 19#include <asm/mach-au1x00/au1550nd.h> 20 21 22struct au1550nd_ctx { 23 struct nand_chip chip; 24 25 int cs; 26 void __iomem *base; |
27 void (*write_byte)(struct mtd_info *, u_char); | 27 void (*write_byte)(struct nand_chip *, u_char); |
28}; 29 30/** 31 * au_read_byte - read one byte from the chip 32 * @this: NAND chip object 33 * 34 * read function for 8bit buswidth 35 */ 36static u_char au_read_byte(struct nand_chip *this) 37{ 38 u_char ret = readb(this->IO_ADDR_R); 39 wmb(); /* drain writebuffer */ 40 return ret; 41} 42 43/** 44 * au_write_byte - write one byte to the chip | 28}; 29 30/** 31 * au_read_byte - read one byte from the chip 32 * @this: NAND chip object 33 * 34 * read function for 8bit buswidth 35 */ 36static u_char au_read_byte(struct nand_chip *this) 37{ 38 u_char ret = readb(this->IO_ADDR_R); 39 wmb(); /* drain writebuffer */ 40 return ret; 41} 42 43/** 44 * au_write_byte - write one byte to the chip |
45 * @mtd: MTD device structure | 45 * @this: NAND chip object |
46 * @byte: pointer to data byte to write 47 * 48 * write function for 8it buswidth 49 */ | 46 * @byte: pointer to data byte to write 47 * 48 * write function for 8it buswidth 49 */ |
50static void au_write_byte(struct mtd_info *mtd, u_char byte) | 50static void au_write_byte(struct nand_chip *this, u_char byte) |
51{ | 51{ |
52 struct nand_chip *this = mtd_to_nand(mtd); | |
53 writeb(byte, this->IO_ADDR_W); 54 wmb(); /* drain writebuffer */ 55} 56 57/** 58 * au_read_byte16 - read one byte endianness aware from the chip 59 * @this: NAND chip object 60 * 61 * read function for 16bit buswidth with endianness conversion 62 */ 63static u_char au_read_byte16(struct nand_chip *this) 64{ 65 u_char ret = (u_char) cpu_to_le16(readw(this->IO_ADDR_R)); 66 wmb(); /* drain writebuffer */ 67 return ret; 68} 69 70/** 71 * au_write_byte16 - write one byte endianness aware to the chip | 52 writeb(byte, this->IO_ADDR_W); 53 wmb(); /* drain writebuffer */ 54} 55 56/** 57 * au_read_byte16 - read one byte endianness aware from the chip 58 * @this: NAND chip object 59 * 60 * read function for 16bit buswidth with endianness conversion 61 */ 62static u_char au_read_byte16(struct nand_chip *this) 63{ 64 u_char ret = (u_char) cpu_to_le16(readw(this->IO_ADDR_R)); 65 wmb(); /* drain writebuffer */ 66 return ret; 67} 68 69/** 70 * au_write_byte16 - write one byte endianness aware to the chip |
72 * @mtd: MTD device structure | 71 * @this: NAND chip object |
73 * @byte: pointer to data byte to write 74 * 75 * write function for 16bit buswidth with endianness conversion 76 */ | 72 * @byte: pointer to data byte to write 73 * 74 * write function for 16bit buswidth with endianness conversion 75 */ |
77static void au_write_byte16(struct mtd_info *mtd, u_char byte) | 76static void au_write_byte16(struct nand_chip *this, u_char byte) |
78{ | 77{ |
79 struct nand_chip *this = mtd_to_nand(mtd); | |
80 writew(le16_to_cpu((u16) byte), this->IO_ADDR_W); 81 wmb(); /* drain writebuffer */ 82} 83 84/** 85 * au_write_buf - write buffer to chip | 78 writew(le16_to_cpu((u16) byte), this->IO_ADDR_W); 79 wmb(); /* drain writebuffer */ 80} 81 82/** 83 * au_write_buf - write buffer to chip |
86 * @mtd: MTD device structure | 84 * @this: NAND chip object |
87 * @buf: data buffer 88 * @len: number of bytes to write 89 * 90 * write function for 8bit buswidth 91 */ | 85 * @buf: data buffer 86 * @len: number of bytes to write 87 * 88 * write function for 8bit buswidth 89 */ |
92static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len) | 90static void au_write_buf(struct nand_chip *this, const u_char *buf, int len) |
93{ 94 int i; | 91{ 92 int i; |
95 struct nand_chip *this = mtd_to_nand(mtd); | |
96 97 for (i = 0; i < len; i++) { 98 writeb(buf[i], this->IO_ADDR_W); 99 wmb(); /* drain writebuffer */ 100 } 101} 102 103/** --- 11 unchanged lines hidden (view full) --- 115 for (i = 0; i < len; i++) { 116 buf[i] = readb(this->IO_ADDR_R); 117 wmb(); /* drain writebuffer */ 118 } 119} 120 121/** 122 * au_write_buf16 - write buffer to chip | 93 94 for (i = 0; i < len; i++) { 95 writeb(buf[i], this->IO_ADDR_W); 96 wmb(); /* drain writebuffer */ 97 } 98} 99 100/** --- 11 unchanged lines hidden (view full) --- 112 for (i = 0; i < len; i++) { 113 buf[i] = readb(this->IO_ADDR_R); 114 wmb(); /* drain writebuffer */ 115 } 116} 117 118/** 119 * au_write_buf16 - write buffer to chip |
123 * @mtd: MTD device structure | 120 * @this: NAND chip object |
124 * @buf: data buffer 125 * @len: number of bytes to write 126 * 127 * write function for 16bit buswidth 128 */ | 121 * @buf: data buffer 122 * @len: number of bytes to write 123 * 124 * write function for 16bit buswidth 125 */ |
129static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) | 126static void au_write_buf16(struct nand_chip *this, const u_char *buf, int len) |
130{ 131 int i; | 127{ 128 int i; |
132 struct nand_chip *this = mtd_to_nand(mtd); | |
133 u16 *p = (u16 *) buf; 134 len >>= 1; 135 136 for (i = 0; i < len; i++) { 137 writew(p[i], this->IO_ADDR_W); 138 wmb(); /* drain writebuffer */ 139 } 140 --- 126 unchanged lines hidden (view full) --- 267 readcmd = NAND_CMD_READOOB; 268 } else if (column < 256) { 269 /* First 256 bytes --> READ0 */ 270 readcmd = NAND_CMD_READ0; 271 } else { 272 column -= 256; 273 readcmd = NAND_CMD_READ1; 274 } | 129 u16 *p = (u16 *) buf; 130 len >>= 1; 131 132 for (i = 0; i < len; i++) { 133 writew(p[i], this->IO_ADDR_W); 134 wmb(); /* drain writebuffer */ 135 } 136 --- 126 unchanged lines hidden (view full) --- 263 readcmd = NAND_CMD_READOOB; 264 } else if (column < 256) { 265 /* First 256 bytes --> READ0 */ 266 readcmd = NAND_CMD_READ0; 267 } else { 268 column -= 256; 269 readcmd = NAND_CMD_READ1; 270 } |
275 ctx->write_byte(mtd, readcmd); | 271 ctx->write_byte(this, readcmd); |
276 } | 272 } |
277 ctx->write_byte(mtd, command); | 273 ctx->write_byte(this, command); |
278 279 /* Set ALE and clear CLE to start address cycle */ 280 au1550_hwcontrol(mtd, NAND_CTL_CLRCLE); 281 282 if (column != -1 || page_addr != -1) { 283 au1550_hwcontrol(mtd, NAND_CTL_SETALE); 284 285 /* Serially input address */ 286 if (column != -1) { 287 /* Adjust columns for 16 bit buswidth */ 288 if (this->options & NAND_BUSWIDTH_16 && 289 !nand_opcode_8bits(command)) 290 column >>= 1; | 274 275 /* Set ALE and clear CLE to start address cycle */ 276 au1550_hwcontrol(mtd, NAND_CTL_CLRCLE); 277 278 if (column != -1 || page_addr != -1) { 279 au1550_hwcontrol(mtd, NAND_CTL_SETALE); 280 281 /* Serially input address */ 282 if (column != -1) { 283 /* Adjust columns for 16 bit buswidth */ 284 if (this->options & NAND_BUSWIDTH_16 && 285 !nand_opcode_8bits(command)) 286 column >>= 1; |
291 ctx->write_byte(mtd, column); | 287 ctx->write_byte(this, column); |
292 } 293 if (page_addr != -1) { | 288 } 289 if (page_addr != -1) { |
294 ctx->write_byte(mtd, (u8)(page_addr & 0xff)); | 290 ctx->write_byte(this, (u8)(page_addr & 0xff)); |
295 296 if (command == NAND_CMD_READ0 || 297 command == NAND_CMD_READ1 || 298 command == NAND_CMD_READOOB) { 299 /* 300 * NAND controller will release -CE after 301 * the last address byte is written, so we'll 302 * have to forcibly assert it. No interrupts 303 * are allowed while we do this as we don't 304 * want the NOR flash or PCMCIA drivers to 305 * steal our precious bytes of data... 306 */ 307 ce_override = 1; 308 local_irq_save(flags); 309 au1550_hwcontrol(mtd, NAND_CTL_SETNCE); 310 } 311 | 291 292 if (command == NAND_CMD_READ0 || 293 command == NAND_CMD_READ1 || 294 command == NAND_CMD_READOOB) { 295 /* 296 * NAND controller will release -CE after 297 * the last address byte is written, so we'll 298 * have to forcibly assert it. No interrupts 299 * are allowed while we do this as we don't 300 * want the NOR flash or PCMCIA drivers to 301 * steal our precious bytes of data... 302 */ 303 ce_override = 1; 304 local_irq_save(flags); 305 au1550_hwcontrol(mtd, NAND_CTL_SETNCE); 306 } 307 |
312 ctx->write_byte(mtd, (u8)(page_addr >> 8)); | 308 ctx->write_byte(this, (u8)(page_addr >> 8)); |
313 314 if (this->options & NAND_ROW_ADDR_3) | 309 310 if (this->options & NAND_ROW_ADDR_3) |
315 ctx->write_byte(mtd, | 311 ctx->write_byte(this, |
316 ((page_addr >> 16) & 0x0f)); 317 } 318 /* Latch in address */ 319 au1550_hwcontrol(mtd, NAND_CTL_CLRALE); 320 } 321 322 /* 323 * Program and erase have their own busy handlers. --- 173 unchanged lines hidden --- | 312 ((page_addr >> 16) & 0x0f)); 313 } 314 /* Latch in address */ 315 au1550_hwcontrol(mtd, NAND_CTL_CLRALE); 316 } 317 318 /* 319 * Program and erase have their own busy handlers. --- 173 unchanged lines hidden --- |