android usb otg轉換成host調試筆記

(原創作品,轉載請標明轉載路徑)

近日在mstar 786平臺上有個需求,即把usb otg轉換成host接U盤。

開始調試時,以為隻要把OTG的配置去掉,即CONFIG_USB_MS_OTG屏蔽掉即可,但編譯燒錄後,插入和撥出U盤時發現提示

android_work: did not send uevent (0 0 (null))

U盤的燈也不亮,說明沒有上電。

後來搜索瞭有關資料,才發現需要把USB_CID腳拉低,拉低表示工作在HOST模式下。

有2種方式拉低該引腳:

1)硬件上把它強制拉低。

2)軟件上拉低,在kernel目錄下的drivers\usb\otg\ms_otg.c 中的ms_otg_init_irq函數,把如下代碼屏蔽掉:

// OTG id pin pull-up
/* reg_t = readl(&msotg->op_regs->usbc_regs->port_ctrl);
reg_t |= IDPULLUP_CTRL;
writel(reg_t, &msotg->op_regs->usbc_regs->port_ctrl);*/

編譯燒錄後,開機插入U盤,有如下LOG,表示識別成功:

[ 1374.141871] hub_events

[ 1374.144655] hub_port_connect_change

[ 1374.303911] hub_port_init

[ 1374.306911] ==13==> hub_port_init 1
[ 1374.310873] Plug in USB Port1
[ 1374.503906] usb 3-1: new high speed USB device number 3 using Mstar-ehci-1
[ 1374.958064] usb-storage 3-1:1.0: Quirks match for vid 058f pid 6387: 20
[ 1374.965494] usb-storage 3-1:1.0: This device (058f,6387,010b S 06 P 50) has unneeded SubClass and Protocol entries in unusual_devs.h (kernel 3.4.5)
[ 1374.965505] Please send a copy of this message to and
[ 1374.992704] scsi1 : usb-storage 3-1:1.0
[ 1374.999392] hub_events

[ 1375.002158] hub_events

[ 1375.996046] scsi 1:0:0:0: Direct-Access Generic Flash Disk 8.07 PQ: 0 ANSI: 4
[ 1376.008295] sd 1:0:0:0: [sdb] 16293888 512-byte logical blocks: (8.34 GB/7.76 GiB)
[ 1376.017568] sd 1:0:0:0: [sdb] Write Protect is off
[ 1376.023685] sd 1:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn’t support DPO or FUA
[ 1376.038784] sdb: sdb1
[ 1376.046711] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[ 1376.054754] sd 1:0:0:0: Attached scsi generic sg0 type 0

識別成功後,在/dev/block/下會生成一個設備節點,有可能叫sda1

需要手動把它mount到mnt目錄後才可訪問:

mount -t vfat /dev/block/sda1 /mnt/sdcard

然後就可以在root權限下cd sdcard訪問該U盤內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *