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

/dts-v1/;
#include <dt-bindings/input/input.h>
#include <dt-bindings/pwm/pwm.h>
#include <dt-bindings/display/media-bus-format.h>
#include"rk3288-firefly.dtsi"
#include"rk3288-rkisp1.dtsi"
#include "rk3288-linux.dtsi"

/ {
	model = "Firefly-RK3288";
	compatible = "firefly,firefly-rk3288", "rockchip,rk3288";

	/delete-node/ sdmmc-regulator;
	vcc_sd: sdmmc-regulator {
		compatible = "regulator-fixed";
		gpio = <&gpio7 11 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&sdmmc_pwr>;
		regulator-name = "vcc_sd";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		startup-delay-us = <100000>;
		vin-supply = <&vcc_io>;
	};

	vcc_lcd: vcc-lcd {
		compatible = "regulator-fixed";
		regulator-boot-on;
		enable-active-high;
		pinctrl-names = "default";
		pinctrl-0 = <&lcd_en>;
		regulator-name = "vcc_lcd";
		vin-supply = <&vcc_io>;
	};

	sound: sound {
		status = "okay";
		compatible = "simple-audio-card";
		simple-audio-card,format = "i2s";
		simple-audio-card,name = "rockchip,firefly-codec";
		simple-audio-card,mclk-fs = <512>;
		simple-audio-card,widgets =
			"Microphone", "Microphone Jack",
			"Headphone", "Headphone Jack";
		simple-audio-card,routing =
			"MIC1", "Microphone Jack",
			"MIC2", "Microphone Jack",
			"Microphone Jack", "micbias1",
			"Headphone Jack", "HPOL",
			"Headphone Jack", "HPOR";

		simple-audio-card,dai-link@0 {
			format = "i2s";
			cpu {
				sound-dai = <&i2s>;
			};

			codec {
				sound-dai = <&es8323>;
			};
		};

		simple-audio-card,dai-link@1 {
			format = "i2s";
			cpu {
				sound-dai = <&i2s>;
			};

			codec {
				sound-dai = <&hdmi>;
			};
		};
	};

	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>;
		};
		simple-audio-card,codec {
			sound-dai = <&spdif_out>;
		};
	};

	backlight: backlight {
		pwms = <&pwm1 0 1000000 0>;
	};

	hdmi_analog_sound: hdmi-analog-sound {
		status = "disabled";
		rockchip,codec = <&es8323>, <&hdmi>;
	};

	vccadc_ref: vccadc-ref {
		compatible = "regulator-fixed";
		regulator-name = "vcc1v8_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
	};

	/*
	 * NOTE: vcc_sd isn't hooked up on v1.0 boards where power comes from
	 * vcc_io directly.  Those boards won't be able to power cycle SD cards
	 * but it shouldn't hurt to toggle this pin there anyway.
	 */

	wireless-bluetooth {
		clocks = <&hym8563>;
		clock-names = "ext_clock";
	};

	ext_cam_clk: external-camera-clock {
		compatible = "fixed-clock";
		clock-frequency = <27000000>;
		clock-output-names = "CLK_CAMERA_27MHZ";
		#clock-cells = <0>;
	};
};

&ir{
	/delete-property/ pinctrl-0;
};

&hdmi {
	#address-cells = <1>;
	#size-cells = <0>;
	#sound-dai-cells = <0>;
	status = "okay";
	ports {
		hdmi_in: port {
			#address-cells = <1>;
			#size-cells = <0>;
			hdmi_in_vopb: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&vopb_out_hdmi>;
			};
			hdmi_in_vopl: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&vopl_out_hdmi>;
			};
		};
	};
};

&hdmi_in_vopb {
	status = "disabled";
};

&hdmi_in_vopl {
	status = "okay";
};

&gmac {
	snps,reset-gpio = <&gpio4 7 0>;
	pinctrl-0 = <&rgmii_pins>;
	max-speed = <100>;
	status = "okay";
};

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

&sdmmc {
	sd-uhs-sdr12;
	sd-uhs-sdr25;
	sd-uhs-sdr50;
	sd-uhs-sdr104;
	pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_cd &sdmmc_bus4>;
	status = "okay";
};

&edp {
	status = "disabled";
};

&i2c0{
	/delete-node/ act8846@5a;
};

&i2c0 {
	act8846: act8846@5a {
		compatible = "active-semi,act8846";
		reg = <0x5a>;
		pinctrl-names = "default";
		pinctrl-0 = <&pmic_vsel>, <&pwr_hold>;
		system-power-controller;

		vp1-supply = <&vcc_sys>;
		vp2-supply = <&vcc_sys>;
		vp3-supply = <&vcc_sys>;
		vp4-supply = <&vcc_sys>;
		inl1-supply = <&vcc_sys>;
		inl2-supply = <&vcc_sys>;
		inl3-supply = <&vcc_20>;

		regulators {
			vcc_ddr: REG1 {
				regulator-name = "vcc_ddr";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <1200000>;
				regulator-always-on;
			};

			vcc_io: REG2 {
				regulator-name = "vcc_io";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-always-on;
			};

			vdd_log: REG3 {
				regulator-name = "vdd_log";
				regulator-min-microvolt = <1100000>;
				regulator-max-microvolt = <1100000>;
				regulator-always-on;
			};

			vcc_20: REG4 {
				regulator-name = "vcc_20";
				regulator-min-microvolt = <2000000>;
				regulator-max-microvolt = <2000000>;
				regulator-always-on;
			};

			vccio_sd: REG5 {
				regulator-name = "vccio_sd";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-always-on;
			};

			vdd10_lcd: REG6 {
				regulator-name = "vdd10_lcd";
				regulator-min-microvolt = <1000000>;
				regulator-max-microvolt = <1000000>;
				regulator-always-on;
			};

			vcca_33: REG7 {
				regulator-name = "vcca_33";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-always-on;
			};

			vcc_lan: REG8 {
				regulator-name = "vcc_lan";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-always-on;
				regulator-boot-on;
			};

			vcc_pmu: REG9 {
				regulator-name = "vcc_pmu";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-always-on;
			};

			vdd_10: REG10 {
				regulator-name = "vdd_10";
				regulator-min-microvolt = <1000000>;
				regulator-max-microvolt = <1000000>;
				regulator-always-on;
			};

			vccio_wl: vcc_18: REG11 {
				regulator-name = "vcc_18";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};

			vcc18_lcd: REG12 {
				regulator-name = "vcc18_lcd";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-always-on;
			};
		};
	};
};

