Commit 055a2512 authored by Paul Mundt's avatar Paul Mundt Committed by Linus Torvalds

[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: default avatarPaul Mundt <lethal@linux-sh.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 72777373
...@@ -30,7 +30,7 @@ superhyway_ro_attr(bot_mb, "0x%02x\n", vcr.bot_mb); ...@@ -30,7 +30,7 @@ superhyway_ro_attr(bot_mb, "0x%02x\n", vcr.bot_mb);
superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb); superhyway_ro_attr(top_mb, "0x%02x\n", vcr.top_mb);
/* Misc */ /* Misc */
superhyway_ro_attr(resource, "0x%08lx\n", resource.start); superhyway_ro_attr(resource, "0x%08lx\n", resource[0].start);
struct device_attribute superhyway_dev_attrs[] = { struct device_attribute superhyway_dev_attrs[] = {
__ATTR_RO(perr_flags), __ATTR_RO(perr_flags),
......
...@@ -27,19 +27,20 @@ static struct device superhyway_bus_device = { ...@@ -27,19 +27,20 @@ static struct device superhyway_bus_device = {
static void superhyway_device_release(struct device *dev) static void superhyway_device_release(struct device *dev)
{ {
kfree(to_superhyway_device(dev)); struct superhyway_device *sdev = to_superhyway_device(dev);
kfree(sdev->resource);
kfree(sdev);
} }
/** /**
* superhyway_add_device - Add a SuperHyway module * superhyway_add_device - Add a SuperHyway module
* @mod_id: Module ID (taken from MODULE.VCR.MOD_ID).
* @base: Physical address where module is mapped. * @base: Physical address where module is mapped.
* @vcr: VCR value. * @sdev: SuperHyway device to add, or NULL to allocate a new one.
* @bus: Bus where SuperHyway module resides.
* *
* This is responsible for adding a new SuperHyway module. This sets up a new * This is responsible for adding a new SuperHyway module. This sets up a new
* struct superhyway_device for the module being added. Each one of @mod_id, * struct superhyway_device for the module being added if @sdev == NULL.
* @base, and @vcr are registered with the new device for further use
* elsewhere.
* *
* Devices are initially added in the order that they are scanned (from the * Devices are initially added in the order that they are scanned (from the
* top-down of the memory map), and are assigned an ID based on the order that * 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,28 +50,40 @@ static void superhyway_device_release(struct device *dev)
* Further work can and should be done in superhyway_scan_bus(), to be sure * Further work can and should be done in superhyway_scan_bus(), to be sure
* that any new modules are properly discovered and subsequently registered. * that any new modules are properly discovered and subsequently registered.
*/ */
int superhyway_add_device(unsigned int mod_id, unsigned long base, int superhyway_add_device(unsigned long base, struct superhyway_device *sdev,
unsigned long long vcr) struct superhyway_bus *bus)
{ {
struct superhyway_device *dev; struct superhyway_device *dev = sdev;
if (!dev) {
dev = kmalloc(sizeof(struct superhyway_device), GFP_KERNEL);
if (!dev)
return -ENOMEM;
dev = kmalloc(sizeof(struct superhyway_device), GFP_KERNEL); memset(dev, 0, sizeof(struct superhyway_device));
if (!dev) }
return -ENOMEM;
memset(dev, 0, sizeof(struct superhyway_device)); dev->bus = bus;
superhyway_read_vcr(dev, base, &dev->vcr);
dev->id.id = mod_id; if (!dev->resource) {
sprintf(dev->name, "SuperHyway device %04x", dev->id.id); dev->resource = kmalloc(sizeof(struct resource), GFP_KERNEL);
if (!dev->resource) {
kfree(dev);
return -ENOMEM;
}
dev->resource->name = dev->name;
dev->resource->start = base;
dev->resource->end = dev->resource->start + 0x01000000;
}
dev->vcr = *((struct vcr_info *)(&vcr));
dev->resource.name = dev->name;
dev->resource.start = base;
dev->resource.end = dev->resource.start + 0x01000000;
dev->dev.parent = &superhyway_bus_device; dev->dev.parent = &superhyway_bus_device;
dev->dev.bus = &superhyway_bus_type; dev->dev.bus = &superhyway_bus_type;
dev->dev.release = superhyway_device_release; dev->dev.release = superhyway_device_release;
dev->id.id = dev->vcr.mod_id;
sprintf(dev->name, "SuperHyway device %04x", dev->id.id);
sprintf(dev->dev.bus_id, "%02x", superhyway_devices); sprintf(dev->dev.bus_id, "%02x", superhyway_devices);
superhyway_devices++; superhyway_devices++;
...@@ -78,10 +91,31 @@ int superhyway_add_device(unsigned int mod_id, unsigned long base, ...@@ -78,10 +91,31 @@ int superhyway_add_device(unsigned int mod_id, unsigned long base,
return device_register(&dev->dev); return device_register(&dev->dev);
} }
int superhyway_add_devices(struct superhyway_bus *bus,
struct superhyway_device **devices,
int nr_devices)
{
int i, ret = 0;
for (i = 0; i < nr_devices; i++) {
struct superhyway_device *dev = devices[i];
ret |= superhyway_add_device(dev->resource[0].start, dev, bus);
}
return ret;
}
static int __init superhyway_init(void) static int __init superhyway_init(void)
{ {
struct superhyway_bus *bus;
int ret = 0;
device_register(&superhyway_bus_device); device_register(&superhyway_bus_device);
return superhyway_scan_bus();
for (bus = superhyway_channels; bus->ops; bus++)
ret |= superhyway_scan_bus(bus);
return ret;
} }
postcore_initcall(superhyway_init); postcore_initcall(superhyway_init);
...@@ -197,6 +231,7 @@ module_exit(superhyway_bus_exit); ...@@ -197,6 +231,7 @@ module_exit(superhyway_bus_exit);
EXPORT_SYMBOL(superhyway_bus_type); EXPORT_SYMBOL(superhyway_bus_type);
EXPORT_SYMBOL(superhyway_add_device); EXPORT_SYMBOL(superhyway_add_device);
EXPORT_SYMBOL(superhyway_add_devices);
EXPORT_SYMBOL(superhyway_register_driver); EXPORT_SYMBOL(superhyway_register_driver);
EXPORT_SYMBOL(superhyway_unregister_driver); EXPORT_SYMBOL(superhyway_unregister_driver);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
*/ */
#define SUPERHYWAY_DEVICE_ID_SH5_DMAC 0x0183 #define SUPERHYWAY_DEVICE_ID_SH5_DMAC 0x0183
struct vcr_info { struct superhyway_vcr_info {
u8 perr_flags; /* P-port Error flags */ u8 perr_flags; /* P-port Error flags */
u8 merr_flags; /* Module Error flags */ u8 merr_flags; /* Module Error flags */
u16 mod_vers; /* Module Version */ u16 mod_vers; /* Module Version */
...@@ -28,6 +28,17 @@ struct vcr_info { ...@@ -28,6 +28,17 @@ struct vcr_info {
u8 top_mb; /* Top Memory block */ u8 top_mb; /* Top Memory block */
}; };
struct superhyway_ops {
int (*read_vcr)(unsigned long base, struct superhyway_vcr_info *vcr);
int (*write_vcr)(unsigned long base, struct superhyway_vcr_info vcr);
};
struct superhyway_bus {
struct superhyway_ops *ops;
};
extern struct superhyway_bus superhyway_channels[];
struct superhyway_device_id { struct superhyway_device_id {
unsigned int id; unsigned int id;
unsigned long driver_data; unsigned long driver_data;
...@@ -55,9 +66,11 @@ struct superhyway_device { ...@@ -55,9 +66,11 @@ struct superhyway_device {
struct superhyway_device_id id; struct superhyway_device_id id;
struct superhyway_driver *drv; struct superhyway_driver *drv;
struct superhyway_bus *bus;
struct resource resource; int num_resources;
struct vcr_info vcr; struct resource *resource;
struct superhyway_vcr_info vcr;
}; };
#define to_superhyway_device(d) container_of((d), struct superhyway_device, dev) #define to_superhyway_device(d) container_of((d), struct superhyway_device, dev)
...@@ -65,12 +78,27 @@ struct superhyway_device { ...@@ -65,12 +78,27 @@ struct superhyway_device {
#define superhyway_get_drvdata(d) dev_get_drvdata(&(d)->dev) #define superhyway_get_drvdata(d) dev_get_drvdata(&(d)->dev)
#define superhyway_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, (p)) #define superhyway_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, (p))
extern int superhyway_scan_bus(void); static inline int
superhyway_read_vcr(struct superhyway_device *dev, unsigned long base,
struct superhyway_vcr_info *vcr)
{
return dev->bus->ops->read_vcr(base, vcr);
}
static inline int
superhyway_write_vcr(struct superhyway_device *dev, unsigned long base,
struct superhyway_vcr_info vcr)
{
return dev->bus->ops->write_vcr(base, vcr);
}
extern int superhyway_scan_bus(struct superhyway_bus *);
/* drivers/sh/superhyway/superhyway.c */ /* drivers/sh/superhyway/superhyway.c */
int superhyway_register_driver(struct superhyway_driver *); int superhyway_register_driver(struct superhyway_driver *);
void superhyway_unregister_driver(struct superhyway_driver *); void superhyway_unregister_driver(struct superhyway_driver *);
int superhyway_add_device(unsigned int, unsigned long, unsigned long long); int superhyway_add_device(unsigned long base, struct superhyway_device *, struct superhyway_bus *);
int superhyway_add_devices(struct superhyway_bus *bus, struct superhyway_device **devices, int nr_devices);
/* drivers/sh/superhyway/superhyway-sysfs.c */ /* drivers/sh/superhyway/superhyway-sysfs.c */
extern struct device_attribute superhyway_dev_attrs[]; extern struct device_attribute superhyway_dev_attrs[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment