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
18 #include <linux/spi/spi-mem.h>
25 #define CDNS_XSPI_NAME "cadence-xspi"
29 * configure XSPI controller pin-strap settings
152 FIELD_PREP(CDNS_XSPI_CMD_P1_R1_ADDR0, (op)->addr.val & 0xff))
155 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR1, ((op)->addr.val >> 8) & 0xFF) | \
156 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR2, ((op)->addr.val >> 16) & 0xFF) | \
157 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR3, ((op)->addr.val >> 24) & 0xFF) | \
158 FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR4, ((op)->addr.val >> 32) & 0xFF))
161 FIELD_PREP(CDNS_XSPI_CMD_P1_R3_ADDR5, ((op)->addr.val >> 40) & 0xFF) | \
162 FIELD_PREP(CDNS_XSPI_CMD_P1_R3_CMD, (op)->cmd.opcode) | \
163 FIELD_PREP(CDNS_XSPI_CMD_P1_R3_NUM_ADDR_BYTES, (op)->addr.nbytes))
166 FIELD_PREP(CDNS_XSPI_CMD_P1_R4_ADDR_IOS, ilog2((op)->addr.buswidth)) | \
167 FIELD_PREP(CDNS_XSPI_CMD_P1_R4_CMD_IOS, ilog2((op)->cmd.buswidth)) | \
174 FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R2_DCNT_L, (op)->data.nbytes & 0xFFFF)
178 ((op)->data.nbytes >> 16) & 0xffff) | \
180 (op)->dummy.buswidth != 0 ? \
181 (((op)->dummy.nbytes * 8) / (op)->dummy.buswidth) : \
187 ilog2((op)->data.buswidth)) | \
189 ((op)->data.dir == SPI_MEM_DATA_IN) ? \
235 return readl_relaxed_poll_timeout(cdns_xspi->iobase + in cdns_xspi_wait_for_controller_idle()
246 writel(cmd_regs[5], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_5); in cdns_xspi_trigger_command()
247 writel(cmd_regs[4], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_4); in cdns_xspi_trigger_command()
248 writel(cmd_regs[3], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_3); in cdns_xspi_trigger_command()
249 writel(cmd_regs[2], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_2); in cdns_xspi_trigger_command()
250 writel(cmd_regs[1], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_1); in cdns_xspi_trigger_command()
251 writel(cmd_regs[0], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_0); in cdns_xspi_trigger_command()
257 u32 cmd_status = readl(cdns_xspi->iobase + CDNS_XSPI_CMD_STATUS_REG); in cdns_xspi_check_command_status()
262 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
264 ret = -EPROTO; in cdns_xspi_check_command_status()
267 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
269 ret = -EPROTO; in cdns_xspi_check_command_status()
272 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
274 ret = -EPROTO; in cdns_xspi_check_command_status()
277 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
279 ret = -EPROTO; in cdns_xspi_check_command_status()
283 dev_err(cdns_xspi->dev, "Fatal err - command not completed\n"); in cdns_xspi_check_command_status()
284 ret = -EPROTO; in cdns_xspi_check_command_status()
295 intr_enable = readl(cdns_xspi->iobase + CDNS_XSPI_INTR_ENABLE_REG); in cdns_xspi_set_interrupts()
300 writel(intr_enable, cdns_xspi->iobase + CDNS_XSPI_INTR_ENABLE_REG); in cdns_xspi_set_interrupts()
309 ctrl_ver = readl(cdns_xspi->iobase + CDNS_XSPI_CTRL_VERSION_REG); in cdns_xspi_controller_init()
312 dev_err(cdns_xspi->dev, in cdns_xspi_controller_init()
313 "Incorrect XSPI magic number: %x, expected: %x\n", in cdns_xspi_controller_init()
315 return -EIO; in cdns_xspi_controller_init()
318 ctrl_features = readl(cdns_xspi->iobase + CDNS_XSPI_CTRL_FEATURES_REG); in cdns_xspi_controller_init()
319 cdns_xspi->hw_num_banks = FIELD_GET(CDNS_XSPI_NUM_BANKS, ctrl_features); in cdns_xspi_controller_init()
330 sdma_size = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_SIZE_REG); in cdns_xspi_sdma_handle()
331 sdma_trd_info = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_TRD_INFO_REG); in cdns_xspi_sdma_handle()
336 ioread8_rep(cdns_xspi->sdmabase, in cdns_xspi_sdma_handle()
337 cdns_xspi->in_buffer, sdma_size); in cdns_xspi_sdma_handle()
341 iowrite8_rep(cdns_xspi->sdmabase, in cdns_xspi_sdma_handle()
342 cdns_xspi->out_buffer, sdma_size); in cdns_xspi_sdma_handle()
357 return -EIO; in cdns_xspi_send_stig_command()
360 cdns_xspi->iobase + CDNS_XSPI_CTRL_CONFIG_REG); in cdns_xspi_send_stig_command()
363 cdns_xspi->sdma_error = false; in cdns_xspi_send_stig_command()
370 cdns_xspi->cur_cs); in cdns_xspi_send_stig_command()
380 cdns_xspi->cur_cs); in cdns_xspi_send_stig_command()
382 cdns_xspi->in_buffer = op->data.buf.in; in cdns_xspi_send_stig_command()
383 cdns_xspi->out_buffer = op->data.buf.out; in cdns_xspi_send_stig_command()
387 wait_for_completion(&cdns_xspi->sdma_complete); in cdns_xspi_send_stig_command()
388 if (cdns_xspi->sdma_error) { in cdns_xspi_send_stig_command()
390 return -EIO; in cdns_xspi_send_stig_command()
395 wait_for_completion(&cdns_xspi->cmd_complete); in cdns_xspi_send_stig_command()
400 return -EPROTO; in cdns_xspi_send_stig_command()
409 enum spi_mem_data_dir dir = op->data.dir; in cdns_xspi_mem_op()
411 if (cdns_xspi->cur_cs != spi_get_chipselect(mem->spi, 0)) in cdns_xspi_mem_op()
412 cdns_xspi->cur_cs = spi_get_chipselect(mem->spi, 0); in cdns_xspi_mem_op()
422 spi_controller_get_devdata(mem->spi->controller); in cdns_xspi_mem_op_execute()
433 spi_controller_get_devdata(mem->spi->controller); in cdns_xspi_adjust_mem_op_size()
435 op->data.nbytes = clamp_val(op->data.nbytes, 0, cdns_xspi->sdmasize); in cdns_xspi_adjust_mem_op_size()
451 irq_status = readl(cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); in cdns_xspi_irq_handler()
452 writel(irq_status, cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); in cdns_xspi_irq_handler()
458 dev_err(cdns_xspi->dev, in cdns_xspi_irq_handler()
460 cdns_xspi->sdma_error = true; in cdns_xspi_irq_handler()
461 complete(&cdns_xspi->sdma_complete); in cdns_xspi_irq_handler()
465 complete(&cdns_xspi->sdma_complete); in cdns_xspi_irq_handler()
468 complete(&cdns_xspi->cmd_complete); in cdns_xspi_irq_handler()
473 irq_status = readl(cdns_xspi->iobase + CDNS_XSPI_TRD_COMP_INTR_STATUS); in cdns_xspi_irq_handler()
476 cdns_xspi->iobase + CDNS_XSPI_TRD_COMP_INTR_STATUS); in cdns_xspi_irq_handler()
478 complete(&cdns_xspi->auto_cmd_complete); in cdns_xspi_irq_handler()
488 struct device_node *node_prop = pdev->dev.of_node; in cdns_xspi_of_get_plat_data()
497 dev_err(&pdev->dev, "Couldn't get memory chip select\n"); in cdns_xspi_of_get_plat_data()
499 return -ENXIO; in cdns_xspi_of_get_plat_data()
501 dev_err(&pdev->dev, "reg (cs) parameter value too large\n"); in cdns_xspi_of_get_plat_data()
503 return -ENXIO; in cdns_xspi_of_get_plat_data()
512 struct device *dev = cdns_xspi->dev; in cdns_xspi_print_phy_config()
516 readl(cdns_xspi->iobase + CDNS_XSPI_DLL_PHY_CTRL)); in cdns_xspi_print_phy_config()
518 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DQ_TIMING)); in cdns_xspi_print_phy_config()
520 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DQS_TIMING)); in cdns_xspi_print_phy_config()
522 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_GATE_LPBCK_CTRL)); in cdns_xspi_print_phy_config()
524 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DLL_SLAVE_CTRL)); in cdns_xspi_print_phy_config()
529 struct device *dev = &pdev->dev; in cdns_xspi_probe()
537 return -ENOMEM; in cdns_xspi_probe()
539 host->mode_bits = SPI_3WIRE | SPI_TX_DUAL | SPI_TX_QUAD | in cdns_xspi_probe()
543 host->mem_ops = &cadence_xspi_mem_ops; in cdns_xspi_probe()
544 host->dev.of_node = pdev->dev.of_node; in cdns_xspi_probe()
545 host->bus_num = -1; in cdns_xspi_probe()
550 cdns_xspi->pdev = pdev; in cdns_xspi_probe()
551 cdns_xspi->dev = &pdev->dev; in cdns_xspi_probe()
552 cdns_xspi->cur_cs = 0; in cdns_xspi_probe()
554 init_completion(&cdns_xspi->cmd_complete); in cdns_xspi_probe()
555 init_completion(&cdns_xspi->auto_cmd_complete); in cdns_xspi_probe()
556 init_completion(&cdns_xspi->sdma_complete); in cdns_xspi_probe()
560 return -ENODEV; in cdns_xspi_probe()
562 cdns_xspi->iobase = devm_platform_ioremap_resource_byname(pdev, "io"); in cdns_xspi_probe()
563 if (IS_ERR(cdns_xspi->iobase)) { in cdns_xspi_probe()
565 return PTR_ERR(cdns_xspi->iobase); in cdns_xspi_probe()
569 cdns_xspi->sdmabase = devm_ioremap_resource(dev, res); in cdns_xspi_probe()
570 if (IS_ERR(cdns_xspi->sdmabase)) in cdns_xspi_probe()
571 return PTR_ERR(cdns_xspi->sdmabase); in cdns_xspi_probe()
572 cdns_xspi->sdmasize = resource_size(res); in cdns_xspi_probe()
574 cdns_xspi->auxbase = devm_platform_ioremap_resource_byname(pdev, "aux"); in cdns_xspi_probe()
575 if (IS_ERR(cdns_xspi->auxbase)) { in cdns_xspi_probe()
577 return PTR_ERR(cdns_xspi->auxbase); in cdns_xspi_probe()
580 cdns_xspi->irq = platform_get_irq(pdev, 0); in cdns_xspi_probe()
581 if (cdns_xspi->irq < 0) in cdns_xspi_probe()
582 return -ENXIO; in cdns_xspi_probe()
584 ret = devm_request_irq(dev, cdns_xspi->irq, cdns_xspi_irq_handler, in cdns_xspi_probe()
585 IRQF_SHARED, pdev->name, cdns_xspi); in cdns_xspi_probe()
587 dev_err(dev, "Failed to request IRQ: %d\n", cdns_xspi->irq); in cdns_xspi_probe()
599 host->num_chipselect = 1 << cdns_xspi->hw_num_banks; in cdns_xspi_probe()
614 .compatible = "cdns,xspi-nor",
630 MODULE_DESCRIPTION("Cadence XSPI Controller Driver");