0
votes

dev-audio declares two devices:

struct platform_device s5pv210_device_iis0 = {
 63         .name = "samsung-i2s",
 64         .id = 0,
 65         .num_resources    = ARRAY_SIZE(s5pv210_iis0_resource),
 66         .resource         = s5pv210_iis0_resource,
 67         .dev = {
 68                 .platform_data = &i2sv5_pdata,
 69         },
 70 };   
 76 static struct resource s5pv210_iis1_resource[] = {
 77         [0] = DEFINE_RES_MEM(S5PV210_PA_IIS1, SZ_256),
 78         [1] = DEFINE_RES_DMA(DMACH_I2S1_TX),
 79         [2] = DEFINE_RES_DMA(DMACH_I2S1_RX),
 80 };
 81 
 82 struct platform_device s5pv210_device_iis1 = {
 83         .name             = "samsung-i2s",
 84         .id               = 1,
 85         .num_resources    = ARRAY_SIZE(s5pv210_iis1_resource),
 86         .resource         = s5pv210_iis1_resource,
 87         .dev = {
 88                 .platform_data = &i2sv3_pdata,
 89         },
 90 };
 91 
 92 static struct resource s5pv210_iis2_resource[] = {
 93         [0] = DEFINE_RES_MEM(S5PV210_PA_IIS2, SZ_256),
 94         [1] = DEFINE_RES_DMA(DMACH_I2S2_TX),
 95         [2] = DEFINE_RES_DMA(DMACH_I2S2_RX),
 96 };

The two devices are 2 instances of the i2s driver.

Assuming I add a function EXPORT_SYMBOL in i2s driver, which will be used by 2 different kernel modules.

How can I declare and use such an exported function doing the following:

if (called from kernel module 1):
 i2s_rxctrl the device id=0
elif (called from kernel module 2):
 i2s_rxctrl the device id=1

There is one-to-one mapping of a kernel module to device id.

So basically what I ask is how to make the exported symbol to be Object oriented style so for each instance it will execute code specific to the device. I thought to give the kernel module an handle to *pdev but it seems to be a violation.

2
I do not understand. Why you want to use a function in two different modules (two different drivers)? Or you mean two different instance that are using the same driver? - Federico
I want that each kernel module will interact with a different instance. - 0x90

2 Answers

0
votes

I think you can always pass a parameter and value to your kernel module and check it in driver code.

0
votes

You can create your custom structure with all necessary information to uniquely identify your instance across different modules (why not, also *pdev). Then, you pass this structure to your library. Thanks to your custom structure, the library can do the correct operation.