Reputation: 31
I have a problem writing a device driver. The number of fields in the platform_data struct is getting too big because of the different use cases. I already have 14 fields and I have to add at least 5 others. The code is getting unreadable.
My manager insists that I use a "struct resource" to pass the parameters. But I can't find an tutorial or at least an example to show me how to do that.
Can you help me to do this?
Upvotes: 3
Views: 2161
Reputation: 2368
I'd agree that the kernel documentation for platform devices doesn't quite explain everything, hope this helps.
In the board file:
static struct resource mydevice_resource[] = {
[0] = {
.start = MYDEVICE_REG_START,
.end = MYDEVICE_REG_STOP,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = MYDEVICE_IV,
.end = MYDEVICE_IV,
.flags = IORESOURCE_IRQ,
},
};
...
static struct platform_device mydevice_device = {
.name = "mydevice",
.id = MYDEVICE_ID_1,
.num_resources = ARRAY_SIZE(mydevice_resource),
.resource = mydevice_resource,
.dev = {
/* .platform_data = ... if needed */
},
};
In the driver:
static int __devinit mydevice_probe(struct platform_device *pdev)
{
struct resource *res;
...
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
...
Upvotes: 4