LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   AMBA device registering (https://www.linuxquestions.org/questions/linux-kernel-70/amba-device-registering-473763/)

drasko 08-14-2006 10:28 AM

AMBA device registering
 
Hi all.
can anybody explain me these lines:

for (pid = 0, i = 0; i < 4; i++)
pid |= (readl(tmp + 0xfe0 + 4 * i) & 255) << (i * 8);
for (cid = 0, i = 0; i < 4; i++)
cid |= (readl(tmp + 0xff0 + 4 * i) & 255) << (i * 8);

iounmap(tmp);

if (cid == 0xb105f00d)
dev->periphid = pid;

if (dev->periphid)
ret = device_register(&dev->dev);
else
ret = -ENODEV;

in amba.c, in /arc/arm/common. I pasted the whole
amba_device_register() fnc. below.

I need to register my i2c_device as an amba_device, so I have question
about .periphid member od amba_device struct. What number does it
represent? Is it connected to above lines found in amba.c and how?
Looks like it is, but I can decypher these...

I have UARTS defined as amba_device:
static struct amba_device uart0_device = {
.dev = {
.bus_id = "dev:00",
},
.res = {
.start = UART0_BASE,
.end = UART0_BASE + SZ_4K - 1,
.flags = IORESOURCE_MEM,
},
.irq = { UARTINTR0_VECTOR, NO_IRQ },
.periphid = 0x0041010,
};

Here stands .periphid = 0x0041010. Why? Is this number something
specific to AMBA or to UART? I can find this nuber figure in several
more files, like arch/arm/mach-integrator/core.c, but also for uart
device...

Also, can anybody describe me .bus_id part of .dev structure (why is it
initialized to "dev:00" and what are possible initializers)? In
arch/arm/mach-integrator/core.c there stands "mb:15", "mb:16"... for
devices. In mine core.c they start from "dev:00". Still I can not
understand what this value means...

-----------------

/**
* 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)
{
u32 pid, cid;
void __iomem *tmp;
int i, ret;

dev->dev.release = amba_device_release;
dev->dev.bus = &amba_bustype;
dev->dev.dma_mask = &dev->dma_mask;
dev->res.name = dev->dev.bus_id;

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);
if (ret == 0) {
tmp = ioremap(dev->res.start, SZ_4K);
if (!tmp) {
ret = -ENOMEM;
goto out;
}

for (pid = 0, i = 0; i < 4; i++)
pid |= (readl(tmp + 0xfe0 + 4 * i) & 255) << (i * 8);
for (cid = 0, i = 0; i < 4; i++)
cid |= (readl(tmp + 0xff0 + 4 * i) & 255) << (i * 8);

iounmap(tmp);

if (cid == 0xb105f00d)
dev->periphid = pid;

if (dev->periphid)
ret = device_register(&dev->dev);
else
ret = -ENODEV;

if (ret == 0) {
device_create_file(&dev->dev, &dev_attr_id);
if (dev->irq[0] != NO_IRQ)
device_create_file(&dev->dev, &dev_attr_irq0);
if (dev->irq[1] != NO_IRQ)
device_create_file(&dev->dev, &dev_attr_irq1);
device_create_file(&dev->dev, &dev_attr_resource);
} else {
out:
release_resource(&dev->res);
}
}

return ret;

}


All times are GMT -5. The time now is 09:16 PM.