Lines Matching refs:nfc

285 	struct sunxi_nfc *nfc = dev_id;  in sunxi_nfc_interrupt()  local
286 u32 st = readl(nfc->regs + NFC_REG_ST); in sunxi_nfc_interrupt()
287 u32 ien = readl(nfc->regs + NFC_REG_INT); in sunxi_nfc_interrupt()
293 complete(&nfc->complete); in sunxi_nfc_interrupt()
295 writel(st & NFC_INT_MASK, nfc->regs + NFC_REG_ST); in sunxi_nfc_interrupt()
296 writel(~st & ien & NFC_INT_MASK, nfc->regs + NFC_REG_INT); in sunxi_nfc_interrupt()
301 static int sunxi_nfc_wait_int(struct sunxi_nfc *nfc, u32 flags, in sunxi_nfc_wait_int() argument
304 init_completion(&nfc->complete); in sunxi_nfc_wait_int()
306 writel(flags, nfc->regs + NFC_REG_INT); in sunxi_nfc_wait_int()
311 if (!wait_for_completion_timeout(&nfc->complete, in sunxi_nfc_wait_int()
313 dev_err(nfc->dev, "wait interrupt timedout\n"); in sunxi_nfc_wait_int()
320 static int sunxi_nfc_wait_cmd_fifo_empty(struct sunxi_nfc *nfc) in sunxi_nfc_wait_cmd_fifo_empty() argument
326 if (!(readl(nfc->regs + NFC_REG_ST) & NFC_CMD_FIFO_STATUS)) in sunxi_nfc_wait_cmd_fifo_empty()
330 dev_err(nfc->dev, "wait for empty cmd FIFO timedout\n"); in sunxi_nfc_wait_cmd_fifo_empty()
334 static int sunxi_nfc_rst(struct sunxi_nfc *nfc) in sunxi_nfc_rst() argument
339 writel(0, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_rst()
340 writel(NFC_RESET, nfc->regs + NFC_REG_CTL); in sunxi_nfc_rst()
343 if (!(readl(nfc->regs + NFC_REG_CTL) & NFC_RESET)) in sunxi_nfc_rst()
347 dev_err(nfc->dev, "wait for NAND controller reset timedout\n"); in sunxi_nfc_rst()
355 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_dev_ready() local
367 ret = !!(readl(nfc->regs + NFC_REG_ST) & in sunxi_nfc_dev_ready()
372 sunxi_nfc_wait_int(nfc, NFC_RB_B2R, timeo); in sunxi_nfc_dev_ready()
373 ret = !!(readl(nfc->regs + NFC_REG_ST) & in sunxi_nfc_dev_ready()
382 dev_err(nfc->dev, "cannot check R/B NAND status!\n"); in sunxi_nfc_dev_ready()
393 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_select_chip() local
403 ctl = readl(nfc->regs + NFC_REG_CTL) & in sunxi_nfc_select_chip()
419 writel(mtd->writesize, nfc->regs + NFC_REG_SPARE_AREA); in sunxi_nfc_select_chip()
421 if (nfc->clk_rate != sunxi_nand->clk_rate) { in sunxi_nfc_select_chip()
422 clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); in sunxi_nfc_select_chip()
423 nfc->clk_rate = sunxi_nand->clk_rate; in sunxi_nfc_select_chip()
427 writel(sunxi_nand->timing_ctl, nfc->regs + NFC_REG_TIMING_CTL); in sunxi_nfc_select_chip()
428 writel(sunxi_nand->timing_cfg, nfc->regs + NFC_REG_TIMING_CFG); in sunxi_nfc_select_chip()
429 writel(ctl, nfc->regs + NFC_REG_CTL); in sunxi_nfc_select_chip()
438 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_read_buf() local
447 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_read_buf()
451 writel(cnt, nfc->regs + NFC_REG_CNT); in sunxi_nfc_read_buf()
453 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_read_buf()
455 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_read_buf()
460 memcpy_fromio(buf + offs, nfc->regs + NFC_RAM0_BASE, in sunxi_nfc_read_buf()
471 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_write_buf() local
480 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_write_buf()
484 writel(cnt, nfc->regs + NFC_REG_CNT); in sunxi_nfc_write_buf()
485 memcpy_toio(nfc->regs + NFC_RAM0_BASE, buf + offs, cnt); in sunxi_nfc_write_buf()
488 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_write_buf()
490 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_write_buf()
512 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_cmd_ctrl() local
516 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_cmd_ctrl()
521 tmp = readl(nfc->regs + NFC_REG_CTL); in sunxi_nfc_cmd_ctrl()
526 writel(tmp, nfc->regs + NFC_REG_CTL); in sunxi_nfc_cmd_ctrl()
533 writel(NFC_SEND_CMD1 | dat, nfc->regs + NFC_REG_CMD); in sunxi_nfc_cmd_ctrl()
535 writel(dat, nfc->regs + NFC_REG_ADDR_LOW); in sunxi_nfc_cmd_ctrl()
536 writel(NFC_SEND_ADR, nfc->regs + NFC_REG_CMD); in sunxi_nfc_cmd_ctrl()
539 sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_cmd_ctrl()
545 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_enable() local
549 ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_enable()
554 writel(ecc_ctl, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_enable()
560 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_disable() local
562 writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_ECC_EN, in sunxi_nfc_hw_ecc_disable()
563 nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_disable()
581 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_read_chunk() local
594 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_read_chunk()
599 nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_read_chunk()
601 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_hw_ecc_read_chunk()
605 status = readl(nfc->regs + NFC_REG_ECC_ST); in sunxi_nfc_hw_ecc_read_chunk()
606 ret = NFC_ECC_ERR_CNT(0, readl(nfc->regs + NFC_REG_ECC_ERR_CNT(0))); in sunxi_nfc_hw_ecc_read_chunk()
608 memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); in sunxi_nfc_hw_ecc_read_chunk()
622 sunxi_nfc_user_data_to_buf(readl(nfc->regs + NFC_REG_USER_DATA(0)), in sunxi_nfc_hw_ecc_read_chunk()
669 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_write_chunk() local
680 nfc->regs + NFC_REG_USER_DATA(0)); in sunxi_nfc_hw_ecc_write_chunk()
685 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_write_chunk()
691 nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_write_chunk()
693 ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0); in sunxi_nfc_hw_ecc_write_chunk()
870 struct sunxi_nfc *nfc = to_sunxi_nfc(chip->nand.controller); in sunxi_nand_chip_set_timings() local
938 dev_err(nfc->dev, "unsupported tWB\n"); in sunxi_nand_chip_set_timings()
944 dev_err(nfc->dev, "unsupported tADL\n"); in sunxi_nand_chip_set_timings()
950 dev_err(nfc->dev, "unsupported tWHR\n"); in sunxi_nand_chip_set_timings()
957 dev_err(nfc->dev, "unsupported tRHW\n"); in sunxi_nand_chip_set_timings()
1036 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nand_hw_common_ecc_ctrl_init() local
1054 dev_err(nfc->dev, "unsupported strength\n"); in sunxi_nand_hw_common_ecc_ctrl_init()
1230 static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, in sunxi_nand_chip_init() argument
1279 if (test_and_set_bit(tmp, &nfc->assigned_cs)) { in sunxi_nand_chip_init()
1327 nand->controller = &nfc->controller; in sunxi_nand_chip_init()
1377 list_add_tail(&chip->node, &nfc->chips); in sunxi_nand_chip_init()
1382 static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) in sunxi_nand_chips_init() argument
1395 ret = sunxi_nand_chip_init(dev, nfc, nand_np); in sunxi_nand_chips_init()
1403 static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) in sunxi_nand_chips_cleanup() argument
1407 while (!list_empty(&nfc->chips)) { in sunxi_nand_chips_cleanup()
1408 chip = list_first_entry(&nfc->chips, struct sunxi_nand_chip, in sunxi_nand_chips_cleanup()
1420 struct sunxi_nfc *nfc; in sunxi_nfc_probe() local
1424 nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); in sunxi_nfc_probe()
1425 if (!nfc) in sunxi_nfc_probe()
1428 nfc->dev = dev; in sunxi_nfc_probe()
1429 spin_lock_init(&nfc->controller.lock); in sunxi_nfc_probe()
1430 init_waitqueue_head(&nfc->controller.wq); in sunxi_nfc_probe()
1431 INIT_LIST_HEAD(&nfc->chips); in sunxi_nfc_probe()
1434 nfc->regs = devm_ioremap_resource(dev, r); in sunxi_nfc_probe()
1435 if (IS_ERR(nfc->regs)) in sunxi_nfc_probe()
1436 return PTR_ERR(nfc->regs); in sunxi_nfc_probe()
1444 nfc->ahb_clk = devm_clk_get(dev, "ahb"); in sunxi_nfc_probe()
1445 if (IS_ERR(nfc->ahb_clk)) { in sunxi_nfc_probe()
1447 return PTR_ERR(nfc->ahb_clk); in sunxi_nfc_probe()
1450 ret = clk_prepare_enable(nfc->ahb_clk); in sunxi_nfc_probe()
1454 nfc->mod_clk = devm_clk_get(dev, "mod"); in sunxi_nfc_probe()
1455 if (IS_ERR(nfc->mod_clk)) { in sunxi_nfc_probe()
1457 ret = PTR_ERR(nfc->mod_clk); in sunxi_nfc_probe()
1461 ret = clk_prepare_enable(nfc->mod_clk); in sunxi_nfc_probe()
1465 ret = sunxi_nfc_rst(nfc); in sunxi_nfc_probe()
1469 writel(0, nfc->regs + NFC_REG_INT); in sunxi_nfc_probe()
1471 0, "sunxi-nand", nfc); in sunxi_nfc_probe()
1475 platform_set_drvdata(pdev, nfc); in sunxi_nfc_probe()
1477 ret = sunxi_nand_chips_init(dev, nfc); in sunxi_nfc_probe()
1486 clk_disable_unprepare(nfc->mod_clk); in sunxi_nfc_probe()
1488 clk_disable_unprepare(nfc->ahb_clk); in sunxi_nfc_probe()
1495 struct sunxi_nfc *nfc = platform_get_drvdata(pdev); in sunxi_nfc_remove() local
1497 sunxi_nand_chips_cleanup(nfc); in sunxi_nfc_remove()