1 #include <tinyx/device.h>
2 #include <tinyx/list.h>
3 #include <tinyx/libc/string.h>
5 DECLARE_LIST_HEAD(bus_list
);
6 DECLARE_LIST_HEAD(driver_list
);
7 DECLARE_LIST_HEAD(device_list
);
9 static void *match_device_driver(struct device
*dev
, struct device_driver
*drv
)
11 struct list_head
*list
;
12 struct list_head
*entry
;
21 list_for_each(list
, entry
) {
23 item
= list_entry(entry
, struct device
, queue
);
24 ret
= strcmp(((struct device
*)item
)->name
, drv
->name
);
26 item
= list_entry(entry
, struct device_driver
, queue
);
27 ret
= strcmp(dev
->name
,
28 ((struct device_driver
*)item
)->name
);
39 int register_bus_type(struct bus_type
*bus
)
47 ret
= bus
->probe(bus
);
49 list_add_tail(&bus_list
, &bus
->queue
);
54 int register_device_driver(struct device_driver
*drv
)
62 dev
= match_device_driver(NULL
, drv
);
65 ret
= dev
->bus
->match(dev
->bus
, dev
, drv
);
66 if (!ret
&& drv
->probe
)
67 ret
= drv
->probe(dev
);
71 list_add_tail(&driver_list
, &drv
->queue
);
76 int register_device(struct device
*dev
, struct bus_type
*bus
)
79 struct device_driver
*drv
;
85 drv
= match_device_driver(dev
, NULL
);
88 ret
= bus
->match(bus
, dev
, drv
);
89 if (!ret
&& drv
->probe
)
90 ret
= drv
->probe(dev
);
94 list_add_tail(&device_list
, &dev
->queue
);