Lines Matching refs:conf
201 static void nand_apply_config(const struct nfc_config *conf) in nand_apply_config() argument
209 writel(val | NFC_CTL_RAM_METHOD | NFC_CTL_PAGE_SIZE(conf->page_size), in nand_apply_config()
211 writel(conf->ecc_size, SUNXI_NFC_BASE + NFC_CNT); in nand_apply_config()
212 writel(conf->page_size, SUNXI_NFC_BASE + NFC_SPARE_AREA); in nand_apply_config()
215 static int nand_load_page(const struct nfc_config *conf, u32 offs) in nand_load_page() argument
217 int page = offs / conf->page_size; in nand_load_page()
228 ((conf->addr_cycles - 1) << NFC_ADDR_NUM_OFFSET)); in nand_load_page()
255 static int nand_read_page(const struct nfc_config *conf, u32 offs, in nand_read_page() argument
258 int nsectors = len / conf->ecc_size; in nand_read_page()
260 int oob_chunk_sz = ecc_bytes[conf->ecc_strength]; in nand_read_page()
261 int page = offs / conf->page_size; in nand_read_page()
265 if (offs % conf->page_size || len % conf->ecc_size || in nand_read_page()
266 len > conf->page_size || len < 0) in nand_read_page()
270 if (conf->randomize) in nand_read_page()
271 rand_seed = random_seed[page % conf->nseeds]; in nand_read_page()
275 int data_off = i * conf->ecc_size; in nand_read_page()
276 int oob_off = conf->page_size + (i * oob_chunk_sz); in nand_read_page()
281 writel((rand_seed << 16) | (conf->ecc_strength << 12) | in nand_read_page()
282 (conf->randomize ? NFC_ECC_RANDOM_EN : 0) | in nand_read_page()
283 (conf->ecc_size == 512 ? NFC_ECC_BLOCK_SIZE : 0) | in nand_read_page()
289 writel(conf->ecc_size, SUNXI_NFC_BASE + NFC_CNT); in nand_read_page()
315 conf->ecc_size); in nand_read_page()
321 if (data_off + conf->ecc_size >= len) in nand_read_page()
328 static int nand_max_ecc_strength(struct nfc_config *conf) in nand_max_ecc_strength() argument
331 int nsectors = conf->page_size / conf->ecc_size; in nand_max_ecc_strength()
338 switch (conf->page_size) { in nand_max_ecc_strength()
368 static int nand_detect_ecc_config(struct nfc_config *conf, u32 offs, in nand_detect_ecc_config() argument
372 int min_ecc_size = conf->page_size > 4096 ? 1024 : 512; in nand_detect_ecc_config()
373 int page = offs / conf->page_size; in nand_detect_ecc_config()
380 for (conf->ecc_size = 1024; conf->ecc_size >= min_ecc_size; in nand_detect_ecc_config()
381 conf->ecc_size >>= 1) { in nand_detect_ecc_config()
382 int max_ecc_strength = nand_max_ecc_strength(conf); in nand_detect_ecc_config()
384 nand_apply_config(conf); in nand_detect_ecc_config()
391 for (conf->ecc_strength = max_ecc_strength; in nand_detect_ecc_config()
392 conf->ecc_strength >= 0; in nand_detect_ecc_config()
393 conf->ecc_strength--) { in nand_detect_ecc_config()
394 conf->randomize = false; in nand_detect_ecc_config()
401 ret = nand_read_page(conf, offs, dest, conf->ecc_size); in nand_detect_ecc_config()
412 conf->randomize = true; in nand_detect_ecc_config()
413 conf->nseeds = ARRAY_SIZE(random_seed); in nand_detect_ecc_config()
418 if (!nand_read_page(conf, offs, dest, in nand_detect_ecc_config()
419 conf->ecc_size)) in nand_detect_ecc_config()
427 while (conf->nseeds >= 16) { in nand_detect_ecc_config()
428 int seed = page % conf->nseeds; in nand_detect_ecc_config()
430 conf->nseeds >>= 1; in nand_detect_ecc_config()
431 if (seed != page % conf->nseeds) in nand_detect_ecc_config()
434 } while (conf->nseeds >= 16); in nand_detect_ecc_config()
441 static int nand_detect_config(struct nfc_config *conf, u32 offs, void *dest) in nand_detect_config() argument
443 if (conf->valid) in nand_detect_config()
450 for (conf->addr_cycles = 5; in nand_detect_config()
451 conf->addr_cycles >= 4; in nand_detect_config()
452 conf->addr_cycles--) { in nand_detect_config()
453 int max_page_size = conf->addr_cycles == 4 ? 2048 : 16384; in nand_detect_config()
459 for (conf->page_size = 2048; conf->page_size <= max_page_size; in nand_detect_config()
460 conf->page_size <<= 1) { in nand_detect_config()
461 if (nand_load_page(conf, offs)) in nand_detect_config()
464 if (!nand_detect_ecc_config(conf, offs, dest)) { in nand_detect_config()
465 conf->valid = true; in nand_detect_config()
474 static int nand_read_buffer(struct nfc_config *conf, uint32_t offs, in nand_read_buffer() argument
479 size = ALIGN(size, conf->page_size); in nand_read_buffer()
480 page = offs / conf->page_size; in nand_read_buffer()
481 if (conf->randomize) in nand_read_buffer()
482 first_seed = page % conf->nseeds; in nand_read_buffer()
484 for (; size; size -= conf->page_size) { in nand_read_buffer()
485 if (nand_load_page(conf, offs)) in nand_read_buffer()
488 ret = nand_read_page(conf, offs, dest, conf->page_size); in nand_read_buffer()
494 if (ret < 0 && conf->randomize) { in nand_read_buffer()
495 int cur_seed = page % conf->nseeds; in nand_read_buffer()
505 conf->nseeds = cur_seed; in nand_read_buffer()
511 if (nand_read_page(conf, offs, dest, conf->page_size)) in nand_read_buffer()
513 } else if (ret && conf->randomize) { in nand_read_buffer()
514 memset(dest, 0xff, conf->page_size); in nand_read_buffer()
518 offs += conf->page_size; in nand_read_buffer()
519 dest += conf->page_size; in nand_read_buffer()
527 static struct nfc_config conf = { }; in nand_spl_load_image() local
530 ret = nand_detect_config(&conf, offs, dest); in nand_spl_load_image()
534 return nand_read_buffer(&conf, offs, size, dest); in nand_spl_load_image()