9
0
Fork 0

we need different bus types

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2009-02-26 00:51:19 +01:00
parent 03c2189aa8
commit 4511a8873b
4 changed files with 93 additions and 8 deletions

View File

@ -68,6 +68,7 @@
/*@{*/ /* do not delete, doxygen relevant */
struct filep;
struct bus_type;
/** @brief Describes a particular device present in the system */
struct device_d {
@ -110,6 +111,7 @@ struct device_d {
/*! This describes the type (or class) of this device. Have a look at
* include/driver.h to see a list of known device types. Currently this
* includes DEVICE_TYPE_ETHER, DEVICE_TYPE_CONSOLE and others. */
struct bus_type *bus;
unsigned long type;
/*! The parameters for this device. This is used to carry information
@ -151,6 +153,7 @@ struct driver_d {
void (*shortinfo) (struct device_d *);
unsigned long type;
struct bus_type *bus;
/*! This is somewhat redundant with the type data in struct device.
* Currently the filesystem implementation uses this field while
@ -273,7 +276,7 @@ static inline int dev_close_default(struct device_d *dev, struct filep *f)
extern const char *dev_id(const struct device_d *dev);
#define dev_printf(dev, format, arg...) \
printf("%s@%s: " format , dev->name , \
printf("%s@%s: " format , (dev)->name , \
dev_id(dev) , ## arg)
#define dev_emerg(dev, format, arg...) \
@ -299,5 +302,15 @@ extern const char *dev_id(const struct device_d *dev);
({ if (0) dev_printf((dev), format, ##arg); 0; })
#endif
struct bus_type {
char *name;
int (*match)(struct device_d *dev, struct driver_d *drv);
int (*probe)(struct device_d *dev);
void (*remove)(struct device_d *dev);
struct list_head list;
};
extern struct bus_type platform_bus;
#endif /* DRIVER_H */

View File

@ -6,6 +6,7 @@ obj-y += vsprintf.o
obj-y += div64.o
obj-y += misc.o
obj-y += driver.o
obj-y += bus.o
obj-y += parameter.o
obj-y += xfuncs.o
obj-y += getopt.o

58
lib/bus.c Normal file
View File

@ -0,0 +1,58 @@
/*
* bus.c - U-Boot 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <common.h>
#include <driver.h>
static int platform_match(struct device_d *dev, struct driver_d *drv)
{
return strcmp(dev->name, drv->name) ? -1 : 0;
}
static int platform_probe(struct device_d *dev)
{
return dev->driver->probe(dev);
}
static int platform_remove(struct device_d *dev)
{
return dev->driver->remove(dev);
}
struct bus_type platform_bus = {
.name = "platform",
.match = platform_match,
.probe = platform_probe,
.remove = platform_remove,
};
#if 0
LIST_HEAD(bus_list);
EXPORT_SYMBOL(bus_list);
int bus_register(struct bus_type *bus)
{
list_add_tail(&bus->list, &bus_list);
return 0;
}
#endif

View File

@ -70,18 +70,21 @@ int get_free_deviceid(char *id, const char *id_template)
static int match(struct driver_d *drv, struct device_d *dev)
{
if (strcmp(dev->name, drv->name))
return -1;
if (dev->type != drv->type)
return -1;
if(drv->probe(dev))
return -1;
dev->driver = drv;
if (dev->bus != drv->bus)
goto err_out;
if (dev->bus->match(dev, drv))
goto err_out;
if (dev->bus->probe(dev))
goto err_out;
list_add(&dev->active, &active);
return 0;
err_out:
dev->driver = NULL;
return -1;
}
int register_device(struct device_d *new_device)
@ -94,6 +97,11 @@ int register_device(struct device_d *new_device)
}
debug ("register_device: %s\n",new_device->name);
if (!new_device->bus) {
// dev_err(new_device, "no bus type associated. Needs fixup\n");
new_device->bus = &platform_bus;
}
list_add_tail(&new_device->list, &device_list);
INIT_LIST_HEAD(&new_device->children);
@ -165,6 +173,11 @@ int register_driver(struct driver_d *drv)
debug("register_driver: %s\n", drv->name);
if (!drv->bus) {
// pr_err("driver %s has no bus type associated. Needs fixup\n", drv->name);
drv->bus = &platform_bus;
}
list_add_tail(&drv->list, &driver_list);
if (!drv->info)