Lines Matching +full:4 +full:f

10  * channels and up to 4 external devices. Each channel supports
11 * Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional
72 #define FSPI_MCR0_RXCLKSRC(x) ((x) << 4)
89 #define FSPI_MCR2_ABRDUMMY BIT(4)
98 #define FSPI_AHBCR_BUFF_EN BIT(4)
110 #define FSPI_INTEN_AHBCMDERR BIT(4)
122 #define FSPI_INTR_AHBCMDERR BIT(4)
221 #define FSPI_STS0_DLPHA(x) ((x) << 4)
320 #define NXP_FSPI_MAX_CHIPSELECT 4
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
447 case 4: in nxp_fspi_check_buswidth()
458 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); 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()
476 * The number of address bytes should be equal to or less than 4 bytes. in nxp_fspi_supports_op()
478 if (op->addr.nbytes > 4) 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()
549 u32 lutval[4] = {}; 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()
598 target_lut_reg = FSPI_LUT_BASE + lut_offset + i * 4; 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[%02x] lutval[0:%08x 1:%08x 2:%08x 3:%08x], 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()
731 4 * spi_get_chipselect(spi, 0)); in nxp_fspi_select_mem()
733 dev_dbg(f->dev, "Target 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 = max_t(u32, len, NXP_FSPI_MIN_IOMAP); in nxp_fspi_read_ahb()
769 f->ahb_addr = ioremap(f->memmap_phy + f->memmap_start, in nxp_fspi_read_ahb()
770 f->memmap_len); in nxp_fspi_read_ahb()
772 if (!f->ahb_addr) { in nxp_fspi_read_ahb()
773 dev_err(f->dev, "failed to alloc memory\n"); in nxp_fspi_read_ahb()
780 f->ahb_addr + start - f->memmap_start, len); in nxp_fspi_read_ahb()
785 static void nxp_fspi_fill_txfifo(struct nxp_fspi *f, in nxp_fspi_fill_txfifo() argument
788 void __iomem *base = f->iobase; in nxp_fspi_fill_txfifo()
793 fspi_writel(f, FSPI_IPTXFCR_CLR, base + FSPI_IPTXFCR); in nxp_fspi_fill_txfifo()
802 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
807 fspi_writel(f, *(u32 *) (buf + i), base + FSPI_TFDR); in nxp_fspi_fill_txfifo()
808 fspi_writel(f, *(u32 *) (buf + i + 4), base + FSPI_TFDR + 4); in nxp_fspi_fill_txfifo()
809 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
817 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
822 for (j = 0; j < ALIGN(remaining, 4); j += 4) { in nxp_fspi_fill_txfifo()
823 memcpy(&data, buf + i + j, min_t(int, 4, remaining - j)); in nxp_fspi_fill_txfifo()
824 fspi_writel(f, data, base + FSPI_TFDR + j); in nxp_fspi_fill_txfifo()
826 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
830 static void nxp_fspi_read_rxfifo(struct nxp_fspi *f, in nxp_fspi_read_rxfifo() argument
833 void __iomem *base = f->iobase; in nxp_fspi_read_rxfifo()
844 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
849 *(u32 *)(buf + i) = fspi_readl(f, base + FSPI_RFDR); in nxp_fspi_read_rxfifo()
850 *(u32 *)(buf + i + 4) = fspi_readl(f, base + FSPI_RFDR + 4); in nxp_fspi_read_rxfifo()
852 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
861 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
867 for (j = 0; j < op->data.nbytes - i; j += 4) { in nxp_fspi_read_rxfifo()
868 tmp = fspi_readl(f, base + FSPI_RFDR + j); in nxp_fspi_read_rxfifo()
869 size = min(len, 4); in nxp_fspi_read_rxfifo()
876 fspi_writel(f, FSPI_IPRXFCR_CLR, base + FSPI_IPRXFCR); in nxp_fspi_read_rxfifo()
878 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
881 static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op) in nxp_fspi_do_op() argument
883 void __iomem *base = f->iobase; in nxp_fspi_do_op()
888 reg = fspi_readl(f, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
892 fspi_writel(f, reg, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
894 init_completion(&f->c); in nxp_fspi_do_op()
896 fspi_writel(f, op->addr.val, base + FSPI_IPCR0); in nxp_fspi_do_op()
902 seqid_lut = f->devtype_data->lut_num - 1; in nxp_fspi_do_op()
903 fspi_writel(f, op->data.nbytes | in nxp_fspi_do_op()
909 fspi_writel(f, FSPI_IPCMD_TRG, base + FSPI_IPCMD); in nxp_fspi_do_op()
912 if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000))) in nxp_fspi_do_op()
917 nxp_fspi_read_rxfifo(f, op); in nxp_fspi_do_op()
924 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); in nxp_fspi_exec_op() local
927 mutex_lock(&f->lock); in nxp_fspi_exec_op()
930 err = fspi_readl_poll_tout(f, f->iobase + FSPI_STS0, in nxp_fspi_exec_op()
934 nxp_fspi_select_mem(f, mem->spi); in nxp_fspi_exec_op()
936 nxp_fspi_prepare_lut(f, op); in nxp_fspi_exec_op()
943 if (op->data.nbytes > (f->devtype_data->rxfifo - 4) && in nxp_fspi_exec_op()
945 !needs_ip_only(f)) { in nxp_fspi_exec_op()
946 err = nxp_fspi_read_ahb(f, op); in nxp_fspi_exec_op()
949 nxp_fspi_fill_txfifo(f, op); in nxp_fspi_exec_op()
951 err = nxp_fspi_do_op(f, op); in nxp_fspi_exec_op()
955 nxp_fspi_invalid(f); in nxp_fspi_exec_op()
957 mutex_unlock(&f->lock); in nxp_fspi_exec_op()
964 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); in nxp_fspi_adjust_op_size() local
967 if (op->data.nbytes > f->devtype_data->txfifo) in nxp_fspi_adjust_op_size()
968 op->data.nbytes = f->devtype_data->txfifo; in nxp_fspi_adjust_op_size()
970 if (op->data.nbytes > f->devtype_data->ahb_buf_size) in nxp_fspi_adjust_op_size()
971 op->data.nbytes = f->devtype_data->ahb_buf_size; in nxp_fspi_adjust_op_size()
972 else if (op->data.nbytes > (f->devtype_data->rxfifo - 4)) in nxp_fspi_adjust_op_size()
978 needs_ip_only(f) && in nxp_fspi_adjust_op_size()
979 op->data.nbytes > f->devtype_data->rxfifo) in nxp_fspi_adjust_op_size()
980 op->data.nbytes = f->devtype_data->rxfifo; in nxp_fspi_adjust_op_size()
985 static void erratum_err050568(struct nxp_fspi *f) in erratum_err050568() argument
997 dev_dbg(f->dev, "Errata applicable only for LS1028A\n"); in erratum_err050568()
1003 dev_err(f->dev, "No syscon regmap\n"); in erratum_err050568()
1012 dev_dbg(f->dev, "val: 0x%08x, sys_pll_ratio: %d\n", val, sys_pll_ratio); in erratum_err050568()
1016 f->devtype_data->quirks |= FSPI_QUIRK_USE_IP_ONLY; in erratum_err050568()
1021 dev_err(f->dev, "Errata cannot be executed. Read via IP bus may not work\n"); in erratum_err050568()
1024 static int nxp_fspi_default_setup(struct nxp_fspi *f) in nxp_fspi_default_setup() argument
1026 void __iomem *base = f->iobase; in nxp_fspi_default_setup()
1031 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_default_setup()
1034 ret = clk_set_rate(f->clk, 20000000); in nxp_fspi_default_setup()
1038 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_default_setup()
1048 if (of_device_is_compatible(f->dev->of_node, "nxp,lx2160a-fspi")) in nxp_fspi_default_setup()
1049 erratum_err050568(f); in nxp_fspi_default_setup()
1053 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, in nxp_fspi_default_setup()
1058 fspi_writel(f, FSPI_MCR0_MDIS, base + FSPI_MCR0); in nxp_fspi_default_setup()
1065 fspi_writel(f, FSPI_DLLACR_OVRDEN, base + FSPI_DLLACR); in nxp_fspi_default_setup()
1066 fspi_writel(f, FSPI_DLLBCR_OVRDEN, base + FSPI_DLLBCR); in nxp_fspi_default_setup()
1069 fspi_writel(f, FSPI_MCR0_AHB_TIMEOUT(0xFF) | in nxp_fspi_default_setup()
1077 reg = fspi_readl(f, f->iobase + FSPI_MCR2); in nxp_fspi_default_setup()
1079 fspi_writel(f, reg, base + FSPI_MCR2); in nxp_fspi_default_setup()
1083 fspi_writel(f, 0, base + FSPI_AHBRX_BUF0CR0 + 4 * i); in nxp_fspi_default_setup()
1089 fspi_writel(f, (f->devtype_data->ahb_buf_size / 8 | in nxp_fspi_default_setup()
1093 fspi_writel(f, FSPI_AHBCR_PREF_EN | FSPI_AHBCR_RDADDROPT, in nxp_fspi_default_setup()
1098 fspi_writel(f, reg, base + FSPI_FLSHA1CR1); in nxp_fspi_default_setup()
1099 fspi_writel(f, reg, base + FSPI_FLSHA2CR1); in nxp_fspi_default_setup()
1100 fspi_writel(f, reg, base + FSPI_FLSHB1CR1); in nxp_fspi_default_setup()
1101 fspi_writel(f, reg, base + FSPI_FLSHB2CR1); in nxp_fspi_default_setup()
1108 seqid_lut = f->devtype_data->lut_num - 1; in nxp_fspi_default_setup()
1110 fspi_writel(f, seqid_lut, base + FSPI_FLSHA1CR2); in nxp_fspi_default_setup()
1111 fspi_writel(f, seqid_lut, base + FSPI_FLSHA2CR2); in nxp_fspi_default_setup()
1112 fspi_writel(f, seqid_lut, base + FSPI_FLSHB1CR2); in nxp_fspi_default_setup()
1113 fspi_writel(f, seqid_lut, base + FSPI_FLSHB2CR2); in nxp_fspi_default_setup()
1115 f->selected = -1; in nxp_fspi_default_setup()
1118 fspi_writel(f, FSPI_INTEN_IPCMDDONE, base + FSPI_INTEN); in nxp_fspi_default_setup()
1125 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); in nxp_fspi_get_name() local
1130 if (of_get_available_child_count(f->dev->of_node) == 1) in nxp_fspi_get_name()
1131 return dev_name(f->dev); in nxp_fspi_get_name()
1134 "%s-%d", dev_name(f->dev), in nxp_fspi_get_name()
1158 struct nxp_fspi *f; in nxp_fspi_probe() local
1162 ctlr = spi_alloc_host(&pdev->dev, sizeof(*f)); in nxp_fspi_probe()
1169 f = spi_controller_get_devdata(ctlr); in nxp_fspi_probe()
1170 f->dev = dev; in nxp_fspi_probe()
1171 f->devtype_data = (struct nxp_fspi_devtype_data *)device_get_match_data(dev); in nxp_fspi_probe()
1172 if (!f->devtype_data) { in nxp_fspi_probe()
1177 platform_set_drvdata(pdev, f); in nxp_fspi_probe()
1180 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_probe()
1181 f->iobase = devm_platform_ioremap_resource(pdev, 0); in nxp_fspi_probe()
1183 f->iobase = devm_platform_ioremap_resource_byname(pdev, "fspi_base"); in nxp_fspi_probe()
1185 if (IS_ERR(f->iobase)) { in nxp_fspi_probe()
1186 ret = PTR_ERR(f->iobase); in nxp_fspi_probe()
1191 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_probe()
1203 f->memmap_phy = res->start; in nxp_fspi_probe()
1204 f->memmap_phy_size = resource_size(res); in nxp_fspi_probe()
1208 f->clk_en = devm_clk_get(dev, "fspi_en"); in nxp_fspi_probe()
1209 if (IS_ERR(f->clk_en)) { in nxp_fspi_probe()
1210 ret = PTR_ERR(f->clk_en); in nxp_fspi_probe()
1214 f->clk = devm_clk_get(dev, "fspi"); in nxp_fspi_probe()
1215 if (IS_ERR(f->clk)) { in nxp_fspi_probe()
1216 ret = PTR_ERR(f->clk); in nxp_fspi_probe()
1220 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_probe()
1228 reg = fspi_readl(f, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1230 fspi_writel(f, reg, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1238 nxp_fspi_irq_handler, 0, pdev->name, f); in nxp_fspi_probe()
1244 mutex_init(&f->lock); in nxp_fspi_probe()
1250 nxp_fspi_default_setup(f); in nxp_fspi_probe()
1261 mutex_destroy(&f->lock); in nxp_fspi_probe()
1264 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_probe()
1275 struct nxp_fspi *f = platform_get_drvdata(pdev); in nxp_fspi_remove() local
1278 fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); in nxp_fspi_remove()
1280 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_remove()
1282 mutex_destroy(&f->lock); in nxp_fspi_remove()
1284 if (f->ahb_addr) in nxp_fspi_remove()
1285 iounmap(f->ahb_addr); in nxp_fspi_remove()
1295 struct nxp_fspi *f = dev_get_drvdata(dev); in nxp_fspi_resume() local
1297 nxp_fspi_default_setup(f); in nxp_fspi_resume()