// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
// Copyright (c) 2023 ARM Ltd.

/dts-v1/;

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

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

/ {
	model = "Remix Mini PC";
	compatible = "jide,remix-mini-pc", "allwinner,sun50i-h64",
		     "allwinner,sun50i-a64";

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

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

	hdmi-connector {
		compatible = "hdmi-connector";
		type = "a";

		port {
			hdmi_con_in: endpoint {
				remote-endpoint = <&hdmi_out_con>;
			};
		};
	};

	reg_vcc5v: regulator-5v {
		/* 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;
	};

	wifi_pwrseq: pwrseq {
		compatible = "mmc-pwrseq-simple";
		reset-gpios = <&r_pio 0 2 GPIO_ACTIVE_LOW>; /* PL2 */
		post-power-on-delay-ms = <200>;
	};
};

&codec {
	status = "okay";
};

&codec_analog {
	cpvdd-supply = <&reg_eldo1>;
	status = "okay";
};

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

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

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

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

&dai {
	status = "okay";
};

&de {
	status = "okay";
};

&ehci0 {
	status = "okay";
};

&ehci1 {
	status = "okay";
};

&hdmi {
	hvcc-supply = <&reg_dldo1>;
	status = "okay";
};

&hdmi_out {
	hdmi_out_con: endpoint {
		remote-endpoint = <&hdmi_con_in>;
	};
};

/* Connects to the AC200 chip */
&i2c0 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c0_pins>;
	status = "okay";
};

&i2c0_pins {
	bias-pull-up;
};

&mmc0 {
	pinctrl-names = "default";
	pinctrl-0 = <&mmc0_pins>;
	vmmc-supply = <&reg_dcdc1>;
	cd-gpios = <&pio 5 6 GPIO_ACTIVE_LOW>;
	disable-wp;
	bus-width = <4>;
	status = "okay";
};

&mmc1 {
	pinctrl-names = "default";
	pinctrl-0 = <&mmc1_pins>;
	vmmc-supply = <&reg_aldo1>;
	vqmmc-supply = <&reg_dldo4>;
	mmc-pwrseq = <&wifi_pwrseq>;
	bus-width = <4>;
	non-removable;
	status = "okay";

	rtl8723bs: wifi@1 {
		reg = <1>;
		interrupt-parent = <&r_pio>;
		interrupts = <0 3 IRQ_TYPE_LEVEL_LOW>; /* PL3 */
		interrupt-names = "host-wake";
	};
};

&mmc2 {
	pinctrl-names = "default";
	pinctrl-0 = <&mmc2_pins>, <&mmc2_ds_pin>;
	vmmc-supply = <&reg_dcdc1>;
	vqmmc-supply = <&reg_eldo1>;
	bus-width = <8>;
	non-removable;
	mmc-hs200-1_8v;
	mmc-hs400-1_8v;
	cap-mmc-hw-reset;
	status = "okay";
};

&ohci0 {
	status = "okay";
};

&ohci1 {
	status = "okay";
};

&pio {
	vcc-pb-supply = <&reg_dcdc1>;
	vcc-pc-supply = <&reg_dcdc1>;
	vcc-pd-supply = <&reg_dcdc1>;
	vcc-pe-supply = <&reg_dcdc1>;
	vcc-pf-supply = <&reg_dcdc1>;
	vcc-pg-supply = <&reg_dldo4>;
	vcc-ph-supply = <&reg_dcdc1>;
};

&r_ir {
	status = "okay";
};

&r_pio {
	/*
	 * We cannot add that supply for now since it would create a circular
	 * dependency between pinctrl, the regulator and the RSB Bus.
	 *
	 * vcc-pl-supply = <&reg_aldo2>;
	 */
};

&r_rsb {
	status = "okay";

	axp803: pmic@3a3 {
		compatible = "x-powers,axp803";
		reg = <0x3a3>;
		interrupt-parent = <&r_intc>;
		interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
		x-powers,drive-vbus-en;

		vin1-supply = <&reg_vcc5v>;
		vin2-supply = <&reg_vcc5v>;
		vin3-supply = <&reg_vcc5v>;
		vin5-supply = <&reg_vcc5v>;
		vin6-supply = <&reg_vcc5v>;
		aldoin-supply = <&reg_vcc5v>;
		dldoin-supply = <&reg_vcc5v>;
		eldoin-supply = <&reg_vcc5v>;
		fldoin-supply = <&reg_vcc5v>;
		drivevbus-supply = <&reg_vcc5v>;
		ips-supply = <&reg_vcc5v>;

		status = "okay";
	};
};

