Lines Matching refs:cdns_xspi

235 static int cdns_xspi_wait_for_controller_idle(struct cdns_xspi_dev *cdns_xspi)  in cdns_xspi_wait_for_controller_idle()  argument
239 return readl_relaxed_poll_timeout(cdns_xspi->iobase + in cdns_xspi_wait_for_controller_idle()
247 static void cdns_xspi_trigger_command(struct cdns_xspi_dev *cdns_xspi, in cdns_xspi_trigger_command() argument
250 writel(cmd_regs[5], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_5); in cdns_xspi_trigger_command()
251 writel(cmd_regs[4], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_4); in cdns_xspi_trigger_command()
252 writel(cmd_regs[3], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_3); in cdns_xspi_trigger_command()
253 writel(cmd_regs[2], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_2); in cdns_xspi_trigger_command()
254 writel(cmd_regs[1], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_1); in cdns_xspi_trigger_command()
255 writel(cmd_regs[0], cdns_xspi->iobase + CDNS_XSPI_CMD_REG_0); in cdns_xspi_trigger_command()
258 static int cdns_xspi_check_command_status(struct cdns_xspi_dev *cdns_xspi) in cdns_xspi_check_command_status() argument
261 u32 cmd_status = readl(cdns_xspi->iobase + CDNS_XSPI_CMD_STATUS_REG); in cdns_xspi_check_command_status()
266 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
271 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
276 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
281 dev_err(cdns_xspi->dev, in cdns_xspi_check_command_status()
287 dev_err(cdns_xspi->dev, "Fatal err - command not completed\n"); in cdns_xspi_check_command_status()
294 static void cdns_xspi_set_interrupts(struct cdns_xspi_dev *cdns_xspi, in cdns_xspi_set_interrupts() argument
299 intr_enable = readl(cdns_xspi->iobase + CDNS_XSPI_INTR_ENABLE_REG); in cdns_xspi_set_interrupts()
304 writel(intr_enable, cdns_xspi->iobase + CDNS_XSPI_INTR_ENABLE_REG); in cdns_xspi_set_interrupts()
307 static int cdns_xspi_controller_init(struct cdns_xspi_dev *cdns_xspi) in cdns_xspi_controller_init() argument
313 ctrl_ver = readl(cdns_xspi->iobase + CDNS_XSPI_CTRL_VERSION_REG); in cdns_xspi_controller_init()
316 dev_err(cdns_xspi->dev, in cdns_xspi_controller_init()
322 ctrl_features = readl(cdns_xspi->iobase + CDNS_XSPI_CTRL_FEATURES_REG); in cdns_xspi_controller_init()
323 cdns_xspi->hw_num_banks = FIELD_GET(CDNS_XSPI_NUM_BANKS, ctrl_features); in cdns_xspi_controller_init()
324 cdns_xspi_set_interrupts(cdns_xspi, false); in cdns_xspi_controller_init()
329 static void cdns_xspi_sdma_handle(struct cdns_xspi_dev *cdns_xspi) in cdns_xspi_sdma_handle() argument
334 sdma_size = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_SIZE_REG); in cdns_xspi_sdma_handle()
335 sdma_trd_info = readl(cdns_xspi->iobase + CDNS_XSPI_SDMA_TRD_INFO_REG); in cdns_xspi_sdma_handle()
340 ioread8_rep(cdns_xspi->sdmabase, in cdns_xspi_sdma_handle()
341 cdns_xspi->in_buffer, sdma_size); in cdns_xspi_sdma_handle()
345 iowrite8_rep(cdns_xspi->sdmabase, in cdns_xspi_sdma_handle()
346 cdns_xspi->out_buffer, sdma_size); in cdns_xspi_sdma_handle()
351 static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, in cdns_xspi_send_stig_command() argument
360 ret = cdns_xspi_wait_for_controller_idle(cdns_xspi); in cdns_xspi_send_stig_command()
365 cdns_xspi->iobase + CDNS_XSPI_CTRL_CONFIG_REG); in cdns_xspi_send_stig_command()
367 cdns_xspi_set_interrupts(cdns_xspi, true); in cdns_xspi_send_stig_command()
368 cdns_xspi->sdma_error = false; in cdns_xspi_send_stig_command()
380 cdns_xspi->cur_cs); in cdns_xspi_send_stig_command()
382 cdns_xspi_trigger_command(cdns_xspi, cmd_regs); in cdns_xspi_send_stig_command()
390 cdns_xspi->cur_cs); in cdns_xspi_send_stig_command()
392 cdns_xspi->in_buffer = op->data.buf.in; in cdns_xspi_send_stig_command()
393 cdns_xspi->out_buffer = op->data.buf.out; in cdns_xspi_send_stig_command()
395 cdns_xspi_trigger_command(cdns_xspi, cmd_regs); in cdns_xspi_send_stig_command()
397 wait_for_completion(&cdns_xspi->sdma_complete); in cdns_xspi_send_stig_command()
398 if (cdns_xspi->sdma_error) { in cdns_xspi_send_stig_command()
399 cdns_xspi_set_interrupts(cdns_xspi, false); in cdns_xspi_send_stig_command()
402 cdns_xspi_sdma_handle(cdns_xspi); in cdns_xspi_send_stig_command()
405 wait_for_completion(&cdns_xspi->cmd_complete); in cdns_xspi_send_stig_command()
406 cdns_xspi_set_interrupts(cdns_xspi, false); in cdns_xspi_send_stig_command()
408 cmd_status = cdns_xspi_check_command_status(cdns_xspi); in cdns_xspi_send_stig_command()
415 static int cdns_xspi_mem_op(struct cdns_xspi_dev *cdns_xspi, in cdns_xspi_mem_op() argument
421 if (cdns_xspi->cur_cs != spi_get_chipselect(mem->spi, 0)) in cdns_xspi_mem_op()
422 cdns_xspi->cur_cs = spi_get_chipselect(mem->spi, 0); in cdns_xspi_mem_op()
424 return cdns_xspi_send_stig_command(cdns_xspi, op, in cdns_xspi_mem_op()
431 struct cdns_xspi_dev *cdns_xspi = in cdns_xspi_mem_op_execute() local
435 ret = cdns_xspi_mem_op(cdns_xspi, mem, op); in cdns_xspi_mem_op_execute()
442 struct cdns_xspi_dev *cdns_xspi = in cdns_xspi_adjust_mem_op_size() local
445 op->data.nbytes = clamp_val(op->data.nbytes, 0, cdns_xspi->sdmasize); in cdns_xspi_adjust_mem_op_size()
457 struct cdns_xspi_dev *cdns_xspi = dev; in cdns_xspi_irq_handler() local
461 irq_status = readl(cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); in cdns_xspi_irq_handler()
462 writel(irq_status, cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG); in cdns_xspi_irq_handler()
468 dev_err(cdns_xspi->dev, in cdns_xspi_irq_handler()
470 cdns_xspi->sdma_error = true; in cdns_xspi_irq_handler()
471 complete(&cdns_xspi->sdma_complete); in cdns_xspi_irq_handler()
475 complete(&cdns_xspi->sdma_complete); in cdns_xspi_irq_handler()
478 complete(&cdns_xspi->cmd_complete); in cdns_xspi_irq_handler()
483 irq_status = readl(cdns_xspi->iobase + CDNS_XSPI_TRD_COMP_INTR_STATUS); in cdns_xspi_irq_handler()
486 cdns_xspi->iobase + CDNS_XSPI_TRD_COMP_INTR_STATUS); in cdns_xspi_irq_handler()
488 complete(&cdns_xspi->auto_cmd_complete); in cdns_xspi_irq_handler()
520 static void cdns_xspi_print_phy_config(struct cdns_xspi_dev *cdns_xspi) in cdns_xspi_print_phy_config() argument
522 struct device *dev = cdns_xspi->dev; in cdns_xspi_print_phy_config()
526 readl(cdns_xspi->iobase + CDNS_XSPI_DLL_PHY_CTRL)); in cdns_xspi_print_phy_config()
528 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DQ_TIMING)); in cdns_xspi_print_phy_config()
530 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DQS_TIMING)); in cdns_xspi_print_phy_config()
532 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_GATE_LPBCK_CTRL)); in cdns_xspi_print_phy_config()
534 readl(cdns_xspi->auxbase + CDNS_XSPI_CCP_PHY_DLL_SLAVE_CTRL)); in cdns_xspi_print_phy_config()
541 struct cdns_xspi_dev *cdns_xspi = NULL; in cdns_xspi_probe() local
545 host = devm_spi_alloc_host(dev, sizeof(*cdns_xspi)); in cdns_xspi_probe()
559 cdns_xspi = spi_controller_get_devdata(host); in cdns_xspi_probe()
560 cdns_xspi->pdev = pdev; in cdns_xspi_probe()
561 cdns_xspi->dev = &pdev->dev; in cdns_xspi_probe()
562 cdns_xspi->cur_cs = 0; in cdns_xspi_probe()
564 init_completion(&cdns_xspi->cmd_complete); in cdns_xspi_probe()
565 init_completion(&cdns_xspi->auto_cmd_complete); in cdns_xspi_probe()
566 init_completion(&cdns_xspi->sdma_complete); in cdns_xspi_probe()
572 cdns_xspi->iobase = devm_platform_ioremap_resource_byname(pdev, "io"); in cdns_xspi_probe()
573 if (IS_ERR(cdns_xspi->iobase)) { in cdns_xspi_probe()
575 return PTR_ERR(cdns_xspi->iobase); in cdns_xspi_probe()
579 cdns_xspi->sdmabase = devm_ioremap_resource(dev, res); in cdns_xspi_probe()
580 if (IS_ERR(cdns_xspi->sdmabase)) in cdns_xspi_probe()
581 return PTR_ERR(cdns_xspi->sdmabase); in cdns_xspi_probe()
582 cdns_xspi->sdmasize = resource_size(res); in cdns_xspi_probe()
584 cdns_xspi->auxbase = devm_platform_ioremap_resource_byname(pdev, "aux"); in cdns_xspi_probe()
585 if (IS_ERR(cdns_xspi->auxbase)) { in cdns_xspi_probe()
587 return PTR_ERR(cdns_xspi->auxbase); in cdns_xspi_probe()
590 cdns_xspi->irq = platform_get_irq(pdev, 0); in cdns_xspi_probe()
591 if (cdns_xspi->irq < 0) in cdns_xspi_probe()
594 ret = devm_request_irq(dev, cdns_xspi->irq, cdns_xspi_irq_handler, in cdns_xspi_probe()
595 IRQF_SHARED, pdev->name, cdns_xspi); in cdns_xspi_probe()
597 dev_err(dev, "Failed to request IRQ: %d\n", cdns_xspi->irq); in cdns_xspi_probe()
601 cdns_xspi_print_phy_config(cdns_xspi); in cdns_xspi_probe()
603 ret = cdns_xspi_controller_init(cdns_xspi); in cdns_xspi_probe()
609 host->num_chipselect = 1 << cdns_xspi->hw_num_banks; in cdns_xspi_probe()