Lines Matching refs:flctl
114 static void empty_fifo(struct sh_flctl *flctl) in empty_fifo() argument
116 writel(flctl->flintdmacr_base | AC1CLR | AC0CLR, FLINTDMACR(flctl)); in empty_fifo()
117 writel(flctl->flintdmacr_base, FLINTDMACR(flctl)); in empty_fifo()
120 static void start_translation(struct sh_flctl *flctl) in start_translation() argument
122 writeb(TRSTRT, FLTRCR(flctl)); in start_translation()
125 static void timeout_error(struct sh_flctl *flctl, const char *str) in timeout_error() argument
127 dev_err(&flctl->pdev->dev, "Timeout occurred in %s\n", str); in timeout_error()
130 static void wait_completion(struct sh_flctl *flctl) in wait_completion() argument
135 if (readb(FLTRCR(flctl)) & TREND) { in wait_completion()
136 writeb(0x0, FLTRCR(flctl)); in wait_completion()
142 timeout_error(flctl, __func__); in wait_completion()
143 writeb(0x0, FLTRCR(flctl)); in wait_completion()
148 struct sh_flctl *flctl = param; in flctl_dma_complete() local
150 complete(&flctl->dma_complete); in flctl_dma_complete()
153 static void flctl_release_dma(struct sh_flctl *flctl) in flctl_release_dma() argument
155 if (flctl->chan_fifo0_rx) { in flctl_release_dma()
156 dma_release_channel(flctl->chan_fifo0_rx); in flctl_release_dma()
157 flctl->chan_fifo0_rx = NULL; in flctl_release_dma()
159 if (flctl->chan_fifo0_tx) { in flctl_release_dma()
160 dma_release_channel(flctl->chan_fifo0_tx); in flctl_release_dma()
161 flctl->chan_fifo0_tx = NULL; in flctl_release_dma()
165 static void flctl_setup_dma(struct sh_flctl *flctl) in flctl_setup_dma() argument
169 struct platform_device *pdev = flctl->pdev; in flctl_setup_dma()
183 flctl->chan_fifo0_tx = dma_request_channel(mask, shdma_chan_filter, in flctl_setup_dma()
186 flctl->chan_fifo0_tx); in flctl_setup_dma()
188 if (!flctl->chan_fifo0_tx) in flctl_setup_dma()
193 cfg.dst_addr = flctl->fifo; in flctl_setup_dma()
195 ret = dmaengine_slave_config(flctl->chan_fifo0_tx, &cfg); in flctl_setup_dma()
199 flctl->chan_fifo0_rx = dma_request_channel(mask, shdma_chan_filter, in flctl_setup_dma()
202 flctl->chan_fifo0_rx); in flctl_setup_dma()
204 if (!flctl->chan_fifo0_rx) in flctl_setup_dma()
209 cfg.src_addr = flctl->fifo; in flctl_setup_dma()
210 ret = dmaengine_slave_config(flctl->chan_fifo0_rx, &cfg); in flctl_setup_dma()
214 init_completion(&flctl->dma_complete); in flctl_setup_dma()
219 flctl_release_dma(flctl); in flctl_setup_dma()
224 struct sh_flctl *flctl = mtd_to_flctl(mtd); in set_addr() local
231 if (flctl->chip.options & NAND_BUSWIDTH_16) in set_addr()
233 if (flctl->page_size) { in set_addr()
238 if (flctl->rw_ADRCNT == ADRCNT2_E) { in set_addr()
241 writel(addr2, FLADR2(flctl)); in set_addr()
250 writel(addr, FLADR(flctl)); in set_addr()
253 static void wait_rfifo_ready(struct sh_flctl *flctl) in wait_rfifo_ready() argument
260 val = readl(FLDTCNTR(flctl)) >> 16; in wait_rfifo_ready()
265 timeout_error(flctl, __func__); in wait_rfifo_ready()
268 static void wait_wfifo_ready(struct sh_flctl *flctl) in wait_wfifo_ready() argument
274 len = (readl(FLDTCNTR(flctl)) >> 16) & 0xFF; in wait_wfifo_ready()
279 timeout_error(flctl, __func__); in wait_wfifo_ready()
283 (struct sh_flctl *flctl, int sector_number) in wait_recfifo_ready() argument
300 size = readl(FLDTCNTR(flctl)) >> 24; in wait_recfifo_ready()
305 if (!(readl(FL4ECCCR(flctl)) & _4ECCEND)) { in wait_recfifo_ready()
315 if (readl(FL4ECCCR(flctl)) & _4ECCFA) { in wait_recfifo_ready()
318 if (flctl->done_buff[i] != 0xff) { in wait_recfifo_ready()
325 dev_dbg(&flctl->pdev->dev, in wait_recfifo_ready()
329 writel(0, FL4ECCCR(flctl)); in wait_recfifo_ready()
334 ecc_reg[0] = FL4ECCRESULT0(flctl); in wait_recfifo_ready()
335 ecc_reg[1] = FL4ECCRESULT1(flctl); in wait_recfifo_ready()
336 ecc_reg[2] = FL4ECCRESULT2(flctl); in wait_recfifo_ready()
337 ecc_reg[3] = FL4ECCRESULT3(flctl); in wait_recfifo_ready()
345 if (flctl->page_size) in wait_recfifo_ready()
351 org = flctl->done_buff[index]; in wait_recfifo_ready()
352 flctl->done_buff[index] = org ^ (data & 0xFF); in wait_recfifo_ready()
355 writel(0, FL4ECCCR(flctl)); in wait_recfifo_ready()
358 timeout_error(flctl, __func__); in wait_recfifo_ready()
362 static void wait_wecfifo_ready(struct sh_flctl *flctl) in wait_wecfifo_ready() argument
369 len = (readl(FLDTCNTR(flctl)) >> 24) & 0xFF; in wait_wecfifo_ready()
374 timeout_error(flctl, __func__); in wait_wecfifo_ready()
377 static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf, in flctl_dma_fifo0_transfer() argument
390 chan = flctl->chan_fifo0_rx; in flctl_dma_fifo0_transfer()
393 chan = flctl->chan_fifo0_tx; in flctl_dma_fifo0_transfer()
404 reg = readl(FLINTDMACR(flctl)); in flctl_dma_fifo0_transfer()
406 writel(reg, FLINTDMACR(flctl)); in flctl_dma_fifo0_transfer()
409 desc->callback_param = flctl; in flctl_dma_fifo0_transfer()
413 dev_warn(&flctl->pdev->dev, in flctl_dma_fifo0_transfer()
421 flctl_release_dma(flctl); in flctl_dma_fifo0_transfer()
422 dev_warn(&flctl->pdev->dev, in flctl_dma_fifo0_transfer()
429 wait_for_completion_timeout(&flctl->dma_complete, in flctl_dma_fifo0_transfer()
434 dev_err(&flctl->pdev->dev, "wait_for_completion_timeout\n"); in flctl_dma_fifo0_transfer()
439 reg = readl(FLINTDMACR(flctl)); in flctl_dma_fifo0_transfer()
441 writel(reg, FLINTDMACR(flctl)); in flctl_dma_fifo0_transfer()
449 static void read_datareg(struct sh_flctl *flctl, int offset) in read_datareg() argument
452 unsigned long *buf = (unsigned long *)&flctl->done_buff[offset]; in read_datareg()
454 wait_completion(flctl); in read_datareg()
456 data = readl(FLDATAR(flctl)); in read_datareg()
460 static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset) in read_fiforeg() argument
463 unsigned long *buf = (unsigned long *)&flctl->done_buff[offset]; in read_fiforeg()
468 if (flctl->chan_fifo0_rx && rlen >= 32 && in read_fiforeg()
469 !flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_FROM_DEVICE)) in read_fiforeg()
474 wait_rfifo_ready(flctl); in read_fiforeg()
475 buf[i] = readl(FLDTFIFO(flctl)); in read_fiforeg()
484 (struct sh_flctl *flctl, uint8_t *buff, int sector) in read_ecfiforeg() argument
490 res = wait_recfifo_ready(flctl , sector); in read_ecfiforeg()
494 ecc_buf[i] = readl(FLECFIFO(flctl)); in read_ecfiforeg()
502 static void write_fiforeg(struct sh_flctl *flctl, int rlen, in write_fiforeg() argument
506 unsigned long *buf = (unsigned long *)&flctl->done_buff[offset]; in write_fiforeg()
510 wait_wfifo_ready(flctl); in write_fiforeg()
511 writel(cpu_to_be32(buf[i]), FLDTFIFO(flctl)); in write_fiforeg()
515 static void write_ec_fiforeg(struct sh_flctl *flctl, int rlen, in write_ec_fiforeg() argument
519 unsigned long *buf = (unsigned long *)&flctl->done_buff[offset]; in write_ec_fiforeg()
527 if (flctl->chan_fifo0_tx && rlen >= 32 && in write_ec_fiforeg()
528 !flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_TO_DEVICE)) in write_ec_fiforeg()
533 wait_wecfifo_ready(flctl); in write_ec_fiforeg()
534 writel(buf[i], FLECFIFO(flctl)); in write_ec_fiforeg()
540 struct sh_flctl *flctl = mtd_to_flctl(mtd); in set_cmd_regs() local
541 uint32_t flcmncr_val = flctl->flcmncr_base & ~SEL_16BIT; in set_cmd_regs()
545 if (flctl->page_size) in set_cmd_regs()
556 addr_len_bytes = flctl->erase_ADRCNT; in set_cmd_regs()
562 addr_len_bytes = flctl->rw_ADRCNT; in set_cmd_regs()
564 if (flctl->chip.options & NAND_BUSWIDTH_16) in set_cmd_regs()
572 addr_len_bytes = flctl->rw_ADRCNT; in set_cmd_regs()
574 if (flctl->chip.options & NAND_BUSWIDTH_16) in set_cmd_regs()
595 writel(flcmncr_val, FLCMNCR(flctl)); in set_cmd_regs()
596 writel(flcmdcr_val, FLCMDCR(flctl)); in set_cmd_regs()
597 writel(flcmcdr_val, FLCMCDR(flctl)); in set_cmd_regs()
623 struct sh_flctl *flctl = mtd_to_flctl(mtd); in execmd_read_page_sector() local
627 page_sectors = flctl->page_size ? 4 : 1; in execmd_read_page_sector()
632 writel(readl(FLCMNCR(flctl)) | ACM_SACCES_MODE | _4ECCCORRECT, in execmd_read_page_sector()
633 FLCMNCR(flctl)); in execmd_read_page_sector()
634 writel(readl(FLCMDCR(flctl)) | page_sectors, FLCMDCR(flctl)); in execmd_read_page_sector()
635 writel(page_addr << 2, FLADR(flctl)); in execmd_read_page_sector()
637 empty_fifo(flctl); in execmd_read_page_sector()
638 start_translation(flctl); in execmd_read_page_sector()
641 read_fiforeg(flctl, 512, 512 * sector); in execmd_read_page_sector()
643 ecc_result = read_ecfiforeg(flctl, in execmd_read_page_sector()
644 &flctl->done_buff[mtd->writesize + 16 * sector], in execmd_read_page_sector()
649 dev_info(&flctl->pdev->dev, in execmd_read_page_sector()
654 dev_warn(&flctl->pdev->dev, in execmd_read_page_sector()
664 wait_completion(flctl); in execmd_read_page_sector()
666 writel(readl(FLCMNCR(flctl)) & ~(ACM_SACCES_MODE | _4ECCCORRECT), in execmd_read_page_sector()
667 FLCMNCR(flctl)); in execmd_read_page_sector()
672 struct sh_flctl *flctl = mtd_to_flctl(mtd); in execmd_read_oob() local
673 int page_sectors = flctl->page_size ? 4 : 1; in execmd_read_oob()
679 empty_fifo(flctl); in execmd_read_oob()
683 writel(16, FLDTCNTR(flctl)); in execmd_read_oob()
685 start_translation(flctl); in execmd_read_oob()
686 read_fiforeg(flctl, 16, 16 * i); in execmd_read_oob()
687 wait_completion(flctl); in execmd_read_oob()
693 struct sh_flctl *flctl = mtd_to_flctl(mtd); in execmd_write_page_sector() local
694 int page_addr = flctl->seqin_page_addr; in execmd_write_page_sector()
697 page_sectors = flctl->page_size ? 4 : 1; in execmd_write_page_sector()
702 empty_fifo(flctl); in execmd_write_page_sector()
703 writel(readl(FLCMNCR(flctl)) | ACM_SACCES_MODE, FLCMNCR(flctl)); in execmd_write_page_sector()
704 writel(readl(FLCMDCR(flctl)) | page_sectors, FLCMDCR(flctl)); in execmd_write_page_sector()
705 writel(page_addr << 2, FLADR(flctl)); in execmd_write_page_sector()
706 start_translation(flctl); in execmd_write_page_sector()
709 write_fiforeg(flctl, 512, 512 * sector); in execmd_write_page_sector()
710 write_ec_fiforeg(flctl, 16, mtd->writesize + 16 * sector); in execmd_write_page_sector()
713 wait_completion(flctl); in execmd_write_page_sector()
714 writel(readl(FLCMNCR(flctl)) & ~ACM_SACCES_MODE, FLCMNCR(flctl)); in execmd_write_page_sector()
719 struct sh_flctl *flctl = mtd_to_flctl(mtd); in execmd_write_oob() local
720 int page_addr = flctl->seqin_page_addr; in execmd_write_oob()
723 page_sectors = flctl->page_size ? 4 : 1; in execmd_write_oob()
729 empty_fifo(flctl); in execmd_write_oob()
731 writel(16, FLDTCNTR(flctl)); /* set read size */ in execmd_write_oob()
733 start_translation(flctl); in execmd_write_oob()
734 write_fiforeg(flctl, 16, 16 * sector); in execmd_write_oob()
735 wait_completion(flctl); in execmd_write_oob()
743 struct sh_flctl *flctl = mtd_to_flctl(mtd); in flctl_cmdfunc() local
746 pm_runtime_get_sync(&flctl->pdev->dev); in flctl_cmdfunc()
748 flctl->read_bytes = 0; in flctl_cmdfunc()
750 flctl->index = 0; in flctl_cmdfunc()
755 if (flctl->hwecc) { in flctl_cmdfunc()
760 if (flctl->page_size) in flctl_cmdfunc()
768 flctl->read_bytes = mtd->writesize + mtd->oobsize; in flctl_cmdfunc()
769 if (flctl->chip.options & NAND_BUSWIDTH_16) in flctl_cmdfunc()
771 flctl->index += column; in flctl_cmdfunc()
775 if (flctl->hwecc) { in flctl_cmdfunc()
781 if (flctl->page_size) { in flctl_cmdfunc()
789 flctl->read_bytes = mtd->oobsize; in flctl_cmdfunc()
793 if (flctl->hwecc) in flctl_cmdfunc()
796 if (flctl->page_size) in flctl_cmdfunc()
804 flctl->read_bytes = mtd->writesize + mtd->oobsize - column; in flctl_cmdfunc()
811 if (flctl->chip.options & NAND_BUSWIDTH_16) in flctl_cmdfunc()
815 flctl->read_bytes = 8; in flctl_cmdfunc()
816 writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */ in flctl_cmdfunc()
817 empty_fifo(flctl); in flctl_cmdfunc()
818 start_translation(flctl); in flctl_cmdfunc()
819 read_fiforeg(flctl, flctl->read_bytes, 0); in flctl_cmdfunc()
820 wait_completion(flctl); in flctl_cmdfunc()
824 flctl->erase1_page_addr = page_addr; in flctl_cmdfunc()
830 set_addr(mtd, -1, flctl->erase1_page_addr); in flctl_cmdfunc()
831 start_translation(flctl); in flctl_cmdfunc()
832 wait_completion(flctl); in flctl_cmdfunc()
836 if (!flctl->page_size) { in flctl_cmdfunc()
848 flctl->seqin_column = column; in flctl_cmdfunc()
849 flctl->seqin_page_addr = page_addr; in flctl_cmdfunc()
850 flctl->seqin_read_cmd = read_cmd; in flctl_cmdfunc()
854 empty_fifo(flctl); in flctl_cmdfunc()
855 if (!flctl->page_size) { in flctl_cmdfunc()
857 flctl->seqin_read_cmd); in flctl_cmdfunc()
859 writel(0, FLDTCNTR(flctl)); /* set 0 size */ in flctl_cmdfunc()
860 start_translation(flctl); in flctl_cmdfunc()
861 wait_completion(flctl); in flctl_cmdfunc()
863 if (flctl->hwecc) { in flctl_cmdfunc()
865 if (flctl->seqin_column == mtd->writesize) in flctl_cmdfunc()
867 else if (!flctl->seqin_column) in flctl_cmdfunc()
874 set_addr(mtd, flctl->seqin_column, flctl->seqin_page_addr); in flctl_cmdfunc()
875 writel(flctl->index, FLDTCNTR(flctl)); /* set write size */ in flctl_cmdfunc()
876 start_translation(flctl); in flctl_cmdfunc()
877 write_fiforeg(flctl, flctl->index, 0); in flctl_cmdfunc()
878 wait_completion(flctl); in flctl_cmdfunc()
885 flctl->read_bytes = 1; in flctl_cmdfunc()
886 writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */ in flctl_cmdfunc()
887 start_translation(flctl); in flctl_cmdfunc()
888 read_datareg(flctl, 0); /* read and end */ in flctl_cmdfunc()
895 writel(0, FLDTCNTR(flctl)); /* set 0 size */ in flctl_cmdfunc()
896 start_translation(flctl); in flctl_cmdfunc()
897 wait_completion(flctl); in flctl_cmdfunc()
906 writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */ in flctl_cmdfunc()
907 empty_fifo(flctl); in flctl_cmdfunc()
908 start_translation(flctl); in flctl_cmdfunc()
909 read_fiforeg(flctl, flctl->read_bytes, 0); in flctl_cmdfunc()
910 wait_completion(flctl); in flctl_cmdfunc()
912 pm_runtime_put_sync(&flctl->pdev->dev); in flctl_cmdfunc()
918 struct sh_flctl *flctl = mtd_to_flctl(nand_to_mtd(chip)); in flctl_select_chip() local
923 flctl->flcmncr_base &= ~CE0_ENABLE; in flctl_select_chip()
925 pm_runtime_get_sync(&flctl->pdev->dev); in flctl_select_chip()
926 writel(flctl->flcmncr_base, FLCMNCR(flctl)); in flctl_select_chip()
928 if (flctl->qos_request) { in flctl_select_chip()
929 dev_pm_qos_remove_request(&flctl->pm_qos); in flctl_select_chip()
930 flctl->qos_request = 0; in flctl_select_chip()
933 pm_runtime_put_sync(&flctl->pdev->dev); in flctl_select_chip()
936 flctl->flcmncr_base |= CE0_ENABLE; in flctl_select_chip()
938 if (!flctl->qos_request) { in flctl_select_chip()
939 ret = dev_pm_qos_add_request(&flctl->pdev->dev, in flctl_select_chip()
940 &flctl->pm_qos, in flctl_select_chip()
944 dev_err(&flctl->pdev->dev, in flctl_select_chip()
946 flctl->qos_request = 1; in flctl_select_chip()
949 if (flctl->holden) { in flctl_select_chip()
950 pm_runtime_get_sync(&flctl->pdev->dev); in flctl_select_chip()
951 writel(HOLDEN, FLHOLDCR(flctl)); in flctl_select_chip()
952 pm_runtime_put_sync(&flctl->pdev->dev); in flctl_select_chip()
962 struct sh_flctl *flctl = mtd_to_flctl(nand_to_mtd(chip)); in flctl_write_buf() local
964 memcpy(&flctl->done_buff[flctl->index], buf, len); in flctl_write_buf()
965 flctl->index += len; in flctl_write_buf()
970 struct sh_flctl *flctl = mtd_to_flctl(nand_to_mtd(chip)); in flctl_read_byte() local
973 data = flctl->done_buff[flctl->index]; in flctl_read_byte()
974 flctl->index++; in flctl_read_byte()
980 struct sh_flctl *flctl = mtd_to_flctl(nand_to_mtd(chip)); in flctl_read_buf() local
982 memcpy(buf, &flctl->done_buff[flctl->index], len); in flctl_read_buf()
983 flctl->index += len; in flctl_read_buf()
990 struct sh_flctl *flctl = mtd_to_flctl(mtd); in flctl_chip_attach_chip() local
997 flctl->flcmncr_base |= SEL_16BIT; in flctl_chip_attach_chip()
1000 flctl->page_size = 0; in flctl_chip_attach_chip()
1003 flctl->rw_ADRCNT = ADRCNT_4; in flctl_chip_attach_chip()
1004 flctl->erase_ADRCNT = ADRCNT_3; in flctl_chip_attach_chip()
1007 flctl->rw_ADRCNT = ADRCNT_3; in flctl_chip_attach_chip()
1008 flctl->erase_ADRCNT = ADRCNT_2; in flctl_chip_attach_chip()
1010 flctl->rw_ADRCNT = ADRCNT_2; in flctl_chip_attach_chip()
1011 flctl->erase_ADRCNT = ADRCNT_1; in flctl_chip_attach_chip()
1014 flctl->page_size = 1; in flctl_chip_attach_chip()
1017 flctl->rw_ADRCNT = ADRCNT2_E; in flctl_chip_attach_chip()
1018 flctl->erase_ADRCNT = ADRCNT_3; in flctl_chip_attach_chip()
1021 flctl->rw_ADRCNT = ADRCNT_4; in flctl_chip_attach_chip()
1022 flctl->erase_ADRCNT = ADRCNT_2; in flctl_chip_attach_chip()
1024 flctl->rw_ADRCNT = ADRCNT_3; in flctl_chip_attach_chip()
1025 flctl->erase_ADRCNT = ADRCNT_1; in flctl_chip_attach_chip()
1029 if (flctl->hwecc) { in flctl_chip_attach_chip()
1046 flctl->flcmncr_base |= _4ECCEN; in flctl_chip_attach_chip()
1061 struct sh_flctl *flctl = dev_id; in flctl_handle_flste() local
1063 dev_err(&flctl->pdev->dev, "flste irq: %x\n", readl(FLINTDMACR(flctl))); in flctl_handle_flste()
1064 writel(flctl->flintdmacr_base, FLINTDMACR(flctl)); in flctl_handle_flste()
1115 struct sh_flctl *flctl; in flctl_probe() local
1122 flctl = devm_kzalloc(&pdev->dev, sizeof(struct sh_flctl), GFP_KERNEL); in flctl_probe()
1123 if (!flctl) in flctl_probe()
1126 flctl->reg = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in flctl_probe()
1127 if (IS_ERR(flctl->reg)) in flctl_probe()
1128 return PTR_ERR(flctl->reg); in flctl_probe()
1129 flctl->fifo = res->start + 0x24; /* FLDTFIFO */ in flctl_probe()
1136 "flste", flctl); in flctl_probe()
1152 platform_set_drvdata(pdev, flctl); in flctl_probe()
1153 nand = &flctl->chip; in flctl_probe()
1157 flctl->pdev = pdev; in flctl_probe()
1158 flctl->hwecc = pdata->has_hwecc; in flctl_probe()
1159 flctl->holden = pdata->use_holden; in flctl_probe()
1160 flctl->flcmncr_base = pdata->flcmncr_val; in flctl_probe()
1161 flctl->flintdmacr_base = flctl->hwecc ? (STERINTE | ECERB) : STERINTE; in flctl_probe()
1183 flctl_setup_dma(flctl); in flctl_probe()
1199 flctl_release_dma(flctl); in flctl_probe()
1206 struct sh_flctl *flctl = platform_get_drvdata(pdev); in flctl_remove() local
1207 struct nand_chip *chip = &flctl->chip; in flctl_remove()
1210 flctl_release_dma(flctl); in flctl_remove()