LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Platform_device structure with more than one driver (https://www.linuxquestions.org/questions/linux-kernel-70/platform_device-structure-with-more-than-one-driver-698510/)

AustinMarton 01-19-2009 10:36 PM

Platform_device structure with more than one driver
 
Hi there, I am working on two drivers for a network device running on uClinux. One is a char driver which controls the configuration registers, and one is a network driver which is responsible for tx/rx of Ethernet frames.

Since the base address and irq configuration could change, we have decided to register them both as a "platform_device".

I have managed to do this successfully with the network driver, but now it comes to doing the same with the character driver I am not sure how to go about it.

Can anyone link me to some sort of outline of the platform device structure? Although it is mentioned a lot I am having difficulty finding any actual definition of how to use it. Does anyone know how this works with two drivers accessing the same resource? Do I need to create two resources with the same address?

Currently my setup.c file looks something like this...
Code:

#if defined(CONFIG_mydriv) && defined(na_mydriv)
#include <linux/mydriv.h>
static struct resource mydriv_resource[] = {
        [0] = {        /* Address */
                .start = na_mydriv + 0,        /* 70 */
                .end  = na_mydriv + 3,        /* 73 */
                .flags = IORESOURCE_MEM,
        },
        [1] = { /* Data */
                .start = na_mydriv + 4,        /* 74 */
                .end  = na_mydriv + 5,        /* 75 */
                .flags = IORESOURCE_MEM,
        },
        [2] = { /* IRQ */
                .start = na_mydriv_irq,        /* 4 */
                .end  = na_mydriv_irq,        /* 4 */
                .flags = IORESOURCE_IRQ | IRQF_TRIGGER_FALLING,
        },
        [3] = { /* CPU_FRAME_REG */
                .start = na_mydriv + 6,        /* 76 */
                .end  = na_mydriv + 7,        /* 77 */
                .flags = IORESOURCE_MEM,
        },
        [4] = { /* CMD_STATUS_REG */
                .start = na_mydriv + 8,        /* 78 */
                .end  = na_mydriv + 9,        /* 79 */
                .flags = IORESOURCE_MEM,
        },
        [5] = { /* INT_REG */
                .start = na_mydriv + 10,        /* 7A */
                .end  = na_mydriv + 11,        /* 7B */
                .flags = IORESOURCE_MEM,
        },
        [6] = { /* CTL_FRAME_BUF1 */
                .start = na_mydriv + 12,        /* 7C */
                .end  = na_mydriv + 13,        /* 7D */
                .flags = IORESOURCE_MEM,
        },
        [7] = { /* CTL_FRAME_BUF2 */
                .start = na_mydriv + 14,        /* 7E */
                .end  = na_mydriv + 15,        /* 7F */
                .flags = IORESOURCE_MEM,
        }

};
static struct mydriv_plat_data mydriv_platdata = {
        .flags                = mydriv_PLATF_16BITONLY,
};
static struct platform_device mydriv_device = {
        .name                = "mydriv",
        .id                = 0,
        .num_resources        = ARRAY_SIZE(mydriv_resource),
        .resource        = mydriv_resource,
        .dev                = {
                .platform_data = &mydriv_platdata,
        }
};
static int __init mydriv_device_init(void)
{
        /* customizes platform devices, or adds new ones */
        platform_device_register(&mydriv_device);
        return 0;
}
arch_initcall(mydriv_device_init);
#endif



All times are GMT -5. The time now is 11:26 AM.