Lines Matching full:f

369 static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr)  in fspi_writel()  argument
371 if (f->devtype_data->little_endian) in fspi_writel()
377 static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr) in fspi_readl() argument
379 if (f->devtype_data->little_endian) in fspi_readl()
387 struct nxp_fspi *f = dev_id; in nxp_fspi_irq_handler() local
391 reg = fspi_readl(f, f->iobase + FSPI_INTR); in nxp_fspi_irq_handler()
392 fspi_writel(f, FSPI_INTR_IPCMDDONE, f->iobase + FSPI_INTR); in nxp_fspi_irq_handler()
395 complete(&f->c); in nxp_fspi_irq_handler()
400 static int nxp_fspi_check_buswidth(struct nxp_fspi *f, u8 width) in nxp_fspi_check_buswidth() argument
416 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_supports_op() local
419 ret = nxp_fspi_check_buswidth(f, op->cmd.buswidth); in nxp_fspi_supports_op()
422 ret |= nxp_fspi_check_buswidth(f, op->addr.buswidth); in nxp_fspi_supports_op()
425 ret |= nxp_fspi_check_buswidth(f, op->dummy.buswidth); in nxp_fspi_supports_op()
428 ret |= nxp_fspi_check_buswidth(f, op->data.buswidth); in nxp_fspi_supports_op()
444 if (op->addr.val >= f->memmap_phy_size) in nxp_fspi_supports_op()
454 (op->data.nbytes > f->devtype_data->ahb_buf_size || in nxp_fspi_supports_op()
455 (op->data.nbytes > f->devtype_data->rxfifo - 4 && in nxp_fspi_supports_op()
460 op->data.nbytes > f->devtype_data->txfifo) in nxp_fspi_supports_op()
467 static int fspi_readl_poll_tout(struct nxp_fspi *f, void __iomem *base, in fspi_readl_poll_tout() argument
473 if (!f->devtype_data->little_endian) in fspi_readl_poll_tout()
489 static inline void nxp_fspi_invalid(struct nxp_fspi *f) in nxp_fspi_invalid() argument
494 reg = fspi_readl(f, f->iobase + FSPI_MCR0); in nxp_fspi_invalid()
495 fspi_writel(f, reg | FSPI_MCR0_SWRST, f->iobase + FSPI_MCR0); in nxp_fspi_invalid()
498 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, in nxp_fspi_invalid()
503 static void nxp_fspi_prepare_lut(struct nxp_fspi *f, in nxp_fspi_prepare_lut() argument
506 void __iomem *base = f->iobase; in nxp_fspi_prepare_lut()
549 fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); in nxp_fspi_prepare_lut()
550 fspi_writel(f, FSPI_LCKER_UNLOCK, f->iobase + FSPI_LCKCR); in nxp_fspi_prepare_lut()
554 fspi_writel(f, lutval[i], base + FSPI_LUT_REG(i)); in nxp_fspi_prepare_lut()
556 dev_dbg(f->dev, "CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x]\n", in nxp_fspi_prepare_lut()
560 fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); in nxp_fspi_prepare_lut()
561 fspi_writel(f, FSPI_LCKER_LOCK, f->iobase + FSPI_LCKCR); in nxp_fspi_prepare_lut()
564 static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f) in nxp_fspi_clk_prep_enable() argument
568 if (is_acpi_node(f->dev->fwnode)) in nxp_fspi_clk_prep_enable()
571 ret = clk_prepare_enable(f->clk_en); in nxp_fspi_clk_prep_enable()
575 ret = clk_prepare_enable(f->clk); in nxp_fspi_clk_prep_enable()
577 clk_disable_unprepare(f->clk_en); in nxp_fspi_clk_prep_enable()
584 static int nxp_fspi_clk_disable_unprep(struct nxp_fspi *f) in nxp_fspi_clk_disable_unprep() argument
586 if (is_acpi_node(f->dev->fwnode)) in nxp_fspi_clk_disable_unprep()
589 clk_disable_unprepare(f->clk); in nxp_fspi_clk_disable_unprep()
590 clk_disable_unprepare(f->clk_en); in nxp_fspi_clk_disable_unprep()
633 static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi) in nxp_fspi_select_mem() argument
643 if (f->selected == spi->chip_select) in nxp_fspi_select_mem()
647 fspi_writel(f, 0, f->iobase + FSPI_FLSHA1CR0); in nxp_fspi_select_mem()
648 fspi_writel(f, 0, f->iobase + FSPI_FLSHA2CR0); in nxp_fspi_select_mem()
649 fspi_writel(f, 0, f->iobase + FSPI_FLSHB1CR0); in nxp_fspi_select_mem()
650 fspi_writel(f, 0, f->iobase + FSPI_FLSHB2CR0); in nxp_fspi_select_mem()
653 size_kb = FSPI_FLSHXCR0_SZ(f->memmap_phy_size); in nxp_fspi_select_mem()
655 fspi_writel(f, size_kb, f->iobase + FSPI_FLSHA1CR0 + in nxp_fspi_select_mem()
658 dev_dbg(f->dev, "Slave device [CS:%x] selected\n", spi->chip_select); in nxp_fspi_select_mem()
660 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_select_mem()
662 ret = clk_set_rate(f->clk, rate); in nxp_fspi_select_mem()
666 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_select_mem()
670 f->selected = spi->chip_select; in nxp_fspi_select_mem()
673 static int nxp_fspi_read_ahb(struct nxp_fspi *f, const struct spi_mem_op *op) in nxp_fspi_read_ahb() argument
679 if ((!f->ahb_addr) || start < f->memmap_start || in nxp_fspi_read_ahb()
680 start + len > f->memmap_start + f->memmap_len) { in nxp_fspi_read_ahb()
681 if (f->ahb_addr) in nxp_fspi_read_ahb()
682 iounmap(f->ahb_addr); in nxp_fspi_read_ahb()
684 f->memmap_start = start; in nxp_fspi_read_ahb()
685 f->memmap_len = len > NXP_FSPI_MIN_IOMAP ? in nxp_fspi_read_ahb()
688 f->ahb_addr = ioremap_wc(f->memmap_phy + f->memmap_start, in nxp_fspi_read_ahb()
689 f->memmap_len); in nxp_fspi_read_ahb()
691 if (!f->ahb_addr) { in nxp_fspi_read_ahb()
692 dev_err(f->dev, "failed to alloc memory\n"); in nxp_fspi_read_ahb()
699 f->ahb_addr + start - f->memmap_start, len); in nxp_fspi_read_ahb()
704 static void nxp_fspi_fill_txfifo(struct nxp_fspi *f, in nxp_fspi_fill_txfifo() argument
707 void __iomem *base = f->iobase; in nxp_fspi_fill_txfifo()
712 fspi_writel(f, FSPI_IPTXFCR_CLR, base + FSPI_IPTXFCR); in nxp_fspi_fill_txfifo()
721 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
726 fspi_writel(f, *(u32 *) (buf + i), base + FSPI_TFDR); in nxp_fspi_fill_txfifo()
727 fspi_writel(f, *(u32 *) (buf + i + 4), base + FSPI_TFDR + 4); in nxp_fspi_fill_txfifo()
728 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
735 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
742 fspi_writel(f, data, base + FSPI_TFDR + j); in nxp_fspi_fill_txfifo()
744 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
748 static void nxp_fspi_read_rxfifo(struct nxp_fspi *f, in nxp_fspi_read_rxfifo() argument
751 void __iomem *base = f->iobase; in nxp_fspi_read_rxfifo()
762 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
767 *(u32 *)(buf + i) = fspi_readl(f, base + FSPI_RFDR); in nxp_fspi_read_rxfifo()
768 *(u32 *)(buf + i + 4) = fspi_readl(f, base + FSPI_RFDR + 4); in nxp_fspi_read_rxfifo()
770 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
779 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
786 tmp = fspi_readl(f, base + FSPI_RFDR + j); in nxp_fspi_read_rxfifo()
794 fspi_writel(f, FSPI_IPRXFCR_CLR, base + FSPI_IPRXFCR); in nxp_fspi_read_rxfifo()
796 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
799 static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op) in nxp_fspi_do_op() argument
801 void __iomem *base = f->iobase; in nxp_fspi_do_op()
806 reg = fspi_readl(f, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
810 fspi_writel(f, reg, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
812 init_completion(&f->c); in nxp_fspi_do_op()
814 fspi_writel(f, op->addr.val, base + FSPI_IPCR0); in nxp_fspi_do_op()
820 fspi_writel(f, op->data.nbytes | in nxp_fspi_do_op()
826 fspi_writel(f, FSPI_IPCMD_TRG, base + FSPI_IPCMD); in nxp_fspi_do_op()
829 if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000))) in nxp_fspi_do_op()
834 nxp_fspi_read_rxfifo(f, op); in nxp_fspi_do_op()
841 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_exec_op() local
844 mutex_lock(&f->lock); in nxp_fspi_exec_op()
847 err = fspi_readl_poll_tout(f, f->iobase + FSPI_STS0, in nxp_fspi_exec_op()
851 nxp_fspi_select_mem(f, mem->spi); in nxp_fspi_exec_op()
853 nxp_fspi_prepare_lut(f, op); in nxp_fspi_exec_op()
859 if (op->data.nbytes > (f->devtype_data->rxfifo - 4) && in nxp_fspi_exec_op()
861 err = nxp_fspi_read_ahb(f, op); in nxp_fspi_exec_op()
864 nxp_fspi_fill_txfifo(f, op); in nxp_fspi_exec_op()
866 err = nxp_fspi_do_op(f, op); in nxp_fspi_exec_op()
870 nxp_fspi_invalid(f); in nxp_fspi_exec_op()
872 mutex_unlock(&f->lock); in nxp_fspi_exec_op()
879 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_adjust_op_size() local
882 if (op->data.nbytes > f->devtype_data->txfifo) in nxp_fspi_adjust_op_size()
883 op->data.nbytes = f->devtype_data->txfifo; in nxp_fspi_adjust_op_size()
885 if (op->data.nbytes > f->devtype_data->ahb_buf_size) in nxp_fspi_adjust_op_size()
886 op->data.nbytes = f->devtype_data->ahb_buf_size; in nxp_fspi_adjust_op_size()
887 else if (op->data.nbytes > (f->devtype_data->rxfifo - 4)) in nxp_fspi_adjust_op_size()
894 static int nxp_fspi_default_setup(struct nxp_fspi *f) in nxp_fspi_default_setup() argument
896 void __iomem *base = f->iobase; in nxp_fspi_default_setup()
901 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_default_setup()
904 ret = clk_set_rate(f->clk, 20000000); in nxp_fspi_default_setup()
908 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_default_setup()
914 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, in nxp_fspi_default_setup()
919 fspi_writel(f, FSPI_MCR0_MDIS, base + FSPI_MCR0); in nxp_fspi_default_setup()
922 fspi_writel(f, FSPI_DLLACR_OVRDEN, base + FSPI_DLLACR); in nxp_fspi_default_setup()
923 fspi_writel(f, FSPI_DLLBCR_OVRDEN, base + FSPI_DLLBCR); in nxp_fspi_default_setup()
926 fspi_writel(f, FSPI_MCR0_AHB_TIMEOUT(0xFF) | in nxp_fspi_default_setup()
934 reg = fspi_readl(f, f->iobase + FSPI_MCR2); in nxp_fspi_default_setup()
936 fspi_writel(f, reg, base + FSPI_MCR2); in nxp_fspi_default_setup()
940 fspi_writel(f, 0, base + FSPI_AHBRX_BUF0CR0 + 4 * i); in nxp_fspi_default_setup()
946 fspi_writel(f, (f->devtype_data->ahb_buf_size / 8 | in nxp_fspi_default_setup()
950 fspi_writel(f, FSPI_AHBCR_PREF_EN | FSPI_AHBCR_RDADDROPT, in nxp_fspi_default_setup()
954 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA1CR2); in nxp_fspi_default_setup()
955 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA2CR2); in nxp_fspi_default_setup()
956 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB1CR2); in nxp_fspi_default_setup()
957 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB2CR2); in nxp_fspi_default_setup()
959 f->selected = -1; in nxp_fspi_default_setup()
962 fspi_writel(f, FSPI_INTEN_IPCMDDONE, base + FSPI_INTEN); in nxp_fspi_default_setup()
969 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_get_name() local
974 if (of_get_available_child_count(f->dev->of_node) == 1) in nxp_fspi_get_name()
975 return dev_name(f->dev); in nxp_fspi_get_name()
978 "%s-%d", dev_name(f->dev), in nxp_fspi_get_name()
1002 struct nxp_fspi *f; in nxp_fspi_probe() local
1006 ctlr = spi_alloc_master(&pdev->dev, sizeof(*f)); in nxp_fspi_probe()
1013 f = spi_controller_get_devdata(ctlr); in nxp_fspi_probe()
1014 f->dev = dev; in nxp_fspi_probe()
1015 f->devtype_data = device_get_match_data(dev); in nxp_fspi_probe()
1016 if (!f->devtype_data) { in nxp_fspi_probe()
1021 platform_set_drvdata(pdev, f); in nxp_fspi_probe()
1024 if (is_acpi_node(f->dev->fwnode)) in nxp_fspi_probe()
1030 f->iobase = devm_ioremap_resource(dev, res); in nxp_fspi_probe()
1031 if (IS_ERR(f->iobase)) { in nxp_fspi_probe()
1032 ret = PTR_ERR(f->iobase); in nxp_fspi_probe()
1037 reg = fspi_readl(f, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1039 fspi_writel(f, reg, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1043 if (is_acpi_node(f->dev->fwnode)) in nxp_fspi_probe()
1055 f->memmap_phy = res->start; in nxp_fspi_probe()
1056 f->memmap_phy_size = resource_size(res); in nxp_fspi_probe()
1060 f->clk_en = devm_clk_get(dev, "fspi_en"); in nxp_fspi_probe()
1061 if (IS_ERR(f->clk_en)) { in nxp_fspi_probe()
1062 ret = PTR_ERR(f->clk_en); in nxp_fspi_probe()
1066 f->clk = devm_clk_get(dev, "fspi"); in nxp_fspi_probe()
1067 if (IS_ERR(f->clk)) { in nxp_fspi_probe()
1068 ret = PTR_ERR(f->clk); in nxp_fspi_probe()
1072 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_probe()
1085 nxp_fspi_irq_handler, 0, pdev->name, f); in nxp_fspi_probe()
1091 mutex_init(&f->lock); in nxp_fspi_probe()
1097 nxp_fspi_default_setup(f); in nxp_fspi_probe()
1108 mutex_destroy(&f->lock); in nxp_fspi_probe()
1111 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_probe()
1122 struct nxp_fspi *f = platform_get_drvdata(pdev); in nxp_fspi_remove() local
1125 fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); in nxp_fspi_remove()
1127 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_remove()
1129 mutex_destroy(&f->lock); in nxp_fspi_remove()
1131 if (f->ahb_addr) in nxp_fspi_remove()
1132 iounmap(f->ahb_addr); in nxp_fspi_remove()
1144 struct nxp_fspi *f = dev_get_drvdata(dev); in nxp_fspi_resume() local
1146 nxp_fspi_default_setup(f); in nxp_fspi_resume()