A.whenever a device is registered on a bus, the kernel has to run the match function to find a matching driver. If there is a match the probe function of that driver is invoked.

MODULE_DEVICE_TABLE is used by the driver to tell kernel what kind of device it can support.At compilation time, the build process extracts
this information out of the driver and builds a table.

How device tree and driver matches

arch/arm/boot/dts/am335x-boneblack-common.dtsi
there is an i2c node

&i2c0 {
tda19988: tda19988 {
compatible = "nxp,tda998x";
reg = <0x70>;
.....
}

go to /home/mrigendra.chaubey/bbb/linux-4.4_prct/drivers/gpu/drm/i2c/tda998x_drv.c

this file declares ,

#ifdef CONFIG_OF
static const struct of_device_id tda998x_dt_ids[] = {
{ .compatible = "nxp,tda998x", },<------
{ }
};
MODULE_DEVICE_TABLE(of, tda998x_dt_ids);
#endif

static struct i2c_device_id tda998x_ids[] = {
{ "tda998x", 0 },<----------
{ }
};

So we can see that device properties are there in device .dtsi file and corresponding driver which supports this device is in driver directory of the kernel.When kernel gets this node it searches in a table for the driver and matches with this driver, and then probe is called.

b.
for platform drvier example check this one
/home/mrigendra.chaubey/bbb/linux-4.4/drivers/leds/leds-gpio.c
and
/home/mrigendra.chaubey/bbb/linux-4.4/arch/arm/boot/dts/am335x-bone-common.dtsi

check gpio-leds in compatible field
leds {
pinctrl-names = "default", "sleep";
pinctrl-0 = <&user_leds_default>;
pinctrl-1 = <&user_leds_sleep>;

compatible = "gpio-leds";

led@2 {
label = "beaglebone:green:usr0";
gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "heartbeat";
default-state = "off";
};

led@3 {
label = "beaglebone:green:usr1";
gpios = <&gpio1 22 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "mmc0";
default-state = "off";
};

led@4 {
label = "beaglebone:green:usr2";
gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "cpu0";
default-state = "off";
};

led@5 {
label = "beaglebone:green:usr3";
gpios = <&gpio1 24 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "mmc1";
default-state = "off";
};
};

Comments

Popular posts from this blog

dev_get_platdata understanding

How to take systrace in android

Getting started with pinctrl subsystem linux