Lines Matching defs:conf

203 static void nand_apply_config(const struct nfc_config *conf)
211 writel(val | NFC_CTL_PAGE_SIZE(conf->page_size),
213 writel(conf->ecc_size, SUNXI_NFC_BASE + NFC_CNT);
214 writel(conf->page_size, SUNXI_NFC_BASE + NFC_SPARE_AREA);
217 static int nand_load_page(const struct nfc_config *conf, u32 offs)
219 int page = offs / conf->page_size;
230 ((conf->addr_cycles - 1) << NFC_ADDR_NUM_OFFSET));
257 static int nand_read_page(const struct nfc_config *conf, u32 offs,
260 int nsectors = len / conf->ecc_size;
262 int oob_chunk_sz = ecc_bytes[conf->ecc_strength];
263 int page = offs / conf->page_size;
267 if (offs % conf->page_size || len % conf->ecc_size ||
268 len > conf->page_size || len < 0)
272 if (conf->randomize)
273 rand_seed = random_seed[page % conf->nseeds];
277 int data_off = i * conf->ecc_size;
278 int oob_off = conf->page_size + (i * oob_chunk_sz);
283 writel((rand_seed << 16) | (conf->ecc_strength << 12) |
284 (conf->randomize ? NFC_ECC_RANDOM_EN : 0) |
285 (conf->ecc_size == 512 ? NFC_ECC_BLOCK_SIZE : 0) |
291 writel(conf->ecc_size, SUNXI_NFC_BASE + NFC_CNT);
317 conf->ecc_size);
323 if (data_off + conf->ecc_size >= len)
330 static int nand_max_ecc_strength(struct nfc_config *conf)
333 int nsectors = conf->page_size / conf->ecc_size;
340 switch (conf->page_size) {
370 static int nand_detect_ecc_config(struct nfc_config *conf, u32 offs,
374 int min_ecc_size = conf->page_size > 4096 ? 1024 : 512;
375 int page = offs / conf->page_size;
382 for (conf->ecc_size = 1024; conf->ecc_size >= min_ecc_size;
383 conf->ecc_size >>= 1) {
384 int max_ecc_strength = nand_max_ecc_strength(conf);
386 nand_apply_config(conf);
393 for (conf->ecc_strength = max_ecc_strength;
394 conf->ecc_strength >= 0;
395 conf->ecc_strength--) {
396 conf->randomize = false;
403 ret = nand_read_page(conf, offs, dest, conf->ecc_size);
414 conf->randomize = true;
415 conf->nseeds = ARRAY_SIZE(random_seed);
420 if (!nand_read_page(conf, offs, dest,
421 conf->ecc_size))
429 while (conf->nseeds >= 16) {
430 int seed = page % conf->nseeds;
432 conf->nseeds >>= 1;
433 if (seed != page % conf->nseeds)
436 } while (conf->nseeds >= 16);
443 static int nand_detect_config(struct nfc_config *conf, u32 offs, void *dest)
445 if (conf->valid)
452 for (conf->addr_cycles = 5;
453 conf->addr_cycles >= 4;
454 conf->addr_cycles--) {
455 int max_page_size = conf->addr_cycles == 4 ? 2048 : 16384;
461 for (conf->page_size = 2048; conf->page_size <= max_page_size;
462 conf->page_size <<= 1) {
463 if (nand_load_page(conf, offs))
466 if (!nand_detect_ecc_config(conf, offs, dest)) {
467 conf->valid = true;
476 static int nand_read_buffer(struct nfc_config *conf, uint32_t offs,
481 size = ALIGN(size, conf->page_size);
482 page = offs / conf->page_size;
483 if (conf->randomize)
484 first_seed = page % conf->nseeds;
486 for (; size; size -= conf->page_size) {
487 if (nand_load_page(conf, offs))
490 ret = nand_read_page(conf, offs, dest, conf->page_size);
496 if (ret < 0 && conf->randomize) {
497 int cur_seed = page % conf->nseeds;
507 conf->nseeds = cur_seed;
513 if (nand_read_page(conf, offs, dest, conf->page_size))
515 } else if (ret && conf->randomize) {
516 memset(dest, 0xff, conf->page_size);
520 offs += conf->page_size;
521 dest += conf->page_size;
527 static struct nfc_config conf;
533 ret = nand_detect_config(&conf, offs, dest);
537 return nand_read_buffer(&conf, offs, size, dest);
542 return conf.page_size;