// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2017 Amlogic, Inc. All rights reserved.
 */

/dts-v1/;

#include "meson-axg.dtsi"
#include <dt-bindings/input/input.h>

/ {
	compatible = "amlogic,s400", "amlogic,a113d", "amlogic,meson-axg";
	model = "Amlogic Meson AXG S400 Development Board";

	keys {
		compatible = "adc-keys";
		io-channels = <&saradc 0>;
		io-channel-names = "buttons";
		keyup-threshold-microvolt = <1800000>;

		button-next {
			label = "Next";
			linux,code = <KEY_NEXT>;
			press-threshold-microvolt = <1116000>; /* 62% */
		};

		button-prev {
			label = "Previous";
			linux,code = <KEY_PREVIOUS>;
			press-threshold-microvolt = <900000>; /* 50% */
		};

		button-wifi {
			label = "Wifi";
			linux,code = <KEY_WLAN>;
			press-threshold-microvolt = <684000>; /* 38% */
		};

		button-up {
			label = "Volume Up";
			linux,code = <KEY_VOLUMEUP>;
			press-threshold-microvolt = <468000>; /* 26% */
		};

		button-down {
			label = "Volume Down";
			linux,code = <KEY_VOLUMEDOWN>;
			press-threshold-microvolt = <252000>; /* 14% */
		};

		button-voice {
			label = "Voice";
			linux,code = <KEY_VOICECOMMAND>;
			press-threshold-microvolt = <0>; /* 0% */
		};
	};

	aliases {
		serial0 = &uart_AO;
		serial1 = &uart_A;
	};

	linein: audio-codec-0 {
		#sound-dai-cells = <0>;
		compatible = "everest,es7241";
		VDDA-supply = <&vcc_3v3>;
		VDDP-supply = <&vcc_3v3>;
		VDDD-supply = <&vcc_3v3>;
		sound-name-prefix = "Linein";
	};

	lineout: audio-codec-1 {
		#sound-dai-cells = <0>;
		compatible = "everest,es7154";
		VDD-supply = <&vcc_3v3>;
		PVDD-supply = <&vcc_5v>;
		sound-name-prefix = "Lineout";
	};

	spdif_dit: audio-codec-2 {
		#sound-dai-cells = <0>;
		compatible = "linux,spdif-dit";
		sound-name-prefix = "DIT";
	};

	dmics: audio-codec-3 {
		#sound-dai-cells = <0>;
		compatible = "dmic-codec";
		num-channels = <7>;
		wakeup-delay-ms = <50>;
		sound-name-prefix = "MIC";
	};

	spdif_dir: audio-codec-4 {
		#sound-dai-cells = <0>;
		compatible = "linux,spdif-dir";
		sound-name-prefix = "DIR";
	};

	emmc_pwrseq: emmc-pwrseq {
		compatible = "mmc-pwrseq-emmc";
		reset-gpios = <&gpio BOOT_9 GPIO_ACTIVE_LOW>;
	};

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

	memory@0 {
		device_type = "memory";
		reg = <0x0 0x0 0x0 0x40000000>;
	};

	main_12v: regulator-main-12v {
		compatible = "regulator-fixed";
		regulator-name = "12V";
		regulator-min-microvolt = <12000000>;
		regulator-max-microvolt = <12000000>;
		regulator-always-on;
	};

	vcc_3v3: regulator-vcc-3v3 {
		compatible = "regulator-fixed";
		regulator-name = "VCC_3V3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&vddao_3v3>;
		regulator-always-on;
	};

	vcc_5v: regulator-vcc-5v {
		compatible = "regulator-fixed";
		regulator-name = "VCC5V";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&main_12v>;

		gpio = <&gpio_ao GPIOAO_13 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	vddao_3v3: regulator-vddao-3v3 {
		compatible = "regulator-fixed";
		regulator-name = "VDDAO_3V3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&main_12v>;
		regulator-always-on;
	};

	vddio_ao18: regulator-vddio-ao18 {
		compatible = "regulator-fixed";
		regulator-name = "VDDIO_AO18";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		vin-supply = <&vddao_3v3>;
		regulator-always-on;
	};

	vddio_boot: regulator-vddio-boot {
		compatible = "regulator-fixed";
		regulator-name = "VDDIO_BOOT";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		vin-supply = <&vddao_3v3>;
		regulator-always-on;
	};

	usb_pwr: regulator-usb-pwr {
		compatible = "regulator-fixed";
		regulator-name = "USB_PWR";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&vcc_5v>;

		gpio = <&gpio_ao GPIOAO_5 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		reset-gpios = <&gpio GPIOX_7 GPIO_ACTIVE_LOW>;
		clocks = <&wifi32k>;
		clock-names = "ext_clock";
	};

	speaker-leds {
		compatible = "gpio-leds";

		aled1 {
			label = "speaker:aled1";
			gpios = <&gpio_speaker 7 0>;
		};

		aled2 {
			label = "speaker:aled2";
			gpios = <&gpio_speaker 6 0>;
		};

		aled3 {
			label = "speaker:aled3";
			gpios = <&gpio_speaker 5 0>;
		};

		aled4 {
			label = "speaker:aled4";
			gpios = <&gpio_speaker 4 0>;
		};

		aled5 {
			label = "speaker:aled5";
			gpios = <&gpio_speaker 3 0>;
		};

		aled6 {
			label = "speaker:aled6";
			gpios = <&gpio_speaker 2 0>;
		};
	};

	sound {
		compatible = "amlogic,axg-sound-card";
		model = "AXG-S400";
		audio-aux-devs = <&tdmin_a>, <&tdmin_b>,  <&tdmin_c>,
				 <&tdmin_lb>, <&tdmout_c>;
		audio-widgets = "Line", "Lineout",
				"Line", "Linein",
				"Speaker", "Speaker1 Left",
				"Speaker", "Speaker1 Right";
		audio-routing = "TDMOUT_C IN 0", "FRDDR_A OUT 2",
				"SPDIFOUT IN 0", "FRDDR_A OUT 3",
				"TDMOUT_C IN 1", "FRDDR_B OUT 2",
				"SPDIFOUT IN 1", "FRDDR_B OUT 3",
				"TDMOUT_C IN 2", "FRDDR_C OUT 2",
				"SPDIFOUT IN 2", "FRDDR_C OUT 3",
				"TDM_C Playback", "TDMOUT_C OUT",
				"TDMIN_A IN 2", "TDM_C Capture",
				"TDMIN_A IN 5", "TDM_C Loopback",
				"TDMIN_B IN 2", "TDM_C Capture",
				"TDMIN_B IN 5", "TDM_C Loopback",
				"TDMIN_C IN 2", "TDM_C Capture",
				"TDMIN_C IN 5", "TDM_C Loopback",
				"TDMIN_LB IN 2", "TDM_C Loopback",
				"TDMIN_LB IN 5", "TDM_C Capture",
				"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",
				"TODDR_A IN 3", "SPDIFIN Capture",
				"TODDR_B IN 3", "SPDIFIN Capture",
				"TODDR_C IN 3", "SPDIFIN Capture",
				"TODDR_A IN 4", "PDM Capture",
				"TODDR_B IN 4", "PDM Capture",
				"TODDR_C IN 4", "PDM Capture",
				"TODDR_A IN 6", "TDMIN_LB OUT",
				"TODDR_B IN 6", "TDMIN_LB OUT",
				"TODDR_C IN 6", "TDMIN_LB OUT",
				"Lineout", "Lineout AOUTL",
				"Lineout", "Lineout AOUTR",
				"Speaker1 Left", "SPK1 OUT_A",
				"Speaker1 Left", "SPK1 OUT_B",
				"Speaker1 Right", "SPK1 OUT_C",
				"Speaker1 Right", "SPK1 OUT_D",
				"Linein AINL", "Linein",
				"Linein AINR", "Linein";
		assigned-clocks = <&clkc CLKID_HIFI_PLL>,
				  <&clkc CLKID_MPLL0>,
				  <&clkc CLKID_MPLL1>;
		assigned-clock-parents = <0>, <0>, <0>;
		assigned-clock-rates = <589824000>,
				       <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>;
		};

		dai-link-6 {
			sound-dai = <&tdmif_c>;
			dai-format = "i2s";
			dai-tdm-slot-tx-mask-2 = <1 1>;
			dai-tdm-slot-rx-mask-1 = <1 1>;
			mclk-fs = <256>;

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

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

			codec-2 {
				sound-dai = <&linein>;
			};

		};

		dai-link-7 {
			sound-dai = <&spdifout>;

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

		dai-link-8 {
			sound-dai = <&spdifin>;

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

		dai-link-9 {
			sound-dai = <&pdm>;

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

	wifi32k: wifi32k {
		compatible = "pwm-clock";
		#clock-cells = <0>;
		clock-frequency = <32768>;
		pwms = <&pwm_ab 0 30518 0>; /* PWM_A at 32.768KHz */
	};
};

&ethmac {
	status = "okay";
	pinctrl-0 = <&eth_rgmii_y_pins>;
	pinctrl-names = "default";
	phy-handle = <&eth_phy0>;
	phy-mode = "rgmii";

	mdio {
		compatible = "snps,dwmac-mdio";
		#address-cells = <1>;
		#size-cells = <0>;

		eth_phy0: ethernet-phy@0 {
			/* Realtek RTL8211F (0x001cc916) */
			reg = <0>;
			interrupt-parent = <&gpio_intc>;
			interrupts = <98 IRQ_TYPE_LEVEL_LOW>;
			eee-broken-1000t;
		};
	};
};

&frddr_a {
	status = "okay";
};

&frddr_b {
	status = "okay";
};

&frddr_c {
	status = "okay";
};

&ir {
	status = "okay";
	pinctrl-0 = <&remote_input_ao_pins>;
	pinctrl-names = "default";
};

&i2c1 {
	status = "okay";
	pinctrl-0 = <&i2c1_z_pins>;
	pinctrl-names = "default";

	speaker_amp1: audio-codec@1b {
		compatible = "ti,tas5707";
		reg = <0x1b>;
		reset-gpios = <&gpio_ao GPIOAO_4 GPIO_ACTIVE_LOW>;
		#sound-dai-cells = <0>;
		AVDD-supply = <&vcc_3v3>;
		DVDD-supply = <&vcc_3v3>;
		PVDD_A-supply = <&main_12v>;
		PVDD_B-supply = <&main_12v>;
		PVDD_C-supply = <&main_12v>;
		PVDD_D-supply = <&main_12v>;
		sound-name-prefix = "SPK1";
	};
};

&i2c_AO {
	status = "okay";
	pinctrl-0 = <&i2c_ao_sck_10_pins>, <&i2c_ao_sda_11_pins>;
	pinctrl-names = "default";

	gpio_speaker: gpio-controller@1f {
		compatible = "nxp,pca9557";
		reg = <0x1f>;
		gpio-controller;
		#gpio-cells = <2>;
		vcc-supply = <&vddao_3v3>;
	};
};

&pdm {
	pinctrl-0 = <&pdm_dclk_a14_pins>, <&pdm_din0_pins>,
		    <&pdm_din1_pins>, <&pdm_din2_pins>, <&pdm_din3_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&pcieA {
	reset-gpios = <&gpio GPIOX_19 GPIO_ACTIVE_LOW>;
	status = "okay";
};

&pcieB {
	reset-gpios = <&gpio GPIOZ_10 (GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN)>;
	status = "okay";
};

&pwm_ab {
	status = "okay";
	pinctrl-0 = <&pwm_a_x20_pins>;
	pinctrl-names = "default";
};

&saradc {
	status = "okay";
	vref-supply = <&vddio_ao18>;
};

/* wifi module */
&sd_emmc_b {
	status = "okay";
	#address-cells = <1>;
	#size-cells = <0>;

	pinctrl-0 = <&sdio_pins>;
	pinctrl-1 = <&sdio_clk_gate_pins>;
	pinctrl-names = "default", "clk-gate";

	bus-width = <4>;
	cap-sd-highspeed;
	sd-uhs-sdr104;
	max-frequency = <200000000>;
	non-removable;
	disable-wp;

	mmc-pwrseq = <&sdio_pwrseq>;

	vmmc-supply = <&vddao_3v3>;
	vqmmc-supply = <&vddio_boot>;

	brcmf: wifi@1 {
		reg = <1>;
		compatible = "brcm,bcm4329-fmac";
	};
};

/* emmc storage */
&sd_emmc_c {
	status = "okay";
	pinctrl-0 = <&emmc_pins>, <&emmc_ds_pins>;
	pinctrl-1 = <&emmc_clk_gate_pins>;
	pinctrl-names = "default", "clk-gate";

	bus-width = <8>;
	cap-mmc-highspeed;
	max-frequency = <200000000>;
	non-removable;
	disable-wp;
	mmc-ddr-1_8v;
	mmc-hs200-1_8v;

	mmc-pwrseq = <&emmc_pwrseq>;

	vmmc-supply = <&vcc_3v3>;
	vqmmc-supply = <&vddio_boot>;
};

&spdifin {
	pinctrl-0 = <&spdif_in_a19_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&spdifout {
	pinctrl-0 = <&spdif_out_a20_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&tdmif_a {
	pinctrl-0 = <&tdma_sclk_pins>, <&tdma_fs_pins>,
		    <&tdma_din0_pins>, <&tdma_dout0_x15_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&tdmif_b {
	pinctrl-0 = <&tdmb_sclk_pins>, <&tdmb_fs_pins>,
		    <&tdmb_din3_pins>, <&mclk_b_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&tdmif_c {
	pinctrl-0 = <&tdmc_sclk_pins>, <&tdmc_fs_pins>,
		    <&tdmc_din1_pins>, <&tdmc_dout2_pins>,
		    <&mclk_c_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&tdmin_a {
	status = "okay";
};

&tdmin_b {
	status = "okay";
};

&tdmin_c {
	status = "okay";
};

&tdmin_lb {
	status = "okay";
};

&tdmout_c {
	status = "okay";
};

&toddr_a {
	status = "okay";
};

&toddr_b {
	status = "okay";
};

&toddr_c {
	status = "okay";
};

&uart_A {
	status = "okay";
	pinctrl-0 = <&uart_a_pins>, <&uart_a_cts_rts_pins>;
	pinctrl-names = "default";
	uart-has-rtscts;

	bluetooth {
		compatible = "brcm,bcm43438-bt";
		shutdown-gpios = <&gpio GPIOX_21 GPIO_ACTIVE_HIGH>;
	};
};

&uart_AO {
	status = "okay";
	pinctrl-0 = <&uart_ao_a_pins>;
	pinctrl-names = "default";
};

&usb {
	status = "okay";
	dr_mode = "otg";
	vbus-supply = <&usb_pwr>;
};
