// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2019 Akash Gajjar <akash@openedev.com>
 * Copyright (c) 2019 Jagan Teki <jagan@openedev.com>
 */

/dts-v1/;
#include "rk3308.dtsi"

/ {
	model = "Radxa ROCK Pi S";
	compatible = "radxa,rockpis", "rockchip,rk3308";

	aliases {
		ethernet0 = &gmac;
		mmc0 = &emmc;
		mmc1 = &sdmmc;
	};

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

	leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&green_led_gio>, <&heartbeat_led_gpio>;

		green-led {
			default-state = "on";
			gpios = <&gpio0 RK_PA6 GPIO_ACTIVE_HIGH>;
			label = "rockpis:green:power";
			linux,default-trigger = "default-on";
		};

		blue-led {
			default-state = "on";
			gpios = <&gpio0 RK_PA5 GPIO_ACTIVE_HIGH>;
			label = "rockpis:blue:user";
			linux,default-trigger = "heartbeat";
		};
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		pinctrl-0 = <&wifi_enable_h>;
		pinctrl-names = "default";
		reset-gpios = <&gpio0 RK_PA2 GPIO_ACTIVE_LOW>;
	};

	vcc_1v8: vcc-1v8 {
		compatible = "regulator-fixed";
		regulator-name = "vcc_1v8";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		vin-supply = <&vcc_io>;
	};

	vcc_io: vcc-io {
		compatible = "regulator-fixed";
		regulator-name = "vcc_io";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc_ddr: vcc-ddr {
		compatible = "regulator-fixed";
		regulator-name = "vcc_ddr";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1500000>;
		regulator-max-microvolt = <1500000>;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc5v0_otg: vcc5v0-otg {
		compatible = "regulator-fixed";
		enable-active-high;
		gpio = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&otg_vbus_drv>;
		regulator-name = "vcc5v0_otg";
		regulator-always-on;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc5v0_sys: vcc5v0-sys {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
	};

	vdd_core: vdd-core {
		compatible = "pwm-regulator";
		pwms = <&pwm0 0 5000 1>;
		pwm-supply = <&vcc5v0_sys>;
		regulator-name = "vdd_core";
		regulator-min-microvolt = <827000>;
		regulator-max-microvolt = <1340000>;
		regulator-settling-time-up-us = <250>;
		regulator-always-on;
		regulator-boot-on;
	};

	vdd_log: vdd-log {
		compatible = "regulator-fixed";
		regulator-name = "vdd_log";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1050000>;
		regulator-max-microvolt = <1050000>;
		vin-supply = <&vcc5v0_sys>;
	};
};

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

&emmc {
	bus-width = <4>;
	cap-mmc-highspeed;
	mmc-hs200-1_8v;
	non-removable;
	vmmc-supply = <&vcc_io>;
	status = "okay";
};

&gmac {
	clock_in_out = "output";
	phy-supply = <&vcc_io>;
	snps,reset-gpio = <&gpio0 RK_PA7 GPIO_ACTIVE_LOW>;
	snps,reset-active-low;
	snps,reset-delays-us = <0 50000 50000>;
	status = "okay";
};

&i2c1 {
	status = "okay";
};

&pinctrl {
	pinctrl-names = "default";
	pinctrl-0 = <&rtc_32k>;

	leds {
		green_led_gio: green-led-gpio {
			rockchip,pins = <0 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		heartbeat_led_gpio: heartbeat-led-gpio {
			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	usb {
		otg_vbus_drv: otg-vbus-drv {
			rockchip,pins = <0 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	sdio-pwrseq {
		wifi_enable_h: wifi-enable-h {
			rockchip,pins = <0 RK_PA2 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		wifi_host_wake: wifi-host-wake {
			rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};
};

&pwm0 {
	status = "okay";
	pinctrl-0 = <&pwm0_pin_pull_down>;
};

&saradc {
	vref-supply = <&vcc_1v8>;
	status = "okay";
};

&sdio {
	#address-cells = <1>;
	#size-cells = <0>;
	cap-sd-highspeed;
	cap-sdio-irq;
	keep-power-in-suspend;
	max-frequency = <1000000>;
	mmc-pwrseq = <&sdio_pwrseq>;
	non-removable;
	sd-uhs-sdr104;
	status = "okay";
};

&sdmmc {
	cap-sd-highspeed;
	status = "okay";
};

&u2phy {
	status = "okay";

	u2phy_host: host-port {
		phy-supply = <&vcc5v0_otg>;
		status = "okay";
	};

	u2phy_otg: otg-port {
		phy-supply = <&vcc5v0_otg>;
		status = "okay";
	};
};

&uart0 {
	status = "okay";
};

&uart4 {
	status = "okay";

	bluetooth {
		compatible = "realtek,rtl8723bs-bt";
		device-wake-gpios = <&gpio4 RK_PB3 GPIO_ACTIVE_HIGH>;
		host-wake-gpios = <&gpio4 RK_PB4 GPIO_ACTIVE_HIGH>;
	};
};

&usb_host_ehci {
	status = "okay";
};

&usb_host_ohci {
	status = "okay";
};

&usb20_otg {
	dr_mode = "peripheral";
	status = "okay";
};

&wdt {
	status = "okay";
};