// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (C) 2023 Arm Ltd.
 */

/dts-v1/;

#include "sun50i-h616.dtsi"
#include "sun50i-h616-cpu-opp.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>

/ {
	model = "Transpeed 8K618-T";
	compatible = "transpeed,8k618-t", "allwinner,sun50i-h618";

	aliases {
		ethernet1 = &sdio_wifi;
		serial0 = &uart0;
	};

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

	reg_vcc5v: vcc5v {
		/* board wide 5V supply directly from the DC input */
		compatible = "regulator-fixed";
		regulator-name = "vcc-5v";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		regulator-always-on;
	};

	reg_vcc3v3: vcc3v3 {
		/* discrete 3.3V regulator */
		compatible = "regulator-fixed";
		regulator-name = "vcc-3v3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};

	wifi_pwrseq: pwrseq {
		compatible = "mmc-pwrseq-simple";
		clocks = <&rtc CLK_OSC32K_FANOUT>;
		clock-names = "ext_clock";
		pinctrl-0 = <&x32clk_fanout_pin>;
		pinctrl-names = "default";
		reset-gpios = <&pio 6 18 GPIO_ACTIVE_LOW>; /* PG18 */
	};
};

&cpu0 {
	cpu-supply = <&reg_dcdc2>;
};

&ehci0 {
	status = "okay";
};

&ehci1 {
	status = "okay";
};

&ir {
	status = "okay";
};

&mmc0 {
	vmmc-supply = <&reg_dldo1>;
	cd-gpios = <&pio 8 16 GPIO_ACTIVE_LOW>;	/* PI16 */
	bus-width = <4>;
	status = "okay";
};

&mmc1 {
	vmmc-supply = <&reg_dldo1>;
	vqmmc-supply = <&reg_aldo1>;
	mmc-pwrseq = <&wifi_pwrseq>;
	bus-width = <4>;
	non-removable;
	status = "okay";

	sdio_wifi: wifi@1 {
		reg = <1>;
	};
};

&mmc2 {
	vmmc-supply = <&reg_dldo1>;
	vqmmc-supply = <&reg_aldo1>;
	bus-width = <8>;
	non-removable;
	cap-mmc-hw-reset;
	mmc-ddr-1_8v;
	mmc-hs200-1_8v;
	status = "okay";
};

&ohci0 {
	status = "okay";
};

&ohci1 {
	status = "okay";
};

&r_i2c {
	status = "okay";

	axp313: pmic@36 {
		compatible = "x-powers,axp313a";
		reg = <0x36>;
		#interrupt-cells = <1>;
		interrupt-controller;

		vin1-supply = <&reg_vcc5v>;
		vin2-supply = <&reg_vcc5v>;
		vin3-supply = <&reg_vcc5v>;

		regulators {
			reg_aldo1: aldo1 {
				regulator-always-on;
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-name = "vcc-1v8-pll";
			};

			reg_dldo1: dldo1 {
				regulator-always-on;
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-name = "vcc-3v3-io-mmc";
			};

			reg_dcdc1: dcdc1 {
				regulator-always-on;
				regulator-min-microvolt = <810000>;
				regulator-max-microvolt = <990000>;
				regulator-name = "vdd-gpu-sys";
			};

			reg_dcdc2: dcdc2 {
				regulator-always-on;
				regulator-min-microvolt = <810000>;
				regulator-max-microvolt = <1100000>;
				regulator-name = "vdd-cpu";
			};

			reg_dcdc3: dcdc3 {
				regulator-always-on;
				regulator-min-microvolt = <1360000>;
				regulator-max-microvolt = <1360000>;
				regulator-name = "vdd-dram";
			};
		};
	};
};

&pio {
	vcc-pc-supply = <&reg_aldo1>;
	vcc-pg-supply = <&reg_dldo1>;
	vcc-ph-supply = <&reg_dldo1>;
	vcc-pi-supply = <&reg_dldo1>;
};

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

&uart1 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart1_pins>, <&uart1_rts_cts_pins>;
	uart-has-rtscts;
	status = "okay";
};

&usbotg {
	dr_mode = "host";	/* USB A type receptable */
	status = "okay";
};

&usbphy {
	status = "okay";
};
