【TINY4412】U-BOOT移植笔记:(14)USB-OTG驱动

【TINY4412】U-BOOT移植笔记:(14)USB-OTG驱动

宿主机 : 虚拟机 Ubuntu 16.04 LTS / X64
目标板[底板]: Tiny4412SDK - 1506
目标板[核心板]: Tiny4412 - 1412
U-BOOT版本: 2017.03
交叉编译器: gcc-arm-none-eabi-5_4-2016q3
日期: 2017-6-11 19:41:44
作者: SY

简介

  • 一般的USB设备必须固定为主机或者从机,比如说:电脑端USB都是作为主机使用,外部可以插键盘、鼠标进行通信。而像U盘的USB接口只能作为从机,使用时被动接收主机的命令并回复数据包。

  • 而USB OTG(Universal Serial Bus On-The-Go)即可以像电脑一样外接U盘等设备,也可以向U盘一样连接电脑自身作为存储设备。

    这里写图片描述

  • 对于标准的USB接口,只需要连接4根线,VCC、GND、D+、D-,信号线为了提高抗干扰能力,使用差分信号传输。而USB OTG接口多了一根ID引脚。

ID电平功能
高电平(默认)从机
低电平主机

移植

    root@ubuntu:/opt/u-boot-2017.03# git diff 6c81ce da9faf

    diff --git a/board/samsung/tiny4412/tiny4412.c b/board/samsung/tiny4412/tiny4412.c
    index 99a2fac..27550bb 100644
    --- a/board/samsung/tiny4412/tiny4412.c
    +++ b/board/samsung/tiny4412/tiny4412.c
    @@ -3,15 +3,22 @@
      *
      * SPDX-License-Identifier:    GPL-2.0+
      */
    -
     #include <common.h>
    -#include <asm/io.h>
    +#include <asm/arch/pinmux.h>
    +#include <asm/arch/power.h>
    +#include <asm/arch/clock.h>
    +#include <asm/arch/gpio.h>
     #include <asm/gpio.h>
     #include <asm/arch/cpu.h>
    -#include <asm/arch/mmc.h>
    -#include <asm/arch/periph.h>
    -#include <asm/arch/pinmux.h>
    +#include <dm.h>
    +#include <power/pmic.h>
    +#include <power/regulator.h>
    +#include <power/max77686_pmic.h>
    +#include <errno.h>
    +#include <mmc.h>
     #include <usb.h>
    +#include <usb/dwc2_udc.h>
    +#include <samsung/misc.h>

     DECLARE_GLOBAL_DATA_PTR;

    @@ -20,14 +27,38 @@ u32 get_board_rev(void)
            return 0;
     }

    +static void board_gpio_init(void)
    +{
    +       ;
    +}
    +
     int exynos_init(void)
     {
    +       board_gpio_init();
    +
    +       return 0;
    +}
    +
    +#ifdef CONFIG_USB_GADGET
    +static int s5pc210_phy_control(int on)
    +{
            return 0;
     }

    +struct dwc2_plat_otg_data s5pc210_otg_data = {
    +       .phy_control    = s5pc210_phy_control,
    +       .regs_phy       = EXYNOS4X12_USBPHY_BASE,
    +       .regs_otg       = EXYNOS4X12_USBOTG_BASE,
    +       .usb_phy_ctrl   = EXYNOS4X12_USBPHY_CONTROL,
    +       .usb_flags      = PHY0_SLEEP,
    +};
    +#endif
    +
     int board_usb_init(int index, enum usb_init_type init)
     {
    -       return 0;
    +       debug("USB_udc_probe\n");
    +       
    +       return dwc2_udc_probe(&s5pc210_otg_data);
     }

     #ifdef CONFIG_BOARD_EARLY_INIT_F
    diff --git a/tiny4412_config b/tiny4412_config
    index 347effb..aadf9b6 100644
    --- a/tiny4412_config
    +++ b/tiny4412_config
    @@ -320,7 +320,17 @@ CONFIG_AUTOBOOT=y
     #
     # FASTBOOT
     #
    -# CONFIG_FASTBOOT is not set
    +CONFIG_FASTBOOT=y
    +CONFIG_USB_FUNCTION_FASTBOOT=y
    +CONFIG_CMD_FASTBOOT=y
    +# CONFIG_ANDROID_BOOT_IMAGE is not set
    +CONFIG_FASTBOOT_BUF_ADDR=0x70000000
    +CONFIG_FASTBOOT_BUF_SIZE=0x100000
    +CONFIG_FASTBOOT_USB_DEV=0
    +CONFIG_FASTBOOT_FLASH=y
    +CONFIG_FASTBOOT_FLASH_MMC_DEV=0
    +CONFIG_FASTBOOT_GPT_NAME="gpt"
    +CONFIG_FASTBOOT_MBR_NAME="mbr"

     #
     # Commands
    @@ -394,7 +404,7 @@ CONFIG_CMD_PART=y
     # CONFIG_CMD_I2C is not set
     CONFIG_CMD_USB=y
     CONFIG_CMD_DFU=y
    -# CONFIG_CMD_USB_MASS_STORAGE is not set
    +CONFIG_CMD_USB_MASS_STORAGE=y
     # CONFIG_CMD_FPGA is not set
     # CONFIG_CMD_GPIO is not set
     CONFIG_CMD_BEEP=y
    @@ -843,7 +853,10 @@ CONFIG_USB_EHCI_GENERIC=y
     # USB peripherals
     #
     CONFIG_USB_STORAGE=y
    -# CONFIG_USB_KEYBOARD is not set
    +CONFIG_USB_KEYBOARD=y
    +# CONFIG_SYS_USB_EVENT_POLL is not set
    +# CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE is not set
    +CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP=y
     CONFIG_USB_GADGET=y
     # CONFIG_USB_GADGET_ATMEL_USBA is not set
     # CONFIG_USB_GADGET_BCM_UDC_OTG_PHY is not set
    @@ -853,9 +866,9 @@ CONFIG_USB_GADGET_DWC2_OTG=y
     CONFIG_USB_GADGET_VBUS_DRAW=2
     CONFIG_USB_GADGET_DUALSPEED=y
     CONFIG_USB_GADGET_DOWNLOAD=y
    -CONFIG_G_DNL_MANUFACTURER="samsung"
    -CONFIG_G_DNL_VENDOR_NUM=0x04E8
    -CONFIG_G_DNL_PRODUCT_NUM=0x685D
    +CONFIG_G_DNL_MANUFACTURER="Freescale"
    +CONFIG_G_DNL_VENDOR_NUM=0x18d1
    +CONFIG_G_DNL_PRODUCT_NUM=0x4e30
     CONFIG_USBNET_DEVADDR="de:ad:be:ef:00:01"

     #
    (END)
  • 函数 dwc2_udc_probe(&s5pc210_otg_data); 贯穿整个 usb otg

  • 参考 u-boot/doc/README.android-fastboot ,需要设置:

