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

#include "qca953x.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/mtd/partitions/uimage.h>

/ {
	model = "Letv LBA-047-CH";
	compatible = "letv,lba-047-ch", "qca,qca9531";

	aliases {
		label-mac-device = &eth0;
		led-boot = &led_status_red;
		led-failsafe = &led_status_blue;
		led-running = &led_status_green;
		led-upgrade = &led_status_blue;
	};

	keys {
		compatible = "gpio-keys";

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

	leds {
		compatible = "gpio-leds";

		led_status_blue: led-0 {
			label = "blue:status";
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
		};

		led_status_green: led-1 {
			label = "green:status";
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
		};

		led_status_red: led-2 {
			label = "red:status";
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
		};
	};

	virtual_flash {
		compatible = "mtd-concat";
		devices = <&fwconcat0 &fwconcat1>;

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

			partition@0 {
				reg = <0x0 0x0>;
				label = "firmware";
				compatible = "openwrt,uimage", "denx,uimage";
				openwrt,ih-magic = <IH_MAGIC_OKLI>;
			};
		};
	};
};

&spi {
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <30000000>;
		m25p,fast-read;

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

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

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

			fwconcat0: partition@50000 {
				label = "fwconcat0";
				reg = <0x50000 0xe30000>;
			};

			partition@e80000 {
				label = "loader";
				reg = <0xe80000 0x10000>;
			};

			fwconcat1: partition@e90000 {
				label = "fwconcat1";
				reg = <0xe90000 0x160000>;
			};

			partition@ff0000 {
				label = "art";
				reg = <0xff0000 0x10000>;
				read-only;

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

				macaddr_art_0: macaddr@0 {
					reg = <0x0 0x6>;
				};

				macaddr_art_6: macaddr@6 {
					reg = <0x6 0x6>;
				};

				cal_art_1000: calibration@1000 {
					reg = <0x1000 0x440>;
				};
			};
		};
	};
};

&eth0 {
	status = "okay";

	phy-handle = <&swphy4>;

	nvmem-cells = <&macaddr_art_0>;
	nvmem-cell-names = "mac-address";
};

&eth1 {
	compatible = "qca,qca9530-eth", "syscon", "simple-mfd";

	nvmem-cells = <&macaddr_art_6>;
	nvmem-cell-names = "mac-address";
};

&wmac {
	status = "okay";

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