Commit d5dc9271 authored by Russell King's avatar Russell King

ARM: amba: add amba_device allocation/add/put functions

Add functions to allocate and initialize AMBA device structures, and
add them to the Linux device manager.  This allows us to kill this
type of operation from individual platforms, moving it to core code.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent dffcb9c5
...@@ -497,38 +497,20 @@ static void amba_device_release(struct device *dev) ...@@ -497,38 +497,20 @@ static void amba_device_release(struct device *dev)
} }
/** /**
* amba_device_register - register an AMBA device * amba_device_add - add a previously allocated AMBA device structure
* @dev: AMBA device to register * @dev: AMBA device allocated by amba_device_alloc
* @parent: parent memory resource * @parent: resource parent for this devices resources
* *
* Setup the AMBA device, reading the cell ID if present. * Claim the resource, and read the device cell ID if not already
* Claim the resource, and register the AMBA device with * initialized. Register the AMBA device with the Linux device
* the Linux device manager. * manager.
*/ */
int amba_device_register(struct amba_device *dev, struct resource *parent) int amba_device_add(struct amba_device *dev, struct resource *parent)
{ {
u32 size; u32 size;
void __iomem *tmp; void __iomem *tmp;
int i, ret; int i, ret;
device_initialize(&dev->dev);
/*
* Copy from device_add
*/
if (dev->dev.init_name) {
dev_set_name(&dev->dev, "%s", dev->dev.init_name);
dev->dev.init_name = NULL;
}
dev->dev.release = amba_device_release;
dev->dev.bus = &amba_bustype;
dev->dev.dma_mask = &dev->dma_mask;
dev->res.name = dev_name(&dev->dev);
if (!dev->dev.coherent_dma_mask && dev->dma_mask)
dev_warn(&dev->dev, "coherent dma mask is unset\n");
ret = request_resource(parent, &dev->res); ret = request_resource(parent, &dev->res);
if (ret) if (ret)
goto err_out; goto err_out;
...@@ -596,6 +578,74 @@ int amba_device_register(struct amba_device *dev, struct resource *parent) ...@@ -596,6 +578,74 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
err_out: err_out:
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(amba_device_add);
static void amba_device_initialize(struct amba_device *dev, const char *name)
{
device_initialize(&dev->dev);
if (name)
dev_set_name(&dev->dev, "%s", name);
dev->dev.release = amba_device_release;
dev->dev.bus = &amba_bustype;
dev->dev.dma_mask = &dev->dma_mask;
dev->res.name = dev_name(&dev->dev);
}
/**
* amba_device_alloc - allocate an AMBA device
* @name: sysfs name of the AMBA device
* @base: base of AMBA device
* @size: size of AMBA device
*
* Allocate and initialize an AMBA device structure. Returns %NULL
* on failure.
*/
struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
size_t size)
{
struct amba_device *dev;
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (dev) {
amba_device_initialize(dev, name);
dev->res.start = base;
dev->res.end = base + size - 1;
dev->res.flags = IORESOURCE_MEM;
}
return dev;
}
EXPORT_SYMBOL_GPL(amba_device_alloc);
/**
* amba_device_register - register an AMBA device
* @dev: AMBA device to register
* @parent: parent memory resource
*
* Setup the AMBA device, reading the cell ID if present.
* Claim the resource, and register the AMBA device with
* the Linux device manager.
*/
int amba_device_register(struct amba_device *dev, struct resource *parent)
{
amba_device_initialize(dev, dev->dev.init_name);
dev->dev.init_name = NULL;
if (!dev->dev.coherent_dma_mask && dev->dma_mask)
dev_warn(&dev->dev, "coherent dma mask is unset\n");
return amba_device_add(dev, parent);
}
/**
* amba_device_put - put an AMBA device
* @dev: AMBA device to put
*/
void amba_device_put(struct amba_device *dev)
{
put_device(&dev->dev);
}
EXPORT_SYMBOL_GPL(amba_device_put);
/** /**
* amba_device_unregister - unregister an AMBA device * amba_device_unregister - unregister an AMBA device
......
...@@ -60,6 +60,9 @@ extern struct bus_type amba_bustype; ...@@ -60,6 +60,9 @@ extern struct bus_type amba_bustype;
int amba_driver_register(struct amba_driver *); int amba_driver_register(struct amba_driver *);
void amba_driver_unregister(struct amba_driver *); void amba_driver_unregister(struct amba_driver *);
struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
void amba_device_put(struct amba_device *);
int amba_device_add(struct amba_device *, struct resource *);
int amba_device_register(struct amba_device *, struct resource *); int amba_device_register(struct amba_device *, struct resource *);
void amba_device_unregister(struct amba_device *); void amba_device_unregister(struct amba_device *);
struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int); struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
......
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