14

I am running the SPI code on the panda board and I want to know which function in the code is responsible for detecting the device when it's hot plugged.

Can somebody with the background of embedded systems, Linux device drivers and/or spi please answer my question?

Sagar Jain
  • 7,475
  • 12
  • 47
  • 83

1 Answers1

21

This is the line in your code that does the magic:

1286 MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);

Process:
1. Driver for each device exposes its information using the API MODULE_DEVICE_TABLE. Each device has a unique vendor Id and device Id.
2. At compilation time, the build process extracts this information out of the driver and builds a table.
3. When the device is plugged in, the kernel checks this device table to see if any driver is available for the particular Vendor/Device Id. If yes then it loads that driver and initializes the device.


Read following articles for more info:

  1. http://www.linux-mag.com/id/2617/
  2. http://www.linuxjournal.com/node/5604/print
brokenfoot
  • 11,083
  • 10
  • 59
  • 80
  • can you please explain the structure members of of_device_id I searched online, but I couldn't find the explanation. – Sagar Jain Apr 01 '14 at 06:28
  • Especially explanation of the member .data – Sagar Jain Apr 01 '14 at 06:36
  • 1
    Read the 2nd link, it's explained under `Preprocessor Abuse` . – brokenfoot Apr 01 '14 at 06:41
  • Is it called `device table`? I'm trying to query on google `linux print device table` *(e.g. to determine whether there is a driver for given product, vendor IDs)*, but see nothing relevant. – Hi-Angel Sep 08 '17 at 22:27
  • Nevermind, I found [here](https://unix.stackexchange.com/questions/26132/how-to-assign-usb-driver-to-device) that I can look it up in the file `/lib/modules/$(uname -r)/modules.alias`. I don't quite understand though what is the relation between the file and your `device table`. – Hi-Angel Sep 08 '17 at 22:41
  • 2
    the links provided are no longer valid :( – nightwatch Jul 23 '19 at 06:43
  • @nightwatch Here are working links http://web.archive.org/web/20141216112516/http://www.linux-mag.com/id/2617/ and http://web.archive.org/web/20161108061014/http://www.linuxjournal.com/node/5604/print -- I tried to amend the answer, but the edit queue was full already. – gstukelj Jul 22 '21 at 07:08