[i2c] amba_device resource
Drasko Draskovic
drasko.draskovic at gmail.com
Thu Aug 24 11:35:22 CEST 2006
Hi all,
I have question about resource member of amba_device struct. Struct
platform_device looks like this:
/* drivers/base/platform.c */
struct platform_device {
char * name;
u32 id;
struct device dev;
u32 num_resources;
struct resource * resource;
};
and amba_device:
struct amba_device {
struct device dev;
struct resource res;
u64 dma_mask;
unsigned int periphid;
unsigned int irq[AMBA_NR_IRQS];
};
So, amba_device has only one resource member while platform_device holds
array of resources.
In linux/drivers/i2c/busses/i2c-s3c2410.c, platform_device is used, and it
looks like this:
/* s3c24xx_i2c_probe
*
* called by the bus driver when a suitable device is found
*/
static int s3c24xx_i2c_probe(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct s3c24xx_i2c *i2c = &s3c24xx_i2c;
struct resource *res;
int ret;
...
...
/* map the registers */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(dev, "cannot find IO resource\n");
ret = -ENOENT;
goto out;
}
i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1,
pdev->name);
if (i2c->ioarea == NULL) {
dev_err(dev, "cannot request IO\n");
ret = -ENXIO;
goto out;
}
i2c->regs = ioremap(res->start, (res->end-res->start)+1);
if (i2c->regs == NULL) {
dev_err(dev, "cannot map IO\n");
ret = -ENXIO;
goto out;
}
dev_dbg(dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res);
...
...
/* find the IRQ for this unit (note, this relies on the init call to
* ensure no current IRQs pending
*/
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (res == NULL) {
dev_err(dev, "cannot find IRQ\n");
ret = -ENOENT;
goto out;
}
ret = request_irq(res->start, s3c24xx_i2c_irq, SA_INTERRUPT,
pdev->name, i2c);
if (ret != 0) {
dev_err(dev, "cannot claim IRQ\n");
goto out;
}
i2c->irq = res;
dev_dbg(dev, "irq resource %p (%ld)\n", res, res->start);
However, I want my i2c adapter to be an amba_device, so I am wondering how
to change calls like this:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
and how will it impact code...
Why platform_device holds array of resources, while amba_device holds one
resource? Can anybody explain a bit this resource(s) and what this member
should represent and describe?
Also -- why this function static int s3c24xx_i2c_probe(struct device *dev) gets
device* dev as an argument and not platform_device, so then has to cast: struct
platform_device *pdev = to_platform_device(dev); ?Is this correct way to
write these kinds of functions and why (since I noted that some of the
functions are taking directly platform_device as a parameter)? How to cast
to _amba_device (if needed)?
Best regards,
--
Drasko DRASKOVIC
Software Developer
Elsys-DESIGN
Belgrade, Serbia
Tel. +381.11.311.5252
Fax. +381.11.311.5251
www.elsys-design.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.lm-sensors.org/pipermail/i2c/attachments/20060824/46e5c397/attachment-0001.html
More information about the i2c
mailing list