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

#include "rk3568.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include <dt-bindings/input/rk-input.h>
#include <dt-bindings/display/drm_mipi_dsi.h>
#include <dt-bindings/sensor-dev.h>

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

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

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

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

	hdmi_sound: hdmi-sound {
		compatible = "simple-audio-card";
		simple-audio-card,format = "i2s";
		simple-audio-card,mclk-fs = <128>;
		simple-audio-card,name = "hdmi-sound";
		status = "okay";

		simple-audio-card,cpu {
				sound-dai = <&i2s0_8ch>;
		};
		simple-audio-card,codec {
				sound-dai = <&hdmi>;
		};
	};

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		rknpu_reserved: rknpu {
			compatible = "shared-dma-pool";
			inactive;
			reusable;
			size = <0x0 0x20000000>;
			alignment = <0x0 0x1000>;
		};
	};

	spdif-sound {
		status = "okay";
		compatible = "simple-audio-card";
		simple-audio-card,name = "ROCKCHIP,SPDIF";
		simple-audio-card,mclk-fs = <128>;
		simple-audio-card,cpu {
				sound-dai = <&spdif_8ch>;
		};
		simple-audio-card,codec {
				sound-dai = <&spdif_out>;
		};
	};

	spdif_out: spdif-out {
			status = "okay";
			compatible = "linux,spdif-dit";
			#sound-dai-cells = <0>;
	};

	vcc3v3_sys: vcc3v3-sys {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&dc_12v>;
	};

	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>;
		vin-supply = <&dc_12v>;
	};

	vcc5v0_host: vcc5v0-host-regulator {
		compatible = "regulator-fixed";
		enable-active-high;
		gpio = <&gpio0 RK_PA5 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc5v0_host_en>;
		regulator-name = "vcc5v0_host";
		regulator-always-on;
	};

	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 = <&vcc5v0_sys>;
	};

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

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

	vdd_logic: vdd-logic {
		compatible = "pwm-regulator";
		pwms = <&pwm1 0 5000 1>;
		regulator-name = "vdd_logic";
		regulator-min-microvolt = <800000>;
		regulator-max-microvolt = <1200000>;
		regulator-init-microvolt = <900000>;
		regulator-always-on;
		regulator-boot-on;
		regulator-settling-time-up-us = <250>;
		pwm-supply = <&vcc5v0_sys>;
		status = "okay";
	};

	vdd_npu: vdd-npu {
		compatible = "pwm-regulator";
		pwms = <&pwm2 0 5000 1>;
		regulator-name = "vdd_npu";
		regulator-min-microvolt = <800000>;
		regulator-max-microvolt = <1200000>;
		regulator-init-microvolt = <950000>;
		regulator-always-on;
		regulator-boot-on;
		regulator-settling-time-up-us = <250>;
		pwm-supply = <&vcc5v0_sys>;
		status = "okay";
	};
};

&bus_npu {
	bus-supply = <&vdd_logic>;
	pvtm-supply = <&vdd_cpu>;
	status = "okay";
};

&combphy0_us {
	status = "okay";
};

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

&cpu0_opp_table {
	/delete-node/ opp-1992000000;
};

&CPU_SLEEP {
	status = "disabled";
};

&dsi0_in_vp0 {
	status = "disabled";
};

&dsi0_in_vp1 {
	status = "okay";
};

&dsi1_in_vp0 {
	status = "disabled";
};

&dsi1_in_vp1 {
	status = "okay";
};

&edp {
	hpd-gpios = <&gpio4 RK_PC4 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

&edp_in_vp0 {
	status = "disabled";
};

&edp_in_vp1 {
	status = "okay";
};

&edp_phy {
	status = "okay";
};

&gpu {
	mali-supply = <&vdd_fixed>;
	status = "okay";
};

&gpu_opp_table {
	/delete-node/ opp-800000000;
};

&hdmi {
	skip-check-420-mode;
	status = "okay";
};

&hdmi_in_vp0 {
	status = "okay";
};

&hdmi_in_vp1 {
	status = "disabled";
};

&i2c0 {
	status = "okay";

	vdd_cpu: tcs4525@1c {
		compatible = "tcs,tcs4525";
		reg = <0x1c>;
		vin-supply = <&vcc5v0_sys>;
		regulator-compatible = "fan53555-reg";
		regulator-name = "vdd_cpu";
		regulator-min-microvolt = <712500>;
		regulator-max-microvolt = <1390000>;
		regulator-init-microvolt = <900000>;
		regulator-ramp-delay = <2300>;
		fcs,suspend-voltage-selector = <1>;
		regulator-boot-on;
		regulator-always-on;
		regulator-state-mem {
			regulator-off-in-suspend;
		};
	};
};

&i2s0_8ch {
	status = "okay";
};

&i2s1_8ch {
	status = "okay";
	rockchip,clk-trcm = <1>;
	pinctrl-names = "default";
	pinctrl-0 = <&i2s1m0_sclktx
		     &i2s1m0_lrcktx
		     &i2s1m0_sdi0
		     &i2s1m0_sdo0>;
};

&iep {
	status = "okay";
};

&iep_mmu {
	status = "okay";
};

&jpegd {
	status = "okay";
};

&jpegd_mmu {
	status = "okay";
};

&video_phy0 {
	status = "okay";
};

&video_phy1 {
	status = "okay";
};

&mpp_srv {
	status = "okay";
};

/* Need to be modified according to the actual hardware */
&pmu_io_domains {
	status = "okay";
	pmuio2-supply = <&vcc_3v3>;
	vccio1-supply = <&vcc_3v3>;
	vccio3-supply = <&vcc_3v3>;
	vccio4-supply = <&vcc_3v3>;
	vccio5-supply = <&vcc_3v3>;
	vccio6-supply = <&vcc_3v3>;
	vccio7-supply = <&vcc_3v3>;
};

&pwm1 {
	status = "okay";
	pinctrl-names = "active";
};

&pwm2 {
	status = "okay";
	pinctrl-names = "active";
};

&rk_rga {
	status = "okay";
};

&rknpu {
	memory-region = <&rknpu_reserved>;
	rknpu-supply = <&vdd_npu>;
	status = "okay";
};

&rknpu_mmu {
	status = "disabled";
};

&rkvdec {
	rockchip,disable-auto-freq;
	assigned-clock-rates = <396000000>, <396000000>, <396000000>, <600000000>;
	status = "okay";
};

&rkvdec_mmu {
	status = "okay";
};

&rkvdec_sram {
	reg = <0x0 0x10000>;
};

&rkvenc {
	status = "okay";
};

&rkvenc_mmu {
	status = "okay";
};

&route_hdmi {
	status = "okay";
	connect = <&vp0_out_hdmi>;
};

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

&sdhci {
	bus-width = <8>;
	no-sdio;
	no-sd;
	non-removable;
	status = "okay";
};

&sfc {
	status = "okay";

	flash@0 {
		compatible = "spi-nand";
		reg = <0>;
		spi-max-frequency = <75000000>;
		spi-rx-bus-width = <4>;
		spi-tx-bus-width = <1>;
	};
};

&spdif_8ch {
	status = "okay";
};

&sram {
	reg = <0x0 0xfdcc0000 0x0 0x10000>;
	ranges = <0x0 0x0 0xfdcc0000 0x10000>;
};

&tsadc {
	status = "okay";
};

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

&u2phy0_otg {
	phy-supply = <&vcc5v0_host>;
	status = "okay";
};

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

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

&usb2phy0 {
	status = "okay";
};

&usb2phy1 {
	status = "okay";
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usb_host1_ehci {
	status = "okay";
};

&usb_host1_ohci {
	status = "okay";
};

&usbdrd_dwc3 {
	dr_mode = "otg";
	extcon = <&usb2phy0>;
	status = "okay";
};

&usbdrd30 {
	status = "okay";
};

&usbhost_dwc3 {
	phys = <&u2phy0_host>;
	phy-names = "usb2-phy";
	maximum-speed = "high-speed";
	status = "okay";
};

&usbhost30 {
	status = "okay";
};

&vdpu {
	status = "okay";
};

&vdpu_mmu {
	status = "okay";
};

&vepu {
	status = "okay";
};

&vepu_mmu {
	status = "okay";
};

&vop {
	status = "okay";
	assigned-clocks = <&cru DCLK_VOP1>;
	assigned-clock-parents = <&cru PLL_VPLL>;
};

&vop_mmu {
	status = "okay";
};

&pinctrl {
	usb {
		vcc5v0_host_en: vcc5v0-host-en {
			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};
