In this mode, the DSPI controller uses PIO to transfer word by word. In comparison, in EOQ mode the 4-word deep FIFO is being used, hence the current logic will need some adaptation for which I do not have the hardware (Coldfire) to test. It is not clear what is the timing of DMA transfers and whether timestamping in the driver brings any overall performance increase compared to regular timestamping done in the core. Tested on LS1021A. Signed-off-by: Vladimir Oltean <olteanv@xxxxxxxxx> --- drivers/spi/spi-fsl-dspi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 4daf8c3d07b7..ea7169d18e09 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -129,6 +129,7 @@ enum dspi_trans_mode { struct fsl_dspi_devtype_data { enum dspi_trans_mode trans_mode; u8 max_clock_factor; + bool ptp_sts_supported; bool xspi_mode; }; @@ -140,12 +141,14 @@ static const struct fsl_dspi_devtype_data vf610_data = { static const struct fsl_dspi_devtype_data ls1021a_v1_data = { .trans_mode = DSPI_TCFQ_MODE, .max_clock_factor = 8, + .ptp_sts_supported = true, .xspi_mode = true, }; static const struct fsl_dspi_devtype_data ls2085a_data = { .trans_mode = DSPI_TCFQ_MODE, .max_clock_factor = 8, + .ptp_sts_supported = true, }; static const struct fsl_dspi_devtype_data coldfire_data = { @@ -179,6 +182,11 @@ struct fsl_dspi { int irq; struct clk *clk; + struct ptp_system_timestamp *ptp_sts; + const void *ptp_sts_word_pre; + const void *ptp_sts_word_post; + bool take_snapshot_pre; + bool take_snapshot_post; struct spi_transfer *cur_transfer; struct spi_message *cur_msg; struct chip_data *cur_chip; @@ -653,6 +661,9 @@ static int dspi_rxtx(struct fsl_dspi *dspi) u16 spi_tcnt; u32 spi_tcr; + if (dspi->take_snapshot_post) + ptp_read_system_postts(dspi->ptp_sts); + /* Get transfer counter (in number of SPI transfers). It was * reset to 0 when transfer(s) were started. */ @@ -670,6 +681,12 @@ static int dspi_rxtx(struct fsl_dspi *dspi) /* Success! */ return 0; + dspi->take_snapshot_pre = (dspi->tx == dspi->ptp_sts_word_pre); + dspi->take_snapshot_post = (dspi->tx == dspi->ptp_sts_word_post); + + if (dspi->take_snapshot_pre) + ptp_read_system_prets(dspi->ptp_sts); + if (dspi->devtype_data->trans_mode == DSPI_EOQ_MODE) dspi_eoq_write(dspi); else @@ -764,6 +781,10 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr, dspi->bytes_per_word = 2; else dspi->bytes_per_word = 4; + dspi->ptp_sts = transfer->ptp_sts; + dspi->ptp_sts_word_pre = spi_xfer_ptp_sts_word(transfer, true); + dspi->ptp_sts_word_post = spi_xfer_ptp_sts_word(transfer, + false); regmap_update_bits(dspi->regmap, SPI_MCR, SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF, @@ -776,6 +797,11 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr, SPI_FRAME_EBITS(transfer->bits_per_word) | SPI_CTARE_DTCP(1)); + dspi->take_snapshot_pre = (dspi->tx == dspi->ptp_sts_word_pre); + + if (dspi->take_snapshot_pre) + ptp_read_system_prets(dspi->ptp_sts); + trans_mode = dspi->devtype_data->trans_mode; switch (trans_mode) { case DSPI_EOQ_MODE: @@ -1140,6 +1166,8 @@ static int dspi_probe(struct platform_device *pdev) ctlr->max_speed_hz = clk_get_rate(dspi->clk) / dspi->devtype_data->max_clock_factor; + ctlr->ptp_sts_supported = dspi->devtype_data->ptp_sts_supported; + platform_set_drvdata(pdev, ctlr); ret = spi_register_controller(ctlr); -- 2.17.1