// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd
 */

#include <dt-bindings/input/input.h>
#include "arm64/rockchip/rk3308.dtsi"

/ {
	model = "Rockchip RK3308 Voice Module Board V10";
	compatible = "rockchip,rk3308-vmb-v10", "rockchip,rk3308";

	chosen {
		bootargs = "earlycon=uart8250,mmio32,0xff0c0000 swiotlb=1 console=ttyFIQ0 root=PARTUUID=614e0000-0000 rootfstype=squashfs rootwait snd_aloop.index=7 snd_aloop.use_raw_jiffies=1";
	};

	adc-keys {
		compatible = "adc-keys";
		io-channels = <&saradc 1>;
		io-channel-names = "buttons";
		poll-interval = <100>;
		keyup-threshold-microvolt = <1800000>;

		esc-key {
			linux,code = <KEY_MICMUTE>;
			label = "micmute";
			press-threshold-microvolt = <1130000>;
		};

		home-key {
			linux,code = <KEY_MODE>;
			label = "mode";
			press-threshold-microvolt = <901000>;
		};

		menu-key {
			linux,code = <KEY_PLAY>;
			label = "play";
			press-threshold-microvolt = <624000>;
		};

		vol-down-key {
			linux,code = <KEY_VOLUMEDOWN>;
			label = "volume down";
			press-threshold-microvolt = <300000>;
		};

		vol-up-key {
			linux,code = <KEY_VOLUMEUP>;
			label = "volume up";
			press-threshold-microvolt = <18000>;
		};
	};

	dummy_codec: dummy-codec {
		compatible = "rockchip,dummy-codec";
		#sound-dai-cells = <0>;
	};

	gpio-keys {
		compatible = "gpio-keys";
		autorepeat;

		pinctrl-names = "default";
		pinctrl-0 = <&pwr_key>;

		power {
			gpios = <&gpio0 RK_PA6 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_POWER>;
			label = "GPIO Key Power";
			wakeup-source;
			debounce-interval = <100>;
		};
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_enable_h>;

		/*
		 * On the module itself this is one of these (depending
		 * on the actual card populated):
		 * - SDIO_RESET_L_WL_REG_ON
		 * - PDN (power down when low)
		 */
		reset-gpios = <&gpio0 RK_PA2 GPIO_ACTIVE_LOW>;
	};

	acodec_sound: acodec-sound {
		compatible = "rockchip,multicodecs-card";
		rockchip,card-name = "rockchip,rk3308-acodec";
		rockchip,codec-hp-det;
		rockchip,mclk-fs = <256>;
		rockchip,cpu = <&i2s_8ch_2>;
		rockchip,codec = <&acodec>;
		status = "disabled";
	};

	bluetooth_sound: bluetooth-sound {
		status = "disabled";
		compatible = "rockchip,multicodecs-card";
		rockchip,card-name = "rockchip,rk3308-pcm";
		rockchip,mclk-fs = <128>;
		rockchip,cpu = <&i2s_2ch_0>;
		rockchip,codec = <&dummy_codec>;
		rockchip,format = "dsp_a";
		rockchip,wait-card-locked = <0>;
	};

	spdif_tx_sound: spdif-tx-sound {
		status = "disabled";
		compatible = "simple-audio-card";
		simple-audio-card,name = "rockchip,spdif-tx-sound";
		simple-audio-card,cpu {
			sound-dai = <&spdif_tx>;
		};
		simple-audio-card,codec {
			sound-dai = <&dummy_codec>;
		};
	};

	vad-sound {
		status = "okay";
		compatible = "rockchip,multicodecs-card";
		rockchip,card-name = "rockchip,rk3308-vad";
		rockchip,codec-hp-det;
		rockchip,cpu = <&i2s_8ch_2>;
		rockchip,codec = <&acodec>, <&vad>;
	};

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

	vdd_1v0: vdd-1v0 {
		compatible = "regulator-fixed";
		regulator-name = "vdd_1v0";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1000000>;
		regulator-max-microvolt = <1000000>;
	};

	vccio_sdio: 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_ddr: vcc-ddr {
		compatible = "regulator-fixed";
		regulator-name = "vcc_ddr";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1500000>;
		regulator-max-microvolt = <1500000>;
	};

	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>;
	};

	vbus_host: vbus-host-regulator {
		compatible = "regulator-fixed";
		enable-active-high;
		gpio = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&usb_drv>;
		regulator-name = "vbus_host";
	};
};

&acodec {
	status = "disabled";

	rockchip,no-hp-det;
	rockchip,delay-start-play-ms = <200>;
	rockchip,loopback-grp = <1>;
	spk-ctl-gpios = <&gpio0 RK_PA5 GPIO_ACTIVE_HIGH>;
};

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

&dmc {
	center-supply = <&vdd_log>;
	status = "okay";
};

&fiq_debugger {
	status = "okay";
};

&io_domains {
	status = "okay";

	vccio0-supply = <&vcc_io>;
	vccio1-supply = <&vcc_io>;
	vccio2-supply = <&vcc_1v8>;
	vccio3-supply = <&vcc_io>;
	vccio4-supply = <&vccio_sdio>;
	vccio5-supply = <&vcc_io>;
};

&i2s_2ch_0 {
	status = "okay";
};

&i2s_8ch_2 {
	status = "okay";
};

&nandc {
	status = "okay";
};

&ramoops_mem {
	reg = <0x0 0x30000 0x0 0x20000>;
};

&ramoops {
	record-size = <0x0 0x00000>;
	console-size = <0x0 0x20000>;
};

&rk_timer_rtc {
	status = "okay";
};

&rockchip_suspend {
	rockchip,pwm-regulator-config = <
		(0
		| RKPM_PWM_REGULATOR
		)
	>;

	rockchip,wakeup-config = <
		(0
		| RKPM_GPIO0_WAKEUP_EN
		| RKPM_TIMER_WAKEUP_EN
		)
	>;

	status = "okay";
};

&rng {
	status = "okay";
};

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

&sdio {
	max-frequency = <110000000>;
	bus-width = <4>;
	cap-sd-highspeed;
	supports-sdio;
	ignore-pm-notify;
	keep-power-in-suspend;
	non-removable;
	mmc-pwrseq = <&sdio_pwrseq>;
	sd-uhs-sdr104;
	status = "okay";
};

&sdmmc {
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	supports-sd;
	card-detect-delay = <300>;
	status = "disabled";
};

&pinctrl {
	buttons {
		pwr_key: pwr-key {
			rockchip,pins = <0 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	usb {
		usb_drv: usb-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>;
		};
	};

	wireless-wlan {
		wifi_wake_host: wifi-wake-host {
			rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};
};

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

&sfc {
	u-boot,dm-pre-reloc;
	status = "okay";
};

&tsadc {
	rockchip,hw-tshut-mode = <0>; /* tshut mode 0:CRU 1:GPIO */
	rockchip,hw-tshut-polarity = <1>; /* tshut polarity 0:LOW 1:HIGH */
	status = "okay";
};

&u2phy {
	status = "okay";

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

	u2phy_otg: otg-port {
		status = "okay";
	};
};

&usb20_otg {
	status = "okay";
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci{
	status = "okay";
};

&vad {
	status = "okay";
	rockchip,audio-src = <&i2s_8ch_2>;
	rockchip,det-channel = <0>;
	rockchip,mode = <1>;
	rockchip,buffer-time-ms = <500>;
	#sound-dai-cells = <0>;
};