Lines Matching +full:tx +full:- +full:freq
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Author: Addy Ke <addy.ke@rock-chips.com>
18 #define DRIVER_NAME "rockchip-spi"
158 * SPI_CTRLR1 is 16-bits, so we should support lengths of 0xffff + 1. However,
179 const void *tx; member
189 u32 freq; member
196 bool cs_high_supported; /* native CS supports active-high polarity */
203 writel_relaxed((enable ? 1U : 0U), rs->regs + ROCKCHIP_SPI_SSIENR); in spi_enable_chip()
212 if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_TARGET_TX_BUSY) && in wait_for_tx_idle()
213 !((readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))) in wait_for_tx_idle()
216 if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)) in wait_for_tx_idle()
221 dev_warn(rs->dev, "spi controller is in busy state!\n"); in wait_for_tx_idle()
228 ver = readl_relaxed(rs->regs + ROCKCHIP_SPI_VERSION); in get_fifo_len()
241 struct spi_controller *ctlr = spi->controller; in rockchip_spi_set_cs()
243 bool cs_asserted = spi->mode & SPI_CS_HIGH ? enable : !enable; in rockchip_spi_set_cs()
247 pm_runtime_get_sync(rs->dev); in rockchip_spi_set_cs()
250 ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, 1); in rockchip_spi_set_cs()
252 ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, in rockchip_spi_set_cs()
256 ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, 1); in rockchip_spi_set_cs()
258 ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, in rockchip_spi_set_cs()
262 pm_runtime_put(rs->dev); in rockchip_spi_set_cs()
272 * this also flushes both rx and tx fifos in rockchip_spi_handle_err()
277 writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR); in rockchip_spi_handle_err()
278 writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR); in rockchip_spi_handle_err()
280 if (atomic_read(&rs->state) & TXDMA) in rockchip_spi_handle_err()
281 dmaengine_terminate_async(ctlr->dma_tx); in rockchip_spi_handle_err()
283 if (atomic_read(&rs->state) & RXDMA) in rockchip_spi_handle_err()
284 dmaengine_terminate_async(ctlr->dma_rx); in rockchip_spi_handle_err()
289 u32 tx_free = rs->fifo_len - readl_relaxed(rs->regs + ROCKCHIP_SPI_TXFLR); in rockchip_spi_pio_writer()
290 u32 words = min(rs->tx_left, tx_free); in rockchip_spi_pio_writer()
292 rs->tx_left -= words; in rockchip_spi_pio_writer()
293 for (; words; words--) { in rockchip_spi_pio_writer()
296 if (rs->n_bytes == 1) in rockchip_spi_pio_writer()
297 txw = *(u8 *)rs->tx; in rockchip_spi_pio_writer()
299 txw = *(u16 *)rs->tx; in rockchip_spi_pio_writer()
301 writel_relaxed(txw, rs->regs + ROCKCHIP_SPI_TXDR); in rockchip_spi_pio_writer()
302 rs->tx += rs->n_bytes; in rockchip_spi_pio_writer()
308 u32 words = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR); in rockchip_spi_pio_reader()
309 u32 rx_left = (rs->rx_left > words) ? rs->rx_left - words : 0; in rockchip_spi_pio_reader()
317 u32 ftl = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFTLR) + 1; in rockchip_spi_pio_reader()
321 words = rs->rx_left - rx_left; in rockchip_spi_pio_reader()
325 rs->rx_left = rx_left; in rockchip_spi_pio_reader()
326 for (; words; words--) { in rockchip_spi_pio_reader()
327 u32 rxw = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR); in rockchip_spi_pio_reader()
329 if (!rs->rx) in rockchip_spi_pio_reader()
332 if (rs->n_bytes == 1) in rockchip_spi_pio_reader()
333 *(u8 *)rs->rx = (u8)rxw; in rockchip_spi_pio_reader()
335 *(u16 *)rs->rx = (u16)rxw; in rockchip_spi_pio_reader()
336 rs->rx += rs->n_bytes; in rockchip_spi_pio_reader()
346 if (rs->cs_inactive && readl_relaxed(rs->regs + ROCKCHIP_SPI_IMR) & INT_CS_INACTIVE) { in rockchip_spi_isr()
347 ctlr->target_abort(ctlr); in rockchip_spi_isr()
348 writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR); in rockchip_spi_isr()
349 writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR); in rockchip_spi_isr()
354 if (rs->tx_left) in rockchip_spi_isr()
358 if (!rs->rx_left) { in rockchip_spi_isr()
360 writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR); in rockchip_spi_isr()
361 writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR); in rockchip_spi_isr()
372 rs->tx = xfer->tx_buf; in rockchip_spi_prepare_irq()
373 rs->rx = xfer->rx_buf; in rockchip_spi_prepare_irq()
374 rs->tx_left = rs->tx ? xfer->len / rs->n_bytes : 0; in rockchip_spi_prepare_irq()
375 rs->rx_left = xfer->len / rs->n_bytes; in rockchip_spi_prepare_irq()
377 writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR); in rockchip_spi_prepare_irq()
381 if (rs->tx_left) in rockchip_spi_prepare_irq()
384 if (rs->cs_inactive) in rockchip_spi_prepare_irq()
385 writel_relaxed(INT_RF_FULL | INT_CS_INACTIVE, rs->regs + ROCKCHIP_SPI_IMR); in rockchip_spi_prepare_irq()
387 writel_relaxed(INT_RF_FULL, rs->regs + ROCKCHIP_SPI_IMR); in rockchip_spi_prepare_irq()
397 int state = atomic_fetch_andnot(RXDMA, &rs->state); in rockchip_spi_dma_rxcb()
399 if (state & TXDMA && !rs->target_abort) in rockchip_spi_dma_rxcb()
402 if (rs->cs_inactive) in rockchip_spi_dma_rxcb()
403 writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR); in rockchip_spi_dma_rxcb()
413 int state = atomic_fetch_andnot(TXDMA, &rs->state); in rockchip_spi_dma_txcb()
415 if (state & RXDMA && !rs->target_abort) in rockchip_spi_dma_txcb()
419 wait_for_tx_idle(rs, ctlr->target); in rockchip_spi_dma_txcb()
443 atomic_set(&rs->state, 0); in rockchip_spi_prepare_dma()
445 rs->tx = xfer->tx_buf; in rockchip_spi_prepare_dma()
446 rs->rx = xfer->rx_buf; in rockchip_spi_prepare_dma()
449 if (xfer->rx_buf) { in rockchip_spi_prepare_dma()
452 .src_addr = rs->dma_addr_rx, in rockchip_spi_prepare_dma()
453 .src_addr_width = rs->n_bytes, in rockchip_spi_prepare_dma()
454 .src_maxburst = rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes), in rockchip_spi_prepare_dma()
457 dmaengine_slave_config(ctlr->dma_rx, &rxconf); in rockchip_spi_prepare_dma()
460 ctlr->dma_rx, in rockchip_spi_prepare_dma()
461 xfer->rx_sg.sgl, xfer->rx_sg.nents, in rockchip_spi_prepare_dma()
464 return -EINVAL; in rockchip_spi_prepare_dma()
466 rxdesc->callback = rockchip_spi_dma_rxcb; in rockchip_spi_prepare_dma()
467 rxdesc->callback_param = ctlr; in rockchip_spi_prepare_dma()
471 if (xfer->tx_buf) { in rockchip_spi_prepare_dma()
474 .dst_addr = rs->dma_addr_tx, in rockchip_spi_prepare_dma()
475 .dst_addr_width = rs->n_bytes, in rockchip_spi_prepare_dma()
476 .dst_maxburst = rs->fifo_len / 4, in rockchip_spi_prepare_dma()
479 dmaengine_slave_config(ctlr->dma_tx, &txconf); in rockchip_spi_prepare_dma()
482 ctlr->dma_tx, in rockchip_spi_prepare_dma()
483 xfer->tx_sg.sgl, xfer->tx_sg.nents, in rockchip_spi_prepare_dma()
487 dmaengine_terminate_sync(ctlr->dma_rx); in rockchip_spi_prepare_dma()
488 return -EINVAL; in rockchip_spi_prepare_dma()
491 txdesc->callback = rockchip_spi_dma_txcb; in rockchip_spi_prepare_dma()
492 txdesc->callback_param = ctlr; in rockchip_spi_prepare_dma()
495 /* rx must be started before tx due to spi instinct */ in rockchip_spi_prepare_dma()
497 atomic_or(RXDMA, &rs->state); in rockchip_spi_prepare_dma()
498 ctlr->dma_rx->cookie = dmaengine_submit(rxdesc); in rockchip_spi_prepare_dma()
499 dma_async_issue_pending(ctlr->dma_rx); in rockchip_spi_prepare_dma()
502 if (rs->cs_inactive) in rockchip_spi_prepare_dma()
503 writel_relaxed(INT_CS_INACTIVE, rs->regs + ROCKCHIP_SPI_IMR); in rockchip_spi_prepare_dma()
508 atomic_or(TXDMA, &rs->state); in rockchip_spi_prepare_dma()
510 dma_async_issue_pending(ctlr->dma_tx); in rockchip_spi_prepare_dma()
530 rs->target_abort = false; in rockchip_spi_config()
532 cr0 |= rs->rsd << CR0_RSD_OFFSET; in rockchip_spi_config()
533 cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET; in rockchip_spi_config()
534 if (spi->mode & SPI_LSB_FIRST) in rockchip_spi_config()
536 if (spi->mode & SPI_CS_HIGH) in rockchip_spi_config()
539 if (xfer->rx_buf && xfer->tx_buf) in rockchip_spi_config()
541 else if (xfer->rx_buf) in rockchip_spi_config()
546 switch (xfer->bits_per_word) { in rockchip_spi_config()
549 cr1 = xfer->len - 1; in rockchip_spi_config()
553 cr1 = xfer->len - 1; in rockchip_spi_config()
557 cr1 = xfer->len / 2 - 1; in rockchip_spi_config()
561 * ctlr->bits_per_word_mask, so this shouldn't in rockchip_spi_config()
564 dev_err(rs->dev, "unknown bits per word: %d\n", in rockchip_spi_config()
565 xfer->bits_per_word); in rockchip_spi_config()
566 return -EINVAL; in rockchip_spi_config()
570 if (xfer->tx_buf) in rockchip_spi_config()
572 if (xfer->rx_buf) in rockchip_spi_config()
576 writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0); in rockchip_spi_config()
577 writel_relaxed(cr1, rs->regs + ROCKCHIP_SPI_CTRLR1); in rockchip_spi_config()
583 if ((xfer->len / rs->n_bytes) < rs->fifo_len) in rockchip_spi_config()
584 writel_relaxed(xfer->len / rs->n_bytes - 1, rs->regs + ROCKCHIP_SPI_RXFTLR); in rockchip_spi_config()
586 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR); in rockchip_spi_config()
588 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_DMATDLR); in rockchip_spi_config()
589 writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1, in rockchip_spi_config()
590 rs->regs + ROCKCHIP_SPI_DMARDLR); in rockchip_spi_config()
591 writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR); in rockchip_spi_config()
597 writel_relaxed(2 * DIV_ROUND_UP(rs->freq, 2 * xfer->speed_hz), in rockchip_spi_config()
598 rs->regs + ROCKCHIP_SPI_BAUDR); in rockchip_spi_config()
616 if (atomic_read(&rs->state) & RXDMA) { in rockchip_spi_target_abort()
617 dmaengine_pause(ctlr->dma_rx); in rockchip_spi_target_abort()
618 status = dmaengine_tx_status(ctlr->dma_rx, ctlr->dma_rx->cookie, &state); in rockchip_spi_target_abort()
620 rs->rx = rs->xfer->rx_buf; in rockchip_spi_target_abort()
621 rs->xfer->len = 0; in rockchip_spi_target_abort()
622 rx_fifo_left = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR); in rockchip_spi_target_abort()
623 for (; rx_fifo_left; rx_fifo_left--) in rockchip_spi_target_abort()
624 readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR); in rockchip_spi_target_abort()
627 rs->rx += rs->xfer->len - rs->n_bytes * state.residue; in rockchip_spi_target_abort()
631 /* Get the valid data left in rx fifo and set rs->xfer->len real rx size */ in rockchip_spi_target_abort()
632 if (rs->rx) { in rockchip_spi_target_abort()
633 rx_fifo_left = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR); in rockchip_spi_target_abort()
634 for (; rx_fifo_left; rx_fifo_left--) { in rockchip_spi_target_abort()
635 u32 rxw = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR); in rockchip_spi_target_abort()
637 if (rs->n_bytes == 1) in rockchip_spi_target_abort()
638 *(u8 *)rs->rx = (u8)rxw; in rockchip_spi_target_abort()
640 *(u16 *)rs->rx = (u16)rxw; in rockchip_spi_target_abort()
641 rs->rx += rs->n_bytes; in rockchip_spi_target_abort()
643 rs->xfer->len = (unsigned int)(rs->rx - rs->xfer->rx_buf); in rockchip_spi_target_abort()
647 if (atomic_read(&rs->state) & RXDMA) in rockchip_spi_target_abort()
648 dmaengine_terminate_sync(ctlr->dma_rx); in rockchip_spi_target_abort()
649 if (atomic_read(&rs->state) & TXDMA) in rockchip_spi_target_abort()
650 dmaengine_terminate_sync(ctlr->dma_tx); in rockchip_spi_target_abort()
651 atomic_set(&rs->state, 0); in rockchip_spi_target_abort()
653 rs->target_abort = true; in rockchip_spi_target_abort()
669 if (!xfer->len) { in rockchip_spi_transfer_one()
674 WARN_ON(readl_relaxed(rs->regs + ROCKCHIP_SPI_SSIENR) && in rockchip_spi_transfer_one()
675 (readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)); in rockchip_spi_transfer_one()
677 if (!xfer->tx_buf && !xfer->rx_buf) { in rockchip_spi_transfer_one()
678 dev_err(rs->dev, "No buffer for transfer\n"); in rockchip_spi_transfer_one()
679 return -EINVAL; in rockchip_spi_transfer_one()
682 if (xfer->len > ROCKCHIP_SPI_MAX_TRANLEN) { in rockchip_spi_transfer_one()
683 dev_err(rs->dev, "Transfer is too long (%d)\n", xfer->len); in rockchip_spi_transfer_one()
684 return -EINVAL; in rockchip_spi_transfer_one()
687 rs->n_bytes = xfer->bits_per_word <= 8 ? 1 : 2; in rockchip_spi_transfer_one()
688 rs->xfer = xfer; in rockchip_spi_transfer_one()
689 use_dma = ctlr->can_dma ? ctlr->can_dma(ctlr, spi, xfer) : false; in rockchip_spi_transfer_one()
691 ret = rockchip_spi_config(rs, spi, xfer, use_dma, ctlr->target); in rockchip_spi_transfer_one()
706 unsigned int bytes_per_word = xfer->bits_per_word <= 8 ? 1 : 2; in rockchip_spi_can_dma()
712 return xfer->len / bytes_per_word >= rs->fifo_len; in rockchip_spi_can_dma()
717 struct rockchip_spi *rs = spi_controller_get_devdata(spi->controller); in rockchip_spi_setup()
720 if (!spi_get_csgpiod(spi, 0) && (spi->mode & SPI_CS_HIGH) && !rs->cs_high_supported) { in rockchip_spi_setup()
721 dev_warn(&spi->dev, "setup: non GPIO CS can't be active-high\n"); in rockchip_spi_setup()
722 return -EINVAL; in rockchip_spi_setup()
725 pm_runtime_get_sync(rs->dev); in rockchip_spi_setup()
727 cr0 = readl_relaxed(rs->regs + ROCKCHIP_SPI_CTRLR0); in rockchip_spi_setup()
730 cr0 |= ((spi->mode & 0x3) << CR0_SCPH_OFFSET); in rockchip_spi_setup()
731 if (spi->mode & SPI_CS_HIGH && spi_get_chipselect(spi, 0) <= 1) in rockchip_spi_setup()
736 writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0); in rockchip_spi_setup()
738 pm_runtime_put(rs->dev); in rockchip_spi_setup()
749 struct device_node *np = pdev->dev.of_node; in rockchip_spi_probe()
753 target_mode = of_property_read_bool(np, "spi-slave"); in rockchip_spi_probe()
756 ctlr = spi_alloc_target(&pdev->dev, in rockchip_spi_probe()
759 ctlr = spi_alloc_host(&pdev->dev, in rockchip_spi_probe()
763 return -ENOMEM; in rockchip_spi_probe()
770 rs->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem); in rockchip_spi_probe()
771 if (IS_ERR(rs->regs)) { in rockchip_spi_probe()
772 ret = PTR_ERR(rs->regs); in rockchip_spi_probe()
776 rs->apb_pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk"); in rockchip_spi_probe()
777 if (IS_ERR(rs->apb_pclk)) { in rockchip_spi_probe()
778 dev_err(&pdev->dev, "Failed to get apb_pclk\n"); in rockchip_spi_probe()
779 ret = PTR_ERR(rs->apb_pclk); in rockchip_spi_probe()
783 rs->spiclk = devm_clk_get_enabled(&pdev->dev, "spiclk"); in rockchip_spi_probe()
784 if (IS_ERR(rs->spiclk)) { in rockchip_spi_probe()
785 dev_err(&pdev->dev, "Failed to get spi_pclk\n"); in rockchip_spi_probe()
786 ret = PTR_ERR(rs->spiclk); in rockchip_spi_probe()
796 ret = devm_request_threaded_irq(&pdev->dev, ret, rockchip_spi_isr, NULL, in rockchip_spi_probe()
797 IRQF_ONESHOT, dev_name(&pdev->dev), ctlr); in rockchip_spi_probe()
801 rs->dev = &pdev->dev; in rockchip_spi_probe()
802 rs->freq = clk_get_rate(rs->spiclk); in rockchip_spi_probe()
804 if (!of_property_read_u32(pdev->dev.of_node, "rx-sample-delay-ns", in rockchip_spi_probe()
807 u32 rsd = DIV_ROUND_CLOSEST(rsd_nsecs * (rs->freq >> 8), in rockchip_spi_probe()
810 dev_warn(rs->dev, "%u Hz are too slow to express %u ns delay\n", in rockchip_spi_probe()
811 rs->freq, rsd_nsecs); in rockchip_spi_probe()
814 dev_warn(rs->dev, "%u Hz are too fast to express %u ns delay, clamping at %u ns\n", in rockchip_spi_probe()
815 rs->freq, rsd_nsecs, in rockchip_spi_probe()
816 CR0_RSD_MAX * 1000000000U / rs->freq); in rockchip_spi_probe()
818 rs->rsd = rsd; in rockchip_spi_probe()
821 rs->fifo_len = get_fifo_len(rs); in rockchip_spi_probe()
822 if (!rs->fifo_len) { in rockchip_spi_probe()
823 dev_err(&pdev->dev, "Failed to get fifo length\n"); in rockchip_spi_probe()
824 ret = -EINVAL; in rockchip_spi_probe()
828 pm_runtime_set_autosuspend_delay(&pdev->dev, ROCKCHIP_AUTOSUSPEND_TIMEOUT); in rockchip_spi_probe()
829 pm_runtime_use_autosuspend(&pdev->dev); in rockchip_spi_probe()
830 pm_runtime_set_active(&pdev->dev); in rockchip_spi_probe()
831 pm_runtime_enable(&pdev->dev); in rockchip_spi_probe()
833 ctlr->auto_runtime_pm = true; in rockchip_spi_probe()
834 ctlr->bus_num = pdev->id; in rockchip_spi_probe()
835 ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP | SPI_LSB_FIRST; in rockchip_spi_probe()
837 ctlr->mode_bits |= SPI_NO_CS; in rockchip_spi_probe()
838 ctlr->target_abort = rockchip_spi_target_abort; in rockchip_spi_probe()
840 ctlr->flags = SPI_CONTROLLER_GPIO_SS; in rockchip_spi_probe()
841 ctlr->max_native_cs = ROCKCHIP_SPI_MAX_NATIVE_CS_NUM; in rockchip_spi_probe()
844 * if num-cs is missing in the dts, default to 1 in rockchip_spi_probe()
846 if (of_property_read_u32(np, "num-cs", &num_cs)) in rockchip_spi_probe()
848 ctlr->num_chipselect = num_cs; in rockchip_spi_probe()
849 ctlr->use_gpio_descriptors = true; in rockchip_spi_probe()
851 ctlr->dev.of_node = pdev->dev.of_node; in rockchip_spi_probe()
852 ctlr->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8) | SPI_BPW_MASK(4); in rockchip_spi_probe()
853 ctlr->min_speed_hz = rs->freq / BAUDR_SCKDV_MAX; in rockchip_spi_probe()
854 ctlr->max_speed_hz = min(rs->freq / BAUDR_SCKDV_MIN, MAX_SCLK_OUT); in rockchip_spi_probe()
856 ctlr->setup = rockchip_spi_setup; in rockchip_spi_probe()
857 ctlr->set_cs = rockchip_spi_set_cs; in rockchip_spi_probe()
858 ctlr->transfer_one = rockchip_spi_transfer_one; in rockchip_spi_probe()
859 ctlr->max_transfer_size = rockchip_spi_max_transfer_size; in rockchip_spi_probe()
860 ctlr->handle_err = rockchip_spi_handle_err; in rockchip_spi_probe()
862 ctlr->dma_tx = dma_request_chan(rs->dev, "tx"); in rockchip_spi_probe()
863 if (IS_ERR(ctlr->dma_tx)) { in rockchip_spi_probe()
864 /* Check tx to see if we need defer probing driver */ in rockchip_spi_probe()
865 if (PTR_ERR(ctlr->dma_tx) == -EPROBE_DEFER) { in rockchip_spi_probe()
866 ret = -EPROBE_DEFER; in rockchip_spi_probe()
869 dev_warn(rs->dev, "Failed to request TX DMA channel\n"); in rockchip_spi_probe()
870 ctlr->dma_tx = NULL; in rockchip_spi_probe()
873 ctlr->dma_rx = dma_request_chan(rs->dev, "rx"); in rockchip_spi_probe()
874 if (IS_ERR(ctlr->dma_rx)) { in rockchip_spi_probe()
875 if (PTR_ERR(ctlr->dma_rx) == -EPROBE_DEFER) { in rockchip_spi_probe()
876 ret = -EPROBE_DEFER; in rockchip_spi_probe()
879 dev_warn(rs->dev, "Failed to request RX DMA channel\n"); in rockchip_spi_probe()
880 ctlr->dma_rx = NULL; in rockchip_spi_probe()
883 if (ctlr->dma_tx && ctlr->dma_rx) { in rockchip_spi_probe()
884 rs->dma_addr_tx = mem->start + ROCKCHIP_SPI_TXDR; in rockchip_spi_probe()
885 rs->dma_addr_rx = mem->start + ROCKCHIP_SPI_RXDR; in rockchip_spi_probe()
886 ctlr->can_dma = rockchip_spi_can_dma; in rockchip_spi_probe()
889 switch (readl_relaxed(rs->regs + ROCKCHIP_SPI_VERSION)) { in rockchip_spi_probe()
891 rs->cs_high_supported = true; in rockchip_spi_probe()
892 ctlr->mode_bits |= SPI_CS_HIGH; in rockchip_spi_probe()
893 if (ctlr->can_dma && target_mode) in rockchip_spi_probe()
894 rs->cs_inactive = true; in rockchip_spi_probe()
896 rs->cs_inactive = false; in rockchip_spi_probe()
899 rs->cs_inactive = false; in rockchip_spi_probe()
903 ret = devm_spi_register_controller(&pdev->dev, ctlr); in rockchip_spi_probe()
905 dev_err(&pdev->dev, "Failed to register controller\n"); in rockchip_spi_probe()
912 if (ctlr->dma_rx) in rockchip_spi_probe()
913 dma_release_channel(ctlr->dma_rx); in rockchip_spi_probe()
915 if (ctlr->dma_tx) in rockchip_spi_probe()
916 dma_release_channel(ctlr->dma_tx); in rockchip_spi_probe()
918 pm_runtime_disable(&pdev->dev); in rockchip_spi_probe()
929 pm_runtime_get_sync(&pdev->dev); in rockchip_spi_remove()
931 pm_runtime_put_noidle(&pdev->dev); in rockchip_spi_remove()
932 pm_runtime_disable(&pdev->dev); in rockchip_spi_remove()
933 pm_runtime_set_suspended(&pdev->dev); in rockchip_spi_remove()
935 if (ctlr->dma_tx) in rockchip_spi_remove()
936 dma_release_channel(ctlr->dma_tx); in rockchip_spi_remove()
937 if (ctlr->dma_rx) in rockchip_spi_remove()
938 dma_release_channel(ctlr->dma_rx); in rockchip_spi_remove()
985 clk_disable_unprepare(rs->spiclk); in rockchip_spi_runtime_suspend()
986 clk_disable_unprepare(rs->apb_pclk); in rockchip_spi_runtime_suspend()
997 ret = clk_prepare_enable(rs->apb_pclk); in rockchip_spi_runtime_resume()
1001 ret = clk_prepare_enable(rs->spiclk); in rockchip_spi_runtime_resume()
1003 clk_disable_unprepare(rs->apb_pclk); in rockchip_spi_runtime_resume()
1016 { .compatible = "rockchip,px30-spi", },
1017 { .compatible = "rockchip,rk3036-spi", },
1018 { .compatible = "rockchip,rk3066-spi", },
1019 { .compatible = "rockchip,rk3188-spi", },
1020 { .compatible = "rockchip,rk3228-spi", },
1021 { .compatible = "rockchip,rk3288-spi", },
1022 { .compatible = "rockchip,rk3308-spi", },
1023 { .compatible = "rockchip,rk3328-spi", },
1024 { .compatible = "rockchip,rk3368-spi", },
1025 { .compatible = "rockchip,rk3399-spi", },
1026 { .compatible = "rockchip,rv1108-spi", },
1027 { .compatible = "rockchip,rv1126-spi", },
1044 MODULE_AUTHOR("Addy Ke <addy.ke@rock-chips.com>");