// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (C) 2023 Martin Botka <martin.botka@somainline.org>.
 */

/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>
#include <dt-bindings/leds/common.h>

/ {
	aliases {
		ethernet0 = &rtl8189ftv;
	};

	leds {
		compatible = "gpio-leds";

		led-0 {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&pio 7 5 GPIO_ACTIVE_HIGH>; /* PH5 */
		};
	};

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

	reg_vcc33_wifi: vcc33-wifi {
		compatible = "regulator-fixed";
		regulator-name = "vcc33-wifi";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
		vin-supply = <&reg_vcc5v>;
	};

	reg_vcc_wifi_io: vcc-wifi-io {
		compatible = "regulator-fixed";
		regulator-name = "vcc-wifi-io";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-always-on;
		vin-supply = <&reg_vcc33_wifi>;
	};

	wifi_pwrseq: wifi-pwrseq {
		compatible = "mmc-pwrseq-simple";
		clocks = <&rtc 1>;
		clock-names = "ext_clock";
		reset-gpios = <&pio 6 18 GPIO_ACTIVE_LOW>; /* PG18 */
		post-power-on-delay-ms = <200>;
	};
};

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

&mmc0 {
	vmmc-supply = <&reg_dldo1>;
	/* Card detection pin is not connected */
	broken-cd;
	bus-width = <4>;
	status = "okay";
};

&mmc1 {
	vmmc-supply = <&reg_vcc33_wifi>;
	vqmmc-supply = <&reg_vcc_wifi_io>;
	mmc-pwrseq = <&wifi_pwrseq>;
	bus-width = <4>;
	non-removable;
	mmc-ddr-1_8v;
	status = "okay";

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

&r_i2c {
	status = "okay";

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

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

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

			reg_dcdc3: dcdc3 {
				regulator-name = "vcc-dram";
				regulator-min-microvolt = <1350000>;
				regulator-max-microvolt = <1500000>;
				regulator-always-on;
			};

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

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

&usbphy {
	status = "okay";
};
