Create SPIdev devices at runtime - linux

I have a device with SPI bus which is connected via PCIe to a linux machine. I'm developing a simple SPI driver for this device. With spi_register_master I can create a SPI master (it is listed under /sys/class/spi_master/spixxxx).
For accessing the bus I would like to use spidev from the userland, but I have not found a way to register a spidev device at runtime. All ways I have found use the device tree to insert the information into the linux kernel.
Is there some way to create spidevdevicesat runtime?
Edit: I suppose it is the same problem with all protocol drivers and not limited to spidev.

Related

How can we create a virtio platform device?

I am writing a virtio driver for a device that is seen in the original driver as a platform device, that is the parent of a character device in the device tree.
In the tutorials that I followed, The virtio drivers are always done for "regular" character devices.
I wanted to create my virtio driver for it to expose a fake platform device as a parent of a "regular" character device.
My question is this one: Should I detect my virtual device in the regular way using the probe function and then create my platform device inside of it or is there a recommended way or order to create both (the platform device and the character device (child))?
When we get the virtio device and trigger the associated probe, we can then register a platform driver and then add some platform devices correponding to your needs.
And your device will appear as a platform device instead of a virtio_device in the guest OS.

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.

Add a SPI filter between driver controller and userspace spidev driver on Linux

We have Linux on a product. The customer is free to write its own application and need to use the spidev driver to access a specific peripheral.
This peripheral is accessed through the SPI master driver for Atmel processor (spi-atmel.c).
Now, I would like to control/limit some data and command which can be sent from the userspace (user application) to this particular peripheral.
I need to keep compatibility on user side and then keep the spidev interface so my basic idea would be to add a driver between the spidev and the master SPI controller but I'm not sure if it's the best way and if so how to achieve that correctly, do you have an idea ?
Thank for your help,
Regards

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

How to access i2c device driver node

Situation 1:
I have an i2c chip driver as part of linux kernel. I can verify the i2c chip driver is in the kernel from kernel boot messages (my chip driver is mma8450)
dmesg:
mma8450 0-001c: uevent
I can also see this driver in (0x1c is i2c address of chip)
cat /sys/bus/i2c/devices/0-001c/name
mma8450
I can not see this driver node in /dev interface. My question is how can I create node of this device in /dev so that I can access this device in a user program ?
Situation 2:
I create the module of the same chip driver and does not make it a part of kernel. I can load this module using insmod mma8450, how can I create a node of this device as I don't have its major / minor numbers ? (I can not see major & minor numbers assigned to this driver in mma8450 source code)
Any help is appreciated
Regards
Load the kernel module:
modprobe i2c-dev
ls /dev/i2*
/dev/i2c-0
/dev/i2c-10
/dev/i2c-12
/dev/i2c-14
/dev/i2c-3
/dev/i2c-5
/dev/i2c-7
/dev/i2c-9
/dev/i2c-1
/dev/i2c-11
/dev/i2c-13
/dev/i2c-2
/dev/i2c-4
/dev/i2c-6
/dev/i2c-8
Find the major/minor numbers for your device:
cat /proc/devices
You should see a device for the i2c bus and one for the i2c device itself.
Create the device node for the i2c device driver:
mknod /dev/[device name] [type] [major] [minor]
This is 3-Axis Accelerometer. Linux registers it as a driver for input_polled_dev type.
You can uaccess it using /dev/i2c-x bus (controller) device node, but there is no much sense using it that way directly from userspace.
I2C clients are not meant to be used using /dev device nodes.
They should be registered to Kernel I2C framework and used through higher layers API.
There is sample program for reading similar MMA7455L x,y,z registers from userspace using /dev/i2c-X bus device node.
Reading the Accelerometer With I²C

Resources