// SPDX-License-Identifier: GPL-2.0-or-later
/dts-v1/;

#include "rtl931x.dtsi"

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

/ {
	compatible = "hasivo,f5800w-12s-plus", "realtek,rtl9313-soc";
	model = "Hasivo F5800W-12S+";

	memory@0 {
		device_type = "memory";
		reg = <0x00000000 0x10000000>, /* 256 MiB lowmem */
		      <0x90000000 0x10000000>; /* 256 MiB highmem */
	};

	chosen {
		stdout-path = "serial0:38400n8";
	};

	keys {
		compatible = "gpio-keys";

		button-reset {
			label = "reset";
			gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};
	};

	led_set {
		compatible = "realtek,rtl9300-leds";
		active-low;

		led_set1 = <
		( // Green lower row - 2.5G/1G link
			RTL93XX_LED_SET_2P5G |
			RTL93XX_LED_SET_1G |
			RTL93XX_LED_SET_LINK |
			RTL93XX_LED_SET_ACT
		)
		( // Green upper row - 10G link
			RTL93XX_LED_SET_10G |
			RTL93XX_LED_SET_LINK |
			RTL93XX_LED_SET_ACT
		)>;
	};

	i2c_sys: i2c-system {
		compatible = "i2c-gpio";
		#address-cells = <1>;
		#size-cells = <0>;

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

		scl-gpios = <&gpio0 4 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		sda-gpios = <&gpio0 3 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
		i2c-gpio,delay-us = <28>;

		rtc@51 {
			compatible = "nxp,pcf8563";
			reg = <0x51>;
		};

		mcu_mgmt: mcu@6f {
			compatible = "hasivo,stc8-mfd", "syscon";
			reg = <0x6f>;

			mcu_wdt: watchdog {
				compatible = "hasivo,mcu-wdt";
			};

			sensor {
				compatible = "hasivo,mcu-sensor";
			};
		};
	};

	sfp1: sfp-p1 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c1_sda0>;
		los-gpios = <&gpio0 8 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>;
	};

	sfp2: sfp-p2 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c1_sda1>;
		los-gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>;
	};

	sfp3: sfp-p3 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c1_sda2>;
		los-gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio0 29 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>;
	};

	sfp4: sfp-p4 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c1_sda3>;
		los-gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio1 1 GPIO_ACTIVE_HIGH>;
	};

	sfp5: sfp-p5 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c1_sda4>;
		los-gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio1 3 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
	};

	sfp6: sfp-p6 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c1_sda5>;
		los-gpios = <&gpio0 20 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
	};

	sfp7: sfp-p7 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c2_sda6>;
		los-gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>;
	};

	sfp8: sfp-p8 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c2_sda7>;
		los-gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio1 32 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio1 33 GPIO_ACTIVE_HIGH>;
	};

	sfp9: sfp-p9 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c2_sda8>;
		los-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio1 36 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio2 0 GPIO_ACTIVE_HIGH>;
	};

	sfp10: sfp-p10 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c2_sda9>;
		los-gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio2 2 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio2 3 GPIO_ACTIVE_HIGH>;
	};

	sfp11: sfp-p11 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c2_sda10>;
		los-gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio2 6 GPIO_ACTIVE_HIGH>;
	};

	sfp12: sfp-p12 {
		compatible = "sff,sfp";
		i2c-bus = <&i2c2_sda11>;
		los-gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>;
		mod-def0-gpios = <&gpio2 8 GPIO_ACTIVE_LOW>;
		tx-disable-gpios = <&gpio2 9 GPIO_ACTIVE_HIGH>;
	};
};

&i2c_mst1 {
	status = "okay";

	i2c1_sda0: i2c@0 { reg = <0>; };
	i2c1_sda1: i2c@1 { reg = <1>; };
	i2c1_sda2: i2c@2 { reg = <2>; };
	i2c1_sda3: i2c@3 { reg = <3>; };
	i2c1_sda4: i2c@4 { reg = <4>; };
	i2c1_sda5: i2c@5 { reg = <5>; };
};

