Lines Matching full: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()
232 * @dspi: the controller data
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.ctlr->dev.parent; in davinci_spi_check_error()
477 if (dspi->version == SPI_VERSION_2) { in davinci_spi_check_error()
501 * @dspi: the controller data
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
575 dspi = spi_controller_get_devdata(spi->controller); in davinci_spi_bufs()
576 pdata = &dspi->pdata; in davinci_spi_bufs()
582 data_type = dspi->bytes_per_word[spi_get_chipselect(spi, 0)]; in davinci_spi_bufs()
584 dspi->tx = t->tx_buf; in davinci_spi_bufs()
585 dspi->rx = t->rx_buf; in davinci_spi_bufs()
586 dspi->wcount = t->len / data_type; in davinci_spi_bufs()
587 dspi->rcount = dspi->wcount; in davinci_spi_bufs()
589 spidat1 = ioread32(dspi->base + SPIDAT1); in davinci_spi_bufs()
591 clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_bufs()
592 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); in davinci_spi_bufs()
594 reinit_completion(&dspi->done); in davinci_spi_bufs()
598 set_io_bits(dspi->base + SPIINT, SPIINT_MASKINT); in davinci_spi_bufs()
600 dspi->wcount--; in davinci_spi_bufs()
601 tx_data = dspi->get_tx(dspi); in davinci_spi_bufs()
604 iowrite32(spidat1, dspi->base + SPIDAT1); in davinci_spi_bufs()
608 .src_addr = (unsigned long)dspi->pbase + SPIBUF, in davinci_spi_bufs()
614 .dst_addr = (unsigned long)dspi->pbase + SPIDAT1, in davinci_spi_bufs()
621 dmaengine_slave_config(dspi->dma_rx, &dma_rx_conf); in davinci_spi_bufs()
622 dmaengine_slave_config(dspi->dma_tx, &dma_tx_conf); in davinci_spi_bufs()
624 rxdesc = dmaengine_prep_slave_sg(dspi->dma_rx, in davinci_spi_bufs()
640 txdesc = dmaengine_prep_slave_sg(dspi->dma_tx, in davinci_spi_bufs()
647 rxdesc->callback_param = (void *)dspi; in davinci_spi_bufs()
649 txdesc->callback_param = (void *)dspi; in davinci_spi_bufs()
652 iowrite16(spidat1 >> 16, dspi->base + SPIDAT1 + 2); in davinci_spi_bufs()
657 dma_async_issue_pending(dspi->dma_rx); in davinci_spi_bufs()
658 dma_async_issue_pending(dspi->dma_tx); in davinci_spi_bufs()
660 set_io_bits(dspi->base + SPIINT, SPIINT_DMA_REQ_EN); in davinci_spi_bufs()
670 if (wait_for_completion_timeout(&dspi->done, timeout) == 0) in davinci_spi_bufs()
673 while (dspi->rcount > 0 || dspi->wcount > 0) { in davinci_spi_bufs()
674 errors = davinci_spi_process_events(dspi); in davinci_spi_bufs()
681 clear_io_bits(dspi->base + SPIINT, SPIINT_MASKALL); in davinci_spi_bufs()
683 clear_io_bits(dspi->base + SPIINT, SPIINT_DMA_REQ_EN); in davinci_spi_bufs()
685 clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); in davinci_spi_bufs()
686 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_bufs()
693 ret = davinci_spi_check_error(dspi, errors); in davinci_spi_bufs()
699 if (dspi->rcount != 0 || dspi->wcount != 0) { in davinci_spi_bufs()
736 struct davinci_spi *dspi = data; in davinci_spi_irq() local
739 status = davinci_spi_process_events(dspi); in davinci_spi_irq()
741 clear_io_bits(dspi->base + SPIINT, SPIINT_MASKINT); in davinci_spi_irq()
743 if ((!dspi->rcount && !dspi->wcount) || status) in davinci_spi_irq()
744 complete(&dspi->done); in davinci_spi_irq()
749 static int davinci_spi_request_dma(struct davinci_spi *dspi) in davinci_spi_request_dma() argument
751 struct device *sdev = dspi->bitbang.ctlr->dev.parent; in davinci_spi_request_dma()
753 dspi->dma_rx = dma_request_chan(sdev, "rx"); in davinci_spi_request_dma()
754 if (IS_ERR(dspi->dma_rx)) in davinci_spi_request_dma()
755 return PTR_ERR(dspi->dma_rx); in davinci_spi_request_dma()
757 dspi->dma_tx = dma_request_chan(sdev, "tx"); in davinci_spi_request_dma()
758 if (IS_ERR(dspi->dma_tx)) { in davinci_spi_request_dma()
759 dma_release_channel(dspi->dma_rx); in davinci_spi_request_dma()
760 return PTR_ERR(dspi->dma_tx); in davinci_spi_request_dma()
809 * @dspi: ptr to driver data
811 * Parses and populates pdata in dspi from device tree bindings.
816 struct davinci_spi *dspi) in spi_davinci_get_pdata() argument
823 pdata = &dspi->pdata; in spi_davinci_get_pdata()
845 struct davinci_spi *dspi) in spi_davinci_get_pdata() argument
865 struct davinci_spi *dspi; in davinci_spi_probe() local
879 dspi = spi_controller_get_devdata(host); in davinci_spi_probe()
883 dspi->pdata = *pdata; in davinci_spi_probe()
885 /* update dspi pdata with that from the DT */ in davinci_spi_probe()
886 ret = spi_davinci_get_pdata(pdev, dspi); in davinci_spi_probe()
891 /* pdata in dspi is now updated and point pdata to that */ in davinci_spi_probe()
892 pdata = &dspi->pdata; in davinci_spi_probe()
894 dspi->bytes_per_word = devm_kcalloc(&pdev->dev, in davinci_spi_probe()
896 sizeof(*dspi->bytes_per_word), in davinci_spi_probe()
898 if (dspi->bytes_per_word == NULL) { in davinci_spi_probe()
903 dspi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &r); in davinci_spi_probe()
904 if (IS_ERR(dspi->base)) { in davinci_spi_probe()
905 ret = PTR_ERR(dspi->base); in davinci_spi_probe()
908 dspi->pbase = r->start; in davinci_spi_probe()
910 init_completion(&dspi->done); in davinci_spi_probe()
915 dspi->irq = ret; in davinci_spi_probe()
917 ret = devm_request_threaded_irq(&pdev->dev, dspi->irq, davinci_spi_irq, in davinci_spi_probe()
918 dummy_thread_fn, 0, dev_name(&pdev->dev), dspi); in davinci_spi_probe()
922 dspi->bitbang.ctlr = host; in davinci_spi_probe()
924 dspi->clk = devm_clk_get_enabled(&pdev->dev, NULL); in davinci_spi_probe()
925 if (IS_ERR(dspi->clk)) { in davinci_spi_probe()
940 dspi->bitbang.chipselect = davinci_spi_chipselect; in davinci_spi_probe()
941 dspi->bitbang.setup_transfer = davinci_spi_setup_transfer; in davinci_spi_probe()
942 dspi->prescaler_limit = pdata->prescaler_limit; in davinci_spi_probe()
943 dspi->version = pdata->version; in davinci_spi_probe()
945 dspi->bitbang.flags = SPI_NO_CS | SPI_LSB_FIRST | SPI_LOOP | SPI_CS_WORD; in davinci_spi_probe()
946 if (dspi->version == SPI_VERSION_2) in davinci_spi_probe()
947 dspi->bitbang.flags |= SPI_READY; in davinci_spi_probe()
949 dspi->bitbang.txrx_bufs = davinci_spi_bufs; in davinci_spi_probe()
951 ret = davinci_spi_request_dma(dspi); in davinci_spi_probe()
956 dspi->dma_rx = NULL; in davinci_spi_probe()
957 dspi->dma_tx = NULL; in davinci_spi_probe()
960 dspi->get_rx = davinci_spi_rx_buf_u8; in davinci_spi_probe()
961 dspi->get_tx = davinci_spi_tx_buf_u8; in davinci_spi_probe()
964 iowrite32(0, dspi->base + SPIGCR0); in davinci_spi_probe()
966 iowrite32(1, dspi->base + SPIGCR0); in davinci_spi_probe()
970 iowrite32(spipc0, dspi->base + SPIPC0); in davinci_spi_probe()
973 iowrite32(SPI_INTLVL_1, dspi->base + SPILVL); in davinci_spi_probe()
975 iowrite32(SPI_INTLVL_0, dspi->base + SPILVL); in davinci_spi_probe()
977 iowrite32(CS_DEFAULT, dspi->base + SPIDEF); in davinci_spi_probe()
980 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_CLKMOD_MASK); in davinci_spi_probe()
981 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_MASTER_MASK); in davinci_spi_probe()
982 set_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_probe()
984 ret = spi_bitbang_start(&dspi->bitbang); in davinci_spi_probe()
988 dev_info(&pdev->dev, "Controller at 0x%p\n", dspi->base); in davinci_spi_probe()
994 clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_probe()
996 if (dspi->dma_rx) { in davinci_spi_probe()
997 dma_release_channel(dspi->dma_rx); in davinci_spi_probe()
998 dma_release_channel(dspi->dma_tx); in davinci_spi_probe()
1017 struct davinci_spi *dspi; in davinci_spi_remove() local
1021 dspi = spi_controller_get_devdata(host); in davinci_spi_remove()
1023 spi_bitbang_stop(&dspi->bitbang); in davinci_spi_remove()
1026 clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); in davinci_spi_remove()
1028 if (dspi->dma_rx) { in davinci_spi_remove()
1029 dma_release_channel(dspi->dma_rx); in davinci_spi_remove()
1030 dma_release_channel(dspi->dma_tx); in davinci_spi_remove()