// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Fii USA Inc.

/dts-v1/;
#include "nuvoton-npcm730.dtsi"

#include <dt-bindings/gpio/gpio.h>

/ {
	model = "Fii Kudo Board";
	compatible = "fii,kudo", "nuvoton,npcm730";

	aliases {
		ethernet1 = &gmac0;
		serial0 = &serial0;
		serial1 = &serial1;
		serial2 = &serial2;
		serial3 = &serial3;
		i2c1 = &i2c1;
		i2c2 = &i2c2;
		i2c3 = &i2c3;
		i2c4 = &i2c4;
		i2c5 = &i2c5;
		i2c6 = &i2c6;
		i2c7 = &i2c7;
		i2c8 = &i2c8;
		i2c9 = &i2c9;
		i2c10 = &i2c10;
		i2c11 = &i2c11;
		i2c12 = &i2c12;
		i2c13 = &i2c13;
		i2c14 = &i2c14;
		i2c15 = &i2c15;
		spi0 = &spi0;
		spi1 = &spi1;
		fiu0 = &fiu0;
		fiu1 = &fiu3;
	};

	chosen {
		stdout-path = &serial3;
	};

	memory {
		reg = <0 0x40000000>;
	};

	iio-hwmon {
		compatible = "iio-hwmon";
		io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 3>,
			<&adc 4>, <&adc 5>, <&adc 6>, <&adc 7>;
	};

	jtag_master {
		compatible = "nuvoton,npcm750-jtag-master";
		#address-cells = <1>;
		#size-cells = <1>;

		// dev/jtag0
		dev-num = <0>;
		// pspi or gpio
		mode = "pspi";

		// pspi2
		pspi-controller = <2>;
		reg = <0xf0201000 0x1000>;
		interrupts = <GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>;
		clocks = <&clk NPCM7XX_CLK_APB5>;

		// TCK, TDI, TDO, TMS
		jtag-gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>,
				<&gpio0 18 GPIO_ACTIVE_HIGH>,
				<&gpio0 17 GPIO_ACTIVE_HIGH>,
				<&gpio0 16 GPIO_ACTIVE_HIGH>;
	};

	leds {
		compatible = "gpio-leds";
		heartbeat {
			label = "heartbeat";
			gpios = <&gpio0 14 1>;
		};
	};

	pinctrl: pinctrl@f0800000 {
		gpio61oh_pins: gpio61oh-pins {
			pins = "GPO61/nDTR1_BOUT1/STRAP6";
			bias-disable;
			output-high;
		};
		gpio62oh_pins: gpio62oh-pins {
			pins = "GPO62/nRTST1/STRAP5";
			bias-disable;
			output-high;
		};
		gpio161ol_pins: gpio161ol-pins {
			pins = "GPIO161/nLFRAME/nESPICS";
			bias-disable;
			output-low;
		};
		gpio163i_pins: gpio163i-pins {
			pins = "GPIO163/LCLK/ESPICLK";
			bias-disable;
			input-enable;
		};
		gpio167ol_pins: gpio167ol-pins {
			pins = "GPIO167/LAD3/ESPI_IO3";
			bias-disable;
			output-low;
		};
		gpio95i_pins: gpio95i-pins {
			pins = "GPIO95/nLRESET/nESPIRST";
			bias-disable;
			input-enable;
		};
		gpio65ol_pins: gpio65ol-pins {
			pins = "GPIO65/FANIN1";
			bias-disable;
			output-low;
		};
		gpio66oh_pins: gpio66oh-pins {
			pins = "GPIO66/FANIN2";
			bias-disable;
			output-high;
		};
		gpio67oh_pins: gpio67oh-pins {
			pins = "GPIO67/FANIN3";
			bias-disable;
			output-high;
		};
		gpio68ol_pins: gpio68ol-pins {
			pins = "GPIO68/FANIN4";
			bias-disable;
			output-low;
		};
		gpio69i_pins: gpio69i-pins {
			pins = "GPIO69/FANIN5";
			bias-disable;
			input-enable;
		};
		gpio70ol_pins: gpio70ol-pins {
			pins = "GPIO70/FANIN6";
			bias-disable;
			output-low;
		};
		gpio71i_pins: gpio71i-pins {
			pins = "GPIO71/FANIN7";
			bias-disable;
			input-enable;
		};
		gpio72i_pins: gpio72i-pins {
			pins = "GPIO72/FANIN8";
			bias-disable;
			input-enable;
		};
		gpio73i_pins: gpio73i-pins {
			pins = "GPIO73/FANIN9";
			bias-disable;
			input-enable;
		};
		gpio74i_pins: gpio74i-pins {
			pins = "GPIO74/FANIN10";
			bias-disable;
			input-enable;
		};
		gpio75i_pins: gpio75i-pins {
			pins = "GPIO75/FANIN11";
			bias-disable;
			input-enable;
		};
		gpio76i_pins: gpio76i-pins {
			pins = "GPIO76/FANIN12";
			bias-disable;
			input-enable;
		};
		gpio77i_pins: gpio77i-pins {
			pins = "GPIO77/FANIN13";
			bias-disable;
			input-enable;
		};
		gpio78i_pins: gpio78i-pins {
			pins = "GPIO78/FANIN14";
			bias-disable;
			input-enable;
		};
		gpio79ol_pins: gpio79ol-pins {
			pins = "GPIO79/FANIN15";
			bias-disable;
			output-low;
		};
		gpio80oh_pins: gpio80oh-pins {
			pins = "GPIO80/PWM0";
			bias-disable;
			output-high;
		};
		gpio81i_pins: gpio81i-pins {
			pins = "GPIO81/PWM1";
			bias-disable;
			input-enable;
		};
		gpio82i_pins: gpio82i-pins {
			pins = "GPIO82/PWM2";
			bias-disable;
			input-enable;
		};
		gpio83i_pins: gpio83i-pins {
			pins = "GPIO83/PWM3";
			bias-disable;
			input-enable;
		};
		gpio144i_pins: gpio144i-pins {
			pins = "GPIO144/PWM4";
			bias-disable;
			input-enable;
		};
		gpio145i_pins: gpio145i-pins {
			pins = "GPIO145/PWM5";
			bias-disable;
			input-enable;
		};
		gpio146i_pins: gpio146i-pins {
			pins = "GPIO146/PWM6";
			bias-disable;
			input-enable;
		};
		gpio147oh_pins: gpio147oh-pins {
			pins = "GPIO147/PWM7";
			bias-disable;
			output-high;
		};
		gpio168ol_pins: gpio168ol-pins {
			pins = "GPIO168/nCLKRUN/nESPIALERT";
			bias-disable;
			output-low;
		};
		gpio169oh_pins: gpio169oh-pins {
			pins = "GPIO169/nSCIPME";
			bias-disable;
			output-high;
		};
		gpio170ol_pins: gpio170ol-pins {
			pins = "GPIO170/nSMI";
			bias-disable;
			output-low;
		};
		gpio218oh_pins: gpio218oh-pins {
			pins = "GPIO218/nWDO1";
			bias-disable;
			output-high;
		};
		gpio37i_pins: gpio37i-pins {
			pins = "GPIO37/SMB3CSDA";
			bias-disable;
			input-enable;
		};
		gpio38i_pins: gpio38i-pins {
			pins = "GPIO38/SMB3CSCL";
			bias-disable;
			input-enable;
		};
		gpio39i_pins: gpio39i-pins {
			pins = "GPIO39/SMB3BSDA";
			bias-disable;
			input-enable;
		};
		gpio40i_pins: gpio40i-pins {
			pins = "GPIO40/SMB3BSCL";
			bias-disable;
			input-enable;
		};
		gpio121i_pins: gpio121i-pins {
			pins = "GPIO121/SMB2CSCL";
			bias-disable;
			input-enable;
		};
		gpio122i_pins: gpio122i-pins {
			pins = "GPIO122/SMB2BSDA";
			bias-disable;
			input-enable;
		};
		gpio123i_pins: gpio123i-pins {
			pins = "GPIO123/SMB2BSCL";
			bias-disable;
			input-enable;
		};
		gpio124i_pins: gpio124i-pins {
			pins = "GPIO124/SMB1CSDA";
			bias-disable;
			input-enable;
		};
		gpio125i_pins: gpio125i-pins {
			pins = "GPIO125/SMB1CSCL";
			bias-disable;
			input-enable;
		};
		gpio126i_pins: gpio126i-pins {
			pins = "GPIO126/SMB1BSDA";
			bias-disable;
			input-enable;
		};
		gpio127i_pins: gpio127i-pins {
			pins = "GPIO127/SMB1BSCL";
			bias-disable;
			input-enable;
		};
		gpio136i_pins: gpio136i-pins {
			pins = "GPIO136/SD1DT0";
			bias-disable;
			input-enable;
		};
		gpio137oh_pins: gpio137oh-pins {
			pins = "GPIO137/SD1DT1";
			bias-disable;
			output-high;
		};
		gpio138i_pins: gpio138i-pins {
			pins = "GPIO138/SD1DT2";
			bias-disable;
			input-enable;
		};
		gpio139i_pins: gpio139i-pins {
			pins = "GPIO139/SD1DT3";
			bias-disable;
			input-enable;
		};
		gpio140i_pins: gpio140i-pins {
			pins = "GPIO140/SD1CLK";
			bias-disable;
			input-enable;
		};
		gpio141i_pins: gpio141i-pins {
			pins = "GPIO141/SD1WP";
			bias-disable;
			input-enable;
		};
		gpio190oh_pins: gpio190oh-pins {
			pins = "GPIO190/nPRD_SMI";
			bias-disable;
			output-high;
		};
		gpio191oh_pins: gpio191oh-pins {
			pins = "GPIO191";
			bias-disable;
			output-high;
		};
		gpio195ol_pins: gpio195ol-pins {
			pins = "GPIO195/SMB0BSDA";
			bias-disable;
			output-low;
		};
		gpio196ol_pins: gpio196ol-pins {
			pins = "GPIO196/SMB0CSCL";
			bias-disable;
			output-low;
		};
		gpio199i_pins: gpio199i-pins {
			pins = "GPIO199/SMB0DSCL";
			bias-disable;
			input-enable;
		};
		gpio202ol_pins: gpio202ol-pins {
			pins = "GPIO202/SMB0CSDA";
			bias-disable;
			output-low;
		};
	};
};

&gmac0 {
	phy-mode = "rgmii-id";
	snps,eee-force-disable;
	status = "okay";
};

&ehci1 {
	status = "okay";
};

&fiu0 {
	pinctrl-names = "default";
	pinctrl-0 = <&spi0cs1_pins>;
	status = "okay";
	flash@0 {
		compatible = "jedec,spi-nor";
		#address-cells = <1>;
		#size-cells = <1>;
		reg = <0>;
		spi-max-frequency = <5000000>;
		spi-rx-bus-width = <2>;
		label = "bmc";
		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;
			u-boot@0 {
				label = "u-boot";
				reg = <0x0000000 0xC0000>;
				read-only;
			};
			u-boot-env@100000{
				label = "u-boot-env";
				reg = <0x00100000 0x40000>;
			};
			kernel@200000 {
				label = "kernel";
				reg = <0x0200000 0x600000>;
			};
			rofs@800000 {
				label = "rofs";
				reg = <0x800000 0x3500000>;
			};
			rwfs@3d00000 {
				label = "rwfs";
				reg = <0x3d00000 0x300000>;
			};
		};
	};
	flash@1 {
		compatible = "jedec,spi-nor";
		#address-cells = <1>;
		#size-cells = <1>;
		reg = <1>;
		spi-max-frequency = <5000000>;
		spi-rx-bus-width = <2>;
		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;
			spare1@0 {
				label = "spi0-cs1-spare1";
				reg = <0x0 0x800000>;
			};
			spare2@800000 {
				label = "spi0-cs1-spare2";
				reg = <0x800000 0x0>;
			};
		};
	};
};

