3 * Copyright (C) 2007 David Cohen <dacohen@gmail.com>
4 * Copyright (C) 2007 Felipe Balbi <me@felipebalbi.com>
6 * This file is part of Tinyx Nanokernel Project.
8 * Tinyx is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Tinyx is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Tinyx. If not, see <http://www.gnu.org/licenses/>.
22 #include <tinyx/device.h>
23 #include <tinyx/list.h>
26 DECLARE_LIST_HEAD(bus_list
);
27 DECLARE_LIST_HEAD(driver_list
);
28 DECLARE_LIST_HEAD(device_list
);
30 static void *match_device_driver(struct device
*dev
, struct device_driver
*drv
)
32 struct list_head
*list
;
33 struct list_head
*entry
;
42 list_for_each(list
, entry
) {
44 item
= list_entry(entry
, struct device
, queue
);
45 ret
= strcmp(((struct device
*)item
)->name
, drv
->name
);
47 item
= list_entry(entry
, struct device_driver
, queue
);
48 ret
= strcmp(dev
->name
,
49 ((struct device_driver
*)item
)->name
);
60 int register_bus_type(struct bus_type
*bus
)
68 ret
= bus
->probe(bus
);
70 list_add_tail(&bus_list
, &bus
->queue
);
75 int register_device_driver(struct device_driver
*drv
)
83 dev
= match_device_driver(NULL
, drv
);
86 ret
= dev
->bus
->match(dev
->bus
, dev
, drv
);
87 if (!ret
&& drv
->probe
)
88 ret
= drv
->probe(dev
);
92 list_add_tail(&driver_list
, &drv
->queue
);
97 int register_device(struct device
*dev
, struct bus_type
*bus
)
100 struct device_driver
*drv
;
106 drv
= match_device_driver(dev
, NULL
);
109 ret
= bus
->match(bus
, dev
, drv
);
110 if (!ret
&& drv
->probe
)
111 ret
= drv
->probe(dev
);
115 list_add_tail(&device_list
, &dev
->queue
);