原文連結:https://blog.csdn.net/Jason_416/article/details/103691302
作者:Jason416
CSDN博客: Jason416就是我
前言
根據前面文章USB和Ethernet協議了解與原理圖分析、DM_USB和DM_ETH模型簡介所介紹,想必大家已經知道移植的流程應該是如何了,這裡再簡單的給出大致步驟,如下。
移植USB Host Controller驅動使能USB3503 Hub移植DM9621驅動測試驗證功能性
接下來就按照這幾個步驟進行Uboot中DM9621網卡的移植之路,最終實現在Uboot中使用網絡命令進行內核的加載等操作。
移植開始
移植USB Host Controller驅動
該部分驅動已經有三星官方提供到Uboot主線中,我們下載的源碼包裡面已經有對應的代碼,drivers/usb/host/ehci-exynos.c文件包含了其實現。我們要做的只是將其編譯選項打開,編譯進Uboot最終bin文件中即可,下面給出詳細的步驟。
打開編譯選項
Kconfig中打開主機驅動宏,對應路徑如下
為Device Drivers ---> [*] USB support ---> 見下圖
打開Exynos4412對應的宏CONFIG_USB_EHCI_EXYNOS
diff --git a/include/configs/itop4412.h b/include/configs/itop4412.hindex c071e02..5bd5fdc 100644@@ -35,6 +35,9 @@ /* #define MACH_TYPE_ITOP4412 0xffffffff */ #define CONFIG_MACH_TYPE MACH_TYPE_ITOP4412 +/* USB */+#define CONFIG_USB_EHCI_EXYNOS+ /* select serial console configuration */ #define CONFIG_SERIAL2Command line interface ---> Device access commands ---> [*] usb
設備樹修改
加入ehci設備描述信息,如下:
45 ehci@12580000 { 46 compatible = "samsung,exynos-ehci"; 47 reg = <0x12580000 0x100>; 48 #address-cells = <1>; 49 #size-cells = <1>; 50 status = "okay"; 51 /* In order to reset USB ethernet, DM9621 RESET IO pin */ 52 samsung,vbus-gpio = <&gpc0 1 0>; 53 phy { 54 compatible = "samsung,exynos-usb-phy"; 55 reg = <0x125B0000 0x100>; 56 }; 57 };編譯與調試
在上述操作編譯完成後,就能使用USB主機控制器了,在終端鍵入USB start便可以看到有相應的USB信息輸出,接下來便可以進行USB 3503的配置與使能。
使能USB3503 Hub
配置GPIO
根據前面文章USB和Ethernet協議了解與原理圖分析的分析,USB 3503 Hub晶片配置簡單,只需要做些IO操作便可。通過地板原理圖核心板原理圖查找分析,需要操作GPM3_3 (USB3503_CONNECT)和GPM2_4 (USB3503_RESET)。這裡使用Uboot的IO驅動模型,而不是直接寫寄存器,通過對應的宏和標準GPIO接口調用,便可以完成對USB Hub晶片的初始化,下面給出代碼。
diff --git a/board/samsung/itop4412/itop4412.c b/board/samsung/itop4412/itop4412.cindex 99a2fac..3068cd4 100644@@ -12,6 +12,14 @@ #include <asm/arch/periph.h> #include <asm/arch/pinmux.h> #include <usb.h>+#include <usb/dwc2_udc.h>++#define DEBUG+#ifdef DEBUG+#undef debug+#define debug(fmt, args...) debug_cond(true, fmt, ##args)+#endif DECLARE_GLOBAL_DATA_PTR; @@ -20,15 +28,82 @@ u32 get_board_rev(void) return 0; } +static void board_gpio_init(void)+{+#ifdef CONFIG_CMD_USB+ /* USB3503A Connect */+ gpio_request(EXYNOS4X12_GPIO_M33, "USB3503A Connect");++ /* USB3503A Reset */+ gpio_request(EXYNOS4X12_GPIO_M24, "USB3503A Reset");++ /* Red LED2 Light On */+ gpio_request(EXYNOS4X12_GPIO_L20, "Red LED2");+ gpio_direction_output(EXYNOS4X12_GPIO_L20, 1);+#endif+}+ int exynos_init(void) {+ debug("---> ready to call board_gpio_init()!\n");+ board_gpio_init();++ /* FIXME: maybe should be not called in here */+ board_usb_init(0, USB_INIT_DEVICE);+ return 0; } +#ifdef CONFIG_USB_GADGET+static int s5pc210_phy_control(int on)+{+ /* FIXME: need to set power? */+#if 0+ struct udevice *dev;+ int ret;++ ret = regulator_get_by_platname("VDD_UOTG_3.0V", &dev);+ if (ret) {+ pr_err("Regulator get error: %d", ret);+ return ret;+ }++ if (on)+ return regulator_set_mode(dev, OPMODE_ON);+ else+ return regulator_set_mode(dev, OPMODE_LPM);+#else+ return 0;+#endif+}++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++#if defined(CONFIG_USB_GADGET) || defined(CONFIG_CMD_USB)+ int board_usb_init(int index, enum usb_init_type init) {- return 0;+#ifdef CONFIG_CMD_USB+ debug("---> ready to init usb3503\n");++ /* USB3503A Disconnect, Reset, Connect */+ gpio_direction_output(EXYNOS4X12_GPIO_M33, 0);+ gpio_direction_output(EXYNOS4X12_GPIO_M24, 0);+ gpio_direction_output(EXYNOS4X12_GPIO_M24, 1);+ gpio_direction_output(EXYNOS4X12_GPIO_M33, 1);++#endif+ debug("USB_udc_probe\n");+ return dwc2_udc_probe(&s5pc210_otg_data); }+#endif #ifdef CONFIG_BOARD_EARLY_INIT_F int exynos_early_init_f(void)編譯與調試
在執行完這步驟的時候,執行usb start; usb reset後,便會有下面的對應輸出,說明USB 3503已經在正常工作了,並且DM9621網卡已經使能了,接下來就是初始化並配置設備和適配到DM_ETH模型的操作了。
CPU: Exynos4412 @ 1 GHzModel: itop-4412 based on Exynos4412Board: itop-4412 based on Exynos4412DRAM: 1 GiBWARNING: Caches not enabled---> ready to call board_gpio_init()!---> ready to init usb3503USB_udc_probeMMC: SAMSUNG SDHCI: 0, EXYNOS DWMMC: 1Net: No ethernet found.Hit any key to stop autoboot: 0 u-boot # usb startstarting USB...USB0: USB EHCI 1.00scanning bus 0 for devices... 1 USB Device(s) foundu-boot # usb resetresetting USB...USB0: USB EHCI 1.00scanning bus 0 for devices... 3 USB Device(s) foundu-boot # usb treeUSB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA) | +-3 See Interface (480 Mb/s, 180mA)移植DM9621驅動
說明
在上面的步驟執行完,可以發現DM9621設備已經使能,能在USB總線上看到該設備了,接下來需要初始化和配置,並根據DM_ETH模型來提供相應的操作集便可。
————————————————
PS:作者為精英版八群交流群的技術高手,如需了解更多,請移步原文作者博客。