#!/bin/bash


write_file () {
cat << EOF > mcp23017_ps$1.dts
// Definitions for MCP23017 Gpio Extender from Microchip Semiconductor

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

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

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

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

			mcp$1: mcp23017@$1 {
				compatible = "microchip,mcp23017";
				reg = <0x$1>;
				gpio-controller;
				#gpio-cells = <2>;
				#interrupt-cells=<2>;
				interrupt-parent = <&gpio>;
				interrupts = <$2 2>;
				interrupt-controller;
				microchip,irq-mirror;

				status = "okay";
			};
		};
	};
};
EOF
}

write_file 20 27 i2c1
write_file 21 17 i2c1
write_file 22 19 i2c3
write_file 23 26 i2c3