register platform device

1
2
3
4
static void __init (void)
{
platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int platform_add_devices(struct platform_device **devs, int num)
{
for (i = 0; i < num; i++)
ret = platform_device_register(devs[i]);
return platform_device_add(pdev);
pdev->dev.bus = &platform_bus_type;
// set name
if (pdev->id != -1) //
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
else
dev_set_name(&pdev->dev, "%s", pdev->name);

ret = device_add(&pdev->dev);
bus_probe_device(dev);
}

bus_probe_device

增加一个device时会对platform bus上的所有driver,都执行__device_attach

1
2
3
4
5
6
7
8
9
10
11
12
13
void bus_probe_device(struct device *dev)
{
struct bus_type *bus = dev->bus;

if (bus && bus->p->drivers_autoprobe)
ret = device_attach(dev);
ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
// 遍历platform bus上的所有driver,都执行fn()
klist_iter_init_node(&bus->p->klist_drivers, &i,
start ? &start->p->knode_bus : NULL);
while ((drv = next_driver(&i)) && !error)
error = fn(drv, data);
}

__device_attach

先match,match成功则probe

1
2
3
4
5
6
7
static int __device_attach(struct device_driver *drv, void *data)
{
driver_match_device(drv, dev);
return drv->bus->match ? drv->bus->match(dev, drv) : 1; // platform_match

return driver_probe_device(drv, dev);
}