diff options
-rw-r--r-- | drivers/sh/superhyway/superhyway-sysfs.c | 2 | ||||
-rw-r--r-- | drivers/sh/superhyway/superhyway.c | 75 | ||||
-rw-r--r-- | include/linux/superhyway.h | 38 |
3 files changed, 89 insertions, 26 deletions
diff --git a/drivers/sh/superhyway/superhyway-sysfs.c b/drivers/sh/superhyway/superhyway-sysfs.c index dc119ce68e3..55434330867 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); | |||
30 | superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb); | 30 | superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb); |
31 | 31 | ||
32 | /* Misc */ | 32 | /* Misc */ |
33 | superhyway_ro_attr(resource, "0x%08lx\n", resource.start); | 33 | superhyway_ro_attr(resource, "0x%08lx\n", resource[0].start); |
34 | 34 | ||
35 | struct device_attribute superhyway_dev_attrs[] = { | 35 | struct 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 28757cb9d24..7bdab2a7f59 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 | ||
28 | static void superhyway_device_release(struct device *dev) | 28 | static 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 | */ |
52 | int superhyway_add_device(unsigned int mod_id, unsigned long base, | 53 | int 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 | ||
94 | int 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 | |||
81 | static int __init superhyway_init(void) | 108 | static 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 | ||
87 | postcore_initcall(superhyway_init); | 121 | postcore_initcall(superhyway_init); |
@@ -197,6 +231,7 @@ module_exit(superhyway_bus_exit); | |||
197 | 231 | ||
198 | EXPORT_SYMBOL(superhyway_bus_type); | 232 | EXPORT_SYMBOL(superhyway_bus_type); |
199 | EXPORT_SYMBOL(superhyway_add_device); | 233 | EXPORT_SYMBOL(superhyway_add_device); |
234 | EXPORT_SYMBOL(superhyway_add_devices); | ||
200 | EXPORT_SYMBOL(superhyway_register_driver); | 235 | EXPORT_SYMBOL(superhyway_register_driver); |
201 | EXPORT_SYMBOL(superhyway_unregister_driver); | 236 | EXPORT_SYMBOL(superhyway_unregister_driver); |
202 | 237 | ||
diff --git a/include/linux/superhyway.h b/include/linux/superhyway.h index c906c5a0aae..17ea468fa36 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 | ||
22 | struct vcr_info { | 22 | struct 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 | ||
31 | struct 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 | |||
36 | struct superhyway_bus { | ||
37 | struct superhyway_ops *ops; | ||
38 | }; | ||
39 | |||
40 | extern struct superhyway_bus superhyway_channels[]; | ||
41 | |||
31 | struct superhyway_device_id { | 42 | struct 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 | ||
68 | extern int superhyway_scan_bus(void); | 81 | static inline int |
82 | superhyway_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 | |||
88 | static inline int | ||
89 | superhyway_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 | |||
95 | extern int superhyway_scan_bus(struct superhyway_bus *); | ||
69 | 96 | ||
70 | /* drivers/sh/superhyway/superhyway.c */ | 97 | /* drivers/sh/superhyway/superhyway.c */ |
71 | int superhyway_register_driver(struct superhyway_driver *); | 98 | int superhyway_register_driver(struct superhyway_driver *); |
72 | void superhyway_unregister_driver(struct superhyway_driver *); | 99 | void superhyway_unregister_driver(struct superhyway_driver *); |
73 | int superhyway_add_device(unsigned int, unsigned long, unsigned long long); | 100 | int superhyway_add_device(unsigned long base, struct superhyway_device *, struct superhyway_bus *); |
101 | int 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 */ |
76 | extern struct device_attribute superhyway_dev_attrs[]; | 104 | extern struct device_attribute superhyway_dev_attrs[]; |