红联Linux门户
Linux帮助

fl2440 linux内核移植usb驱动

发布时间:2017-06-08 10:57:53来源:linux网站作者:zouleideboke
开发板:fl2440
Linux内核:linux-3.0
 
1.添加USB结构体变量,加厂商ID和设备ID
[zoulei@CentOS linux-3.0]$vim arch/arm/mach-s3c2440/mach-smdk2440.c
--- mach1-smdk2440.c    2017-04-15 06:12:36.061000246 -0700
+++ mach2-smdk2440.c    2017-04-15 06:21:30.015999978 -0700
@@ -13,6 +13,7 @@
*
*/ 
+#include <linux/dm9000.h> 
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/interrupt.h>
@@ -22,6 +23,12 @@
#include <linux/serial_core.h>
#include <linux/platform_device.h>
#include <linux/io.h>
+/*  add by zoulei for norflash  */  
+#include <linux/gpio_keys.h>  
+#include <linux/input.h>  
+#include <linux/mtd/physmap.h>  
+#include <linux/mtd/mtd.h>  
+#include <linux/mtd/partitions.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
@@ -44,9 +51,45 @@
#include <plat/clock.h>
#include <plat/devs.h>
#include <plat/cpu.h>
-
+#include <plat/ts.h>         /*Add by zoulei to support Touch screen, 2017.04.15*/  
+#include <mach/regs-clock.h> /*Add by zoulei  2017.04.15, for usb_s3c2440_init() */  
+#include <linux/i2c.h>       /*Add by zoulei 2017.4.15, for AT24C512 driver */  
+#include <linux/i2c/at24.h>  /*Add by zoulei 2017.4.15, for AT24C512 driver */  
+#include <linux/delay.h>  
#include <plat/common-smdk.h>
+#define DM9000_BASE    (S3C2410_CS4 + 0x300)  
+static struct resource s3c_dm9000_resource[] = {  
+     [0] = {  
+        .start = DM9000_BASE,  
+        .end   = DM9000_BASE + 3,  
+        .flags = IORESOURCE_MEM  
+    },  
+    [1] = {  
+        .start = DM9000_BASE + 4,  
+        .end   = DM9000_BASE + 7,  
+        .flags = IORESOURCE_MEM  
+    },  
+    [2] = {  
+        .start = IRQ_EINT7,  
+        .end   = IRQ_EINT7,  
+        .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,  
+    }  
+};  
+
+static struct dm9000_plat_data s3c_dm9000_pdata = {  
+    .flags      = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),  
+};  
+static struct platform_device s3c_device_dm9000 = {  
+    .name       = "dm9000",  
+    .id     = -1,  
+    .num_resources  = ARRAY_SIZE(s3c_dm9000_resource),  
+    .resource   = s3c_dm9000_resource,  
+    .dev        = {  
+        .platform_data  = &s3c_dm9000_pdata,  
+    },  
+};   
+
static struct map_desc smdk2440_iodesc[] __initdata = {
/* ISA IO Space map (memory space selected by A24) */
@@ -155,13 +198,30 @@
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
+        &s3c_device_dm9000,
};
+/* Add by zoulei 2017.04.15, fix device descriptor read/64, error -62 bug, value refer to datasheet P255 */   
+int usb_s3c2440_init(void)  
+{  
+    /* Input Frequency is 12.0000MHz, and MDEV=0x38 PDIV=2 SDIV=2, so output frequency 48.00MHz */  
+    unsigned long upllvalue = (0x38<<12)|(0x02<<4)|(0x02);   
+    while (upllvalue != __raw_readl(S3C2410_UPLLCON))  
+   {  
+        __raw_writel(upllvalue, S3C2410_UPLLCON);   
+        mdelay(1);   
+    }  
+  
+    return 0;  
+}  
+
+
static void __init smdk2440_map_io(void)
{
s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));
-       s3c24xx_init_clocks(16934400);
+       s3c24xx_init_clocks(12000000);
        s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
