gpio_request_by_name_nodev(dev, node, “gpio”, 0, &gpio, GPIOD_IS_OUT);
// 调用gpio_request_by_name_nodev来获取node节点中的"lgpio"属性,并转化为gpio_desc描述符,标志为输出
GPIOD_IS_IN 输入
dm_gpio_set_value(&gpio, 0); // 将gpio设置输出低电平
dm_gpio_set_value(&gpio, 1); // 将gpio设置输出高电平
dm_gpio_is_valid //判断该gpio_desc是否可用
dm_gpio_request //申请gpio_desc描述的GPIO
dm_gpio_get_value //获取gpio_desc描述的GPIO的值
uboot启动驱动
static void owner_option(void)
{
struct udevice *dev2;
uclass_get_device_by_driver(UCLASS_MISC,
DM_GET_DRIVER(option), &dev2);
}
将函数添加board_init中
option.c
驱动
#include <common.h>
#include <dm.h>
#include <errno.h>
#include <asm-generic/gpio.h>
#include <dm/lists.h>
#include <misc.h>
#include <linux/bitops.h>
#include <linux/delay.h>
#include <command.h>
#include <dm/of_access.h>
#include <dm/ofnode.h>
static int option_probe(struct udevice *dev)
{
struct gpio_desc gpio_eeprom_wp;
struct device_node *np;
int ret;
np = of_find_compatible_node(NULL,NULL,"—");
if(np == NULL)
{
printf("%s :can not get —\r\n",func);
}
else
{
printf("%s : get — node successed : -->%s\r\n",func,np->name);
}
ret = gpio_request_by_name(dev, "gpio", 0, &gpio,GPIOD_IS_OUT);
if(ret)
{printf("%s :can not get eepro_wp gpio\r\n",__func__);
}
else
{printf("%s :get eepro_wp gpio \r\n",__func__);
}
/---------------操作gpio---------------/
return 0;
}
static int option_remove(struct udevice *dev)
{
return 0;
}
static const struct udevice_id option_ids[] = {
{ .compatible = “—” },
{ }
};
U_BOOT_DRIVER(option) = {
.name = “—”,
.id = UCLASS_GPIO,
.of_match = misc_vantron_ids,
.probe = option_probe,
.remove = option_remove,
};
dts
gpio-verify {
compatible="—";
pinctrl-names = “default”;
pinctrl-0 = <&pin>;
gpio = <&gpio gpio10 GPIO_ACTIVE_HIGH>;
status = “okay”;
};
参考连接:https://blog.csdn.net/weixin_68294039/article/details/125937245