Last edited one month ago

How to find Linux kernel driver associated to a device

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP25x lines

1. Introduction[edit source]

This article shows the user how to find the Linux® kernel driver associated to a kernel device.

This can, for example, be useful when debugging devices that the user does not know, or monitoring for correct system behavior.

2. Find kernel driver for a device[edit source]

2.1. Major and minor numbers for a Linux kernel device[edit source]

The device files in the Linux kernel are associated to a MAJOR and a MINOR number, giving each file a unitary identity. This abstraction of device handling is a basic features of the Linux kernel.

A list of MAJOR numbers, and rules for MINOR numbers are given in Documentation/admin-guide/devices.txt of the Linux kernel source[1], or in[2].

2.2. List of available devices[edit source]

A list of the available devices for the Linux kernel can be read from the procfs file /proc/devices:

cat /proc/devices

This lists all of the available devices, according to their classification as a character or a block device.
The number preceding the device name corresponds to the MAJOR number of the device (for example, "4" is the MAJOR number for the "tty" device):

Character devices:
  1 mem
  2 pty
  3 ttyp
  4 /dev/vc/0
  4 tty
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  5 ttyRPMSG
  7 vcs
 10 misc
 13 input
 21 sg
 29 fb
 81 video4linux
 89 i2c
 90 mtd
116 alsa
128 ptm
136 pts
153 spi
166 ttyACM
180 usb
189 usb_device
199 galcore
226 drm
245 cec
246 media
247 ttySTM
248 bsg
249 watchdog
250 iio
251 ptp
252 pps
253 rtc
254 gpiochip

Block devices:
  1 ramdisk
  7 loop
  8 sd
 11 sr
 31 mtdblock
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
179 mmc
254 virtblk
259 blkext

For further information about the major and minor numbers for a Linux kernel driver, refer to the Linux tutorial web page[3].

Note: 'Misc devices have a specific setup; you can find the list of misc devices with the corresponding MINOR number in the /proc/misc file.

2.3. Device entries in /dev[edit source]

Each device has a corresponding entry in the /dev directory of the Linux kernel pseudo filesystem.

ls -lR /dev

Be careful, /dev contains some sub-directories containing device entries, that is, input. That the reason why -R should be used.

This command lists all of the device entries, including the device type and the associated MAJOR and MINOR numbers

For example:

crw-rw---- 1 root video 81, 0 Dec 18 16:26 video0
This device video0 is of type character (c), with MAJOR number of 81 and MINOR number of 0.

2.4. System device entries in /sys/dev[edit source]

All devices, classified by type (char or block), and identified by their MAJOR/MINOR number can be found in the dev subdirectory of the sysfs file system entry (/sys).

A platform device is then linked to each MAJOR/MINOR number.

For example:

ls -l /sys/dev/char/81\:0
lrwxrwxrwx 1 root root 0 Dec 18 17:00 81:0 -> ../../devices/platform/soc/4c006000.dcmi/video4linux/video0
The device video0 is linked to the platform device 4c006000.dcmi/video4linux/video0.

2.5. Driver associated to a platform device[edit source]

If the device is linked to a platform device, you can find the corresponding driver definition in the device tree with the compatible parameter.

For example: Look for device 4c006000.dcmi/video4linux/video0 in arch/arm/boot/dts/stm32mp151.dtsi .

dcmi: dcmi@4c006000 {
 compatible = "st,stm32-dcmi";
 reg = <0x4c006000 0x400>;
 interrupts = <GIC_SPI 78 IRQ_TYPE_NONE>;
 resets = <&rcc CAMITF_R>;
 clocks = <&rcc DCMI>;
 clock-names = "mclk";
 dmas = <&dmamux1 75 0x400 0x05>;
 dma-names = "tx";
 status = "disabled";

The driver associated to the video0 device is st,stm32-dcmi.

If the driver belongs to your Linux kernel tree, you can search for the driver by declaring st,stm32-dcmi as a compatible device.

  • In the previous example, when looking for the driver compatible with st,stm32-dcmi, you find drivers/media/platform/stm32/stm32-dcmi.c driver
cd <your_kernel_source_path>
grep -rs "st,stm32-dcmi" *
drivers/media/platform/stm32/stm32-dcmi.c:	{ .compatible = "st,stm32-dcmi"},

If the driver is not part of your Linux kernel source tree, it is present as a kernel object library file and you can check on the board:

cd /lib/modules/<kernel_version>
grep <compatible_name> modules.alias

This gives you the name of the module driver.

For example, for the gcnano driver used for the GPU:

grep "st,gcnano" modules.alias
 alias of:N*T*Cst,gcnano galcore

This means that the module name is galcore.ko.

3. References[edit source]