I've added a MAX7320 i2c output chip. How can I get the kernel to load the driver for it?

半世苍凉 提交于 2019-12-04 15:14:02
Sam Protsenko

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. Modify .dts Device Tree file for your board (look in arch/arm/boot/dts/), then recompile it and re-flash it to your device.

    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.

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

    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.

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>;
    };
};

Kernel configuration

As your expander chip (MAX7320) has no input GPIOs, you don't need IRQ support for MAX732x. So you can disable CONFIG_GPIO_MAX732X_IRQ in your kernel configuration.

Matching device with driver

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.

In Device Tree file you have compatible property:

compatible = "maxim,max7320";

In MAX732x driver you can see this table:

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

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.

Obtaining patches

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.

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

Hardware concerns

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+
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!