Blame view
drivers/mtd/nand/raw/mxs_nand.c
43 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
0d4e85098 iMX28: Add GPMI N... |
2 3 4 5 6 7 8 9 10 11 12 |
/* * Freescale i.MX28 NAND flash driver * * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> * on behalf of DENX Software Engineering GmbH * * Based on code from LTIB: * Freescale GPMI NFC NAND Flash Driver * * Copyright (C) 2010 Freescale Semiconductor, Inc. * Copyright (C) 2008 Embedded Alley Solutions, Inc. |
722f0ff0b MLK-12693-2 nand:... |
13 |
* Copyright 2017-2019 NXP |
0d4e85098 iMX28: Add GPMI N... |
14 |
*/ |
651eb7322 NAND: MXS: includ... |
15 |
#include <common.h> |
68748340c mtd: nand: mxs_na... |
16 |
#include <dm.h> |
6ae3900a8 mtd: nand: Rename... |
17 |
#include <linux/mtd/rawnand.h> |
984df7add mtd: nand: mxs_na... |
18 |
#include <linux/sizes.h> |
0d4e85098 iMX28: Add GPMI N... |
19 |
#include <linux/types.h> |
0d4e85098 iMX28: Add GPMI N... |
20 |
#include <malloc.h> |
1221ce459 treewide: replace... |
21 |
#include <linux/errno.h> |
0d4e85098 iMX28: Add GPMI N... |
22 23 24 |
#include <asm/io.h> #include <asm/arch/clock.h> #include <asm/arch/imx-regs.h> |
552a848e4 imx: reorganize I... |
25 26 |
#include <asm/mach-imx/regs-bch.h> #include <asm/mach-imx/regs-gpmi.h> |
0d4e85098 iMX28: Add GPMI N... |
27 |
#include <asm/arch/sys_proto.h> |
49538a259 i.MX6: nand: add ... |
28 |
#include <mxs_nand.h> |
0d4e85098 iMX28: Add GPMI N... |
29 30 |
#define MXS_NAND_DMA_DESCRIPTOR_COUNT 4 |
a9f0815c2 MLK-16034-02: ena... |
31 |
#if (defined(CONFIG_MX6) || defined(CONFIG_MX7) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)) |
ae695b18d mtd: mxs_nand: Ad... |
32 33 34 35 |
#define MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT 2 #else #define MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT 0 #endif |
0d4e85098 iMX28: Add GPMI N... |
36 |
#define MXS_NAND_METADATA_SIZE 10 |
1fbdb7061 mtd: nand: mxs: R... |
37 |
#define MXS_NAND_BITS_PER_ECC_LEVEL 13 |
2a83c95fd mtd: nand: mxs: f... |
38 39 |
#if !defined(CONFIG_SYS_CACHELINE_SIZE) || CONFIG_SYS_CACHELINE_SIZE < 32 |
0d4e85098 iMX28: Add GPMI N... |
40 |
#define MXS_NAND_COMMAND_BUFFER_SIZE 32 |
2a83c95fd mtd: nand: mxs: f... |
41 42 43 |
#else #define MXS_NAND_COMMAND_BUFFER_SIZE CONFIG_SYS_CACHELINE_SIZE #endif |
0d4e85098 iMX28: Add GPMI N... |
44 45 |
#define MXS_NAND_BCH_TIMEOUT 10000 |
0d4e85098 iMX28: Add GPMI N... |
46 |
struct nand_ecclayout fake_ecc_layout; |
6b9408edd i.MX28: Add cache... |
47 48 49 50 51 52 |
/* * Cache management functions */ #ifndef CONFIG_SYS_DCACHE_OFF static void mxs_nand_flush_data_buf(struct mxs_nand_info *info) { |
a9f0815c2 MLK-16034-02: ena... |
53 |
uint32_t addr = (uintptr_t)info->data_buf; |
6b9408edd i.MX28: Add cache... |
54 55 56 57 58 59 |
flush_dcache_range(addr, addr + info->data_buf_size); } static void mxs_nand_inval_data_buf(struct mxs_nand_info *info) { |
a9f0815c2 MLK-16034-02: ena... |
60 |
uint32_t addr = (uintptr_t)info->data_buf; |
6b9408edd i.MX28: Add cache... |
61 62 63 64 65 66 |
invalidate_dcache_range(addr, addr + info->data_buf_size); } static void mxs_nand_flush_cmd_buf(struct mxs_nand_info *info) { |
a9f0815c2 MLK-16034-02: ena... |
67 |
uint32_t addr = (uintptr_t)info->cmd_buf; |
6b9408edd i.MX28: Add cache... |
68 69 70 71 72 73 74 75 |
flush_dcache_range(addr, addr + MXS_NAND_COMMAND_BUFFER_SIZE); } #else static inline void mxs_nand_flush_data_buf(struct mxs_nand_info *info) {} static inline void mxs_nand_inval_data_buf(struct mxs_nand_info *info) {} static inline void mxs_nand_flush_cmd_buf(struct mxs_nand_info *info) {} #endif |
0d4e85098 iMX28: Add GPMI N... |
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
static struct mxs_dma_desc *mxs_nand_get_dma_desc(struct mxs_nand_info *info) { struct mxs_dma_desc *desc; if (info->desc_index >= MXS_NAND_DMA_DESCRIPTOR_COUNT) { printf("MXS NAND: Too many DMA descriptors requested "); return NULL; } desc = info->desc[info->desc_index]; info->desc_index++; return desc; } static void mxs_nand_return_dma_descs(struct mxs_nand_info *info) { int i; struct mxs_dma_desc *desc; for (i = 0; i < info->desc_index; i++) { desc = info->desc[i]; memset(desc, 0, sizeof(struct mxs_dma_desc)); desc->address = (dma_addr_t)desc; } info->desc_index = 0; } |
0d4e85098 iMX28: Add GPMI N... |
105 106 107 108 |
static uint32_t mxs_nand_aux_status_offset(void) { return (MXS_NAND_METADATA_SIZE + 0x3) & ~0x3; } |
71fe512f8 MLK-11719-4: mtd:... |
109 110 |
static inline bool mxs_nand_bbm_in_data_chunk(struct bch_geometry *geo, struct mtd_info *mtd, unsigned int *chunk_num) |
0d4e85098 iMX28: Add GPMI N... |
111 |
{ |
71fe512f8 MLK-11719-4: mtd:... |
112 |
unsigned int i, j; |
0d4e85098 iMX28: Add GPMI N... |
113 |
|
71fe512f8 MLK-11719-4: mtd:... |
114 115 116 117 118 |
if (geo->ecc_chunk0_size != geo->ecc_chunkn_size) { dev_err(this->dev, "The size of chunk0 must equal to chunkn "); return false; } |
0d4e85098 iMX28: Add GPMI N... |
119 |
|
71fe512f8 MLK-11719-4: mtd:... |
120 121 122 |
i = (mtd->writesize * 8 - MXS_NAND_METADATA_SIZE * 8) / (geo->gf_len * geo->ecc_strength + geo->ecc_chunkn_size * 8); |
0d4e85098 iMX28: Add GPMI N... |
123 |
|
71fe512f8 MLK-11719-4: mtd:... |
124 125 126 |
j = (mtd->writesize * 8 - MXS_NAND_METADATA_SIZE * 8) - (geo->gf_len * geo->ecc_strength + geo->ecc_chunkn_size * 8) * i; |
0d4e85098 iMX28: Add GPMI N... |
127 |
|
71fe512f8 MLK-11719-4: mtd:... |
128 129 130 131 132 133 134 |
if (j < geo->ecc_chunkn_size * 8) { *chunk_num = i+1; dev_dbg(this->dev, "Set ecc to %d and bbm in chunk %d ", geo->ecc_strength, *chunk_num); return true; } |
0d4e85098 iMX28: Add GPMI N... |
135 |
|
71fe512f8 MLK-11719-4: mtd:... |
136 |
return false; |
0d4e85098 iMX28: Add GPMI N... |
137 |
} |
984df7add mtd: nand: mxs_na... |
138 |
static inline int mxs_nand_calc_ecc_layout_by_info(struct bch_geometry *geo, |
627544506 mtd: nand: mxs_na... |
139 140 141 |
struct mtd_info *mtd, unsigned int ecc_strength, unsigned int ecc_step) |
984df7add mtd: nand: mxs_na... |
142 143 |
{ struct nand_chip *chip = mtd_to_nand(mtd); |
502bdc6b4 mtd: nand: mxs_na... |
144 |
struct mxs_nand_info *nand_info = nand_get_controller_data(chip); |
71fe512f8 MLK-11719-4: mtd:... |
145 |
unsigned int block_mark_bit_offset; |
984df7add mtd: nand: mxs_na... |
146 |
|
627544506 mtd: nand: mxs_na... |
147 |
switch (ecc_step) { |
984df7add mtd: nand: mxs_na... |
148 149 150 151 152 153 154 155 156 |
case SZ_512: geo->gf_len = 13; break; case SZ_1K: geo->gf_len = 14; break; default: return -EINVAL; } |
71fe512f8 MLK-11719-4: mtd:... |
157 158 |
geo->ecc_chunk0_size = ecc_step; geo->ecc_chunkn_size = ecc_step; |
627544506 mtd: nand: mxs_na... |
159 |
geo->ecc_strength = round_up(ecc_strength, 2); |
984df7add mtd: nand: mxs_na... |
160 161 |
/* Keep the C >= O */ |
71fe512f8 MLK-11719-4: mtd:... |
162 |
if (geo->ecc_chunkn_size < mtd->oobsize) |
984df7add mtd: nand: mxs_na... |
163 |
return -EINVAL; |
502bdc6b4 mtd: nand: mxs_na... |
164 |
if (geo->ecc_strength > nand_info->max_ecc_strength_supported) |
984df7add mtd: nand: mxs_na... |
165 |
return -EINVAL; |
71fe512f8 MLK-11719-4: mtd:... |
166 167 168 169 170 171 172 173 174 |
geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunkn_size; /* For bit swap. */ block_mark_bit_offset = mtd->writesize * 8 - (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - 1) + MXS_NAND_METADATA_SIZE * 8); geo->block_mark_byte_offset = block_mark_bit_offset / 8; geo->block_mark_bit_offset = block_mark_bit_offset % 8; |
984df7add mtd: nand: mxs_na... |
175 176 177 |
return 0; } |
71fe512f8 MLK-11719-4: mtd:... |
178 |
static inline int mxs_nand_legacy_calc_ecc_layout(struct bch_geometry *geo, |
28897e8d2 mtd: nand: mxs_na... |
179 |
struct mtd_info *mtd) |
0d4e85098 iMX28: Add GPMI N... |
180 |
{ |
502bdc6b4 mtd: nand: mxs_na... |
181 182 |
struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); |
71fe512f8 MLK-11719-4: mtd:... |
183 |
unsigned int block_mark_bit_offset; |
502bdc6b4 mtd: nand: mxs_na... |
184 |
|
28897e8d2 mtd: nand: mxs_na... |
185 186 187 188 |
/* The default for the length of Galois Field. */ geo->gf_len = 13; /* The default for chunk size. */ |
71fe512f8 MLK-11719-4: mtd:... |
189 190 |
geo->ecc_chunk0_size = 512; geo->ecc_chunkn_size = 512; |
28897e8d2 mtd: nand: mxs_na... |
191 |
|
71fe512f8 MLK-11719-4: mtd:... |
192 |
if (geo->ecc_chunkn_size < mtd->oobsize) { |
28897e8d2 mtd: nand: mxs_na... |
193 |
geo->gf_len = 14; |
71fe512f8 MLK-11719-4: mtd:... |
194 195 |
geo->ecc_chunk0_size *= 2; geo->ecc_chunkn_size *= 2; |
28897e8d2 mtd: nand: mxs_na... |
196 |
} |
71fe512f8 MLK-11719-4: mtd:... |
197 |
geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunkn_size; |
28897e8d2 mtd: nand: mxs_na... |
198 |
|
28897e8d2 mtd: nand: mxs_na... |
199 200 201 202 203 204 205 206 207 208 |
/* * Determine the ECC layout with the formula: * ECC bits per chunk = (total page spare data bits) / * (bits per ECC level) / (chunks per page) * where: * total page spare data bits = * (page oob size - meta data size) * (bits per byte) */ geo->ecc_strength = ((mtd->oobsize - MXS_NAND_METADATA_SIZE) * 8) / (geo->gf_len * geo->ecc_chunk_count); |
984df7add mtd: nand: mxs_na... |
209 |
geo->ecc_strength = min(round_down(geo->ecc_strength, 2), |
502bdc6b4 mtd: nand: mxs_na... |
210 |
nand_info->max_ecc_strength_supported); |
28897e8d2 mtd: nand: mxs_na... |
211 |
|
71fe512f8 MLK-11719-4: mtd:... |
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
block_mark_bit_offset = mtd->writesize * 8 - (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - 1) + MXS_NAND_METADATA_SIZE * 8); geo->block_mark_byte_offset = block_mark_bit_offset / 8; geo->block_mark_bit_offset = block_mark_bit_offset % 8; return 0; } static inline int mxs_nand_calc_ecc_for_large_oob(struct bch_geometry *geo, struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); unsigned int block_mark_bit_offset; unsigned int max_ecc; unsigned int bbm_chunk; unsigned int i; /* sanity check for the minimum ecc nand required */ if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) return -EINVAL; geo->ecc_strength = chip->ecc_strength_ds; /* calculate the maximum ecc platform can support*/ geo->gf_len = 14; geo->ecc_chunk0_size = 1024; geo->ecc_chunkn_size = 1024; geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunkn_size; max_ecc = ((mtd->oobsize - MXS_NAND_METADATA_SIZE) * 8) / (geo->gf_len * geo->ecc_chunk_count); max_ecc = min(round_down(max_ecc, 2), nand_info->max_ecc_strength_supported); /* search a supported ecc strength that makes bbm */ /* located in data chunk */ geo->ecc_strength = chip->ecc_strength_ds; while (!(geo->ecc_strength > max_ecc)) { if (mxs_nand_bbm_in_data_chunk(geo, mtd, &bbm_chunk)) break; geo->ecc_strength += 2; } /* if none of them works, keep using the minimum ecc */ /* nand required but changing ecc page layout */ if (geo->ecc_strength > max_ecc) { geo->ecc_strength = chip->ecc_strength_ds; /* add extra ecc for meta data */ geo->ecc_chunk0_size = 0; geo->ecc_chunk_count = (mtd->writesize / geo->ecc_chunkn_size) + 1; geo->ecc_for_meta = 1; /* check if oob can afford this extra ecc chunk */ if (mtd->oobsize * 8 < MXS_NAND_METADATA_SIZE * 8 + geo->gf_len * geo->ecc_strength * geo->ecc_chunk_count) { printf("unsupported NAND chip with new layout "); return -EINVAL; } /* calculate in which chunk bbm located */ bbm_chunk = (mtd->writesize * 8 - MXS_NAND_METADATA_SIZE * 8 - geo->gf_len * geo->ecc_strength) / (geo->gf_len * geo->ecc_strength + geo->ecc_chunkn_size * 8) + 1; } /* calculate the number of ecc chunk behind the bbm */ i = (mtd->writesize / geo->ecc_chunkn_size) - bbm_chunk + 1; block_mark_bit_offset = mtd->writesize * 8 - (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - i) + MXS_NAND_METADATA_SIZE * 8); geo->block_mark_byte_offset = block_mark_bit_offset / 8; geo->block_mark_bit_offset = block_mark_bit_offset % 8; |
28897e8d2 mtd: nand: mxs_na... |
290 |
return 0; |
0d4e85098 iMX28: Add GPMI N... |
291 292 293 294 295 |
} /* * Wait for BCH complete IRQ and clear the IRQ */ |
931747e51 mtd: nand: mxs_na... |
296 |
static int mxs_nand_wait_for_bch_complete(struct mxs_nand_info *nand_info) |
0d4e85098 iMX28: Add GPMI N... |
297 |
{ |
0d4e85098 iMX28: Add GPMI N... |
298 299 |
int timeout = MXS_NAND_BCH_TIMEOUT; int ret; |
931747e51 mtd: nand: mxs_na... |
300 |
ret = mxs_wait_mask_set(&nand_info->bch_regs->hw_bch_ctrl_reg, |
0d4e85098 iMX28: Add GPMI N... |
301 |
BCH_CTRL_COMPLETE_IRQ, timeout); |
931747e51 mtd: nand: mxs_na... |
302 |
writel(BCH_CTRL_COMPLETE_IRQ, &nand_info->bch_regs->hw_bch_ctrl_clr); |
0d4e85098 iMX28: Add GPMI N... |
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
return ret; } /* * This is the function that we install in the cmd_ctrl function pointer of the * owning struct nand_chip. The only functions in the reference implementation * that use these functions pointers are cmdfunc and select_chip. * * In this driver, we implement our own select_chip, so this function will only * be called by the reference implementation's cmdfunc. For this reason, we can * ignore the chip enable bit and concentrate only on sending bytes to the NAND * Flash. */ static void mxs_nand_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl) { |
17cb4b8f3 mtd: nand: Add+us... |
319 320 |
struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
0d4e85098 iMX28: Add GPMI N... |
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
struct mxs_dma_desc *d; uint32_t channel = MXS_DMA_CHANNEL_AHB_APBH_GPMI0 + nand_info->cur_chip; int ret; /* * If this condition is true, something is _VERY_ wrong in MTD * subsystem! */ if (nand_info->cmd_queue_len == MXS_NAND_COMMAND_BUFFER_SIZE) { printf("MXS NAND: Command queue too long "); return; } /* * Every operation begins with a command byte and a series of zero or * more address bytes. These are distinguished by either the Address * Latch Enable (ALE) or Command Latch Enable (CLE) signals being * asserted. When MTD is ready to execute the command, it will * deasert both latch enables. * * Rather than run a separate DMA operation for every single byte, we * queue them up and run a single DMA operation for the entire series * of command and data bytes. */ if (ctrl & (NAND_ALE | NAND_CLE)) { if (data != NAND_CMD_NONE) nand_info->cmd_buf[nand_info->cmd_queue_len++] = data; return; } /* * If control arrives here, MTD has deasserted both the ALE and CLE, * which means it's ready to run an operation. Check if we have any * bytes to send. */ if (nand_info->cmd_queue_len == 0) return; /* Compile the DMA descriptor -- a descriptor that sends command. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_DMA_READ | MXS_DMA_DESC_IRQ | MXS_DMA_DESC_CHAIN | MXS_DMA_DESC_DEC_SEM | MXS_DMA_DESC_WAIT4END | (3 << MXS_DMA_DESC_PIO_WORDS_OFFSET) | (nand_info->cmd_queue_len << MXS_DMA_DESC_BYTES_OFFSET); d->cmd.address = (dma_addr_t)nand_info->cmd_buf; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_WRITE | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_CLE | GPMI_CTRL0_ADDRESS_INCREMENT | nand_info->cmd_queue_len; mxs_dma_desc_append(channel, d); |
6b9408edd i.MX28: Add cache... |
379 380 |
/* Flush caches */ mxs_nand_flush_cmd_buf(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
/* Execute the DMA chain. */ ret = mxs_dma_go(channel); if (ret) printf("MXS NAND: Error sending command "); mxs_nand_return_dma_descs(nand_info); /* Reset the command queue. */ nand_info->cmd_queue_len = 0; } /* * Test if the NAND flash is ready. */ static int mxs_nand_device_ready(struct mtd_info *mtd) { |
17cb4b8f3 mtd: nand: Add+us... |
398 399 |
struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); |
0d4e85098 iMX28: Add GPMI N... |
400 |
uint32_t tmp; |
931747e51 mtd: nand: mxs_na... |
401 |
tmp = readl(&nand_info->gpmi_regs->hw_gpmi_stat); |
0d4e85098 iMX28: Add GPMI N... |
402 403 404 405 406 407 408 409 410 411 |
tmp >>= (GPMI_STAT_READY_BUSY_OFFSET + nand_info->cur_chip); return tmp & 1; } /* * Select the NAND chip. */ static void mxs_nand_select_chip(struct mtd_info *mtd, int chip) { |
17cb4b8f3 mtd: nand: Add+us... |
412 413 |
struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
0d4e85098 iMX28: Add GPMI N... |
414 415 416 417 418 419 420 421 422 423 424 |
nand_info->cur_chip = chip; } /* * Handle block mark swapping. * * Note that, when this function is called, it doesn't know whether it's * swapping the block mark, or swapping it *back* -- but it doesn't matter * because the the operation is the same. */ |
28897e8d2 mtd: nand: mxs_na... |
425 426 |
static void mxs_nand_swap_block_mark(struct bch_geometry *geo, uint8_t *data_buf, uint8_t *oob_buf) |
0d4e85098 iMX28: Add GPMI N... |
427 |
{ |
28897e8d2 mtd: nand: mxs_na... |
428 429 |
uint32_t bit_offset = geo->block_mark_bit_offset; uint32_t buf_offset = geo->block_mark_byte_offset; |
0d4e85098 iMX28: Add GPMI N... |
430 431 432 |
uint32_t src; uint32_t dst; |
0d4e85098 iMX28: Add GPMI N... |
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
/* * Get the byte from the data area that overlays the block mark. Since * the ECC engine applies its own view to the bits in the page, the * physical block mark won't (in general) appear on a byte boundary in * the data. */ src = data_buf[buf_offset] >> bit_offset; src |= data_buf[buf_offset + 1] << (8 - bit_offset); dst = oob_buf[0]; oob_buf[0] = src; data_buf[buf_offset] &= ~(0xff << bit_offset); data_buf[buf_offset + 1] &= 0xff << bit_offset; data_buf[buf_offset] |= dst << bit_offset; data_buf[buf_offset + 1] |= dst >> (8 - bit_offset); } /* * Read data from NAND. */ static void mxs_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int length) { |
17cb4b8f3 mtd: nand: Add+us... |
458 459 |
struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
0d4e85098 iMX28: Add GPMI N... |
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
struct mxs_dma_desc *d; uint32_t channel = MXS_DMA_CHANNEL_AHB_APBH_GPMI0 + nand_info->cur_chip; int ret; if (length > NAND_MAX_PAGESIZE) { printf("MXS NAND: DMA buffer too big "); return; } if (!buf) { printf("MXS NAND: DMA buffer is NULL "); return; } /* Compile the DMA descriptor - a descriptor that reads data. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_DMA_WRITE | MXS_DMA_DESC_IRQ | MXS_DMA_DESC_DEC_SEM | MXS_DMA_DESC_WAIT4END | (1 << MXS_DMA_DESC_PIO_WORDS_OFFSET) | (length << MXS_DMA_DESC_BYTES_OFFSET); d->cmd.address = (dma_addr_t)nand_info->data_buf; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_READ | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_DATA | length; mxs_dma_desc_append(channel, d); /* * A DMA descriptor that waits for the command to end and the chip to * become ready. * * I think we actually should *not* be waiting for the chip to become * ready because, after all, we don't care. I think the original code * did that and no one has re-thought it yet. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_IRQ | MXS_DMA_DESC_NAND_WAIT_4_READY | MXS_DMA_DESC_DEC_SEM | |
5263a02e8 mtd: nand: mxs: f... |
507 |
MXS_DMA_DESC_WAIT4END | (1 << MXS_DMA_DESC_PIO_WORDS_OFFSET); |
0d4e85098 iMX28: Add GPMI N... |
508 509 510 511 512 513 514 515 516 517 |
d->cmd.address = 0; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_WAIT_FOR_READY | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_DATA; mxs_dma_desc_append(channel, d); |
ecfb8768b mtd: nand: mxs in... |
518 519 |
/* Invalidate caches */ mxs_nand_inval_data_buf(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
520 521 522 523 524 525 526 |
/* Execute the DMA chain. */ ret = mxs_dma_go(channel); if (ret) { printf("MXS NAND: DMA read error "); goto rtn; } |
6b9408edd i.MX28: Add cache... |
527 528 |
/* Invalidate caches */ mxs_nand_inval_data_buf(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
529 530 531 532 533 534 535 536 537 538 539 540 |
memcpy(buf, nand_info->data_buf, length); rtn: mxs_nand_return_dma_descs(nand_info); } /* * Write data to NAND. */ static void mxs_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int length) { |
17cb4b8f3 mtd: nand: Add+us... |
541 542 |
struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
0d4e85098 iMX28: Add GPMI N... |
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
struct mxs_dma_desc *d; uint32_t channel = MXS_DMA_CHANNEL_AHB_APBH_GPMI0 + nand_info->cur_chip; int ret; if (length > NAND_MAX_PAGESIZE) { printf("MXS NAND: DMA buffer too big "); return; } if (!buf) { printf("MXS NAND: DMA buffer is NULL "); return; } memcpy(nand_info->data_buf, buf, length); /* Compile the DMA descriptor - a descriptor that writes data. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_DMA_READ | MXS_DMA_DESC_IRQ | MXS_DMA_DESC_DEC_SEM | MXS_DMA_DESC_WAIT4END | |
88a2cbb2a mtd: nand: mxs: f... |
566 |
(1 << MXS_DMA_DESC_PIO_WORDS_OFFSET) | |
0d4e85098 iMX28: Add GPMI N... |
567 568 569 570 571 572 573 574 575 576 577 578 |
(length << MXS_DMA_DESC_BYTES_OFFSET); d->cmd.address = (dma_addr_t)nand_info->data_buf; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_WRITE | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_DATA | length; mxs_dma_desc_append(channel, d); |
6b9408edd i.MX28: Add cache... |
579 580 |
/* Flush caches */ mxs_nand_flush_data_buf(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
/* Execute the DMA chain. */ ret = mxs_dma_go(channel); if (ret) printf("MXS NAND: DMA write error "); mxs_nand_return_dma_descs(nand_info); } /* * Read a single byte from NAND. */ static uint8_t mxs_nand_read_byte(struct mtd_info *mtd) { uint8_t buf; mxs_nand_read_buf(mtd, &buf, 1); return buf; } |
eefb30b8e MLK-12693-1 nand:... |
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
static bool mxs_nand_erased_page(struct mtd_info *mtd, struct nand_chip *nand, uint8_t *buf, int chunk, int page) { struct mxs_nand_info *nand_info = nand_get_controller_data(nand); struct bch_geometry *geo = &nand_info->bch_geometry; unsigned int flip_bits = 0, flip_bits_noecc = 0; unsigned int threshold; unsigned int base = geo->ecc_chunkn_size * chunk; uint32_t *dma_buf = (uint32_t *)buf; int i; threshold = geo->gf_len / 2; if (threshold > geo->ecc_strength) threshold = geo->ecc_strength; for (i = 0; i < geo->ecc_chunkn_size; i++) { flip_bits += hweight8(~buf[base + i]); if (flip_bits > threshold) return false; } nand->cmdfunc(mtd, NAND_CMD_READ0, 0, page); nand->read_buf(mtd, buf, mtd->writesize); for (i = 0; i < mtd->writesize / 4; i++) { flip_bits_noecc += hweight32(~dma_buf[i]); if (flip_bits_noecc > threshold) return false; } mtd->ecc_stats.corrected += flip_bits; memset(buf, 0xff, mtd->writesize); printf("The page(%d) is an erased page(%d,%d,%d,%d). ", page, chunk, threshold, flip_bits, flip_bits_noecc); return true; } |
0d4e85098 iMX28: Add GPMI N... |
638 639 640 641 |
/* * Read a page from NAND. */ static int mxs_nand_ecc_read_page(struct mtd_info *mtd, struct nand_chip *nand, |
dfe64e2c8 mtd: resync with ... |
642 643 |
uint8_t *buf, int oob_required, int page) |
0d4e85098 iMX28: Add GPMI N... |
644 |
{ |
17cb4b8f3 mtd: nand: Add+us... |
645 |
struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
28897e8d2 mtd: nand: mxs_na... |
646 |
struct bch_geometry *geo = &nand_info->bch_geometry; |
722f0ff0b MLK-12693-2 nand:... |
647 |
struct mxs_bch_regs *bch_regs = nand_info->bch_regs; |
0d4e85098 iMX28: Add GPMI N... |
648 649 650 651 652 |
struct mxs_dma_desc *d; uint32_t channel = MXS_DMA_CHANNEL_AHB_APBH_GPMI0 + nand_info->cur_chip; uint32_t corrected = 0, failed = 0; uint8_t *status; int i, ret; |
722f0ff0b MLK-12693-2 nand:... |
653 |
int flag = 0; |
0d4e85098 iMX28: Add GPMI N... |
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
/* Compile the DMA descriptor - wait for ready. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_CHAIN | MXS_DMA_DESC_NAND_WAIT_4_READY | MXS_DMA_DESC_WAIT4END | (1 << MXS_DMA_DESC_PIO_WORDS_OFFSET); d->cmd.address = 0; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_WAIT_FOR_READY | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_DATA; mxs_dma_desc_append(channel, d); /* Compile the DMA descriptor - enable the BCH block and read. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_CHAIN | MXS_DMA_DESC_WAIT4END | (6 << MXS_DMA_DESC_PIO_WORDS_OFFSET); d->cmd.address = 0; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_READ | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_DATA | (mtd->writesize + mtd->oobsize); d->cmd.pio_words[1] = 0; d->cmd.pio_words[2] = GPMI_ECCCTRL_ENABLE_ECC | GPMI_ECCCTRL_ECC_CMD_DECODE | GPMI_ECCCTRL_BUFFER_MASK_BCH_PAGE; d->cmd.pio_words[3] = mtd->writesize + mtd->oobsize; d->cmd.pio_words[4] = (dma_addr_t)nand_info->data_buf; d->cmd.pio_words[5] = (dma_addr_t)nand_info->oob_buf; mxs_dma_desc_append(channel, d); /* Compile the DMA descriptor - disable the BCH block. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_CHAIN | MXS_DMA_DESC_NAND_WAIT_4_READY | MXS_DMA_DESC_WAIT4END | (3 << MXS_DMA_DESC_PIO_WORDS_OFFSET); d->cmd.address = 0; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_WAIT_FOR_READY | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_DATA | (mtd->writesize + mtd->oobsize); d->cmd.pio_words[1] = 0; d->cmd.pio_words[2] = 0; mxs_dma_desc_append(channel, d); /* Compile the DMA descriptor - deassert the NAND lock and interrupt. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_IRQ | MXS_DMA_DESC_DEC_SEM; d->cmd.address = 0; mxs_dma_desc_append(channel, d); |
ecfb8768b mtd: nand: mxs in... |
726 727 |
/* Invalidate caches */ mxs_nand_inval_data_buf(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
728 729 730 731 732 733 734 |
/* Execute the DMA chain. */ ret = mxs_dma_go(channel); if (ret) { printf("MXS NAND: DMA read error "); goto rtn; } |
931747e51 mtd: nand: mxs_na... |
735 |
ret = mxs_nand_wait_for_bch_complete(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
736 737 738 739 740 |
if (ret) { printf("MXS NAND: BCH read timeout "); goto rtn; } |
eefb30b8e MLK-12693-1 nand:... |
741 |
mxs_nand_return_dma_descs(nand_info); |
6b9408edd i.MX28: Add cache... |
742 743 |
/* Invalidate caches */ mxs_nand_inval_data_buf(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
744 |
/* Read DMA completed, now do the mark swapping. */ |
28897e8d2 mtd: nand: mxs_na... |
745 |
mxs_nand_swap_block_mark(geo, nand_info->data_buf, nand_info->oob_buf); |
0d4e85098 iMX28: Add GPMI N... |
746 747 748 |
/* Loop over status bytes, accumulating ECC status. */ status = nand_info->oob_buf + mxs_nand_aux_status_offset(); |
28897e8d2 mtd: nand: mxs_na... |
749 |
for (i = 0; i < geo->ecc_chunk_count; i++) { |
0d4e85098 iMX28: Add GPMI N... |
750 751 |
if (status[i] == 0x00) continue; |
722f0ff0b MLK-12693-2 nand:... |
752 |
if (status[i] == 0xff) { |
887f33890 MLK-22827-2: mxs_... |
753 754 755 |
if (!nand_info->en_randomizer && (is_mx6dqp() || is_mx7() || is_mx6ul() || is_imx8() || is_imx8m())) |
722f0ff0b MLK-12693-2 nand:... |
756 757 |
if (readl(&bch_regs->hw_bch_debug1)) flag = 1; |
0d4e85098 iMX28: Add GPMI N... |
758 |
continue; |
722f0ff0b MLK-12693-2 nand:... |
759 |
} |
0d4e85098 iMX28: Add GPMI N... |
760 761 |
if (status[i] == 0xfe) { |
eefb30b8e MLK-12693-1 nand:... |
762 763 764 |
if (mxs_nand_erased_page(mtd, nand, nand_info->data_buf, i, page)) break; |
0d4e85098 iMX28: Add GPMI N... |
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 |
failed++; continue; } corrected += status[i]; } /* Propagate ECC status to the owning MTD. */ mtd->ecc_stats.failed += failed; mtd->ecc_stats.corrected += corrected; /* * It's time to deliver the OOB bytes. See mxs_nand_ecc_read_oob() for * details about our policy for delivering the OOB. * * We fill the caller's buffer with set bits, and then copy the block * mark to the caller's buffer. Note that, if block mark swapping was * necessary, it has already been done, so we can rely on the first * byte of the auxiliary buffer to contain the block mark. */ memset(nand->oob_poi, 0xff, mtd->oobsize); nand->oob_poi[0] = nand_info->oob_buf[0]; memcpy(buf, nand_info->data_buf, mtd->writesize); |
722f0ff0b MLK-12693-2 nand:... |
790 791 |
if (flag) memset(buf, 0xff, mtd->writesize); |
0d4e85098 iMX28: Add GPMI N... |
792 793 794 795 796 797 798 799 800 |
rtn: mxs_nand_return_dma_descs(nand_info); return ret; } /* * Write a page to NAND. */ |
dfe64e2c8 mtd: resync with ... |
801 802 |
static int mxs_nand_ecc_write_page(struct mtd_info *mtd, struct nand_chip *nand, const uint8_t *buf, |
81c772521 mtd: nand: Add pa... |
803 |
int oob_required, int page) |
0d4e85098 iMX28: Add GPMI N... |
804 |
{ |
17cb4b8f3 mtd: nand: Add+us... |
805 |
struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
28897e8d2 mtd: nand: mxs_na... |
806 |
struct bch_geometry *geo = &nand_info->bch_geometry; |
0d4e85098 iMX28: Add GPMI N... |
807 808 809 810 811 812 813 814 |
struct mxs_dma_desc *d; uint32_t channel = MXS_DMA_CHANNEL_AHB_APBH_GPMI0 + nand_info->cur_chip; int ret; memcpy(nand_info->data_buf, buf, mtd->writesize); memcpy(nand_info->oob_buf, nand->oob_poi, mtd->oobsize); /* Handle block mark swapping. */ |
28897e8d2 mtd: nand: mxs_na... |
815 |
mxs_nand_swap_block_mark(geo, nand_info->data_buf, nand_info->oob_buf); |
0d4e85098 iMX28: Add GPMI N... |
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
/* Compile the DMA descriptor - write data. */ d = mxs_nand_get_dma_desc(nand_info); d->cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_IRQ | MXS_DMA_DESC_DEC_SEM | MXS_DMA_DESC_WAIT4END | (6 << MXS_DMA_DESC_PIO_WORDS_OFFSET); d->cmd.address = 0; d->cmd.pio_words[0] = GPMI_CTRL0_COMMAND_MODE_WRITE | GPMI_CTRL0_WORD_LENGTH | (nand_info->cur_chip << GPMI_CTRL0_CS_OFFSET) | GPMI_CTRL0_ADDRESS_NAND_DATA; d->cmd.pio_words[1] = 0; d->cmd.pio_words[2] = GPMI_ECCCTRL_ENABLE_ECC | GPMI_ECCCTRL_ECC_CMD_ENCODE | GPMI_ECCCTRL_BUFFER_MASK_BCH_PAGE; d->cmd.pio_words[3] = (mtd->writesize + mtd->oobsize); d->cmd.pio_words[4] = (dma_addr_t)nand_info->data_buf; d->cmd.pio_words[5] = (dma_addr_t)nand_info->oob_buf; |
14772d11c MLK-22580-1: nand... |
839 |
if ((is_mx7() && nand_info->en_randomizer) || (is_imx8m() && nand_info->en_randomizer)) { |
77ac4a3e3 MLK-22444-2: nand... |
840 841 842 843 844 845 846 847 848 849 850 |
d->cmd.pio_words[2] |= GPMI_ECCCTRL_RANDOMIZER_ENABLE | GPMI_ECCCTRL_RANDOMIZER_TYPE2; /* * Write NAND page number needed to be randomized * to GPMI_ECCCOUNT register. * * The value is between 0-255. For additional details * check 9.6.6.4 of i.MX7D Applications Processor reference */ d->cmd.pio_words[3] |= (page % 255) << 16; } |
77ac4a3e3 MLK-22444-2: nand... |
851 |
|
0d4e85098 iMX28: Add GPMI N... |
852 |
mxs_dma_desc_append(channel, d); |
6b9408edd i.MX28: Add cache... |
853 854 |
/* Flush caches */ mxs_nand_flush_data_buf(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
855 856 857 858 859 860 861 |
/* Execute the DMA chain. */ ret = mxs_dma_go(channel); if (ret) { printf("MXS NAND: DMA write error "); goto rtn; } |
931747e51 mtd: nand: mxs_na... |
862 |
ret = mxs_nand_wait_for_bch_complete(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
863 864 865 866 867 868 869 870 |
if (ret) { printf("MXS NAND: BCH write timeout "); goto rtn; } rtn: mxs_nand_return_dma_descs(nand_info); |
dfe64e2c8 mtd: resync with ... |
871 |
return 0; |
0d4e85098 iMX28: Add GPMI N... |
872 873 874 875 876 877 878 879 880 881 882 |
} /* * Read OOB from NAND. * * This function is a veneer that replaces the function originally installed by * the NAND Flash MTD code. */ static int mxs_nand_hook_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) { |
17cb4b8f3 mtd: nand: Add+us... |
883 884 |
struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); |
0d4e85098 iMX28: Add GPMI N... |
885 |
int ret; |
dfe64e2c8 mtd: resync with ... |
886 |
if (ops->mode == MTD_OPS_RAW) |
0d4e85098 iMX28: Add GPMI N... |
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 |
nand_info->raw_oob_mode = 1; else nand_info->raw_oob_mode = 0; ret = nand_info->hooked_read_oob(mtd, from, ops); nand_info->raw_oob_mode = 0; return ret; } /* * Write OOB to NAND. * * This function is a veneer that replaces the function originally installed by * the NAND Flash MTD code. */ static int mxs_nand_hook_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) { |
17cb4b8f3 mtd: nand: Add+us... |
907 908 |
struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); |
0d4e85098 iMX28: Add GPMI N... |
909 |
int ret; |
dfe64e2c8 mtd: resync with ... |
910 |
if (ops->mode == MTD_OPS_RAW) |
0d4e85098 iMX28: Add GPMI N... |
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 |
nand_info->raw_oob_mode = 1; else nand_info->raw_oob_mode = 0; ret = nand_info->hooked_write_oob(mtd, to, ops); nand_info->raw_oob_mode = 0; return ret; } /* * Mark a block bad in NAND. * * This function is a veneer that replaces the function originally installed by * the NAND Flash MTD code. */ static int mxs_nand_hook_block_markbad(struct mtd_info *mtd, loff_t ofs) { |
17cb4b8f3 mtd: nand: Add+us... |
930 931 |
struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); |
0d4e85098 iMX28: Add GPMI N... |
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 |
int ret; nand_info->marking_block_bad = 1; ret = nand_info->hooked_block_markbad(mtd, ofs); nand_info->marking_block_bad = 0; return ret; } /* * There are several places in this driver where we have to handle the OOB and * block marks. This is the function where things are the most complicated, so * this is where we try to explain it all. All the other places refer back to * here. * * These are the rules, in order of decreasing importance: * * 1) Nothing the caller does can be allowed to imperil the block mark, so all * write operations take measures to protect it. * * 2) In read operations, the first byte of the OOB we return must reflect the * true state of the block mark, no matter where that block mark appears in * the physical page. * * 3) ECC-based read operations return an OOB full of set bits (since we never * allow ECC-based writes to the OOB, it doesn't matter what ECC-based reads * return). * * 4) "Raw" read operations return a direct view of the physical bytes in the * page, using the conventional definition of which bytes are data and which * are OOB. This gives the caller a way to see the actual, physical bytes * in the page, without the distortions applied by our ECC engine. * * What we do for this specific read operation depends on whether we're doing * "raw" read, or an ECC-based read. * * It turns out that knowing whether we want an "ECC-based" or "raw" read is not * easy. When reading a page, for example, the NAND Flash MTD code calls our * ecc.read_page or ecc.read_page_raw function. Thus, the fact that MTD wants an * ECC-based or raw view of the page is implicit in which function it calls * (there is a similar pair of ECC-based/raw functions for writing). * * Since MTD assumes the OOB is not covered by ECC, there is no pair of * ECC-based/raw functions for reading or or writing the OOB. The fact that the * caller wants an ECC-based or raw view of the page is not propagated down to * this driver. * * Since our OOB *is* covered by ECC, we need this information. So, we hook the * ecc.read_oob and ecc.write_oob function pointers in the owning * struct mtd_info with our own functions. These hook functions set the * raw_oob_mode field so that, when control finally arrives here, we'll know * what to do. */ static int mxs_nand_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *nand, |
dfe64e2c8 mtd: resync with ... |
988 |
int page) |
0d4e85098 iMX28: Add GPMI N... |
989 |
{ |
17cb4b8f3 mtd: nand: Add+us... |
990 |
struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
0d4e85098 iMX28: Add GPMI N... |
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 |
/* * First, fill in the OOB buffer. If we're doing a raw read, we need to * get the bytes from the physical page. If we're not doing a raw read, * we need to fill the buffer with set bits. */ if (nand_info->raw_oob_mode) { /* * If control arrives here, we're doing a "raw" read. Send the * command to read the conventional OOB and read it. */ nand->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page); nand->read_buf(mtd, nand->oob_poi, mtd->oobsize); } else { /* * If control arrives here, we're not doing a "raw" read. Fill * the OOB buffer with set bits and correct the block mark. */ memset(nand->oob_poi, 0xff, mtd->oobsize); nand->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page); mxs_nand_read_buf(mtd, nand->oob_poi, 1); } return 0; } /* * Write OOB data to NAND. */ static int mxs_nand_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *nand, int page) { |
17cb4b8f3 mtd: nand: Add+us... |
1025 |
struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
0d4e85098 iMX28: Add GPMI N... |
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 |
uint8_t block_mark = 0; /* * There are fundamental incompatibilities between the i.MX GPMI NFC and * the NAND Flash MTD model that make it essentially impossible to write * the out-of-band bytes. * * We permit *ONE* exception. If the *intent* of writing the OOB is to * mark a block bad, we can do that. */ if (!nand_info->marking_block_bad) { printf("NXS NAND: Writing OOB isn't supported "); return -EIO; } /* Write the block mark. */ nand->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page); nand->write_buf(mtd, &block_mark, 1); nand->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); /* Check if it worked. */ if (nand->waitfunc(mtd, nand) & NAND_STATUS_FAIL) return -EIO; return 0; } /* * Claims all blocks are good. * * In principle, this function is *only* called when the NAND Flash MTD system * isn't allowed to keep an in-memory bad block table, so it is forced to ask * the driver for bad block information. * * In fact, we permit the NAND Flash MTD system to have an in-memory BBT, so * this function is *only* called when we take it away. * * Thus, this function is only called when we want *all* blocks to look good, * so it *always* return success. */ |
ceee07b65 mtd: nand: Sync w... |
1068 |
static int mxs_nand_block_bad(struct mtd_info *mtd, loff_t ofs) |
0d4e85098 iMX28: Add GPMI N... |
1069 1070 1071 |
{ return 0; } |
627544506 mtd: nand: mxs_na... |
1072 1073 1074 1075 1076 |
static int mxs_nand_set_geometry(struct mtd_info *mtd, struct bch_geometry *geo) { struct nand_chip *chip = mtd_to_nand(mtd); struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
71fe512f8 MLK-11719-4: mtd:... |
1077 1078 1079 1080 1081 1082 |
if (chip->ecc_strength_ds > nand_info->max_ecc_strength_supported) { printf("unsupported NAND chip, minimum ecc required %d " , chip->ecc_strength_ds); return -EINVAL; } |
71253252c MLK-12601: mtd: g... |
1083 1084 |
if ((!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0) && (mtd->oobsize < 1024)) || nand_info->legacy_bch_geometry) { |
71fe512f8 MLK-11719-4: mtd:... |
1085 1086 1087 1088 |
dev_warn(this->dev, "use legacy bch geometry "); return mxs_nand_legacy_calc_ecc_layout(geo, mtd); } |
627544506 mtd: nand: mxs_na... |
1089 |
|
71fe512f8 MLK-11719-4: mtd:... |
1090 1091 |
if (mtd->oobsize > 1024 || chip->ecc_step_ds < mtd->oobsize) return mxs_nand_calc_ecc_for_large_oob(geo, mtd); |
627544506 mtd: nand: mxs_na... |
1092 |
|
71fe512f8 MLK-11719-4: mtd:... |
1093 |
return mxs_nand_calc_ecc_layout_by_info(geo, mtd, |
627544506 mtd: nand: mxs_na... |
1094 |
chip->ecc_strength_ds, chip->ecc_step_ds); |
627544506 mtd: nand: mxs_na... |
1095 1096 1097 |
return 0; } |
0d4e85098 iMX28: Add GPMI N... |
1098 |
/* |
0d4e85098 iMX28: Add GPMI N... |
1099 1100 1101 1102 |
* At this point, the physical NAND Flash chips have been identified and * counted, so we know the physical geometry. This enables us to make some * important configuration decisions. * |
62a3b7dd0 Various, unrelate... |
1103 |
* The return value of this function propagates directly back to this driver's |
5346c31e3 mtd: nand: mxs_na... |
1104 |
* board_nand_init(). Anything other than zero will cause this driver to |
0d4e85098 iMX28: Add GPMI N... |
1105 1106 |
* tear everything down and declare failure. */ |
5346c31e3 mtd: nand: mxs_na... |
1107 |
int mxs_nand_setup_ecc(struct mtd_info *mtd) |
0d4e85098 iMX28: Add GPMI N... |
1108 |
{ |
17cb4b8f3 mtd: nand: Add+us... |
1109 1110 |
struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); |
28897e8d2 mtd: nand: mxs_na... |
1111 |
struct bch_geometry *geo = &nand_info->bch_geometry; |
931747e51 mtd: nand: mxs_na... |
1112 |
struct mxs_bch_regs *bch_regs = nand_info->bch_regs; |
0d4e85098 iMX28: Add GPMI N... |
1113 |
uint32_t tmp; |
627544506 mtd: nand: mxs_na... |
1114 |
int ret; |
984df7add mtd: nand: mxs_na... |
1115 |
|
77ac4a3e3 MLK-22444-2: nand... |
1116 1117 1118 |
nand_info->en_randomizer = 0; nand_info->oobsize = mtd->oobsize; nand_info->writesize = mtd->writesize; |
627544506 mtd: nand: mxs_na... |
1119 |
ret = mxs_nand_set_geometry(mtd, geo); |
984df7add mtd: nand: mxs_na... |
1120 1121 |
if (ret) return ret; |
0d4e85098 iMX28: Add GPMI N... |
1122 |
/* Configure BCH and set NFC geometry */ |
fa7a51cb8 mxs: Convert sys_... |
1123 |
mxs_reset_block(&bch_regs->hw_bch_ctrl_reg); |
0d4e85098 iMX28: Add GPMI N... |
1124 1125 |
/* Configure layout 0 */ |
28897e8d2 mtd: nand: mxs_na... |
1126 |
tmp = (geo->ecc_chunk_count - 1) << BCH_FLASHLAYOUT0_NBLOCKS_OFFSET; |
0d4e85098 iMX28: Add GPMI N... |
1127 |
tmp |= MXS_NAND_METADATA_SIZE << BCH_FLASHLAYOUT0_META_SIZE_OFFSET; |
28897e8d2 mtd: nand: mxs_na... |
1128 |
tmp |= (geo->ecc_strength >> 1) << BCH_FLASHLAYOUT0_ECC0_OFFSET; |
71fe512f8 MLK-11719-4: mtd:... |
1129 |
tmp |= geo->ecc_chunk0_size >> MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT; |
28897e8d2 mtd: nand: mxs_na... |
1130 |
tmp |= (geo->gf_len == 14 ? 1 : 0) << |
63b29d808 mtd: nand: mxs su... |
1131 |
BCH_FLASHLAYOUT0_GF13_0_GF14_1_OFFSET; |
0d4e85098 iMX28: Add GPMI N... |
1132 |
writel(tmp, &bch_regs->hw_bch_flash0layout0); |
77ac4a3e3 MLK-22444-2: nand... |
1133 |
nand_info->bch_flash0layout0 = tmp; |
0d4e85098 iMX28: Add GPMI N... |
1134 1135 1136 |
tmp = (mtd->writesize + mtd->oobsize) << BCH_FLASHLAYOUT1_PAGE_SIZE_OFFSET; |
28897e8d2 mtd: nand: mxs_na... |
1137 |
tmp |= (geo->ecc_strength >> 1) << BCH_FLASHLAYOUT1_ECCN_OFFSET; |
71fe512f8 MLK-11719-4: mtd:... |
1138 |
tmp |= geo->ecc_chunkn_size >> MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT; |
28897e8d2 mtd: nand: mxs_na... |
1139 |
tmp |= (geo->gf_len == 14 ? 1 : 0) << |
63b29d808 mtd: nand: mxs su... |
1140 |
BCH_FLASHLAYOUT1_GF13_0_GF14_1_OFFSET; |
0d4e85098 iMX28: Add GPMI N... |
1141 |
writel(tmp, &bch_regs->hw_bch_flash0layout1); |
77ac4a3e3 MLK-22444-2: nand... |
1142 |
nand_info->bch_flash0layout1 = tmp; |
0d4e85098 iMX28: Add GPMI N... |
1143 |
|
722f0ff0b MLK-12693-2 nand:... |
1144 1145 |
/* Set erase threshold to ecc strength for mx6ul, mx6qp and mx7 */ if (is_mx6dqp() || is_mx7() || |
a9f0815c2 MLK-16034-02: ena... |
1146 |
is_mx6ul() || is_imx8() || is_imx8m()) |
722f0ff0b MLK-12693-2 nand:... |
1147 1148 |
writel(BCH_MODE_ERASE_THRESHOLD(geo->ecc_strength), &bch_regs->hw_bch_mode); |
0d4e85098 iMX28: Add GPMI N... |
1149 1150 1151 1152 1153 1154 1155 |
/* Set *all* chip selects to use layout 0 */ writel(0, &bch_regs->hw_bch_layoutselect); /* Enable BCH complete interrupt */ writel(BCH_CTRL_COMPLETE_IRQ_EN, &bch_regs->hw_bch_ctrl_set); /* Hook some operations at the MTD level. */ |
dfe64e2c8 mtd: resync with ... |
1156 1157 1158 |
if (mtd->_read_oob != mxs_nand_hook_read_oob) { nand_info->hooked_read_oob = mtd->_read_oob; mtd->_read_oob = mxs_nand_hook_read_oob; |
0d4e85098 iMX28: Add GPMI N... |
1159 |
} |
dfe64e2c8 mtd: resync with ... |
1160 1161 1162 |
if (mtd->_write_oob != mxs_nand_hook_write_oob) { nand_info->hooked_write_oob = mtd->_write_oob; mtd->_write_oob = mxs_nand_hook_write_oob; |
0d4e85098 iMX28: Add GPMI N... |
1163 |
} |
dfe64e2c8 mtd: resync with ... |
1164 1165 1166 |
if (mtd->_block_markbad != mxs_nand_hook_block_markbad) { nand_info->hooked_block_markbad = mtd->_block_markbad; mtd->_block_markbad = mxs_nand_hook_block_markbad; |
0d4e85098 iMX28: Add GPMI N... |
1167 |
} |
5346c31e3 mtd: nand: mxs_na... |
1168 |
return 0; |
0d4e85098 iMX28: Add GPMI N... |
1169 1170 1171 1172 1173 1174 1175 1176 1177 |
} /* * Allocate DMA buffers */ int mxs_nand_alloc_buffers(struct mxs_nand_info *nand_info) { uint8_t *buf; const int size = NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE; |
6b9408edd i.MX28: Add cache... |
1178 |
nand_info->data_buf_size = roundup(size, MXS_DMA_ALIGNMENT); |
0d4e85098 iMX28: Add GPMI N... |
1179 |
/* DMA buffers */ |
6b9408edd i.MX28: Add cache... |
1180 |
buf = memalign(MXS_DMA_ALIGNMENT, nand_info->data_buf_size); |
0d4e85098 iMX28: Add GPMI N... |
1181 1182 1183 1184 1185 |
if (!buf) { printf("MXS NAND: Error allocating DMA buffers "); return -ENOMEM; } |
6b9408edd i.MX28: Add cache... |
1186 |
memset(buf, 0, nand_info->data_buf_size); |
0d4e85098 iMX28: Add GPMI N... |
1187 1188 1189 |
nand_info->data_buf = buf; nand_info->oob_buf = buf + NAND_MAX_PAGESIZE; |
0d4e85098 iMX28: Add GPMI N... |
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 |
/* Command buffers */ nand_info->cmd_buf = memalign(MXS_DMA_ALIGNMENT, MXS_NAND_COMMAND_BUFFER_SIZE); if (!nand_info->cmd_buf) { free(buf); printf("MXS NAND: Error allocating command buffers "); return -ENOMEM; } memset(nand_info->cmd_buf, 0, MXS_NAND_COMMAND_BUFFER_SIZE); nand_info->cmd_queue_len = 0; return 0; } /* * Initializes the NFC hardware. */ |
5645df9e0 MTD: NAND: mxs_na... |
1208 |
static int mxs_nand_init_dma(struct mxs_nand_info *info) |
0d4e85098 iMX28: Add GPMI N... |
1209 |
{ |
549d7c0e0 nand: mxs: fix er... |
1210 |
int i = 0, j, ret = 0; |
0d4e85098 iMX28: Add GPMI N... |
1211 |
|
99b54a696 MLK-12483-4 mx6: ... |
1212 1213 1214 1215 1216 1217 1218 |
#ifdef CONFIG_MX6 if (check_module_fused(MX6_MODULE_GPMI)) { printf("NAND GPMI@0x%x is fused, disable it ", (u32)info->gpmi_regs); return -EPERM; } #endif |
0d4e85098 iMX28: Add GPMI N... |
1219 1220 |
info->desc = malloc(sizeof(struct mxs_dma_desc *) * MXS_NAND_DMA_DESCRIPTOR_COUNT); |
549d7c0e0 nand: mxs: fix er... |
1221 1222 |
if (!info->desc) { ret = -ENOMEM; |
0d4e85098 iMX28: Add GPMI N... |
1223 |
goto err1; |
549d7c0e0 nand: mxs: fix er... |
1224 |
} |
0d4e85098 iMX28: Add GPMI N... |
1225 1226 1227 1228 |
/* Allocate the DMA descriptors. */ for (i = 0; i < MXS_NAND_DMA_DESCRIPTOR_COUNT; i++) { info->desc[i] = mxs_dma_desc_alloc(); |
549d7c0e0 nand: mxs: fix er... |
1229 1230 |
if (!info->desc[i]) { ret = -ENOMEM; |
0d4e85098 iMX28: Add GPMI N... |
1231 |
goto err2; |
549d7c0e0 nand: mxs: fix er... |
1232 |
} |
0d4e85098 iMX28: Add GPMI N... |
1233 1234 1235 |
} /* Init the DMA controller. */ |
a1d1fdc92 mx6: soc: Move mx... |
1236 |
mxs_dma_init(); |
96666a39a DMA: Split the AP... |
1237 1238 |
for (j = MXS_DMA_CHANNEL_AHB_APBH_GPMI0; j <= MXS_DMA_CHANNEL_AHB_APBH_GPMI7; j++) { |
549d7c0e0 nand: mxs: fix er... |
1239 1240 |
ret = mxs_dma_init_channel(j); if (ret) |
96666a39a DMA: Split the AP... |
1241 1242 |
goto err3; } |
0d4e85098 iMX28: Add GPMI N... |
1243 1244 |
/* Reset the GPMI block. */ |
931747e51 mtd: nand: mxs_na... |
1245 1246 |
mxs_reset_block(&info->gpmi_regs->hw_gpmi_ctrl0_reg); mxs_reset_block(&info->bch_regs->hw_bch_ctrl_reg); |
0d4e85098 iMX28: Add GPMI N... |
1247 1248 1249 1250 1251 |
/* * Choose NAND mode, set IRQ polarity, disable write protection and * select BCH ECC. */ |
931747e51 mtd: nand: mxs_na... |
1252 |
clrsetbits_le32(&info->gpmi_regs->hw_gpmi_ctrl1, |
0d4e85098 iMX28: Add GPMI N... |
1253 1254 1255 1256 1257 |
GPMI_CTRL1_GPMI_MODE, GPMI_CTRL1_ATA_IRQRDY_POLARITY | GPMI_CTRL1_DEV_RESET | GPMI_CTRL1_BCH_MODE); return 0; |
96666a39a DMA: Split the AP... |
1258 |
err3: |
549d7c0e0 nand: mxs: fix er... |
1259 |
for (--j; j >= MXS_DMA_CHANNEL_AHB_APBH_GPMI0; j--) |
96666a39a DMA: Split the AP... |
1260 |
mxs_dma_release(j); |
0d4e85098 iMX28: Add GPMI N... |
1261 |
err2: |
0d4e85098 iMX28: Add GPMI N... |
1262 1263 |
for (--i; i >= 0; i--) mxs_dma_desc_free(info->desc[i]); |
549d7c0e0 nand: mxs: fix er... |
1264 1265 1266 1267 1268 1269 |
free(info->desc); err1: if (ret == -ENOMEM) printf("MXS NAND: Unable to allocate DMA descriptors "); return ret; |
0d4e85098 iMX28: Add GPMI N... |
1270 |
} |
9345943b2 mtd: nand: mxs_na... |
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 |
int mxs_nand_init_spl(struct nand_chip *nand) { struct mxs_nand_info *nand_info; int err; nand_info = malloc(sizeof(struct mxs_nand_info)); if (!nand_info) { printf("MXS NAND: Failed to allocate private data "); return -ENOMEM; } memset(nand_info, 0, sizeof(struct mxs_nand_info)); |
931747e51 mtd: nand: mxs_na... |
1283 1284 |
nand_info->gpmi_regs = (struct mxs_gpmi_regs *)MXS_GPMI_BASE; nand_info->bch_regs = (struct mxs_bch_regs *)MXS_BCH_BASE; |
5ae585ba3 MTD: mxs_nand: Fi... |
1285 |
|
a9f0815c2 MLK-16034-02: ena... |
1286 |
if (is_mx6sx() || is_mx7() || is_imx8() || is_imx8m()) |
5ae585ba3 MTD: mxs_nand: Fi... |
1287 1288 1289 |
nand_info->max_ecc_strength_supported = 62; else nand_info->max_ecc_strength_supported = 40; |
9345943b2 mtd: nand: mxs_na... |
1290 1291 1292 |
err = mxs_nand_alloc_buffers(nand_info); if (err) return err; |
0d4e9d8be mtd: nand: mxs_na... |
1293 |
err = mxs_nand_init_dma(nand_info); |
9345943b2 mtd: nand: mxs_na... |
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
if (err) return err; nand_set_controller_data(nand, nand_info); nand->options |= NAND_NO_SUBPAGE_WRITE; nand->cmd_ctrl = mxs_nand_cmd_ctrl; nand->dev_ready = mxs_nand_device_ready; nand->select_chip = mxs_nand_select_chip; |
9345943b2 mtd: nand: mxs_na... |
1304 1305 1306 1307 1308 1309 1310 |
nand->read_byte = mxs_nand_read_byte; nand->read_buf = mxs_nand_read_buf; nand->ecc.read_page = mxs_nand_ecc_read_page; nand->ecc.mode = NAND_ECC_HW; |
9345943b2 mtd: nand: mxs_na... |
1311 1312 1313 |
return 0; } |
68748340c mtd: nand: mxs_na... |
1314 |
int mxs_nand_init_ctrl(struct mxs_nand_info *nand_info) |
0d4e85098 iMX28: Add GPMI N... |
1315 |
{ |
5346c31e3 mtd: nand: mxs_na... |
1316 |
struct mtd_info *mtd; |
5346c31e3 mtd: nand: mxs_na... |
1317 |
struct nand_chip *nand; |
0d4e85098 iMX28: Add GPMI N... |
1318 |
int err; |
5346c31e3 mtd: nand: mxs_na... |
1319 1320 |
nand = &nand_info->chip; mtd = nand_to_mtd(nand); |
0d4e85098 iMX28: Add GPMI N... |
1321 1322 |
err = mxs_nand_alloc_buffers(nand_info); if (err) |
3b1328a0a mtd: nand: mxs_na... |
1323 |
return err; |
0d4e85098 iMX28: Add GPMI N... |
1324 |
|
0d4e9d8be mtd: nand: mxs_na... |
1325 |
err = mxs_nand_init_dma(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
1326 |
if (err) |
3b1328a0a mtd: nand: mxs_na... |
1327 |
goto err_free_buffers; |
0d4e85098 iMX28: Add GPMI N... |
1328 1329 |
memset(&fake_ecc_layout, 0, sizeof(fake_ecc_layout)); |
dc0b69fa9 mtd: nand: mxs_na... |
1330 1331 1332 |
#ifdef CONFIG_SYS_NAND_USE_FLASH_BBT nand->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB; #endif |
17cb4b8f3 mtd: nand: Add+us... |
1333 |
nand_set_controller_data(nand, nand_info); |
0d4e85098 iMX28: Add GPMI N... |
1334 |
nand->options |= NAND_NO_SUBPAGE_WRITE; |
f75e83bfa mtd: nand: mxs_na... |
1335 1336 |
if (nand_info->dev) nand->flash_node = dev_of_offset(nand_info->dev); |
0d4e85098 iMX28: Add GPMI N... |
1337 1338 1339 1340 1341 |
nand->cmd_ctrl = mxs_nand_cmd_ctrl; nand->dev_ready = mxs_nand_device_ready; nand->select_chip = mxs_nand_select_chip; nand->block_bad = mxs_nand_block_bad; |
0d4e85098 iMX28: Add GPMI N... |
1342 1343 1344 1345 1346 |
nand->read_byte = mxs_nand_read_byte; nand->read_buf = mxs_nand_read_buf; nand->write_buf = mxs_nand_write_buf; |
5346c31e3 mtd: nand: mxs_na... |
1347 1348 |
/* first scan to find the device and get the page size */ if (nand_scan_ident(mtd, CONFIG_SYS_MAX_NAND_DEVICE, NULL)) |
3b1328a0a mtd: nand: mxs_na... |
1349 |
goto err_free_buffers; |
5346c31e3 mtd: nand: mxs_na... |
1350 1351 |
if (mxs_nand_setup_ecc(mtd)) |
3b1328a0a mtd: nand: mxs_na... |
1352 |
goto err_free_buffers; |
5346c31e3 mtd: nand: mxs_na... |
1353 |
|
0d4e85098 iMX28: Add GPMI N... |
1354 1355 1356 1357 1358 1359 1360 |
nand->ecc.read_page = mxs_nand_ecc_read_page; nand->ecc.write_page = mxs_nand_ecc_write_page; nand->ecc.read_oob = mxs_nand_ecc_read_oob; nand->ecc.write_oob = mxs_nand_ecc_write_oob; nand->ecc.layout = &fake_ecc_layout; nand->ecc.mode = NAND_ECC_HW; |
71fe512f8 MLK-11719-4: mtd:... |
1361 |
nand->ecc.size = nand_info->bch_geometry.ecc_chunkn_size; |
5c69dd073 mtd: nand: mxs_na... |
1362 |
nand->ecc.strength = nand_info->bch_geometry.ecc_strength; |
0d4e85098 iMX28: Add GPMI N... |
1363 |
|
5346c31e3 mtd: nand: mxs_na... |
1364 1365 1366 |
/* second phase scan */ err = nand_scan_tail(mtd); if (err) |
3b1328a0a mtd: nand: mxs_na... |
1367 |
goto err_free_buffers; |
5346c31e3 mtd: nand: mxs_na... |
1368 1369 1370 |
err = nand_register(0, mtd); if (err) |
3b1328a0a mtd: nand: mxs_na... |
1371 |
goto err_free_buffers; |
5346c31e3 mtd: nand: mxs_na... |
1372 |
|
3b1328a0a mtd: nand: mxs_na... |
1373 |
return 0; |
0d4e85098 iMX28: Add GPMI N... |
1374 |
|
3b1328a0a mtd: nand: mxs_na... |
1375 |
err_free_buffers: |
0d4e85098 iMX28: Add GPMI N... |
1376 1377 |
free(nand_info->data_buf); free(nand_info->cmd_buf); |
3b1328a0a mtd: nand: mxs_na... |
1378 1379 1380 |
return err; } |
f75e83bfa mtd: nand: mxs_na... |
1381 |
#ifndef CONFIG_NAND_MXS_DT |
3b1328a0a mtd: nand: mxs_na... |
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 |
void board_nand_init(void) { struct mxs_nand_info *nand_info; nand_info = malloc(sizeof(struct mxs_nand_info)); if (!nand_info) { printf("MXS NAND: Failed to allocate private data "); return; } memset(nand_info, 0, sizeof(struct mxs_nand_info)); nand_info->gpmi_regs = (struct mxs_gpmi_regs *)MXS_GPMI_BASE; nand_info->bch_regs = (struct mxs_bch_regs *)MXS_BCH_BASE; |
502bdc6b4 mtd: nand: mxs_na... |
1396 1397 1398 1399 1400 1401 1402 1403 1404 |
/* Refer to Chapter 17 for i.MX6DQ, Chapter 18 for i.MX6SX */ if (is_mx6sx() || is_mx7()) nand_info->max_ecc_strength_supported = 62; else nand_info->max_ecc_strength_supported = 40; #ifdef CONFIG_NAND_MXS_USE_MINIMUM_ECC nand_info->use_minimum_ecc = true; #endif |
68748340c mtd: nand: mxs_na... |
1405 |
if (mxs_nand_init_ctrl(nand_info) < 0) |
3b1328a0a mtd: nand: mxs_na... |
1406 |
goto err; |
5346c31e3 mtd: nand: mxs_na... |
1407 |
return; |
3b1328a0a mtd: nand: mxs_na... |
1408 1409 1410 |
err: free(nand_info); |
0d4e85098 iMX28: Add GPMI N... |
1411 |
} |
f75e83bfa mtd: nand: mxs_na... |
1412 |
#endif |
77ac4a3e3 MLK-22444-2: nand... |
1413 |
|
14772d11c MLK-22580-1: nand... |
1414 |
#if defined(CONFIG_MX6) || defined(CONFIG_MX7) || defined(CONFIG_IMX8M) |
77ac4a3e3 MLK-22444-2: nand... |
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 |
/* * Read NAND layout for FCB block generation. */ void mxs_nand_get_layout(struct mtd_info *mtd, struct mxs_nand_layout *l) { struct mxs_bch_regs *bch_regs = (struct mxs_bch_regs *)MXS_BCH_BASE; u32 tmp; tmp = readl(&bch_regs->hw_bch_flash0layout0); l->nblocks = (tmp & BCH_FLASHLAYOUT0_NBLOCKS_MASK) >> BCH_FLASHLAYOUT0_NBLOCKS_OFFSET; l->meta_size = (tmp & BCH_FLASHLAYOUT0_META_SIZE_MASK) >> BCH_FLASHLAYOUT0_META_SIZE_OFFSET; tmp = readl(&bch_regs->hw_bch_flash0layout1); l->data0_size = 4 * ((tmp & BCH_FLASHLAYOUT0_DATA0_SIZE_MASK) >> BCH_FLASHLAYOUT0_DATA0_SIZE_OFFSET); l->ecc0 = (tmp & BCH_FLASHLAYOUT0_ECC0_MASK) >> BCH_FLASHLAYOUT0_ECC0_OFFSET; l->datan_size = 4 * ((tmp & BCH_FLASHLAYOUT1_DATAN_SIZE_MASK) >> BCH_FLASHLAYOUT1_DATAN_SIZE_OFFSET); l->eccn = (tmp & BCH_FLASHLAYOUT1_ECCN_MASK) >> BCH_FLASHLAYOUT1_ECCN_OFFSET; |
644f70768 MLK-22723-1: mtd:... |
1438 1439 |
l->gf_len = (tmp & BCH_FLASHLAYOUT1_GF13_0_GF14_1_MASK) >> BCH_FLASHLAYOUT1_GF13_0_GF14_1_OFFSET; |
77ac4a3e3 MLK-22444-2: nand... |
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 |
} /* * Set BCH to specific layout used by ROM bootloader to read FCB. */ void mxs_nand_mode_fcb(struct mtd_info *mtd) { u32 tmp; struct mxs_bch_regs *bch_regs = (struct mxs_bch_regs *)MXS_BCH_BASE; struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); nand_info->en_randomizer = 1; mtd->writesize = 1024; mtd->oobsize = 1862 - 1024; /* 8 ecc_chunks_*/ tmp = 7 << BCH_FLASHLAYOUT0_NBLOCKS_OFFSET; /* 32 bytes for metadata */ tmp |= 32 << BCH_FLASHLAYOUT0_META_SIZE_OFFSET; /* using ECC62 level to be performed */ tmp |= 0x1F << BCH_FLASHLAYOUT0_ECC0_OFFSET; /* 0x20 * 4 bytes of the data0 block */ tmp |= 0x20 << BCH_FLASHLAYOUT0_DATA0_SIZE_OFFSET; tmp |= 0 << BCH_FLASHLAYOUT0_GF13_0_GF14_1_OFFSET; writel(tmp, &bch_regs->hw_bch_flash0layout0); /* 1024 for data + 838 for OOB */ tmp = 1862 << BCH_FLASHLAYOUT1_PAGE_SIZE_OFFSET; /* using ECC62 level to be performed */ tmp |= 0x1F << BCH_FLASHLAYOUT1_ECCN_OFFSET; /* 0x20 * 4 bytes of the data0 block */ tmp |= 0x20 << BCH_FLASHLAYOUT1_DATAN_SIZE_OFFSET; tmp |= 0 << BCH_FLASHLAYOUT1_GF13_0_GF14_1_OFFSET; writel(tmp, &bch_regs->hw_bch_flash0layout1); } /* * Restore BCH to normal settings. */ void mxs_nand_mode_normal(struct mtd_info *mtd) { struct mxs_bch_regs *bch_regs = (struct mxs_bch_regs *)MXS_BCH_BASE; struct nand_chip *nand = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(nand); nand_info->en_randomizer = 0; mtd->writesize = nand_info->writesize; mtd->oobsize = nand_info->oobsize; writel(nand_info->bch_flash0layout0, &bch_regs->hw_bch_flash0layout0); writel(nand_info->bch_flash0layout1, &bch_regs->hw_bch_flash0layout1); } uint32_t mxs_nand_mark_byte_offset(struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); struct bch_geometry *geo = &nand_info->bch_geometry; return geo->block_mark_byte_offset; } uint32_t mxs_nand_mark_bit_offset(struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); struct mxs_nand_info *nand_info = nand_get_controller_data(chip); struct bch_geometry *geo = &nand_info->bch_geometry; return geo->block_mark_bit_offset; } #endif /* CONFIG_IS_ENABLED(MX7) */ |