// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2019 Hardkernel Co., Ltd
 * Copyright (c) 2020 Theobroma Systems Design und Consulting GmbH
 * Copyright (c) 2022 Maya Matuszczyk <maccraft123mc@gmail.com>
 */

/dts-v1/;
#include "rk3326-odroid-go.dtsi"

/ {
	model = "ODROID-GO Advance Black Edition";
	compatible = "hardkernel,rk3326-odroid-go2-v11", "rockchip,rk3326";

	aliases {
		mmc1 = &sdio;
	};

	analog_sticks: adc-joystick {
		compatible = "adc-joystick";
		io-channels = <&saradc 1>,
			      <&saradc 2>;
		poll-interval = <60>;
		#address-cells = <1>;
		#size-cells = <0>;

		axis@0 {
			reg = <0>;
			abs-flat = <10>;
			abs-fuzz = <10>;
			abs-range = <172 772>;
			linux,code = <ABS_X>;
			};

		axis@1 {
			reg = <1>;
			abs-flat = <10>;
			abs-fuzz = <10>;
			abs-range = <278 815>;
			linux,code = <ABS_Y>;
		};
	};

	battery: battery {
		compatible = "simple-battery";
		charge-full-design-microamp-hours = <3000000>;
		charge-term-current-microamp = <300000>;
		constant-charge-current-max-microamp = <2000000>;
		constant-charge-voltage-max-microvolt = <4200000>;
		factory-internal-resistance-micro-ohms = <180000>;
		voltage-max-design-microvolt = <4100000>;
		voltage-min-design-microvolt = <3500000>;

		ocv-capacity-celsius = <20>;
		ocv-capacity-table-0 =  <4046950 100>, <4001920 95>, <3967900 90>, <3919950 85>,
					<3888450 80>, <3861850 75>, <3831540 70>, <3799130 65>,
					<3768190 60>, <3745650 55>, <3726610 50>, <3711630 45>,
					<3696720 40>, <3685660 35>, <3674950 30>, <3663050 25>,
					<3649470 20>, <3635260 15>, <3616920 10>, <3592440 5>,
					<3574170 0>;
	};

	wifi_pwrseq: wifi-pwrseq {
		compatible = "mmc-pwrseq-simple";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_pwrseq_pins>;
		reset-gpios = <&gpio3 RK_PB1 GPIO_ACTIVE_LOW>;
	};
};

&builtin_gamepad {
	button-sw20 {
		gpios = <&gpio3 RK_PB7 GPIO_ACTIVE_LOW>;
		label = "TOP-LEFT 2";
		linux,code = <BTN_TL2>;
	};
	button-sw21 {
		gpios = <&gpio3 RK_PB2 GPIO_ACTIVE_LOW>;
		label = "TOP-RIGHT 2";
		linux,code = <BTN_TR2>;
	};
};

&internal_display {
	compatible = "elida,kd35t133";
	iovcc-supply = <&vcc_lcd>;
	vdd-supply = <&vcc_lcd>;
};

&rk817 {
	regulators {
		vcc_wifi: LDO_REG9 {
			regulator-name = "vcc_wifi";
			regulator-min-microvolt = <3300000>;
			regulator-max-microvolt = <3300000>;

			regulator-state-mem {
				regulator-on-in-suspend;
				regulator-suspend-microvolt = <3300000>;
			};
		};
	};
};

&rk817_charger {
	monitored-battery = <&battery>;
};

&sdio {
	bus-width = <4>;
	cap-sd-highspeed;
	cap-sdio-irq;
	disable-wp;
	keep-power-in-suspend;
	mmc-pwrseq = <&wifi_pwrseq>;
	non-removable;
	vmmc-supply = <&vcc_wifi>;
	#address-cells = <1>;
	#size-cells = <0>;
	status = "okay";

	esp8089: wifi@1 {
		compatible = "esp,esp8089";
		reg = <1>;
	};
};

&pinctrl {
	btns {
		btn_pins: btn-pins {
			rockchip,pins = <1 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>,
					<1 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>,
					<1 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>,
					<1 RK_PA7 RK_FUNC_GPIO &pcfg_pull_up>,
					<1 RK_PB4 RK_FUNC_GPIO &pcfg_pull_up>,
					<1 RK_PB5 RK_FUNC_GPIO &pcfg_pull_up>,
					<1 RK_PB6 RK_FUNC_GPIO &pcfg_pull_up>,
					<1 RK_PB7 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA4 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>,
					<2 RK_PA7 RK_FUNC_GPIO &pcfg_pull_up>,
					<3 RK_PB2 RK_FUNC_GPIO &pcfg_pull_up>,
					<3 RK_PB7 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	wifi {
		wifi_pwrseq_pins: wifi-pwrseq-pins {
			rockchip,pins = <3 RK_PB1 RK_FUNC_GPIO &pcfg_pull_up>,
					<3 RK_PB6 RK_FUNC_GPIO &pcfg_output_high>;
		};
	};
};