开发者

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 ad开发者_高级运维dress 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