Lines Matching refs:host

107 static void __iomem *pmecc_get_alpha_to(struct atmel_nand_host *host)  in pmecc_get_alpha_to()  argument
111 table_size = host->pmecc_sector_size == 512 ? in pmecc_get_alpha_to()
115 return host->pmecc_rom_base + host->pmecc_index_table_offset + in pmecc_get_alpha_to()
119 static void pmecc_data_free(struct atmel_nand_host *host) in pmecc_data_free() argument
121 free(host->pmecc_partial_syn); in pmecc_data_free()
122 free(host->pmecc_si); in pmecc_data_free()
123 free(host->pmecc_lmu); in pmecc_data_free()
124 free(host->pmecc_smu); in pmecc_data_free()
125 free(host->pmecc_mu); in pmecc_data_free()
126 free(host->pmecc_dmu); in pmecc_data_free()
127 free(host->pmecc_delta); in pmecc_data_free()
130 static int pmecc_data_alloc(struct atmel_nand_host *host) in pmecc_data_alloc() argument
132 const int cap = host->pmecc_corr_cap; in pmecc_data_alloc()
136 host->pmecc_partial_syn = malloc(size); in pmecc_data_alloc()
137 host->pmecc_si = malloc(size); in pmecc_data_alloc()
138 host->pmecc_lmu = malloc((cap + 1) * sizeof(int16_t)); in pmecc_data_alloc()
139 host->pmecc_smu = malloc((cap + 2) * size); in pmecc_data_alloc()
142 host->pmecc_mu = malloc(size); in pmecc_data_alloc()
143 host->pmecc_dmu = malloc(size); in pmecc_data_alloc()
144 host->pmecc_delta = malloc(size); in pmecc_data_alloc()
146 if (host->pmecc_partial_syn && in pmecc_data_alloc()
147 host->pmecc_si && in pmecc_data_alloc()
148 host->pmecc_lmu && in pmecc_data_alloc()
149 host->pmecc_smu && in pmecc_data_alloc()
150 host->pmecc_mu && in pmecc_data_alloc()
151 host->pmecc_dmu && in pmecc_data_alloc()
152 host->pmecc_delta) in pmecc_data_alloc()
156 pmecc_data_free(host); in pmecc_data_alloc()
164 struct atmel_nand_host *host = nand_get_controller_data(nand_chip); in pmecc_gen_syndrome() local
169 for (i = 0; i < host->pmecc_corr_cap; i++) { in pmecc_gen_syndrome()
170 value = pmecc_readl(host->pmecc, rem_port[sector].rem[i / 2]); in pmecc_gen_syndrome()
174 host->pmecc_partial_syn[(2 * i) + 1] = (int16_t)value; in pmecc_gen_syndrome()
181 struct atmel_nand_host *host = nand_get_controller_data(nand_chip); in pmecc_substitute() local
182 int16_t __iomem *alpha_to = host->pmecc_alpha_to; in pmecc_substitute()
183 int16_t __iomem *index_of = host->pmecc_index_of; in pmecc_substitute()
184 int16_t *partial_syn = host->pmecc_partial_syn; in pmecc_substitute()
185 const int cap = host->pmecc_corr_cap; in pmecc_substitute()
192 si = host->pmecc_si; in pmecc_substitute()
199 for (j = 0; j < host->pmecc_degree; j++) { in pmecc_substitute()
212 tmp = (tmp * 2) % host->pmecc_cw_len; in pmecc_substitute()
231 struct atmel_nand_host *host = nand_get_controller_data(nand_chip); in pmecc_get_sigma() local
233 int16_t *lmu = host->pmecc_lmu; in pmecc_get_sigma()
234 int16_t *si = host->pmecc_si; in pmecc_get_sigma()
235 int *mu = host->pmecc_mu; in pmecc_get_sigma()
236 int *dmu = host->pmecc_dmu; /* Discrepancy */ in pmecc_get_sigma()
237 int *delta = host->pmecc_delta; /* Delta order */ in pmecc_get_sigma()
238 int cw_len = host->pmecc_cw_len; in pmecc_get_sigma()
239 const int16_t cap = host->pmecc_corr_cap; in pmecc_get_sigma()
241 int16_t __iomem *index_of = host->pmecc_index_of; in pmecc_get_sigma()
242 int16_t __iomem *alpha_to = host->pmecc_alpha_to; in pmecc_get_sigma()
245 int16_t *smu = host->pmecc_smu; in pmecc_get_sigma()
387 struct atmel_nand_host *host = nand_get_controller_data(nand_chip); in pmecc_err_location() local
388 const int cap = host->pmecc_corr_cap; in pmecc_err_location()
390 int sector_size = host->pmecc_sector_size; in pmecc_err_location()
395 int16_t *smu = host->pmecc_smu; in pmecc_err_location()
398 pmecc_writel(host->pmerrloc, eldis, PMERRLOC_DISABLE); in pmecc_err_location()
400 for (i = 0; i <= host->pmecc_lmu[cap + 1] >> 1; i++) { in pmecc_err_location()
401 pmecc_writel(host->pmerrloc, sigma[i], in pmecc_err_location()
410 pmecc_writel(host->pmerrloc, elcfg, val); in pmecc_err_location()
411 pmecc_writel(host->pmerrloc, elen, in pmecc_err_location()
412 sector_size * 8 + host->pmecc_degree * cap); in pmecc_err_location()
415 if (pmecc_readl(host->pmerrloc, elisr) & PMERRLOC_CALC_DONE) in pmecc_err_location()
422 dev_err(host->dev, "atmel_nand : Timeout to calculate PMECC error location\n"); in pmecc_err_location()
426 roots_nbr = (pmecc_readl(host->pmerrloc, elisr) & PMERRLOC_ERR_NUM_MASK) in pmecc_err_location()
429 if (roots_nbr == host->pmecc_lmu[cap + 1] >> 1) in pmecc_err_location()
441 struct atmel_nand_host *host = nand_get_controller_data(nand_chip); in pmecc_correct_data() local
447 sector_size = host->pmecc_sector_size; in pmecc_correct_data()
450 tmp = pmecc_readl(host->pmerrloc, el[i]) - 1; in pmecc_correct_data()
461 pos = sector_num * host->pmecc_sector_size + byte_pos; in pmecc_correct_data()
462 dev_dbg(host->dev, "Bit flip in data area, byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n", in pmecc_correct_data()
466 tmp = sector_num * host->pmecc_bytes_per_sector in pmecc_correct_data()
472 dev_dbg(host->dev, "Bit flip in OOB, oob_byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n", in pmecc_correct_data()
487 struct atmel_nand_host *host = nand_get_controller_data(nand_chip); in pmecc_correction() local
492 if (host->pmecc_version >= PMECC_VERSION_SAMA5D4) in pmecc_correction()
503 for (i = 0; i < host->pmecc_sector_number; i++) { in pmecc_correction()
506 buf_pos = buf + i * host->pmecc_sector_size; in pmecc_correction()
514 dev_err(host->dev, "PMECC: Too many errors\n"); in pmecc_correction()
519 host->pmecc_bytes_per_sector, err_nbr); in pmecc_correction()
532 struct atmel_nand_host *host = nand_get_controller_data(chip); in atmel_nand_pmecc_read_page() local
539 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_RST); in atmel_nand_pmecc_read_page()
540 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_DISABLE); in atmel_nand_pmecc_read_page()
541 pmecc_writel(host->pmecc, cfg, ((pmecc_readl(host->pmecc, cfg)) in atmel_nand_pmecc_read_page()
544 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_ENABLE); in atmel_nand_pmecc_read_page()
545 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_DATA); in atmel_nand_pmecc_read_page()
551 if (!(pmecc_readl(host->pmecc, sr) & PMECC_SR_BUSY)) in atmel_nand_pmecc_read_page()
558 dev_err(host->dev, "atmel_nand : Timeout to read PMECC page\n"); in atmel_nand_pmecc_read_page()
562 stat = pmecc_readl(host->pmecc, isr); in atmel_nand_pmecc_read_page()
574 struct atmel_nand_host *host = nand_get_controller_data(chip); in atmel_nand_pmecc_write_page() local
579 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_RST); in atmel_nand_pmecc_write_page()
580 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_DISABLE); in atmel_nand_pmecc_write_page()
582 pmecc_writel(host->pmecc, cfg, (pmecc_readl(host->pmecc, cfg) | in atmel_nand_pmecc_write_page()
585 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_ENABLE); in atmel_nand_pmecc_write_page()
586 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_DATA); in atmel_nand_pmecc_write_page()
591 if (!(pmecc_readl(host->pmecc, sr) & PMECC_SR_BUSY)) in atmel_nand_pmecc_write_page()
598 dev_err(host->dev, "atmel_nand : Timeout to read PMECC status, fail to write PMECC in oob\n"); in atmel_nand_pmecc_write_page()
602 for (i = 0; i < host->pmecc_sector_number; i++) { in atmel_nand_pmecc_write_page()
603 for (j = 0; j < host->pmecc_bytes_per_sector; j++) { in atmel_nand_pmecc_write_page()
606 pos = i * host->pmecc_bytes_per_sector + j; in atmel_nand_pmecc_write_page()
608 pmecc_readb(host->pmecc, ecc_port[i].ecc[j]); in atmel_nand_pmecc_write_page()
619 struct atmel_nand_host *host = nand_get_controller_data(nand_chip); in atmel_pmecc_core_init() local
623 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_RST); in atmel_pmecc_core_init()
624 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_DISABLE); in atmel_pmecc_core_init()
626 switch (host->pmecc_corr_cap) { in atmel_pmecc_core_init()
647 if (host->pmecc_sector_size == 512) in atmel_pmecc_core_init()
649 else if (host->pmecc_sector_size == 1024) in atmel_pmecc_core_init()
652 switch (host->pmecc_sector_number) { in atmel_pmecc_core_init()
669 pmecc_writel(host->pmecc, cfg, val); in atmel_pmecc_core_init()
672 pmecc_writel(host->pmecc, sarea, mtd->oobsize - 1); in atmel_pmecc_core_init()
673 pmecc_writel(host->pmecc, saddr, ecc_layout->eccpos[0]); in atmel_pmecc_core_init()
674 pmecc_writel(host->pmecc, eaddr, in atmel_pmecc_core_init()
677 pmecc_writel(host->pmecc, clk, PMECC_CLK_133MHZ); in atmel_pmecc_core_init()
678 pmecc_writel(host->pmecc, idr, 0xff); in atmel_pmecc_core_init()
679 pmecc_writel(host->pmecc, ctrl, PMECC_CTRL_ENABLE); in atmel_pmecc_core_init()
696 static int pmecc_choose_ecc(struct atmel_nand_host *host, in pmecc_choose_ecc() argument
711 dev_info(host->dev, "NAND chip is not ONFI compliant, assume ecc_bits is 2 in 512 bytes\n"); in pmecc_choose_ecc()
717 if (host->pmecc_corr_cap == 0) { in pmecc_choose_ecc()
720 host->pmecc_corr_cap = 2; in pmecc_choose_ecc()
722 host->pmecc_corr_cap = 4; in pmecc_choose_ecc()
724 host->pmecc_corr_cap = 8; in pmecc_choose_ecc()
726 host->pmecc_corr_cap = 12; in pmecc_choose_ecc()
728 host->pmecc_corr_cap = 24; in pmecc_choose_ecc()
731 host->pmecc_corr_cap = 32; in pmecc_choose_ecc()
733 host->pmecc_corr_cap = 24; in pmecc_choose_ecc()
736 if (host->pmecc_sector_size == 0) { in pmecc_choose_ecc()
739 host->pmecc_sector_size = 1024; in pmecc_choose_ecc()
741 host->pmecc_sector_size = 512; in pmecc_choose_ecc()
808 struct atmel_nand_host *host; in atmel_pmecc_nand_init_params() local
811 host = &pmecc_host; in atmel_pmecc_nand_init_params()
812 nand_set_controller_data(nand, host); in atmel_pmecc_nand_init_params()
820 host->pmecc_corr_cap = host->pmecc_sector_size = 0; in atmel_pmecc_nand_init_params()
823 host->pmecc_corr_cap = CONFIG_PMECC_CAP; in atmel_pmecc_nand_init_params()
826 host->pmecc_sector_size = CONFIG_PMECC_SECTOR_SIZE; in atmel_pmecc_nand_init_params()
832 if (pmecc_choose_ecc(host, nand, &cap, &sector_size)) { in atmel_pmecc_nand_init_params()
833 dev_err(host->dev, "Required ECC %d bits in %d bytes not supported!\n", in atmel_pmecc_nand_init_params()
838 if (cap > host->pmecc_corr_cap) in atmel_pmecc_nand_init_params()
839 …dev_info(host->dev, "WARNING: Using different ecc correct bits(%d bit) from Nand ONFI ECC reqireme… in atmel_pmecc_nand_init_params()
840 host->pmecc_corr_cap, cap); in atmel_pmecc_nand_init_params()
841 if (sector_size < host->pmecc_sector_size) in atmel_pmecc_nand_init_params()
842 …dev_info(host->dev, "WARNING: Using different ecc correct sector size (%d bytes) from Nand ONFI EC… in atmel_pmecc_nand_init_params()
843 host->pmecc_sector_size, sector_size); in atmel_pmecc_nand_init_params()
845 host->pmecc_corr_cap = CONFIG_PMECC_CAP; in atmel_pmecc_nand_init_params()
846 host->pmecc_sector_size = CONFIG_PMECC_SECTOR_SIZE; in atmel_pmecc_nand_init_params()
849 cap = host->pmecc_corr_cap; in atmel_pmecc_nand_init_params()
850 sector_size = host->pmecc_sector_size; in atmel_pmecc_nand_init_params()
858 host->pmecc_index_table_offset = 0; in atmel_pmecc_nand_init_params()
860 if (host->pmecc_sector_size == 512) in atmel_pmecc_nand_init_params()
861 host->pmecc_index_table_offset = ATMEL_PMECC_INDEX_OFFSET_512; in atmel_pmecc_nand_init_params()
863 host->pmecc_index_table_offset = ATMEL_PMECC_INDEX_OFFSET_1024; in atmel_pmecc_nand_init_params()
869 host->pmecc = (struct pmecc_regs __iomem *) ATMEL_BASE_PMECC; in atmel_pmecc_nand_init_params()
870 host->pmerrloc = (struct pmecc_errloc_regs __iomem *) in atmel_pmecc_nand_init_params()
873 pmecc_galois_table = create_lookup_table(host->pmecc_sector_size); in atmel_pmecc_nand_init_params()
875 dev_err(host->dev, "out of memory\n"); in atmel_pmecc_nand_init_params()
879 host->pmecc_rom_base = (void __iomem *)pmecc_galois_table; in atmel_pmecc_nand_init_params()
881 host->pmecc_rom_base = (void __iomem *) ATMEL_BASE_ROM; in atmel_pmecc_nand_init_params()
892 host->pmecc_degree = (sector_size == 512) ? in atmel_pmecc_nand_init_params()
894 host->pmecc_cw_len = (1 << host->pmecc_degree) - 1; in atmel_pmecc_nand_init_params()
895 host->pmecc_sector_number = mtd->writesize / sector_size; in atmel_pmecc_nand_init_params()
896 host->pmecc_bytes_per_sector = pmecc_get_ecc_bytes( in atmel_pmecc_nand_init_params()
898 host->pmecc_alpha_to = pmecc_get_alpha_to(host); in atmel_pmecc_nand_init_params()
899 host->pmecc_index_of = host->pmecc_rom_base + in atmel_pmecc_nand_init_params()
900 host->pmecc_index_table_offset; in atmel_pmecc_nand_init_params()
903 nand->ecc.bytes = host->pmecc_bytes_per_sector * in atmel_pmecc_nand_init_params()
904 host->pmecc_sector_number; in atmel_pmecc_nand_init_params()
907 dev_err(host->dev, "too large eccpos entries. max support ecc.bytes is %d\n", in atmel_pmecc_nand_init_params()
913 dev_err(host->dev, "No room for ECC bytes\n"); in atmel_pmecc_nand_init_params()
924 dev_err(host->dev, "Unsupported page size for PMECC, use Software ECC\n"); in atmel_pmecc_nand_init_params()
937 if (pmecc_data_alloc(host)) { in atmel_pmecc_nand_init_params()
938 dev_err(host->dev, "Cannot allocate memory for PMECC computation!\n"); in atmel_pmecc_nand_init_params()
948 host->pmecc_version = pmecc_readl(host->pmerrloc, version); in atmel_pmecc_nand_init_params()
949 dev_dbg(host->dev, "PMECC IP version is: %x\n", host->pmecc_version); in atmel_pmecc_nand_init_params()
1112 dev_warn(host->dev, "atmel_nand : multiple errors detected." in atmel_nand_correct()
1122 dev_warn(host->dev, "atmel_nand : one bit error on ECC code." in atmel_nand_correct()
1127 dev_warn(host->dev, "atmel_nand : one bit error on data." in atmel_nand_correct()
1139 dev_warn(host->dev, "atmel_nand : error corrected\n"); in atmel_nand_correct()
1509 dev_err(host->dev, "atmel_nand: Fail to initialize #%d chip", in board_nand_init()