c - How to forward a generic resource/data of platform_device to a driver -
i have platform_device
instance , want pass function pointer, wondering cleanest , generic way doing it.
the optimal thing if had misc resource in kernel can pass void*
whatever want available resources:
31 #define ioresource_type_bits 0x00001f00 /* resource type */ 32 #define ioresource_io 0x00000100 /* pci/isa i/o ports */ 33 #define ioresource_mem 0x00000200 34 #define ioresource_reg 0x00000300 /* register offsets */ 35 #define ioresource_irq 0x00000400 36 #define ioresource_dma 0x00000800 37 #define ioresource_bus 0x00001000
actually have container platform device allocated , initialized dynamically in probe function.
my question how pass generic pointer resource device ? or how can in cleanest way?
use platform_data
described @ bottom of lwn article link in question. in case, data structure this. untested, idea. platform_data struct hold function pointers, set @ same time define particulars of device.
int sleep_function_chip1(struct platform_device *pdev) { // go sleep return 0; } int resume_function_chip1(struct platform_device *pdev) { // resume return 0; } struct my_platform_data { int (*sleep_function)(struct platform_device *); int (*resume_function)(struct platform_device *); }; // instance of my_platform_data particular hardware (called chip1 now) static struct my_platform_data my_platform_data_chip1 = { .sleep_function = &sleep_function_chip1, .resume_function = &resume_function_chip1, }; // second instance of my_platform_data different hardware (called chip2 now) static struct my_platform_data my_platform_data_chip2 = { .sleep_function = &sleep_function_chip2, .resume_function = &resume_function_chip2, }; // include data when create descriptor // platform static struct platform_device my_platform_device_chip1 = { .name = "my_device", .id = 0, .dev = { .platform_data = &my_platform_data_chip1, } }; int some_driver_function() { struct platform_device *pdev; pdev = // wherever store // time need data, extract platform_data pointer struct my_platform_data *pd = (struct my_platform_data*)pdev->dev.platform_data; // call function pointer pd->sleep_function(pdev); }
Comments
Post a Comment