CONFIG_USBDOWNLOAD_GADGET
CONFIG_G_DNL_VENDOR_NUM
CONFIG_G_DNL_PRODUCT_NUM
CONFIG_G_DNL_MANUFACTURER
NOTE: The CONFIG_G_DNL_VENDOR_NUM must be one of the numbers supported by
the fastboot client. The list of vendor IDs supported can be found in the
fastboot client source code (fastboot.c) mentioned above.
  • CONFIG_G_DNL_VENDOR_NUM不能随便设置,需要在电脑端的fastboot.c列表中查找匹配的ID
/* Keep the list below sorted alphabetically by #define name */
// Acer's USB Vendor ID
#define VENDOR_ID_ACER          0x0502
// Allwinner's USB Vendor ID
#define VENDOR_ID_ALLWINNER     0x1F3A
// Amlogic's USB Vendor ID
#define VENDOR_ID_AMLOGIC       0x1b8e
// AnyDATA's USB Vendor ID
#define VENDOR_ID_ANYDATA       0x16D5
// Archos's USB Vendor ID
#define VENDOR_ID_ARCHOS        0x0E79
// Asus's USB Vendor ID
#define VENDOR_ID_ASUS          0x0b05
// BYD's USB Vendor ID
#define VENDOR_ID_BYD           0x1D91
// Compal's USB Vendor ID
#define VENDOR_ID_COMPAL        0x04B7
// Compalcomm's USB Vendor ID
#define VENDOR_ID_COMPALCOMM    0x1219
// Dell's USB Vendor ID
#define VENDOR_ID_DELL          0x413c
// ECS's USB Vendor ID
#define VENDOR_ID_ECS           0x03fc
// EMERGING_TECH's USB Vendor ID
#define VENDOR_ID_EMERGING_TECH 0x297F
// Emerson's USB Vendor ID
#define VENDOR_ID_EMERSON       0x2207
// Foxconn's USB Vendor ID
#define VENDOR_ID_FOXCONN       0x0489
// Fujitsu's USB Vendor ID
#define VENDOR_ID_FUJITSU       0x04C5
// Funai's USB Vendor ID
#define VENDOR_ID_FUNAI         0x0F1C
// Garmin-Asus's USB Vendor ID
#define VENDOR_ID_GARMIN_ASUS   0x091E
// Gigabyte's USB Vendor ID
#define VENDOR_ID_GIGABYTE      0x0414
// Gigaset's USB Vendor ID
#define VENDOR_ID_GIGASET       0x1E85
// GIONEE's USB Vendor ID
#define VENDOR_ID_GIONEE        0x271D
// Google's USB Vendor ID
#define VENDOR_ID_GOOGLE        0x18d1
// Haier's USB Vendor ID
#define VENDOR_ID_HAIER         0x201E
// Harris's USB Vendor ID
#define VENDOR_ID_HARRIS        0x19A5
// Hisense's USB Vendor ID
#define VENDOR_ID_HISENSE       0x109b
// Honeywell's USB Vendor ID
#define VENDOR_ID_HONEYWELL     0x0c2e
// HP's USB Vendor ID
#define VENDOR_ID_HP            0x03f0
// HTC's USB Vendor ID
#define VENDOR_ID_HTC           0x0bb4
// Huawei's USB Vendor ID
#define VENDOR_ID_HUAWEI        0x12D1
// INQ Mobile's USB Vendor ID
#define VENDOR_ID_INQ_MOBILE    0x2314
// Intel's USB Vendor ID
#define VENDOR_ID_INTEL         0x8087
// Intermec's USB Vendor ID
#define VENDOR_ID_INTERMEC      0x067e
// IRiver's USB Vendor ID
#define VENDOR_ID_IRIVER        0x2420
// K-Touch's USB Vendor ID
#define VENDOR_ID_K_TOUCH       0x24E3
// KT Tech's USB Vendor ID
#define VENDOR_ID_KT_TECH       0x2116
// Kobo's USB Vendor ID
#define VENDOR_ID_KOBO          0x2237
// Kyocera's USB Vendor ID
#define VENDOR_ID_KYOCERA       0x0482
// Lab126's USB Vendor ID
#define VENDOR_ID_LAB126        0x1949
// Lenovo's USB Vendor ID
#define VENDOR_ID_LENOVO        0x17EF
// LenovoMobile's USB Vendor ID
#define VENDOR_ID_LENOVOMOBILE  0x2006
// LG's USB Vendor ID
#define VENDOR_ID_LGE           0x1004
// Lumigon's USB Vendor ID
#define VENDOR_ID_LUMIGON       0x25E3
// Motorola's USB Vendor ID
#define VENDOR_ID_MOTOROLA      0x22b8
// MSI's USB Vendor ID
#define VENDOR_ID_MSI           0x0DB0
// MTK's USB Vendor ID
#define VENDOR_ID_MTK           0x0e8d
// NEC's USB Vendor ID
#define VENDOR_ID_NEC           0x0409
// B&N Nook's USB Vendor ID
#define VENDOR_ID_NOOK          0x2080
// Nvidia's USB Vendor ID
#define VENDOR_ID_NVIDIA        0x0955
// OPPO's USB Vendor ID
#define VENDOR_ID_OPPO          0x22D9
// On-The-Go-Video's USB Vendor ID
#define VENDOR_ID_OTGV          0x2257
// OUYA's USB Vendor ID
#define VENDOR_ID_OUYA          0x2836
// Pantech's USB Vendor ID
#define VENDOR_ID_PANTECH       0x10A9
// Pegatron's USB Vendor ID
#define VENDOR_ID_PEGATRON      0x1D4D
// Philips's USB Vendor ID
#define VENDOR_ID_PHILIPS       0x0471
// Panasonic Mobile Communication's USB Vendor ID
#define VENDOR_ID_PMC           0x04DA
// Positivo's USB Vendor ID
#define VENDOR_ID_POSITIVO      0x1662
// Prestigio's USB Vendor ID
#define VENDOR_ID_PRESTIGIO     0x29e4
// Qisda's USB Vendor ID
#define VENDOR_ID_QISDA         0x1D45
// Qualcomm's USB Vendor ID
#define VENDOR_ID_QUALCOMM      0x05c6
// Quanta's USB Vendor ID
#define VENDOR_ID_QUANTA        0x0408
// Rockchip's USB Vendor ID
#define VENDOR_ID_ROCKCHIP      0x2207
// Samsung's USB Vendor ID
#define VENDOR_ID_SAMSUNG       0x04e8
// Sharp's USB Vendor ID
#define VENDOR_ID_SHARP         0x04dd
// SK Telesys's USB Vendor ID
#define VENDOR_ID_SK_TELESYS    0x1F53
// Smartisan's USB Vendor ID
#define VENDOR_ID_SMARTISAN     0x29a9
// Sony's USB Vendor ID
#define VENDOR_ID_SONY          0x054C
// Sony Ericsson's USB Vendor ID
#define VENDOR_ID_SONY_ERICSSON 0x0FCE
// T & A Mobile Phones' USB Vendor ID
#define VENDOR_ID_T_AND_A       0x1BBB
// TechFaith's USB Vendor ID
#define VENDOR_ID_TECHFAITH     0x1d09
// Teleepoch's USB Vendor ID
#define VENDOR_ID_TELEEPOCH     0x2340
// Texas Instruments's USB Vendor ID
#define VENDOR_ID_TI            0x0451
// Toshiba's USB Vendor ID
#define VENDOR_ID_TOSHIBA       0x0930
// Unowhy's USB Vendor ID
#define VENDOR_ID_UNOWHY        0x2A49
// Vizio's USB Vendor ID
#define VENDOR_ID_VIZIO         0xE040
// Wacom's USB Vendor ID
#define VENDOR_ID_WACOM         0x0531
// Xiaomi's USB Vendor ID
#define VENDOR_ID_XIAOMI        0x2717
// YotaDevices's USB Vendor ID
#define VENDOR_ID_YOTADEVICES   0x2916
// Yulong Coolpad's USB Vendor ID
#define VENDOR_ID_YULONG_COOLPAD 0x1EBF
// ZTE's USB Vendor ID
#define VENDOR_ID_ZTE           0x19D2
/* Keep the list above sorted alphabetically by #define name */

测试

    >> Tiny4412端:

    U-Boot 2017.03-gda9faf9 (Jun 11 2017 - 19:49:20 +0800) for TINY4412



    CPU:   Exynos4412 @ 1.4 GHz

    Model: Tiny4412 based on Exynos4412

    Board: Tiny4412 based on Exynos4412

    DRAM:  1 GiB

    WARNING: Caches not enabled

    MMC:   SAMSUNG SDHCI: 0, EXYNOS DWMMC: 1

    Hit any key to stop autoboot:  0 

    SD/MMC found on device 0

    ** Invalid partition 1 **

    ** Invalid partition 1 **

    ** Invalid partition 1 **

    Wrong Image Format for bootm command

    ERROR: can't get kernel image!

    TINY4412 # fastboot 0

    USB PHY0 Enable

    crq->brequest:0x0

>> 电脑端Linux:
    root@ubuntu:/opt/u-boot-2017.03# fastboot getvar bootloader-version
    bootloader-version: U-Boot 2017.03-gda9faf9
    finished. total time: 0.000s
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值