&fiu3 {
	pinctrl-0 = <&spi3_pins>;
	flash@0 {
		compatible = "jedec,spi-nor";
		#address-cells = <1>;
		#size-cells = <1>;
		reg = <0>;
		spi-max-frequency = <5000000>;
		spi-rx-bus-width = <2>;
		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;
			system1@0 {
				label = "bios";
				reg = <0x0 0x0>;
			};
			system2@800000 {
				label = "spi3-system2";
				reg = <0x800000 0x0>;
			};
		};
	};
};

&watchdog1 {
	status = "okay";
};

&rng {
	status = "okay";
};

&serial0 {
	status = "okay";
};

&serial1 {
	status = "okay";
};

&serial2 {
	status = "okay";
};

&serial3 {
	status = "okay";
};

&adc {
	#io-channel-cells = <1>;
	status = "okay";
};

&i2c1 {
	status = "okay";
	i2c-mux@75 {
		compatible = "nxp,pca9548";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0x75>;
		i2c-mux-idle-disconnect;

		i2c@2 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2>;

			// Rear-Fan
			max31790@58 {
				compatible = "maxim,max31790";
				reg = <0x58>;
			};
		};

		i2c@3 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <3>;

			// Mid-Fan
			max31790@58 {
				compatible = "maxim,max31790";
				reg = <0x58>;
			};
		};

		i2c-bus@4 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <4>;

			// INLET1_T
			lm75@5c {
				compatible = "ti,lm75";
				reg = <0x5c>;
			};
		};

		i2c-bus@5 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <5>;

			// OUTLET1_T
			lm75@5c {
				compatible = "ti,lm75";
				reg = <0x5c>;
			};
		};

		i2c-bus@6 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <6>;

			// OUTLET2_T
			lm75@5c {
				compatible = "ti,lm75";
				reg = <0x5c>;
			};
		};

		i2c-bus@7 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <7>;

			// OUTLET3_T
			lm75@5c {
				compatible = "ti,lm75";
				reg = <0x5c>;
			};
		};
	};
	i2c-mux@77 {
		compatible = "nxp,pca9548";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0x77>;
		i2c-mux-idle-disconnect;

		i2c-bus@2 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <2>;

			// STB-T
			pmbus@74 {
				compatible = "pmbus";
				reg = <0x74>;
			};
		};
	};
};