&i2c1 {
	status = "okay";
	clock-frequency = <400000>;

	camera: tc358749@0f {
		compatible = "toshiba,tc358749";
		reg = <0x0f>;
		clocks = <&ext_cam_clk>;
		clock-names = "refclk";

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

		reset-gpios = <&gpio8 8 GPIO_ACTIVE_LOW>;

		interrupt-parent = <&gpio8>;
		interrupts = <9 IRQ_TYPE_LEVEL_LOW>;

		port {
			camera_out: endpoint {
				remote-endpoint = <&mipi_rx0_in>;
				clock-lanes = <0>;
				data-lanes = <1 2 3 4>;
				clock-noncontinuous;
				link-frequencies =
					/bits/ 64 <297000000>;
			};
		};
	};
};

&i2c2 {
	status = "okay";

	es8323: es8323@10 {
		status = "okay";
		compatible = "everest,es8323";
		reg = <0x10>;
		spk-con-gpio = <&gpio7 3 GPIO_ACTIVE_HIGH>;
		hp-det-gpio = <&gpio7 15 GPIO_ACTIVE_LOW>;
		clock-names = "mclk";
		clocks = <&cru SCLK_I2S0_OUT>;
		pinctrl-names = "default";
		pinctrl-0 = <&i2s0_mclk>;
		#sound-dai-cells = <0>;
	};
};

&i2c3 {
	status = "okay";
};

&i2c4 {
	status = "okay";
};

&i2s {
	#sound-dai-cells = <0>;
	status = "okay";
};

&pwm1 {
	status = "okay";
};

&isp {
	status = "okay";

	port {
		isp_mipi_in: endpoint {
			remote-endpoint = <&dphy_rx0_out>;
		};
	};
};

&isp_mmu {
	status = "okay";
};

&mipi_phy_rx0 {
	status = "okay";

	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;

			mipi_rx0_in: endpoint {
				remote-endpoint = <&camera_out>;
				data-lanes = <1 2 3 4>;
			};
		};

		port@1 {
			reg = <1>;

			dphy_rx0_out: endpoint {
				remote-endpoint = <&isp_mipi_in>;
			};
		};
	};
};

&vopb {
	status = "okay";
		vopb_out: port {
			vopb_out_edp: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&edp_in_vopb>;
			};
		};
};

&vopl {
	status = "okay";
	vopl_out: port {
		#address-cells = <1>;
		#size-cells = <0>;

		vopl_out_hdmi: endpoint@0 {
			reg = <0>;
			remote-endpoint = <&hdmi_in_vopl>;
		};
	};
};

&rga {
	status = "okay";
};

&tsadc {
	rockchip,hw-tshut-polarity = <1>; /* tshut polarity 0:LOW 1:HIGH */
};

&pinctrl {

	/* sata:gpio0 c1  */
	init-gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;

	pcfg_output_high: pcfg-output-high {
		output-high;
	};

	pcfg_output_low: pcfg-output-low {
		output-low;
	};
	pmic {
		pmic_int: pmic-int {
			rockchip,pins = <0 RK_PA4 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	lcd {
		lcd_cs: lcd-cs {
			rockchip,pins = <7 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		lcd_en: lcd-en  {
			rockchip,pins = <7 RK_PA3 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	act8846 {
		pmic_vsel: pmic-vsel {
			rockchip,pins = <7 RK_PB6 RK_FUNC_GPIO &pcfg_output_low>;
		};

		pwr_hold: pwr-hold {
			rockchip,pins = <0 RK_PA1 RK_FUNC_GPIO &pcfg_output_high>;
		};
	};

	backlight {
		bl_en: bl-en {
			rockchip,pins = <7 RK_PA2 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	buttons {
		pwrbtn: pwrbtn {
			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	hdmiin {
		hdmiin_gpios: hdmiin_gpios {
			rockchip,pins =
				<7 RK_PA5 RK_FUNC_GPIO &pcfg_output_high>,
				<7 RK_PC5 RK_FUNC_GPIO &pcfg_output_high>,
				<8 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>,
				<8 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	i2c1 {
		i2c1_xfer: i2c1-xfer {
			rockchip,pins = <8 RK_PA4 1 &pcfg_pull_up>,
				<8 RK_PA5 1 &pcfg_pull_up>;
		};
	};
};
