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

#include "rtl839x.dtsi"
#include "rtl83xx_hpe_1920.dtsi"

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

/ {
	aliases {
		led-boot = &led_power;
		led-failsafe = &led_power;
		led-running = &led_power;
		led-upgrade = &led_power;
	};

	leds {
		compatible = "gpio-leds";

		led_power: led-0 {
			label = "green:power";
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_POWER;
			gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>;
		};
	};

	i2c0: i2c-gpio-0 {
		compatible = "i2c-gpio";
		sda-gpios = <&gpio0 18 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		scl-gpios = <&gpio0 17 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		i2c-gpio,delay-us = <2>;
		#address-cells = <1>;
		#size-cells = <0>;
	};

	sfp0: sfp-p49 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c0>;
		los-gpio = <&gpio0 20 GPIO_ACTIVE_HIGH>;
		mod-def0-gpio = <&gpio0 19 GPIO_ACTIVE_LOW>;
		// tx-fault unconnected (TODO?)
		// tx-disable connected to RTL8214FC (TODO?)
	};

	i2c1: i2c-gpio-1 {
		compatible = "i2c-gpio";
		sda-gpios = <&gpio0 2 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		scl-gpios = <&gpio0 1 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		i2c-gpio,delay-us = <2>;
		#address-cells = <1>;
		#size-cells = <0>;
	};

	sfp1: sfp-p50 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c1>;
		los-gpio = <&gpio0 13 GPIO_ACTIVE_HIGH>;
		mod-def0-gpio = <&gpio0 12 GPIO_ACTIVE_LOW>;
		// tx-fault unconnected (TODO?)
		// tx-disable connected to RTL8214FC (TODO?)
	};

	// not enabled due to shared I2C clock
	i2c2: i2c-gpio-2 {
		status = "disabled";
		compatible = "i2c-gpio";
		sda-gpios = <&gpio0 21 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		scl-gpios = <&gpio0 17 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		i2c-gpio,delay-us = <2>;
		#address-cells = <1>;
		#size-cells = <0>;
	};

	sfp2: sfp-p51 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c2>;
		los-gpio = <&gpio0 23 GPIO_ACTIVE_HIGH>;
		mod-def0-gpio = <&gpio0 22 GPIO_ACTIVE_LOW>;
		// tx-fault unconnected (TODO?)
		// tx-disable connected to RTL8214FC (TODO?)
	};

	// not enabled due to shared I2C clock
	i2c3: i2c-gpio-3 {
		status = "disabled";
		compatible = "i2c-gpio";
		sda-gpios = <&gpio0 14 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		scl-gpios = <&gpio0 1 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		i2c-gpio,delay-us = <2>;
		#address-cells = <1>;
		#size-cells = <0>;
	};

	sfp3: sfp-p52 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c3>;
		los-gpio = <&gpio0 16 GPIO_ACTIVE_HIGH>;
		mod-def0-gpio = <&gpio0 15 GPIO_ACTIVE_LOW>;
		// tx-fault unconnected (TODO?)
		// tx-disable connected to RTL8214FC (TODO?)
	};
};

&ethernet0 {
	mdio: mdio-bus {
		compatible = "realtek,rtl838x-mdio";
		regmap = <&ethernet0>;
		#address-cells = <1>;
		#size-cells = <0>;

		EXTERNAL_PHY(0)
		EXTERNAL_PHY(1)
		EXTERNAL_PHY(2)
		EXTERNAL_PHY(3)
		EXTERNAL_PHY(4)
		EXTERNAL_PHY(5)
		EXTERNAL_PHY(6)
		EXTERNAL_PHY(7)

		EXTERNAL_PHY(8)
		EXTERNAL_PHY(9)
		EXTERNAL_PHY(10)
		EXTERNAL_PHY(11)
		EXTERNAL_PHY(12)
		EXTERNAL_PHY(13)
		EXTERNAL_PHY(14)
		EXTERNAL_PHY(15)

		EXTERNAL_PHY(16)
		EXTERNAL_PHY(17)
		EXTERNAL_PHY(18)
		EXTERNAL_PHY(19)
		EXTERNAL_PHY(20)
		EXTERNAL_PHY(21)
		EXTERNAL_PHY(22)
		EXTERNAL_PHY(23)

		EXTERNAL_PHY(24)
		EXTERNAL_PHY(25)
		EXTERNAL_PHY(26)
		EXTERNAL_PHY(27)
		EXTERNAL_PHY(28)
		EXTERNAL_PHY(29)
		EXTERNAL_PHY(30)
		EXTERNAL_PHY(31)

		EXTERNAL_PHY(32)
		EXTERNAL_PHY(33)
		EXTERNAL_PHY(34)
		EXTERNAL_PHY(35)
		EXTERNAL_PHY(36)
		EXTERNAL_PHY(37)
		EXTERNAL_PHY(38)
		EXTERNAL_PHY(39)

		EXTERNAL_PHY(40)
		EXTERNAL_PHY(41)
		EXTERNAL_PHY(42)
		EXTERNAL_PHY(43)
		EXTERNAL_PHY(44)
		EXTERNAL_PHY(45)
		EXTERNAL_PHY(46)
		EXTERNAL_PHY(47)

		EXTERNAL_SFP_PHY_FULL(48, 1)
		EXTERNAL_SFP_PHY_FULL(49, 3)
		EXTERNAL_SFP_PHY_FULL(50, 0)
		EXTERNAL_SFP_PHY_FULL(51, 2)
	};
};

