/*
 * 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 NAND 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";
};

&pio {
	nand_pins_default: nanddefault {
		pins_dat {
			pinmux = <MT7623_PIN_111_MSDC0_DAT7_FUNC_NLD7>,
				 <MT7623_PIN_112_MSDC0_DAT6_FUNC_NLD6>,
				 <MT7623_PIN_114_MSDC0_DAT4_FUNC_NLD4>,
				 <MT7623_PIN_118_MSDC0_DAT3_FUNC_NLD3>,
				 <MT7623_PIN_121_MSDC0_DAT0_FUNC_NLD0>,
				 <MT7623_PIN_120_MSDC0_DAT1_FUNC_NLD1>,
				 <MT7623_PIN_113_MSDC0_DAT5_FUNC_NLD5>,
				 <MT7623_PIN_115_MSDC0_RSTB_FUNC_NLD8>,
				 <MT7623_PIN_119_MSDC0_DAT2_FUNC_NLD2>;
				input-enable;
				drive-strength = <MTK_DRIVE_8mA>;
				bias-pull-up;
		};

		pins_we {
			pinmux = <MT7623_PIN_117_MSDC0_CLK_FUNC_NWEB>;
			drive-strength = <MTK_DRIVE_8mA>;
			bias-pull-up = <MTK_PUPD_SET_R1R0_10>;
		};

		pins_ale {
			pinmux = <MT7623_PIN_116_MSDC0_CMD_FUNC_NALE>;
			drive-strength = <MTK_DRIVE_8mA>;
			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>;
		};
	};
};

&nandc {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&nand_pins_default>;
	nand@0 {
		reg = <0>;
		spare_per_sector = <64>;
		nand-ecc-mode = "hw";
		nand-ecc-strength = <12>;
		nand-ecc-step-size = <1024>;
		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			partition@C0000 {
				label = "uboot-env";
				reg = <0xC0000 0x40000>;
			};

			partition@100000 {
				label = "factory";
				reg = <0x100000 0x40000>;
			};

			partition@140000 {
				label = "kernel";
				reg = <0x140000 0x2000000>;
			};

			partition@2140000 {
				label = "recovery";
				reg = <0x2140000 0x2000000>;
			};

			partition@4140000 {
				label = "ubi";
				reg = <0x4140000 0x1000000>;
			};
		};
	};
};
&bch {
	status = "okay";
};

&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-mode = "rgmii";

	fixed-link {
		speed = <1000>;
		full-duplex;
		pause;
	};
};

&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";
};
