Use SPI in kernel space for MCP3564

Hello,

We’re trying to access SPI in through a kernel module but probe function does not get called after module_spi_driver().

Right now spidev0.0 is enabled using device tree. Is there any way to access SPIDev library in kernel space itself.

If not, how can we write a driver to communicate with ADC chip MCP3564 (datasheet attached). and also, is there any way to use DMA as ADC chip also supports DMA.

Thank you,
Soham

Hello,
Awaiting response.

Hi @Soham

You could try to modify the following driver to make it work with the MCP3564:
http://git.toradex.com/cgit/linux-toradex.git/tree/drivers/iio/adc/mcp320x.c?h=toradex_5.4-2.1.x-imx
I think they are not exactly the same but similar.

The spidev API is only supported from user space. However, normally that should be fast enough. If you don’t want to implement it in kernel space that should work too.

Regarding DMA, the iMX8M Mini SPI controller supports transfers over DMA. It is enabled by default.

Regards,
Stefan

Hi @stefan_e.tx
I tried using mcp3911.c from this link

I’ve been able to communicate over SPI with MCP3564 but we need to calculate FFT at sampling rate = 7000 with a 10 seconds window (70000 samples). So we should get frequency resolution in ± 0.1 Hz. but right now we’ve not been able to achieve that in user space as well as kernel space.

In user space we used timers while in kernel we’ve used High Resolution Timers with Kthreads to be able to call spi_sync

I’m ready to share code if you want.

Please let me know where we might be going wrong?
(Is it practical to use timer with frequency of 7000 (period = 142.8 uSecs) in user-space)?

Thank you,
Soham

Hi @Soham

I think in theory you can handle it… But you will get a huge interrupt load and if another interrupt is running you will also get a big jitter. To reduce that you could use the RT patched kernel but then the CPU load would increase even more. What resolution do you achieve today? However, to have a proper resolution and low jitter I would recommend you to change the design and use e.g. a micro Controller or even an FPGA to queue the data.

Regards,
Stefan