// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2017 T-Chip Intelligent Technology Co., Ltd
 */

/dts-v1/;
#include "rk3399-roc-pc.dtsi"

/*
 * Notice:
 * 1. rk3399-roc-pc-plus is powered by dc_12v directly.
 * 2. rk3399-roc-pc-plus has only vcc_bus_typec0 in schematic, which is coresponding
 *    to vcc_vbus_typec1 in rk3399-roc-pc.
 *    For simplicity, reserve the node name of vcc_vbus_typec1.
 * 3. vcc5v0_host is actually 2 regulators (host0, 1) controlled by the same gpio.
 */

/delete-node/ &fusb1;
/delete-node/ &hub_rst;
/delete-node/ &mp8859;
/delete-node/ &vcc_sys_en;
/delete-node/ &vcc_vbus_typec0;
/delete-node/ &yellow_led;

/ {
	model = "Firefly ROC-RK3399-PC-PLUS Board";
	compatible = "firefly,roc-rk3399-pc-plus", "rockchip,rk3399";

	dc_12v: regulator-dc-12v {
		compatible = "regulator-fixed";
		regulator-name = "dc_12v";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <12000000>;
		regulator-max-microvolt = <12000000>;
	};

	es8388-sound {
		compatible = "simple-audio-card";
		pinctrl-names = "default";
		pinctrl-0 = <&hp_det_pin>;
		simple-audio-card,name = "rockchip,es8388-codec";
		simple-audio-card,format = "i2s";
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,widgets =
			"Microphone", "Mic Jack",
			"Headphone", "Headphones";
		simple-audio-card,routing =
			"LINPUT1", "Mic Jack",
			"Headphone Amp INL", "LOUT2",
			"Headphone Amp INR", "ROUT2",
			"Headphones", "Headphone Amp OUTL",
			"Headphones", "Headphone Amp OUTR";
		simple-audio-card,hp-det-gpios = <&gpio2 RK_PA6 GPIO_ACTIVE_HIGH>;
		simple-audio-card,aux-devs = <&headphones_amp>;
		simple-audio-card,pin-switches = "Headphones";

		simple-audio-card,codec {
			sound-dai = <&es8388>;
		};

		simple-audio-card,cpu {
			sound-dai = <&i2s1>;
		};
	};

	gpio-fan {
		#cooling-cells = <2>;
		compatible = "gpio-fan";
		gpio-fan,speed-map = <0 0 3000 1>;
		gpios = <&gpio1 RK_PA1 GPIO_ACTIVE_HIGH>;
	};

	/delete-node/ gpio-keys;

	/* not amplifier, used as switcher only */
	headphones_amp: headphones-amp {
		compatible = "simple-audio-amplifier";
		pinctrl-names = "default";
		pinctrl-0 = <&ear_ctl_pin>;
		enable-gpios = <&gpio0 RK_PA2 GPIO_ACTIVE_HIGH>;
		sound-name-prefix = "Headphone Amp";
		VCC-supply = <&vcca3v0_codec>;
	};

	ir-receiver {
		linux,rc-map-name = "rc-khadas";
	};

	leds {
		pinctrl-names = "default";
		pinctrl-0 = <&work_led_pin>, <&diy_led_pin>;
	};
};

&fusb0 {
	vbus-supply = <&vcc_vbus_typec1>;
};

&i2c0 {
	hym8563: rtc@51 {
		compatible = "haoyu,hym8563";
		reg = <0x51>;
		interrupt-parent = <&gpio0>;
		interrupts = <RK_PA5 IRQ_TYPE_EDGE_FALLING>;
		#clock-cells = <0>;
		clock-output-names = "xin32k";
		pinctrl-names = "default";
		pinctrl-0 = <&hym8563_int>;
	};
};

&i2c1 {
	es8388: es8388@11 {
		compatible = "everest,es8388", "everest,es8328";
		reg = <0x11>;
		clocks = <&cru SCLK_I2S_8CH_OUT>;
		#sound-dai-cells = <0>;
		AVDD-supply = <&vcca3v0_codec>;
		DVDD-supply = <&vcca1v8_codec>;
		HPVDD-supply = <&vcca3v0_codec>;
		PVDD-supply = <&vcca1v8_codec>;
	};
};

