-   Linux - Kernel (
-   -   How to access i2c device driver node (

farrukh_arshad 05-19-2011 07:07 AM

How to access i2c device driver node
Greetings All,

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)


mma8450 0-001c: uevent

I can also see this driver in (0x1c is i2c address of chip)

cat /sys/bus/i2c/devices/0-001c

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

Farrukh Arshad.

bsat 05-20-2011 06:15 AM

the command to create nodes manually is "mknod"


mknod /dev/"device name" [types of device character/block] [major number] [minor number]
The source code might not have the major number if it follows dynamic allocation of major number.
To get to know the major number assigned to your module look in /proc/devices,after insmod.
The first column lists the major numbers and the second column the name with which the module was registered.

farrukh_arshad 05-23-2011 09:38 AM

Hi Bsat,

Thanks for the response. My /proc/devices lists the i2c bus driver

89 i2c

and I can see the node of this driver in /dev/ as /dev/i2c-0 /dev/i2c-1. I can verify both these nodes from

/sys/bus/i2c/devices/i2c-0 /sys/bus/i2c/devices/i2c-1

I have another i2c chip driver which is also appearing in /sys/bus/i2c/devices/0-001c. I can verify the device of this driver (& its the same device I am trying to access) from

cat /sys/bus/i2c/devices/0-001c/name.

I don't see any node for this device in /dev/

or perhaps I am asking the wrong question or doing it the wrong way. My problem is simple (i think so). I have a i2c accelerometer attached on i2c bus of my board. I can see the driver for this i2c chip in my linux system as I have mentioned above (/sys/bus/i2c/devices/0-001c/name). Now I want to access this chip through this driver, for which I believe in need a device node in /dev/ to open from a user space program, but I can't see the node !!

I was reading an article (,0) that i2c chip drivers expose their parameter values (readable/writable) in sysfs (each exposed parameter will create a file in sysfs). My question, should such i2c chip driver will be accessed through sysfs and if yes then how. Wouldn't my user space program will be highly dependent on one particular driver implementation.

Any thought or help is appreciated.

Farrukh Arshad.

robvoo 05-23-2011 09:54 AM

Did you include/load the i2c-dev module?
Check your kernel config file, or try
"lsmod | grep i2c-dev"

This creates the /dev/ references for the i2c bus.

Search the kernel documentation for more information (have a look at this link)

AustinMarton 06-02-2011 05:47 PM

When you do

cat /proc/devices
I would expect you to see a device for the i2c bus (at 89) AND the i2c device itself. If it hasn't been done automatically, you should be able to create a device node in /dev for the i2c device driver using mknod as bsat suggested:

mknod /dev/[device name] [type] [major number] [minor number]
Does that work?

AustinMarton 06-02-2011 06:00 PM

Also, where did you find the driver? Are you trying to use this recently submitted patch ? I can't find any mma8450 driver in the latest kernel.

farrukh_arshad 06-03-2011 06:51 AM

I am bit busy in other work so I haven't tried this so far. Will let you know when I do this.

Not sure about the patch you have mentioned but I found the driver from Freescale iMX53 Quick Start Board BSP for Linux provided by Freescale.

Go to "Board Support Packages" and download the file L2.6.35_11.03_ER_SOURCE. Apply patches and you will have your driver in kernel source.

garryhk 12-19-2012 11:05 PM

HI farrukh_arshad,

I ma new to device driver,,,Board is up,,,and i wanted to check the i2c devices present in the board...

Please let me know how we do it?

All times are GMT -5. The time now is 12:07 AM.