// SPDX-License-Identifier: GPL-2.0-or-later OR MIT

#include "ar9132.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>

/ {
	aliases {
		led-boot = &led_diag;
		led-failsafe = &led_security;
		led-upgrade = &led_diag;
	};

	/* There is a GPIO driven NXP 74HC153 dual 4-way multiplexer on board
	 * used for buttons that are on top of the the device.
         */
	mux: mux-controller {
		compatible = "gpio-mux";
		#mux-control-cells = <0>;

		mux-gpios = <&gpio 9 GPIO_ACTIVE_HIGH>,		/* s0 */
			    <&gpio 11 GPIO_ACTIVE_HIGH>;	/* s1 */
	};

	gpio2: key-mux1 {
		compatible = "gpio-cascade";
		mux-controls = <&mux>;

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

		// GPIOs used by this node, the mux pin
		upstream-gpios = <&gpio 12 GPIO_ACTIVE_HIGH>; /* 1y */
	};

	gpio3: key-mux2 {
		compatible = "gpio-cascade";
		mux-controls = <&mux>;

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

		// GPIOs used by this node, the mux pin
		upstream-gpios = <&gpio 14 GPIO_ACTIVE_HIGH>; /* 2y */
	};

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

		aoss {
			label = "aoss";
			linux,code = <KEY_WPS_BUTTON>;
			gpios = <&gpio2 0 GPIO_ACTIVE_LOW>;
			debounce-interval = <60>;
		};

		reset {
			label = "reset";
			linux,code = <KEY_RESTART>;
			gpios = <&gpio2 1 GPIO_ACTIVE_LOW>;
			debounce-interval = <60>;
		};

		router_on {
			label = "router_on";
			linux,code = <BTN_5>;
			gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>;
			debounce-interval = <60>;
		};

		movie_off {
			label = "movie_off";
			linux,code = <BTN_3>;
			gpios = <&gpio2 3 GPIO_ACTIVE_HIGH>;
			debounce-interval = <60>;
		};

		usb {
			label = "usb";
			linux,code = <BTN_2>;
			gpios = <&gpio3 1 GPIO_ACTIVE_LOW>;
			debounce-interval = <60>;
		};

		router_auto {
			label = "router_auto";
			linux,code = <BTN_6>;
			gpios = <&gpio3 2 GPIO_ACTIVE_HIGH>;
			debounce-interval = <60>;
		};

		movie_on {
			label = "movie_on";
			linux,code = <BTN_4>;
			gpios = <&gpio3 3 GPIO_ACTIVE_HIGH>;
			debounce-interval = <60>;
		};
	};

	flash@1e000000 {
		compatible = "cfi-flash";
		reg = <0x1e000000 0x2000000>;
		bank-width = <2>;
		device-width = <2>;

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

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

			partition@40000 {
				label = "u-boot-env";
				reg = <0x0040000 0x0020000>;
				read-only;
			};

			partition@60000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0x0060000 0x1f60000>;
			};

			partition@1fc0000 {
				label = "user_property";
				reg = <0x1fc0000 0x0020000>;
				read-only;
			};

			partition@1fe0000 {
				label = "art";
				reg = <0x1fe0000 0x020000>;
				read-only;

				nvmem-layout {
					compatible = "fixed-layout";
					#address-cells = <1>;
					#size-cells = <1>;

					cal_art_11000: calibration@11000 {
						reg = <0x11000 0x440>;
					};

					macaddr_art_1120c: macaddr@1120c {
						reg = <0x1120c 0x6>;
					};
				};
			};
		};
	};

	leds {
		compatible = "gpio-leds";

		usb {
			function = LED_FUNCTION_USB;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 0 GPIO_ACTIVE_LOW>;
			trigger-sources = <&hub_port>;
			linux,default-trigger = "usbport";
		};

		led_diag: diag {
			label = "red:diag";
			gpios = <&gpio 1 GPIO_ACTIVE_LOW>;
		};

		wireless {
			label = "green:wireless";
			gpios = <&gpio 6 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "phy0tpt";
		};

		led_security: security {
			label = "amber:security";
			gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
		};

		router {
			label = "green:router";
			gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
		};
	};

	switch: switch {
		status = "disabled";

		gpio-sda = <&gpio 19 GPIO_ACTIVE_HIGH>;
		gpio-sck = <&gpio 20 GPIO_ACTIVE_HIGH>;

		mdio-bus {
			status = "okay";

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

			phy4: ethernet-phy@4 {
				reg = <4>;
				phy-mode = "rgmii";
			};
		};
	};
};

&mdio0 {
	status = "okay";
};

&eth0 {
	status = "disabled";

	phy-mode = "rgmii";
	nvmem-cells = <&macaddr_art_1120c>;
	nvmem-cell-names = "mac-address";

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

&mdio1 {
	status = "okay";
};

&eth1 {
	status = "disabled";

	compatible = "qca,ar9130-eth", "syscon";
	reg = <0x1a000000 0x200
		0x18070004 0x4>;

	pll-reg = <0x4 0x18 22>;
	pll-handle = <&pll>;

	phy-mode = "rgmii";
	phy-handle = <&phy4>;
	resets = <&rst 13>;
	reset-names = "mac";
	qca,mac-idx = <1>;
	nvmem-cells = <&macaddr_art_1120c>;
	nvmem-cell-names = "mac-address";
};

&wmac {
	status = "okay";

	nvmem-cells = <&cal_art_11000>;
	nvmem-cell-names = "calibration";
};

&uart {
	status = "okay";
};

&usb {
	status = "okay";
};

&usb_phy {
	status = "okay";
};