【TINY4412】LINUX移植笔记:(9)USB驱动

【TINY4412】LINUX移植笔记:(9)USB驱动

宿主机 : 虚拟机 Ubuntu 16.04 LTS / X64
目标板[底板]: Tiny4412SDK - 1506
目标板[核心板]: Tiny4412 - 1412
LINUX内核: 4.12.0
交叉编译器: gcc-arm-none-eabi-5_4-2016q3
日期: 2017-7-27 21:29:22
作者: SY

简介

开发板使用了一块USB-HUB芯片USB4604,扩展了4USB。一路用于以太网,两路用于USB接口,还有一路使用排针引出。

设备树

# exynos4.dtsi
exynos_usbphy: exynos-usbphy@125B0000 {
    compatible = "samsung,exynos4210-usb2-phy";
    reg = <0x125B0000 0x100>;
    samsung,pmureg-phandle = <&pmu_system_controller>;
    clocks = <&clock CLK_USB_DEVICE>, <&clock CLK_XUSBXTI>;
    clock-names = "phy", "ref";
    #phy-cells = <1>;
    status = "disabled";
};

# exynos4412.dtsi
&exynos_usbphy {
    compatible = "samsung,exynos4x12-usb2-phy";
    samsung,sysreg-phandle = <&sys_reg>;
};

# exynos4412-tiny4412.dts
&exynos_usbphy {
        status = "okay";
};

# exynos4.dtsi
ehci: ehci@12580000 {
    compatible = "samsung,exynos4210-ehci";
    reg = <0x12580000 0x100>;
    interrupts = 70 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&clock CLK_USB_HOST>;
    clock-names = "usbhost";
    status = "disabled";
    #address-cells = <1>;
    #size-cells = <0>;
    port@0 {
      reg = <0>;
      phys = <&exynos_usbphy 1>;
      status = "disabled";
    };
    port@1 {
      reg = <1>;
      phys = <&exynos_usbphy 2>;
      status = "disabled";
    };
    port@2 {
      reg = <2>;
      phys = <&exynos_usbphy 3>;
      status = "disabled";
    };
};

# exynos4412-tiny4412.dts
&ehci {
    status = "okay";
    port@0 {
      status = "okay";
    };
    port@1 {
      status = "okay";
    };
    port@2 {
      status = "okay";
    };
};

# exynos4412-tiny4412.dts
usb-hub { 
    compatible = "smsc,usb4604";
    reset-gpios = <&gpm2 4 GPIO_ACTIVE_LOW>;
    initial-mode = <1>; 
    status = "okay";
};

发明设备树的人很好借鉴了面向对象程序设计,使用继承的方式,如果对父类的方法写的不满意,可以重写父类方法。

initial-mode = <1>; 

# 参考 usb4604.c
enum usb4604_mode {
    USB4604_MODE_UNKNOWN,
    USB4604_MODE_HUB,
    USB4604_MODE_STANDBY,
};
Device Drivers  --->
    [*] USB support  --->
        <*>   EHCI HCD (USB 2.0) support
        <*>     EHCI support for Samsung S5P/EXYNOS SoC Series 
        <*>   USB Mass Storage support
        <*>   USB4604 HSIC to USB20 Driver

测试

插上U盘USB并不能识别。在移植U-BOOTUSB时,就被坑过,那个USB复位引脚没有配置,所以导致不能正确启动USB,因此直奔主题:

#ifdef CONFIG_OF
static const struct of_device_id usb4604_of_match[] = {
    { .compatible = "smsc,usb4604" },
    {}
};
MODULE_DEVICE_TABLE(of, usb4604_of_match);
#endif

static struct i2c_driver usb4604_i2c_driver = {
    .driver = {
        .name = "usb4604",
        .pm = &usb4604_i2c_pm_ops,
        .of_match_table = of_match_ptr(usb4604_of_match),
    },
    .probe      = usb4604_i2c_probe,
    .id_table   = usb4604_id,
};
module_i2c_driver(usb4604_i2c_driver);

放置调试语句:

