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
79 #define FSPI_MCR0_RXCLKSRC(x) ((x) << 4)
96 #define FSPI_MCR2_ABRDUMMY BIT(4)
105 #define FSPI_AHBCR_BUFF_EN BIT(4)
117 #define FSPI_INTEN_AHBCMDERR BIT(4)
129 #define FSPI_INTR_AHBCMDERR BIT(4)
228 #define FSPI_STS0_DLPHA(x) ((x) << 4)
266 #define FSPI_LUT_OFFSET (SEQID_LUT * 4 * 4)
268 (FSPI_LUT_BASE + FSPI_LUT_OFFSET + (idx) * 4)
330 #define NXP_FSPI_MAX_CHIPSELECT 4
395 static inline int needs_ip_only(struct nxp_fspi *f) in needs_ip_only() argument
397 return f->devtype_data->quirks & FSPI_QUIRK_USE_IP_ONLY; in needs_ip_only()
407 static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr) in fspi_writel() argument
409 if (f->devtype_data->little_endian) in fspi_writel()
415 static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr) in fspi_readl() argument
417 if (f->devtype_data->little_endian) in fspi_readl()
425 struct nxp_fspi *f = dev_id; in nxp_fspi_irq_handler() local
429 reg = fspi_readl(f, f->iobase + FSPI_INTR); in nxp_fspi_irq_handler()
430 fspi_writel(f, FSPI_INTR_IPCMDDONE, f->iobase + FSPI_INTR); in nxp_fspi_irq_handler()
433 complete(&f->c); in nxp_fspi_irq_handler()
438 static int nxp_fspi_check_buswidth(struct nxp_fspi *f, u8 width) in nxp_fspi_check_buswidth() argument
443 case 4: in nxp_fspi_check_buswidth()
454 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); in nxp_fspi_supports_op() local
457 ret = nxp_fspi_check_buswidth(f, op->cmd.buswidth); in nxp_fspi_supports_op()
460 ret |= nxp_fspi_check_buswidth(f, op->addr.buswidth); in nxp_fspi_supports_op()
463 ret |= nxp_fspi_check_buswidth(f, op->dummy.buswidth); in nxp_fspi_supports_op()
466 ret |= nxp_fspi_check_buswidth(f, op->data.buswidth); in nxp_fspi_supports_op()
472 * The number of address bytes should be equal to or less than 4 bytes. in nxp_fspi_supports_op()
474 if (op->addr.nbytes > 4) in nxp_fspi_supports_op()
482 if (op->addr.val >= f->memmap_phy_size) in nxp_fspi_supports_op()
492 (op->data.nbytes > f->devtype_data->ahb_buf_size || in nxp_fspi_supports_op()
493 (op->data.nbytes > f->devtype_data->rxfifo - 4 && in nxp_fspi_supports_op()
498 op->data.nbytes > f->devtype_data->txfifo) in nxp_fspi_supports_op()
505 static int fspi_readl_poll_tout(struct nxp_fspi *f, void __iomem *base, in fspi_readl_poll_tout() argument
511 if (!f->devtype_data->little_endian) in fspi_readl_poll_tout()
527 static inline void nxp_fspi_invalid(struct nxp_fspi *f) in nxp_fspi_invalid() argument
532 reg = fspi_readl(f, f->iobase + FSPI_MCR0); in nxp_fspi_invalid()
533 fspi_writel(f, reg | FSPI_MCR0_SWRST, f->iobase + FSPI_MCR0); in nxp_fspi_invalid()
536 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, in nxp_fspi_invalid()
541 static void nxp_fspi_prepare_lut(struct nxp_fspi *f, in nxp_fspi_prepare_lut() argument
544 void __iomem *base = f->iobase; in nxp_fspi_prepare_lut()
545 u32 lutval[4] = {}; in nxp_fspi_prepare_lut()
587 fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); in nxp_fspi_prepare_lut()
588 fspi_writel(f, FSPI_LCKER_UNLOCK, f->iobase + FSPI_LCKCR); in nxp_fspi_prepare_lut()
592 fspi_writel(f, lutval[i], base + FSPI_LUT_REG(i)); in nxp_fspi_prepare_lut()
594 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()
598 fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); in nxp_fspi_prepare_lut()
599 fspi_writel(f, FSPI_LCKER_LOCK, f->iobase + FSPI_LCKCR); in nxp_fspi_prepare_lut()
602 static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f) in nxp_fspi_clk_prep_enable() argument
606 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_clk_prep_enable()
609 ret = clk_prepare_enable(f->clk_en); in nxp_fspi_clk_prep_enable()
613 ret = clk_prepare_enable(f->clk); in nxp_fspi_clk_prep_enable()
615 clk_disable_unprepare(f->clk_en); in nxp_fspi_clk_prep_enable()
622 static int nxp_fspi_clk_disable_unprep(struct nxp_fspi *f) in nxp_fspi_clk_disable_unprep() argument
624 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_clk_disable_unprep()
627 clk_disable_unprepare(f->clk); in nxp_fspi_clk_disable_unprep()
628 clk_disable_unprepare(f->clk_en); in nxp_fspi_clk_disable_unprep()
633 static void nxp_fspi_dll_calibration(struct nxp_fspi *f) in nxp_fspi_dll_calibration() argument
638 fspi_writel(f, FSPI_DLLACR_DLLRESET, f->iobase + FSPI_DLLACR); in nxp_fspi_dll_calibration()
639 fspi_writel(f, FSPI_DLLBCR_DLLRESET, f->iobase + FSPI_DLLBCR); in nxp_fspi_dll_calibration()
640 fspi_writel(f, 0, f->iobase + FSPI_DLLACR); in nxp_fspi_dll_calibration()
641 fspi_writel(f, 0, f->iobase + FSPI_DLLBCR); in nxp_fspi_dll_calibration()
650 fspi_writel(f, FSPI_DLLACR_DLLEN | FSPI_DLLACR_SLVDLY(0xF), in nxp_fspi_dll_calibration()
651 f->iobase + FSPI_DLLACR); in nxp_fspi_dll_calibration()
652 fspi_writel(f, FSPI_DLLBCR_DLLEN | FSPI_DLLBCR_SLVDLY(0xF), in nxp_fspi_dll_calibration()
653 f->iobase + FSPI_DLLBCR); in nxp_fspi_dll_calibration()
656 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_STS2, FSPI_STS2_AB_LOCK, in nxp_fspi_dll_calibration()
659 dev_warn(f->dev, "DLL lock failed, please fix it!\n"); in nxp_fspi_dll_calibration()
700 static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi) in nxp_fspi_select_mem() argument
710 if (f->selected == spi_get_chipselect(spi, 0)) in nxp_fspi_select_mem()
714 fspi_writel(f, 0, f->iobase + FSPI_FLSHA1CR0); in nxp_fspi_select_mem()
715 fspi_writel(f, 0, f->iobase + FSPI_FLSHA2CR0); in nxp_fspi_select_mem()
716 fspi_writel(f, 0, f->iobase + FSPI_FLSHB1CR0); in nxp_fspi_select_mem()
717 fspi_writel(f, 0, f->iobase + FSPI_FLSHB2CR0); in nxp_fspi_select_mem()
720 size_kb = FSPI_FLSHXCR0_SZ(f->memmap_phy_size); in nxp_fspi_select_mem()
722 fspi_writel(f, size_kb, f->iobase + FSPI_FLSHA1CR0 + in nxp_fspi_select_mem()
723 4 * spi_get_chipselect(spi, 0)); in nxp_fspi_select_mem()
725 dev_dbg(f->dev, "Target device [CS:%x] selected\n", spi_get_chipselect(spi, 0)); in nxp_fspi_select_mem()
727 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_select_mem()
729 ret = clk_set_rate(f->clk, rate); in nxp_fspi_select_mem()
733 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_select_mem()
742 nxp_fspi_dll_calibration(f); in nxp_fspi_select_mem()
744 f->selected = spi_get_chipselect(spi, 0); in nxp_fspi_select_mem()
747 static int nxp_fspi_read_ahb(struct nxp_fspi *f, const struct spi_mem_op *op) in nxp_fspi_read_ahb() argument
753 if ((!f->ahb_addr) || start < f->memmap_start || in nxp_fspi_read_ahb()
754 start + len > f->memmap_start + f->memmap_len) { in nxp_fspi_read_ahb()
755 if (f->ahb_addr) in nxp_fspi_read_ahb()
756 iounmap(f->ahb_addr); in nxp_fspi_read_ahb()
758 f->memmap_start = start; in nxp_fspi_read_ahb()
759 f->memmap_len = len > NXP_FSPI_MIN_IOMAP ? in nxp_fspi_read_ahb()
762 f->ahb_addr = ioremap(f->memmap_phy + f->memmap_start, in nxp_fspi_read_ahb()
763 f->memmap_len); in nxp_fspi_read_ahb()
765 if (!f->ahb_addr) { in nxp_fspi_read_ahb()
766 dev_err(f->dev, "failed to alloc memory\n"); in nxp_fspi_read_ahb()
773 f->ahb_addr + start - f->memmap_start, len); in nxp_fspi_read_ahb()
778 static void nxp_fspi_fill_txfifo(struct nxp_fspi *f, in nxp_fspi_fill_txfifo() argument
781 void __iomem *base = f->iobase; in nxp_fspi_fill_txfifo()
786 fspi_writel(f, FSPI_IPTXFCR_CLR, base + FSPI_IPTXFCR); in nxp_fspi_fill_txfifo()
795 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
800 fspi_writel(f, *(u32 *) (buf + i), base + FSPI_TFDR); in nxp_fspi_fill_txfifo()
801 fspi_writel(f, *(u32 *) (buf + i + 4), base + FSPI_TFDR + 4); in nxp_fspi_fill_txfifo()
802 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
809 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_fill_txfifo()
814 for (j = 0; j < ALIGN(op->data.nbytes - i, 4); j += 4) { in nxp_fspi_fill_txfifo()
815 memcpy(&data, buf + i + j, 4); in nxp_fspi_fill_txfifo()
816 fspi_writel(f, data, base + FSPI_TFDR + j); in nxp_fspi_fill_txfifo()
818 fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); in nxp_fspi_fill_txfifo()
822 static void nxp_fspi_read_rxfifo(struct nxp_fspi *f, in nxp_fspi_read_rxfifo() argument
825 void __iomem *base = f->iobase; in nxp_fspi_read_rxfifo()
836 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
841 *(u32 *)(buf + i) = fspi_readl(f, base + FSPI_RFDR); in nxp_fspi_read_rxfifo()
842 *(u32 *)(buf + i + 4) = fspi_readl(f, base + FSPI_RFDR + 4); in nxp_fspi_read_rxfifo()
844 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
853 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, in nxp_fspi_read_rxfifo()
859 for (j = 0; j < op->data.nbytes - i; j += 4) { in nxp_fspi_read_rxfifo()
860 tmp = fspi_readl(f, base + FSPI_RFDR + j); in nxp_fspi_read_rxfifo()
861 size = min(len, 4); in nxp_fspi_read_rxfifo()
868 fspi_writel(f, FSPI_IPRXFCR_CLR, base + FSPI_IPRXFCR); in nxp_fspi_read_rxfifo()
870 fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); in nxp_fspi_read_rxfifo()
873 static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op) in nxp_fspi_do_op() argument
875 void __iomem *base = f->iobase; in nxp_fspi_do_op()
880 reg = fspi_readl(f, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
884 fspi_writel(f, reg, base + FSPI_IPRXFCR); in nxp_fspi_do_op()
886 init_completion(&f->c); in nxp_fspi_do_op()
888 fspi_writel(f, op->addr.val, base + FSPI_IPCR0); in nxp_fspi_do_op()
894 fspi_writel(f, op->data.nbytes | in nxp_fspi_do_op()
900 fspi_writel(f, FSPI_IPCMD_TRG, base + FSPI_IPCMD); in nxp_fspi_do_op()
903 if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000))) in nxp_fspi_do_op()
908 nxp_fspi_read_rxfifo(f, op); in nxp_fspi_do_op()
915 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); in nxp_fspi_exec_op() local
918 mutex_lock(&f->lock); in nxp_fspi_exec_op()
921 err = fspi_readl_poll_tout(f, f->iobase + FSPI_STS0, in nxp_fspi_exec_op()
925 nxp_fspi_select_mem(f, mem->spi); in nxp_fspi_exec_op()
927 nxp_fspi_prepare_lut(f, op); in nxp_fspi_exec_op()
934 if (op->data.nbytes > (f->devtype_data->rxfifo - 4) && in nxp_fspi_exec_op()
936 !needs_ip_only(f)) { in nxp_fspi_exec_op()
937 err = nxp_fspi_read_ahb(f, op); in nxp_fspi_exec_op()
940 nxp_fspi_fill_txfifo(f, op); in nxp_fspi_exec_op()
942 err = nxp_fspi_do_op(f, op); in nxp_fspi_exec_op()
946 nxp_fspi_invalid(f); in nxp_fspi_exec_op()
948 mutex_unlock(&f->lock); in nxp_fspi_exec_op()
955 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); in nxp_fspi_adjust_op_size() local
958 if (op->data.nbytes > f->devtype_data->txfifo) in nxp_fspi_adjust_op_size()
959 op->data.nbytes = f->devtype_data->txfifo; in nxp_fspi_adjust_op_size()
961 if (op->data.nbytes > f->devtype_data->ahb_buf_size) in nxp_fspi_adjust_op_size()
962 op->data.nbytes = f->devtype_data->ahb_buf_size; in nxp_fspi_adjust_op_size()
963 else if (op->data.nbytes > (f->devtype_data->rxfifo - 4)) in nxp_fspi_adjust_op_size()
969 needs_ip_only(f) && in nxp_fspi_adjust_op_size()
970 op->data.nbytes > f->devtype_data->rxfifo) in nxp_fspi_adjust_op_size()
971 op->data.nbytes = f->devtype_data->rxfifo; in nxp_fspi_adjust_op_size()
976 static void erratum_err050568(struct nxp_fspi *f) in erratum_err050568() argument
988 dev_dbg(f->dev, "Errata applicable only for LS1028A\n"); in erratum_err050568()
994 dev_err(f->dev, "No syscon regmap\n"); in erratum_err050568()
1003 dev_dbg(f->dev, "val: 0x%08x, sys_pll_ratio: %d\n", val, sys_pll_ratio); in erratum_err050568()
1007 f->devtype_data->quirks |= FSPI_QUIRK_USE_IP_ONLY; in erratum_err050568()
1012 dev_err(f->dev, "Errata cannot be executed. Read via IP bus may not work\n"); in erratum_err050568()
1015 static int nxp_fspi_default_setup(struct nxp_fspi *f) in nxp_fspi_default_setup() argument
1017 void __iomem *base = f->iobase; in nxp_fspi_default_setup()
1022 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_default_setup()
1025 ret = clk_set_rate(f->clk, 20000000); in nxp_fspi_default_setup()
1029 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_default_setup()
1039 if (of_device_is_compatible(f->dev->of_node, "nxp,lx2160a-fspi")) in nxp_fspi_default_setup()
1040 erratum_err050568(f); in nxp_fspi_default_setup()
1044 ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, in nxp_fspi_default_setup()
1049 fspi_writel(f, FSPI_MCR0_MDIS, base + FSPI_MCR0); in nxp_fspi_default_setup()
1056 fspi_writel(f, FSPI_DLLACR_OVRDEN, base + FSPI_DLLACR); in nxp_fspi_default_setup()
1057 fspi_writel(f, FSPI_DLLBCR_OVRDEN, base + FSPI_DLLBCR); in nxp_fspi_default_setup()
1060 fspi_writel(f, FSPI_MCR0_AHB_TIMEOUT(0xFF) | in nxp_fspi_default_setup()
1068 reg = fspi_readl(f, f->iobase + FSPI_MCR2); in nxp_fspi_default_setup()
1070 fspi_writel(f, reg, base + FSPI_MCR2); in nxp_fspi_default_setup()
1074 fspi_writel(f, 0, base + FSPI_AHBRX_BUF0CR0 + 4 * i); in nxp_fspi_default_setup()
1080 fspi_writel(f, (f->devtype_data->ahb_buf_size / 8 | in nxp_fspi_default_setup()
1084 fspi_writel(f, FSPI_AHBCR_PREF_EN | FSPI_AHBCR_RDADDROPT, in nxp_fspi_default_setup()
1089 fspi_writel(f, reg, base + FSPI_FLSHA1CR1); in nxp_fspi_default_setup()
1090 fspi_writel(f, reg, base + FSPI_FLSHA2CR1); in nxp_fspi_default_setup()
1091 fspi_writel(f, reg, base + FSPI_FLSHB1CR1); in nxp_fspi_default_setup()
1092 fspi_writel(f, reg, base + FSPI_FLSHB2CR1); in nxp_fspi_default_setup()
1095 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA1CR2); in nxp_fspi_default_setup()
1096 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA2CR2); in nxp_fspi_default_setup()
1097 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB1CR2); in nxp_fspi_default_setup()
1098 fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB2CR2); in nxp_fspi_default_setup()
1100 f->selected = -1; in nxp_fspi_default_setup()
1103 fspi_writel(f, FSPI_INTEN_IPCMDDONE, base + FSPI_INTEN); in nxp_fspi_default_setup()
1110 struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->controller); in nxp_fspi_get_name() local
1115 if (of_get_available_child_count(f->dev->of_node) == 1) in nxp_fspi_get_name()
1116 return dev_name(f->dev); in nxp_fspi_get_name()
1119 "%s-%d", dev_name(f->dev), in nxp_fspi_get_name()
1143 struct nxp_fspi *f; in nxp_fspi_probe() local
1147 ctlr = spi_alloc_host(&pdev->dev, sizeof(*f)); in nxp_fspi_probe()
1154 f = spi_controller_get_devdata(ctlr); in nxp_fspi_probe()
1155 f->dev = dev; in nxp_fspi_probe()
1156 f->devtype_data = (struct nxp_fspi_devtype_data *)device_get_match_data(dev); in nxp_fspi_probe()
1157 if (!f->devtype_data) { in nxp_fspi_probe()
1162 platform_set_drvdata(pdev, f); in nxp_fspi_probe()
1165 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_probe()
1166 f->iobase = devm_platform_ioremap_resource(pdev, 0); in nxp_fspi_probe()
1168 f->iobase = devm_platform_ioremap_resource_byname(pdev, "fspi_base"); in nxp_fspi_probe()
1170 if (IS_ERR(f->iobase)) { in nxp_fspi_probe()
1171 ret = PTR_ERR(f->iobase); in nxp_fspi_probe()
1176 if (is_acpi_node(dev_fwnode(f->dev))) in nxp_fspi_probe()
1188 f->memmap_phy = res->start; in nxp_fspi_probe()
1189 f->memmap_phy_size = resource_size(res); in nxp_fspi_probe()
1193 f->clk_en = devm_clk_get(dev, "fspi_en"); in nxp_fspi_probe()
1194 if (IS_ERR(f->clk_en)) { in nxp_fspi_probe()
1195 ret = PTR_ERR(f->clk_en); in nxp_fspi_probe()
1199 f->clk = devm_clk_get(dev, "fspi"); in nxp_fspi_probe()
1200 if (IS_ERR(f->clk)) { in nxp_fspi_probe()
1201 ret = PTR_ERR(f->clk); in nxp_fspi_probe()
1205 ret = nxp_fspi_clk_prep_enable(f); in nxp_fspi_probe()
1213 reg = fspi_readl(f, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1215 fspi_writel(f, reg, f->iobase + FSPI_INTR); in nxp_fspi_probe()
1223 nxp_fspi_irq_handler, 0, pdev->name, f); in nxp_fspi_probe()
1229 mutex_init(&f->lock); in nxp_fspi_probe()
1235 nxp_fspi_default_setup(f); in nxp_fspi_probe()
1246 mutex_destroy(&f->lock); in nxp_fspi_probe()
1249 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_probe()
1260 struct nxp_fspi *f = platform_get_drvdata(pdev); in nxp_fspi_remove() local
1263 fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); in nxp_fspi_remove()
1265 nxp_fspi_clk_disable_unprep(f); in nxp_fspi_remove()
1267 mutex_destroy(&f->lock); in nxp_fspi_remove()
1269 if (f->ahb_addr) in nxp_fspi_remove()
1270 iounmap(f->ahb_addr); in nxp_fspi_remove()
1280 struct nxp_fspi *f = dev_get_drvdata(dev); in nxp_fspi_resume() local
1282 nxp_fspi_default_setup(f); in nxp_fspi_resume()