2009-02-25 23:51:19 +00:00
|
|
|
/*
|
2009-12-15 08:11:09 +00:00
|
|
|
* bus.c - barebox driver model
|
2009-02-25 23:51:19 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2011-08-09 17:12:34 +00:00
|
|
|
#include <errno.h>
|
2012-09-20 05:36:44 +00:00
|
|
|
#include <init.h>
|
2009-02-25 23:51:19 +00:00
|
|
|
|
|
|
|
static int platform_match(struct device_d *dev, struct driver_d *drv)
|
|
|
|
{
|
2011-08-09 17:12:34 +00:00
|
|
|
if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
|
|
|
|
drv->of_compatible)
|
|
|
|
return of_match(dev, drv);
|
|
|
|
|
2012-09-09 14:28:59 +00:00
|
|
|
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;
|
2009-02-25 23:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int platform_probe(struct device_d *dev)
|
|
|
|
{
|
|
|
|
return dev->driver->probe(dev);
|
|
|
|
}
|
|
|
|
|
2009-02-27 00:10:36 +00:00
|
|
|
static void platform_remove(struct device_d *dev)
|
2009-02-25 23:51:19 +00:00
|
|
|
{
|
2009-02-27 00:10:36 +00:00
|
|
|
dev->driver->remove(dev);
|
2009-02-25 23:51:19 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 19:22:17 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
return register_device(new_device);
|
|
|
|
}
|
|
|
|
|
2009-02-25 23:51:19 +00:00
|
|
|
struct bus_type platform_bus = {
|
|
|
|
.name = "platform",
|
|
|
|
.match = platform_match,
|
|
|
|
.probe = platform_probe,
|
|
|
|
.remove = platform_remove,
|
|
|
|
};
|
|
|
|
|
2012-12-03 10:05:34 +00:00
|
|
|
static int platform_init(void)
|
2009-02-25 23:51:19 +00:00
|
|
|
{
|
2012-09-20 05:36:44 +00:00
|
|
|
return bus_register(&platform_bus);
|
2009-02-25 23:51:19 +00:00
|
|
|
}
|
2012-12-03 10:05:34 +00:00
|
|
|
pure_initcall(platform_init);
|