2010/11/17 Dave Hylands <dhylands@xxxxxxxxx>: > Hi lalith, > > On Tue, Nov 16, 2010 at 12:19 AM, laliteshwar yadav <lalit4294@xxxxxxxxx> wrote: >> how probe function works? >> >> how is it getting called? >> >> after registering the device driver who is the first function to call it.. > > There are 2 things required for the probe function to be called: a > device and a driver. > > Normally, the architecture portion of the kernel registers devices for > all of the device that it has. > Then when you register a driver, it will detect if a device with a > matching name has been registered. If it finds a match, it will call > the probe routine. > > I normally work with linux in an embedded environment (ARM and MIPS), > not programming for linux under x86, so its possible that things > happen a little differently in that environment. > Dave gave the good explanation. In linux world, codes show everything. codes: /* Structure for a device driver */ static struct platform_driver gfar_driver = { .probe = gfar_probe, .remove = gfar_remove, .driver = { .name = "fsl-gianfar", }, }; 1987 static int __init gfar_init(void) 1988 { 1989 int err = gfar_mdio_init(); 1990 1991 if (err) 1992 return err; 1993 1994 err = platform_driver_register(&gfar_driver); 1995 1996 if (err) 1997 gfar_mdio_exit(); 1998 1999 return err; 2000 } 443 int platform_driver_register(struct platform_driver *drv) 444 { 445 drv->driver.bus = &platform_bus_type; 446 if (drv->probe) 447 drv->driver.probe = platform_drv_probe; 448 if (drv->remove) 449 drv->driver.remove = platform_drv_remove; 450 if (drv->shutdown) 451 drv->driver.shutdown = platform_drv_shutdown; 452 if (drv->suspend) 453 drv->driver.suspend = platform_drv_suspend; 454 if (drv->resume) 455 drv->driver.resume = platform_drv_resume; 456 return driver_register(&drv->driver); 457 } 217 int driver_register(struct device_driver *drv) 218 { 219 int ret; 220 221 if ((drv->bus->probe && drv->probe) || 222 (drv->bus->remove && drv->remove) || 223 (drv->bus->shutdown && drv->shutdown)) 224 printk(KERN_WARNING "Driver '%s' needs updating - please use " 225 "bus_type methods\n", drv->name); 226 ret = bus_add_driver(drv); 227 if (ret) 228 return ret; 229 ret = driver_add_groups(drv, drv->groups); 230 if (ret) 231 bus_remove_driver(drv); 232 return ret; 233 } > -- > Dave Hylands > Shuswap, BC, Canada > http://www.DaveHylands.com/ > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx > Please read the FAQ at http://kernelnewbies.org/FAQ > > -- Best Regards Lin -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