fl2440添加USB驱动

fl2440添加USB驱动

make menuconfig选项

linux内核对于USB驱动已经完善得很好,我们只需要在make menuconfig选项中选择相应的选项便可以直接使用。

  Device Drivers  ---> 
      Generic Driver Options  --->
           (/sbin/hotplug) path to uevent helper /*支持热拔插*/
      [*] Block devices  ---> 
           <*>   Low Performance USB Block driver 
      /*因为u盘用到了scsi命令,所以我们需要增加scsi支持*/
      SCSI device support  ---> 
           <*> SCSI device support
           [*] legacy /proc/scsi/ support /*一些老的刻录程序可能需要它 ,最好选上*/
           <*> SCSI disk support
           <*> SCSI generic support                          
           [*] Probe all LUNs on each SCSI device
      [*] USB support  --->  
          <*>  Support for Host-side USB 
          [*]     USB device filesystem (DEPRECATED)
          [*]     USB device class-devices (DEPRECATED)
          <*>  USB Monitor 
          <*>  OHCI HCD support  
          <*>  USB Mass Storage support/*配置内核支持USB大容量存储,选上该选项才能查看U盘内容*/
       /*HID是Human Interface Devices的缩写.翻译成中文即为人机交互设备.这里的人机交互设备是一个宏观上面的概念,任何设备,只要符合HID spec,都可以称之为HID设备*/   
      [*] HID Devices  --->
           <*>   USB Human Interface Device (full HID) support 
           [*]   /dev/hiddev raw HID device support    

 /*添加文件系统支持*/
   File systems  ---> 
       DOS/FAT/NT Filesystems  ---> 
           <*> MSDOS fs support 
           <*> VFAT (Windows-95) fs support
           (437) Default codepage for FAT  
           (iso8859-1) Default iocharset for FAT 
           <*> NTFS file system support
           [*]   NTFS debugging support 
           [*]   NTFS write support 

在make menuconfig中,以上这些选项必须要选上

修改内核源码

添加厂商ID和设备ID
操作目标:内核目录/drivers/usb/serial/option.c
操作事件:添加USB设备ID和厂商ID
下面是我修改源码后自己做的补丁文件

[lwn@localhost linux-lwn-3.0.1]$ vim option.patch
--- ../linux-3.0.1/drivers/usb/serial/option.c  2011-08-05 12:59:21.000000000 +0800
+++ drivers/usb/serial/option.c 2017-04-15 12:16:12.357379163 +0800
@@ -51,6 +51,13 @@
 static void option_instat_callback(struct urb *urb);

 /* Vendor and product IDs */
+static int vendor = 0;/* add by li wanneng */
+static int product = 0;/* add by Li Wanneng */
+
+/*    Vendor and product IDs */
+#define OPTION_VENDOR_RESERVED      0xFFFF /*    Add by Li wanneng */
+#define OPTION_RESERVED_DEVICE      0xFFFF /*    Add by liwanneng */
+
 #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) },/* add by liwanneng */
    { 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,14 @@
 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;

操作目标:内核目录/arch/arm/mach-s3c2440/mach-smdk2440.c
操作事件:在文件中添加usb支持
下面是我修改源码后自己做的补丁文件

[lwn@localhost linux-lwn-3.0.1]$ vim mach-smdk2440.patch
--- ../linux-3.0.1/arch/arm/mach-s3c2440/mach-smdk2440.c    2011-08-05 12:59:21.000000000 +0800
+++ arch/arm/mach-s3c2440/mach-smdk2440.c   2017-04-15 12:32:10.778304531 +0800
@@ -13,6 +13,7 @@
  *
 */

 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/interrupt.h>
@@ -23,6 +24,13 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>

+/* add by liwanneng 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>
 #include <asm/mach/irq.h>
@@ -45,8 +53,57 @@
 #include <plat/devs.h>
 #include <plat/cpu.h>

+#include <plat/ts.h>         /* Add by liwanneng to support Touch screen, 2017-4-15 12:25:32 */
+#include <mach/regs-clock.h> /* Add by liwanneng 2017-4-15 12:26:08, for usb_s3c2440_init() */
+#include <linux/i2c.h>       /* Add by liwanneng 2017-4-15 12:26:31, for AT24C512 driver  */
+#include <linux/i2c/at24.h>  /* Add by liwanneng 2017-4-15 12:26:53, for AT24C512 driver  */
+#include <linux/delay.h> /*Add by liwanneng 2017-4-15 12:27:32  */
+
 #include <plat/common-smdk.h>


@@ -155,13 +212,29 @@
    &s3c_device_wdt,
    &s3c_device_i2c0,
    &s3c_device_iis,
+    &s3c_device_dm9000,
 };

+/*  Add by liwanneng 2017-4-15 12:29:19, 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);/*fl2440的时钟频率改为12000000*/
+   s3c24xx_init_clocks(12000000);/* Modify by liwanneng,2017-4-15 12:31:04 */
    s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
+    usb_s3c2440_init(); /*  Add by liwanneng 2017-4-15 12:31:32 */
 }

 static void __init smdk2440_machine_init(void)
重新编译

内核修改完成之后,重新编译生成内核文件并烧录到开发板上,启动内核,打印以下信息说明usb驱动已经添加成功
Freeing init memory: 128K
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected

插入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: [sda] Write Protect is off
sd 0:0:0:0: Attached scsi generic sg0 type 0
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

查看U盘文件内容:
:>ls /mnt/usb
这里写图片描述
拔出U盘显示

: usb 1-1.1: USB disconnect, device number 3

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值