Lines Matching refs:fsl_lpspi
150 static void fsl_lpspi_buf_rx_##type(struct fsl_lpspi_data *fsl_lpspi) \
152 unsigned int val = readl(fsl_lpspi->base + IMX7ULP_RDR); \
154 if (fsl_lpspi->rx_buf) { \
155 *(type *)fsl_lpspi->rx_buf = val; \
156 fsl_lpspi->rx_buf += sizeof(type); \
161 static void fsl_lpspi_buf_tx_##type(struct fsl_lpspi_data *fsl_lpspi) \
165 if (fsl_lpspi->tx_buf) { \
166 val = *(type *)fsl_lpspi->tx_buf; \
167 fsl_lpspi->tx_buf += sizeof(type); \
170 fsl_lpspi->remain -= sizeof(type); \
171 writel(val, fsl_lpspi->base + IMX7ULP_TDR); \
181 static void fsl_lpspi_intctrl(struct fsl_lpspi_data *fsl_lpspi, in LPSPI_BUF_TX()
184 writel(enable, fsl_lpspi->base + IMX7ULP_IER); in LPSPI_BUF_TX()
217 struct fsl_lpspi_data *fsl_lpspi = in lpspi_prepare_xfer_hardware() local
221 ret = pm_runtime_resume_and_get(fsl_lpspi->dev); in lpspi_prepare_xfer_hardware()
223 dev_err(fsl_lpspi->dev, "failed to enable clock\n"); in lpspi_prepare_xfer_hardware()
232 struct fsl_lpspi_data *fsl_lpspi = in lpspi_unprepare_xfer_hardware() local
235 pm_runtime_mark_last_busy(fsl_lpspi->dev); in lpspi_unprepare_xfer_hardware()
236 pm_runtime_put_autosuspend(fsl_lpspi->dev); in lpspi_unprepare_xfer_hardware()
241 static void fsl_lpspi_write_tx_fifo(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_write_tx_fifo() argument
246 txfifo_cnt = readl(fsl_lpspi->base + IMX7ULP_FSR) & 0xff; in fsl_lpspi_write_tx_fifo()
248 while (txfifo_cnt < fsl_lpspi->txfifosize) { in fsl_lpspi_write_tx_fifo()
249 if (!fsl_lpspi->remain) in fsl_lpspi_write_tx_fifo()
251 fsl_lpspi->tx(fsl_lpspi); in fsl_lpspi_write_tx_fifo()
255 if (txfifo_cnt < fsl_lpspi->txfifosize) { in fsl_lpspi_write_tx_fifo()
256 if (!fsl_lpspi->is_target) { in fsl_lpspi_write_tx_fifo()
257 temp = readl(fsl_lpspi->base + IMX7ULP_TCR); in fsl_lpspi_write_tx_fifo()
259 writel(temp, fsl_lpspi->base + IMX7ULP_TCR); in fsl_lpspi_write_tx_fifo()
262 fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE); in fsl_lpspi_write_tx_fifo()
264 fsl_lpspi_intctrl(fsl_lpspi, IER_TDIE); in fsl_lpspi_write_tx_fifo()
267 static void fsl_lpspi_read_rx_fifo(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_read_rx_fifo() argument
269 while (!(readl(fsl_lpspi->base + IMX7ULP_RSR) & RSR_RXEMPTY)) in fsl_lpspi_read_rx_fifo()
270 fsl_lpspi->rx(fsl_lpspi); in fsl_lpspi_read_rx_fifo()
273 static void fsl_lpspi_set_cmd(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_set_cmd() argument
277 temp |= fsl_lpspi->config.bpw - 1; in fsl_lpspi_set_cmd()
278 temp |= (fsl_lpspi->config.mode & 0x3) << 30; in fsl_lpspi_set_cmd()
279 temp |= (fsl_lpspi->config.chip_select & 0x3) << 24; in fsl_lpspi_set_cmd()
280 if (!fsl_lpspi->is_target) { in fsl_lpspi_set_cmd()
281 temp |= fsl_lpspi->config.prescale << 27; in fsl_lpspi_set_cmd()
287 if (!fsl_lpspi->usedma) { in fsl_lpspi_set_cmd()
289 if (fsl_lpspi->is_first_byte) in fsl_lpspi_set_cmd()
295 writel(temp, fsl_lpspi->base + IMX7ULP_TCR); in fsl_lpspi_set_cmd()
297 dev_dbg(fsl_lpspi->dev, "TCR=0x%x\n", temp); in fsl_lpspi_set_cmd()
300 static void fsl_lpspi_set_watermark(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_set_watermark() argument
304 if (!fsl_lpspi->usedma) in fsl_lpspi_set_watermark()
305 temp = fsl_lpspi->watermark >> 1 | in fsl_lpspi_set_watermark()
306 (fsl_lpspi->watermark >> 1) << 16; in fsl_lpspi_set_watermark()
308 temp = fsl_lpspi->watermark >> 1; in fsl_lpspi_set_watermark()
310 writel(temp, fsl_lpspi->base + IMX7ULP_FCR); in fsl_lpspi_set_watermark()
312 dev_dbg(fsl_lpspi->dev, "FCR=0x%x\n", temp); in fsl_lpspi_set_watermark()
315 static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_set_bitrate() argument
317 struct lpspi_config config = fsl_lpspi->config; in fsl_lpspi_set_bitrate()
322 perclk_rate = clk_get_rate(fsl_lpspi->clk_per); in fsl_lpspi_set_bitrate()
323 prescale_max = fsl_lpspi->devtype_data->prescale_max; in fsl_lpspi_set_bitrate()
326 dev_err(fsl_lpspi->dev, in fsl_lpspi_set_bitrate()
332 dev_err(fsl_lpspi->dev, in fsl_lpspi_set_bitrate()
342 fsl_lpspi->config.prescale = prescale; in fsl_lpspi_set_bitrate()
351 fsl_lpspi->base + IMX7ULP_CCR); in fsl_lpspi_set_bitrate()
353 dev_dbg(fsl_lpspi->dev, "perclk=%d, speed=%d, prescale=%d, scldiv=%d\n", in fsl_lpspi_set_bitrate()
364 struct fsl_lpspi_data *fsl_lpspi = in fsl_lpspi_dma_configure() local
367 switch (fsl_lpspi_bytes_per_word(fsl_lpspi->config.bpw)) { in fsl_lpspi_dma_configure()
382 tx.dst_addr = fsl_lpspi->base_phys + IMX7ULP_TDR; in fsl_lpspi_dma_configure()
387 dev_err(fsl_lpspi->dev, "TX dma configuration failed with %d\n", in fsl_lpspi_dma_configure()
393 rx.src_addr = fsl_lpspi->base_phys + IMX7ULP_RDR; in fsl_lpspi_dma_configure()
398 dev_err(fsl_lpspi->dev, "RX dma configuration failed with %d\n", in fsl_lpspi_dma_configure()
406 static int fsl_lpspi_config(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_config() argument
411 if (!fsl_lpspi->is_target) { in fsl_lpspi_config()
412 ret = fsl_lpspi_set_bitrate(fsl_lpspi); in fsl_lpspi_config()
417 fsl_lpspi_set_watermark(fsl_lpspi); in fsl_lpspi_config()
419 if (!fsl_lpspi->is_target) in fsl_lpspi_config()
423 if (fsl_lpspi->config.mode & SPI_CS_HIGH) in fsl_lpspi_config()
425 writel(temp, fsl_lpspi->base + IMX7ULP_CFGR1); in fsl_lpspi_config()
427 temp = readl(fsl_lpspi->base + IMX7ULP_CR); in fsl_lpspi_config()
429 writel(temp, fsl_lpspi->base + IMX7ULP_CR); in fsl_lpspi_config()
432 if (fsl_lpspi->usedma) in fsl_lpspi_config()
434 writel(temp, fsl_lpspi->base + IMX7ULP_DER); in fsl_lpspi_config()
443 struct fsl_lpspi_data *fsl_lpspi = in fsl_lpspi_setup_transfer() local
449 fsl_lpspi->config.mode = spi->mode; in fsl_lpspi_setup_transfer()
450 fsl_lpspi->config.bpw = t->bits_per_word; in fsl_lpspi_setup_transfer()
451 fsl_lpspi->config.speed_hz = t->speed_hz; in fsl_lpspi_setup_transfer()
452 if (fsl_lpspi->is_only_cs1) in fsl_lpspi_setup_transfer()
453 fsl_lpspi->config.chip_select = 1; in fsl_lpspi_setup_transfer()
455 fsl_lpspi->config.chip_select = spi_get_chipselect(spi, 0); in fsl_lpspi_setup_transfer()
457 if (!fsl_lpspi->config.speed_hz) in fsl_lpspi_setup_transfer()
458 fsl_lpspi->config.speed_hz = spi->max_speed_hz; in fsl_lpspi_setup_transfer()
459 if (!fsl_lpspi->config.bpw) in fsl_lpspi_setup_transfer()
460 fsl_lpspi->config.bpw = spi->bits_per_word; in fsl_lpspi_setup_transfer()
463 if (fsl_lpspi->config.bpw <= 8) { in fsl_lpspi_setup_transfer()
464 fsl_lpspi->rx = fsl_lpspi_buf_rx_u8; in fsl_lpspi_setup_transfer()
465 fsl_lpspi->tx = fsl_lpspi_buf_tx_u8; in fsl_lpspi_setup_transfer()
466 } else if (fsl_lpspi->config.bpw <= 16) { in fsl_lpspi_setup_transfer()
467 fsl_lpspi->rx = fsl_lpspi_buf_rx_u16; in fsl_lpspi_setup_transfer()
468 fsl_lpspi->tx = fsl_lpspi_buf_tx_u16; in fsl_lpspi_setup_transfer()
470 fsl_lpspi->rx = fsl_lpspi_buf_rx_u32; in fsl_lpspi_setup_transfer()
471 fsl_lpspi->tx = fsl_lpspi_buf_tx_u32; in fsl_lpspi_setup_transfer()
474 if (t->len <= fsl_lpspi->txfifosize) in fsl_lpspi_setup_transfer()
475 fsl_lpspi->watermark = t->len; in fsl_lpspi_setup_transfer()
477 fsl_lpspi->watermark = fsl_lpspi->txfifosize; in fsl_lpspi_setup_transfer()
480 fsl_lpspi->usedma = true; in fsl_lpspi_setup_transfer()
482 fsl_lpspi->usedma = false; in fsl_lpspi_setup_transfer()
484 return fsl_lpspi_config(fsl_lpspi); in fsl_lpspi_setup_transfer()
489 struct fsl_lpspi_data *fsl_lpspi = in fsl_lpspi_target_abort() local
492 fsl_lpspi->target_aborted = true; in fsl_lpspi_target_abort()
493 if (!fsl_lpspi->usedma) in fsl_lpspi_target_abort()
494 complete(&fsl_lpspi->xfer_done); in fsl_lpspi_target_abort()
496 complete(&fsl_lpspi->dma_tx_completion); in fsl_lpspi_target_abort()
497 complete(&fsl_lpspi->dma_rx_completion); in fsl_lpspi_target_abort()
505 struct fsl_lpspi_data *fsl_lpspi = in fsl_lpspi_wait_for_completion() local
508 if (fsl_lpspi->is_target) { in fsl_lpspi_wait_for_completion()
509 if (wait_for_completion_interruptible(&fsl_lpspi->xfer_done) || in fsl_lpspi_wait_for_completion()
510 fsl_lpspi->target_aborted) { in fsl_lpspi_wait_for_completion()
511 dev_dbg(fsl_lpspi->dev, "interrupted\n"); in fsl_lpspi_wait_for_completion()
515 if (!wait_for_completion_timeout(&fsl_lpspi->xfer_done, HZ)) { in fsl_lpspi_wait_for_completion()
516 dev_dbg(fsl_lpspi->dev, "wait for completion timeout\n"); in fsl_lpspi_wait_for_completion()
524 static int fsl_lpspi_reset(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_reset() argument
528 if (!fsl_lpspi->usedma) { in fsl_lpspi_reset()
530 fsl_lpspi_intctrl(fsl_lpspi, 0); in fsl_lpspi_reset()
535 writel(temp, fsl_lpspi->base + IMX7ULP_SR); in fsl_lpspi_reset()
539 writel(temp, fsl_lpspi->base + IMX7ULP_CR); in fsl_lpspi_reset()
546 struct fsl_lpspi_data *fsl_lpspi = (struct fsl_lpspi_data *)cookie; in fsl_lpspi_dma_rx_callback() local
548 complete(&fsl_lpspi->dma_rx_completion); in fsl_lpspi_dma_rx_callback()
553 struct fsl_lpspi_data *fsl_lpspi = (struct fsl_lpspi_data *)cookie; in fsl_lpspi_dma_tx_callback() local
555 complete(&fsl_lpspi->dma_tx_completion); in fsl_lpspi_dma_tx_callback()
558 static int fsl_lpspi_calculate_timeout(struct fsl_lpspi_data *fsl_lpspi, in fsl_lpspi_calculate_timeout() argument
564 timeout = (8 + 4) * size / fsl_lpspi->config.speed_hz; in fsl_lpspi_calculate_timeout()
574 struct fsl_lpspi_data *fsl_lpspi, in fsl_lpspi_dma_transfer() argument
594 desc_rx->callback_param = (void *)fsl_lpspi; in fsl_lpspi_dma_transfer()
596 reinit_completion(&fsl_lpspi->dma_rx_completion); in fsl_lpspi_dma_transfer()
608 desc_tx->callback_param = (void *)fsl_lpspi; in fsl_lpspi_dma_transfer()
610 reinit_completion(&fsl_lpspi->dma_tx_completion); in fsl_lpspi_dma_transfer()
613 fsl_lpspi->target_aborted = false; in fsl_lpspi_dma_transfer()
615 if (!fsl_lpspi->is_target) { in fsl_lpspi_dma_transfer()
616 transfer_timeout = fsl_lpspi_calculate_timeout(fsl_lpspi, in fsl_lpspi_dma_transfer()
620 timeout = wait_for_completion_timeout(&fsl_lpspi->dma_tx_completion, in fsl_lpspi_dma_transfer()
623 dev_err(fsl_lpspi->dev, "I/O Error in DMA TX\n"); in fsl_lpspi_dma_transfer()
626 fsl_lpspi_reset(fsl_lpspi); in fsl_lpspi_dma_transfer()
630 timeout = wait_for_completion_timeout(&fsl_lpspi->dma_rx_completion, in fsl_lpspi_dma_transfer()
633 dev_err(fsl_lpspi->dev, "I/O Error in DMA RX\n"); in fsl_lpspi_dma_transfer()
636 fsl_lpspi_reset(fsl_lpspi); in fsl_lpspi_dma_transfer()
640 if (wait_for_completion_interruptible(&fsl_lpspi->dma_tx_completion) || in fsl_lpspi_dma_transfer()
641 fsl_lpspi->target_aborted) { in fsl_lpspi_dma_transfer()
642 dev_dbg(fsl_lpspi->dev, in fsl_lpspi_dma_transfer()
646 fsl_lpspi_reset(fsl_lpspi); in fsl_lpspi_dma_transfer()
650 if (wait_for_completion_interruptible(&fsl_lpspi->dma_rx_completion) || in fsl_lpspi_dma_transfer()
651 fsl_lpspi->target_aborted) { in fsl_lpspi_dma_transfer()
652 dev_dbg(fsl_lpspi->dev, in fsl_lpspi_dma_transfer()
656 fsl_lpspi_reset(fsl_lpspi); in fsl_lpspi_dma_transfer()
661 fsl_lpspi_reset(fsl_lpspi); in fsl_lpspi_dma_transfer()
680 struct fsl_lpspi_data *fsl_lpspi, in fsl_lpspi_dma_init() argument
703 init_completion(&fsl_lpspi->dma_rx_completion); in fsl_lpspi_dma_init()
704 init_completion(&fsl_lpspi->dma_tx_completion); in fsl_lpspi_dma_init()
717 struct fsl_lpspi_data *fsl_lpspi = in fsl_lpspi_pio_transfer() local
721 fsl_lpspi->tx_buf = t->tx_buf; in fsl_lpspi_pio_transfer()
722 fsl_lpspi->rx_buf = t->rx_buf; in fsl_lpspi_pio_transfer()
723 fsl_lpspi->remain = t->len; in fsl_lpspi_pio_transfer()
725 reinit_completion(&fsl_lpspi->xfer_done); in fsl_lpspi_pio_transfer()
726 fsl_lpspi->target_aborted = false; in fsl_lpspi_pio_transfer()
728 fsl_lpspi_write_tx_fifo(fsl_lpspi); in fsl_lpspi_pio_transfer()
734 fsl_lpspi_reset(fsl_lpspi); in fsl_lpspi_pio_transfer()
743 struct fsl_lpspi_data *fsl_lpspi = in fsl_lpspi_transfer_one() local
747 fsl_lpspi->is_first_byte = true; in fsl_lpspi_transfer_one()
752 fsl_lpspi_set_cmd(fsl_lpspi); in fsl_lpspi_transfer_one()
753 fsl_lpspi->is_first_byte = false; in fsl_lpspi_transfer_one()
755 if (fsl_lpspi->usedma) in fsl_lpspi_transfer_one()
756 ret = fsl_lpspi_dma_transfer(controller, fsl_lpspi, t); in fsl_lpspi_transfer_one()
768 struct fsl_lpspi_data *fsl_lpspi = dev_id; in fsl_lpspi_isr() local
770 temp_IER = readl(fsl_lpspi->base + IMX7ULP_IER); in fsl_lpspi_isr()
771 fsl_lpspi_intctrl(fsl_lpspi, 0); in fsl_lpspi_isr()
772 temp_SR = readl(fsl_lpspi->base + IMX7ULP_SR); in fsl_lpspi_isr()
774 fsl_lpspi_read_rx_fifo(fsl_lpspi); in fsl_lpspi_isr()
777 fsl_lpspi_write_tx_fifo(fsl_lpspi); in fsl_lpspi_isr()
782 readl(fsl_lpspi->base + IMX7ULP_FSR) & FSR_TXCOUNT) { in fsl_lpspi_isr()
783 writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR); in fsl_lpspi_isr()
784 fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE); in fsl_lpspi_isr()
789 writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR); in fsl_lpspi_isr()
790 complete(&fsl_lpspi->xfer_done); in fsl_lpspi_isr()
801 struct fsl_lpspi_data *fsl_lpspi; in fsl_lpspi_runtime_resume() local
804 fsl_lpspi = spi_controller_get_devdata(controller); in fsl_lpspi_runtime_resume()
806 ret = clk_prepare_enable(fsl_lpspi->clk_per); in fsl_lpspi_runtime_resume()
810 ret = clk_prepare_enable(fsl_lpspi->clk_ipg); in fsl_lpspi_runtime_resume()
812 clk_disable_unprepare(fsl_lpspi->clk_per); in fsl_lpspi_runtime_resume()
822 struct fsl_lpspi_data *fsl_lpspi; in fsl_lpspi_runtime_suspend() local
824 fsl_lpspi = spi_controller_get_devdata(controller); in fsl_lpspi_runtime_suspend()
826 clk_disable_unprepare(fsl_lpspi->clk_per); in fsl_lpspi_runtime_suspend()
827 clk_disable_unprepare(fsl_lpspi->clk_ipg); in fsl_lpspi_runtime_suspend()
833 static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi) in fsl_lpspi_init_rpm() argument
835 struct device *dev = fsl_lpspi->dev; in fsl_lpspi_init_rpm()
847 struct fsl_lpspi_data *fsl_lpspi; in fsl_lpspi_probe() local
872 fsl_lpspi = spi_controller_get_devdata(controller); in fsl_lpspi_probe()
873 fsl_lpspi->dev = &pdev->dev; in fsl_lpspi_probe()
874 fsl_lpspi->is_target = is_target; in fsl_lpspi_probe()
875 fsl_lpspi->is_only_cs1 = of_property_read_bool((&pdev->dev)->of_node, in fsl_lpspi_probe()
877 fsl_lpspi->devtype_data = devtype_data; in fsl_lpspi_probe()
879 init_completion(&fsl_lpspi->xfer_done); in fsl_lpspi_probe()
881 fsl_lpspi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in fsl_lpspi_probe()
882 if (IS_ERR(fsl_lpspi->base)) { in fsl_lpspi_probe()
883 ret = PTR_ERR(fsl_lpspi->base); in fsl_lpspi_probe()
886 fsl_lpspi->base_phys = res->start; in fsl_lpspi_probe()
895 dev_name(&pdev->dev), fsl_lpspi); in fsl_lpspi_probe()
901 fsl_lpspi->clk_per = devm_clk_get(&pdev->dev, "per"); in fsl_lpspi_probe()
902 if (IS_ERR(fsl_lpspi->clk_per)) { in fsl_lpspi_probe()
903 ret = PTR_ERR(fsl_lpspi->clk_per); in fsl_lpspi_probe()
907 fsl_lpspi->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in fsl_lpspi_probe()
908 if (IS_ERR(fsl_lpspi->clk_ipg)) { in fsl_lpspi_probe()
909 ret = PTR_ERR(fsl_lpspi->clk_ipg); in fsl_lpspi_probe()
914 ret = fsl_lpspi_init_rpm(fsl_lpspi); in fsl_lpspi_probe()
918 ret = pm_runtime_get_sync(fsl_lpspi->dev); in fsl_lpspi_probe()
920 dev_err(fsl_lpspi->dev, "failed to enable clock\n"); in fsl_lpspi_probe()
924 temp = readl(fsl_lpspi->base + IMX7ULP_PARAM); in fsl_lpspi_probe()
925 fsl_lpspi->txfifosize = 1 << (temp & 0x0f); in fsl_lpspi_probe()
926 fsl_lpspi->rxfifosize = 1 << ((temp >> 8) & 0x0f); in fsl_lpspi_probe()
945 if (!fsl_lpspi->is_target) in fsl_lpspi_probe()
948 ret = fsl_lpspi_dma_init(&pdev->dev, fsl_lpspi, controller); in fsl_lpspi_probe()
966 pm_runtime_mark_last_busy(fsl_lpspi->dev); in fsl_lpspi_probe()
967 pm_runtime_put_autosuspend(fsl_lpspi->dev); in fsl_lpspi_probe()
974 pm_runtime_dont_use_autosuspend(fsl_lpspi->dev); in fsl_lpspi_probe()
975 pm_runtime_put_sync(fsl_lpspi->dev); in fsl_lpspi_probe()
976 pm_runtime_disable(fsl_lpspi->dev); in fsl_lpspi_probe()
984 struct fsl_lpspi_data *fsl_lpspi = in fsl_lpspi_remove() local
989 pm_runtime_dont_use_autosuspend(fsl_lpspi->dev); in fsl_lpspi_remove()
990 pm_runtime_disable(fsl_lpspi->dev); in fsl_lpspi_remove()