// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/*
 * Copyright (c) 2026 SpacemiT (Hangzhou) Technology Co. Ltd
 * Copyright (c) 2026 Guodong Xu <guodong@riscstar.com>
 */
#include <dt-bindings/gpio/gpio.h>

#include "k3.dtsi"
#include "k3-pinctrl.dtsi"

/ {
	model = "SpacemiT K3 Pico-ITX";
	compatible = "spacemit,k3-pico-itx", "spacemit,k3";

	aliases {
		ethernet0 = &eth0;
		i2c2 = &i2c2;
		i2c8 = &i2c8;
		serial0 = &uart0;
	};

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

	memory@100000000 {
		device_type = "memory";
		reg = <0x1 0x00000000 0x4 0x00000000>;
	};

	reg_aux_vcc3v3: regulator-aux-vcc3v3 {
		compatible = "regulator-fixed";
		regulator-name = "AUX_VCC3V3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};

	reg_aux_vcc5v: regulator-aux-vcc5v {
		compatible = "regulator-fixed";
		regulator-name = "AUX_VCC5V";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		regulator-always-on;
	};

	rfkill-pcie-wlan {
		compatible = "rfkill-gpio";
		label = "rfkill-pcie-wlan";
		radio-type = "wlan";
		shutdown-gpios = <&gpio 1 3 GPIO_ACTIVE_HIGH>;
	};

	rfkill-usb-bt {
		compatible = "rfkill-gpio";
		label = "rfkill-usb-bt";
		radio-type = "bluetooth";
		shutdown-gpios = <&gpio 0 30 GPIO_ACTIVE_HIGH>;
	};
};

&i2c2 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c2_1_cfg>;
	status = "okay";

	eeprom@50 {
		compatible = "atmel,24c02";
		reg = <0x50>;
		pagesize = <8>;
		read-only;
		size = <256>;
		status = "okay";

		nvmem-layout {
			compatible = "onie,tlv-layout";

			mac-address {
				#nvmem-cell-cells = <1>;
			};

			num-macs {
			};

			part-number {
			};

			product-name {
			};

			serial-number {
			};

		};
	};
};

&i2c8 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c8_cfg>;
	status = "okay";

	p1@41 {
		compatible = "spacemit,p1";
		reg = <0x41>;
		interrupts = <64 IRQ_TYPE_LEVEL_HIGH>;
		vin1-supply = <&reg_aux_vcc5v>;
		vin2-supply = <&reg_aux_vcc5v>;
		vin3-supply = <&reg_aux_vcc5v>;
		vin4-supply = <&reg_aux_vcc5v>;
		vin5-supply = <&reg_aux_vcc5v>;
		vin6-supply = <&reg_aux_vcc5v>;
		aldoin-supply = <&reg_aux_vcc5v>;
		dldoin1-supply = <&buck4>;
		dldoin2-supply = <&buck4>;

		regulators {
			buck1: buck1 {
				regulator-min-microvolt = <1050000>;
				regulator-max-microvolt = <1050000>;
				regulator-ramp-delay = <5000>;
				regulator-always-on;
			};

			buck2: buck2 {
				regulator-min-microvolt = <1050000>;
				regulator-max-microvolt = <1050000>;
				regulator-ramp-delay = <5000>;
				regulator-always-on;
			};

			buck3: buck3 {
				regulator-min-microvolt = <800000>;
				regulator-max-microvolt = <800000>;
				regulator-ramp-delay = <5000>;
				regulator-always-on;
			};

			buck4: buck4 {
				regulator-min-microvolt = <2100000>;
				regulator-max-microvolt = <2100000>;
				regulator-ramp-delay = <5000>;
				regulator-always-on;
			};

			buck5: buck5 {
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-ramp-delay = <5000>;
				regulator-always-on;
			};

			buck6: buck6 {
				regulator-min-microvolt = <500000>;
				regulator-max-microvolt = <500000>;
				regulator-ramp-delay = <5000>;
				regulator-always-on;
			};

			aldo1: aldo1 {
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3300000>;
				regulator-always-on;
				regulator-boot-on;
			};

			aldo2: aldo2 {
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
				regulator-boot-on;
			};

			aldo3: aldo3 {
				regulator-min-microvolt = <500000>;
				regulator-max-microvolt = <3400000>;
			};

			aldo4: aldo4 {
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-always-on;
				regulator-boot-on;
			};

			dldo1: dldo1 {
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <1200000>;
				regulator-always-on;
				regulator-boot-on;
			};

			dldo2: dldo2 {
				regulator-min-microvolt = <900000>;
				regulator-max-microvolt = <900000>;
				regulator-always-on;
				regulator-boot-on;
			};

			dldo3: dldo3 {
				regulator-min-microvolt = <800000>;
				regulator-max-microvolt = <800000>;
				regulator-always-on;
				regulator-boot-on;
			};

			dldo4: dldo4 {
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-boot-on;
			};

			dldo5: dldo5 {
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
				regulator-boot-on;
			};

			dldo6: dldo6 {
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
				regulator-boot-on;
			};

			dldo7: dldo7 {
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
				regulator-boot-on;
			};
		};
	};
};

&combophy {
	spacemit,apmu = <&syscon_apmu 0x11>;
	status = "okay";
};

&eth0 {
	pinctrl-names = "default";
	pinctrl-0 = <&gmac0_rgmii_0_cfg>, <&gmac0_phy_0_cfg>;
	phy-mode = "rgmii-id";
	phy-handle = <&phy0>;
	status = "okay";

	mdio {
		phy0: ethernet-phy@1 {
			compatible = "ethernet-phy-id001c.c916";
			reg = <1>;
			reset-gpios = <&gpio 0 15 GPIO_ACTIVE_LOW>;
			reset-assert-us = <10000>;
			reset-deassert-us = <50000>;
			realtek,aldps-enable;
			realtek,clkout-disable;
		};
	};
};

&qspi_cfg {
	qspi-pins {
		power-source = <1800>;
	};

	qspi-cs0-pins {
		power-source = <1800>;
	};
};

&qspi {
	pinctrl-names = "default";
	pinctrl-0 = <&qspi_cfg>;
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <26500000>;
		spi-rx-bus-width = <4>;
		spi-tx-bus-width = <4>;
		vcc-supply = <&aldo2>; /* PMIC_VCC1V8_QSPI */
		m25p,fast-read;

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

			bootinfo@0 {
				reg = <0x0 0x20000>;
			};

			fsbl@20000 {
				reg = <0x20000 0x80000>;
			};

			env@a0000 {
				reg = <0xa0000 0x10000>;
			};

			esos@b0000 {
				reg = <0xb0000 0x100000>;
			};

			opensbi@1b0000 {
				reg = <0x1b0000 0x60000>;
			};

			uboot@210000 {
				reg = <0x210000 0x5f0000>;
			};
		};
	};
};

&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_0_cfg>;
	status = "okay";
};

&usb2_host {
	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	hub@1 {
		compatible = "usb1a40,0101";
		reg = <1>;
		vdd-supply = <&reg_aux_vcc3v3>;
	};
};

&usb2_phy {
	status = "okay";
};

&usb3b {
	phys = <&usb3b_u2phy>;
	phy-names = "usb2-phy";
	maximum-speed = "high-speed";
	status = "okay";
};

&usb3b_u2phy {
	status = "okay";
};

&usb3c {
	phys = <&usb3c_u2phy>;
	phy-names = "usb2-phy";
	maximum-speed = "high-speed";
	status = "okay";
};

&usb3c_u2phy {
	status = "okay";
};

&usb3d_u2phy {
	status = "okay";
};

&usb3d {
	phys = <&usb3d_u2phy>, <&combophy 4 PHY_TYPE_USB3>;
	phy-names = "usb2-phy", "usb3-phy";
	status = "okay";
};