Lines Matching refs:conf

200 static void nand_apply_config(const struct nfc_config *conf)  in nand_apply_config()  argument
208 writel(val | NFC_CTL_RAM_METHOD | NFC_CTL_PAGE_SIZE(conf->page_size), in nand_apply_config()
210 writel(conf->ecc_size, SUNXI_NFC_BASE + NFC_CNT); in nand_apply_config()
211 writel(conf->page_size, SUNXI_NFC_BASE + NFC_SPARE_AREA); in nand_apply_config()
214 static int nand_load_page(const struct nfc_config *conf, u32 offs) in nand_load_page() argument
216 int page = offs / conf->page_size; in nand_load_page()
227 ((conf->addr_cycles - 1) << NFC_ADDR_NUM_OFFSET)); in nand_load_page()
254 static int nand_read_page(const struct nfc_config *conf, u32 offs, in nand_read_page() argument
257 int nsectors = len / conf->ecc_size; in nand_read_page()
259 int oob_chunk_sz = ecc_bytes[conf->ecc_strength]; in nand_read_page()
260 int page = offs / conf->page_size; in nand_read_page()
264 if (offs % conf->page_size || len % conf->ecc_size || in nand_read_page()
265 len > conf->page_size || len < 0) in nand_read_page()
269 if (conf->randomize) in nand_read_page()
270 rand_seed = random_seed[page % conf->nseeds]; in nand_read_page()
274 int data_off = i * conf->ecc_size; in nand_read_page()
275 int oob_off = conf->page_size + (i * oob_chunk_sz); in nand_read_page()
280 writel((rand_seed << 16) | (conf->ecc_strength << 12) | in nand_read_page()
281 (conf->randomize ? NFC_ECC_RANDOM_EN : 0) | in nand_read_page()
282 (conf->ecc_size == 512 ? NFC_ECC_BLOCK_SIZE : 0) | in nand_read_page()
288 writel(conf->ecc_size, SUNXI_NFC_BASE + NFC_CNT); in nand_read_page()
314 conf->ecc_size); in nand_read_page()
320 if (data_off + conf->ecc_size >= len) in nand_read_page()
327 static int nand_max_ecc_strength(struct nfc_config *conf) in nand_max_ecc_strength() argument
330 int nsectors = conf->page_size / conf->ecc_size; in nand_max_ecc_strength()
337 switch (conf->page_size) { in nand_max_ecc_strength()
367 static int nand_detect_ecc_config(struct nfc_config *conf, u32 offs, in nand_detect_ecc_config() argument
371 int min_ecc_size = conf->page_size > 4096 ? 1024 : 512; in nand_detect_ecc_config()
372 int page = offs / conf->page_size; in nand_detect_ecc_config()
379 for (conf->ecc_size = 1024; conf->ecc_size >= min_ecc_size; in nand_detect_ecc_config()
380 conf->ecc_size >>= 1) { in nand_detect_ecc_config()
381 int max_ecc_strength = nand_max_ecc_strength(conf); in nand_detect_ecc_config()
383 nand_apply_config(conf); in nand_detect_ecc_config()
390 for (conf->ecc_strength = max_ecc_strength; in nand_detect_ecc_config()
391 conf->ecc_strength >= 0; in nand_detect_ecc_config()
392 conf->ecc_strength--) { in nand_detect_ecc_config()
393 conf->randomize = false; in nand_detect_ecc_config()
400 ret = nand_read_page(conf, offs, dest, conf->ecc_size); in nand_detect_ecc_config()
411 conf->randomize = true; in nand_detect_ecc_config()
412 conf->nseeds = ARRAY_SIZE(random_seed); in nand_detect_ecc_config()
417 if (!nand_read_page(conf, offs, dest, in nand_detect_ecc_config()
418 conf->ecc_size)) in nand_detect_ecc_config()
426 while (conf->nseeds >= 16) { in nand_detect_ecc_config()
427 int seed = page % conf->nseeds; in nand_detect_ecc_config()
429 conf->nseeds >>= 1; in nand_detect_ecc_config()
430 if (seed != page % conf->nseeds) in nand_detect_ecc_config()
433 } while (conf->nseeds >= 16); in nand_detect_ecc_config()
440 static int nand_detect_config(struct nfc_config *conf, u32 offs, void *dest) in nand_detect_config() argument
442 if (conf->valid) in nand_detect_config()
449 for (conf->addr_cycles = 5; in nand_detect_config()
450 conf->addr_cycles >= 4; in nand_detect_config()
451 conf->addr_cycles--) { in nand_detect_config()
452 int max_page_size = conf->addr_cycles == 4 ? 2048 : 16384; in nand_detect_config()
458 for (conf->page_size = 2048; conf->page_size <= max_page_size; in nand_detect_config()
459 conf->page_size <<= 1) { in nand_detect_config()
460 if (nand_load_page(conf, offs)) in nand_detect_config()
463 if (!nand_detect_ecc_config(conf, offs, dest)) { in nand_detect_config()
464 conf->valid = true; in nand_detect_config()
473 static int nand_read_buffer(struct nfc_config *conf, uint32_t offs, in nand_read_buffer() argument
478 size = ALIGN(size, conf->page_size); in nand_read_buffer()
479 page = offs / conf->page_size; in nand_read_buffer()
480 if (conf->randomize) in nand_read_buffer()
481 first_seed = page % conf->nseeds; in nand_read_buffer()
483 for (; size; size -= conf->page_size) { in nand_read_buffer()
484 if (nand_load_page(conf, offs)) in nand_read_buffer()
487 ret = nand_read_page(conf, offs, dest, conf->page_size); in nand_read_buffer()
493 if (ret < 0 && conf->randomize) { in nand_read_buffer()
494 int cur_seed = page % conf->nseeds; in nand_read_buffer()
504 conf->nseeds = cur_seed; in nand_read_buffer()
510 if (nand_read_page(conf, offs, dest, conf->page_size)) in nand_read_buffer()
512 } else if (ret && conf->randomize) { in nand_read_buffer()
513 memset(dest, 0xff, conf->page_size); in nand_read_buffer()
517 offs += conf->page_size; in nand_read_buffer()
518 dest += conf->page_size; in nand_read_buffer()
526 static struct nfc_config conf = { }; in nand_spl_load_image() local
529 ret = nand_detect_config(&conf, offs, dest); in nand_spl_load_image()
533 return nand_read_buffer(&conf, offs, size, dest); in nand_spl_load_image()