Lines Matching refs:dspi

134 static void davinci_spi_rx_buf_u8(u32 data, struct davinci_spi *dspi)  in davinci_spi_rx_buf_u8()  argument
136 if (dspi->rx) { in davinci_spi_rx_buf_u8()
137 u8 *rx = dspi->rx; in davinci_spi_rx_buf_u8()
139 dspi->rx = rx; in davinci_spi_rx_buf_u8()
143 static void davinci_spi_rx_buf_u16(u32 data, struct davinci_spi *dspi) in davinci_spi_rx_buf_u16() argument
145 if (dspi->rx) { in davinci_spi_rx_buf_u16()
146 u16 *rx = dspi->rx; in davinci_spi_rx_buf_u16()
148 dspi->rx = rx; in davinci_spi_rx_buf_u16()
152 static u32 davinci_spi_tx_buf_u8(struct davinci_spi *dspi) in davinci_spi_tx_buf_u8() argument
156 if (dspi->tx) { in davinci_spi_tx_buf_u8()
157 const u8 *tx = dspi->tx; in davinci_spi_tx_buf_u8()
160 dspi->tx = tx; in davinci_spi_tx_buf_u8()
165 static u32 davinci_spi_tx_buf_u16(struct davinci_spi *dspi) in davinci_spi_tx_buf_u16() argument
169 if (dspi->tx) { in davinci_spi_tx_buf_u16()
170 const u16 *tx = dspi->tx; in davinci_spi_tx_buf_u16()
173 dspi->tx = tx; in davinci_spi_tx_buf_u16()
199 struct davinci_spi *dspi; in davinci_spi_chipselect() local
204 dspi = spi_controller_get_devdata(spi->controller); in davinci_spi_chipselect()
227 iowrite16(spidat1, dspi->base + SPIDAT1 + 2); in davinci_spi_chipselect()
241 static inline int davinci_spi_get_prescale(struct davinci_spi *dspi, in davinci_spi_get_prescale() argument
247 ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz) - 1; in davinci_spi_get_prescale()
249 if (ret < dspi->prescaler_limit || ret > 255) in davinci_spi_get_prescale()
268 struct davinci_spi *dspi; in davinci_spi_setup_transfer() local
274 dspi = spi_controller_get_devdata(spi->controller); in davinci_spi_setup_transfer()
293 dspi->get_rx = davinci_spi_rx_buf_u8; in davinci_spi_setup_transfer()
294 dspi->get_tx = davinci_spi_tx_buf_u8; in davinci_spi_setup_transfer()
295 dspi->bytes_per_word[spi_get_chipselect(spi, 0)] = 1; in davinci_spi_setup_transfer()
297 dspi->get_rx = davinci_spi_rx_buf_u16; in davinci_spi_setup_transfer()
298 dspi->get_tx = davinci_spi_tx_buf_u16; in davinci_spi_setup_transfer()
299 dspi->bytes_per_word[spi_get_chipselect(spi, 0)] = 2; in davinci_spi_setup_transfer()
307 prescale = davinci_spi_get_prescale(dspi, hz); in davinci_spi_setup_transfer()
343 if (dspi->version == SPI_VERSION_2) { in davinci_spi_setup_transfer()
370 iowrite32(delay, dspi->base + SPIDELAY); in davinci_spi_setup_transfer()
373 iowrite32(spifmt, dspi->base + SPIFMT0); in davinci_spi_setup_transfer()
382 struct davinci_spi *dspi = spi_controller_get_devdata(spi->controller); in davinci_spi_of_setup() local
395 if (dspi->dma_rx && dspi->dma_tx) in davinci_spi_of_setup()
410 struct davinci_spi *dspi; in davinci_spi_setup() local
414 dspi = spi_controller_get_devdata(spi->controller); in davinci_spi_setup()
421 set_io_bits(dspi->base + SPIPC0, 1 << spi_get_chipselect(spi, 0)); in davinci_spi_setup()
425 set_io_bits(dspi->base + SPIPC0, SPIPC0_SPIENA_MASK); in davinci_spi_setup()
428 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_LOOPBACK_MASK); in davinci_spi_setup()
430 clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_LOOPBACK_MASK); in davinci_spi_setup()
460 static int davinci_spi_check_error(struct davinci_spi *dspi, int int_status) in davinci_spi_check_error() argument
462 struct device *sdev = dspi->bitbang.master->dev.parent; in davinci_spi_check_error()
477 if (dspi->version == SPI_VERSION_2) { in davinci_spi_check_error()
506 static int davinci_spi_process_events(struct davinci_spi *dspi) in davinci_spi_process_events() argument
510 buf = ioread32(dspi->base + SPIBUF); in davinci_spi_process_events()
512 if (dspi->rcount > 0 && !(buf & SPIBUF_RXEMPTY_MASK)) { in davinci_spi_process_events()
513 dspi->get_rx(buf & 0xFFFF, dspi); in davinci_spi_process_events()
514 dspi->rcount--; in davinci_spi_process_events()
517 status = ioread32(dspi->base + SPIFLG); in davinci_spi_process_events()
524 if (dspi->wcount > 0 && !(buf & SPIBUF_TXFULL_MASK)) { in davinci_spi_process_events()
525 spidat1 = ioread32(dspi->base + SPIDAT1); in davinci_spi_process_events()
526 dspi->wcount--; in davinci_spi_process_events()
528 spidat1 |= 0xFFFF & dspi->get_tx(dspi); in davinci_spi_process_events()
529 iowrite32(spidat1, dspi->base + SPIDAT1); in davinci_spi_process_events()
538 struct davinci_spi *dspi = (struct davinci_spi *)data; in davinci_spi_dma_rx_callback() local
540 dspi->rcount = 0; in davinci_spi_dma_rx_callback()
542 if (!dspi->wcount && !dspi->rcount) in davinci_spi_dma_rx_callback()
543 complete(&dspi->done); in davinci_spi_dma_rx_callback()
548 struct davinci_spi *dspi = (struct davinci_spi *)data; in davinci_spi_dma_tx_callback() local
550 dspi->wcount = 0; in davinci_spi_dma_tx_callback()
552 if (!dspi->wcount && !dspi->rcount) in davinci_spi_dma_tx_callback()
553 complete(&dspi->done); in davinci_spi_dma_tx_callback()
567 struct davinci_spi *dspi; in davinci_spi_bufs() local
574 dspi = spi_controller_get_devdata(spi->controller); in davinci_spi_bufs()
575 pdata = &dspi->pdata; in davinci_spi_bufs()
581 data_type = dspi->bytes_per_word[spi_get_chipselect(spi, 0)]; in davinci_spi_bufs()
583 dspi->tx = t->tx_buf; in davinci_spi_bufs()
584 dspi->rx = t->rx_buf; in davinci_spi_bufs()
585 dspi->wcount = t->len / data_type; in davinci_spi_bufs()
586 dspi->rcount = dspi->wcount; in davinci_spi_bufs()
588 spidat1 = ioread32(dspi->base + SPIDAT1); in davinci_spi_bufs()
590 clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_bufs()
591 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); in davinci_spi_bufs()
593 reinit_completion(&dspi->done); in davinci_spi_bufs()
597 set_io_bits(dspi->base + SPIINT, SPIINT_MASKINT); in davinci_spi_bufs()
599 dspi->wcount--; in davinci_spi_bufs()
600 tx_data = dspi->get_tx(dspi); in davinci_spi_bufs()
603 iowrite32(spidat1, dspi->base + SPIDAT1); in davinci_spi_bufs()
607 .src_addr = (unsigned long)dspi->pbase + SPIBUF, in davinci_spi_bufs()
613 .dst_addr = (unsigned long)dspi->pbase + SPIDAT1, in davinci_spi_bufs()
620 dmaengine_slave_config(dspi->dma_rx, &dma_rx_conf); in davinci_spi_bufs()
621 dmaengine_slave_config(dspi->dma_tx, &dma_tx_conf); in davinci_spi_bufs()
623 rxdesc = dmaengine_prep_slave_sg(dspi->dma_rx, in davinci_spi_bufs()
639 txdesc = dmaengine_prep_slave_sg(dspi->dma_tx, in davinci_spi_bufs()
646 rxdesc->callback_param = (void *)dspi; in davinci_spi_bufs()
648 txdesc->callback_param = (void *)dspi; in davinci_spi_bufs()
651 iowrite16(spidat1 >> 16, dspi->base + SPIDAT1 + 2); in davinci_spi_bufs()
656 dma_async_issue_pending(dspi->dma_rx); in davinci_spi_bufs()
657 dma_async_issue_pending(dspi->dma_tx); in davinci_spi_bufs()
659 set_io_bits(dspi->base + SPIINT, SPIINT_DMA_REQ_EN); in davinci_spi_bufs()
664 if (wait_for_completion_timeout(&dspi->done, HZ) == 0) in davinci_spi_bufs()
667 while (dspi->rcount > 0 || dspi->wcount > 0) { in davinci_spi_bufs()
668 errors = davinci_spi_process_events(dspi); in davinci_spi_bufs()
675 clear_io_bits(dspi->base + SPIINT, SPIINT_MASKALL); in davinci_spi_bufs()
677 clear_io_bits(dspi->base + SPIINT, SPIINT_DMA_REQ_EN); in davinci_spi_bufs()
679 clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); in davinci_spi_bufs()
680 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_bufs()
687 ret = davinci_spi_check_error(dspi, errors); in davinci_spi_bufs()
693 if (dspi->rcount != 0 || dspi->wcount != 0) { in davinci_spi_bufs()
730 struct davinci_spi *dspi = data; in davinci_spi_irq() local
733 status = davinci_spi_process_events(dspi); in davinci_spi_irq()
735 clear_io_bits(dspi->base + SPIINT, SPIINT_MASKINT); in davinci_spi_irq()
737 if ((!dspi->rcount && !dspi->wcount) || status) in davinci_spi_irq()
738 complete(&dspi->done); in davinci_spi_irq()
743 static int davinci_spi_request_dma(struct davinci_spi *dspi) in davinci_spi_request_dma() argument
745 struct device *sdev = dspi->bitbang.master->dev.parent; in davinci_spi_request_dma()
747 dspi->dma_rx = dma_request_chan(sdev, "rx"); in davinci_spi_request_dma()
748 if (IS_ERR(dspi->dma_rx)) in davinci_spi_request_dma()
749 return PTR_ERR(dspi->dma_rx); in davinci_spi_request_dma()
751 dspi->dma_tx = dma_request_chan(sdev, "tx"); in davinci_spi_request_dma()
752 if (IS_ERR(dspi->dma_tx)) { in davinci_spi_request_dma()
753 dma_release_channel(dspi->dma_rx); in davinci_spi_request_dma()
754 return PTR_ERR(dspi->dma_tx); in davinci_spi_request_dma()
810 struct davinci_spi *dspi) in spi_davinci_get_pdata() argument
817 pdata = &dspi->pdata; in spi_davinci_get_pdata()
839 struct davinci_spi *dspi) in spi_davinci_get_pdata() argument
859 struct davinci_spi *dspi; in davinci_spi_probe() local
873 dspi = spi_controller_get_devdata(host); in davinci_spi_probe()
877 dspi->pdata = *pdata; in davinci_spi_probe()
880 ret = spi_davinci_get_pdata(pdev, dspi); in davinci_spi_probe()
886 pdata = &dspi->pdata; in davinci_spi_probe()
888 dspi->bytes_per_word = devm_kcalloc(&pdev->dev, in davinci_spi_probe()
890 sizeof(*dspi->bytes_per_word), in davinci_spi_probe()
892 if (dspi->bytes_per_word == NULL) { in davinci_spi_probe()
897 dspi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &r); in davinci_spi_probe()
898 if (IS_ERR(dspi->base)) { in davinci_spi_probe()
899 ret = PTR_ERR(dspi->base); in davinci_spi_probe()
902 dspi->pbase = r->start; in davinci_spi_probe()
904 init_completion(&dspi->done); in davinci_spi_probe()
909 dspi->irq = ret; in davinci_spi_probe()
911 ret = devm_request_threaded_irq(&pdev->dev, dspi->irq, davinci_spi_irq, in davinci_spi_probe()
912 dummy_thread_fn, 0, dev_name(&pdev->dev), dspi); in davinci_spi_probe()
916 dspi->bitbang.master = host; in davinci_spi_probe()
918 dspi->clk = devm_clk_get(&pdev->dev, NULL); in davinci_spi_probe()
919 if (IS_ERR(dspi->clk)) { in davinci_spi_probe()
923 ret = clk_prepare_enable(dspi->clk); in davinci_spi_probe()
937 dspi->bitbang.chipselect = davinci_spi_chipselect; in davinci_spi_probe()
938 dspi->bitbang.setup_transfer = davinci_spi_setup_transfer; in davinci_spi_probe()
939 dspi->prescaler_limit = pdata->prescaler_limit; in davinci_spi_probe()
940 dspi->version = pdata->version; in davinci_spi_probe()
942 dspi->bitbang.flags = SPI_NO_CS | SPI_LSB_FIRST | SPI_LOOP | SPI_CS_WORD; in davinci_spi_probe()
943 if (dspi->version == SPI_VERSION_2) in davinci_spi_probe()
944 dspi->bitbang.flags |= SPI_READY; in davinci_spi_probe()
946 dspi->bitbang.txrx_bufs = davinci_spi_bufs; in davinci_spi_probe()
948 ret = davinci_spi_request_dma(dspi); in davinci_spi_probe()
953 dspi->dma_rx = NULL; in davinci_spi_probe()
954 dspi->dma_tx = NULL; in davinci_spi_probe()
957 dspi->get_rx = davinci_spi_rx_buf_u8; in davinci_spi_probe()
958 dspi->get_tx = davinci_spi_tx_buf_u8; in davinci_spi_probe()
961 iowrite32(0, dspi->base + SPIGCR0); in davinci_spi_probe()
963 iowrite32(1, dspi->base + SPIGCR0); in davinci_spi_probe()
967 iowrite32(spipc0, dspi->base + SPIPC0); in davinci_spi_probe()
970 iowrite32(SPI_INTLVL_1, dspi->base + SPILVL); in davinci_spi_probe()
972 iowrite32(SPI_INTLVL_0, dspi->base + SPILVL); in davinci_spi_probe()
974 iowrite32(CS_DEFAULT, dspi->base + SPIDEF); in davinci_spi_probe()
977 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_CLKMOD_MASK); in davinci_spi_probe()
978 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_MASTER_MASK); in davinci_spi_probe()
979 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_probe()
981 ret = spi_bitbang_start(&dspi->bitbang); in davinci_spi_probe()
985 dev_info(&pdev->dev, "Controller at 0x%p\n", dspi->base); in davinci_spi_probe()
990 if (dspi->dma_rx) { in davinci_spi_probe()
991 dma_release_channel(dspi->dma_rx); in davinci_spi_probe()
992 dma_release_channel(dspi->dma_tx); in davinci_spi_probe()
995 clk_disable_unprepare(dspi->clk); in davinci_spi_probe()
1013 struct davinci_spi *dspi; in davinci_spi_remove() local
1017 dspi = spi_controller_get_devdata(host); in davinci_spi_remove()
1019 spi_bitbang_stop(&dspi->bitbang); in davinci_spi_remove()
1021 clk_disable_unprepare(dspi->clk); in davinci_spi_remove()
1023 if (dspi->dma_rx) { in davinci_spi_remove()
1024 dma_release_channel(dspi->dma_rx); in davinci_spi_remove()
1025 dma_release_channel(dspi->dma_tx); in davinci_spi_remove()