Re: When "probe" is called?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> However, could you point me out where the kernel actually detects the
> device? Is it keep polling with the driver's name which was given at compile
> time? Or Is there other mechanism to detect the device? Basically, how the
> kernel detects those devices, which calls "probe"?

Platform devices represent devices that are usually integrated into a
given chip and therefore are always there. The platform-specific
initialization code statically initializes such arrays of platform
devices and then registers them in a row using platform_register.
Therefore there is no need for sophisticated probing. Instead, the
string contained in platform_device.name is compared
platform_driver.driver.name and a match is assumed if they are equal.
Have a look at the attached example file that defines and registers a
dummy platform driver for a dummy platform device. If you change the
string, the probe function will not be called anymore.

Other buses have more sophisticated detection/probing methods. For
more information about platform devices, including the places where
these functions are called, see drivers/base/platform.c. Reading
Documentation/driver-model/platform.txt is also a good idea.

Alex.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>

static int __devinit drivertest_probe(struct platform_device *dev)
{
	printk(KERN_ALERT "Probe device: %s\n", dev->name);
	return 0;
}

static int drivertest_remove(struct platform_device *dev)
{
	return 0;
}

static void drivertest_device_release(struct device *dev)
{
}

static struct platform_driver drivertest_driver = {
	.driver = {
		.name = "drivertest",
		.owner = THIS_MODULE,
	},
	.probe = drivertest_probe,
	.remove = drivertest_remove,
};

static struct platform_device drivertest_device = {
	.name = "drivertest",
	.id = 0,
	.dev = {
		.release = drivertest_device_release,
	},
};

static int __init drivertest_init(void)
{
	printk(KERN_ALERT "Driver test init\n");
	platform_device_register(&drivertest_device);
	platform_driver_register(&drivertest_driver);
	return 0;
}

static void __exit drivertest_exit(void)
{
	printk(KERN_ALERT "Driver test exit\n");
	platform_driver_unregister(&drivertest_driver);
	platform_device_unregister(&drivertest_device);
}

module_init(drivertest_init);
module_exit(drivertest_exit);
MODULE_LICENSE("GPL");
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux