// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) 2018 Logic PD, Inc - https://www.logicpd.com/
 */

#include <dt-bindings/input/input.h>

/ {
	codec1 {
		compatible = "simple-audio-card";
		simple-audio-card,name = "tlv320aic23-hifi";

		simple-audio-card,widgets =
			"Microphone", "Mic In",
			"Line", "Line In",
			"Line", "Line Out";

		simple-audio-card,routing =
			"Line Out", "LOUT",
			"Line Out", "ROUT",
			"LLINEIN", "Line In",
			"RLINEIN", "Line In",
			"MICIN", "Mic In";

		simple-audio-card,format = "i2s";
		simple-audio-card,bitclock-master = <&sound_master>;
		simple-audio-card,frame-master = <&sound_master>;

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

		sound_master: simple-audio-card,codec {
			sound-dai = <&tlv320aic23_1>;
			system-clock-frequency = <12000000>;
		};
	};

	codec2 {
		compatible = "simple-audio-card";
		simple-audio-card,name = "tlv320aic23-hifi";

		simple-audio-card,widgets =
			"Microphone", "Mic In",
			"Line", "Line In",
			"Line", "Line Out";

		simple-audio-card,routing =
			"Line Out", "LOUT",
			"Line Out", "ROUT",
			"LLINEIN", "Line In",
			"RLINEIN", "Line In",
			"MICIN", "Mic In";

		simple-audio-card,format = "i2s";
		simple-audio-card,bitclock-master = <&sound_master2>;
		simple-audio-card,frame-master = <&sound_master2>;

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

		sound_master2: simple-audio-card,codec {
			sound-dai = <&tlv320aic23_2>;
			system-clock-frequency = <12000000>;
		};
	};

	expander-keys {
		compatible = "gpio-keys-polled";
		poll-interval = <100>;

		key-record {
			label = "Record";
			/* linux,code = <BTN_0>; */
			gpios = <&tca6416_2 15 GPIO_ACTIVE_LOW>;
		};

		key-play {
			label = "Play";
			linux,code = <KEY_PLAY>;
			gpios = <&tca6416_2 14 GPIO_ACTIVE_LOW>;
		};

		key-stop {
			label = "Stop";
			linux,code = <KEY_STOP>;
			gpios = <&tca6416_2 13 GPIO_ACTIVE_LOW>;
		};

		key-fwd {
			label = "FWD";
			linux,code = <KEY_FASTFORWARD>;
			gpios = <&tca6416_2 12 GPIO_ACTIVE_LOW>;
		};

		key-rwd {
			label = "RWD";
			linux,code = <KEY_REWIND>;
			gpios = <&tca6416_2 11 GPIO_ACTIVE_LOW>;
		};

		key-shift {
			label = "Shift";
			linux,code = <KEY_LEFTSHIFT>;
			gpios = <&tca6416_2 10 GPIO_ACTIVE_LOW>;
		};

		key-mode {
			label = "Mode";
			linux,code = <BTN_MODE>;
			gpios = <&tca6416_2 9 GPIO_ACTIVE_LOW>;
		};

		key-menu {
			label = "Menu";
			linux,code = <KEY_MENU>;
			gpios = <&tca6416_2 8 GPIO_ACTIVE_LOW>;
		};

		key-up {
			label = "Up";
			linux,code = <KEY_UP>;
			gpios = <&tca6416_2 7 GPIO_ACTIVE_LOW>;
		};

		key-down {
			label = "Down";
			linux,code = <KEY_DOWN>;
			gpios = <&tca6416_2 6 GPIO_ACTIVE_LOW>;
		};
	};
};

&i2c2 {
	/* Audio codecs */
	tlv320aic23_1: codec@1a {
		compatible = "ti,tlv320aic23";
		reg = <0x1a>;
		#sound-dai-cells = <0>;
		status = "okay";
	};

	tlv320aic23_2: codec@1b {
		compatible = "ti,tlv320aic23";
		reg = <0x1b>;
		#sound-dai-cells = <0>;
		status = "okay";
	};
};

&i2c3 {
	/* Audio codecs */
	tlv320aic23_3: codec@1a {
		compatible = "ti,tlv320aic23";
		reg = <0x1a>;
		#sound-dai-cells = <0>;
		status = "okay";
	};

	/* GPIO Expanders */
	tca6416_2: gpio@20 {
		compatible = "ti,tca6416";
		reg = <0x20>;
		gpio-controller;
		#gpio-cells = <2>;
		vcc-supply = <&vdd_io_reg>;
	};

	tca6416_3: gpio@21 {
		compatible = "ti,tca6416";
		reg = <0x21>;
		gpio-controller;
		#gpio-cells = <2>;
		vcc-supply = <&vdd_io_reg>;
	};

	/* TVP5146 Analog Video decoder input */
	tvp5146@5c {
		compatible = "ti,tvp5146m2";
		reg = <0x5c>;
	};
};

&mcbsp1 {
	status = "okay";
	#sound-dai-cells = <0>;
	pinctrl-names = "default";
	pinctrl-0 = <&mcbsp1_pins>;
};

&mcbsp2 {
	status = "okay";
	#sound-dai-cells = <0>;
	pinctrl-names = "default";
	pinctrl-0 = <&mcbsp2_pins>;
};

&omap3_pmx_core {
	mcbsp1_pins: pinmux_mcbsp1_pins {
		pinctrl-single,pins = <
			OMAP3_CORE1_IOPAD(0x2190, PIN_OUTPUT | MUX_MODE0)	/* mcbsp1_dx.mcbsp1_dx */
			OMAP3_CORE1_IOPAD(0x2192, PIN_INPUT | MUX_MODE0)	/* mcbsp1_dx.mcbsp1_dr */
			OMAP3_CORE1_IOPAD(0x2196, PIN_INPUT | MUX_MODE0)	/* mcbsp_clks.mcbsp1_fsx */
			OMAP3_CORE1_IOPAD(0x2198, PIN_INPUT | MUX_MODE0)	/* mcbsp1_clkx.mcbsp1_clkx */
		>;
	};

	mcbsp2_pins: pinmux_mcbsp2_pins {
		pinctrl-single,pins = <
			OMAP3_CORE1_IOPAD(0x213c, PIN_INPUT | MUX_MODE0)	/* mcbsp2_fsx.mcbsp2_fsx */
			OMAP3_CORE1_IOPAD(0x213e, PIN_INPUT | MUX_MODE0)	/* mcbsp2_clkx.mcbsp2_clkx */
			OMAP3_CORE1_IOPAD(0x2140, PIN_INPUT | MUX_MODE0)	/* mcbsp2_dr.mcbsp2.dr */
			OMAP3_CORE1_IOPAD(0x2142, PIN_OUTPUT | MUX_MODE0)	/* mcbsp2_dx.mcbsp2_dx */
		>;
	};
};
