// SPDX-License-Identifier: GPL-2.0 OR MIT

#include "qcom-ipq8068-cryptid-common.dtsi"

#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>

/ {
	model = "Meraki MR42";
	compatible = "meraki,mr42", "qcom,ipq8064";

	aliases {
		serial1 = &gsbi1_serial;
		ethernet0 = &gmac3;

		led-boot = &led_active;
		led-failsafe = &led_power;
		led-running = &led_active;
		led-upgrade = &led_active;
	};

	keys {
		compatible = "gpio-keys";
		pinctrl-0 = <&button_pins>;
		pinctrl-names = "default";

		reset {
			label = "reset";
			gpios = <&qcom_pinmux 26 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
			debounce-interval = <60>;
			wakeup-source;
		};
	};

	leds {
		compatible = "gpio-leds";
		pinctrl-0 = <&led_pins>;
		pinctrl-names = "default";

		led_power: power {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_ORANGE>;
			gpios = <&qcom_pinmux 31 GPIO_ACTIVE_HIGH>;
		};

		led_active: active {
			label = "white:active";
			gpios = <&qcom_pinmux 32 GPIO_ACTIVE_HIGH>;
		};
	};
};

&gmac3 {
	status = "okay";

	qcom,id = <3>;
	mdiobus = <&mdio0>;

	phy-mode = "sgmii";
	phy-handle = <&phy2>;

	nvmem-cells = <&mac_address 0>;
	nvmem-cell-names = "mac-address";
};

&gsbi2 {
	status = "okay";
	qcom,mode = <GSBI_PROT_I2C>;
};

&gsbi2_i2c {
	status = "okay";

	pinctrl-0 = <&i2c0_pins>;
	pinctrl-names = "default";

	ina2xx@40 {
		compatible = "ina219";
		shunt-resistor = <40000>;
		reg = <0x40>;
	};

	eeprom@56 {
		compatible = "atmel,24c64";
		pagesize = <32>;
		reg = <0x56>;
		read-only;

		nvmem-layout {
			compatible = "fixed-layout";
			#address-cells = <1>;
			#size-cells = <1>;

			mac_address: mac-address@66 {
				compatible = "mac-base";
				reg = <0x66 0x6>;
				#nvmem-cell-cells = <1>;
			};
		};
	};
};

&gsbi6 {
	qcom,mode = <GSBI_PROT_I2C>;
	status = "okay";
};

&gsbi6_i2c {
	status = "okay";

	pinctrl-0 = <&i2c1_pins>;
	pinctrl-names = "default";

	tlc591xx@40 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "ti,tlc59108";
		reg = <0x40>;

		red@0 {
			label = "red:user";
			reg = <0x0>;
		};

		green@1 {
			label = "green:user";
			reg = <0x1>;
		};

		blue@2 {
			label = "blue:user";
			reg = <0x2>;
		};
	};
};

&mdio0 {
	status = "okay";

	pinctrl-0 = <&mdio0_pins_active>, <&phy_active>;
	pinctrl-names = "default";

	phy2: ethernet-phy2 {
		reg = <2>;

		reset-gpios = <&qcom_pinmux 6 GPIO_ACTIVE_LOW>;
		reset-assert-us = <24000>;

		eee-broken-100tx;
		eee-broken-1000t;
	};
};

&qcom_pinmux {
	i2c0_pins: i2c0_pins {
		mux {
			pins = "gpio24", "gpio25";
			function = "gsbi2";
			drive-strength = <2>;
			bias-pull-up;
			input;
		};
	};

	button_pins: button_pins {
		mux {
			pins = "gpio26";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-up;
		};
	};

	i2c1_pins: i2c1_pins {
		mux {
			pins = "gpio29", "gpio30";
			function = "gsbi6";
			drive-strength = <2>;
			bias-pull-up;
			input;
		};
	};

	led_pins: led_pins {
		mux {
			pins = "gpio31", "gpio32";
			function = "gpio";
			drive-strength = <12>;
			bias-pull-down;
			output-low;
		};
	};
};

&wifi0 {
	nvmem-cells = <&mac_address 1>;
	nvmem-cell-names = "mac-address";
};

&wifi1 {
	nvmem-cells = <&mac_address 2>;
	nvmem-cell-names = "mac-address";
};

&wifi2 {
	nvmem-cells = <&mac_address 3>;
	nvmem-cell-names = "mac-address";
};

&hs_phy_0 {
	status = "okay";
};

&ss_phy_0 {
	status = "okay";
};

&usb3_0 {
	status = "okay";
};

&hs_phy_1 {
	status = "okay";
};

&ss_phy_1 {
	status = "okay";
};

&usb3_1 {
	status = "okay";
};
