// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2024 Relfor Labs Pvt. Ltd.
 */


/dts-v1/;
#include "rv1109.dtsi"
#include <dt-bindings/leds/common.h>
#include <dt-bindings/input/input.h>

/ {
	model = "Rockchip RV1109 Relfor Saib Board";
	compatible = "relfor,saib", "rockchip,rv1109";

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

		button {
			gpios = <&gpio2 RK_PA7 GPIO_ACTIVE_HIGH>;
			linux,code = <KEY_DATA>;
			label = "GPIO User Switch";
			linux,input-type = <1>;
		};
	};

	ir_receiver: ir-receiver {
		compatible = "gpio-ir-receiver";
		gpios = <&gpio3  RK_PB4 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&ir_rx>;
	};

	ir_transmitter: ir-transmitter {
		compatible = "pwm-ir-tx";
		pwms = <&pwm11 0 10000000 1>;
	};

	led-controller {
		compatible = "pwm-leds-multicolor";

		multi-led {
			color = <LED_COLOR_ID_RGB>;
			function = LED_FUNCTION_INDICATOR;
			max-brightness = <65535>;

			led-0 {
				active-low;
				color = <LED_COLOR_ID_BLUE>;
				pwms = <&pwm9 0 50000 0>;
			};

			led-1 {
				active-low;
				color = <LED_COLOR_ID_GREEN>;
				pwms = <&pwm6 0 50000 0>;
			};

			led-2 {
				active-low;
				color = <LED_COLOR_ID_RED>;
				pwms = <&pwm10 0 50000 0>;
			};
		};
	};

	pwm-leds {
		compatible = "pwm-leds";

		led-0 {
			pwms = <&pwm2 0 50000 0>;
			max-brightness = <255>;
			linux,default-trigger = "none";
		};

		led-1 {
			pwms = <&pwm8 0 50000 0>;
			max-brightness = <0>;
			linux,default-trigger = "none";
		};

		led-2 {
			pwms = <&pwm5 0 50000 0>;
			max-brightness = <255>;
			linux,default-trigger = "none";
		};
	};

	sdio_pwrseq: pwrseq-sdio {
		compatible = "mmc-pwrseq-simple";
		clocks = <&rtc0>;
		clock-names = "ext_clock";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_enable_h>;
		reset-gpios = <&gpio1 RK_PD0 GPIO_ACTIVE_LOW>;
	};

	vcc_0v8: regulator-vcc-0v8 {
		compatible = "regulator-fixed";
		regulator-name = "vcc_0v8";
		regulator-min-microvolt = <800000>;
		regulator-max-microvolt = <800000>;
		regulator-always-on;
		regulator-boot-on;
		startup-delay-us = <150>;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc_1v2_ddr: regulator-vcc-1v2-ddr {
		compatible = "regulator-fixed";
		regulator-name = "vcc_1v2_ddr";
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1200000>;
		regulator-always-on;
		regulator-boot-on;
		startup-delay-us = <75000>;
		vin-supply = <&vcc5v0_sys>;
	};

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

	vcc1v8_ir: regulator-vcc1v8-ir {
		compatible = "regulator-fixed";
		regulator-name = "vcc1v8_ir";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-always-on;
		regulator-boot-on;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc_2v5_ddr: regulator-vcc-2v5-ddr {
		compatible = "regulator-fixed";
		regulator-name = "vcc_2v5_ddr";
		regulator-min-microvolt = <2500000>;
		regulator-max-microvolt = <2500000>;
		regulator-always-on;
		regulator-boot-on;
		vin-supply = <&vcc3v3_sys>;
	};

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

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

	vdd_arm: regulator-vdd-arm {
		compatible = "pwm-regulator";
		pwms = <&pwm0 0 5000 1>;
		regulator-name = "vdd_arm";
		regulator-min-microvolt = <720000>;
		regulator-max-microvolt = <1000000>;
		regulator-settling-time-up-us = <18000>;
		regulator-always-on;
		regulator-boot-on;
		pwm-supply = <&vcc3v3_sys>;
		vin-supply = <&vcc5v0_sys>;
	};

	vdd_npu_vepu: regulator-vdd-npu-vepu {
		compatible = "pwm-regulator";
		pwms = <&pwm1 0 5000 1>;
		regulator-name = "vdd_npu_vepu";
		regulator-min-microvolt = <650000>;
		regulator-max-microvolt = <950000>;
		regulator-settling-time-up-us = <18000>;
		regulator-always-on;
		regulator-boot-on;
		pwm-supply = <&vcc3v3_sys>;
		vin-supply = <&vcc5v0_sys>;
	};

	thermal_sensor1: thermal-sensor1 {
		compatible = "generic-adc-thermal";
		#thermal-sensor-cells = <0>;
		io-channels = <&saradc 1>;
		io-channel-names = "sensor-channel";
		temperature-lookup-table = <(-40000) 826
					     85000 609>;
	};

	thermal_sensor2: thermal-sensor2 {
		compatible = "generic-adc-thermal";
		#thermal-sensor-cells = <0>;
		io-channels = <&saradc 2>;
		io-channel-names = "sensor-channel";
		temperature-lookup-table = <(-40000) 826
					     85000 609>;
	};
};

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

&cpu1 {
	cpu-supply = <&vdd_arm>;
};

&emmc {
	bus-width = <8>;
	non-removable;
	pinctrl-0 = <&emmc_bus8 &emmc_cmd &emmc_clk>;
	pinctrl-names = "default";
	rockchip,default-sample-phase = <90>;
	vmmc-supply = <&vcc3v3_sys>;
	status = "okay";
};

&i2c3 {
	pinctrl-0 = <&i2c3m2_xfer>;
	pinctrl-names = "default";
	status = "okay";

	rtc0: rtc@52 {
		compatible = "microcrystal,rv3028";
		reg = <0x52>;
		#clock-cells = <0>;
		interrupt-parent = <&gpio2>;
		interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
		pinctrl-0 = <&rtc_int>;
		pinctrl-names = "default";
	};
};

&i2s0 {
	/delete-property/ pinctrl-0;
	rockchip,trcm-sync-rx-only;
	pinctrl-0 = <&i2s0m0_sclk_rx>,
		    <&i2s0m0_lrck_rx>,
		    <&i2s0m0_sdi0>;
	pinctrl-names = "default";
	status = "okay";
};

&pinctrl {
	bluetooth-pins {
		bt_reset: bt-reset {
			rockchip,pins =
			<1 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
		};
		bt_wake_dev: bt-wake-dev {
			rockchip,pins =
			<1 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
		bt_wake_host: bt-wake-host {
			rockchip,pins =
			<1 RK_PC6 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};

	buttons {
		switch: switch {
			rockchip,pins = <2 RK_PA7 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	ir {
		ir_rx: ir-rx {
			rockchip,pins = <3 RK_PB4 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	pwm {
		pwm0m0_pins_pull_up: pwm0m0-pins-pull-up {
			rockchip,pins =
			/* pwm0_pin_m0 */
			<0 RK_PB6 3 &pcfg_pull_up>;
		};
		pwm1m0_pins_pull_up: pwm1m0-pins-pull-up {
			rockchip,pins =
			/* pwm1_pin_m0 */
			<0 RK_PB7 3 &pcfg_pull_up>;
		};
	};

	rtc {
		rtc_int: rtc-int {
			rockchip,pins = <2 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

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

&pmu_io_domains {
	pmuio0-supply = <&vcc3v3_sys>;
	pmuio1-supply = <&vcc3v3_sys>;
	vccio4-supply = <&vcc3v3_sys>;
	vccio5-supply = <&vcc3v3_sys>;
	vccio6-supply = <&vcc3v3_sys>;
	vccio7-supply = <&vcc3v3_sys>;
	status = "okay";
};

&pwm0 {
	/delete-property/ pinctrl-0;
	pinctrl-0 = <&pwm0m0_pins_pull_up>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm1 {
	/delete-property/ pinctrl-0;
	pinctrl-0 = <&pwm1m0_pins_pull_up>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm2 {
	/delete-property/ pinctrl-0;
	pinctrl-0 = <&pwm2m1_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm5 {
	pinctrl-0 = <&pwm5m0_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm6 {
	pinctrl-0 = <&pwm6m0_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm8 {
	pinctrl-0 = <&pwm8m1_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm9 {
	pinctrl-0 = <&pwm9m1_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm10 {
	pinctrl-0 = <&pwm10m1_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&pwm11 {
	/delete-property/ pinctrl-0;
	pinctrl-0 = <&pwm11m1_pins>;
	pinctrl-names = "default";
	status = "okay";
};

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

&sdio {
	bus-width = <4>;
	cap-sd-highspeed;
	cap-sdio-irq;
	max-frequency = <100000000>;
	mmc-pwrseq = <&sdio_pwrseq>;
	no-mmc;
	no-sd;
	non-removable;
	pinctrl-0 = <&sdmmc1_clk &sdmmc1_cmd &sdmmc1_bus4>;
	pinctrl-names = "default";
	sd-uhs-sdr104;
	vmmc-supply = <&vcc3v3_sys>;
	status = "okay";
};

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

	bluetooth {
		compatible = "realtek,rtl8822cs-bt";
		device-wake-gpios = <&gpio1 RK_PC5 GPIO_ACTIVE_HIGH>;
		enable-gpios = <&gpio1 RK_PC4 GPIO_ACTIVE_HIGH>;
		host-wake-gpios = <&gpio1 RK_PC6 GPIO_ACTIVE_HIGH>;
		pinctrl-0 = <&bt_reset>, <&bt_wake_dev>, <&bt_wake_host>;
		pinctrl-names = "default";
	};
};

&uart2 {
	pinctrl-0 = <&uart2m1_xfer>;
	pinctrl-names = "default";
	status = "okay";
};