static int usb4604_i2c_probe(struct i2c_client *i2c,
                 const struct i2c_device_id *id)
{
    struct usb4604 *hub;
    pr_notice("------------I am Hear!----------\n");
    hub = devm_kzalloc(&i2c->dev, sizeof(*hub), GFP_KERNEL);
    if (!hub)
        return -ENOMEM;

    i2c_set_clientdata(i2c, hub);
    hub->dev = &i2c->dev;

    return usb4604_probe(hub);
}

重新上电,特么的居然没有执行!瞬间火大了,仔细检测了设备树

compatible = "smsc,usb4604";
status = "okay";

按道理匹配了,然后使能了,没理由不执行probe函数

困扰了一天,突然发现module_i2c_driver(usb4604_i2c_driver);,居然不是module_init(),估计需要使用I2C总线,但是I2C最快也才400Kbps,这种辣鸡总线也配USB使用,参考网上资料,直接从usb3503.c移植。其实移植很简单,就是将usb3053.cusb3053.h全部替换为usb4064.cusb4064.h即可。 删除原来的usb4064.c

再次测试:

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
[    0.000000] Booting Linux on physical CPU 0xa00
[    0.000000] Linux version 4.12.0-ga37d87e-dirty (root@ubuntu) (gcc version 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496] (GNU Tools for ARM Embedded Processors) ) #111 SMP PREEMPT Thu Jul 27 21:36:42 CST 2017
[    0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: FriendlyARM TINY4412 board based on Exynos4412
[    0.000000] bootconsole [earlycon0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 96 MiB at 0x7a000000
[    0.000000] Samsung CPU ID: 0xe4412011
[    0.000000] percpu: Embedded 16 pages/cpu @ef78f000 s34968 r8192 d22376 u65536
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 260608
[    0.000000] Kernel command line: initrd=0x42000040,0x800000 root=/dev/ram0 rw rootfstype=ext2 console=ttySAC0,115200 init=/linuxrc earlyprintk
[    0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[    0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Memory: 919504K/1048576K available (7168K kernel code, 324K rwdata, 2364K rodata, 1024K init, 326K bss, 30768K reserved, 98304K cma-reserved, 163840K highmem)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xf0800000 - 0xff800000   ( 240 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xf0000000   ( 768 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0xc0008000 - 0xc0800000   (8160 kB)
[    0.000000]       .init : 0xc0b00000 - 0xc0c00000   (1024 kB)
[    0.000000]       .data : 0xc0c00000 - 0xc0c51268   ( 325 kB)
[    0.000000]        .bss : 0xc0c58fc4 - 0xc0caa920   ( 327 kB)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Preemptible hierarchical RCU implementation.
[    0.000000]  RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
[    0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS:16 nr_irqs:16 16
[    0.000000] L2C: platform modifies aux control register: 0x02070000 -> 0x3e470001
[    0.000000] L2C: platform provided aux values permit register corruption.
[    0.000000] L2C: DT/platform modifies aux control register: 0x02070000 -> 0x3e470001
[    0.000000] L2C-310 enabling early BRESP for Cortex-A9
[    0.000000] L2C-310: enabling full line of zeros but not enabled in Cortex-A9
[    0.000000] L2C-310 dynamic clock gating enabled, standby mode enabled
[    0.000000] L2C-310 cache controller enabled, 16 ways, 1024 kB
[    0.000000] L2C-310: CACHE_ID 0x4100c4c8, AUX_CTRL 0x4e470001
[    0.000000] Exynos4x12 clocks: sclk_apll = 700000000, sclk_mpll = 800000000
[    0.000000]  sclk_epll = 96035156, sclk_vpll = 108035156, arm_clk = 1400000000
[    0.000000] Switching to timer-based delay loop, resolution 41ns
[    0.000000] clocksource: mct-frc: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[    0.000003] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
[    0.008065] Console: colour dummy device 80x30
[    0.012419] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000)
[    0.022834] pid_max: default: 32768 minimum: 301
[    0.027577] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.034198] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.041621] CPU: Testing write buffer coherency: ok
[    0.046602] CPU0: thread -1, cpu 0, socket 10, mpidr 80000a00
[    0.084751] Setting up static identity map for 0x40100000 - 0x40100060
[    0.144728] smp: Bringing up secondary CPUs ...
[    0.204799] CPU1: thread -1, cpu 1, socket 10, mpidr 80000a01
[    0.284779] CPU2: thread -1, cpu 2, socket 10, mpidr 80000a02
[    0.364781] CPU3: thread -1, cpu 3, socket 10, mpidr 80000a03
[    0.364827] smp: Brought up 1 node, 4 CPUs
[    0.386283] SMP: Total of 4 processors activated (192.00 BogoMIPS).
[    0.392611] CPU: All CPU(s) started in SVC mode.
[    0.397895] devtmpfs: initialized
[    0.407990] VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
[    0.415719] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.425473] futex hash table entries: 1024 (order: 4, 65536 bytes)
[    0.434612] pinctrl core: initialized pinctrl subsystem
[    0.440278] /lcd0-power-domain@10023C80 has as child subdomain: /tv-power-domain@10023C20.
[    0.449056] NET: Registered protocol family 16
[    0.454819] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.462634] cpuidle: using governor menu
[    0.486076] SCSI subsystem initialized
[    0.489869] usbcore: registered new interface driver usbfs
[    0.495340] usbcore: registered new interface driver hub
[    0.500713] usbcore: registered new device driver usb
[    0.506342] Advanced Linux Sound Architecture Driver Initialized.
[    0.513054] clocksource: Switched to clocksource mct-frc
[    0.525375] missing cooling_device property
[    0.529461] failed to build thermal zone cpu-thermal: -2
[    0.534916] NET: Registered protocol family 2
[    0.539609] TCP established hash table entries: 8192 (order: 3, 32768 bytes)
[    0.546628] TCP bind hash table entries: 8192 (order: 5, 163840 bytes)
[    0.553282] TCP: Hash tables configured (established 8192 bind 8192)
[    0.559668] UDP hash table entries: 512 (order: 2, 24576 bytes)
[    0.565612] UDP-Lite hash table entries: 512 (order: 2, 24576 bytes)
[    0.572109] NET: Registered protocol family 1
[    0.576691] RPC: Registered named UNIX socket transport module.
[    0.582512] RPC: Registered udp transport module.
[    0.587304] RPC: Registered tcp transport module.
[    0.592060] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.598710] Trying to unpack rootfs image as initramfs...
[    0.604401] rootfs image is not initramfs (no cpio magic); looks like an initrd
[    0.638266] Freeing initrd memory: 8196K
[    0.642881] audit: initializing netlink subsys (disabled)
[    0.648400] audit: type=2000 audit(0.645:1): state=initialized audit_enabled=0 res=1
[    0.648494] workingset: timestamp_bits=30 max_order=18 bucket_order=0
[    0.653295] NFS: Registering the id_resolver key type
[    0.653310] Key type id_resolver registered
[    0.653312] Key type id_legacy registered
[    0.653334] romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
[    0.656511] bounce: pool size: 64 pages
[    0.656540] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 248)
[    0.656544] io scheduler noop registered
[    0.656547] io scheduler deadline registered
[    0.656562] io scheduler cfq registered (default)
[    0.656565] io scheduler mq-deadline registered
[    0.656568] io scheduler kyber registered
[    0.663511] samsung-usb2-phy 125b0000.exynos-usbphy: 125b0000.exynos-usbphy supply vbus not found, using dummy regulator
[    0.667317] dma-pl330 12680000.pdma: Loaded driver for PL330 DMAC-141330
[    0.667323] dma-pl330 12680000.pdma:         DBUFF-32x4bytes Num_Chans-8 Num_Peri-32 Num_Events-32
[    0.669218] dma-pl330 12690000.pdma: Loaded driver for PL330 DMAC-141330
[    0.669223] dma-pl330 12690000.pdma:         DBUFF-32x4bytes Num_Chans-8 Num_Peri-32 Num_Events-32
[    0.669967] dma-pl330 12850000.mdma: Loaded driver for PL330 DMAC-141330
[    0.66997] dma-pl330 12850000.mdma:  DBUFF-64x8bytes Num_Chans-8 Num_Peri-1 Num_Events-32
[    0.762165] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.763391] 13800000.serial: ttySAC0 at MMIO 0x13800000 (irq = 47, base_baud = 0) is a S3C6400/10
[    0.785864] console [ttySAC0] enabled
[    0.785864] console [ttySAC0] enabled
[    0.793211] bootconsole [earlycon0] disabled
[    0.793211] bootconsole [earlycon0] disabled
[    0.802037] 13810000.serial: ttySAC1 at MMIO 0x13810000 (irq = 48, base_baud = 0) is a S3C6400/10
[    0.802329] 13820000.serial: ttySAC2 at MMIO 0x13820000 (irq = 49, base_baud = 0) is a S3C6400/10
[    0.802624] 13830000.serial: ttySAC3 at MMIO 0x13830000 (irq = 50, base_baud = 0) is a S3C6400/10
[    0.815688] brd: module loaded
[    0.821021] loop: module loaded
[    0.821827] libphy: Fixed MDIO Bus: probed
[    0.822076] usbcore: registered new interface driver cdc_ether
[    0.822378] usbcore: registered new interface driver dm9601
[    0.827979] usbcore: registered new interface driver net1080
[    0.833619] usbcore: registered new interface driver cdc_subset
[    0.839478] usbcore: registered new interface driver zaurus
[    0.845066] usbcore: registered new interface driver cdc_ncm
[    0.850913] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.857203] ehci-exynos: EHCI EXYNOS driver
[    0.861924] exynos-ehci 12580000.ehci: EHCI Host Controller
[    0.866926] exynos-ehci 12580000.ehci: new USB bus registered, assigned bus number 1
[    0.874837] exynos-ehci 12580000.ehci: irq 45, io mem 0x12580000
[    0.903084] exynos-ehci 12580000.ehci: USB 2.0 started, EHCI 1.00
[    0.903291] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    0.903361] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.903432] usb usb1: Product: EHCI Host Controller
[    0.905696] usb usb1: Manufacturer: Linux 4.12.0-ga37d87e-dirty ehci_hcd
[    0.912379] usb usb1: SerialNumber: 12580000.ehci
[    0.917458] hub 1-0:1.0: USB hub found
[    0.920816] hub 1-0:1.0: 3 ports detected
[    0.925326] usbcore: registered new interface driver usb-storage
[    0.941005] USB4604 usb-hub: switched to HUB mode
[    0.941055] USB4604 usb-hub: USB4604_probe: probed in hub mode
[    0.941860] s3c-rtc 10070000.rtc: failed to find rtc source clock
[    0.947414] s3c-rtc: probe of 10070000.rtc failed with error -2
[    0.953440] i2c /dev entries driver
[    0.958496] s3c2410-wdt 10060000.watchdog: watchdog inactive, reset disabled, irq disabled
[    0.965420] device-mapper: ioctl: 4.35.0-ioctl (2016-06-23) initialised: [email protected]
[    0.974892] sdhci: Secure Digital Host Controller Interface driver
[    0.979561] sdhci: Copyright(c) Pierre Ossman
[    0.984180] s3c-sdhci 12530000.sdhci: clock source 2: mmc_busclk.2 (20000000 Hz)
[    1.043096] mmc0: SDHCI controller on samsung-hsmmc [12530000.sdhci] using ADMA
[    1.043283] Synopsys Designware Multimedia Card Interface Driver
[    1.047026] dwmmc_exynos 12550000.mmc: IDMAC supports 32-bit address mode.
[    1.047139] dwmmc_exynos 12550000.mmc: Using internal DMA controller.
[    1.047390] dwmmc_exynos 12550000.mmc: Version ID is 240a
[    1.052785] dwmmc_exynos 12550000.mmc: DW MMC controller at irq 98,32 bit host data width,128 deep fifo
[    1.062253] mmc_host mmc1: card is polling.
[    1.093098] mmc_host mmc1: Bus speed (slot 0) = 50000000Hz (slot req 400000Hz, actual 396825HZ div = 63)
[    1.101909] mmc0: new high speed SDHC card at address 0007
[    1.102261] mmcblk0: mmc0:0007 SD16G 14.5 GiB 
[    1.123117] dwmmc_exynos 12550000.mmc: 1 slots initialized
[    1.124481] s5p-secss 10830000.sss: s5p-sss driver registered
[    1.124909] usbcore: registered new interface driver usbhid
[    1.124965] usbhid: USB HID core driver
[    1.127540] NET: Registered protocol family 10
[    1.131226] Segment Routing with IPv6
[    1.131302] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    1.135866] NET: Registered protocol family 17
[    1.139829] NET: Registered protocol family 15
[    1.144370] Key type dns_resolver registered
[    1.148662] Registering SWP/SWPB emulation handler
[    1.167628] hctosys: unable to open rtc device (rtc0)
[    1.168291] ALSA device list:
[    1.168325]   No soundcards found.
[    1.168891] RAMDISK: gzip image found at block 0
[    1.197817] mmc_host mmc1: Bus speed (slot 0) = 50000000Hz (slot req 52000000Hz, actual 50000000HZ div = 0)
[    1.198198] mmc1: new DDR MMC card at address 0001
[    1.198826] mmcblk1: mmc1:0001 4YMD3R 3.63 GiB 
[    1.199092] mmcblk1boot0: mmc1:0001 4YMD3R partition 1 4.00 MiB
[    1.200665] mmcblk1boot1: mmc1:0001 4YMD3R partition 2 4.00 MiB
[    1.206700] mmcblk1rpmb: mmc1:0001 4YMD3R partition 3 512 KiB
[    1.213022]  mmcblk1: p1 p2 p3 p4
[    1.283149] usb 1-2: new high-speed USB device number 2 using exynos-ehci
[    1.323765] VFS: Mounted root (ext2 filesystem) on device 1:0.
[    1.323958] devtmpfs: mounted
[    1.325101] Freeing unused kernel memory: 1024K

