// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/dts-v1/;

#include <dt-bindings/leds/common.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include "an7583.dtsi"

/ {
	model = "Airoha AN7583 Evaluation Board";
	compatible = "airoha,an7583-evb", "airoha,an7583", "airoha,en7583";

	aliases {
		serial0 = &uart1;
	};

	chosen {
		bootargs = "console=ttyS0,115200 earlycon";
		stdout-path = "serial0:115200n8";
	};

	memory@80000000 {
		device_type = "memory";
		reg = <0x0 0x80000000 0x2 0x00000000>;
	};

	gpio-keys-polled {
		compatible = "gpio-keys-polled";
		poll-interval = <100>;

		btn-reset {
			label = "reset";
			linux,code = <BTN_0>;
			gpios = <&an7583_pinctrl 0 GPIO_ACTIVE_LOW>;
		};
	};

	leds {
		compatible = "gpio-leds";

		led-1 {
			label = "pon";
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&an7583_pinctrl 12 GPIO_ACTIVE_LOW>;
		};

		led-2 {
			label = "internet";
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&an7583_pinctrl 26 GPIO_ACTIVE_LOW>;
		};

		led-3 {
			label = "wps";
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&an7583_pinctrl 31 GPIO_ACTIVE_LOW>;
		};

		led-4 {
			label = "los";
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_STATUS;
			gpios = <&an7583_pinctrl 27 GPIO_ACTIVE_LOW>;
		};

		led-5 {
			label = "voip_hook";
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&an7583_pinctrl 29 GPIO_ACTIVE_LOW>;
		};
	};
};

&an7583_pinctrl {
	gpio-ranges = <&an7583_pinctrl 0 2 53>;

	mdio0_pins: mdio0-pins {
		conf {
			pins = "mdio_0";
			output-high;
		};
	};

	pcie0_rst_pins: pcie0-rst-pins {
		conf {
			pins = "pcie_reset0";
			drive-open-drain = <1>;
		};
	};

	pcie1_rst_pins: pcie1-rst-pins {
		conf {
			pins = "pcie_reset1";
			drive-open-drain = <1>;
		};
	};

	gswp1_led0_pins: gswp1-led0-pins {
		mux {
			function = "phy1_led0";
			pins = "gpio1";
		};
	};

	gswp2_led0_pins: gswp2-led0-pins {
		mux {
			function = "phy2_led0";
			pins = "gpio2";
		};
	};

	gswp3_led0_pins: gswp3-led0-pins {
		mux {
			function = "phy3_led0";
			pins = "gpio3";
		};
	};

	gswp4_led0_pins: gswp4-led0-pins {
		mux {
			function = "phy4_led0";
			pins = "gpio4";
		};
	};

	mmc_pins: mmc-pins {
		mux {
			function = "emmc";
			groups = "emmc";
		};
	};
};

&mmc0 {
	pinctrl-names = "default", "state_uhs";
	pinctrl-0 = <&mmc_pins>;
	pinctrl-1 = <&mmc_pins>;
	status = "okay";

	#address-cells = <1>;
	#size-cells = <0>;

	card@0 {
		compatible = "mmc-card";
		reg = <0>;

		block {
			compatible = "block-device";
			partitions {
				block-partition-factory {
					partname = "art";

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

						eeprom_factory_0: eeprom@0 {
							reg = <0x40000 0x1e00>;
						};

						mac_factory_2c0000: mac@2c0000 {
							reg = <0x2c0000 0x6>;
						};

						pon_mac_factory_2c0006: pon_mac@2c0006 {
							reg = <0x2c0006 0x6>;
						};

						onu_type_factory_2e0000: onu_type@2e0000 {
							reg = <0x2e0000 0x10>;
						};

						board_config_factory_2e0010: board_config@2e0010 {
							reg = <0x2e0010 0x8>;
						};
					};
				};
			};
		};
	};
};

&i2c0 {
	status = "okay";
};

&i2c1 {
	status = "okay";
};

&mdio_0 {
	pinctrl-names = "default";
	pinctrl-0 = <&mdio0_pins>;

	en8811: ethernet-phy@f {
		reg = <0xf>;

		reset-gpios = <&an7583_pinctrl 28 GPIO_ACTIVE_LOW>;
		reset-assert-us = <10000>;
		reset-deassert-us = <20000>;

		leds {
			#address-cells = <1>;
			#size-cells = <0>;

			led@0 {
				reg = <0>;
				function = LED_FUNCTION_LAN;
				color = <LED_COLOR_ID_GREEN>;
				function-enumerator = <0>;
				default-state = "keep";
			};

			led@1 {
				reg = <1>;
				function = LED_FUNCTION_LAN;
				color = <LED_COLOR_ID_GREEN>;
				function-enumerator = <1>;
				default-state = "keep";
			};
		};
	};
};

&npu {
	status = "okay";
};

&eth {
	status = "okay";
	nvmem-cells = <&mac_factory_2c0000>;
	nvmem-cell-names = "mac";
};

&gdm1 {
	status = "okay";
};

&gdm3 {
	status = "okay";

	phy-handle = <&en8811>;
	phy-mode = "2500base-x";
};

&switch {
	status = "okay";
};

&gsw_phy1 {
	pinctrl-names = "gbe-led";
	pinctrl-0 = <&gswp1_led0_pins>;
	status = "okay";
};

&gsw_phy1_led0 {
	status = "okay";
	active-low;
};

&gsw_phy2 {
	pinctrl-names = "gbe-led";
	pinctrl-0 = <&gswp2_led0_pins>;
	status = "okay";
};

&gsw_phy2_led0 {
	status = "okay";
	active-low;
};

&gsw_phy3 {
	pinctrl-names = "gbe-led";
	pinctrl-0 = <&gswp3_led0_pins>;
	status = "okay";
};

&gsw_phy3_led0 {
	status = "okay";
	active-low;
};

&gsw_phy4 {
	pinctrl-names = "gbe-led";
	pinctrl-0 = <&gswp4_led0_pins>;
	status = "okay";
};

&gsw_phy4_led0 {
	status = "okay";
	active-low;
};
