AM335x - i2c slave for linux kernel - linux

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.

Related

Create SPIdev devices at runtime

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.

Interrupt driven SPI or I2C driver

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.

How to write I2C Device Driver for i2c sensor?

I want to write i2c device driver for i2c sensor, I'm totally confusing with
what is:
i2c client driver
what is i2c host driver
what is i2c adapter driver
what is algorithm driver
how char driver access i2c device information
Get some information regarding for I2C Here. And This Documentation may help you to program it.

Simple SPI device driver

I have written a simple driver for a character device in Non Blocking mode using epoll.
Now I would like to use that driver for SPI interface.
What should be the device name or how will I map the actual device with the kernel ?
How will I use the interrupt?
Also who is the Master and Slave?Suppose I am connecting a SPI compatible device to the panda board.Will that device becomes a slave and the development board becomes Master?
I am a newbie.I am using a panda board.
In what way should I go through the Technical Reference manual?
I would really appreciate if anybody would explain and clarify my doubts.
You probably want to connect your driver to a SPI bus driver. This requires a slight reworking of your driver. See drivers/spi/spi.c
You'll be using the commands for the bus (master, the CPU side) to read and write the commands to the unit.
I don't know what a Panda board is, but if it connects via SPI, it might be a master, but it is probably a slave.
Go through the basics of spi here

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