Lines Matching +full:xspi +full:- +full:nor

1 // SPDX-License-Identifier: GPL-2.0+
2 // Cadence XSPI flash controller driver
3 // Copyright (C) 2020-21 Cadence
19 #include <linux/spi/spi-mem.h>
26 #define CDNS_XSPI_NAME "cadence-xspi"
30 * configure XSPI controller pin-strap settings
153 FIELD_PREP(CDNS_XSPI_CMD_P1_R1_ADDR0, (op)->addr.val & 0xff))
156 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR1, ((op)->addr.val >> 8) & 0xFF) | \
157 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR2, ((op)->addr.val >> 16) & 0xFF) | \
158 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR3, ((op)->addr.val >> 24) & 0xFF) | \
159 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR4, ((op)->addr.val >> 32) & 0xFF))
162 FIELD_PREP(CDNS_XSPI_CMD_P1_R3_ADDR5, ((op)->addr.val >> 40) & 0xFF) | \
163 FIELD_PREP(CDNS_XSPI_CMD_P1_R3_CMD, (op)->cmd.opcode) | \
164 FIELD_PREP(CDNS_XSPI_CMD_P1_R3_NUM_ADDR_BYTES, (op)->addr.nbytes))
167 FIELD_PREP(CDNS_XSPI_CMD_P1_R4_ADDR_IOS, ilog2((op)->addr.buswidth)) | \
168 FIELD_PREP(CDNS_XSPI_CMD_P1_R4_CMD_IOS, ilog2((op)->cmd.buswidth)) | \
175 FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R2_DCNT_L, (op)->data.nbytes & 0xFFFF)
179 ((op)->data.nbytes >> 16) & 0xffff) | \
180 FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R3_NUM_OF_DUMMY, (op)->dummy.nbytes * 8))
185 ilog2((op)->data.buswidth)) | \
187 ((op)->data.dir == SPI_MEM_DATA_IN) ? \
233 return readl_relaxed_poll_timeout(cdns_xspi->iobase + in cdns_xspi_wait_for_controller_idle()
244 writel(cmd_regs[5], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_5); in cdns_xspi_trigger_command()
245 writel(cmd_regs[4], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_4); in cdns_xspi_trigger_command()
246 writel(cmd_regs[3], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_3); in cdns_xspi_trigger_command()
247 writel(cmd_regs[2], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_2); in cdns_xspi_trigger_command()
248 writel(cmd_regs[1], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_1); in cdns_xspi_trigger_command()
249 writel(cmd_regs[0], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_0); in cdns_xspi_trigger_command()
255 u32 cmd_status = readl(cdns_xspi->iobase + CDNS_XSPI_CMD_STATUS_REG); in cdns_xspi_check_command_status()
260 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
262 ret = -EPROTO; in cdns_xspi_check_command_status()
265 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
267 ret = -EPROTO; in cdns_xspi_check_command_status()
270 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
272 ret = -EPROTO; in cdns_xspi_check_command_status()
275 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
277 ret = -EPROTO; in cdns_xspi_check_command_status()
281 dev_err(cdns_xspi->dev, "Fatal err - command not completed\n"); in cdns_xspi_check_command_status()
282 ret = -EPROTO; in cdns_xspi_check_command_status()
293 intr_enable = readl(cdns_xspi->iobase + CDNS_XSPI_INTR_ENABLE_REG); in cdns_xspi_set_interrupts()
298 writel(intr_enable, cdns_xspi->iobase + CDNS_XSPI_INTR_ENABLE_REG); in cdns_xspi_set_interrupts()
307 ctrl_ver = readl(cdns_xspi->iobase + CDNS_XSPI_CTRL_VERSION_REG); in cdns_xspi_controller_init()
310 dev_err(cdns_xspi->dev, in cdns_xspi_controller_init()
311 "Incorrect XSPI magic number: %x, expected: %x\n", in cdns_xspi_controller_init()
313 return -EIO; in cdns_xspi_controller_init()
316 ctrl_features = readl(cdns_xspi->iobase + CDNS_XSPI_CTRL_FEATURES_REG); in cdns_xspi_controller_init()
317 cdns_xspi->hw_num_banks = FIELD_GET(CDNS_XSPI_NUM_BANKS, ctrl_features); in cdns_xspi_controller_init()
328 sdma_size = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_SIZE_REG); in cdns_xspi_sdma_handle()
329 sdma_trd_info = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_TRD_INFO_REG); in cdns_xspi_sdma_handle()
334 ioread8_rep(cdns_xspi->sdmabase, in cdns_xspi_sdma_handle()
335 cdns_xspi->in_buffer, sdma_size); in cdns_xspi_sdma_handle()
339 iowrite8_rep(cdns_xspi->sdmabase, in cdns_xspi_sdma_handle()
340 cdns_xspi->out_buffer, sdma_size); in cdns_xspi_sdma_handle()
355 return -EIO; in cdns_xspi_send_stig_command()
358 cdns_xspi->iobase + CDNS_XSPI_CTRL_CONFIG_REG); in cdns_xspi_send_stig_command()
361 cdns_xspi->sdma_error = false; in cdns_xspi_send_stig_command()
368 cdns_xspi->cur_cs); in cdns_xspi_send_stig_command()
378 cdns_xspi->cur_cs); in cdns_xspi_send_stig_command()
380 cdns_xspi->in_buffer = op->data.buf.in; in cdns_xspi_send_stig_command()
381 cdns_xspi->out_buffer = op->data.buf.out; in cdns_xspi_send_stig_command()
385 wait_for_completion(&cdns_xspi->sdma_complete); in cdns_xspi_send_stig_command()
386 if (cdns_xspi->sdma_error) { in cdns_xspi_send_stig_command()
388 return -EIO; in cdns_xspi_send_stig_command()
393 wait_for_completion(&cdns_xspi->cmd_complete); in cdns_xspi_send_stig_command()
398 return -EPROTO; in cdns_xspi_send_stig_command()
407 enum spi_mem_data_dir dir = op->data.dir; in cdns_xspi_mem_op()
409 if (cdns_xspi->cur_cs != mem->spi->chip_select) in cdns_xspi_mem_op()
410 cdns_xspi->cur_cs = mem->spi->chip_select; in cdns_xspi_mem_op()
420 spi_master_get_devdata(mem->spi->master); in cdns_xspi_mem_op_execute()
431 spi_master_get_devdata(mem->spi->master); in cdns_xspi_adjust_mem_op_size()
433 op->data.nbytes = clamp_val(op->data.nbytes, 0, cdns_xspi->sdmasize); in cdns_xspi_adjust_mem_op_size()
449 irq_status = readl(cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); in cdns_xspi_irq_handler()
450 writel(irq_status, cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); in cdns_xspi_irq_handler()
456 dev_err(cdns_xspi->dev, in cdns_xspi_irq_handler()
458 cdns_xspi->sdma_error = true; in cdns_xspi_irq_handler()
459 complete(&cdns_xspi->sdma_complete); in cdns_xspi_irq_handler()
463 complete(&cdns_xspi->sdma_complete); in cdns_xspi_irq_handler()
466 complete(&cdns_xspi->cmd_complete); in cdns_xspi_irq_handler()
471 irq_status = readl(cdns_xspi->iobase + CDNS_XSPI_TRD_COMP_INTR_STATUS); in cdns_xspi_irq_handler()
474 cdns_xspi->iobase + CDNS_XSPI_TRD_COMP_INTR_STATUS); in cdns_xspi_irq_handler()
476 complete(&cdns_xspi->auto_cmd_complete); in cdns_xspi_irq_handler()
486 struct device_node *node_prop = pdev->dev.of_node; in cdns_xspi_of_get_plat_data()
495 dev_err(&pdev->dev, "Couldn't get memory chip select\n"); in cdns_xspi_of_get_plat_data()
497 return -ENXIO; in cdns_xspi_of_get_plat_data()
499 dev_err(&pdev->dev, "reg (cs) parameter value too large\n"); in cdns_xspi_of_get_plat_data()
501 return -ENXIO; in cdns_xspi_of_get_plat_data()
510 struct device *dev = cdns_xspi->dev; in cdns_xspi_print_phy_config()
514 readl(cdns_xspi->iobase + CDNS_XSPI_DLL_PHY_CTRL)); in cdns_xspi_print_phy_config()
516 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DQ_TIMING)); in cdns_xspi_print_phy_config()
518 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DQS_TIMING)); in cdns_xspi_print_phy_config()
520 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_GATE_LPBCK_CTRL)); in cdns_xspi_print_phy_config()
522 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DLL_SLAVE_CTRL)); in cdns_xspi_print_phy_config()
527 struct device *dev = &pdev->dev; in cdns_xspi_probe()
535 return -ENOMEM; in cdns_xspi_probe()
537 master->mode_bits = SPI_3WIRE | SPI_TX_DUAL | SPI_TX_QUAD | in cdns_xspi_probe()
541 master->mem_ops = &cadence_xspi_mem_ops; in cdns_xspi_probe()
542 master->dev.of_node = pdev->dev.of_node; in cdns_xspi_probe()
543 master->bus_num = -1; in cdns_xspi_probe()
548 cdns_xspi->pdev = pdev; in cdns_xspi_probe()
549 cdns_xspi->dev = &pdev->dev; in cdns_xspi_probe()
550 cdns_xspi->cur_cs = 0; in cdns_xspi_probe()
552 init_completion(&cdns_xspi->cmd_complete); in cdns_xspi_probe()
553 init_completion(&cdns_xspi->auto_cmd_complete); in cdns_xspi_probe()
554 init_completion(&cdns_xspi->sdma_complete); in cdns_xspi_probe()
558 return -ENODEV; in cdns_xspi_probe()
560 cdns_xspi->iobase = devm_platform_ioremap_resource_byname(pdev, "io"); in cdns_xspi_probe()
561 if (IS_ERR(cdns_xspi->iobase)) { in cdns_xspi_probe()
563 return PTR_ERR(cdns_xspi->iobase); in cdns_xspi_probe()
567 cdns_xspi->sdmabase = devm_ioremap_resource(dev, res); in cdns_xspi_probe()
568 if (IS_ERR(cdns_xspi->sdmabase)) in cdns_xspi_probe()
569 return PTR_ERR(cdns_xspi->sdmabase); in cdns_xspi_probe()
570 cdns_xspi->sdmasize = resource_size(res); in cdns_xspi_probe()
572 cdns_xspi->auxbase = devm_platform_ioremap_resource_byname(pdev, "aux"); in cdns_xspi_probe()
573 if (IS_ERR(cdns_xspi->auxbase)) { in cdns_xspi_probe()
575 return PTR_ERR(cdns_xspi->auxbase); in cdns_xspi_probe()
578 cdns_xspi->irq = platform_get_irq(pdev, 0); in cdns_xspi_probe()
579 if (cdns_xspi->irq < 0) in cdns_xspi_probe()
580 return -ENXIO; in cdns_xspi_probe()
582 ret = devm_request_irq(dev, cdns_xspi->irq, cdns_xspi_irq_handler, in cdns_xspi_probe()
583 IRQF_SHARED, pdev->name, cdns_xspi); in cdns_xspi_probe()
585 dev_err(dev, "Failed to request IRQ: %d\n", cdns_xspi->irq); in cdns_xspi_probe()
597 master->num_chipselect = 1 << cdns_xspi->hw_num_banks; in cdns_xspi_probe()
613 .compatible = "cdns,xspi-nor",
633 MODULE_DESCRIPTION("Cadence XSPI Controller Driver");