带Linux设备树的max732x.c I2C IO扩展器+ GPIO密钥不起作用 [英] max732x.c I2C IO Expander + GPIO Keys w/ Linux Device Tree not working

查看:151
本文介绍了带Linux设备树的max732x.c I2C IO扩展器+ GPIO密钥不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Freescale MX6和3.10.31 Freescale修改后的内核.我有一个用作IO扩展器的Maxim MAX7325,其按钮已连接到P0-P2. 7325的中断线连接到GPIO_3焊盘(我认为是GPIO1_3 ...)

I'm working with a Freescale MX6 and a 3.10.31 Freescale modified kernel. I have a Maxim MAX7325 used as an IO expander, which has pushbuttons attached to P0-P2. The interrupt line from the 7325 is attached to the GPIO_3 pad (which I believe is GPIO1_3...)

我在设备树中设置了7325和gpio密钥,如下所示:

I set up the 7325 and gpio-keys in the device tree like this:

max7325_reset: max7325-reset {
  compatible = "gpio-reset";
  reset-gpios = <&gpio5 16 GPIO_ACTIVE_LOW>;
  reset-delay-us = <1>;
  #reset-cells = <0>;
};


gpio-keys {
  compatible = "gpio-keys";

  sw2 {
     gpios = <&max7325 2 GPIO_ACTIVE_LOW>;
     linux,code = <30>;    //a
     gpio-key,wakeup;
  };
};

&i2c1 {
   clock-frequency = <100000>;
   pinctrl-names = "default";
   pinctrl-0 = <&pinctrl_i2c1_2>;
   status = "okay";

   max7325: gpio@68 {
      compatible = "maxim,max7325";
      reg = <0x68>;
      gpio-controller;
      #gpio-cells = <2>;
      resets = <&max7325_reset>;

      gpios = <&gpio1 3 GPIO_ACTIVE_LOW>;
      interrupt-parent = <&gpio1>;
      interrupts = <3 2>;
   };
};

似乎是发生在调用MAX7325驱动程序的探针时,client-> dev.platform_data为NULL.因此,稍后调用max732x_irq_setup时,它不会设置chip-> gpio_chip.to_irq指针来指向max732x_gpio_to_irq函数(大概是因为它没有正确的信息才能工作). 尝试配置第一个输入,但在尝试设置中断时失败,并且没有其他键被设置.

What appears to happen is when probe for the MAX7325 driver is called, client->dev.platform_data is NULL. Because of this, when max732x_irq_setup is called later, it doesn't set up the chip->gpio_chip.to_irq pointer to point at max732x_gpio_to_irq function (presumably because it doesn't have the right info for this to work.) Later, when gpio_keys tries to config the first input, it fails when it tries to set up the interrupt and none of the other keys get set up.

gpio-keys gpio-keys.20: Unable to get irq number for GPIO 242, error -6

我确实使用/sys接口确定P0映射到GPIO 240,所以,是的,GPIO 242是我尝试设置的sw2 GPIO-KEY.

I did determine using the /sys interface that P0 maps to GPIO 240, so yeah, GPIO 242 is the sw2 GPIO-KEY I was trying to set up.

我想知道,此驱动程序是否不适用于设备树?我没有看到它试图获取任何设备树属性,但是我看过的其他IO扩展器驱动程序也没有,所以我认为I2C核心可能正在读取设备树并应该以某种方式从那里填充platform_data.它调用驱动程序的探测功能(?)

I'm wondering, does this driver not work with a device tree? I don't see it trying to get any device tree properties, but other IO expander drivers I looked at didn't either, so I thought maybe the I2C core is reading the device tree and supposed to fill in the platform_data from there somehow before it calls the driver's probe function (?)

我在这方面还很陌生,所以任何帮助都将不胜感激. =)我确实在线阅读了一些设备树"文档,但是我认为这是我没有正确执行的相当具体的内容,它们没有涵盖...(?)

I'm fairly new at this, so any help would be appreciated. =) I did read a few of the Device Tree docs online, but I'm thinking this is something fairly specific that I'm not doing correctly, which they don't cover... (?)

我确实在内核中配置了CONFIG_GPIO_MAX732X_IRQ ...,我曾经尝试过为max7325 I2c1节点设置中断控制器属性,但是我不确定是否需要(?)

I do have CONFIG_GPIO_MAX732X_IRQ configured in the kernel... and I did at one point try setting the interrupt-controller property for the max7325 I2c1 node, but I wasn't sure that was needed (?)

推荐答案

MAX732x设备树支持

您使用的驱动程序不适用于设备树中的数据.我已向该驱动程序添加了设备树支持,并将其发送到内核邮件列表中进行审查,但尚未合并.请参见此线程(共4个补丁):

MAX732x device tree support

Driver you are using won't work with data from device tree. I have added device tree support to this driver and sent it to kernel mailing lists for review, but they are not merged yet. See this thread (total 4 patches):

您可以将这些补丁应用到您的分支,或者等待它们进入上游内核,然后从那里将它们樱桃挑选(进入您的分支).

