DM9000驱动程序详解

时间:2013-03-21作者:klpeng分类:数据库浏览:2228评论:0
//arch/arm/mach-s5pv210/mach-smdkv210.c

/*片选信号使用的是XM0CSn1,查看S5PV210的芯片手册内存映射一节可以找到SROM BANK1的地址范围是0x8800_0000 --0x8FFF_FFFF,
   则访问这个范围的地址时会激活片选使能信号XM0CSn1*/
#define S5PV210_PA_DM9000_A     (0x88001000) 
#define S5PV210_PA_DM9000_F     (S5PV210_PA_DM9000_A + 0x300C)
//
static struct resource smdkv210_dm9000_resources[] = {
    [0] = {
        .start  = S5PV210_PA_DM9000_A, //地址线
        .end    = S5PV210_PA_DM9000_A + SZ_1K*4 - 1,
        .flags  = IORESOURCE_MEM,
    },
    [1] = {
        .start  = S5PV210_PA_DM9000_F, //数据线
        .end    = S5PV210_PA_DM9000_F + SZ_1K*4 - 1,
        .flags  = IORESOURCE_MEM,
    },  
    [2] = { 
        .start  = IRQ_EINT(7),
        .end    = IRQ_EINT(7),
        .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,//中断资源和高频存储发资源
    },
};


//arch/arm/mach-s5pv210/mach-smdkv210.c

static struct dm9000_plat_data smdkv210_dm9000_platdata = { .flags = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM, //16bit模式 .dev_addr = { 0x08, 0x90, 0x00, 0xa0, 0x02, 0x10 }, //设置网卡的物理地址 };


struct platform_device smdkv210_dm9000 = {
    .name       = "dm9000",  //平台设备名
    .id     = -1,
    .num_resources  = ARRAY_SIZE(smdkv210_dm9000_resources), //资源数组个数
    .resource   = smdkv210_dm9000_resources, //资源数组
    .dev        = {
        .platform_data  = &smdkv210_dm9000_platdata, //平台设备数据
    },
};

static struct platform_device *smdkv210_devices[] __initdata = {
     ...
&smdkv210_dm9000,
...
};

static void __init smdkv210_dm9000_init(void)
{
    unsigned int tmp;

    gpio_request(S5PV210_MP01(1), "nCS1");
    s3c_gpio_cfgpin(S5PV210_MP01(1), S3C_GPIO_SFN(2));
    gpio_free(S5PV210_MP01(1));

    tmp = (5 << S5P_SROM_BCX__TACC__SHIFT);
    __raw_writel(tmp, S5P_SROM_BC1);

    tmp = __raw_readl(S5P_SROM_BW);
    tmp &= (S5P_SROM_BW__CS_MASK << S5P_SROM_BW__NCS1__SHIFT);
    tmp |= (1 << S5P_SROM_BW__NCS1__SHIFT);
    __raw_writel(tmp, S5P_SROM_BW);
}


static void __init smdkv210_machine_init(void)
{
s3c_pm_init();

    smdkv210_dm9000_init(); //dm9000初始化
....

    platform_add_devices(smdkv210_devices, ARRAY_SIZE(smdkv210_devices));//将所有设备添加到系统

};


MACHINE_START(SMDKV210, "SMDKV210")
    /* Maintainer: Kukjin Kim <kgene.kim@samsung.com> */
    .boot_params    = S5P_PA_SDRAM + 0x100,
    .init_irq   = s5pv210_init_irq,
    .map_io     = smdkv210_map_io,
    .init_machine   = smdkv210_machine_init, //机器初始化
    .timer      = &s5p_timer,
MACHINE_END

//drivers/base/platform.c
int platform_add_devices(struct platform_device **devs, int num)
{   
    int i, ret = 0;

    for (i = 0; i < num; i++) {
        ret = platform_device_register(devs[i]);
        if (ret) {  
            while (--i >= 0)
                platform_device_unregister(devs[i]);
            break;  
        }
    }

    return ret;
}


打赏
文章版权声明:除非注明,否则均为彭超的博客原创文章,转载或复制请以超链接形式并注明出处。
相关推荐

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

猜你喜欢