/*
 * Copyright (c) 2016 MediaTek Inc.
 * Author: John Crispin <blogic@openwrt.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/dts-v1/;

#include "_mt7623.dtsi"
#include <dt-bindings/gpio/gpio.h>

/ {
	model = "MediaTek MT7623 eMMC evaluation board";
	compatible = "mediatek,mt7623-evb", "mediatek,mt7623";

	chosen {
		stdout-path = &uart2;
	};

	memory {
		reg = <0 0x80000000 0 0x20000000>;
	};

	usb_p1_vbus: regulator@0 {
		compatible = "regulator-fixed";
		regulator-name = "usb_vbus";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&pio 135 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};
};

&cpu0 {
	proc-supply = <&mt6323_vproc_reg>;
};

&cpu1 {
	proc-supply = <&mt6323_vproc_reg>;
};

&cpu2 {
	proc-supply = <&mt6323_vproc_reg>;
};

&cpu3 {
	proc-supply = <&mt6323_vproc_reg>;
};

&pwrap {
	pmic: mt6323 {
		compatible = "mediatek,mt6323";
		interrupt-parent = <&pio>;
		interrupts = <150 IRQ_TYPE_LEVEL_HIGH>;
		interrupt-controller;
		#interrupt-cells = <2>;

		mt6323regulator: mt6323regulator{
			compatible = "mediatek,mt6323-regulator";

			mt6323_vproc_reg: buck_vproc{
				regulator-name = "vproc";
				regulator-min-microvolt = < 700000>;
				regulator-max-microvolt = <1350000>;
				regulator-ramp-delay = <12500>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vsys_reg: buck_vsys{
				regulator-name = "vsys";
				regulator-min-microvolt = <1400000>;
				regulator-max-microvolt = <2987500>;
				regulator-ramp-delay = <25000>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vpa_reg: buck_vpa{
				regulator-name = "vpa";
				regulator-min-microvolt = < 500000>;
				regulator-max-microvolt = <3650000>;
			};

			mt6323_vtcxo_reg: ldo_vtcxo{
				regulator-name = "vtcxo";
				regulator-min-microvolt = <2800000>;
				regulator-max-microvolt = <2800000>;
				regulator-enable-ramp-delay = <90>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vcn28_reg: ldo_vcn28{
				regulator-name = "vcn28";
				regulator-min-microvolt = <2800000>;
				regulator-max-microvolt = <2800000>;
				regulator-enable-ramp-delay = <185>;
			};

			mt6323_vcn33_bt_reg: ldo_vcn33_bt{
				regulator-name = "vcn33_bt";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3600000>;
				regulator-enable-ramp-delay = <185>;
			};

			mt6323_vcn33_wifi_reg: ldo_vcn33_wifi{
				regulator-name = "vcn33_wifi";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3600000>;
				regulator-enable-ramp-delay = <185>;
			};

			mt6323_va_reg: ldo_va{
				regulator-name = "va";
				regulator-min-microvolt = <2800000>;
				regulator-max-microvolt = <2800000>;
				regulator-enable-ramp-delay = <216>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vcama_reg: ldo_vcama{
				regulator-name = "vcama";
				regulator-min-microvolt = <1500000>;
				regulator-max-microvolt = <2800000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vio28_reg: ldo_vio28{
				regulator-name = "vio28";
				regulator-min-microvolt = <2800000>;
				regulator-max-microvolt = <2800000>;
				regulator-enable-ramp-delay = <216>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vusb_reg: ldo_vusb{
				regulator-name = "vusb";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
				regulator-enable-ramp-delay = <216>;
				regulator-boot-on;
			};

			mt6323_vmc_reg: ldo_vmc{
				regulator-name = "vmc";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3300000>;
				regulator-enable-ramp-delay = <36>;
				regulator-boot-on;
			};

			mt6323_vmch_reg: ldo_vmch{
				regulator-name = "vmch";
				regulator-min-microvolt = <3000000>;
				regulator-max-microvolt = <3300000>;
				regulator-enable-ramp-delay = <36>;
				regulator-boot-on;
			};

			mt6323_vemc3v3_reg: ldo_vemc3v3{
				regulator-name = "vemc3v3";
				regulator-min-microvolt = <3000000>;
				regulator-max-microvolt = <3300000>;
				regulator-enable-ramp-delay = <36>;
				regulator-boot-on;
			};

			mt6323_vgp1_reg: ldo_vgp1{
				regulator-name = "vgp1";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <3300000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vgp2_reg: ldo_vgp2{
				regulator-name = "vgp2";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <3000000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vgp3_reg: ldo_vgp3{
				regulator-name = "vgp3";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <1800000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vcn18_reg: ldo_vcn18{
				regulator-name = "vcn18";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vsim1_reg: ldo_vsim1{
				regulator-name = "vsim1";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3000000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vsim2_reg: ldo_vsim2{
				regulator-name = "vsim2";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3000000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vrtc_reg: ldo_vrtc{
				regulator-name = "vrtc";
				regulator-min-microvolt = <2800000>;
				regulator-max-microvolt = <2800000>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vcamaf_reg: ldo_vcamaf{
				regulator-name = "vcamaf";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <3300000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vibr_reg: ldo_vibr{
				regulator-name = "vibr";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <3300000>;
				regulator-enable-ramp-delay = <36>;
			};

			mt6323_vrf18_reg: ldo_vrf18{
				regulator-name = "vrf18";
				regulator-min-microvolt = <1825000>;
				regulator-max-microvolt = <1825000>;
				regulator-enable-ramp-delay = <187>;
			};

			mt6323_vm_reg: ldo_vm{
				regulator-name = "vm";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <1800000>;
				regulator-enable-ramp-delay = <216>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vio18_reg: ldo_vio18{
				regulator-name = "vio18";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-enable-ramp-delay = <216>;
				regulator-always-on;
				regulator-boot-on;
			};

			mt6323_vcamd_reg: ldo_vcamd{
				regulator-name = "vcamd";
				regulator-min-microvolt = <1200000>;
				regulator-max-microvolt = <1800000>;
				regulator-enable-ramp-delay = <216>;
			};

			mt6323_vcamio_reg: ldo_vcamio{
				regulator-name = "vcamio";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <1800000>;
				regulator-enable-ramp-delay = <216>;
			};
		};
	};
};

&uart2 {
	status = "okay";
};

&mmc0 {
	status = "okay";
	pinctrl-names = "default", "state_uhs";
	pinctrl-0 = <&mmc0_pins_default>;
	pinctrl-1 = <&mmc0_pins_uhs>;
	bus-width = <8>;
	max-frequency = <50000000>;
	cap-mmc-highspeed;
	vmmc-supply = <&mt6323_vemc3v3_reg>;
	vqmmc-supply = <&mt6323_vio18_reg>;
	non-removable;
};

&mmc1 {
	status = "okay";
	pinctrl-names = "default", "state_uhs";
	pinctrl-0 = <&mmc1_pins_default>;
	pinctrl-1 = <&mmc1_pins_uhs>;
	bus-width = <4>;
	max-frequency = <50000000>;
	cap-sd-highspeed;
	sd-uhs-sdr25;
//	cd-gpios = <&pio 132 0>;
	vmmc-supply = <&mt6323_vmch_reg>;
	vqmmc-supply = <&mt6323_vmc_reg>;
};

&pio {
	mmc0_pins_default: mmc0default {
		pins_cmd_dat {
			pinmux = <MT7623_PIN_111_MSDC0_DAT7_FUNC_MSDC0_DAT7>,
				 <MT7623_PIN_112_MSDC0_DAT6_FUNC_MSDC0_DAT6>,
				 <MT7623_PIN_113_MSDC0_DAT5_FUNC_MSDC0_DAT5>,
				 <MT7623_PIN_114_MSDC0_DAT4_FUNC_MSDC0_DAT4>,
				 <MT7623_PIN_118_MSDC0_DAT3_FUNC_MSDC0_DAT3>,
				 <MT7623_PIN_119_MSDC0_DAT2_FUNC_MSDC0_DAT2>,
				 <MT7623_PIN_120_MSDC0_DAT1_FUNC_MSDC0_DAT1>,
				 <MT7623_PIN_121_MSDC0_DAT0_FUNC_MSDC0_DAT0>,
				 <MT7623_PIN_116_MSDC0_CMD_FUNC_MSDC0_CMD>;
			input-enable;
			bias-pull-up;
		};

		pins_clk {
			pinmux = <MT7623_PIN_117_MSDC0_CLK_FUNC_MSDC0_CLK>;
			bias-pull-down;
		};

		pins_rst {
			pinmux = <MT7623_PIN_115_MSDC0_RSTB_FUNC_MSDC0_RSTB>;
			bias-pull-up;
		};
	};

	mmc0_pins_uhs: mmc0 {
		pins_cmd_dat {
			pinmux = <MT7623_PIN_111_MSDC0_DAT7_FUNC_MSDC0_DAT7>,
				 <MT7623_PIN_112_MSDC0_DAT6_FUNC_MSDC0_DAT6>,
				 <MT7623_PIN_113_MSDC0_DAT5_FUNC_MSDC0_DAT5>,
				 <MT7623_PIN_114_MSDC0_DAT4_FUNC_MSDC0_DAT4>,
				 <MT7623_PIN_118_MSDC0_DAT3_FUNC_MSDC0_DAT3>,
				 <MT7623_PIN_119_MSDC0_DAT2_FUNC_MSDC0_DAT2>,
				 <MT7623_PIN_120_MSDC0_DAT1_FUNC_MSDC0_DAT1>,
				 <MT7623_PIN_121_MSDC0_DAT0_FUNC_MSDC0_DAT0>,
				 <MT7623_PIN_116_MSDC0_CMD_FUNC_MSDC0_CMD>;
			input-enable;
			drive-strength = <MTK_DRIVE_2mA>;
			bias-pull-up = <MTK_PUPD_SET_R1R0_01>;
		};

		pins_clk {
			pinmux = <MT7623_PIN_117_MSDC0_CLK_FUNC_MSDC0_CLK>;
			drive-strength = <MTK_DRIVE_2mA>;
			bias-pull-down = <MTK_PUPD_SET_R1R0_01>;
		};

		pins_rst {
			pinmux = <MT7623_PIN_115_MSDC0_RSTB_FUNC_MSDC0_RSTB>;
			bias-pull-up;
		};
	};

	mmc1_pins_default: mmc1default {
		pins_cmd_dat {
			pinmux = <MT7623_PIN_107_MSDC1_DAT0_FUNC_MSDC1_DAT0>,
				 <MT7623_PIN_108_MSDC1_DAT1_FUNC_MSDC1_DAT1>,
				 <MT7623_PIN_109_MSDC1_DAT2_FUNC_MSDC1_DAT2>,
				 <MT7623_PIN_110_MSDC1_DAT3_FUNC_MSDC1_DAT3>,
				 <MT7623_PIN_105_MSDC1_CMD_FUNC_MSDC1_CMD>;
			input-enable;
			drive-strength = <MTK_DRIVE_4mA>;
			bias-pull-up = <MTK_PUPD_SET_R1R0_10>;
		};

		pins_clk {
			pinmux = <MT7623_PIN_106_MSDC1_CLK_FUNC_MSDC1_CLK>;
			bias-pull-down;
			drive-strength = <MTK_DRIVE_4mA>;
		};

//		pins_insert {
//			pinmux = <MT8173_PIN_132_I2S0_DATA1_FUNC_GPIO132>;
//			bias-pull-up;
//		};
	};

	mmc1_pins_uhs: mmc1 {
		pins_cmd_dat {
			pinmux = <MT7623_PIN_107_MSDC1_DAT0_FUNC_MSDC1_DAT0>,
				 <MT7623_PIN_108_MSDC1_DAT1_FUNC_MSDC1_DAT1>,
				 <MT7623_PIN_109_MSDC1_DAT2_FUNC_MSDC1_DAT2>,
				 <MT7623_PIN_110_MSDC1_DAT3_FUNC_MSDC1_DAT3>,
				 <MT7623_PIN_105_MSDC1_CMD_FUNC_MSDC1_CMD>;
			input-enable;
			drive-strength = <MTK_DRIVE_4mA>;
			bias-pull-up = <MTK_PUPD_SET_R1R0_10>;
		};

		pins_clk {
			pinmux = <MT7623_PIN_106_MSDC1_CLK_FUNC_MSDC1_CLK>;
			drive-strength = <MTK_DRIVE_4mA>;
			bias-pull-down = <MTK_PUPD_SET_R1R0_10>;
		};
	};

	eth_default: eth {
		pins_eth {
			pinmux = <MT7623_PIN_275_G2_MDC_FUNC_MDC>,
				 <MT7623_PIN_276_G2_MDIO_FUNC_MDIO>,
				 <MT7623_PIN_262_G2_TXEN_FUNC_G2_TXEN>,
				 <MT7623_PIN_263_G2_TXD3_FUNC_G2_TXD3>,
				 <MT7623_PIN_264_G2_TXD2_FUNC_G2_TXD2>,
				 <MT7623_PIN_265_G2_TXD1_FUNC_G2_TXD1>,
				 <MT7623_PIN_266_G2_TXD0_FUNC_G2_TXD0>,
				 <MT7623_PIN_267_G2_TXCLK_FUNC_G2_TXC>,
				 <MT7623_PIN_268_G2_RXCLK_FUNC_G2_RXC>,
				 <MT7623_PIN_269_G2_RXD0_FUNC_G2_RXD0>,
				 <MT7623_PIN_270_G2_RXD1_FUNC_G2_RXD1>,
				 <MT7623_PIN_271_G2_RXD2_FUNC_G2_RXD2>,
				 <MT7623_PIN_272_G2_RXD3_FUNC_G2_RXD3>,
				 <MT7623_PIN_273_ESW_INT_FUNC_ESW_INT>,
				 <MT7623_PIN_274_G2_RXDV_FUNC_G2_RXDV>;
		};
		
		pins_eth_rst {
			pinmux = <MT7623_PIN_15_GPIO15_FUNC_GPIO15>;
			output-low;
		};
	};

	pwm_pins: pwm {
		pins_pwm1 {
			pinmux = <MT7623_PIN_204_PWM1_FUNC_PWM1>;
		};

		pins_pwm2 {
			pinmux = <MT7623_PIN_205_PWM2_FUNC_PWM2>;
		};
	};
};

&usb1 {
	vusb33-supply = <&mt6323_vusb_reg>;
	vbus-supply = <&usb_p1_vbus>;
	status = "okay";
};

&u3phy1 {
	status = "okay";
};

&pcie {
	status = "okay";
};

&eth {
	status = "okay";
};

&gmac1 {
	mac-address = [00 11 22 33 44 56];
	status = "okay";
};

&gmac2 {
	mac-address = [00 11 22 33 44 55];
	status = "okay";
	phy-handle = <&phy5>;
};

&gsw {
	pinctrl-names = "default";
	pinctrl-0 = <&eth_default>;
	mediatek,reset-pin = <&pio 15 0>;
	status = "okay";
};

&pwm {
	pinctrl-names = "default";
	pinctrl-0 = <&pwm_pins>;
	status = "okay";
};