#include "axp803.dtsi"

&ac_power_supply {
	status = "okay";
};

&reg_dcdc1 {
	regulator-always-on;
	regulator-min-microvolt = <3300000>;
	regulator-max-microvolt = <3300000>;
	regulator-name = "vcc-3v3";
};

&reg_dcdc2 {
	regulator-always-on;
	regulator-min-microvolt = <1040000>;
	regulator-max-microvolt = <1300000>;
	regulator-name = "vdd-cpux";
};

/* DCDC3 is polyphased with DCDC2 */

&reg_dcdc5 {
	regulator-always-on;
	regulator-min-microvolt = <1500000>;
	regulator-max-microvolt = <1500000>;
	regulator-name = "vcc-dram";
};

/* Deviates from the reset default of 1.1V. */
&reg_dcdc6 {
	regulator-always-on;
	regulator-min-microvolt = <1200000>;
	regulator-max-microvolt = <1200000>;
	regulator-name = "vdd-sys";
};

&reg_aldo1 {
	regulator-min-microvolt = <3300000>;
	regulator-max-microvolt = <3300000>;
	regulator-name = "vcc-wifi";
};

&reg_aldo2 {
	/* Specifying R_PIO consumer would create circular dependency. */
	regulator-always-on;
	regulator-min-microvolt = <3300000>;
	regulator-max-microvolt = <3300000>;
	regulator-name = "vcc-pl";
};

&reg_aldo3 {
	regulator-always-on;
	regulator-min-microvolt = <3000000>;
	regulator-max-microvolt = <3000000>;
	regulator-name = "vcc-pll-avcc";
};

/* AC200 power supply */
&reg_dldo1 {
	regulator-always-on;
	regulator-min-microvolt = <3300000>;
	regulator-max-microvolt = <3300000>;
	regulator-name = "vcc-ave-33";
};

&reg_dldo4 {
	regulator-min-microvolt = <3300000>;
	regulator-max-microvolt = <3300000>;
	regulator-name = "vcc-wifi-io";
};

&reg_drivevbus {
	regulator-name = "usb0-vbus";
	status = "okay";
};

&reg_eldo1 {
	regulator-always-on;
	regulator-min-microvolt = <1800000>;
	regulator-max-microvolt = <1800000>;
	regulator-name = "vcc-cpvdd-dram-emmc";
};

/* Supplies the arisc management core, needed by TF-A to power off cores. */
&reg_fldo2 {
	regulator-always-on;
	regulator-min-microvolt = <1100000>;
	regulator-max-microvolt = <1100000>;
	regulator-name = "vdd-cpus";
};

&reg_rtc_ldo {
	regulator-name = "vcc-rtc";
};

&simplefb_hdmi {
	vcc-hdmi-supply = <&reg_dcdc1>;
};

&sound {
	simple-audio-card,aux-devs = <&codec_analog>;
	simple-audio-card,widgets = "Microphone", "Microphone Jack",
				    "Headphone", "Headphone Jack";
	simple-audio-card,routing =
			"Left DAC", "DACL",
			"Right DAC", "DACR",
			"Headphone Jack", "HP",
			"ADCL", "Left ADC",
			"ADCR", "Right ADC",
			"MIC2", "Microphone Jack";
	status = "okay";
};

/* On the (unpopulated) UART pads. */
&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_pb_pins>;
	status = "okay";
};

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

	bluetooth {
		compatible = "realtek,rtl8723bs-bt";
		enable-gpios = <&r_pio 0 4 GPIO_ACTIVE_HIGH>; /* PL4 */
		max-speed = <1500000>;
	};
};

&usb_otg {
	dr_mode = "host";
	status = "okay";
};

&usbphy {
	usb0_vbus-supply = <&reg_drivevbus>;
	usb1_vbus-supply = <&reg_drivevbus>;
	status = "okay";
};
