Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * (C) Copyright 2006 Detlev Zundel, dzu@denx.de | |
| 3 * (C) Copyright 2006 DENX Software Engineering | |
| 4 * (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com> | |
| 5 * | |
| 6 * See file CREDITS for list of people who contributed to this | |
| 7 * project. | |
| 8 * | |
| 9 * This program is free software; you can redistribute it and/or | |
| 10 * modify it under the terms of the GNU General Public License as | |
| 11 * published by the Free Software Foundation; either version 2 of | |
| 12 * the License, or (at your option) any later version. | |
| 13 * | |
| 14 * This program is distributed in the hope that it will be useful, | |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 * GNU General Public License for more details. | |
| 18 * | |
| 19 * You should have received a copy of the GNU General Public License | |
| 20 * along with this program; if not, write to the Free Software | |
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
| 22 * MA 02111-1307 USA | |
| 23 */ | |
| 24 | |
| 25 #include <common.h> | |
| 26 #include <asm/io.h> | |
| 27 #include <nand.h> | |
| 28 #include <asm/arch/gpio.h> | |
| 29 #include "tegra2_nand.h" | |
| 30 #include <asm/arch/nvcommon.h> | |
| 31 #include "../../board.h" | |
| 32 | |
| 33 #define NAND_PIO_CMD_TIMEOUT_MS 100 | |
| 34 static int byte_count; | |
| 35 | |
| 36 static struct nand_ecclayout nand_soft_eccoob = { | |
| 37 .oobfree = { | |
| 38 {.offset = 40, .length = 24 }} | |
| 39 }; | |
| 40 | |
| 41 /** | |
| 42 * tegra2_nand_read_byte - [DEFAULT] read one byte from the chip | |
| 43 * @mtd: MTD device structure | |
| 44 * | |
| 45 * Default read function for 8bit buswith | |
| 46 */ | |
| 47 static uint8_t tegra2_nand_read_byte(struct mtd_info *mtd) | |
| 48 { | |
| 49 struct nand_chip *chip = mtd->priv; | |
| 50 int dword_read; | |
| 51 | |
| 52 dword_read = readl(chip->IO_ADDR_R + NAND_RESP_0); | |
| 53 dword_read = dword_read >> (8 * byte_count); | |
| 54 byte_count ++; | |
| 55 return (uint8_t) dword_read; | |
| 56 } | |
| 57 | |
| 58 /** | |
| 59 * tegra2_nand_write_buf - [DEFAULT] write buffer to chip | |
| 60 * @mtd: MTD device structure | |
| 61 * @buf: data buffer | |
| 62 * @len: number of bytes to write | |
| 63 * | |
| 64 * Default write function for 8bit buswith | |
| 65 */ | |
| 66 static void tegra2_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, | |
| 67 int len) | |
| 68 { | |
| 69 int i, j, l, l2; | |
| 70 struct nand_chip *chip = mtd->priv; | |
| 71 | |
| 72 for (i = 0; i < len/4; i++) | |
| 73 { | |
| 74 l = ((int *)buf)[i]; | |
| 75 writel(l, chip->IO_ADDR_W+ NAND_RESP_0); | |
| 76 /* Go, PIO, Tx, TRANS_SIZE=3 for 4 bytes, A_valid, CE0 */ | |
| 77 writel(Bit31+Bit28+Bit27+(3<<20)+Bit19+Bit8, chip->IO_ADDR_W + | |
|
Tom Warren
2011/03/10 17:06:23
I had this comment in Patchset 1, but I must not h
| |
| 78 NAND_COMMAND_0); | |
| 79 if (!tegra2_nand_waitfor_GO_cleared(mtd)) | |
| 80 printf("Command timeout during write_buf\n"); | |
| 81 } | |
| 82 if ((len % 4) != 0) | |
| 83 { | |
| 84 l = 0; | |
| 85 for (j=0; j<(len %4); j++) | |
| 86 { | |
| 87 l2 = (int) buf[i*4+j]; | |
| 88 l |= (l2<< (8*j)); | |
| 89 } | |
| 90 writel(l, chip->IO_ADDR_W+ NAND_RESP_0); | |
| 91 /* Go, PIO, Tx, TRANS_SIZE, A_valid, CE0 */ | |
| 92 writel(Bit31+Bit28+Bit27+(((len % 4)-1)<<20)+Bit19+Bit8, | |
| 93 chip->IO_ADDR_W + NAND_COMMAND_0); | |
| 94 if (!tegra2_nand_waitfor_GO_cleared(mtd)) | |
| 95 printf("Command timeout during write_buf\n"); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 /** | |
| 100 * tegra2_nand_read_buf - [DEFAULT] read chip data into buffer | |
| 101 * @mtd: MTD device structure | |
| 102 * @buf: buffer to store date | |
| 103 * @len: number of bytes to read | |
| 104 * | |
| 105 * Default read function for 8bit buswith | |
| 106 */ | |
| 107 static void tegra2_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) | |
| 108 { | |
| 109 int i, j, l; | |
| 110 struct nand_chip *chip = mtd->priv; | |
| 111 int *buf_dword; | |
| 112 | |
| 113 buf_dword = (int *) buf; | |
| 114 for (i = 0; i < len/4; i++) | |
| 115 { | |
| 116 /* Go, PIO, Rx, TRANS_SIZE=3 for 4 bytes, A_valid, CE0 */ | |
| 117 writel(Bit31+Bit28+Bit26+(3<<20)+Bit19+Bit8, chip->IO_ADDR_W + | |
| 118 NAND_COMMAND_0); | |
| 119 if (!tegra2_nand_waitfor_GO_cleared(mtd)) | |
| 120 printf("Command timeout during read_buf\n"); | |
| 121 l = readl(chip->IO_ADDR_R+ NAND_RESP_0); | |
| 122 buf_dword[i] = l; | |
| 123 } | |
| 124 if ((len % 4) != 0) | |
| 125 { | |
| 126 /* Go, PIO, Rx, TRANS_SIZE, A_valid, CE0 */ | |
| 127 writel(Bit31+Bit28+Bit26+(((len % 4)-1)<<20)+Bit19+Bit8, | |
| 128 chip->IO_ADDR_W + NAND_COMMAND_0); | |
| 129 if (!tegra2_nand_waitfor_GO_cleared(mtd)) | |
| 130 printf("Command timeout during read_buf\n"); | |
| 131 l = readl(chip->IO_ADDR_R+ NAND_RESP_0); | |
| 132 for (j=0; j<(len %4); j++) | |
| 133 { | |
| 134 buf[i*4+j] = (char) (l>>(8*j)); | |
| 135 } | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 /* | |
| 140 * = 1 - ready | |
| 141 * 0 - not ready | |
| 142 */ | |
| 143 static int tegra2_nand_waitfor_GO_cleared(struct mtd_info *mtd) | |
| 144 { | |
| 145 struct nand_chip *this = mtd->priv; | |
| 146 int i; | |
| 147 | |
| 148 for (i=0; i< NAND_PIO_CMD_TIMEOUT_MS * 1000; i++) | |
| 149 { | |
| 150 if (!(readl(this->IO_ADDR_R + NAND_CMD_REG1_0) & Bit31)) | |
| 151 break; | |
| 152 else | |
| 153 udelay(1); | |
| 154 } | |
| 155 if (i== NAND_PIO_CMD_TIMEOUT_MS * 1000) | |
| 156 return 0; | |
| 157 return 1; | |
| 158 } | |
| 159 | |
| 160 /* | |
| 161 * = 1 - ready | |
| 162 * 0 - not ready | |
| 163 */ | |
| 164 static int tegra2_nand_dev_ready(struct mtd_info *mtd) | |
| 165 { | |
| 166 register struct nand_chip *chip = mtd->priv; | |
| 167 int status; | |
| 168 | |
| 169 writel(NAND_CMD_STATUS, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 170 /* Go, CLE, PIO, Rx, CE0, 0+1 transfer byte */ | |
| 171 writel(Bit31+Bit30+Bit28+Bit26+(0<<20)+Bit8, chip->IO_ADDR_W + | |
| 172 NAND_COMMAND_0); | |
| 173 if (!(tegra2_nand_waitfor_GO_cleared(mtd))) | |
| 174 printf("NAND_CMD_STATUS command timeout\n"); | |
| 175 udelay(1); | |
| 176 status = readl(chip->IO_ADDR_R + NAND_RESP_0); | |
| 177 if (status & NAND_STATUS_READY) | |
| 178 return 1; | |
| 179 return 0; | |
| 180 } | |
| 181 | |
| 182 /* | |
| 183 * hardware specific access to control-lines | |
| 184 */ | |
| 185 static void tegra2_nand_hwcontrol(struct mtd_info *mtd, int cmd, | |
| 186 unsigned int ctrl) | |
| 187 { | |
| 188 } | |
| 189 | |
| 190 /** | |
| 191 * tegra2_nand_command - [DEFAULT] Send command to NAND device | |
| 192 * @mtd: MTD device structure | |
| 193 * @command: the command to be sent | |
| 194 * @column: the column address for this command, -1 if none | |
| 195 * @page_addr: the page address for this command, -1 if none | |
| 196 */ | |
| 197 static void tegra2_nand_command(struct mtd_info *mtd, unsigned int command, | |
| 198 int column, int page_addr) | |
| 199 { | |
| 200 register struct nand_chip *chip = mtd->priv; | |
| 201 | |
| 202 /* | |
| 203 * Write out the command to the device. | |
| 204 */ | |
| 205 if (mtd->writesize < 2048) { | |
| 206 /* Only command NAND_CMD_RESET or NAND_CMD_READID will come | |
| 207 * here before mtd->writesize is initialized, we don't have | |
| 208 * any action here because page size of NAND HY27UF084G2B | |
| 209 * is 2048 bytes and mtd->writesize will be 2048 after | |
| 210 * initialized. */ | |
| 211 } | |
| 212 else | |
| 213 { | |
| 214 /* Emulate NAND_CMD_READOOB */ | |
| 215 if (command == NAND_CMD_READOOB) | |
| 216 { | |
| 217 column += mtd->writesize; | |
| 218 command = NAND_CMD_READ0; | |
| 219 } | |
| 220 | |
| 221 if (column != -1 || page_addr != -1) | |
| 222 { | |
| 223 /* Serially input address */ | |
| 224 if (column != -1) | |
| 225 { | |
| 226 /* Adjust columns for 16 bit buswidth */ | |
| 227 if (chip->options & NAND_BUSWIDTH_16) | |
| 228 column >>= 1; | |
| 229 } | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 /* | |
| 234 * program and erase have their own busy handlers | |
| 235 * status and sequential in needs no delay | |
| 236 */ | |
| 237 switch (command) { | |
| 238 case NAND_CMD_READID: | |
| 239 writel(NAND_CMD_READID, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 240 writel(Bit31+Bit30+Bit29+Bit28+Bit26+(3<<20)+Bit8, | |
| 241 chip->IO_ADDR_W + NAND_COMMAND_0); | |
| 242 byte_count = 0; | |
| 243 break; | |
| 244 case NAND_CMD_READ0: | |
| 245 writel(NAND_CMD_READ0, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 246 writel(NAND_CMD_READSTART, chip->IO_ADDR_W + NAND_CMD_REG2_0); | |
| 247 writel((page_addr <<16)+ (column & 0xFFFF), chip->IO_ADDR_W + | |
| 248 NAND_ADDR_REG1_0); | |
| 249 writel(page_addr >>16, chip->IO_ADDR_W + NAND_ADDR_REG2_0); | |
| 250 /* Go, CLE, ALE, PIO, SEC_CMD, CE0, 4+1 address cycles */ | |
| 251 writel(Bit31+Bit30+Bit29+Bit28+Bit25+Bit8+4, chip->IO_ADDR_W + | |
| 252 NAND_COMMAND_0); | |
| 253 byte_count = 0; | |
| 254 break; | |
| 255 case NAND_CMD_SEQIN: | |
| 256 writel(NAND_CMD_SEQIN, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 257 writel(NAND_CMD_PAGEPROG, chip->IO_ADDR_W + NAND_CMD_REG2_0); | |
| 258 writel((page_addr <<16)+ (column & 0xFFFF), chip->IO_ADDR_W + | |
| 259 NAND_ADDR_REG1_0); | |
| 260 writel(page_addr >>16, chip->IO_ADDR_W + NAND_ADDR_REG2_0); | |
| 261 /* Go, CLE, ALE, PIO, SEC_CMD, AFT_DAT, CE0, 4+1 address cycles */ | |
| 262 writel(Bit31+Bit30+Bit29+Bit28+Bit25+Bit24+Bit8+4, chip->IO_ADDR _W + | |
| 263 NAND_COMMAND_0); | |
| 264 break; | |
| 265 case NAND_CMD_PAGEPROG: | |
| 266 writel(NAND_CMD_PAGEPROG, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 267 /* Go, CLE, CE0 */ | |
| 268 writel(Bit31+Bit30+Bit8, chip->IO_ADDR_W + NAND_COMMAND_0); | |
| 269 break; | |
| 270 case NAND_CMD_ERASE1: | |
| 271 writel(NAND_CMD_ERASE1, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 272 writel(NAND_CMD_ERASE2, chip->IO_ADDR_W + NAND_CMD_REG2_0); | |
| 273 writel(page_addr, chip->IO_ADDR_W + NAND_ADDR_REG1_0); | |
| 274 /* Go, CLE, ALE, SEC_CMD, CE0, 2+1 address cycles */ | |
| 275 writel(Bit31+Bit30+Bit29+Bit25+Bit8+2, chip->IO_ADDR_W + | |
| 276 NAND_COMMAND_0); | |
| 277 break; | |
| 278 case NAND_CMD_RNDOUT: | |
| 279 writel(NAND_CMD_RNDOUT, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 280 writel(NAND_CMD_RNDOUTSTART, chip->IO_ADDR_W + NAND_CMD_REG2_0); | |
| 281 writel((column & 0xFFFF), chip->IO_ADDR_W + NAND_ADDR_REG1_0); | |
| 282 /* Go, CLE, ALE, PIO, SEC_CMD, CE0, 1+1 address cycles */ | |
| 283 writel(Bit31+Bit30+Bit29+Bit28+Bit25+Bit8+1, chip->IO_ADDR_W + | |
| 284 NAND_COMMAND_0); | |
| 285 break; | |
| 286 case NAND_CMD_ERASE2: | |
| 287 return; | |
| 288 case NAND_CMD_STATUS: | |
| 289 writel(NAND_CMD_STATUS, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 290 /* Go, CLE, PIO, Rx, CE0, 0+1 transfer byte */ | |
| 291 writel(Bit31+Bit30+Bit28+Bit26+(0<<20)+Bit8, chip->IO_ADDR_W + | |
| 292 NAND_COMMAND_0); | |
| 293 byte_count = 0; | |
| 294 break; | |
| 295 | |
| 296 case NAND_CMD_RESET: | |
| 297 writel(NAND_CMD_RESET, chip->IO_ADDR_W + NAND_CMD_REG1_0); | |
| 298 /* Go, CLE, CE0 */ | |
| 299 writel(Bit31+Bit30+Bit8, chip->IO_ADDR_W + NAND_COMMAND_0); | |
| 300 break; | |
| 301 default: | |
| 302 /* | |
| 303 * If we don't have access to the busy pin, we apply the given | |
| 304 * command delay | |
| 305 */ | |
| 306 if (!chip->dev_ready) | |
| 307 { | |
| 308 udelay(chip->chip_delay); | |
| 309 return; | |
| 310 } | |
| 311 } | |
| 312 if (!tegra2_nand_waitfor_GO_cleared(mtd)) | |
| 313 printf("Command 0x%02X timeout\n", command); | |
| 314 | |
| 315 if (command == NAND_CMD_READ0) | |
| 316 udelay(25); | |
| 317 else | |
| 318 udelay(1); | |
| 319 } | |
| 320 | |
| 321 /* | |
| 322 * Board-specific NAND initialization. The following members of the | |
| 323 * argument are board-specific (per include/linux/mtd/nand.h): | |
| 324 * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device | |
| 325 * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device | |
| 326 * - cmd_ctrl: hardwarespecific function for accesing control-lines | |
| 327 * - dev_ready: hardwarespecific function for accesing device ready/busy line | |
| 328 * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must | |
| 329 * only be provided if a hardware ECC is available | |
| 330 * - eccm.ode: mode of ecc, see defines | |
| 331 * - chip_delay: chip dependent delay for transfering data from array to | |
| 332 * read regs (tR) | |
| 333 * - options: various chip options. They can partly be set to inform | |
| 334 * nand_scan about special functionality. See the defines for further | |
| 335 * explanation | |
| 336 * Members with a "?" were not set in the merged testing-NAND branch, | |
| 337 * so they are not set here either. | |
| 338 */ | |
| 339 int board_nand_init(struct nand_chip *nand) | |
| 340 { | |
| 341 #if (LINUX_MACH_TYPE == MACH_TYPE_SEABOARD) | |
| 342 /* GPIO port H bit 3, H.03, GMI_AD11->MFG_MODE_R, */ | |
| 343 tg2_gpio_direction_output(7, 3, 1); | |
| 344 #endif | |
| 345 #if (LINUX_MACH_TYPE == MACH_TYPE_HARMONY) | |
| 346 /* GPIO port C bit 7, C.07, GMI_WP->NAND_WP */ | |
| 347 tg2_gpio_direction_output(2, 7, 1); | |
| 348 #endif | |
| 349 nand->cmd_ctrl = tegra2_nand_hwcontrol; | |
| 350 nand->dev_ready = tegra2_nand_dev_ready; | |
| 351 nand->ecc.mode = NAND_ECC_NONE; | |
| 352 nand->ecc.layout = &nand_soft_eccoob; | |
| 353 nand->options = LP_OPTIONS; | |
| 354 nand->cmdfunc = tegra2_nand_command; | |
| 355 nand->read_byte = tegra2_nand_read_byte; | |
| 356 nand->read_buf = tegra2_nand_read_buf; | |
| 357 nand->write_buf = tegra2_nand_write_buf; | |
| 358 return 0; | |
| 359 } | |
| OLD | NEW |