<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use DMA transaction in SPI device driver in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2012020#M231859</link>
    <description>&lt;P&gt;Thank you for your response!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, I want to continuously read the data from an ADC in the kernel thread, so when I don't use the DMA and go with the PIO method, the CPU usage just goes crazy (&amp;gt; 70%). For SPI transactions, I wish to offload that using DMA. I have made changes in the spi-imx.c to forcefully use the dma instead of 64-byte fifo limit.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;While the standard regiser read/write APIs function well with DMA, the SPI transactions fail when reading the samples, and spi_sync returns an error code.&lt;/P&gt;&lt;P&gt;What could be the issue? Something I have overlooked?&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: When I perform a register read/write transaction, I also receive the DMA debug prints, confirming that DMA is functioning with register read/write.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my api to read the samples&lt;/P&gt;&lt;P&gt;int ad4134_sample_read(struct spi_device *spi)&lt;BR /&gt;{&lt;BR /&gt;int ret;&lt;BR /&gt;uint32_t pad[8] = {0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;struct spi_transfer tr =&lt;BR /&gt;{&lt;BR /&gt;.tx_buf = pad,&lt;BR /&gt;.rx_buf = st.sample,&lt;BR /&gt;.len = 32,&lt;BR /&gt;.bits_per_word = 32,&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;struct spi_message m;&lt;BR /&gt;spi_message_init(&amp;amp;m);&lt;/P&gt;&lt;P&gt;spi_message_add_tail(&amp;amp;tr, &amp;amp;m);&lt;BR /&gt;spi_sync(spi,&amp;amp;m);&lt;/P&gt;&lt;P&gt;return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2024 12:40:38 GMT</pubDate>
    <dc:creator>pratham_malaviya</dc:creator>
    <dc:date>2024-12-11T12:40:38Z</dc:date>
    <item>
      <title>Use DMA transaction in SPI device driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2010163#M231722</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;We are using IMX8MP for one of our project,&amp;nbsp;&lt;SPAN&gt;I am writing a linux kernel driver for an ADC which works on SPI interface. To achieve high-speed data read, We are planning to use the DMA for data transmission. But there is not enough documentation available on how to implement that,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Moreover, i have read below threads, which makes it more complex to implement.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;They say in &lt;A href="https://community.nxp.com/t5/i-MX-Processors/Using-DMA-in-imx6ul-SPI-client-driver/m-p/920304" target="_self"&gt;this&lt;/A&gt; thread that we may need to add "dma-names" and modify dts for the dma support, with the spi-imx.c and dma subsystem handling everything else. and we only need to use standard spi APIs.&lt;/LI&gt;&lt;LI&gt;According to &lt;A href="https://community.nxp.com/t5/i-MX-Processors/How-does-the-IMX6-SPI-use-DMA-to-transfer-data/m-p/887144?commentID=1113939&amp;amp;et=notification.mention#comment-1113939" target="_self"&gt;this&lt;/A&gt; thread, the controller will only carry out DMA transfer if the data size is more than 64 bytes. Also they are changing the spi-imx.c file to force the dma transfer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;So, What is the best approach to use dma transfer?&lt;/P&gt;&lt;P&gt;Do I need to use the &lt;STRONG&gt;"dma_coherent_alloc()"&lt;/STRONG&gt; apis?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 11:55:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2010163#M231722</guid>
      <dc:creator>pratham_malaviya</dc:creator>
      <dc:date>2024-12-09T11:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use DMA transaction in SPI device driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2011728#M231846</link>
      <description>&lt;P&gt;I checked the spi driver, it seems it already enable DMA&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/nxp-imx/linux-imx/blob/lf-6.1.y/drivers/spi/spi-imx.c" target="_blank"&gt;https://github.com/nxp-imx/linux-imx/blob/lf-6.1.y/drivers/spi/spi-imx.c&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 07:48:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2011728#M231846</guid>
      <dc:creator>joanxie</dc:creator>
      <dc:date>2024-12-11T07:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use DMA transaction in SPI device driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2011908#M231855</link>
      <description>&lt;P&gt;Regarding dma-names. Yes, to enable ECSPI DMA, your DT should include dma-names. You may verify if you have them set on live system. Find your SPI controller, perhaps like this, results from iMX7D:&lt;/P&gt;&lt;P&gt;# find /sys/firmware/ -name "*spi*" /sys/firmware/devicetree/base/soc/bus@30800000/spi@30bb0000&lt;BR /&gt;/sys/firmware/devicetree/base/soc/bus@30800000/spba-bus@30800000/spi@30820000&lt;BR /&gt;/sys/firmware/devicetree/base/soc/bus@30800000/spba-bus@30800000/spi@30830000&lt;BR /&gt;/sys/firmware/devicetree/base/soc/bus@30800000/spba-bus@30800000/spi@30840000&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;then look in device folder&amp;nbsp;&lt;/P&gt;&lt;P&gt;# ls /sys/firmware/devicetree/base/soc/bus@30800000/spba-bus@30800000/spi@30820000&lt;BR /&gt;#address-cells clocks dmas reg&lt;BR /&gt;#size-cells compatible interrupts status&lt;BR /&gt;clock-names &lt;STRONG&gt;dma-names&lt;/STRONG&gt; name&lt;/P&gt;&lt;P&gt;DMA is enabled, just check what's in dma-names&lt;/P&gt;&lt;P&gt;hexdump -C /sys/firmware/devicetree/base/soc/bus@30800000/spba-bus@30800000/spi@30820000/dma-names&lt;BR /&gt;00000000 72 78 00 74 78 00 |rx.tx.|&lt;BR /&gt;00000006&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regarding "&lt;SPAN&gt;only carry out DMA transfer if the data size is more than 64 bytes"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Not 64 bytes but 64 (x 32bit) FIFO entries. So more than 64 bytes with 8-bit transfer units; 64 words or double words in 16- and 32-bit mode. If you are using spidev_test utility, -b / --bpw bits per word command line switch controls it. Your Linux SPI device as well specifies transfer bits per word. Most likely your driver uses 8-bits to simplify compatibility.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Shorter than 64x transfers simply don't need DMA at all, FIFO is enough.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 10:16:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2011908#M231855</guid>
      <dc:creator>kef2</dc:creator>
      <dc:date>2024-12-11T10:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Use DMA transaction in SPI device driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2012020#M231859</link>
      <description>&lt;P&gt;Thank you for your response!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, I want to continuously read the data from an ADC in the kernel thread, so when I don't use the DMA and go with the PIO method, the CPU usage just goes crazy (&amp;gt; 70%). For SPI transactions, I wish to offload that using DMA. I have made changes in the spi-imx.c to forcefully use the dma instead of 64-byte fifo limit.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;While the standard regiser read/write APIs function well with DMA, the SPI transactions fail when reading the samples, and spi_sync returns an error code.&lt;/P&gt;&lt;P&gt;What could be the issue? Something I have overlooked?&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: When I perform a register read/write transaction, I also receive the DMA debug prints, confirming that DMA is functioning with register read/write.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my api to read the samples&lt;/P&gt;&lt;P&gt;int ad4134_sample_read(struct spi_device *spi)&lt;BR /&gt;{&lt;BR /&gt;int ret;&lt;BR /&gt;uint32_t pad[8] = {0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;struct spi_transfer tr =&lt;BR /&gt;{&lt;BR /&gt;.tx_buf = pad,&lt;BR /&gt;.rx_buf = st.sample,&lt;BR /&gt;.len = 32,&lt;BR /&gt;.bits_per_word = 32,&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;struct spi_message m;&lt;BR /&gt;spi_message_init(&amp;amp;m);&lt;/P&gt;&lt;P&gt;spi_message_add_tail(&amp;amp;tr, &amp;amp;m);&lt;BR /&gt;spi_sync(spi,&amp;amp;m);&lt;/P&gt;&lt;P&gt;return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 12:40:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2012020#M231859</guid>
      <dc:creator>pratham_malaviya</dc:creator>
      <dc:date>2024-12-11T12:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use DMA transaction in SPI device driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2017703#M232222</link>
      <description>&lt;P&gt;sorry for my delay, as I known imx8mp spi DMA has delay issue, I'm not sure if your case is caused by this issue I sent patch to you via mail, you can test it&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 07:42:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2017703#M232222</guid>
      <dc:creator>joanxie</dc:creator>
      <dc:date>2024-12-20T07:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use DMA transaction in SPI device driver</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2042686#M233932</link>
      <description>&lt;P&gt;I would like to do the same with iMX8MP and I thought to change the spi-imx.c mocking the UART driver tty/serial/imx.c based on cyrcular RX buffer.&lt;/P&gt;&lt;P&gt;Look at&amp;nbsp;imx_uart_start_rx_dma using&amp;nbsp;dmaengine_prep_dma_cyclic&lt;/P&gt;&lt;P&gt;Then you can get status of your ring with&amp;nbsp;dmaengine_tx_status, as you can find in&amp;nbsp;imx_uart_dma_rx_callback, or, I guess, you can even have the status of your ring without calling the callback, if you want a continuous transfer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 15:01:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Use-DMA-transaction-in-SPI-device-driver/m-p/2042686#M233932</guid>
      <dc:creator>atessadri</dc:creator>
      <dc:date>2025-02-12T15:01:55Z</dc:date>
    </item>
  </channel>
</rss>