&i2c_mst2 {
	status = "okay";

	i2c2_sda6: i2c@6 { reg = <6>; };
	i2c2_sda7: i2c@7 { reg = <7>; };
	i2c2_sda8: i2c@8 { reg = <8>; };
	i2c2_sda9: i2c@9 { reg = <9>; };
	i2c2_sda10: i2c@a { reg = <10>; };
	i2c2_sda11: i2c@b { reg = <11>; };
};

&mdio_aux {
	status = "okay";

	gpio1: gpio@0 {
		compatible = "realtek,rtl8231";
		reg = <0>;

		gpio-controller;
		#gpio-cells = <2>;
		gpio-ranges = <&gpio1 0 0 37>;

		led-controller {
			compatible = "realtek,rtl8231-leds";
			status = "disabled";
		};
	};

	gpio2: gpio@1 {
		compatible = "realtek,rtl8231";
		reg = <1>;

		gpio-controller;
		#gpio-cells = <2>;
		gpio-ranges = <&gpio2 0 0 37>;

		led-controller {
			compatible = "realtek,rtl8231-leds";
			status = "disabled";
		};
	};
};

&spi0 {
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <10000000>;

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

			/* stock is LOADER */
			partition@0 {
				label = "u-boot";
				reg = <0x0000000 0x00e0000>;
				read-only;
			};

			/* stock is BDINFO */
			partition@e0000 {
				label = "u-boot-env";
				reg = <0x00e0000 0x0010000>;
			};

			/* stock is SYSINFO */
			partition@f0000 {
				label = "u-boot-env2";
				reg = <0x00f0000 0x0010000>;
			};

			/* stock is CFG JFFS2 */
			partition@100000 {
				label = "jffs";
				reg = <0x0100000 0x0100000>;
			};

			/* stock is LOG JFFS2 */
			partition@200000 {
				label = "jffs2";
				reg = <0x0200000 0x0100000>;
			};

			/* stock is RUNTIME and RUNTIME2
			 * RUNTIME is <0x0300000 0x0700000>
			 * RUNTIME2 is <0x0a00000 0x1600000>
			 */
			partition@300000 {
				compatible = "openwrt,uimage", "denx,uimage";
				label = "firmware";
				reg = <0x0300000 0x1d00000>;
			};
		};
	};
};

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

		SWITCH_PORT_SFP(0, 1, 2, 1, 1)
		SWITCH_PORT_SFP(8, 2, 3, 1, 2)
		SWITCH_PORT_SFP(16, 3, 4, 1, 3)
		SWITCH_PORT_SFP(24, 4, 5, 1, 4)
		SWITCH_PORT_SFP(32, 5, 6, 1, 5)
		SWITCH_PORT_SFP(40, 6, 7, 1, 6)
		SWITCH_PORT_SFP(48, 7, 8, 1, 7)
		SWITCH_PORT_SFP(50, 8, 9, 1, 8)
		SWITCH_PORT_SFP(52, 9, 10, 1, 9)
		SWITCH_PORT_SFP(53, 10, 11, 1, 10)
		SWITCH_PORT_SFP(54, 11, 12, 1, 11)
		SWITCH_PORT_SFP(55, 12, 13, 1, 12)

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

&serdes2 { tx-polarity = <PHY_POL_INVERT>; };
&serdes3 { tx-polarity = <PHY_POL_INVERT>; };
&serdes4 { tx-polarity = <PHY_POL_INVERT>; };
&serdes5 { tx-polarity = <PHY_POL_INVERT>; };
&serdes6 { tx-polarity = <PHY_POL_INVERT>; };
&serdes7 { tx-polarity = <PHY_POL_INVERT>; };
&serdes8 { tx-polarity = <PHY_POL_INVERT>; };
&serdes9 { tx-polarity = <PHY_POL_INVERT>; };
&serdes10 { tx-polarity = <PHY_POL_INVERT>; };
&serdes11 { tx-polarity = <PHY_POL_INVERT>; };
&serdes12 { tx-polarity = <PHY_POL_INVERT>; };
&serdes13 { tx-polarity = <PHY_POL_INVERT>; };
