LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-05-2018, 02:01 AM   #1
rksyeung
Member
 
Registered: Feb 2018
Posts: 70

Rep: Reputation: Disabled
How to find driver given device, major and minor numbers


I've a device, /dev/i2c-0, with major #=89, and minor=0. How do I find out the name of the driver? I'd searched online and tried one approach using /sys/dev, but didn't work too well for me. And we've a number of i2c implementations. Note, this seems to be a user's space driver as there is no .ko file (and couldn't identify one with lsmod).
 
Old 06-05-2018, 02:48 AM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
cat /proc/devices will give major numbers and their corresponding modules.
 
Old 06-05-2018, 11:29 AM   #3
rksyeung
Member
 
Registered: Feb 2018
Posts: 70

Original Poster
Rep: Reputation: Disabled
I'd tried dumping /proc/devices previously, but this doesn't tell me anything about the driver. What I'm looking for is something similar to modinfo that gives .ko file name:

/proc # modinfo ipv6
filename: /lib/modules/2.6.32.27-Cavium-Octeon/kernel/net/ipv6/ipv6.ko
alias: net-pf-10
[snip]
 
Old 06-05-2018, 11:55 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,705
Blog Entries: 13

Rep: Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922
Please note that the /proc/devices file does not show any information about the module, it only shows the character or block driver ID number, which you see as 89, and then the name of the driver type, which in this case is i2c. That is the ID of the driver.

To see what is on your i2c bus you would use a utility like i2cdetect and then put in the bus number, which typically may be 1, 2, or 3. If it blows up and shows what appears to be errors, there is no bus and you happen to be scanning memory. If it gives you a brief report, which looks something like this:
Code:
# i2cdetect 3
i2cdetect: WARNING! This program can confuse your I2C bus
Continue? [y/N] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: UU 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --
Then you have an i2c bus there and also may have devices. In this case my bus has devices on bus #3 at addresses 50 - 57.

An example of a case where there is no bus, such as an attempt to read bus #1 on my machine shows:
Code:
# i2cdetect 1
i2cdetect: WARNING! This program can confuse your I2C bus
Continue? [y/N] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          at91_i2c fc028000.i2c: controller timed out
-- at91_i2c fc028000.i2c: controller timed out
That will continue until you hit CTRL-C, but the point there is that the interface is really not an I2C and you're just looking at random memory.

There are also i2cget and i2cset functions as well as i2cdump which you can use. You would have to have an i2c package installed to allow you to talk to this interface. You may have it, you may have to look for a package repository for your distribution which contains it. I suggest you type "i2c[TAB]" to determine if you have these utilities. It seems likely because i2c is there as a driver on your system. A typical i2c device would be a real time clock or temperature device.

Meanwhile, the report of a device type of 89 is nothing more than the ID of the i2c driver in the kernel.
 
Old 06-05-2018, 12:58 PM   #5
rksyeung
Member
 
Registered: Feb 2018
Posts: 70

Original Poster
Rep: Reputation: Disabled
Thanks for the tips. Perhaps I'm not clear enough. I'm trying to understand our code (as a new hire). The code base however has many more i2c files/directories than I expect. I'm looking for a way at run-time to trace down the file(s) I should be looking into. I'd done similar thing with 10Gbe driver which is a LKM. I did lsmod and then modinfo, and I was able to pin point with more accuracy the driver (and thus file) name.

The driver I'm dealing with is not a LKM; it appears to be a User's space driver. I could go by static analysis also, if there are specific APIs used to bind the major number to the driver. This could be used for grepping. Any other tips?
 
Old 06-05-2018, 01:28 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,705
Blog Entries: 13

Rep: Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922Reputation: 3922
It is still worth reading the code a bit more. Concentrate on a limited set of i2c files. There has to be an initialization main section for i2c for starters, and then if there are tons of devices in the code, active or inactive (i.e. if old code is around because no one wishes to throw it away). There also should be one or more Makefiles as well.

Someone could have written a kernel module named rtc-driver for a real time clock, which uses i2c, but does not have i2c in the name; however in the source files, ultimately you'll run into i2c somewhere. Or they could have written a user space application which employs i2c communications, but does not contain the string i2c in the file names. Same comment, "within" those files you should see the string.

The i2c utilities I remarked about in my other post, i2cdetect, i2cget, i2cset, and i2cdump? Those can be found as source files somewhere, I'm sure they can be, just not looking because you can do that just as readily as myself. They'll show you how those files access i2c devices.

All that as well as ask someone you work with.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB device driver Major No. Minor NO. neccesity? rohaanembedded Programming 1 07-16-2013 01:29 AM
unable to find device-mapper major/minor? help!!!!! can't boot up! kernel panic! newtovanilla Linux - Newbie 5 11-23-2008 02:39 PM
how to find major and minor device numbers Steve Riley Red Hat 2 03-25-2008 06:46 PM
special device node minor and major numbers crash88 Linux - General 1 06-22-2006 12:17 PM
Where can i find major and minor numbers yugandhar Linux - Software 1 06-02-2006 03:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration