内核 gpio 解析 设备树的 gpio 配置

gpiod = devm_gpiod_get(dev, "recv", GPIOD_IN);  

对应的设备树

recv-gpios = <&gpio XGPIO_000 1>;
gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);  

对应的设备树

gpios = <&gpio XGPIO_000 1>;
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
设备树配置GPIO按键驱动需要完成以下几个步骤: 1. 定义GPIO节点 在设备树中需要定义GPIO节点,节点包含GPIO的编号、使用模式、中断类型等信息。例如: gpio-keys { compatible = "gpio-keys"; pinctrl-names = "default"; pinctrl-0 = <&gpio_keys_pins>; #address-cells = <1>; #size-cells = <0>; power { label = "Power button"; gpios = <&gpio1 0 GPIO_ACTIVE_LOW>; linux,code = <KEY_POWER>; debounce-interval = <50>; interrupt-parent = <&gpio1>; interrupts = <0 IRQ_TYPE_EDGE_FALLING>; }; }; 2. 定义中断控制器节点 中断控制器节点是一个必要的节点,它描述了中断控制器的类型、中断号等信息。例如: gpio_keys_pins: gpio_keys_pins { gpio-key1 { gpio-hog; gpios = <&gpio1 0 GPIO_ACTIVE_LOW>; output-low; line-name = "Power Button"; }; }; 3. 配置中断控制器 在设备树中需要配置中断控制器,使其能够正确的处理GPIO中断。例如: gpio1: gpio@4804c000 { compatible = "ti,omap4-gpio"; reg = <0x4804c000 0x1000>; interrupts = <34>; gpio-controller; #gpio-cells = <2>; interrupt-controller; #interrupt-cells = <2>; interrupt-parent = <&intc>; }; 4. 在驱动中解析设备树 在Linux内核驱动中需要解析设备树,获取GPIO节点的信息,从而正确的控制GPIO。例如: static int gpio_keys_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct gpio_keys_drvdata *ddata; struct input_dev *input_dev; struct gpio_desc *desc; int i, err; ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); if (!ddata) return -ENOMEM; input_dev = devm_input_allocate_device(&pdev->dev); if (!input_dev) return -ENOMEM; input_dev->name = "gpio-keys"; input_dev->id.bustype = BUS_GPIO; for_each_child_of_node(np, desc) { const char *label; err = of_property_read_string(desc, "label", &label); if (err) continue; err = of_property_read_u32(desc, "linux,code", &ddata->keycodes[i]); if (err) continue; ddata->key_count++; err = gpiod_direction_input(desc); if (err < 0) continue; ddata->gpio_descs[i] = desc; input_set_capability(input_dev, EV_KEY, ddata->keycodes[i]); i++; } input_dev->keycode = ddata->keycodes; input_dev->keycodesize = sizeof(ddata->keycodes[0]); input_dev->keycodemax = ddata->key_count; ddata->input_dev = input_dev; platform_set_drvdata(pdev, ddata); err = input_register_device(input_dev); if (err) { dev_err(&pdev->dev, "Failed to register input device: %d\n", err); return err; } return 0; } 以上就是在Android系统中配置GPIO按键驱动的设备树方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值