uboot the IO port initialization

Due to achieve certain application functions when the product needs to be started in uboot, so the number of IO ports are initialized in uboot, the reference here to the use of dm-gpio.

1.dts increase in the definition of GPIO. (Arch / arm / dts / armada-3720-espressobin.dts)

first {
        compatible = "marvell,first";  //first随便取的一个名字
        reset-gpio = <&gpionb 14 GPIO_ACTIVE_LOW>;  //MPP1_14(北桥第14个gpio,从0开始)蜂鸣器
        wdi-gpio = <&gpiosb 1 GPIO_ACTIVE_LOW>;     //MPP2_1   看门狗
        enable-gpio = <&gpionb 9 GPIO_ACTIVE_LOW>;  //MPP1_9   WDI enable      
};

2. Get a GPIO driver from the node, increasing board_init () in. (Board / Marvell / mvebu_armada-37xx / board.c)

 int board_init(void)
 {
+        struct gpio_desc gpio = {};
+        struct gpio_desc wdi_gpio = {};
+        struct gpio_desc enable_gpio = {};
+        int node;
         /* adress of boot parameters */
         gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
 
         /* enable serdes lane 2 mux for sata phy */
         board_comphy_usb3_sata_mux(COMPHY_LANE2_MUX_SATA);

+        node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,"marvell,first");
+        if (node < 0)
+         {                            
+            printf("===========================Don't find marvell,first node\n");
+            return -1; 
+        }
+
+        gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio",0, &gpio,         
+        GPIOD_IS_OUT); /* 在驱动中调用gpio_request_by_name_nodev接口或者其他接口从dtsi节点 
+        中获取对应GPIO属性的gpio_desc描述符 */
+        gpio_request_by_name_nodev(offset_to_ofnode(node), "wdi-gpio",0, &wdi_gpio, 
+        GPIOD_IS_OUT);
+        gpio_request_by_name_nodev(offset_to_ofnode(node), "enable-gpio",0, 
+        &enable_gpio, GPIOD_IS_OUT);
         
         if (dm_gpio_is_valid(&gpio)) /*调用dm_gpio_is_valid判断该gpio_desc是否可用*/
+        {
+            dm_gpio_set_value(&gpio, 1);  /* MPP1_14置0,启动uboot时关闭蜂鸣器  */
+        }
+
+        if (dm_gpio_is_valid(&wdi_gpio))
+        {
+            dm_gpio_set_value(&wdi_gpio, 1);  /* gpio设置1是低电平,0是高电平 */
+        }
+
+        if (dm_gpio_is_valid(&enable_gpio))
+        {  
+            dm_gpio_set_value(&enable_gpio, 1);/*  默认输出低0,开门狗功能使能, 
+            开启开门狗功能后,此IO需置高1方可使能 */
+        }

         return 0;
 }

* Here we must note in menuconfig to be supported CONFIG_DM and CONFIG_DM_GPIO both options.

After compiling the programming device starts the like uboot found ineffective added GPIO port initialization, examination revealed board_init () is not running to the added board_init in common / board_r.c in.

    #ifdef CONFIG_PS2KBD
            initr_kbd,
    #endif
+           board_init,
            run_main_loop,

Recompile programming uboot, GPIO port initialization for normal applications.

Released six original articles · won praise 4 · Views 4387

Guess you like

Origin blog.csdn.net/qq_33205540/article/details/104674481