wiwi
Posts: 8
Joined: Fri Aug 02, 2019 1:35 pm

MCP23S17: Device tree interrupt configuration for multiple devices on the same chip select

Fri Aug 02, 2019 5:01 pm

Hello all,

I designed a board with multiple MCP23S17 on the same chipselect, unfortunately I discovered after that the current dts (https://github.com/raspberrypi/linux/bl ... verlay.dts) can only handle the configuration interrupt configuration if there is only one device.

I took a (quick) look on the driver and it seems to support different configuration for each device on the same bus, but I am not really sure the interrupt handling could manage it correctly. I am not sufficiently aware of the driver architecture and device tree configuration on linux to confirm this without deep investigation.
  • Do you know if I can manage this case if I write my own dts
  • If I configure manually in my program the interrupt configuration in the MCP23, how can I configure the interrupt handling according to my configuration
Best regards,

Wilfrid

dloranger
Posts: 34
Joined: Wed Nov 02, 2016 1:56 am

Re: MCP23S17: Device tree interrupt configuration for multiple devices on the same chip select

Sun Aug 25, 2019 6:50 pm

I use the MCP23017 frequently which I believe is basically the same drivers, just I2C instead of SPI.

I write my own overlays for these devices for every hat I have designed with these devices as I need more that one and the overlays don't really handle this condition.

Here is what I do, hopefully it will be helpful for you to get started.

Code: Select all

// Definitions for MCP23017 Gpio Extender from Microchip Semiconductor 
/dts-v1/; /plugin/; / {
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
	[email protected] {
		target = <&i2c1>;
		__overlay__ {
			status = "okay";
		};
	};
	[email protected] {
		target = <&gpio>;
		__overlay__ {
			mcp23017_pins: mcp23017_pins {
				brcm,pins = <4>;
				brcm,function = <0>;
			};
		};
	};
	[email protected] {
		target = <&i2c1>;
		__overlay__ {
			#address-cells = <1>; size-cells = <0>;
			mcp23017_20: [email protected] {
				compatible = "microchip,mcp23017";
				reg = <0x20>;
				gpio-controller;
				#gpio-cells = <2>; interrupt-cells=<2>;
				interrupt-parent = <&gpio>;
				interrupts = <12 2>;
				interrupt-controller;
				microchip,irq-mirror;
				status = "okay";
			};
		};
	};
	
	[email protected] {
		target = <&i2c1>;
		__overlay__ {
			#address-cells = <1>; size-cells = <0>;
			mcp23017_21: [email protected] {
				compatible = "microchip,mcp23017";
				reg = <0x21>;
				gpio-controller;
				#gpio-cells = <2>; interrupt-cells=<2>;
				interrupt-parent = <&gpio>;
				interrupts = <25 2>;
				interrupt-controller;
				microchip,irq-mirror;
				status = "okay";
			};
		};
	};
};
I haven't had any issues with the interrupts (although I don't think they are actually implemented correctly as others have had problems using the interrupt notifications on the interrupt pins. I know that if I don't put a pull up on the pins, the systems goes beserk on the i2c bus, but otherwise the interrupt count never actually increments.

https://www.raspberrypi.org/forums/view ... 0#p1440463

Code: Select all

watch -n 1 cat /proc/interrupts

will show you the interrupts being generated by the chipsets.

as you can see, my system has been up for over a day and the counters at 178 and 191 are still at 0 interrupts fired.
[email protected](ro):~$ uptime
11:46:32 up 1 day, 25 min, 1 user, load average: 0.03, 0.02, 0.00
[email protected](ro):~$ cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
16: 0 0 0 0 bcm2836-timer 0 Edge arch_timer
17: 5303883 823726 1785503 4410680 bcm2836-timer 1 Edge arch_timer
23: 56 0 0 0 ARMCTRL-level 1 Edge 3f00b880.mailbox
24: 2 0 0 0 ARMCTRL-level 2 Edge VCHIQ doorbell
46: 0 0 0 0 ARMCTRL-level 48 Edge bcm2708_fb dma
48: 0 0 0 0 ARMCTRL-level 50 Edge DMA IRQ
50: 0 0 0 0 ARMCTRL-level 52 Edge DMA IRQ
51: 7878 0 0 0 ARMCTRL-level 53 Edge DMA IRQ
54: 0 0 0 0 ARMCTRL-level 56 Edge DMA IRQ
55: 0 0 0 0 ARMCTRL-level 57 Edge DMA IRQ
56: 0 0 0 0 ARMCTRL-level 58 Edge DMA IRQ
59: 1 0 0 0 ARMCTRL-level 61 Edge bcm2835-auxirq
62: 23411232 0 0 0 ARMCTRL-level 64 Edge dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
79: 3656 0 0 0 ARMCTRL-level 81 Edge 3f200000.gpio:bank0
80: 0 0 0 0 ARMCTRL-level 82 Edge 3f200000.gpio:bank1
83: 312562 0 0 0 ARMCTRL-level 85 Edge 3f804000.i2c
86: 1122 0 0 0 ARMCTRL-level 88 Edge mmc0
92: 414270 0 0 0 ARMCTRL-level 94 Edge mmc1
170: 0 0 0 0 pinctrl-bcm2835 4 Edge pps.-1
178: 0 0 0 0 pinctrl-bcm2835 12 Level 1-0020
190: 3656 0 0 0 pinctrl-bcm2835 24 Edge 1-004d
191: 0 0 0 0 pinctrl-bcm2835 25 Level 1-0021
220: 1 0 0 0 bcm2835-auxirq 0 Edge
FIQ: usb_fiq
IPI0: 0 0 0 0 CPU wakeup interrupts
IPI1: 0 0 0 0 Timer broadcast interrupts
IPI2: 140520 333982 369329 422204 Rescheduling interrupts
IPI3: 28 29 38 28 Function call interrupts
IPI4: 0 0 0 0 CPU stop interrupts
IPI5: 15632 34979 88667 14231 IRQ work interrupts
IPI6: 0 0 0 0 completion interrupts
Err: 0
[email protected](ro):~$

wiwi
Posts: 8
Joined: Fri Aug 02, 2019 1:35 pm

Re: MCP23S17: Device tree interrupt configuration for multiple devices on the same chip select

Thu Aug 29, 2019 1:38 pm

Hello,

Thank you for your answer.
I did not have the time to try this yet. I will keep you informed.

regards,

Wilfrid

wiwi
Posts: 8
Joined: Fri Aug 02, 2019 1:35 pm

Re: MCP23S17: Device tree interrupt configuration for multiple devices on the same chip select

Tue Nov 26, 2019 11:37 pm

Sorry for the late reply,

My case is with SPI MCP23S17, its a whole lot different.

A link to the issue with the interrupt in the SPI devices case on github:
https://github.com/raspberrypi/linux/issues/3207

Best regards,

Wilfrid

Return to “Device Tree”