diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/sh |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/sh')
-rw-r--r-- | drivers/sh/Makefile | 6 | ||||
-rw-r--r-- | drivers/sh/superhyway/Makefile | 7 | ||||
-rw-r--r-- | drivers/sh/superhyway/superhyway-sysfs.c | 45 | ||||
-rw-r--r-- | drivers/sh/superhyway/superhyway.c | 201 |
4 files changed, 259 insertions, 0 deletions
diff --git a/drivers/sh/Makefile b/drivers/sh/Makefile new file mode 100644 index 000000000000..8a143894e33f --- /dev/null +++ b/drivers/sh/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | # | ||
2 | # Makefile for the SuperH specific drivers. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_SUPERHYWAY) += superhyway/ | ||
6 | |||
diff --git a/drivers/sh/superhyway/Makefile b/drivers/sh/superhyway/Makefile new file mode 100644 index 000000000000..499dc47d8dcd --- /dev/null +++ b/drivers/sh/superhyway/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # | ||
2 | # Makefile for the SuperHyway bus drivers. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_SUPERHYWAY) += superhyway.o | ||
6 | obj-$(CONFIG_SYSFS) += superhyway-sysfs.o | ||
7 | |||
diff --git a/drivers/sh/superhyway/superhyway-sysfs.c b/drivers/sh/superhyway/superhyway-sysfs.c new file mode 100644 index 000000000000..39ab6a12da76 --- /dev/null +++ b/drivers/sh/superhyway/superhyway-sysfs.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * drivers/sh/superhyway/superhyway-sysfs.c | ||
3 | * | ||
4 | * SuperHyway Bus sysfs interface | ||
5 | * | ||
6 | * Copyright (C) 2004, 2005 Paul Mundt <lethal@linux-sh.org> | ||
7 | * | ||
8 | * This file is subject to the terms and conditions of the GNU General Public | ||
9 | * License. See the file "COPYING" in the main directory of this archive | ||
10 | * for more details. | ||
11 | */ | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/device.h> | ||
14 | #include <linux/types.h> | ||
15 | #include <linux/superhyway.h> | ||
16 | |||
17 | #define superhyway_ro_attr(name, fmt, field) \ | ||
18 | static ssize_t name##_show(struct device *dev, char *buf) \ | ||
19 | { \ | ||
20 | struct superhyway_device *s = to_superhyway_device(dev); \ | ||
21 | return sprintf(buf, fmt, s->field); \ | ||
22 | } | ||
23 | |||
24 | /* VCR flags */ | ||
25 | superhyway_ro_attr(perr_flags, "0x%02x\n", vcr.perr_flags); | ||
26 | superhyway_ro_attr(merr_flags, "0x%02x\n", vcr.merr_flags); | ||
27 | superhyway_ro_attr(mod_vers, "0x%04x\n", vcr.mod_vers); | ||
28 | superhyway_ro_attr(mod_id, "0x%04x\n", vcr.mod_id); | ||
29 | superhyway_ro_attr(bot_mb, "0x%02x\n", vcr.bot_mb); | ||
30 | superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb); | ||
31 | |||
32 | /* Misc */ | ||
33 | superhyway_ro_attr(resource, "0x%08lx\n", resource.start); | ||
34 | |||
35 | struct device_attribute superhyway_dev_attrs[] = { | ||
36 | __ATTR_RO(perr_flags), | ||
37 | __ATTR_RO(merr_flags), | ||
38 | __ATTR_RO(mod_vers), | ||
39 | __ATTR_RO(mod_id), | ||
40 | __ATTR_RO(bot_mb), | ||
41 | __ATTR_RO(top_mb), | ||
42 | __ATTR_RO(resource), | ||
43 | __ATTR_NULL, | ||
44 | }; | ||
45 | |||
diff --git a/drivers/sh/superhyway/superhyway.c b/drivers/sh/superhyway/superhyway.c new file mode 100644 index 000000000000..f056276b08a1 --- /dev/null +++ b/drivers/sh/superhyway/superhyway.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | * drivers/sh/superhyway/superhyway.c | ||
3 | * | ||
4 | * SuperHyway Bus Driver | ||
5 | * | ||
6 | * Copyright (C) 2004, 2005 Paul Mundt <lethal@linux-sh.org> | ||
7 | * | ||
8 | * This file is subject to the terms and conditions of the GNU General Public | ||
9 | * License. See the file "COPYING" in the main directory of this archive | ||
10 | * for more details. | ||
11 | */ | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/device.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/types.h> | ||
17 | #include <linux/list.h> | ||
18 | #include <linux/superhyway.h> | ||
19 | |||
20 | static int superhyway_devices; | ||
21 | |||
22 | static struct device superhyway_bus_device = { | ||
23 | .bus_id = "superhyway", | ||
24 | }; | ||
25 | |||
26 | static void superhyway_device_release(struct device *dev) | ||
27 | { | ||
28 | kfree(to_superhyway_device(dev)); | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * superhyway_add_device - Add a SuperHyway module | ||
33 | * @mod_id: Module ID (taken from MODULE.VCR.MOD_ID). | ||
34 | * @base: Physical address where module is mapped. | ||
35 | * @vcr: VCR value. | ||
36 | * | ||
37 | * This is responsible for adding a new SuperHyway module. This sets up a new | ||
38 | * struct superhyway_device for the module being added. Each one of @mod_id, | ||
39 | * @base, and @vcr are registered with the new device for further use | ||
40 | * elsewhere. | ||
41 | * | ||
42 | * Devices are initially added in the order that they are scanned (from the | ||
43 | * top-down of the memory map), and are assigned an ID based on the order that | ||
44 | * they are added. Any manual addition of a module will thus get the ID after | ||
45 | * the devices already discovered regardless of where it resides in memory. | ||
46 | * | ||
47 | * Further work can and should be done in superhyway_scan_bus(), to be sure | ||
48 | * that any new modules are properly discovered and subsequently registered. | ||
49 | */ | ||
50 | int superhyway_add_device(unsigned int mod_id, unsigned long base, | ||
51 | unsigned long long vcr) | ||
52 | { | ||
53 | struct superhyway_device *dev; | ||
54 | |||
55 | dev = kmalloc(sizeof(struct superhyway_device), GFP_KERNEL); | ||
56 | if (!dev) | ||
57 | return -ENOMEM; | ||
58 | |||
59 | memset(dev, 0, sizeof(struct superhyway_device)); | ||
60 | |||
61 | dev->id.id = mod_id; | ||
62 | sprintf(dev->name, "SuperHyway device %04x", dev->id.id); | ||
63 | |||
64 | dev->vcr = *((struct vcr_info *)(&vcr)); | ||
65 | dev->resource.name = dev->name; | ||
66 | dev->resource.start = base; | ||
67 | dev->resource.end = dev->resource.start + 0x01000000; | ||
68 | dev->dev.parent = &superhyway_bus_device; | ||
69 | dev->dev.bus = &superhyway_bus_type; | ||
70 | dev->dev.release = superhyway_device_release; | ||
71 | |||
72 | sprintf(dev->dev.bus_id, "%02x", superhyway_devices); | ||
73 | |||
74 | superhyway_devices++; | ||
75 | |||
76 | return device_register(&dev->dev); | ||
77 | } | ||
78 | |||
79 | static int __init superhyway_init(void) | ||
80 | { | ||
81 | device_register(&superhyway_bus_device); | ||
82 | return superhyway_scan_bus(); | ||
83 | } | ||
84 | |||
85 | postcore_initcall(superhyway_init); | ||
86 | |||
87 | static const struct superhyway_device_id * | ||
88 | superhyway_match_id(const struct superhyway_device_id *ids, | ||
89 | struct superhyway_device *dev) | ||
90 | { | ||
91 | while (ids->id) { | ||
92 | if (ids->id == dev->id.id) | ||
93 | return ids; | ||
94 | |||
95 | ids++; | ||
96 | } | ||
97 | |||
98 | return NULL; | ||
99 | } | ||
100 | |||
101 | static int superhyway_device_probe(struct device *dev) | ||
102 | { | ||
103 | struct superhyway_device *shyway_dev = to_superhyway_device(dev); | ||
104 | struct superhyway_driver *shyway_drv = to_superhyway_driver(dev->driver); | ||
105 | |||
106 | if (shyway_drv && shyway_drv->probe) { | ||
107 | const struct superhyway_device_id *id; | ||
108 | |||
109 | id = superhyway_match_id(shyway_drv->id_table, shyway_dev); | ||
110 | if (id) | ||
111 | return shyway_drv->probe(shyway_dev, id); | ||
112 | } | ||
113 | |||
114 | return -ENODEV; | ||
115 | } | ||
116 | |||
117 | static int superhyway_device_remove(struct device *dev) | ||
118 | { | ||
119 | struct superhyway_device *shyway_dev = to_superhyway_device(dev); | ||
120 | struct superhyway_driver *shyway_drv = to_superhyway_driver(dev->driver); | ||
121 | |||
122 | if (shyway_drv && shyway_drv->remove) { | ||
123 | shyway_drv->remove(shyway_dev); | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | return -ENODEV; | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * superhyway_register_driver - Register a new SuperHyway driver | ||
132 | * @drv: SuperHyway driver to register. | ||
133 | * | ||
134 | * This registers the passed in @drv. Any devices matching the id table will | ||
135 | * automatically be populated and handed off to the driver's specified probe | ||
136 | * routine. | ||
137 | */ | ||
138 | int superhyway_register_driver(struct superhyway_driver *drv) | ||
139 | { | ||
140 | drv->drv.name = drv->name; | ||
141 | drv->drv.bus = &superhyway_bus_type; | ||
142 | drv->drv.probe = superhyway_device_probe; | ||
143 | drv->drv.remove = superhyway_device_remove; | ||
144 | |||
145 | return driver_register(&drv->drv); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * superhyway_unregister_driver - Unregister a SuperHyway driver | ||
150 | * @drv: SuperHyway driver to unregister. | ||
151 | * | ||
152 | * This cleans up after superhyway_register_driver(), and should be invoked in | ||
153 | * the exit path of any module drivers. | ||
154 | */ | ||
155 | void superhyway_unregister_driver(struct superhyway_driver *drv) | ||
156 | { | ||
157 | driver_unregister(&drv->drv); | ||
158 | } | ||
159 | |||
160 | static int superhyway_bus_match(struct device *dev, struct device_driver *drv) | ||
161 | { | ||
162 | struct superhyway_device *shyway_dev = to_superhyway_device(dev); | ||
163 | struct superhyway_driver *shyway_drv = to_superhyway_driver(drv); | ||
164 | const struct superhyway_device_id *ids = shyway_drv->id_table; | ||
165 | |||
166 | if (!ids) | ||
167 | return -EINVAL; | ||
168 | if (superhyway_match_id(ids, shyway_dev)) | ||
169 | return 1; | ||
170 | |||
171 | return -ENODEV; | ||
172 | } | ||
173 | |||
174 | struct bus_type superhyway_bus_type = { | ||
175 | .name = "superhyway", | ||
176 | .match = superhyway_bus_match, | ||
177 | #ifdef CONFIG_SYSFS | ||
178 | .dev_attrs = superhyway_dev_attrs, | ||
179 | #endif | ||
180 | }; | ||
181 | |||
182 | static int __init superhyway_bus_init(void) | ||
183 | { | ||
184 | return bus_register(&superhyway_bus_type); | ||
185 | } | ||
186 | |||
187 | static void __exit superhyway_bus_exit(void) | ||
188 | { | ||
189 | device_unregister(&superhyway_bus_device); | ||
190 | bus_unregister(&superhyway_bus_type); | ||
191 | } | ||
192 | |||
193 | core_initcall(superhyway_bus_init); | ||
194 | module_exit(superhyway_bus_exit); | ||
195 | |||
196 | EXPORT_SYMBOL(superhyway_bus_type); | ||
197 | EXPORT_SYMBOL(superhyway_add_device); | ||
198 | EXPORT_SYMBOL(superhyway_register_driver); | ||
199 | EXPORT_SYMBOL(superhyway_unregister_driver); | ||
200 | |||
201 | MODULE_LICENSE("GPL"); | ||