Linux-4.9.2内核在mini2440上的移植(六)——修改MD9000驱动

本篇目标:修改DM9000驱动,使内核支持网络。

6.1 移植DM9000 网卡驱动

(1)在linux-4.9.2文件夹,输入

root@ubuntu:~/linux-4.9.2#vim arch/arm/mach-s3c24xx/mach-mini2440.c

定位到53行,添加

#include

#include

 

(2)填充该平台设备的资源设置

定位到206行附近,如入下面代码:

tatic struct s3c2410_platform_nand mini2440_nand_info = {
 .tacls  = 20,
 .twrph0  = 60,
 .twrph1  = 20,
 .nr_sets = ARRAY_SIZE(mini2440_nand_sets),
 .sets  = mini2440_nand_sets,
 .ignore_unset_ecc = 1,
};
/* DM9000AEP 10/100 ethernet controller */

#define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)

static struct resource mini2440_dm9k_resource[] = {

        [0] = {

               .start = MACH_MINI2440_DM9K_BASE,

               .end   = MACH_MINI2440_DM9K_BASE +3,

               .flags = IORESOURCE_MEM

        },

        [1] = {

               .start = MACH_MINI2440_DM9K_BASE + 4,

               .end   = MACH_MINI2440_DM9K_BASE +7,

               .flags = IORESOURCE_MEM

        },

        [2] = {

               .start = IRQ_EINT7,

               .end   = IRQ_EINT7,

               .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,

        }

};

/*

 *  *  *The DM9000 has no eeprom, and it's MAC address is set by

 *   *   *the bootloader before starting the kernel.

 *    *   */

static struct dm9000_plat_data mini2440_dm9k_pdata = {

        .flags          = (DM9000_PLATF_16BITONLY |DM9000_PLATF_NO_EEPROM),

};

static struct platform_device mini2440_device_eth = {

        .name           = "dm9000",

        .id             = -1,

       .num_resources  = ARRAY_SIZE(mini2440_dm9k_resource),

       .resource       =mini2440_dm9k_resource,

        .dev            = {

               .platform_data  =&mini2440_dm9k_pdata,

        },

};

 

static struct platform_device *mini2440_devices[]__initdata = {

       &s3c_device_ohci,

       &s3c_device_lcd,

       &s3c_device_wdt,

       &s3c_device_i2c0,

       &s3c_device_iis,

       &s3c_device_nand,

        &mini2440_device_eth,

};

保存退出。

6.2 调整DM9000 所用的位宽寄存器

DM9000的驱动是有问题的,不能直接使用,需要修改

root@ubuntu:~/linux-4.9.2#vim drivers/net/ethernet/davicom/dm9000.c

 

(1)打开linux-4.9.2/drivers/net/ethernet/davicom/dm9000.c,定位到49行附近,添加2410 相关的配置定义,如下红色部分:

#include
#include
#include

#include "dm9000.h"
#define CONFIG_ARCH_S3C2410

#if defined(CONFIG_ARCH_S3C2410)

#include<../../../../arch/arm/mach-s3c24xx/regs-mem.h>

#endif

(2) 在dm9000 设备的初始化函数中添加如下红色部分,这里是配置DM9000 所用片选总线的时序,因为mini2440 目前只有一个通过总线外扩的设备,在此设备驱动中直接修改相关的寄存器配置会更加容易理解一些,当然这部分也可以放到mach-mini2440.c 中。

打开linux-4.9.2/drivers/net/ethernet/davicom/dm9000.c,定位到914行附近,加入下面代码:

/*

 * Initialize dm9000 board

 */

static void

dm9000_init_dm9000(struct net_device *dev)

{

#ifdefined(CONFIG_ARCH_S3C2410)

       unsigned int oldval_bwscon = *(volatile unsigned int*)S3C2410_BWSCON;                unsignedint oldval_bankcon4 = *(volatile unsigned int *)S3C2410_BANKCON4;            *((volatile unsigned int*)S3C2410_BWSCON) =                                                  (oldval_bwscon &~(3<<16)) | (1<<16) | (1<<18) | (1<<19);                     *((volatile unsigned int*)S3C2410_BANKCON4) = 0x1f7c;

#endif

 

        struct board_info *db= netdev_priv(dev);

        unsigned int imr;

        unsigned int ncr;

到此为止 DM9000 就已经移植结束了。

 

6.3编译测试

root@ubuntu:~/linux-4.9.2# make -j8

root@ubuntu:~/linux-4.9.2#./mkuImage.sh

你可能感兴趣的:(Linux-4.9.2内核在mini2440上的移植(六)——修改MD9000驱动)