Detect the presence of a device when it's hot plugged in Linux
Asked Answered
B

1

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?

Bully answered 1/4, 2014 at 5:38 Comment(0)
S
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
Steve answered 1/4, 2014 at 6:1 Comment(8)
can you please explain the structure members of of_device_id I searched online, but I couldn't find the explanation.Bully
Especially explanation of the member .dataBully
Read the 2nd link, it's explained under Preprocessor Abuse .Steve
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.Indemonstrable
Nevermind, I found here 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.Indemonstrable
the links provided are no longer valid :(Linton
@Linton Here are working links web.archive.org/web/20141216112516/http://www.linux-mag.com/id/… and web.archive.org/web/20161108061014/http://www.linuxjournal.com/… -- I tried to amend the answer, but the edit queue was full already.Dispense
@Steve - does the struct pci_device_id my_pci_tbl that I define and add to the MODULE_DEVICE_TABLE(pci, my_pci_tbl);` ALSO HAS to be set in the (PCI in this case) id_table of the `struct pci_driver pchar_driver = { .name = "my pci device", .id_table = my_pci_tbl, .probe = my_probe_function, remove = my_remove_function,}Twotime

© 2022 - 2024 — McMap. All rights reserved.