#include "vr9.dtsi"

#include <dt-bindings/input/input.h>
#include <dt-bindings/mips/lantiq_rcu_gphy.h>

/ {
	compatible = "buffalo,wbmr-300hpd", "lantiq,xway", "lantiq,vr9";
	model = "Buffalo WBMR-300HPD";

	chosen {
		bootargs = "console=ttyLTQ0,115200";
	};

	aliases {
		led-boot = &power_g;
		led-failsafe = &diag_r;
		led-running = &power_g;
		led-upgrade = &power_g;

		led-dsl = &dsl;
		led-internet = &router_g;
		led-wifi = &wifi_g;
	};

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

	gpio_poweroff {
		compatible = "gpio-poweroff";
		gpios = <&gpio 6 GPIO_ACTIVE_LOW>;
	};

	keys {
		compatible = "gpio-keys-polled";
		poll-interval = <100>;

		power {
			label = "power";
			gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_POWER>;
		};

		reset {
			label = "reset";
			gpios = <&gpio 7 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};

		wps {
			label = "wps";
			gpios = <&gpio 31 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_WPS_BUTTON>;
		};

		auto {
			label = "auto";
			gpios = <&gpio 48 GPIO_ACTIVE_HIGH>;
			linux,code = <BTN_0>;
			linux,input-type = <EV_SW>;
		};

		router {
			label = "router";
			gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
			linux,code = <BTN_1>;
			linux,input-type = <EV_SW>;
		};
	};

	leds {
		compatible = "gpio-leds";

		diag_r: diag_r {
			label = "red:diag";
			gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
			default_state = "off";
		};

		wifi_g: wifi_g {
			label = "green:wifi";
			gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
		};

		dsl: dsl {
			label = "dsl";
			gpios = <&gpio 4 GPIO_ACTIVE_HIGH>;
		};

		router_y: router_y {
			label = "yellow:router";
			gpios = <&gpio 8 GPIO_ACTIVE_HIGH>;
		};

		wifi_y: wifi_y {
			label = "yellow:wifi";
			gpios = <&gpio 9 GPIO_ACTIVE_HIGH>;
		};

		lan1: lan1 {
			label = "green:lan1";
			gpios = <&gpio 11 GPIO_ACTIVE_HIGH>;
		};

		wan: wan {
			label = "green:wan";
			gpios = <&gpio 12 GPIO_ACTIVE_HIGH>;
		};

		lan3: lan3 {
			label = "green:lan3";
			gpios = <&gpio 15 GPIO_ACTIVE_HIGH>;
		};

		lan2: lan2 {
			label = "green:lan2";
			gpios = <&gpio 33 GPIO_ACTIVE_HIGH>;
		};

		internet_g: internet_g {
			label = "green:internet";
			gpios = <&gpio 34 GPIO_ACTIVE_HIGH>;
		};

		internet_y: internet_y {
			label = "yellow:internet";
			gpios = <&gpio 35 GPIO_ACTIVE_HIGH>;
		};

		router_g: router_g {
			label = "green:router";
			gpios = <&gpio 36 GPIO_ACTIVE_HIGH>;
		};

		power_g: power_g {
			label = "green:power";
			gpios = <&gpio 49 GPIO_ACTIVE_HIGH>;
		};
	};

	usb_vbus: regulator-usb-vbus {
		compatible = "regulator-fixed";

		regulator-name = "USB_VBUS";

		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;

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

&gphy0 {
	lantiq,gphy-mode = <GPHY_MODE_FE>;
};

&gphy1 {
	lantiq,gphy-mode = <GPHY_MODE_FE>;
};

&gpio {
	pinctrl-names = "default";
	pinctrl-0 = <&state_default>;

	state_default: pinmux {
		phy-rst {
			lantiq,pins = "io42";
			lantiq,pull = <0>;
			lantiq,open-drain = <0>;
			lantiq,output = <1>;
		};
		pcie-rst {
			lantiq,pins = "io38";
			lantiq,pull = <0>;
			lantiq,output = <1>;
		};
	};
};

&gswip_mdio {
	phy11: ethernet-phy@11 {
		reg = <0x11>;
	};
	phy12: ethernet-phy@12 {
		reg = <0x12>;
	};
	phy13: ethernet-phy@13 {
		reg = <0x13>;
	};
	phy14: ethernet-phy@14 {
		reg = <0x14>;
	};
};

&gswip_ports {
	port@2 {
		reg = <2>;
		label = "lan3";
		phy-mode = "internal";
		phy-handle = <&phy11>;
	};
	port@3 {
		reg = <3>;
		label = "lan4";
		phy-mode = "internal";
		phy-handle = <&phy12>;
	};
	port@4 {
		reg = <4>;
		label = "lan1";
		phy-mode = "internal";
		phy-handle = <&phy13>;
	};
	port@5 {
		reg = <5>;
		label = "lan2";
		phy-mode = "internal";
		phy-handle = <&phy14>;
	};
};

&spi {
	status = "okay";

	flash@4 {
		compatible = "jedec,spi-nor";
		reg = <4>;
		spi-max-frequency = <20000000>;

		partitions {
			#address-cells = <1>;
			#size-cells = <1>;

			partition@0 {
				reg = <0x0 0x10000>;
				label = "u-boot";
				read-only;
			};

			partition@10000 {
				reg = <0x10000 0x10000>;
				label = "gphyfirmware";
				read-only;
			};

			partition@20000 {
				reg = <0x20000 0x80000>;
				label = "dsl_fw";
			};

			partition@de0000 {
				reg = <0xa0000 0xf40000>;
				label = "firmware";
			};

			partition@fe0000 {
				reg = <0xfe0000 0x10000>;
				label = "sysconfig";
				read-only;
			};

			partition@ff0000 {
				reg = <0xff0000 0x2000>;
				label = "u-boot-env";
			};

			partition@ff3000 {
				reg = <0xff3000 0x2000>;
				label = "board_config";
				read-only;
			};
		};
	};
};

&usb_phy0 {
	status = "okay";
};

&usb_phy1 {
	status = "okay";
};

&usb0 {
	status = "okay";
	vbus-supply = <&usb_vbus>;
};

&usb1 {
	status = "okay";
	vbus-supply = <&usb_vbus>;
};
