1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*
* arch/sh/kernel/cpu/bus.c
*
* Virtual bus for SuperH.
*
* Copyright (C) 2004 Paul Mundt
*
* Shamelessly cloned from arch/arm/mach-omap/bus.c, which was written
* by:
*
* Copyright (C) 2003 - 2004 Nokia Corporation
* Written by Tony Lindgren <tony@atomide.com>
* Portions of code based on sa1111.c.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/module.h>
#include <asm/bus-sh.h>
static int sh_bus_match(struct device *dev, struct device_driver *drv)
{
struct sh_driver *shdrv = to_sh_driver(drv);
struct sh_dev *shdev = to_sh_dev(dev);
return shdev->dev_id == shdrv->dev_id;
}
static int sh_bus_suspend(struct device *dev, pm_message_t state)
{
struct sh_dev *shdev = to_sh_dev(dev);
struct sh_driver *shdrv = to_sh_driver(dev->driver);
if (shdrv && shdrv->suspend)
return shdrv->suspend(shdev, state);
return 0;
}
static int sh_bus_resume(struct device *dev)
{
struct sh_dev *shdev = to_sh_dev(dev);
struct sh_driver *shdrv = to_sh_driver(dev->driver);
if (shdrv && shdrv->resume)
return shdrv->resume(shdev);
return 0;
}
static int sh_device_probe(struct device *dev)
{
struct sh_dev *shdev = to_sh_dev(dev);
struct sh_driver *shdrv = to_sh_driver(dev->driver);
if (shdrv && shdrv->probe)
return shdrv->probe(shdev);
return -ENODEV;
}
static int sh_device_remove(struct device *dev)
{
struct sh_dev *shdev = to_sh_dev(dev);
struct sh_driver *shdrv = to_sh_driver(dev->driver);
if (shdrv && shdrv->remove)
return shdrv->remove(shdev);
return 0;
}
static struct device sh_bus_devices[SH_NR_BUSES] = {
{
.bus_id = SH_BUS_NAME_VIRT,
},
};
struct bus_type sh_bus_types[SH_NR_BUSES] = {
{
.name = SH_BUS_NAME_VIRT,
.match = sh_bus_match,
.probe = sh_bus_probe,
.remove = sh_bus_remove,
.suspend = sh_bus_suspend,
.resume = sh_bus_resume,
},
};
int sh_device_register(struct sh_dev *dev)
{
if (!dev)
return -EINVAL;
if (dev->bus_id < 0 || dev->bus_id >= SH_NR_BUSES) {
printk(KERN_ERR "%s: bus_id invalid: %s bus: %d\n",
__FUNCTION__, dev->name, dev->bus_id);
return -EINVAL;
}
dev->dev.parent = &sh_bus_devices[dev->bus_id];
dev->dev.bus = &sh_bus_types[dev->bus_id];
/* This is needed for USB OHCI to work */
if (dev->dma_mask)
dev->dev.dma_mask = dev->dma_mask;
snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%s%u",
dev->name, dev->dev_id);
printk(KERN_INFO "Registering SH device '%s'. Parent at %s\n",
dev->dev.bus_id, dev->dev.parent->bus_id);
return device_register(&dev->dev);
}
void sh_device_unregister(struct sh_dev *dev)
{
device_unregister(&dev->dev);
}
int sh_driver_register(struct sh_driver *drv)
{
if (!drv)
return -EINVAL;
if (drv->bus_id < 0 || drv->bus_id >= SH_NR_BUSES) {
printk(KERN_ERR "%s: bus_id invalid: bus: %d device %d\n",
__FUNCTION__, drv->bus_id, drv->dev_id);
return -EINVAL;
}
drv->drv.bus = &sh_bus_types[drv->bus_id];
return driver_register(&drv->drv);
}
void sh_driver_unregister(struct sh_driver *drv)
{
driver_unregister(&drv->drv);
}
static int __init sh_bus_init(void)
{
int i, ret = 0;
for (i = 0; i < SH_NR_BUSES; i++) {
ret = device_register(&sh_bus_devices[i]);
if (ret != 0) {
printk(KERN_ERR "Unable to register bus device %s\n",
sh_bus_devices[i].bus_id);
continue;
}
ret = bus_register(&sh_bus_types[i]);
if (ret != 0) {
printk(KERN_ERR "Unable to register bus %s\n",
sh_bus_types[i].name);
device_unregister(&sh_bus_devices[i]);
}
}
printk(KERN_INFO "SH Virtual Bus initialized\n");
return ret;
}
static void __exit sh_bus_exit(void)
{
int i;
for (i = 0; i < SH_NR_BUSES; i++) {
bus_unregister(&sh_bus_types[i]);
device_unregister(&sh_bus_devices[i]);
}
}
module_init(sh_bus_init);
module_exit(sh_bus_exit);
MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
MODULE_DESCRIPTION("SH Virtual Bus");
MODULE_LICENSE("GPL");
EXPORT_SYMBOL(sh_bus_types);
EXPORT_SYMBOL(sh_device_register);
EXPORT_SYMBOL(sh_device_unregister);
EXPORT_SYMBOL(sh_driver_register);
EXPORT_SYMBOL(sh_driver_unregister);
|