Revert "Remove support for xpp drivers."
[dahdi/linux.git] / drivers / dahdi / xpp / mmapbus.c
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/device.h>
4 #include "mmapbus.h"
5
6 static int mmap_match(struct device *dev, struct device_driver *driver)
7 {
8         return !strncmp(dev_name(dev), driver->name, strlen(driver->name));
9 }
10
11 static int mmap_uevent(struct device *dev, char **envp, int num_envp,
12                        char *buffer, int buffer_size)
13 {
14         envp[0] = buffer;
15         envp[1] = NULL;
16         return 0;
17 }
18
19 static void mmap_bus_release(struct device *dev)
20 {
21 }
22
23 static void mmap_dev_release(struct device *dev)
24 {
25 }
26
27 static struct bus_type mmap_bus_type = {
28         .name = "mmap",
29         .match = mmap_match,
30         .uevent = mmap_uevent,
31 };
32
33 static struct device mmap_bus = {
34         .bus_id = "mmap0",
35         .release = mmap_bus_release,
36 };
37
38 int register_mmap_device(struct mmap_device *dev)
39 {
40         dev->dev.bus = &mmap_bus_type;
41         dev->dev.parent = &mmap_bus;
42         dev->dev.release = mmap_dev_release;
43         strncpy(dev->dev.bus_id, dev->name, BUS_ID_SIZE);
44         return device_register(&dev->dev);
45 }
46 EXPORT_SYMBOL(register_mmap_device);
47
48 void unregister_mmap_device(struct mmap_device *dev)
49 {
50         device_unregister(&dev->dev);
51 }
52 EXPORT_SYMBOL(unregister_mmap_device);
53
54 int register_mmap_driver(struct mmap_driver *driver)
55 {
56         driver->driver.bus = &mmap_bus_type;
57         return driver_register(&driver->driver);
58 }
59 EXPORT_SYMBOL(register_mmap_driver);
60
61 void unregister_mmap_driver(struct mmap_driver *driver)
62 {
63         driver_unregister(&driver->driver);
64 }
65 EXPORT_SYMBOL(unregister_mmap_driver);
66
67 int register_mmap_bus(void)
68 {
69         int ret = 0;
70         if ((ret = bus_register(&mmap_bus_type)) < 0)
71                 goto bus_type_reg;
72         if ((ret = device_register(&mmap_bus)) < 0)
73                 goto bus_reg;
74         return ret;
75
76 bus_reg:
77         bus_unregister(&mmap_bus_type);
78 bus_type_reg:
79         return ret;
80 }
81 EXPORT_SYMBOL(register_mmap_bus);
82
83 void unregister_mmap_bus(void)
84 {
85         device_unregister(&mmap_bus);
86         bus_unregister(&mmap_bus_type);
87 }
88 EXPORT_SYMBOL(unregister_mmap_bus);
89
90 MODULE_AUTHOR("Alexander Landau <landau.alex@gmail.com>");
91 MODULE_LICENSE("GPL");