9
0
Fork 0

driver: register bus

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2012-09-20 07:36:44 +02:00 committed by Sascha Hauer
parent 33a8fa16c6
commit 72b0a6503f
8 changed files with 71 additions and 10 deletions

View File

@ -1,3 +1,4 @@
obj-y += bus.o
obj-y += driver.o obj-y += driver.o
obj-y += platform.o obj-y += platform.o
obj-y += resource.o obj-y += resource.o

34
drivers/base/bus.c Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
*
* Under GPLv2
*/
#include <common.h>
#include <driver.h>
#include <errno.h>
LIST_HEAD(bus_list);
EXPORT_SYMBOL(bus_list);
struct bus_type *get_bus_by_name(const char *name)
{
struct bus_type *bus;
for_each_bus(bus) {
if(!strcmp(bus->name, name))
return bus;
}
return NULL;
}
int bus_register(struct bus_type *bus)
{
if (get_bus_by_name(bus->name))
return -EEXIST;
list_add_tail(&bus->list, &bus_list);
return 0;
}

View File

@ -22,6 +22,7 @@
#include <common.h> #include <common.h>
#include <driver.h> #include <driver.h>
#include <errno.h> #include <errno.h>
#include <init.h>
static int platform_match(struct device_d *dev, struct driver_d *drv) static int platform_match(struct device_d *dev, struct driver_d *drv)
{ {
@ -64,15 +65,8 @@ struct bus_type platform_bus = {
.remove = platform_remove, .remove = platform_remove,
}; };
#if 0 static int plarform_init(void)
LIST_HEAD(bus_list);
EXPORT_SYMBOL(bus_list);
int bus_register(struct bus_type *bus)
{ {
list_add_tail(&bus->list, &bus_list); return bus_register(&platform_bus);
return 0;
} }
#endif pure_initcall(plarform_init);

View File

@ -21,6 +21,7 @@
#include <errno.h> #include <errno.h>
#include <malloc.h> #include <malloc.h>
#include <xfuncs.h> #include <xfuncs.h>
#include <init.h>
#include <i2c/i2c.h> #include <i2c/i2c.h>
@ -395,3 +396,9 @@ struct bus_type i2c_bus = {
.probe = i2c_probe, .probe = i2c_probe,
.remove = i2c_remove, .remove = i2c_remove,
}; };
static int i2c_bus_init(void)
{
return bus_register(&i2c_bus);
}
pure_initcall(i2c_bus_init);

View File

@ -295,3 +295,9 @@ struct bus_type spi_bus = {
.probe = spi_probe, .probe = spi_probe,
.remove = spi_remove, .remove = spi_remove,
}; };
static int spi_bus_init(void)
{
return bus_register(&spi_bus);
}
pure_initcall(spi_bus_init);

View File

@ -1422,3 +1422,8 @@ struct bus_type usb_bus_type = {
.remove = usb_remove, .remove = usb_remove,
}; };
static int usb_bus_init(void)
{
return bus_register(&usb_bus_type);
}
pure_initcall(usb_bus_init);

View File

@ -1141,6 +1141,12 @@ struct bus_type fs_bus = {
.remove = fs_remove, .remove = fs_remove,
}; };
static int fs_bus_init(void)
{
return bus_register(&fs_bus);
}
pure_initcall(fs_bus_init);
int register_fs_driver(struct fs_driver_d *fsdrv) int register_fs_driver(struct fs_driver_d *fsdrv)
{ {
fsdrv->drv.bus = &fs_bus; fsdrv->drv.bus = &fs_bus;

View File

@ -383,6 +383,14 @@ struct bus_type {
struct list_head list; struct list_head list;
}; };
int bus_register(struct bus_type *bus);
extern struct list_head bus_list;
/* Iterate over all buses
*/
#define for_each_bus(bus) list_for_each_entry(bus, &bus_list, list)
extern struct bus_type platform_bus; extern struct bus_type platform_bus;
struct file_operations { struct file_operations {