Lines Matching full:mcspi
3 * OMAP2 McSPI controller driver
32 #include <linux/platform_data/spi-omap2-mcspi.h>
152 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in mcspi_write_reg() local
154 writel_relaxed(val, mcspi->base + idx); in mcspi_write_reg()
159 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in mcspi_read_reg() local
161 return readl_relaxed(mcspi->base + idx); in mcspi_read_reg()
243 struct omap2_mcspi *mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_set_cs() local
254 int err = pm_runtime_resume_and_get(mcspi->dev); in omap2_mcspi_set_cs()
256 dev_err(mcspi->dev, "failed to get sync: %d\n", err); in omap2_mcspi_set_cs()
263 if (mcspi->use_multi_mode) { in omap2_mcspi_set_cs()
274 pm_runtime_mark_last_busy(mcspi->dev); in omap2_mcspi_set_cs()
275 pm_runtime_put_autosuspend(mcspi->dev); in omap2_mcspi_set_cs()
281 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_set_mode() local
282 struct omap2_mcspi_regs *ctx = &mcspi->ctx; in omap2_mcspi_set_mode()
296 if (mcspi->use_multi_mode) in omap2_mcspi_set_mode()
311 struct omap2_mcspi *mcspi; in omap2_mcspi_set_fifo() local
316 mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_set_fifo()
346 mcspi->fifo_depth = max_fifo_depth; in omap2_mcspi_set_fifo()
359 mcspi->fifo_depth = 0; in omap2_mcspi_set_fifo()
379 static int mcspi_wait_for_completion(struct omap2_mcspi *mcspi, in mcspi_wait_for_completion() argument
382 if (spi_controller_is_target(mcspi->ctlr)) { in mcspi_wait_for_completion()
384 mcspi->target_aborted) in mcspi_wait_for_completion()
396 struct omap2_mcspi *mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_rx_callback() local
397 struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi_get_chipselect(spi, 0)]; in omap2_mcspi_rx_callback()
408 struct omap2_mcspi *mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_tx_callback() local
409 struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi_get_chipselect(spi, 0)]; in omap2_mcspi_tx_callback()
421 struct omap2_mcspi *mcspi; in omap2_mcspi_tx_dma() local
425 mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_tx_dma()
426 mcspi_dma = &mcspi->dma_channels[spi_get_chipselect(spi, 0)]; in omap2_mcspi_tx_dma()
450 struct omap2_mcspi *mcspi; in omap2_mcspi_rx_dma() local
463 mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_rx_dma()
464 mcspi_dma = &mcspi->dma_channels[spi_get_chipselect(spi, 0)]; in omap2_mcspi_rx_dma()
472 if (mcspi->fifo_depth == 0) in omap2_mcspi_rx_dma()
489 * Reduce DMA transfer length by one more if McSPI is in omap2_mcspi_rx_dma()
492 if ((l & OMAP2_MCSPI_CHCONF_TURBO) && mcspi->fifo_depth == 0) in omap2_mcspi_rx_dma()
531 ret = mcspi_wait_for_completion(mcspi, &mcspi_dma->dma_rx_completion); in omap2_mcspi_rx_dma()
532 if (ret || mcspi->target_aborted) { in omap2_mcspi_rx_dma()
541 if (mcspi->fifo_depth > 0) in omap2_mcspi_rx_dma()
595 struct omap2_mcspi *mcspi; in omap2_mcspi_txrx_dma() local
608 mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_txrx_dma()
609 mcspi_dma = &mcspi->dma_channels[spi_get_chipselect(spi, 0)]; in omap2_mcspi_txrx_dma()
635 mcspi->target_aborted = false; in omap2_mcspi_txrx_dma()
638 reinit_completion(&mcspi->txdone); in omap2_mcspi_txrx_dma()
654 ret = mcspi_wait_for_completion(mcspi, &mcspi_dma->dma_tx_completion); in omap2_mcspi_txrx_dma()
655 if (ret || mcspi->target_aborted) { in omap2_mcspi_txrx_dma()
661 if (spi_controller_is_target(mcspi->ctlr)) { in omap2_mcspi_txrx_dma()
662 ret = mcspi_wait_for_completion(mcspi, &mcspi->txdone); in omap2_mcspi_txrx_dma()
663 if (ret || mcspi->target_aborted) in omap2_mcspi_txrx_dma()
667 if (mcspi->fifo_depth > 0) { in omap2_mcspi_txrx_dma()
668 irqstat_reg = mcspi->base + OMAP2_MCSPI_IRQSTATUS; in omap2_mcspi_txrx_dma()
674 mcspi_write_reg(mcspi->ctlr, OMAP2_MCSPI_IRQSTATUS, in omap2_mcspi_txrx_dma()
681 if (mcspi->fifo_depth > 0) { in omap2_mcspi_txrx_dma()
914 struct omap2_mcspi *mcspi; in omap2_mcspi_setup_transfer() local
919 mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_setup_transfer()
929 ref_clk_hz = mcspi->ref_clk_hz; in omap2_mcspi_setup_transfer()
948 if (mcspi->pin_dir == MCSPI_PINDIR_D0_IN_D1_OUT) { in omap2_mcspi_setup_transfer()
1007 static int omap2_mcspi_request_dma(struct omap2_mcspi *mcspi, in omap2_mcspi_request_dma() argument
1012 mcspi_dma->dma_rx = dma_request_chan(mcspi->dev, in omap2_mcspi_request_dma()
1020 mcspi_dma->dma_tx = dma_request_chan(mcspi->dev, in omap2_mcspi_request_dma()
1038 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_release_dma() local
1043 mcspi_dma = &mcspi->dma_channels[i]; in omap2_mcspi_release_dma()
1073 struct omap2_mcspi *mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_setup() local
1074 struct omap2_mcspi_regs *ctx = &mcspi->ctx; in omap2_mcspi_setup()
1081 cs->base = mcspi->base + spi_get_chipselect(spi, 0) * 0x14; in omap2_mcspi_setup()
1082 cs->phys = mcspi->phys + spi_get_chipselect(spi, 0) * 0x14; in omap2_mcspi_setup()
1092 ret = pm_runtime_resume_and_get(mcspi->dev); in omap2_mcspi_setup()
1104 pm_runtime_mark_last_busy(mcspi->dev); in omap2_mcspi_setup()
1105 pm_runtime_put_autosuspend(mcspi->dev); in omap2_mcspi_setup()
1112 struct omap2_mcspi *mcspi = data; in omap2_mcspi_irq_handler() local
1115 irqstat = mcspi_read_reg(mcspi->ctlr, OMAP2_MCSPI_IRQSTATUS); in omap2_mcspi_irq_handler()
1120 mcspi_write_reg(mcspi->ctlr, OMAP2_MCSPI_IRQENABLE, 0); in omap2_mcspi_irq_handler()
1122 complete(&mcspi->txdone); in omap2_mcspi_irq_handler()
1129 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_target_abort() local
1130 struct omap2_mcspi_dma *mcspi_dma = mcspi->dma_channels; in omap2_mcspi_target_abort()
1132 mcspi->target_aborted = true; in omap2_mcspi_target_abort()
1135 complete(&mcspi->txdone); in omap2_mcspi_target_abort()
1152 struct omap2_mcspi *mcspi; in omap2_mcspi_transfer_one() local
1160 mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_transfer_one()
1161 mcspi_dma = mcspi->dma_channels + spi_get_chipselect(spi, 0); in omap2_mcspi_transfer_one()
1237 if (mcspi->fifo_depth > 0) in omap2_mcspi_transfer_one()
1252 if (mcspi->fifo_depth > 0 && t) in omap2_mcspi_transfer_one()
1261 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_prepare_message() local
1262 struct omap2_mcspi_regs *ctx = &mcspi->ctx; in omap2_mcspi_prepare_message()
1271 mcspi->use_multi_mode = true; in omap2_mcspi_prepare_message()
1287 mcspi->use_multi_mode = false; in omap2_mcspi_prepare_message()
1292 mcspi->use_multi_mode = false; in omap2_mcspi_prepare_message()
1300 if (!mcspi->use_multi_mode) in omap2_mcspi_prepare_message()
1314 if (msg->spi->controller_state == cs && !mcspi->use_multi_mode) { in omap2_mcspi_prepare_message()
1333 struct omap2_mcspi *mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_can_dma() local
1335 &mcspi->dma_channels[spi_get_chipselect(spi, 0)]; in omap2_mcspi_can_dma()
1351 struct omap2_mcspi *mcspi = spi_controller_get_devdata(spi->controller); in omap2_mcspi_max_xfer_size() local
1353 &mcspi->dma_channels[spi_get_chipselect(spi, 0)]; in omap2_mcspi_max_xfer_size()
1355 if (mcspi->max_xfer_len && mcspi_dma->dma_rx) in omap2_mcspi_max_xfer_size()
1356 return mcspi->max_xfer_len; in omap2_mcspi_max_xfer_size()
1361 static int omap2_mcspi_controller_setup(struct omap2_mcspi *mcspi) in omap2_mcspi_controller_setup() argument
1363 struct spi_controller *ctlr = mcspi->ctlr; in omap2_mcspi_controller_setup()
1364 struct omap2_mcspi_regs *ctx = &mcspi->ctx; in omap2_mcspi_controller_setup()
1367 ret = pm_runtime_resume_and_get(mcspi->dev); in omap2_mcspi_controller_setup()
1376 pm_runtime_mark_last_busy(mcspi->dev); in omap2_mcspi_controller_setup()
1377 pm_runtime_put_autosuspend(mcspi->dev); in omap2_mcspi_controller_setup()
1400 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap_mcspi_runtime_resume() local
1401 struct omap2_mcspi_regs *ctx = &mcspi->ctx; in omap_mcspi_runtime_resume()
1409 /* McSPI: context restore */ in omap_mcspi_runtime_resume()
1449 .compatible = "ti,omap2-mcspi",
1453 .compatible = "ti,omap4-mcspi",
1457 .compatible = "ti,am654-mcspi",
1468 struct omap2_mcspi *mcspi; in omap2_mcspi_probe() local
1476 ctlr = spi_alloc_target(&pdev->dev, sizeof(*mcspi)); in omap2_mcspi_probe()
1478 ctlr = spi_alloc_host(&pdev->dev, sizeof(*mcspi)); in omap2_mcspi_probe()
1498 mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_probe()
1499 mcspi->ctlr = ctlr; in omap2_mcspi_probe()
1509 mcspi->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN; in omap2_mcspi_probe()
1513 mcspi->pin_dir = pdata->pin_dir; in omap2_mcspi_probe()
1517 mcspi->max_xfer_len = pdata->max_xfer_len; in omap2_mcspi_probe()
1521 mcspi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &r); in omap2_mcspi_probe()
1522 if (IS_ERR(mcspi->base)) { in omap2_mcspi_probe()
1523 status = PTR_ERR(mcspi->base); in omap2_mcspi_probe()
1526 mcspi->phys = r->start + regs_offset; in omap2_mcspi_probe()
1527 mcspi->base += regs_offset; in omap2_mcspi_probe()
1529 mcspi->dev = &pdev->dev; in omap2_mcspi_probe()
1531 INIT_LIST_HEAD(&mcspi->ctx.cs); in omap2_mcspi_probe()
1533 mcspi->dma_channels = devm_kcalloc(&pdev->dev, ctlr->num_chipselect, in omap2_mcspi_probe()
1536 if (mcspi->dma_channels == NULL) { in omap2_mcspi_probe()
1542 sprintf(mcspi->dma_channels[i].dma_rx_ch_name, "rx%d", i); in omap2_mcspi_probe()
1543 sprintf(mcspi->dma_channels[i].dma_tx_ch_name, "tx%d", i); in omap2_mcspi_probe()
1545 status = omap2_mcspi_request_dma(mcspi, in omap2_mcspi_probe()
1546 &mcspi->dma_channels[i]); in omap2_mcspi_probe()
1554 init_completion(&mcspi->txdone); in omap2_mcspi_probe()
1557 mcspi); in omap2_mcspi_probe()
1563 mcspi->ref_clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); in omap2_mcspi_probe()
1564 if (mcspi->ref_clk) in omap2_mcspi_probe()
1565 mcspi->ref_clk_hz = clk_get_rate(mcspi->ref_clk); in omap2_mcspi_probe()
1567 mcspi->ref_clk_hz = OMAP2_MCSPI_MAX_FREQ; in omap2_mcspi_probe()
1568 ctlr->max_speed_hz = mcspi->ref_clk_hz; in omap2_mcspi_probe()
1569 ctlr->min_speed_hz = mcspi->ref_clk_hz >> 15; in omap2_mcspi_probe()
1575 status = omap2_mcspi_controller_setup(mcspi); in omap2_mcspi_probe()
1598 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_remove() local
1602 pm_runtime_dont_use_autosuspend(mcspi->dev); in omap2_mcspi_remove()
1603 pm_runtime_put_sync(mcspi->dev); in omap2_mcspi_remove()
1613 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_suspend() local
1618 dev_warn(mcspi->dev, "%s: failed to set pins: %i\n", in omap2_mcspi_suspend()
1623 dev_warn(mcspi->dev, "%s: controller suspend failed: %i\n", in omap2_mcspi_suspend()
1632 struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); in omap2_mcspi_resume() local
1637 dev_warn(mcspi->dev, "%s: controller resume failed: %i\n", in omap2_mcspi_resume()
1661 MODULE_DESCRIPTION("OMAP2 McSPI controller driver");