// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * Copyright (C) 2022-2023 Steffen Trumtrar <kernel@pengutronix.de>
 * Copyright (C) Phytec GmbH 2019-2020 - All Rights Reserved
 * Author: Dom VOVARD <dom.vovard@linrt.com>.
 */

#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/leds/leds-pca9532.h>

/ {
	aliases {
		mmc0 = &sdmmc1;
		mmc1 = &sdmmc2;
		mmc2 = &sdmmc3;
		serial0 = &uart4;
		serial1 = &usart3;
		serial2 = &usart1;
	};

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

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

		key-home {
			label = "Home";
			gpios = <&gpioa 13 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_HOME>;
		};

		key-enter {
			label = "Enter";
			gpios = <&gpioa 14 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_ENTER>;
		};
	};

	sound {
		compatible = "audio-graph-card";
		label = "STM32MP1-PHYCORE";
		routing =
			"Playback", "MCLK", /* Set a route between "MCLK" and "playback" widgets */
			"Capture", "MCLK";
		dais = <&sai2b_port>,
		       <&sai2a_port>;
	};
};

&dcmi {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&dcmi_pins_d>;
	pinctrl-1 = <&dcmi_sleep_pins_d>;
};

&i2c1 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2c1_pins_b>;
	pinctrl-1 = <&i2c1_sleep_pins_b>;
	i2c-scl-rising-time-ns = <100>;
	i2c-scl-falling-time-ns = <7>;
	status = "okay";

	codec@18 {
		compatible = "ti,tlv320aic3007";
		reg = <0x18>;
		#sound-dai-cells = <0>;

		ai3x-micbias-vg = <2>;

		AVDD-supply = <&v3v3>;
		IOVDD-supply = <&v3v3>;
		DRVDD-supply = <&v3v3>;
		DVDD-supply = <&v1v8_audio>;

		clocks = <&sai2b>;

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

			tlv320_tx_endpoint: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&sai2b_endpoint>;
				frame-master;
				bitclock-master;
			};

			tlv320_rx_endpoint: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&sai2a_endpoint>;
				frame-master;
				bitclock-master;
			};
		};
	};

	touch@44 {
		compatible = "st,stmpe811";
		reg = <0x44>;
		interrupts = <3 IRQ_TYPE_EDGE_FALLING>;
		interrupt-parent = <&gpioi>;
		vio-supply = <&v3v3>;
		vcc-supply = <&v3v3>;
		st,sample-time = <4>;
		st,mod-12b = <1>;
		st,ref-sel = <0>;
		st,adc-freq = <1>;

		touchscreen {
			compatible = "st,stmpe-ts";
			st,ave-ctrl = <1>;
			st,touch-det-delay = <2>;
			st,settling = <2>;
			st,fraction-z = <7>;
			st,i-drive = <1>;
		};
	};

	leds@62 {
		compatible = "nxp,pca9533";
		reg = <0x62>;

		led-0 {
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_POWER;
			type = <PCA9532_TYPE_LED>;
		};

		led-1 {
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_POWER;
			type = <PCA9532_TYPE_LED>;
		};

		led-2 {
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_HEARTBEAT;
			type = <PCA9532_TYPE_LED>;
			linux,default-trigger = "heartbeat";
		};
	};
};

&ltdc {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&ltdc_pins_f>;
	pinctrl-1 = <&ltdc_sleep_pins_f>;
};

&m_can2 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&m_can2_pins_a>;
	pinctrl-1 = <&m_can2_sleep_pins_a>;
	status = "okay";
};

&sai2 {
	clocks = <&rcc SAI2>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
	clock-names = "pclk", "x8k", "x11k";
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sai2a_pins_d>, <&sai2b_pins_d>;
	pinctrl-1 = <&sai2a_sleep_pins_d>, <&sai2b_sleep_pins_d>;
	status = "okay";
};

&sai2a {
	dma-names = "rx";
	clocks = <&rcc SAI2_K>, <&sai2b>;
	clock-names = "sai_ck", "MCLK";
	#clock-cells = <0>;
	st,sync = <&sai2b 2>;

	sai2a_port: port {
		sai2a_endpoint: endpoint {
			remote-endpoint = <&tlv320_rx_endpoint>;
			mclk-fs = <256>;
			dai-tdm-slot-num = <2>;
			dai-tdm-slot-width = <16>;
		};
	};
};

&sai2b {
	dma-names = "tx";
	#clock-cells = <0>;

	sai2b_port: port {
		sai2b_endpoint: endpoint {
			remote-endpoint = <&tlv320_tx_endpoint>;
			mclk-fs = <256>;
			dai-tdm-slot-num = <2>;
			dai-tdm-slot-width = <16>;
		};
	};
};

&sdmmc1 {
	pinctrl-names = "default", "opendrain", "sleep";
	pinctrl-0 = <&sdmmc1_b4_pins_b>;
	pinctrl-1 = <&sdmmc1_b4_od_pins_b>;
	pinctrl-2 = <&sdmmc1_b4_sleep_pins_b>;
	cd-gpios = <&gpiof 3 GPIO_ACTIVE_LOW>;
	disable-wp;
	bus-width = <4>;
	vmmc-supply = <&v3v3>;
	st,neg-edge;
	status = "okay";
};

&spi1 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&spi1_pins_a>;
	pinctrl-1 = <&spi1_sleep_pins_a>;
	cs-gpios = <&gpioz 3 0>;
	status = "okay";
};

&timers5 {
	/* spare dmas for other usage */
	/delete-property/dmas;
	/delete-property/dma-names;
	pwm5: pwm {
		pinctrl-names = "default", "sleep";
		pinctrl-0 = <&pwm5_pins_c>;
		pinctrl-1 = <&pwm5_sleep_pins_c>;
	};
};

&uart4 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&uart4_pins_f>;
	pinctrl-1 = <&uart4_sleep_pins_f>;
	pinctrl-2 = <&uart4_idle_pins_f>;
	/delete-property/dmas;
	/delete-property/dma-names;
	status = "okay";
};

&usart1 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&usart1_pins_b &usart1_pins_a>;
	pinctrl-1 = <&usart1_sleep_pins_b &usart1_sleep_pins_a>;
	pinctrl-2 = <&usart1_idle_pins_b &usart1_idle_pins_a>;
	uart-has-rtscts;
	status = "okay";
};

&usart3 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&usart3_pins_a>;
	pinctrl-1 = <&usart3_sleep_pins_a>;
	pinctrl-2 = <&usart3_idle_pins_a>;
	status = "okay";
};

&usbh_ehci {
	status = "okay";
};

&usbh_ohci {
	status = "okay";
};

&usbotg_hs {
	phys = <&usbphyc_port1 0>;
	phy-names = "usb2-phy";
	status = "okay";
};

&usbphyc {
	status = "okay";
};

&usbphyc_port0 {
	phy-supply = <&vdd_usb>;
};

&usbphyc_port1 {
	phy-supply = <&vdd_usb>;
};