aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/sh/superhyway/superhyway-sysfs.c2
-rw-r--r--drivers/sh/superhyway/superhyway.c75
-rw-r--r--include/linux/superhyway.h38
3 files changed, 89 insertions, 26 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
diff --git a/include/linux/superhyway.h b/include/linux/superhyway.h
index c906c5a0aaef..17ea468fa362 100644
--- a/include/linux/superhyway.h
+++ b/include/linux/superhyway.h
@@ -19,7 +19,7 @@
19 */ 19 */
20#define SUPERHYWAY_DEVICE_ID_SH5_DMAC 0x0183 20#define SUPERHYWAY_DEVICE_ID_SH5_DMAC 0x0183
21 21
22struct vcr_info { 22struct superhyway_vcr_info {
23 u8 perr_flags; /* P-port Error flags */ 23 u8 perr_flags; /* P-port Error flags */
24 u8 merr_flags; /* Module Error flags */ 24 u8 merr_flags; /* Module Error flags */
25 u16 mod_vers; /* Module Version */ 25 u16 mod_vers; /* Module Version */
@@ -28,6 +28,17 @@ struct vcr_info {
28 u8 top_mb; /* Top Memory block */ 28 u8 top_mb; /* Top Memory block */
29}; 29};
30 30
31struct superhyway_ops {
32 int (*read_vcr)(unsigned long base, struct superhyway_vcr_info *vcr);
33 int (*write_vcr)(unsigned long base, struct superhyway_vcr_info vcr);
34};
35
36struct superhyway_bus {
37 struct superhyway_ops *ops;
38};
39
40extern struct superhyway_bus superhyway_channels[];
41
31struct superhyway_device_id { 42struct superhyway_device_id {
32 unsigned int id; 43 unsigned int id;
33 unsigned long driver_data; 44 unsigned long driver_data;
@@ -55,9 +66,11 @@ struct superhyway_device {
55 66
56 struct superhyway_device_id id; 67 struct superhyway_device_id id;
57 struct superhyway_driver *drv; 68 struct superhyway_driver *drv;
69 struct superhyway_bus *bus;
58 70
59 struct resource resource; 71 int num_resources;
60 struct vcr_info vcr; 72 struct resource *resource;
73 struct superhyway_vcr_info vcr;
61}; 74};
62 75
63#define to_superhyway_device(d) container_of((d), struct superhyway_device, dev) 76#define to_superhyway_device(d) container_of((d), struct superhyway_device, dev)
@@ -65,12 +78,27 @@ struct superhyway_device {
65#define superhyway_get_drvdata(d) dev_get_drvdata(&(d)->dev) 78#define superhyway_get_drvdata(d) dev_get_drvdata(&(d)->dev)
66#define superhyway_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, (p)) 79#define superhyway_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, (p))
67 80
68extern int superhyway_scan_bus(void); 81static inline int
82superhyway_read_vcr(struct superhyway_device *dev, unsigned long base,
83 struct superhyway_vcr_info *vcr)
84{
85 return dev->bus->ops->read_vcr(base, vcr);
86}
87
88static inline int
89superhyway_write_vcr(struct superhyway_device *dev, unsigned long base,
90 struct superhyway_vcr_info vcr)
91{
92 return dev->bus->ops->write_vcr(base, vcr);
93}
94
95extern int superhyway_scan_bus(struct superhyway_bus *);
69 96
70/* drivers/sh/superhyway/superhyway.c */ 97/* drivers/sh/superhyway/superhyway.c */
71int superhyway_register_driver(struct superhyway_driver *); 98int superhyway_register_driver(struct superhyway_driver *);
72void superhyway_unregister_driver(struct superhyway_driver *); 99void superhyway_unregister_driver(struct superhyway_driver *);
73int superhyway_add_device(unsigned int, unsigned long, unsigned long long); 100int superhyway_add_device(unsigned long base, struct superhyway_device *, struct superhyway_bus *);
101int superhyway_add_devices(struct superhyway_bus *bus, struct superhyway_device **devices, int nr_devices);
74 102
75/* drivers/sh/superhyway/superhyway-sysfs.c */ 103/* drivers/sh/superhyway/superhyway-sysfs.c */
76extern struct device_attribute superhyway_dev_attrs[]; 104extern struct device_attribute superhyway_dev_attrs[];