// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2021 BayLibre SAS
 * Author: Neil Armstrong <narmstrong@baylibre.com>
 */

/dts-v1/;

#include "meson-sm1-bananapi.dtsi"
#include <dt-bindings/sound/meson-g12a-toacodec.h>
#include <dt-bindings/sound/meson-g12a-tohdmitx.h>

/ {
	compatible = "bananapi,bpi-m5", "amlogic,sm1";
	model = "Banana Pi BPI-M5";

	/* TOFIX: handle CVBS_DET on SARADC channel 0 */
	cvbs-connector {
		compatible = "composite-video-connector";

		port {
			cvbs_connector_in: endpoint {
				remote-endpoint = <&cvbs_vdac_out>;
			};
		};
	};

	sound {
		compatible = "amlogic,axg-sound-card";
		model = "BPI-M5";
		audio-widgets = "Line", "Lineout";
		audio-aux-devs = <&tdmout_b>, <&tdmout_c>,
				 <&tdmin_a>, <&tdmin_b>, <&tdmin_c>;
		audio-routing = "TDMOUT_B IN 0", "FRDDR_A OUT 1",
				"TDMOUT_B IN 1", "FRDDR_B OUT 1",
				"TDMOUT_B IN 2", "FRDDR_C OUT 1",
				"TDM_B Playback", "TDMOUT_B OUT",
				"TDMOUT_C IN 0", "FRDDR_A OUT 2",
				"TDMOUT_C IN 1", "FRDDR_B OUT 2",
				"TDMOUT_C IN 2", "FRDDR_C OUT 2",
				"TDM_C Playback", "TDMOUT_C OUT",
				"TDMIN_A IN 4", "TDM_B Loopback",
				"TDMIN_B IN 4", "TDM_B Loopback",
				"TDMIN_C IN 4", "TDM_B Loopback",
				"TDMIN_A IN 5", "TDM_C Loopback",
				"TDMIN_B IN 5", "TDM_C Loopback",
				"TDMIN_C IN 5", "TDM_C Loopback",
				"TODDR_A IN 0", "TDMIN_A OUT",
				"TODDR_B IN 0", "TDMIN_A OUT",
				"TODDR_C IN 0", "TDMIN_A OUT",
				"TODDR_A IN 1", "TDMIN_B OUT",
				"TODDR_B IN 1", "TDMIN_B OUT",
				"TODDR_C IN 1", "TDMIN_B OUT",
				"TODDR_A IN 2", "TDMIN_C OUT",
				"TODDR_B IN 2", "TDMIN_C OUT",
				"TODDR_C IN 2", "TDMIN_C OUT",
				"Lineout", "ACODEC LOLP",
				"Lineout", "ACODEC LORP";

		assigned-clocks = <&clkc CLKID_MPLL2>,
				  <&clkc CLKID_MPLL0>,
				  <&clkc CLKID_MPLL1>;
		assigned-clock-parents = <0>, <0>, <0>;
		assigned-clock-rates = <294912000>,
				       <270950400>,
				       <393216000>;

		dai-link-0 {
			sound-dai = <&frddr_a>;
		};

		dai-link-1 {
			sound-dai = <&frddr_b>;
		};

		dai-link-2 {
			sound-dai = <&frddr_c>;
		};

		dai-link-3 {
			sound-dai = <&toddr_a>;
		};

		dai-link-4 {
			sound-dai = <&toddr_b>;
		};

		dai-link-5 {
			sound-dai = <&toddr_c>;
		};

		/* 8ch hdmi interface */
		dai-link-6 {
			sound-dai = <&tdmif_b>;
			dai-format = "i2s";
			dai-tdm-slot-tx-mask-0 = <1 1>;
			dai-tdm-slot-tx-mask-1 = <1 1>;
			dai-tdm-slot-tx-mask-2 = <1 1>;
			dai-tdm-slot-tx-mask-3 = <1 1>;
			mclk-fs = <256>;

			codec-0 {
				sound-dai = <&tohdmitx TOHDMITX_I2S_IN_B>;
			};

			codec-1 {
				sound-dai = <&toacodec TOACODEC_IN_B>;
			};
		};

		/* i2s jack output interface */
		dai-link-7 {
			sound-dai = <&tdmif_c>;
			dai-format = "i2s";
			dai-tdm-slot-tx-mask-0 = <1 1>;
			mclk-fs = <256>;

			codec-0 {
				sound-dai = <&tohdmitx TOHDMITX_I2S_IN_C>;
			};

			codec-1 {
				sound-dai = <&toacodec TOACODEC_IN_C>;
			};
		};

		/* hdmi glue */
		dai-link-8 {
			sound-dai = <&tohdmitx TOHDMITX_I2S_OUT>;

			codec {
				sound-dai = <&hdmi_tx>;
			};
		};

		/* acodec glue */
		dai-link-9 {
			sound-dai = <&toacodec TOACODEC_OUT>;

			codec {
				sound-dai = <&acodec>;
			};
		};
	};
};

&acodec {
	AVDD-supply = <&vddao_1v8>;
	status = "okay";
};


&clkc_audio {
	status = "okay";
};

&cvbs_vdac_port {
	cvbs_vdac_out: endpoint {
		remote-endpoint = <&cvbs_connector_in>;
	};
};

&frddr_a {
	status = "okay";
};

&frddr_b {
	status = "okay";
};

&frddr_c {
	status = "okay";
};

&tdmif_b {
	status = "okay";
};

&tdmif_c {
	status = "okay";
};

&tdmin_a {
	status = "okay";
};

&tdmin_b {
	status = "okay";
};

&tdmin_c {
	status = "okay";
};

&tdmout_b {
	status = "okay";
};

&tdmout_c {
	status = "okay";
};

&toacodec {
	status = "okay";
};

&tohdmitx {
	status = "okay";
};

&toddr_a {
	status = "okay";
};

&toddr_b {
	status = "okay";
};

&toddr_c {
	status = "okay";
};
