Custom Device Tree Overlay for MCP23017 via i2c-ao

Hello community,

I am attempting to create a custom device tree overlay for an MCP23017. Below is the spec from the manufacturer:

gpiom1: gpio@20 {
        compatible = "microchip,mcp23017";
        gpio-controller;
        #gpio-cells = <2>;
        reg = <0x20>;

        interrupt-parent = <&gpio1>;
        interrupts = <17 IRQ_TYPE_LEVEL_LOW>;
        interrupt-controller;
        #interrupt-cells=<2>;
        microchip,irq-mirror;
};

And below is my current custom overlay:

/dts-v1/;
/plugin/;

/ {
        compatible = "libretech,cc", "amlogic,s905x", "amlogic,meson-gxl";

        fragment@0 {
                target = <&i2c_AO>;

                __overlay__ {
                        mcp23017@20 {
                                compatible = "mcp,23017";
                                reg = <0x20>;
                        };
                };
        };

};

I was hoping to get some guidance on how to integrate the necessary elements for the interrupts and GPIO. I have not had any luck with using the examples I have found from Libre.

This is the last item needed to complete a port of the SW from RaspberryPi to Libre and I have been stuck for quite a few weeks trying to get something going. Any help from the community would be greatly appreciated.

Thank you!

Here is another example that I have found which is similar:

/dts-v1/;
/plugin/;

/ {
	compatible = "libretech,cc", "amlogic,s905x", "amlogic,meson-gxl";

	fragment@0 {
		target = <&i2c0>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			mcp23017_pins: mcp23017_pins {
				brcm,pins = <4>;
				brcm,function = <0>;
			};
		};
	};

	fragment@2 {
		target = <&i2c0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;

			mcp23017: mcp@20 {
				compatible = "microchip,mcp23017";
				reg = <0x20>;
				gpio-controller;
				#gpio-cells = <2>;
				#interrupt-cells=<2>;
				interrupt-parent = <&gpio>;
				interrupts = <4 2>;
				interrupt-controller;
				microchip,irq-mirror;
			};
		};
	};
	
	__overrides__ {
		gpiopin = <&mcp23017_pins>,"brcm,pins:0",
				<&mcp23017>,"interrupts:0";
		addr = <&mcp23017>,"reg:0";
	};
};

@angus @librecomputer @GeertVc @Iain_R any help with this would be much appreciated. I have seen from the forum that you have gotten the MCP23017 to talk with the LePotato successfully

Raspberry Pi overlays are non-generic. They put a lot of hacks (brcm) that is specific to Raspberry Pi Broadcom SoC. Simply copying it verbatim is not going to work. An overlay usually requires the following:

  • Compatible string from a driver in the Linux kernel
  • GPIO pins used so that they can be locked away from other software access
  • GPIO pins that act as interrupts and their interrupt parents
  • For I2C and SPI devices, the address or channel select
  • Status field

We don’t have any devices to test and create the overlay.

They’re cheap enough; I’ll add one to my next parts order if I can find a driver. I’d like to try an i2c overlay.

I’m new at this, so I wouldn’t expect a super quick turnaround.

1 Like

I found the driver:

And some documentation:

Hey @angus and @librecomputer I got this to work finally but it required adding a 1k pull up resistor to pins 3 and 5. @librecomputer you mentioned that this was fixed in the most recent build but I am on the latest image from Libre and have ran an apt-get install and update.

How do I get those pull ups to be active without external resistors?

Thank you

1 Like

You can flash the latest bootloader to your image using libretech-flash-tool. It sets the internal pull ups. However on some designs, it may not be enough.

Cool! I have one on order!

1 Like

@blue How did you end up making this work? Were you able to use the device tree overlay? I am up against the same issue (trying to add support for the MCP23008 GPIO expander) and I am having no luck with the overlay method so far. Thanks!

What exactly is the issue you are running into?