&switch0 {
	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		SWITCH_PORT(0, 1, qsgmii)
		SWITCH_PORT(1, 2, qsgmii)
		SWITCH_PORT(2, 3, qsgmii)
		SWITCH_PORT(3, 4, qsgmii)
		SWITCH_PORT(4, 5, qsgmii)
		SWITCH_PORT(5, 6, qsgmii)
		SWITCH_PORT(6, 7, qsgmii)
		SWITCH_PORT(7, 8, qsgmii)

		SWITCH_PORT(8, 9, qsgmii)
		SWITCH_PORT(9, 10, qsgmii)
		SWITCH_PORT(10, 11, qsgmii)
		SWITCH_PORT(11, 12, qsgmii)
		SWITCH_PORT(12, 13, qsgmii)
		SWITCH_PORT(13, 14, qsgmii)
		SWITCH_PORT(14, 15, qsgmii)
		SWITCH_PORT(15, 16, qsgmii)

		SWITCH_PORT(16, 17, qsgmii)
		SWITCH_PORT(17, 18, qsgmii)
		SWITCH_PORT(18, 19, qsgmii)
		SWITCH_PORT(19, 20, qsgmii)
		SWITCH_PORT(20, 21, qsgmii)
		SWITCH_PORT(21, 22, qsgmii)
		SWITCH_PORT(22, 23, qsgmii)
		SWITCH_PORT(23, 24, qsgmii)

		SWITCH_PORT(24, 25, qsgmii)
		SWITCH_PORT(25, 26, qsgmii)
		SWITCH_PORT(26, 27, qsgmii)
		SWITCH_PORT(27, 28, qsgmii)
		SWITCH_PORT(28, 29, qsgmii)
		SWITCH_PORT(29, 30, qsgmii)
		SWITCH_PORT(30, 31, qsgmii)
		SWITCH_PORT(31, 32, qsgmii)

		SWITCH_PORT(32, 33, qsgmii)
		SWITCH_PORT(33, 34, qsgmii)
		SWITCH_PORT(34, 35, qsgmii)
		SWITCH_PORT(35, 36, qsgmii)
		SWITCH_PORT(36, 37, qsgmii)
		SWITCH_PORT(37, 38, qsgmii)
		SWITCH_PORT(38, 39, qsgmii)
		SWITCH_PORT(39, 40, qsgmii)

		SWITCH_PORT(40, 41, qsgmii)
		SWITCH_PORT(41, 42, qsgmii)
		SWITCH_PORT(42, 43, qsgmii)
		SWITCH_PORT(43, 44, qsgmii)
		SWITCH_PORT(44, 45, qsgmii)
		SWITCH_PORT(45, 46, qsgmii)
		SWITCH_PORT(46, 47, qsgmii)
		SWITCH_PORT(47, 48, qsgmii)

		SWITCH_PORT(48, 50, qsgmii)
		SWITCH_PORT(49, 52, qsgmii)
		SWITCH_PORT(50, 49, qsgmii)
		SWITCH_PORT(51, 51, qsgmii)

		port@52 {
			ethernet = <&ethernet0>;
			reg = <52>;
			phy-mode = "internal";
			fixed-link {
				speed = <1000>;
				full-duplex;
			};
		};
	};
};