Lines Matching refs:f

399 static inline int needs_ip_only(struct nxp_fspi *f)  in needs_ip_only()  argument
401 return f->devtype_data->quirks & FSPI_QUIRK_USE_IP_ONLY; in needs_ip_only()
411 static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr) in fspi_writel() argument
413 if (f->devtype_data->little_endian) in fspi_writel()
419 static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr) in fspi_readl() argument
421 if (f->devtype_data->little_endian) in fspi_readl()
429 struct nxp_fspi *f = dev_id; in nxp_fspi_irq_handler() local
433 reg = fspi_readl(f, f->iobase + FSPI_INTR); in nxp_fspi_irq_handler()
434 fspi_writel(f, FSPI_INTR_IPCMDDONE, f->iobase + FSPI_INTR); in nxp_fspi_irq_handler()
437 complete(&f->c); in nxp_fspi_irq_handler()
442 static int nxp_fspi_check_buswidth(struct nxp_fspi *f, u8 width) in nxp_fspi_check_buswidth() argument
458 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_supports_op() local
461 ret = nxp_fspi_check_buswidth(f, op->cmd.buswidth); in nxp_fspi_supports_op()
464 ret |= nxp_fspi_check_buswidth(f, op->addr.buswidth); in nxp_fspi_supports_op()
467 ret |= nxp_fspi_check_buswidth(f, op->dummy.buswidth); in nxp_fspi_supports_op()
470 ret |= nxp_fspi_check_buswidth(f, op->data.buswidth); in nxp_fspi_supports_op()
486 if (op->addr.val >= f->memmap_phy_size) in nxp_fspi_supports_op()
496 (op->data.nbytes > f->devtype_data->ahb_buf_size || in nxp_fspi_supports_op()
497 (op->data.nbytes > f->devtype_data->rxfifo - 4 && in nxp_fspi_supports_op()
502 op->data.nbytes > f->devtype_data->txfifo) in nxp_fspi_supports_op()
509 static int fspi_readl_poll_tout(struct nxp_fspi *f, void __iomem *base, in fspi_readl_poll_tout() argument
515 if (!f->devtype_data->little_endian) in fspi_readl_poll_tout()
531 static inline void nxp_fspi_invalid(struct nxp_fspi *f) in nxp_fspi_invalid() argument
536 reg = fspi_readl(f, f->iobase + FSPI_MCR0); in nxp_fspi_invalid()
537 fspi_writel(f, reg | FSPI_MCR0_SWRST, f->iobase + FSPI_MCR0); in nxp_fspi_invalid()
540 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, in nxp_fspi_invalid()
545 static void nxp_fspi_prepare_lut(struct nxp_fspi *f, in nxp_fspi_prepare_lut() argument
548 void __iomem *base = f->iobase; in nxp_fspi_prepare_lut()
551 u32 lut_offset = (f->devtype_data->lut_num - 1) * 4 * 4; in nxp_fspi_prepare_lut()
593 fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); in nxp_fspi_prepare_lut()
594 fspi_writel(f, FSPI_LCKER_UNLOCK, f->iobase + FSPI_LCKCR); in nxp_fspi_prepare_lut()
599 fspi_writel(f, lutval[i], base + target_lut_reg); in nxp_fspi_prepare_lut()
602 dev_dbg(f->dev, "CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x], size: 0x%08x\n", in nxp_fspi_prepare_lut()
606 fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); in nxp_fspi_prepare_lut()
607 fspi_writel(f, FSPI_LCKER_LOCK, f->iobase + FSPI_LCKCR); in nxp_fspi_prepare_lut()
610 static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f) in nxp_fspi_clk_prep_enable() argument
614 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_clk_prep_enable()
617 ret = clk_prepare_enable(f->clk_en); in nxp_fspi_clk_prep_enable()
621 ret = clk_prepare_enable(f->clk); in nxp_fspi_clk_prep_enable()
623 clk_disable_unprepare(f->clk_en); in nxp_fspi_clk_prep_enable()
630 static int nxp_fspi_clk_disable_unprep(struct nxp_fspi *f) in nxp_fspi_clk_disable_unprep() argument
632 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_clk_disable_unprep()
635 clk_disable_unprepare(f->clk); in nxp_fspi_clk_disable_unprep()
636 clk_disable_unprepare(f->clk_en); in nxp_fspi_clk_disable_unprep()
641 static void nxp_fspi_dll_calibration(struct nxp_fspi *f) in nxp_fspi_dll_calibration() argument
646 fspi_writel(f, FSPI_DLLACR_DLLRESET, f->iobase + FSPI_DLLACR); in nxp_fspi_dll_calibration()
647 fspi_writel(f, FSPI_DLLBCR_DLLRESET, f->iobase + FSPI_DLLBCR); in nxp_fspi_dll_calibration()
648 fspi_writel(f, 0, f->iobase + FSPI_DLLACR); in nxp_fspi_dll_calibration()
649 fspi_writel(f, 0, f->iobase + FSPI_DLLBCR); in nxp_fspi_dll_calibration()
658 fspi_writel(f, FSPI_DLLACR_DLLEN | FSPI_DLLACR_SLVDLY(0xF), in nxp_fspi_dll_calibration()
659 f->iobase + FSPI_DLLACR); in nxp_fspi_dll_calibration()
660 fspi_writel(f, FSPI_DLLBCR_DLLEN | FSPI_DLLBCR_SLVDLY(0xF), in nxp_fspi_dll_calibration()
661 f->iobase + FSPI_DLLBCR); in nxp_fspi_dll_calibration()
664 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_STS2, FSPI_STS2_AB_LOCK, in nxp_fspi_dll_calibration()
667 dev_warn(f->dev, "DLL lock failed, please fix it!\n"); in nxp_fspi_dll_calibration()
708 static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi) in nxp_fspi_select_mem() argument
718 if (f->selected == spi_get_chipselect(spi, 0)) in nxp_fspi_select_mem()
722 fspi_writel(f, 0, f->iobase + FSPI_FLSHA1CR0); in nxp_fspi_select_mem()
723 fspi_writel(f, 0, f->iobase + FSPI_FLSHA2CR0); in nxp_fspi_select_mem()
724 fspi_writel(f, 0, f->iobase + FSPI_FLSHB1CR0); in nxp_fspi_select_mem()
725 fspi_writel(f, 0, f->iobase + FSPI_FLSHB2CR0); in nxp_fspi_select_mem()
728 size_kb = FSPI_FLSHXCR0_SZ(f->memmap_phy_size); in nxp_fspi_select_mem()
730 fspi_writel(f, size_kb, f->iobase + FSPI_FLSHA1CR0 + in nxp_fspi_select_mem()
733 dev_dbg(f->dev, "Slave device [CS:%x] selected\n", spi_get_chipselect(spi, 0)); in nxp_fspi_select_mem()
735 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_select_mem()
737 ret = clk_set_rate(f->clk, rate); in nxp_fspi_select_mem()
741 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_select_mem()
750 nxp_fspi_dll_calibration(f); in nxp_fspi_select_mem()
752 f->selected = spi_get_chipselect(spi, 0); in nxp_fspi_select_mem()
755 static int nxp_fspi_read_ahb(struct nxp_fspi *f, const struct spi_mem_op *op) in nxp_fspi_read_ahb() argument
761 if ((!f->ahb_addr) || start < f->memmap_start || in nxp_fspi_read_ahb()
762 start + len > f->memmap_start + f->memmap_len) { in nxp_fspi_read_ahb()
763 if (f->ahb_addr) in nxp_fspi_read_ahb()
764 iounmap(f->ahb_addr); in nxp_fspi_read_ahb()
766 f->memmap_start = start; in nxp_fspi_read_ahb()
767 f->memmap_len = len > NXP_FSPI_MIN_IOMAP ? in nxp_fspi_read_ahb()
770 f->ahb_addr = ioremap(f->memmap_phy + f->memmap_start, in nxp_fspi_read_ahb()
771 f->memmap_len); in nxp_fspi_read_ahb()
773 if (!f->ahb_addr) { in nxp_fspi_read_ahb()
774 dev_err(f->dev, "failed to alloc memory\n"); in nxp_fspi_read_ahb()
781 f->ahb_addr + start - f->memmap_start, len); in nxp_fspi_read_ahb()
786 static void nxp_fspi_fill_txfifo(struct nxp_fspi *f, in nxp_fspi_fill_txfifo() argument
789 void __iomem *base = f->iobase; in nxp_fspi_fill_txfifo()
794 fspi_writel(f, FSPI_IPTXFCR_CLR, base + FSPI_IPTXFCR); in nxp_fspi_fill_txfifo()
803 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
808 fspi_writel(f, *(u32 *) (buf + i), base + FSPI_TFDR); in nxp_fspi_fill_txfifo()
809 fspi_writel(f, *(u32 *) (buf + i + 4), base + FSPI_TFDR + 4); in nxp_fspi_fill_txfifo()
810 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
818 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
825 fspi_writel(f, data, base + FSPI_TFDR + j); in nxp_fspi_fill_txfifo()
827 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
831 static void nxp_fspi_read_rxfifo(struct nxp_fspi *f, in nxp_fspi_read_rxfifo() argument
834 void __iomem *base = f->iobase; in nxp_fspi_read_rxfifo()
845 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
850 *(u32 *)(buf + i) = fspi_readl(f, base + FSPI_RFDR); in nxp_fspi_read_rxfifo()
851 *(u32 *)(buf + i + 4) = fspi_readl(f, base + FSPI_RFDR + 4); in nxp_fspi_read_rxfifo()
853 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
862 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
869 tmp = fspi_readl(f, base + FSPI_RFDR + j); in nxp_fspi_read_rxfifo()
877 fspi_writel(f, FSPI_IPRXFCR_CLR, base + FSPI_IPRXFCR); in nxp_fspi_read_rxfifo()
879 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
882 static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op) in nxp_fspi_do_op() argument
884 void __iomem *base = f->iobase; in nxp_fspi_do_op()
889 reg = fspi_readl(f, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
893 fspi_writel(f, reg, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
895 init_completion(&f->c); in nxp_fspi_do_op()
897 fspi_writel(f, op->addr.val, base + FSPI_IPCR0); in nxp_fspi_do_op()
903 seqid_lut = f->devtype_data->lut_num - 1; in nxp_fspi_do_op()
904 fspi_writel(f, op->data.nbytes | in nxp_fspi_do_op()
910 fspi_writel(f, FSPI_IPCMD_TRG, base + FSPI_IPCMD); in nxp_fspi_do_op()
913 if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000))) in nxp_fspi_do_op()
918 nxp_fspi_read_rxfifo(f, op); in nxp_fspi_do_op()
925 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_exec_op() local
928 mutex_lock(&f->lock); in nxp_fspi_exec_op()
931 err = fspi_readl_poll_tout(f, f->iobase + FSPI_STS0, in nxp_fspi_exec_op()
935 nxp_fspi_select_mem(f, mem->spi); in nxp_fspi_exec_op()
937 nxp_fspi_prepare_lut(f, op); in nxp_fspi_exec_op()
944 if (op->data.nbytes > (f->devtype_data->rxfifo - 4) && in nxp_fspi_exec_op()
946 !needs_ip_only(f)) { in nxp_fspi_exec_op()
947 err = nxp_fspi_read_ahb(f, op); in nxp_fspi_exec_op()
950 nxp_fspi_fill_txfifo(f, op); in nxp_fspi_exec_op()
952 err = nxp_fspi_do_op(f, op); in nxp_fspi_exec_op()
956 nxp_fspi_invalid(f); in nxp_fspi_exec_op()
958 mutex_unlock(&f->lock); in nxp_fspi_exec_op()
965 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_adjust_op_size() local
968 if (op->data.nbytes > f->devtype_data->txfifo) in nxp_fspi_adjust_op_size()
969 op->data.nbytes = f->devtype_data->txfifo; in nxp_fspi_adjust_op_size()
971 if (op->data.nbytes > f->devtype_data->ahb_buf_size) in nxp_fspi_adjust_op_size()
972 op->data.nbytes = f->devtype_data->ahb_buf_size; in nxp_fspi_adjust_op_size()
973 else if (op->data.nbytes > (f->devtype_data->rxfifo - 4)) in nxp_fspi_adjust_op_size()
979 needs_ip_only(f) && in nxp_fspi_adjust_op_size()
980 op->data.nbytes > f->devtype_data->rxfifo) in nxp_fspi_adjust_op_size()
981 op->data.nbytes = f->devtype_data->rxfifo; in nxp_fspi_adjust_op_size()
986 static void erratum_err050568(struct nxp_fspi *f) in erratum_err050568() argument
998 dev_dbg(f->dev, "Errata applicable only for LS1028A\n"); in erratum_err050568()
1004 dev_err(f->dev, "No syscon regmap\n"); in erratum_err050568()
1013 dev_dbg(f->dev, "val: 0x%08x, sys_pll_ratio: %d\n", val, sys_pll_ratio); in erratum_err050568()
1017 f->devtype_data->quirks |= FSPI_QUIRK_USE_IP_ONLY; in erratum_err050568()
1022 dev_err(f->dev, "Errata cannot be executed. Read via IP bus may not work\n"); in erratum_err050568()
1025 static int nxp_fspi_default_setup(struct nxp_fspi *f) in nxp_fspi_default_setup() argument
1027 void __iomem *base = f->iobase; in nxp_fspi_default_setup()
1032 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_default_setup()
1035 ret = clk_set_rate(f->clk, 20000000); in nxp_fspi_default_setup()
1039 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_default_setup()
1049 if (of_device_is_compatible(f->dev->of_node, "nxp,lx2160a-fspi")) in nxp_fspi_default_setup()
1050 erratum_err050568(f); in nxp_fspi_default_setup()
1054 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, in nxp_fspi_default_setup()
1059 fspi_writel(f, FSPI_MCR0_MDIS, base + FSPI_MCR0); in nxp_fspi_default_setup()
1066 fspi_writel(f, FSPI_DLLACR_OVRDEN, base + FSPI_DLLACR); in nxp_fspi_default_setup()
1067 fspi_writel(f, FSPI_DLLBCR_OVRDEN, base + FSPI_DLLBCR); in nxp_fspi_default_setup()
1070 fspi_writel(f, FSPI_MCR0_AHB_TIMEOUT(0xFF) | in nxp_fspi_default_setup()
1078 reg = fspi_readl(f, f->iobase + FSPI_MCR2); in nxp_fspi_default_setup()
1080 fspi_writel(f, reg, base + FSPI_MCR2); in nxp_fspi_default_setup()
1084 fspi_writel(f, 0, base + FSPI_AHBRX_BUF0CR0 + 4 * i); in nxp_fspi_default_setup()
1090 fspi_writel(f, (f->devtype_data->ahb_buf_size / 8 | in nxp_fspi_default_setup()
1094 fspi_writel(f, FSPI_AHBCR_PREF_EN | FSPI_AHBCR_RDADDROPT, in nxp_fspi_default_setup()
1099 fspi_writel(f, reg, base + FSPI_FLSHA1CR1); in nxp_fspi_default_setup()
1100 fspi_writel(f, reg, base + FSPI_FLSHA2CR1); in nxp_fspi_default_setup()
1101 fspi_writel(f, reg, base + FSPI_FLSHB1CR1); in nxp_fspi_default_setup()
1102 fspi_writel(f, reg, base + FSPI_FLSHB2CR1); in nxp_fspi_default_setup()
1109 seqid_lut = f->devtype_data->lut_num - 1; in nxp_fspi_default_setup()
1111 fspi_writel(f, seqid_lut, base + FSPI_FLSHA1CR2); in nxp_fspi_default_setup()
1112 fspi_writel(f, seqid_lut, base + FSPI_FLSHA2CR2); in nxp_fspi_default_setup()
1113 fspi_writel(f, seqid_lut, base + FSPI_FLSHB1CR2); in nxp_fspi_default_setup()
1114 fspi_writel(f, seqid_lut, base + FSPI_FLSHB2CR2); in nxp_fspi_default_setup()
1116 f->selected = -1; in nxp_fspi_default_setup()
1119 fspi_writel(f, FSPI_INTEN_IPCMDDONE, base + FSPI_INTEN); in nxp_fspi_default_setup()
1126 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); in nxp_fspi_get_name() local
1131 if (of_get_available_child_count(f->dev->of_node) == 1) in nxp_fspi_get_name()
1132 return dev_name(f->dev); in nxp_fspi_get_name()
1135 "%s-%d", dev_name(f->dev), in nxp_fspi_get_name()
1159 struct nxp_fspi *f; in nxp_fspi_probe() local
1163 ctlr = spi_alloc_master(&pdev->dev, sizeof(*f)); in nxp_fspi_probe()
1170 f = spi_controller_get_devdata(ctlr); in nxp_fspi_probe()
1171 f->dev = dev; in nxp_fspi_probe()
1172 f->devtype_data = (struct nxp_fspi_devtype_data *)device_get_match_data(dev); in nxp_fspi_probe()
1173 if (!f->devtype_data) { in nxp_fspi_probe()
1178 platform_set_drvdata(pdev, f); in nxp_fspi_probe()
1181 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_probe()
1182 f->iobase = devm_platform_ioremap_resource(pdev, 0); in nxp_fspi_probe()
1184 f->iobase = devm_platform_ioremap_resource_byname(pdev, "fspi_base"); in nxp_fspi_probe()
1186 if (IS_ERR(f->iobase)) { in nxp_fspi_probe()
1187 ret = PTR_ERR(f->iobase); in nxp_fspi_probe()
1192 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_probe()
1204 f->memmap_phy = res->start; in nxp_fspi_probe()
1205 f->memmap_phy_size = resource_size(res); in nxp_fspi_probe()
1209 f->clk_en = devm_clk_get(dev, "fspi_en"); in nxp_fspi_probe()
1210 if (IS_ERR(f->clk_en)) { in nxp_fspi_probe()
1211 ret = PTR_ERR(f->clk_en); in nxp_fspi_probe()
1215 f->clk = devm_clk_get(dev, "fspi"); in nxp_fspi_probe()
1216 if (IS_ERR(f->clk)) { in nxp_fspi_probe()
1217 ret = PTR_ERR(f->clk); in nxp_fspi_probe()
1221 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_probe()
1229 reg = fspi_readl(f, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1231 fspi_writel(f, reg, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1239 nxp_fspi_irq_handler, 0, pdev->name, f); in nxp_fspi_probe()
1245 mutex_init(&f->lock); in nxp_fspi_probe()
1251 nxp_fspi_default_setup(f); in nxp_fspi_probe()
1262 mutex_destroy(&f->lock); in nxp_fspi_probe()
1265 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_probe()
1276 struct nxp_fspi *f = platform_get_drvdata(pdev); in nxp_fspi_remove() local
1279 fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); in nxp_fspi_remove()
1281 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_remove()
1283 mutex_destroy(&f->lock); in nxp_fspi_remove()
1285 if (f->ahb_addr) in nxp_fspi_remove()
1286 iounmap(f->ahb_addr); in nxp_fspi_remove()
1296 struct nxp_fspi *f = dev_get_drvdata(dev); in nxp_fspi_resume() local
1298 nxp_fspi_default_setup(f); in nxp_fspi_resume()