Skip to content

Commit

Permalink
ARM: 5625/1: fix hard coded 4K resource size in amba bus detection
Browse files Browse the repository at this point in the history
This patch modifies the amba bus detection logic in the kernel
to detect the AMBA devices using the calculated resource
size information rather than the hard coded 4K size.

It also calculates the resource size when request mem region
and release mem region.

Signed-off-by: Leo Chen <leochen@broadcom.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Leo Chen authored and Russell King committed Sep 2, 2009
1 parent 98b0979 commit 8afe0b9
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions drivers/amba/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ static void amba_device_release(struct device *dev)
int amba_device_register(struct amba_device *dev, struct resource *parent)
{
u32 pid, cid;
u32 size;
void __iomem *tmp;
int i, ret;

Expand All @@ -219,16 +220,25 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
if (ret)
goto err_out;

tmp = ioremap(dev->res.start, SZ_4K);
/*
* Dynamically calculate the size of the resource
* and use this for iomap
*/
size = resource_size(&dev->res);
tmp = ioremap(dev->res.start, size);
if (!tmp) {
ret = -ENOMEM;
goto err_release;
}

/*
* Read pid and cid based on size of resource
* they are located at end of region
*/
for (pid = 0, i = 0; i < 4; i++)
pid |= (readl(tmp + 0xfe0 + 4 * i) & 255) << (i * 8);
pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) << (i * 8);
for (cid = 0, i = 0; i < 4; i++)
cid |= (readl(tmp + 0xff0 + 4 * i) & 255) << (i * 8);
cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << (i * 8);

iounmap(tmp);

Expand Down Expand Up @@ -343,11 +353,14 @@ amba_find_device(const char *busid, struct device *parent, unsigned int id,
int amba_request_regions(struct amba_device *dev, const char *name)
{
int ret = 0;
u32 size;

if (!name)
name = dev->dev.driver->name;

if (!request_mem_region(dev->res.start, SZ_4K, name))
size = resource_size(&dev->res);

if (!request_mem_region(dev->res.start, size, name))
ret = -EBUSY;

return ret;
Expand All @@ -361,7 +374,10 @@ int amba_request_regions(struct amba_device *dev, const char *name)
*/
void amba_release_regions(struct amba_device *dev)
{
release_mem_region(dev->res.start, SZ_4K);
u32 size;

size = resource_size(&dev->res);
release_mem_region(dev->res.start, size);
}

EXPORT_SYMBOL(amba_driver_register);
Expand Down

0 comments on commit 8afe0b9

Please sign in to comment.