我添加了MAX7320 i2c输出芯片.如何获得内核来为其加载驱动程序? [英] I've added a MAX7320 i2c output chip. How can I get the kernel to load the driver for it?

查看:147
本文介绍了我添加了MAX7320 i2c输出芯片.如何获得内核来为其加载驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在ARM Linux板上的i2c总线0上添加了MAX7320 i2c扩展器芯片.

I've added a MAX7320 i2c expander chip to i2c bus 0 on my ARM Linux board.

该芯片可以使用诸如/usr/sbin/i2cset -y 0 0x5d 0x02/usr/sbin/i2cget -y 0 0x5d之类的命令从用户空间正常工作.

The chip works correctly from userspace with commands such as /usr/sbin/i2cset -y 0 0x5d 0x02 and /usr/sbin/i2cget -y 0 0x5d.

内核源文件中有一个drivers/gpio/gpio-max732x.c文件,该文件已编译到我正在运行的内核中. (我从源头上构建了它.)

There is a drivers/gpio/gpio-max732x.c file in the kernel source, which is compiled into the kernel that I'm running. (I've built it from source.)

如何告诉内核应实例化"i2c总线0,芯片ID为0x5d"上的gpio-max732x驱动程序?

How do I tell the kernel that it should instantiate the gpio-max732x driver on "i2c bus 0, chip id 0x5d"?

我是否需要修改设备树.dts文件并将新的.dtb文件放入/boot/dtbs/?

Do I need to modify the device tree .dts file and put a new .dtb file in /boot/dtbs/?

实例化gpio-max732x模块的子句是什么样的?

What would the clause for instantiating a gpio-max732x module look like?

P.S.我见过 https://lkml.org/lkml/2015/1/13/305 ,但我不知道如何获取补丁文件.

P.S. I've seen https://lkml.org/lkml/2015/1/13/305 but I can't figure out how to get the patch files.

推荐答案

设备树

您的芯片必须具有适当的设备树定义,以便驱动程序实例化.有两种方法可以做到这一点:

Device Tree

There must be appropriate Device Tree definition for your chip, in order for driver to instantiate. There are 2 ways to do so:

  1. 修改板的.dts设备树文件(在arch/arm/boot/dts/)中查看,然后重新编译并重新刷新到设备中.)

  1. Modify .dts Device Tree file for your board (look in arch/arm/boot/dts/), then recompile it and re-flash it to your device.

如果您可以访问开发板的内核源并且可以将.dtb文件重新刷新到设备中,则首选这种方法.

This way is preferred in case when you have access you kernel sources for your board and you are able to re-flash .dtb file to your device.

创建设备树覆盖文件,对其进行编译,然后在您的设备上加载

Create Device Tree Overlay file, compile it and load it on your device.

如果您无权访问开发板的内核源代码,或者无法将新的设备树blob刷新到设备,则首选这种方法.

This way is preferred when you don't have access to kernel sources for your board, or you are unable to flash new device tree blob to your device.

您在设备树中的设备定义应如下所示(根据文档/devicetree/bindings/gpio/gpio-max732x.txt ):

Your device definition in Device Tree should look like (according to Documentation/devicetree/bindings/gpio/gpio-max732x.txt):

&i2c0 {
    expander: max7320@5d {
        compatible = "maxim,max7320";
        reg = <0x5d>;
        gpio-controller;
        #gpio-cells = <2>;
    };
};

内核配置

由于扩展器芯片(MAX7320)没有输入GPIO,因此不需要MAX732x的IRQ支持.因此,您可以在内核配置中禁用CONFIG_GPIO_MAX732X_IRQ.

一旦加载了设备树(具有MAX7320的定义),MAX732x驱动程序将与设备定义匹配并实例化.下面说明了匹配是如何发生的.

Once you have your Device Tree loaded (with definition for MAX7320), MAX732x driver will be matched with device definition, and instantiated. Below is explained how matching happens.

在设备树文件中,您具有compatible属性:

In Device Tree file you have compatible property:

compatible = "maxim,max7320";

在MAX732x驱动程序中,您可以看到此表:

In MAX732x driver you can see this table:

static const struct of_device_id max732x_of_table[] = {
    ...
    { .compatible = "maxim,max7320" },
    ...

在加载驱动程序以及加载设备树blob时,内核会尝试查找每个驱动程序和设备树定义的匹配项.只是通过比较上面的字符串.如果字符串匹配-内核实例化驱动程序,并将相应的设备参数传递给它.查看 i2c_device_match()函数以获取详细信息.

When driver is being loaded, and when Device Tree blob is being loaded, kernel tries to find the match for each driver and Device Tree definition. Just by comparing strings above. If strings are matched -- kernel instantiates driver, passing corresponding device parameters to it. Look at i2c_device_match() function for details.

最好的方法是使用已经支持MAX732x(v4.0 +)的设备树的内核源.但是,如果不是这种情况,那么...

The best way is to use kernel sources that already have Device Tree support of MAX732x (v4.0+). But if it's not the case, then...

您可以从上游内核中挑选补丁到内核:

You can cherry-pick patches from upstream kernel to your kernel:

$ git remote add upstream git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
$ git fetch --all
$ git cherry-pick 43c4bcf9425e
$ git cherry-pick 479f8a5744d8
$ git cherry-pick 09afa276d52e
$ git cherry-pick 996bd13f28e6

如果您仍然想手动应用补丁程序(实际上是最差的选择),请此处,您可以找到直接链接补丁.点击(补丁)链接以获取原始补丁.

And if you still want to apply patches manually (worst option, actually), here you can find direct links to patches. Click (patch) link to get a raw patch.

还要检查更高版本的gpio-max732x.c 此处.

Also check later patches for gpio-max732x.c here.

为确保您的芯片具有0x5d I2C地址,请检查配置引脚是否与下一行连接在一起(按照

To be sure that your chip has 0x5d I2C address, check that configuration pins are tied to next lines (as per datasheet):

Pin    Line
-----------
AD2     V+
AD0     V+

这篇关于我添加了MAX7320 i2c输出芯片.如何获得内核来为其加载驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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