+        usb_s3c2440_init(); /* Add by zoulei, 2017.04.15 */
}
static void __init smdk2440_machine_init(void)
##################################################
[zoulei@CentOS linux-3.0]$ vim drivers/usb/serial/option.c
--- option.c    2017-04-15 06:06:17.470001485 -0700
+++ option1.c   2017-04-15 05:47:14.996001503 -0700
@@ -50,7 +50,14 @@
static int option_send_setup(struct usb_serial_port *port);
static void option_instat_callback(struct urb *urb);
-/* Vendor and product IDs */
+ /* Vendor and product IDs */  
+static int vendor = 0; /*   Add by zoulei */  
+static int product = 0; /*   Add by zoulei  */  
+
+/*   Vendor and product IDs */  
+#define OPTION_VENDOR_RESERVED      0xFFFF /*   Add by zoulei */  
+#define OPTION_RESERVED_DEVICE      0xFFFF /*   Add by zoulei */   
+
#define OPTION_VENDOR_ID                       0x0AF0
#define OPTION_PRODUCT_COLT                    0x5000
#define OPTION_PRODUCT_RICOLA                  0x6000
@@ -446,7 +453,8 @@
.reason = OPTION_BLACKLIST_SENDSETUP
};
-static const struct usb_device_id option_ids[] = {
+static  struct usb_device_id option_ids[] = {
+        { USB_DEVICE(OPTION_VENDOR_RESERVED, OPTION_RESERVED_DEVICE) },
{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) },
@@ -1079,6 +1087,15 @@
static int __init option_init(void)
{
int retval;
+        
+         if ((vendor>0) && (product>0))  
+           {  
+              option_ids[0].match_flags = USB_DEVICE_ID_MATCH_DEVICE;  
+              option_ids[0].idVendor = vendor;  
+              option_ids[0].idProduct = product;  
+              printk("Register option drvier for modem vendor=0x%04x product=0x%04x\n", vendor, product);  
+            }  
+
retval = usb_serial_register(&option_1port_device);
if (retval)
goto failed_1port_device_register;
 
2.添加U盘支持  
[zoulei@CentOS linux-3.0]$ make menuconfig
Device Drivers  ---> 
Generic Driver Options  --->
(/sbin/hotplug) path to uevent helper                  //配置u盘的热插拔
[*] Block devices  --->
<*>   Low Performance USB Block driver     //低性能USB块设备驱动
SCSI device support  ---> 
<*> SCSI device support   //SCSI设备的支持
[*]  legacy /proc/scsi/ support
<*> SCSI disk support     //是对 USB 鼠标键盘的支持
<*> SCSI generic support //SCSI通用的支持
[*] Probe all LUNs on each SCSI device           //所有在每个SCSI LUN探针装置
[*] HID Devices --->
<*> USB Human Interface Device (full HID) support //是对 USB 鼠标键盘的支持
[*] /dev/hiddev raw HID device support
[*] USB support  ---> 
<*>   Support for Host-side USB  //主机端USB支持
[*]     USB device filesystem (DEPRECATED)  //USB设备文件系统(不推荐使用)
[*]     USB device class-devices (DEPRECATED)   / /USB设备类设备(不推荐使用)
<*>   USB Monitor   //USB监控
<*>   OHCI HCD support  //支持OHCI标准
<*>   USB Mass Storage support  //支持USB海量存储
File systems  --->               //配置u盘的文件系统
DOS/FAT/NT Filesystems  --->
<*> MSDOS fs support
<*> VFAT (Windows-95) fs support
(437) Default codepage for FAT //默认代码页
(iso8859-1) Default iocharset for FAT //默认字符集
-*- Native language support  --->     //配置u盘的语言格式支持
--- Native language support       
<*>    Codepage  437 (United States, Canada)
<*>   Simplified Chinese charset (CP936, GB2312)
<*>   ASCII (United States) 
<*>   NLS UTF-8
 
3.自动挂载:
[zoulei@centos6 ~]$ cd /home/zoulei/opt/rootfs/etc
[zoulei@centos6 etc]$ vim mdev.conf
sd[a-z][0-9]      0:0 0777        @(mount /dev/$MDEV /mnt/usb)
sd[a-z]           0:0 0777        $(umount /mnt/usb)
#ub[a-z][0-9]      0:0 0777        @(mount /dev/$MDEV /mnt/usb)
#ub[a-z]           0:0 0777        $(umount /mnt/usb)
mmcblk[0-9]p[0-9] 0:0 0777        @(mount /dev/$MDEV /mnt/sdc)
mmcblk[0-9]       0:0 0777        $(umount /mnt/sdc)
注意:根文件树加了这个配置文件就可以自动挂载了,否则就需要手动挂载:mount  /dev/sda  /mnt/usb
如果你的U盘在板子上显示是sd,也可能有的设备是ub,这时候进入你的根文件树查看是否自动挂载
sd的设备后置a-z或者0-9都可以显示自动挂载 ub的设备后置从a-z可以显示自动挂载,如果你的ub设备显示数字,可将第三行改为
#ub[a-z][0-9]      0:0 0777        @(mount /dev/$MDEV /mnt/usb)
mmcblk的设备也是如此。
 
4.开发板上操作
当插上U盘后开发板上显示:
>: usb 1-1.1: new full speed USB device number 3 using s3c2410-ohci
scsi0 : usb-storage 1-1.1:1.0
scsi 0:0:0:0: Direct-Access     UDISK    PDU15_1G 71G2.0  0.00 PQ: 0 ANSI: 2
sd 0:0:0:0: [sda] 2015231 512-byte logical blocks: (1.03 GB/983 MiB)
sd 0:0:0:0: Attached scsi generic sg0 type 0
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sda: sda1
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] Attached SCSI removable disk
fl2440 linux内核移植usb驱动
查看挂载到/mnt/usb目录,可以看到里面有我的u盘的内容,说明U盘移植成功了!
已经添加了中文支持。可是u盘还是显示不了中文。
 
遇到的问题及解决方法:
问题1.
>: usb 1-1.2: new full speed USB device number 3 using s3c2410-ohci
scsi0 : usb-storage 1-1.2:1.0
JFFS2 notice: (769) check_node_data: wrong data CRC in data node at 0x00bc06f8: read 0x45e69e3e, calculated 0x21c8152d.
JFFS2 notice: (769) check_node_data: wrong data CRC in data node at 0x0109c890: read 0x10e5206a, calculated 0x8be51971.
scsi 0:0:0:0: Direct-Access     UDISK    PDU15_1G 71G2.0  0.00 PQ: 0 ANSI: 2
scsi 0:0:0:0: Attached scsi generic sg0 type 0
>: usb 1-1.2: USB disconnect, device number 3
usb 1-1.1: new full speed USB device number 4 using s3c2410-ohci
scsi1 : usb-storage 1-1.1:1.0
scsi 1:0:0:0: Direct-Access     UDISK    PDU15_1G 71G2.0  0.00 PQ: 0 ANSI: 2
scsi 1:0:0:0: Attached scsi generic sg0 type 0
解决:插上U盘后开发板上只显示这么少的信息,而且查看我的U盘会有错误显示!
说明有很多内核配置我没选上,于是又再选上支持usb,u盘的选项
问题2:
>: mount /dev/sda1 /mnt/usb/
mount: mounting /dev/sda1 on /mnt/usb/ failed: Device or resource busy
解决:因为内核是自动挂载的,当然这是自己在根文件系统树里面配置的,如果你已经自动挂载,
那么再手动挂载就会显示设备资源忙的提示。
问题3.
>: usb 1-1.1: new full speed USB device number 3 using s3c2410-ohci
scsi0 : usb-storage 1-1.1:1.0
scsi 0:0:0:0: Direct-Access     UDISK    PDU15_1G 71G2.0  0.00 PQ: 0 ANSI: 2
sd 0:0:0:0: [sda] 2015231 512-byte logical blocks: (1.03 GB/983 MiB)
sd 0:0:0:0: Attached scsi generic sg0 type 0
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sda: sda1
sd 0:0:0:0: [sda] Asking for cache data failed
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] Attached SCSI removable disk
FAT-fs (sda1): codepage cp437 not found
FAT-fs (sda1): codepage cp437 not found
FAT-fs (sda1): IO charset iso8859-1 not found
解决:内核没有选上Codepage  437,在--- Native language support 里面选上就可以了!
 
本文永久更新地址:http://www.linuxdiyf.com/linux/31335.html