Interrupt driven SPI or I2C driver - linux

I am working on a user application, which depends on I2C or SPI device connected with the beaglebone board.
My app is running in userspace. Now whenever an interrupt occurs from I2c device, My application should get the data from I2c device.
My question is how to sync all these. Do I need to write a device driver which gets the data from I2c device or trigger another device driver to read the data from I2c and how it can trigger my user app to get the data?

You'll need to know about three things: i2c drivers, spi drivers and input subsystem.
For i2c drivers, search kernel code for struct i2c_driver and module_i2c_driver helper macro for registering and unregistering the driver.
Similarly, struct spi_driver and module_spi_driver for spi.
For input subsystem, search for struct input_dev. Among other things, you'll need to "hook" into interesting events by setting relevant event bits and implement input_event event handler.
UPDATE: Forgot to mention, aim of input subsystem is to help take care of input events coming in from i2c or spi device.

Related

AM335x - i2c slave for linux kernel

I need to have i2c slave Linux kernel driver for TI AM335x.
I googled about and didn't find precise information.
Should I do everything from scratch, or maybe someone has some reference about it? or even a patch
Thanks
Avner
For new device which connected as slave to i2c bus, you should write neither "i2c driver" nor "driver for AM335x" (as far as the processor support already present in kernel).
i2c is a bus and there is kernel infrastructure for the bus, see documentation.
You should figure out what type your device is and then write driver for this type of device using i2c bus primitives.
For example, the driver for DS13xx and compatible IC is rtc driver.
A driver "for" PCF8574 i2c gpio expander can be GPIO driver as well as keypad driver.

How existing kernel driver should be initialized as PCI memory-mapped?

Existing kernel drivers such as xilinx have specific way to be registered (as tty device), if they are mapped directly to cpu memory map as done here with device tree:
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842249/Uartlite+Driver
But in other cases, there is a PCIe device (like FPGA which has the xilinx uart IPs) which is connected to and the cpu.
How should we make the uart get registered when using PCIe device ?
The device tree I try to register into PCIe is uartlite driver:
https://github.com/Xilinx/linux-xlnx/blob/master/drivers/tty/serial/uartlite.c
I think that what I probably need to do is:
Write a custom pci driver.
Need to prepare platform_device struct and then call the uart probe routine from pci driver:
ulite_probe(struct platform_device *pdev)
I've seen related question with others using FPGA with multiple device connected, but seems that there is no docuemnt, or tutorial which describes how to do this.
Any comment, example or document is appreciated.
So something like a ARM CPU connected to an Artix FPGA over PCIe right?
Yes, you would need a custom PCIe driver. The PCIe configuration and data spaces would have to be mapped. Have a look at pci_resource_{start, len} and pci_remap_bar functions. You can then use pci_get_device to get a pointer to the struct device and retrieve the virtual address of the PCIe configuration space. The UART driver can then use the struct device pointer and it's register map should be at some offset to the virtual address of the PCIe configuration space as per your design. You can invoke the probe call of UARTlite IP driver in your own driver.
"Existing kernel drivers such as xilinx have specific way to be registered (as tty device), if they are mapped directly to cpu memory map as done here with device tree". Note that this is true if we are only talking of tty devices. A GPIO peripheral IP won't be expose as tty but in /sys/class/gpio.

SPI Interface linux

Micro controller is connected to Ethernet controller through SPI interface. Ethernet controller always gets configuration information from EEPROM(128) when board boots up. I have written basic driver to read/write eeprom, used data, control and status register to do read write opperation. This registers are memory mapped to process address space. Selecting eeprom by making chip select through GPIO.
Question: In the above scenario, what is the need SPI driver to read/write EEPROM. This register read operation is using SPI driver internally..?
Thanks
As mentioned by you "Micro controller is connected to Ethernet controller through SPI interface. Ethernet controller always gets configuration information from EEPROM(128) when board boots up."
It means that the ethernet is tied to SPI bus. It cannot read/write data on it's own.It means eeprom is not using SPI but Ethernet controller is using it.Since it is reading/writing from/to EEPROM and hence it might be giving illusion that EEPROM is using SPI.
Note:- I am assuming EEPROM is not tied to SPI.

How to access USB bus number from Linux device driver?

I have two identical USB devices connected to different USB host controllers. Sometimes devices initialization order changes spontaneously breaking devices enumeration. Is there a way to get USB bus number in device driver (it would be enough for implementing of correct initialization) like it is done in user space with lsusb?
I found the decision. The task was to get USB bus number in kernel module, the similar task was found at this post. It was necessary to get a bus->busnum member of usb_device structure in the driver init function:
struct usb_device *usbdev;
struct usb_bus *mybus;
usbdev=interface_to_usbdev(pusb_intf);
mybus=usbdev->bus;
printk("USB Bus number is %d\n",mybus->busnum);

Are DMA transfers supported with the davinci-spi device driver that is configured using devicetree?

I am trying to use DMA to program an FPGA connected to an OMAP-L138's SPI bus, but without success.
Currently, I am using the stock davinci-spi driver (drivers/spi/spi-davinci.c)that comes with linux 3.19. FPGA configuration is successful (without DMA enabled), but it is very slow. I am using a device tree to configure the SPI interface.
I would like to use DMA to improve performance, however from looking at the spi-davinci.c source code and its device tree bindings, the driver does not appear to support DMA when configured with device tree. Is my understanding correct? If so, are there any plans to support DMA transfers using davinci's SPI driver when also using device tree?
Here are a few guidelines to achieve your goal:
First, check if the SPI has it's own DMA engine. If it doesn't, perhaps there's a generic DMA controller on board. You can check this by looking at the SPI datasheet and looking at the board interconnect schematics.
If none of the above are true, then you can't use DMA with the SPI.
If the SPI has its own DMA, you'll need to write a driver for that.
If there's a DMA on board, it's probably utilized by other components, search for dma_dngine driver for that particular device. Then you'll need to create a DMA client for that particular DMA engine.
Please read:
DMA Provider
DMA Client
Good luck

Resources