RK3588 在uboot 和kernel下对GPIO的配置

        由于项目的原因在kernel初始化GPIO已不能满足需求,所以在uboot 时就必须初始化好GPIO,本想着uboot 跟kernel一样dts中直接配置就完成了,结果却不行,大概看了下uboot 下的pinctrl源码发现只对bank,pin,mux,conf 有进行解析,没看到对direction 和value有解析。因此我在uboot 配置GPIO时采用了代码和dts的组合。如有可以直接使用dts 完成的请留言告诉。

一、查找GPIO的寄存器地址

        为什么首先要查找寄存器地址呢,因为我们必须对我们修改进行确认,通过寄存器的地址我们能明确知道我们的修改是否成功。

        GPIO复用

GPIO功能

二、在dts中配置GPIO的复用和上,下拉。

gpio_func_init: gpio_func_init{

        u-boot,dm-pre-reloc;

        compatible = "regulator-fixed";

        pinctrl-names = "default";

        pinctrl-0 = <&init_gpio_func>;

        status = "okay";

        regulator-always-on;

};

&pinctrl{

        gpio_func_pins{

                init_gpio_func:init-gpio-func{

                        u-boot,dm-spl;

                        rockchip,pins=

                        <3, RK_PA3 0  &pcfg_pull_up>

                        <2, RK_PA3 0  &pcfg_pull_up>

                };

        };

};

三、在代码中实现相应管脚的输入,输出及电平的配置

#define FUNC_GPIO_BANK0    0
#define FUNC_GPIO_BANK1    32
#define FUNC_GPIO_BANK2    64
#define FUNC_GPIO_BANK3    96
#define FUNC_GPIO_BANK4    128
#define FUNC_PA0           0
#define FUNC_PA1           1
#define FUNC_PA2           2
#define FUNC_PA3           3
#define FUNC_PA4           4
#define FUNC_PA5           5
#define FUNC_PA6           6
#define FUNC_PA7           7
#define FUNC_PB0           8
#define FUNC_PB1           9
#define FUNC_PB2           10
#define FUNC_PB3           11
#define FUNC_PB4           12
#define FUNC_PB5           13
#define FUNC_PB6           14
#define FUNC_PB7           15
#define FUNC_PC0           16
#define FUNC_PC1           17
#define FUNC_PC2           18
#define FUNC_PC3           19
#define FUNC_PC4           20
#define FUNC_PC5           21
#define FUNC_PC6           22
#define FUNC_PC7           23
#define FUNC_PD0           24
#define FUNC_PD1           25
#define FUNC_PD2           26
#define FUNC_PD3           27
#define FUNC_PD4           28
#define FUNC_PD5           29
#define FUNC_PD6           30
#define FUNC_PD7           31

static void func_gpio_init(void)
{
    gpio_request(FUNC_GPIO_BANK2|FUNC_PA3,"FUNC_GPIO2_PA3");
    gpio_direction_output(FUNC_GPIO_BANK2|FUNC_PA3,0);

    gpio_request(FUNC_GPIO_BANK3|FUNC_PA3,"FUNC_GPIO3_PA3");
    gpio_direction_output(FUNC_GPIO_BANK3|FUNC_PA3,0);
}

猜你喜欢

转载自blog.csdn.net/dreamliweiming/article/details/134703414