blob: 13b4620506f9ca821a5e52e81ef46b653ed480a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* bus.c - barebox driver model
*
* Copyright (c) 2009 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <common.h>
#include <driver.h>
#include <errno.h>
#include <init.h>
static int platform_match(struct device_d *dev, struct driver_d *drv)
{
if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
drv->of_compatible)
return of_match(dev, drv);
if (!strcmp(dev->name, drv->name))
return 0;
if (drv->id_table) {
struct platform_device_id *id = drv->id_table;
while (id->name) {
if (!strcmp(id->name, dev->name)) {
dev->id_entry = id;
return 0;
}
id++;
}
}
return -1;
}
static int platform_probe(struct device_d *dev)
{
return dev->driver->probe(dev);
}
static void platform_remove(struct device_d *dev)
{
dev->driver->remove(dev);
}
int platform_driver_register(struct driver_d *drv)
{
drv->bus = &platform_bus;
return register_driver(drv);
}
int platform_device_register(struct device_d *new_device)
{
new_device->bus = &platform_bus;
if (new_device->resource) {
struct device_d *dev;
bus_for_each_device(new_device->bus, dev) {
if (!dev->resource)
continue;
if (dev->resource->start == new_device->resource->start) {
return -EBUSY;
}
}
}
return register_device(new_device);
}
struct bus_type platform_bus = {
.name = "platform",
.match = platform_match,
.probe = platform_probe,
.remove = platform_remove,
};
static int plarform_init(void)
{
return bus_register(&platform_bus);
}
pure_initcall(plarform_init);
|