You can either apply those patches to your branch or wait for them to get into upstream kernel and then cherry-pick them from there (into your branch).

绑定文档(参见以上补丁)显示了如何为MAX732x创建设备树声明.在您的情况下,它可能看起来像这样:

Bindings documentation (see patches above) shows how to create device tree declaration for MAX732x. In your case it may look like this:

&i2c1 {
    expander: max7325@68 {
        compatible = "maxim,max7325";
        reg = <0x68>;
        gpio-controller;
        #gpio-cells = <2>;
        interrupt-controller;
        #interrupt-cells = <2>;
        interrupt-parent = <&gpio1>;
        interrupts = <3 2>;
    };
};

使用该驱动程序的另一种方法(上面没有补丁)是在电路板文件中为您的电路板指定平台数据.我相信它应该是下一个文件之一:

Another way for you to use this driver (without patches above) is to specify platform data in board file for your board. I believe it should be one of next files:

  • arch/arm/mach-imx/mach-imx6q.c
  • arch/arm/mach-imx/mach-imx6sl.c
  • arch/arm/mach-imx/mach-imx6sx.c

您可以在此处找到操作方法示例:arch/arm/mach-pxa/littleton.c,第394行.

You can find an example how to do so here: arch/arm/mach-pxa/littleton.c, line 394.

但这可能不是可靠的方法:我尝试这样做,但i2c总线号存在一些问题(尽管看起来不太像).将设备的定义分散在board文件和dts文件之间看起来也很糟糕.因此,我强烈建议您使用上面的补丁.

But it may be not reliable way: I tried to do so and had some issues with i2c buses numbers (didn't look too much in that way though). It also looks bad to scatter devices' definitions between board file and dts file. So I strongly recommend you to use patches above.

似乎是发生在调用MAX7325驱动程序探针时,client-> dev.platform_data为NULL.

What appears to happen is when probe for the MAX7325 driver is called, client->dev.platform_data is NULL.

发生这种情况是因为驱动程序与设备树文件中的设备声明绑定在一起,而不是与 board文件中的设备声明绑定在一起.在这种情况下,驱动程序应使用 client-> dev.of_node 而不是 client-> dev.platform_data .只要在上面的补丁中看看它是如何完成的即可.

It happens because driver was binded with device declaration from device tree file rather than from board file. In that case driver should use client->dev.of_node instead of client->dev.platform_data. Just see how it's done in my patch above.

您可以在以下内核文档中了解有关绑定/匹配/实例化如何发生的更多信息:

You can read more about how binding/matching/instantiating happens in kernel documentation here:

  • 文档/i2c/实例化设备
  • Documentation/devicetree/usage-model.txt

我认为I2C内核可能正在读取设备树,并应该在调用驱动程序的探测功能(?)之前以某种方式从该位置填充platform_data

I thought maybe the I2C core is reading the device tree and supposed to fill in the platform_data from there somehow before it calls the driver's probe function (?)

不.发生绑定时, client-> irq 将自动填充到I2C内核中(在调用驱动程序的探测功能之前).诸如 gpio_base irq_base 之类的属性-如果数据来自设备树,则不需要它们.

No. When binding is happening, client->irq being automatically populated in I2C core (before driver's probe function being called). Properties like gpio_base and irq_base -- you don't need them in case when data came from device tree.

我曾经尝试过为max7325 I2c1节点设置中断控制器属性,但我不确定是否需要(?)

I did at one point try setting the interrupt-controller property for the max7325 I2c1 node, but I wasn't sure that was needed (?)

MAX7325在检测到输入线路(更具体而言,配置为输入的漏极开路I/O端口)上的更改时,向SoC发出中断. 因此,如果希望驱动程序为每个输入I/O线生成单独的中断(以便其他驱动程序可以使用它们),则应指定"interrupt-controller"和#interrupt-cells"属性.但是为此,您需要应用上述所有补丁.

MAX7325 issues interrupt to your SoC when it detects changes on input lines (more specifically, on open-drain I/O ports configured as inputs). So if you want your driver to generate separate interrupts for each input I/O line (so that other drivers can consume them), you should specify "interrupt-controller" and "#interrupt-cells" properties. But for this you need all patches mentioned above to be applied.

现在所有提到的补丁都已合并到上游内核(v4.0和更高版本)中:

Now all mentioned patches were merged into upstream kernel (v4.0 and later):

  1. gpio:max732x:添加设备树支持
  2. gpio:max732x:重写使用irq_domain API的IRQ代码
  3. gpio:max732x:已修复可能的死锁
  4. gpio:max732x:添加DT绑定文档
  1. gpio: max732x: Add device tree support
  2. gpio: max732x: Rewrite IRQ code to use irq_domain API
  3. gpio: max732x: Fix possible deadlock
  4. gpio: max732x: Add DT binding documentation

还请注意,在我的补丁程序之上做了一些新的补丁程序.您可以观看它们这里.

Also notice that there are some new patches were made on top of my patches. You can watch them here.

这篇关于带Linux设备树的max732x.c I2C IO扩展器+ GPIO密钥不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