Processing /etc/profile... Done

[root@TINY4412:/]# [    1.473765] usb 1-2: New USB device found, idVendor=0424, idProduct=4604
[    1.473841] usb 1-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    1.474527] hub 1-2:1.0: USB hub found
[    1.474631] hub 1-2:1.0: 5 ports detected
[    1.793220] usb 1-2.4: new high-speed USB device number 3 using exynos-ehci
[    1.944001] usb 1-2.4: config 1 interface 0 altsetting 0 endpoint 0x83 has an invalid bInterval 0, changing to 7
[    2.133264] usb 1-2.5: new high-speed USB device number 4 using exynos-ehci
[    2.284321] usb 1-2.5: New USB device found, idVendor=0424, idProduct=2530
[    2.284440] usb 1-2.5: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[    2.284554] usb 1-2.5: Product: Bridge device

插上U盘

[ 1484.693225] usb 1-2.3: new high-speed USB device number 5 using exynos-ehci
[ 1484.847975] usb 1-2.3: New USB device found, idVendor=0930, idProduct=6544
[ 1484.848124] usb 1-2.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1484.848263] usb 1-2.3: Product: TransMemory     
[ 1484.848366] usb 1-2.3: Manufacturer: TOSHIBA 
[ 1484.848808] usb 1-2.3: SerialNumber: 3AC4C59887B0CE11F96D5759
[ 1484.856862] usb-storage 1-2.3:1.0: USB Mass Storage device detected
[ 1484.862138] scsi host0: usb-storage 1-2.3:1.0
[ 1485.933432] scsi 0:0:0:0: Direct-Access     TOSHIBA  TransMemory      1.00 PQ: 0 ANSI: 4
[ 1485.936627] sd 0:0:0:0: [sda] 15155200 512-byte logical blocks: (7.76 GB/7.23 GiB)
[ 1485.936943] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 1485.937878] sd 0:0:0:0: [sda] Write Protect is off
[ 1485.939168] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 1485.953446]  sda: sda1
[ 1485.958706] sd 0:0:0:0: [sda] Attached SCSI removable disk

可以正常识别了!

[root@TINY4412:/]# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 7.7M      2.0M      5.7M  26% /
devtmpfs                449.0M         0    449.0M   0% /dev
[root@TINY4412:/]# mkdir /mnt/usb
[root@TINY4412:/]# mount /dev/sda1 /mnt/usb/
[ 1515.592924] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[root@TINY4412:/]# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 7.7M      2.0M      5.7M  26% /
devtmpfs                449.0M         0    449.0M   0% /dev
/dev/sda1                 7.4G     16.0K      7.4G   0% /mnt/usb

挂载U盘正常。

你可能感兴趣的:(TINY4412,LINUX)