aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sh/superhyway
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2005-11-07 03:58:21 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-07 10:53:28 -0500
commit055a2512144cd7e60dcaae7a13e460df43b98787 (patch)
treebf304d17352f1b3b59edb35a6f67672c6490caa1 /drivers/sh/superhyway
parent72777373b3a09c9132a787d5e1e03eaf64f30a64 (diff)
[PATCH] superhyway: multiple block support and VCR rework
This extends the API somewhat to allow for platform-specific VCR reading and writing. Some platforms (like SH4-202) implement the VCR in a split VCRL and VCRH, but end up being in reverse order or have other quirks that need to be dealt with, so we add a set of superhyway_ops per-bus to accomodate this. We also have to extend the per-device resources somewhat, as some devices now conveniently split control and data blocks. So we allow a platform to register its set of SuperHyway devices via superhyway_add_devices() with the control block always ordered as the first resource (as this is the one that userspace cares about). Signed-off-by: Paul Mundt <lethal@linux-sh.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/sh/superhyway')
-rw-r--r--drivers/sh/superhyway/superhyway-sysfs.c2
-rw-r--r--drivers/sh/superhyway/superhyway.c75
2 files changed, 56 insertions, 21 deletions
diff --git a/drivers/sh/superhyway/superhyway-sysfs.c b/drivers/sh/superhyway/superhyway-sysfs.c
index dc119ce68e3e..55434330867b 100644
--- a/drivers/sh/superhyway/superhyway-sysfs.c
+++ b/drivers/sh/superhyway/superhyway-sysfs.c
@@ -30,7 +30,7 @@ superhyway_ro_attr(bot_mb, "0x%02x\n", vcr.bot_mb);
30superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb); 30superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb);
31 31
32/* Misc */ 32/* Misc */
33superhyway_ro_attr(resource, "0x%08lx\n", resource.start); 33superhyway_ro_attr(resource, "0x%08lx\n", resource[0].start);
34 34
35struct device_attribute superhyway_dev_attrs[] = { 35struct device_attribute superhyway_dev_attrs[] = {
36 __ATTR_RO(perr_flags), 36 __ATTR_RO(perr_flags),
diff --git a/drivers/sh/superhyway/superhyway.c b/drivers/sh/superhyway/superhyway.c
index 28757cb9d246..7bdab2a7f59c 100644
--- a/drivers/sh/superhyway/superhyway.c
+++ b/drivers/sh/superhyway/superhyway.c
@@ -27,19 +27,20 @@ static struct device superhyway_bus_device = {
27 27
28static void superhyway_device_release(struct device *dev) 28static void superhyway_device_release(struct device *dev)
29{ 29{
30 kfree(to_superhyway_device(dev)); 30 struct superhyway_device *sdev = to_superhyway_device(dev);
31
32 kfree(sdev->resource);
33 kfree(sdev);
31} 34}
32 35
33/** 36/**
34 * superhyway_add_device - Add a SuperHyway module 37 * superhyway_add_device - Add a SuperHyway module
35 * @mod_id: Module ID (taken from MODULE.VCR.MOD_ID).
36 * @base: Physical address where module is mapped. 38 * @base: Physical address where module is mapped.
37 * @vcr: VCR value. 39 * @sdev: SuperHyway device to add, or NULL to allocate a new one.
40 * @bus: Bus where SuperHyway module resides.
38 * 41 *
39 * This is responsible for adding a new SuperHyway module. This sets up a new 42 * This is responsible for adding a new SuperHyway module. This sets up a new
40 * struct superhyway_device for the module being added. Each one of @mod_id, 43 * struct superhyway_device for the module being added if @sdev == NULL.
41 * @base, and @vcr are registered with the new device for further use
42 * elsewhere.
43 * 44 *
44 * Devices are initially added in the order that they are scanned (from the 45 * Devices are initially added in the order that they are scanned (from the
45 * top-down of the memory map), and are assigned an ID based on the order that 46 * top-down of the memory map), and are assigned an ID based on the order that
@@ -49,28 +50,40 @@ static void superhyway_device_release(struct device *dev)
49 * Further work can and should be done in superhyway_scan_bus(), to be sure 50 * Further work can and should be done in superhyway_scan_bus(), to be sure
50 * that any new modules are properly discovered and subsequently registered. 51 * that any new modules are properly discovered and subsequently registered.
51 */ 52 */
52int superhyway_add_device(unsigned int mod_id, unsigned long base, 53int superhyway_add_device(unsigned long base, struct superhyway_device *sdev,
53 unsigned long long vcr) 54 struct superhyway_bus *bus)
54{ 55{
55 struct superhyway_device *dev; 56 struct superhyway_device *dev = sdev;
57
58 if (!dev) {
59 dev = kmalloc(sizeof(struct superhyway_device), GFP_KERNEL);
60 if (!dev)
61 return -ENOMEM;
56 62
57 dev = kmalloc(sizeof(struct superhyway_device), GFP_KERNEL); 63 memset(dev, 0, sizeof(struct superhyway_device));
58 if (!dev) 64 }
59 return -ENOMEM;
60 65
61 memset(dev, 0, sizeof(struct superhyway_device)); 66 dev->bus = bus;
67 superhyway_read_vcr(dev, base, &dev->vcr);
62 68
63 dev->id.id = mod_id; 69 if (!dev->resource) {
64 sprintf(dev->name, "SuperHyway device %04x", dev->id.id); 70 dev->resource = kmalloc(sizeof(struct resource), GFP_KERNEL);
71 if (!dev->resource) {
72 kfree(dev);
73 return -ENOMEM;
74 }
75
76 dev->resource->name = dev->name;
77 dev->resource->start = base;
78 dev->resource->end = dev->resource->start + 0x01000000;
79 }
65 80
66 dev->vcr = *((struct vcr_info *)(&vcr));
67 dev->resource.name = dev->name;
68 dev->resource.start = base;
69 dev->resource.end = dev->resource.start + 0x01000000;
70 dev->dev.parent = &superhyway_bus_device; 81 dev->dev.parent = &superhyway_bus_device;
71 dev->dev.bus = &superhyway_bus_type; 82 dev->dev.bus = &superhyway_bus_type;
72 dev->dev.release = superhyway_device_release; 83 dev->dev.release = superhyway_device_release;
84 dev->id.id = dev->vcr.mod_id;
73 85
86 sprintf(dev->name, "SuperHyway device %04x", dev->id.id);
74 sprintf(dev->dev.bus_id, "%02x", superhyway_devices); 87 sprintf(dev->dev.bus_id, "%02x", superhyway_devices);
75 88
76 superhyway_devices++; 89 superhyway_devices++;
@@ -78,10 +91,31 @@ int superhyway_add_device(unsigned int mod_id, unsigned long base,
78 return device_register(&dev->dev); 91 return device_register(&dev->dev);
79} 92}
80 93
94int superhyway_add_devices(struct superhyway_bus *bus,
95 struct superhyway_device **devices,
96 int nr_devices)
97{
98 int i, ret = 0;
99
100 for (i = 0; i < nr_devices; i++) {
101 struct superhyway_device *dev = devices[i];
102 ret |= superhyway_add_device(dev->resource[0].start, dev, bus);
103 }
104
105 return ret;
106}
107
81static int __init superhyway_init(void) 108static int __init superhyway_init(void)
82{ 109{
110 struct superhyway_bus *bus;
111 int ret = 0;
112
83 device_register(&superhyway_bus_device); 113 device_register(&superhyway_bus_device);
84 return superhyway_scan_bus(); 114
115 for (bus = superhyway_channels; bus->ops; bus++)
116 ret |= superhyway_scan_bus(bus);
117
118 return ret;
85} 119}
86 120
87postcore_initcall(superhyway_init); 121postcore_initcall(superhyway_init);
@@ -197,6 +231,7 @@ module_exit(superhyway_bus_exit);
197 231
198EXPORT_SYMBOL(superhyway_bus_type); 232EXPORT_SYMBOL(superhyway_bus_type);
199EXPORT_SYMBOL(superhyway_add_device); 233EXPORT_SYMBOL(superhyway_add_device);
234EXPORT_SYMBOL(superhyway_add_devices);
200EXPORT_SYMBOL(superhyway_register_driver); 235EXPORT_SYMBOL(superhyway_register_driver);
201EXPORT_SYMBOL(superhyway_unregister_driver); 236EXPORT_SYMBOL(superhyway_unregister_driver);
202 237