&i2c2 {
	status = "okay";
	smpro@4f {
		compatible = "ampere,smpro";
		reg = <0x4f>;
	};

	smpro@4e {
		compatible = "ampere,smpro";
		reg = <0x4e>;
	};
};

&i2c3 {
	status = "okay";
};

&i2c4 {
	status = "okay";
	i2c-mux@77 {
		compatible = "nxp,pca9548";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0x77>;
		i2c-mux-idle-disconnect;

		i2c-bus@0 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <0>;

			// ADC sensors
			adm1266@40 {
				compatible = "adi,adm1266";
				reg = <0x40>;
			};
		};

		i2c-bus@1 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <1>;

			// ADC sensors
			adm1266@41 {
				compatible = "adi,adm1266";
				reg = <0x41>;
			};
		};
	};
};

&i2c5 {
	status = "okay";
};

&i2c6 {
	status = "okay";
};

&i2c7 {
	status = "okay";
};

&i2c8 {
	status = "okay";
};

&i2c9 {
	status = "okay";
};

&i2c10 {
	status = "okay";
};

&i2c11 {
	status = "okay";
};

&i2c12 {
	status = "okay";
	ssif-bmc@10 {
		compatible = "ssif-bmc";
		reg = <0x10>;
	};
};

&i2c13 {
	status = "okay";
	i2c-mux@77 {
		compatible = "nxp,pca9548";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0x77>;
		i2c-mux-idle-disconnect;

		i2c-bus@3 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <3>;

			// M2_ZONE_T
			lm75@28 {
				compatible = "ti,lm75";
				reg = <0x28>;
			};
		};

		i2c-bus@4 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <4>;

			// BATT_ZONE_T
			lm75@29 {
				compatible = "ti,lm75";
				reg = <0x29>;
			};
		};

		i2c-bus@5 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <5>;

			// NBM1_ZONE_T
			lm75@28 {
				compatible = "ti,lm75";
				reg = <0x28>;
			};
		};
		i2c-bus@6 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <6>;

			// NBM2_ZONE_T
			lm75@29 {
				compatible = "ti,lm75";
				reg = <0x29>;
			};
		};
	};
};

&i2c14 {
	status = "okay";
};

&i2c15 {
	status = "okay";
};

&spi0 {
	cs-gpios = <&gpio6 11 GPIO_ACTIVE_LOW>;
	status = "okay";
};

&pinctrl {
	pinctrl-names = "default";
	pinctrl-0 = <
			&gpio61oh_pins
			&gpio62oh_pins
			&gpio161ol_pins
			&gpio163i_pins
			&gpio167ol_pins
			&gpio95i_pins
			&gpio65ol_pins
			&gpio66oh_pins
			&gpio67oh_pins
			&gpio68ol_pins
			&gpio69i_pins
			&gpio70ol_pins
			&gpio71i_pins
			&gpio72i_pins
			&gpio73i_pins
			&gpio74i_pins
			&gpio75i_pins
			&gpio76i_pins
			&gpio77i_pins
			&gpio78i_pins
			&gpio79ol_pins
			&gpio80oh_pins
			&gpio81i_pins
			&gpio82i_pins
			&gpio83i_pins
			&gpio144i_pins
			&gpio145i_pins
			&gpio146i_pins
			&gpio147oh_pins
			&gpio168ol_pins
			&gpio169oh_pins
			&gpio170ol_pins
			&gpio218oh_pins
			&gpio37i_pins
			&gpio38i_pins
			&gpio39i_pins
			&gpio40i_pins
			&gpio121i_pins
			&gpio122i_pins
			&gpio123i_pins
			&gpio124i_pins
			&gpio125i_pins
			&gpio126i_pins
			&gpio127i_pins
			&gpio136i_pins
			&gpio137oh_pins
			&gpio138i_pins
			&gpio139i_pins
			&gpio140i_pins
			&gpio141i_pins
			&gpio190oh_pins
			&gpio191oh_pins
			&gpio195ol_pins
			&gpio196ol_pins
			&gpio199i_pins
			&gpio202ol_pins
			>;
};

&gcr {
	serial_port_mux: mux-controller {
		compatible = "mmio-mux";
		#mux-control-cells = <1>;

		mux-reg-masks = <0x38 0x07>;
		idle-states = <2>;
	};
};