// SPDX-License-Identifier: (GPL-2.0+ OR MIT)

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/linux-event-codes.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include "rk3566-anbernic-rg353x.dtsi"

/ {
	model = "RG353V";
	compatible = "anbernic,rg353v", "rockchip,rk3566";

	aliases {
		mmc0 = &sdhci;
		mmc1 = &sdmmc0;
		mmc2 = &sdmmc1;
		mmc3 = &sdmmc2;
	};

	battery: battery {
		compatible = "simple-battery";
		charge-full-design-microamp-hours = <3151000>;
		charge-term-current-microamp = <300000>;
		constant-charge-current-max-microamp = <2000000>;
		constant-charge-voltage-max-microvolt = <4200000>;
		factory-internal-resistance-micro-ohms = <117000>;
		voltage-max-design-microvolt = <4172000>;
		voltage-min-design-microvolt = <3400000>;

		ocv-capacity-celsius = <20>;
		ocv-capacity-table-0 =  <4172000 100>, <4054000 95>, <3984000 90>, <3926000 85>,
					<3874000 80>, <3826000 75>, <3783000 70>, <3746000 65>,
					<3714000 60>, <3683000 55>, <3650000 50>, <3628000 45>,
					<3612000 40>, <3600000 35>, <3587000 30>, <3571000 25>,
					<3552000 20>, <3525000 15>, <3492000 10>, <3446000 5>,
					<3400000 0>;
	};

	/* Channels reversed for headphones. */
	sound {
		compatible = "simple-audio-card";
		simple-audio-card,name = "rk817_int";
		simple-audio-card,format = "i2s";
		simple-audio-card,hp-det-gpio = <&gpio4 RK_PC6 GPIO_ACTIVE_HIGH>;
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,widgets =
			"Microphone", "Mic Jack",
			"Headphone", "Headphones",
			"Speaker", "Internal Speakers";
		simple-audio-card,routing =
			"MICL", "Mic Jack",
			"Headphones", "HPOL",
			"Headphones", "HPOR",
			"Internal Speakers", "SPKO";

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

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

&gpio_keys_control {
	button-r1 {
		gpios = <&gpio3 RK_PB3 GPIO_ACTIVE_LOW>;
		label = "TR";
		linux,code = <BTN_TR>;
	};

	button-r2 {
		gpios = <&gpio3 RK_PB4 GPIO_ACTIVE_LOW>;
		label = "TR2";
		linux,code = <BTN_TR2>;
	};
};

&i2c2 {
	pintctrl-names = "default";
	pinctrl-0 = <&i2c2m1_xfer>;
	status = "okay";

	touch@1a {
		compatible = "hynitron,cst340";
		reg = <0x1a>;
		interrupt-parent = <&gpio4>;
		interrupts = <RK_PB1 IRQ_TYPE_EDGE_FALLING>;
		pinctrl-0 = <&touch_rst>;
		pinctrl-names = "default";
		reset-gpios = <&gpio4 RK_PA6 GPIO_ACTIVE_LOW>;
		touchscreen-size-x = <640>;
		touchscreen-size-y = <480>;
	};
};

&pinctrl {
	touch {
		touch_rst: touch-rst {
			rockchip,pins =
				<4 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};
};

&rk817 {
	rk817_charger: charger {
		monitored-battery = <&battery>;
		rockchip,resistor-sense-micro-ohms = <10000>;
		rockchip,sleep-enter-current-microamp = <300000>;
		rockchip,sleep-filter-current-microamp = <100000>;
	};
};

&sdhci {
	pinctrl-0 = <&emmc_bus8>, <&emmc_clk>, <&emmc_cmd>, <&emmc_datastrobe>, <&emmc_rstnout>;
	pinctrl-names = "default";
	bus-width = <8>;
	mmc-hs200-1_8v;
	non-removable;
	vmmc-supply = <&vcc_3v3>;
	vqmmc-supply = <&vcc_1v8>;
	status = "okay";
};