&hym8563 {
	/delete-property/ clock-output-names;
};

/* <4 RK_PA0 1 &pcfg_pull_none> is used as i2s_8ch_mclk_pin */
&i2s0_8ch_bus {
	rockchip,pins =
		<3 RK_PD0 1 &pcfg_pull_none>,
		<3 RK_PD1 1 &pcfg_pull_none>,
		<3 RK_PD2 1 &pcfg_pull_none>,
		<3 RK_PD3 1 &pcfg_pull_none>,
		<3 RK_PD4 1 &pcfg_pull_none>,
		<3 RK_PD5 1 &pcfg_pull_none>,
		<3 RK_PD6 1 &pcfg_pull_none>,
		<3 RK_PD7 1 &pcfg_pull_none>;
};

&i2s0_8ch_bus_bclk_off {
	rockchip,pins =
		<3 RK_PD0 RK_FUNC_GPIO &pcfg_pull_none>,
		<3 RK_PD1 1 &pcfg_pull_none>,
		<3 RK_PD2 1 &pcfg_pull_none>,
		<3 RK_PD3 1 &pcfg_pull_none>,
		<3 RK_PD4 1 &pcfg_pull_none>,
		<3 RK_PD5 1 &pcfg_pull_none>,
		<3 RK_PD6 1 &pcfg_pull_none>,
		<3 RK_PD7 1 &pcfg_pull_none>;
};

&i2s1 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2s_8ch_mclk_pin>, <&i2s1_2ch_bus>;
	rockchip,playback-channels = <2>;
	rockchip,capture-channels = <2>;
	status = "okay";
};

&pinctrl {
	bt {
		bt_enable_h: bt-enable-h {
			rockchip,pins = <0 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		bt_host_wake_l: bt-host-wake-l {
			rockchip,pins = <0 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		bt_wake_l: bt-wake-l {
			rockchip,pins = <2 RK_PD2 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	es8388 {
		ear_ctl_pin: ear-ctl-pin {
			rockchip,pins = <0 RK_PA2 RK_FUNC_GPIO &pcfg_output_high>;
		};

		hp_det_pin: hp-det-pin {
			rockchip,pins = <2 RK_PA6 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};

	hym8563 {
		hym8563_int: hym8563-int {
			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	i2s1 {
		i2s_8ch_mclk_pin: i2s-8ch-mclk-pin {
			rockchip,pins = <4 RK_PA0 1 &pcfg_pull_none>;
		};
	};
};

&sdio_pwrseq {
	/delete-property/ clocks;
	/delete-property/ clock-names;
	post-power-on-delay-ms = <100>;
	power-off-delay-us = <500000>;
};

&sdio0 {
	#address-cells = <1>;
	#size-cells = <0>;
	bus-width = <4>;
	cap-sd-highspeed;
	cap-sdio-irq;
	keep-power-in-suspend;
	mmc-pwrseq = <&sdio_pwrseq>;
	non-removable;
	pinctrl-names = "default";
	pinctrl-0 = <&sdio0_bus4 &sdio0_cmd &sdio0_clk>;
	sd-uhs-sdr104;
	status = "okay";
};

&u2phy0 {
	status = "okay";

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

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

&u2phy1 {
	status = "okay";

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

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

&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_xfer &uart0_cts &uart0_rts>;
	status = "okay";

	bluetooth {
		compatible = "brcm,bcm43438-bt";
		clocks = <&rk808 1>;
		clock-names = "lpo";
		device-wakeup-gpios = <&gpio2 RK_PD2 GPIO_ACTIVE_HIGH>;
		host-wakeup-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_HIGH>;
		shutdown-gpios = <&gpio0 RK_PB1 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&bt_host_wake_l &bt_wake_l &bt_enable_h>;
	};
};

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

&vcc_sys {
	/* vcc_sys is fixed, not controlled by any gpio */
	/delete-property/ gpio;
	/delete-property/ pinctrl-names;
	/delete-property/ pinctrl-0;
};

&vcc5v0_host {
	pinctrl-names = "default";
	pinctrl-0 = <&vcc5v0_host_en>;
};

&work_led {
	linux,default-trigger = "default-on";
};