Commit f6bec0e6 authored by Patrick Mochel's avatar Patrick Mochel

driver model: add better platform device support.

Platform devices are devices commonly found on the motherboard of systems. This
includes legacy devices (serial ports, floppy controllers, parallel ports, etc)
and host bridges to peripheral buses. 

We already had a platform bus type, which gives a way to group platform devices
and drivers, and allow each to be bound to each other dynamically. Though before,
it didn't do anything. It still doesn't do much, but we now have:

- struct platform_device, which generically describes platform deviecs. This only
  includes a name and id in addition to a struct device, but more may be added later.

- implelemnt platform_device_register() and platform_device_unregister() to handle
  adding and removing these devices. 

- Create legacy_bus - a default parent device for legacy devices. 

- Change the floppy driver to define a platform_device (instead of a sys_device). 
  In driverfs, this gives us now:

a# tree -d /sys/bus/platform/
/sys/bus/platform/
|-- devices
|   `-- floppy0 -> ../../../root/legacy/floppy0
`-- drivers

and

# tree -d /sys/root/legacy/
/sys/root/legacy/
`-- floppy0
parent d668723c
......@@ -7,6 +7,6 @@ obj-y := core.o sys.o interface.o power.o bus.o \
obj-y += fs/
export-objs := core.o power.o sys.o bus.o driver.o \
class.o intf.o cpu.o
class.o intf.o platform.o cpu.o
include $(TOPDIR)/Rules.make
......@@ -9,19 +9,56 @@
#include <linux/module.h>
#include <linux/init.h>
static struct device legacy_bus = {
.name = "legacy bus",
.bus_id = "legacy",
};
/**
* platform_device_register - add a platform-level device
* @dev: platform device we're adding
*
*/
int platform_device_register(struct platform_device * pdev)
{
if (!pdev)
return -EINVAL;
if (!pdev->dev.parent)
pdev->dev.parent = &legacy_bus;
pdev->dev.bus = &platform_bus_type;
snprintf(pdev->dev.bus_id,BUS_ID_SIZE,"%s%u",pdev->name,pdev->id);
pr_debug("Registering platform device '%s'. Parent at %s\n",
pdev->dev.bus_id,pdev->dev.parent->bus_id);
return device_register(&pdev->dev);
}
void platform_device_unregister(struct platform_device * pdev)
{
if (pdev)
put_device(&pdev->dev);
}
static int platform_match(struct device * dev, struct device_driver * drv)
{
return 0;
}
struct bus_type platform_bus = {
struct bus_type platform_bus_type = {
.name = "platform",
.match = platform_match,
};
static int __init platform_bus_init(void)
{
return bus_register(&platform_bus);
device_register(&legacy_bus);
return bus_register(&platform_bus_type);
}
postcore_initcall(platform_bus_init);
EXPORT_SYMBOL(platform_device_register);
EXPORT_SYMBOL(platform_device_unregister);
......@@ -4220,7 +4220,7 @@ static int __init floppy_setup(char *str)
static int have_no_fdc= -ENODEV;
static struct sys_device floppy_device = {
static struct platform_device floppy_device = {
.name = "floppy",
.id = 0,
.dev = {
......@@ -4379,7 +4379,7 @@ int __init floppy_init(void)
add_disk(disks + drive);
}
sys_device_register(&floppy_device);
platform_device_register(&floppy_device);
return have_no_fdc;
}
......@@ -4563,7 +4563,7 @@ void cleanup_module(void)
{
int drive;
sys_device_unregister(&floppy_device);
platform_device_unregister(&floppy_device);
devfs_unregister (devfs_handle);
unregister_blkdev(MAJOR_NR, "fd");
blk_set_probe(MAJOR_NR, NULL);
......
......@@ -402,7 +402,17 @@ extern void sys_device_unregister(struct sys_device *);
extern struct bus_type system_bus_type;
/* drivers/base/platform.c */
extern struct bus_type platform_bus;
struct platform_device {
char * name;
u32 id;
struct device dev;
};
extern int platform_device_register(struct platform_device *);
extern void platform_device_unregister(struct platform_device *);
extern struct bus_type platform_bus_type;
/* drivers/base/power.c */
extern int device_suspend(u32 state, u32 level);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment