// 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 MR52";
	compatible = "meraki,mr52", "qcom,ipq8064";

	aliases {
		serial1 = &gsbi1_serial;
		mdio-gpio0 = &mdio_gpio0;
		ethernet0 = &gmac2;
		ethernet1 = &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 25 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 19 GPIO_ACTIVE_HIGH>;
		};

		lan1_green {
			label = "green:lan1";
			gpios = <&qcom_pinmux 24 GPIO_ACTIVE_HIGH>;
		};

		lan2_green {
			label = "green:lan2";
			gpios = <&qcom_pinmux 23 GPIO_ACTIVE_HIGH>;
		};

		led_active: active {
			label = "white:active";
			gpios = <&qcom_pinmux 26 GPIO_ACTIVE_LOW>;
		};

		lan1_orange {
			label = "orange:lan1";
			gpios = <&qcom_pinmux 62 GPIO_ACTIVE_HIGH>;
		};

		lan2_orange {
			label = "orange:lan2";
			gpios = <&qcom_pinmux 60 GPIO_ACTIVE_HIGH>;
		};
	};
};

&gmac2 {
	status = "okay";

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

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

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

&gmac3 {
	status = "okay";

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

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

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

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

&gsbi7_i2c {
	status = "okay";

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

	ina2xx@45 {
		compatible = "ina219";
		shunt-resistor = <80000>;
		reg = <0x45>;
	};

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

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

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

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

	eeprom@52 {
		compatible = "atmel,24c64";
		pagesize = <32>;
		reg = <0x52>;
		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>;
			};
		};
	};
};

&qcom_pinmux {
	i2c_pins: i2c_pins {
		mux {
			pins = "gpio8", "gpio9";
			function = "gsbi7";
			drive-strength = <2>;
			bias-pull-up;
			input;
		};
	};

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

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

&soc {
	mdio_gpio0: mdio {
		compatible = "virtual,mdio-gpio";
		#address-cells = <1>;
		#size-cells = <0>;

		status = "okay";

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

		gpios = <&qcom_pinmux 1 GPIO_ACTIVE_HIGH
			 &qcom_pinmux 0 GPIO_ACTIVE_HIGH>;

		phy0: ethernet-phy0 {
			reg = <0>;
			reset-gpios = <&qcom_pinmux 7 GPIO_ACTIVE_LOW>;
			reset-assert-us = <24000>;
		};

		phy4: ethernet-phy4 {
			reg = <4>;
			reset-gpios = <&qcom_pinmux 6 GPIO_ACTIVE_LOW>;
			reset-assert-us = <24000>;
		};
	};
};

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

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

&wifi2 {
	nvmem-cells = <&mac_address 2>;
	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";
};
