// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2019 BayLibre, SAS.
 * Author: Fabien Parent <fparent@baylibre.com>
 */

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

/ {
	aliases {
		serial0 = &uart0;
		ethernet0 = &ethernet;
	};

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

	firmware {
		optee: optee {
			compatible = "linaro,optee-tz";
			method = "smc";
		};
	};

	gpio-keys {
		compatible = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&gpio_keys_default>;

		key-volume-up {
			gpios = <&pio 42 GPIO_ACTIVE_LOW>;
			label = "volume_up";
			linux,code = <115>;
			wakeup-source;
			debounce-interval = <15>;
		};

		key-volume-down {
			gpios = <&pio 43 GPIO_ACTIVE_LOW>;
			label = "volume_down";
			linux,code = <114>;
			wakeup-source;
			debounce-interval = <15>;
		};
	};
};

&i2c0 {
	clock-div = <2>;
	pinctrl-names = "default";
	pinctrl-0 = <&i2c0_pins_a>;
	status = "okay";

	tca6416: gpio@20 {
		compatible = "ti,tca6416";
		reg = <0x20>;
		reset-gpios = <&pio 65 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&tca6416_pins>;

		gpio-controller;
		#gpio-cells = <2>;

		eint20-mux-sel0-hog {
			gpio-hog;
			gpios = <0 0>;
			input;
			line-name = "eint20_mux_sel0";
		};

		expcon-mux-sel1-hog {
			gpio-hog;
			gpios = <1 0>;
			input;
			line-name = "expcon_mux_sel1";
		};

		mrg-di-mux-sel2-hog {
			gpio-hog;
			gpios = <2 0>;
			input;
			line-name = "mrg_di_mux_sel2";
		};

		sd-sdio-mux-sel3-hog {
			gpio-hog;
			gpios = <3 0>;
			input;
			line-name = "sd_sdio_mux_sel3";
		};

		sd-sdio-mux-ctrl7-hog {
			gpio-hog;
			gpios = <7 0>;
			output-low;
			line-name = "sd_sdio_mux_ctrl7";
		};

		hw-id0-hog {
			gpio-hog;
			gpios = <8 0>;
			input;
			line-name = "hw_id0";
		};

		hw-id1-hog {
			gpio-hog;
			gpios = <9 0>;
			input;
			line-name = "hw_id1";
		};

		hw-id2-hog {
			gpio-hog;
			gpios = <10 0>;
			input;
			line-name = "hw_id2";
		};

		fg-int-n-hog {
			gpio-hog;
			gpios = <11 0>;
			input;
			line-name = "fg_int_n";
		};

		usba-pwr-en-hog {
			gpio-hog;
			gpios = <12 0>;
			output-high;
			line-name = "usba_pwr_en";
		};

		wifi-3v3-pg-hog {
			gpio-hog;
			gpios = <13 0>;
			input;
			line-name = "wifi_3v3_pg";
		};

		cam-rst-hog {
			gpio-hog;
			gpios = <14 0>;
			output-low;
			line-name = "cam_rst";
		};

		cam-pwdn-hog {
			gpio-hog;
			gpios = <15 0>;
			output-low;
			line-name = "cam_pwdn";
		};
	};
};

&i2c2 {
	clock-div = <2>;
	pinctrl-names = "default";
	pinctrl-0 = <&i2c2_pins_a>;
	status = "okay";
};

&uart0 {
	status = "okay";
};

&ethernet {
	pinctrl-names = "default";
	pinctrl-0 = <&ethernet_pins_default>;
	phy-handle = <&eth_phy>;
	phy-mode = "rmii";
	mac-address = [00 00 00 00 00 00];
	status = "okay";

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

		eth_phy: ethernet-phy@0 {
			reg = <0>;
		};
	};
};

&usb0 {
	status = "okay";
	dr_mode = "peripheral";
	usb-role-switch;

	usb_con: connector {
		compatible = "usb-c-connector";
		label = "USB-C";
	};
};

&usb_phy {
	status = "okay";
};

&pio {
	gpio_keys_default: gpiodefault {
		pins_cmd_dat {
			pinmux = <MT8516_PIN_42_KPCOL0__FUNC_GPIO42>,
				 <MT8516_PIN_43_KPCOL1__FUNC_GPIO43>;
			bias-pull-up;
			input-enable;
		};
	};

	i2c0_pins_a: i2c0 {
		pins1 {
			pinmux = <MT8516_PIN_58_SDA0__FUNC_SDA0_0>,
				 <MT8516_PIN_59_SCL0__FUNC_SCL0_0>;
			bias-disable;
		};
	};

	i2c2_pins_a: i2c2 {
		pins1 {
			pinmux = <MT8516_PIN_60_SDA2__FUNC_SDA2_0>,
				 <MT8516_PIN_61_SCL2__FUNC_SCL2_0>;
			bias-disable;
		};
	};

	tca6416_pins: pinmux_tca6416_pins {
		gpio_mux_rst_n_pin {
			pinmux = <MT8516_PIN_65_UTXD1__FUNC_GPIO65>;
			output-high;
		};

		gpio_mux_int_n_pin {
			pinmux = <MT8516_PIN_64_URXD1__FUNC_GPIO64>;
			input-enable;
			bias-pull-up;
		};
	};

	ethernet_pins_default: ethernet {
		pins_ethernet {
			pinmux = <MT8516_PIN_0_EINT0__FUNC_EXT_TXD0>,
				 <MT8516_PIN_1_EINT1__FUNC_EXT_TXD1>,
				 <MT8516_PIN_5_EINT5__FUNC_EXT_RXER>,
				 <MT8516_PIN_6_EINT6__FUNC_EXT_RXC>,
				 <MT8516_PIN_7_EINT7__FUNC_EXT_RXDV>,
				 <MT8516_PIN_8_EINT8__FUNC_EXT_RXD0>,
				 <MT8516_PIN_9_EINT9__FUNC_EXT_RXD1>,
				 <MT8516_PIN_12_EINT12__FUNC_EXT_TXEN>,
				 <MT8516_PIN_38_MRG_DI__FUNC_EXT_MDIO>,
				 <MT8516_PIN_39_MRG_DO__FUNC_EXT_MDC>;
		};
	};
};
