Lines Matching refs:nfc
268 struct sunxi_nfc *nfc = dev_id; in sunxi_nfc_interrupt() local
269 u32 st = readl(nfc->regs + NFC_REG_ST); in sunxi_nfc_interrupt()
270 u32 ien = readl(nfc->regs + NFC_REG_INT); in sunxi_nfc_interrupt()
276 complete(&nfc->complete); in sunxi_nfc_interrupt()
278 writel(st & NFC_INT_MASK, nfc->regs + NFC_REG_ST); in sunxi_nfc_interrupt()
279 writel(~st & ien & NFC_INT_MASK, nfc->regs + NFC_REG_INT); in sunxi_nfc_interrupt()
284 static int sunxi_nfc_wait_int(struct sunxi_nfc *nfc, u32 flags, in sunxi_nfc_wait_int() argument
287 init_completion(&nfc->complete); in sunxi_nfc_wait_int()
289 writel(flags, nfc->regs + NFC_REG_INT); in sunxi_nfc_wait_int()
294 if (!wait_for_completion_timeout(&nfc->complete, in sunxi_nfc_wait_int()
296 dev_err(nfc->dev, "wait interrupt timedout\n"); in sunxi_nfc_wait_int()
303 static int sunxi_nfc_wait_cmd_fifo_empty(struct sunxi_nfc *nfc) in sunxi_nfc_wait_cmd_fifo_empty() argument
309 if (!(readl(nfc->regs + NFC_REG_ST) & NFC_CMD_FIFO_STATUS)) in sunxi_nfc_wait_cmd_fifo_empty()
313 dev_err(nfc->dev, "wait for empty cmd FIFO timedout\n"); in sunxi_nfc_wait_cmd_fifo_empty()
317 static int sunxi_nfc_rst(struct sunxi_nfc *nfc) in sunxi_nfc_rst() argument
322 writel(0, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_rst()
323 writel(NFC_RESET, nfc->regs + NFC_REG_CTL); in sunxi_nfc_rst()
326 if (!(readl(nfc->regs + NFC_REG_CTL) & NFC_RESET)) in sunxi_nfc_rst()
330 dev_err(nfc->dev, "wait for NAND controller reset timedout\n"); in sunxi_nfc_rst()
338 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_dev_ready() local
350 ret = !!(readl(nfc->regs + NFC_REG_ST) & in sunxi_nfc_dev_ready()
355 sunxi_nfc_wait_int(nfc, NFC_RB_B2R, timeo); in sunxi_nfc_dev_ready()
356 ret = !!(readl(nfc->regs + NFC_REG_ST) & in sunxi_nfc_dev_ready()
365 dev_err(nfc->dev, "cannot check R/B NAND status!\n"); in sunxi_nfc_dev_ready()
376 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_select_chip() local
386 ctl = readl(nfc->regs + NFC_REG_CTL) & in sunxi_nfc_select_chip()
402 writel(mtd->writesize, nfc->regs + NFC_REG_SPARE_AREA); in sunxi_nfc_select_chip()
404 if (nfc->clk_rate != sunxi_nand->clk_rate) { in sunxi_nfc_select_chip()
405 clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); in sunxi_nfc_select_chip()
406 nfc->clk_rate = sunxi_nand->clk_rate; in sunxi_nfc_select_chip()
410 writel(ctl, nfc->regs + NFC_REG_CTL); in sunxi_nfc_select_chip()
419 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_read_buf() local
428 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_read_buf()
432 writel(cnt, nfc->regs + NFC_REG_CNT); in sunxi_nfc_read_buf()
434 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_read_buf()
436 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_read_buf()
441 memcpy_fromio(buf + offs, nfc->regs + NFC_RAM0_BASE, in sunxi_nfc_read_buf()
452 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_write_buf() local
461 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_write_buf()
465 writel(cnt, nfc->regs + NFC_REG_CNT); in sunxi_nfc_write_buf()
466 memcpy_toio(nfc->regs + NFC_RAM0_BASE, buf + offs, cnt); in sunxi_nfc_write_buf()
469 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_write_buf()
471 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_write_buf()
493 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_cmd_ctrl() local
497 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_cmd_ctrl()
502 tmp = readl(nfc->regs + NFC_REG_CTL); in sunxi_nfc_cmd_ctrl()
507 writel(tmp, nfc->regs + NFC_REG_CTL); in sunxi_nfc_cmd_ctrl()
514 writel(NFC_SEND_CMD1 | dat, nfc->regs + NFC_REG_CMD); in sunxi_nfc_cmd_ctrl()
516 writel(dat, nfc->regs + NFC_REG_ADDR_LOW); in sunxi_nfc_cmd_ctrl()
517 writel(NFC_SEND_ADR, nfc->regs + NFC_REG_CMD); in sunxi_nfc_cmd_ctrl()
520 sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_cmd_ctrl()
527 struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller); in sunxi_nfc_hw_ecc_read_page() local
538 tmp = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_read_page()
543 writel(tmp, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_read_page()
555 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_read_page()
560 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_read_page()
562 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_hw_ecc_read_page()
567 nfc->regs + NFC_RAM0_BASE, ecc->size); in sunxi_nfc_hw_ecc_read_page()
569 if (readl(nfc->regs + NFC_REG_ECC_ST) & 0x1) { in sunxi_nfc_hw_ecc_read_page()
572 tmp = readl(nfc->regs + NFC_REG_ECC_CNT0) & 0xff; in sunxi_nfc_hw_ecc_read_page()
580 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_read_page()
601 tmp = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_read_page()
604 writel(tmp, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_read_page()
613 struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller); in sunxi_nfc_hw_ecc_write_page() local
623 tmp = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_write_page()
628 writel(tmp, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_write_page()
641 nfc->regs + NFC_REG_USER_DATA_BASE); in sunxi_nfc_hw_ecc_write_page()
645 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_write_page()
651 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_write_page()
652 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_hw_ecc_write_page()
668 tmp = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_write_page()
671 writel(tmp, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_write_page()
681 struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller); in sunxi_nfc_hw_syndrome_ecc_read_page() local
692 tmp = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_syndrome_ecc_read_page()
697 writel(tmp, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_syndrome_ecc_read_page()
703 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_syndrome_ecc_read_page()
705 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_hw_syndrome_ecc_read_page()
709 memcpy_fromio(buf, nfc->regs + NFC_RAM0_BASE, ecc->size); in sunxi_nfc_hw_syndrome_ecc_read_page()
713 if (readl(nfc->regs + NFC_REG_ECC_ST) & 0x1) { in sunxi_nfc_hw_syndrome_ecc_read_page()
716 tmp = readl(nfc->regs + NFC_REG_ECC_CNT0) & 0xff; in sunxi_nfc_hw_syndrome_ecc_read_page()
738 writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_ECC_EN, in sunxi_nfc_hw_syndrome_ecc_read_page()
739 nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_syndrome_ecc_read_page()
749 struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller); in sunxi_nfc_hw_syndrome_ecc_write_page() local
759 tmp = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_syndrome_ecc_write_page()
764 writel(tmp, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_syndrome_ecc_write_page()
772 nfc->regs + NFC_REG_USER_DATA_BASE); in sunxi_nfc_hw_syndrome_ecc_write_page()
776 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_syndrome_ecc_write_page()
778 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_hw_syndrome_ecc_write_page()
794 tmp = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_syndrome_ecc_write_page()
797 writel(tmp, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_syndrome_ecc_write_page()
923 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nand_hw_common_ecc_ctrl_init() local
941 dev_err(nfc->dev, "unsupported strength\n"); in sunxi_nand_hw_common_ecc_ctrl_init()
1130 static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, in sunxi_nand_chip_init() argument
1179 if (test_and_set_bit(tmp, &nfc->assigned_cs)) { in sunxi_nand_chip_init()
1227 nand->controller = &nfc->controller; in sunxi_nand_chip_init()
1272 list_add_tail(&chip->node, &nfc->chips); in sunxi_nand_chip_init()
1277 static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) in sunxi_nand_chips_init() argument
1290 ret = sunxi_nand_chip_init(dev, nfc, nand_np); in sunxi_nand_chips_init()
1298 static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) in sunxi_nand_chips_cleanup() argument
1302 while (!list_empty(&nfc->chips)) { in sunxi_nand_chips_cleanup()
1303 chip = list_first_entry(&nfc->chips, struct sunxi_nand_chip, in sunxi_nand_chips_cleanup()
1315 struct sunxi_nfc *nfc; in sunxi_nfc_probe() local
1319 nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); in sunxi_nfc_probe()
1320 if (!nfc) in sunxi_nfc_probe()
1323 nfc->dev = dev; in sunxi_nfc_probe()
1324 spin_lock_init(&nfc->controller.lock); in sunxi_nfc_probe()
1325 init_waitqueue_head(&nfc->controller.wq); in sunxi_nfc_probe()
1326 INIT_LIST_HEAD(&nfc->chips); in sunxi_nfc_probe()
1329 nfc->regs = devm_ioremap_resource(dev, r); in sunxi_nfc_probe()
1330 if (IS_ERR(nfc->regs)) in sunxi_nfc_probe()
1331 return PTR_ERR(nfc->regs); in sunxi_nfc_probe()
1339 nfc->ahb_clk = devm_clk_get(dev, "ahb"); in sunxi_nfc_probe()
1340 if (IS_ERR(nfc->ahb_clk)) { in sunxi_nfc_probe()
1342 return PTR_ERR(nfc->ahb_clk); in sunxi_nfc_probe()
1345 ret = clk_prepare_enable(nfc->ahb_clk); in sunxi_nfc_probe()
1349 nfc->mod_clk = devm_clk_get(dev, "mod"); in sunxi_nfc_probe()
1350 if (IS_ERR(nfc->mod_clk)) { in sunxi_nfc_probe()
1352 ret = PTR_ERR(nfc->mod_clk); in sunxi_nfc_probe()
1356 ret = clk_prepare_enable(nfc->mod_clk); in sunxi_nfc_probe()
1360 ret = sunxi_nfc_rst(nfc); in sunxi_nfc_probe()
1364 writel(0, nfc->regs + NFC_REG_INT); in sunxi_nfc_probe()
1366 0, "sunxi-nand", nfc); in sunxi_nfc_probe()
1370 platform_set_drvdata(pdev, nfc); in sunxi_nfc_probe()
1376 writel(0x100, nfc->regs + NFC_REG_TIMING_CTL); in sunxi_nfc_probe()
1377 writel(0x7ff, nfc->regs + NFC_REG_TIMING_CFG); in sunxi_nfc_probe()
1379 ret = sunxi_nand_chips_init(dev, nfc); in sunxi_nfc_probe()
1388 clk_disable_unprepare(nfc->mod_clk); in sunxi_nfc_probe()
1390 clk_disable_unprepare(nfc->ahb_clk); in sunxi_nfc_probe()
1397 struct sunxi_nfc *nfc = platform_get_drvdata(pdev); in sunxi_nfc_remove() local
1399 sunxi_nand_chips_cleanup(nfc); in sunxi_nfc_remove()