// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2016 Andreas Färber
 * Copyright (c) 2016 BayLibre, Inc.
 * Author: Kevin Hilman <khilman@kernel.org>
 */

/dts-v1/;

#include "meson-gxbb-p20x.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/sound/meson-aiu.h>

/ {
	compatible = "amlogic,p200", "amlogic,meson-gxbb";
	model = "Amlogic Meson GXBB P200 Development Board";

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

	avdd18_usb_adc: regulator-avdd18-usb-adc {
		compatible = "regulator-fixed";
		regulator-name = "AVDD18_USB_ADC";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
	};

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

		button-home {
			label = "Home";
			linux,code = <KEY_HOME>;
			press-threshold-microvolt = <900000>; /* 50% */
		};

		button-esc {
			label = "Esc";
			linux,code = <KEY_ESC>;
			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-menu {
			label = "Menu";
			linux,code = <KEY_MENU>;
			press-threshold-microvolt = <0>; /* 0% */
		};
	};

	sound {
		compatible = "amlogic,gx-sound-card";
		model = "P200";
		assigned-clocks = <&clkc CLKID_MPLL0>,
				  <&clkc CLKID_MPLL1>,
				  <&clkc CLKID_MPLL2>;
		assigned-clock-parents = <0>, <0>, <0>;
		assigned-clock-rates = <294912000>,
				       <270950400>,
				       <393216000>;

		dai-link-0 {
			sound-dai = <&aiu AIU_CPU CPU_I2S_FIFO>;
		};

		dai-link-1 {
			sound-dai = <&aiu AIU_CPU CPU_SPDIF_FIFO>;
		};

		dai-link-2 {
			sound-dai = <&aiu AIU_CPU CPU_I2S_ENCODER>;
			dai-format = "i2s";
			mclk-fs = <256>;

			codec-0 {
				sound-dai = <&aiu AIU_HDMI CTRL_I2S>;
			};
		};

		dai-link-3 {
			sound-dai = <&aiu AIU_CPU CPU_SPDIF_ENCODER>;

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

		dai-link-4 {
			sound-dai = <&aiu AIU_HDMI CTRL_OUT>;

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

&aiu {
	status = "okay";
	pinctrl-0 = <&spdif_out_y_pins>;
	pinctrl-names = "default";
};

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

	amlogic,tx-delay-ns = <2>;

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

		eth_phy0: ethernet-phy@3 {
			/* Micrel KSZ9031 (0x00221620) */
			reg = <3>;

			reset-assert-us = <10000>;
			reset-deassert-us = <30000>;
			reset-gpios = <&gpio GPIOZ_14 GPIO_ACTIVE_LOW>;

			interrupt-parent = <&gpio_intc>;
			/* MAC_INTR on GPIOZ_15 */
			interrupts = <29 IRQ_TYPE_LEVEL_LOW>;
		};
	};
};

&i2c_B {
	status = "okay";
	pinctrl-0 = <&i2c_b_pins>;
	pinctrl-names = "default";
};

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