// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2022 Theobroma Systems Design und Consulting GmbH
 */

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

/ {
	model = "Theobroma Systems PX30-uQ7 SoM on Haikou devkit";
	compatible = "tsd,px30-ringneck-haikou", "rockchip,px30";

	aliases {
		mmc2 = &sdmmc;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	gpio-keys {
		compatible = "gpio-keys";
		pinctrl-0 = <&haikou_keys_pin>;
		pinctrl-names = "default";

		button-batlow-n {
			label = "BATLOW#";
			linux,code = <KEY_BATTERY>;
			gpios = <&gpio3 RK_PA7 GPIO_ACTIVE_LOW>;
		};

		button-slp-btn-n {
			label = "SLP_BTN#";
			linux,code = <KEY_SLEEP>;
			gpios = <&gpio1 RK_PB7 GPIO_ACTIVE_LOW>;
		};

		button-wake-n {
			label = "WAKE#";
			linux,code = <KEY_WAKEUP>;
			gpios = <&gpio1 RK_PB6 GPIO_ACTIVE_LOW>;
			wakeup-source;
		};

		switch-lid-btn-n {
			label = "LID_BTN#";
			linux,code = <SW_LID>;
			linux,input-type = <EV_SW>;
			gpios = <&gpio3 RK_PA6 GPIO_ACTIVE_LOW>;
		};
	};

	leds {
		pinctrl-0 = <&module_led_pin>, <&sd_card_led_pin>;

		sd_card_led: led-1 {
			gpios = <&gpio3 RK_PB3 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "mmc2";
			function = LED_FUNCTION_SD;
			color = <LED_COLOR_ID_BLUE>;
		};
	};

	i2s0-sound {
		compatible = "simple-audio-card";
		simple-audio-card,format = "i2s";
		simple-audio-card,name = "Haikou,I2S-codec";
		simple-audio-card,mclk-fs = <512>;
		simple-audio-card,frame-master = <&sgtl5000_codec>;
		simple-audio-card,bitclock-master = <&sgtl5000_codec>;

		sgtl5000_codec: simple-audio-card,codec {
			sound-dai = <&sgtl5000>;
			// Prevent the dai subsystem from overwriting the clock
			// frequency. We are using a fixed-frequency oscillator.
			system-clock-fixed;
		};

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

	sgtl5000_clk: sgtl5000-oscillator {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency  = <24576000>;
	};

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

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

	vcc5v0_baseboard: vcc5v0-baseboard-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_baseboard";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&dc_12v>;
	};

	vdda_codec: vdda-codec-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vdda_codec";
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&vcc5v0_baseboard>;
	};

	vddd_codec: vddd-codec-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vddd_codec";
		regulator-boot-on;
		regulator-min-microvolt = <1600000>;
		regulator-max-microvolt = <1600000>;
		vin-supply = <&vcc5v0_baseboard>;
	};
};

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

	sgtl5000: codec@a {
		compatible = "fsl,sgtl5000";
		reg = <0x0a>;
		clocks = <&sgtl5000_clk>;
		#sound-dai-cells = <0>;
		VDDA-supply = <&vdda_codec>;
		VDDIO-supply = <&vcc3v3_baseboard>;
		VDDD-supply = <&vddd_codec>;
	};
};

&i2c3 {
	eeprom@50 {
		reg = <0x50>;
		compatible = "atmel,24c01";
		pagesize = <8>;
		size = <128>;
		vcc-supply = <&vcc3v3_baseboard>;
	};
};

&i2s0_8ch {
	status = "okay";
};

&gmac {
	status = "okay";
};

&pinctrl {
	haikou {
		haikou_keys_pin: haikou-keys-pin {
			rockchip,pins =
			  /* WAKE# */
			  <1 RK_PB6 RK_FUNC_GPIO &pcfg_pull_up>,
			  /* SLP_BTN# */
			  <1 RK_PB7 RK_FUNC_GPIO &pcfg_pull_up>,
			  /* LID_BTN */
			  <3 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>,
			  /* BATLOW# */
			  <3 RK_PA7 RK_FUNC_GPIO &pcfg_pull_up>,
			  /* BIOS_DISABLE# */
			  <2 RK_PC2 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	leds {
		sd_card_led_pin: sd-card-led-pin {
			rockchip,pins =
			  <3 RK_PB3 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&pwm0 {
	status = "okay";
};

&sdmmc {
	sd-uhs-sdr12;
	sd-uhs-sdr25;
	sd-uhs-sdr50;
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	cd-gpios = <&gpio0 RK_PA3 GPIO_ACTIVE_LOW>;
	disable-wp;
	vmmc-supply = <&vcc3v3_baseboard>;
	status = "okay";
};

&spi1 {
	status = "okay";
};

&u2phy_otg {
	status = "okay";
};

&uart0 {
	status = "okay";
};

&uart5 {
	pinctrl-0 = <&uart5_xfer>;
	status = "okay";
};

&usb20_otg {
	status = "okay";
};