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

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/leds/common.h>
#include "armada-7040.dtsi"

/ {
	model = "Check Point V-80";
	compatible = "checkpoint,v-80", "marvell,armada7040",
		     "marvell,armada-ap806-quad", "marvell,armada-ap806";

	aliases {
		ethernet0 = &cp0_eth0;
		ethernet1 = &cp0_eth1;
		mmc0 = &ap_sdhci0;
		mmc1 = &cp0_sdhci0;
		led-boot = &led_power_blue;
		led-failsafe = &led_power_red;
		led-running = &led_power_blue;
		led-upgrade = &led_power_blue;
		label-mac-device = &cp0_eth1;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	memory@0 {
		device_type = "memory";
		reg = <0x00000000 0x00000000 0x00000000 0x80000000>;
	};

	keys {
		compatible = "gpio-keys";
		pinctrl-0 = <&pmx_gpio_keys_pins>;
		pinctrl-names = "default";

		button-reset {
			label = "reset";
			gpios = <&cp0_gpio1 12 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};
	};

	leds {
		compatible = "gpio-leds";
		pinctrl-0 = <&pmx_gpio_leds_pins>;
		pinctrl-names = "default";

		/* populated but no hole on the case */
		led-0 {
			gpios = <&cp0_gpio1 13 GPIO_ACTIVE_LOW>;
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_WLAN;
		};

		led_power_red: led-1 {
			gpios = <&cp0_gpio1 23 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_POWER;
		};

		led-2 {
			gpios = <&cp0_gpio1 26 GPIO_ACTIVE_LOW>;
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_WAN_ONLINE;
		};

		/* populated but no hole on the case */
		led-3 {
			gpios = <&cp0_gpio2 1 GPIO_ACTIVE_LOW>;
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_WLAN;
		};

		led_power_blue: led-4 {
			gpios = <&cp0_gpio2 2 GPIO_ACTIVE_LOW>;
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_POWER;
		};

		led-5 {
			gpios = <&cp0_gpio2 19 GPIO_ACTIVE_LOW>;
			color = <LED_COLOR_ID_RED>;
			function = "management";
		};

		led-6 {
			gpios = <&cp0_gpio2 20 GPIO_ACTIVE_LOW>;
			color = <LED_COLOR_ID_BLUE>;
			function = "management";
		};

		led-7 {
			gpios = <&cp0_gpio2 22 GPIO_ACTIVE_LOW>;
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_WAN_ONLINE;
		};
	};

	regulator-usb-vbus {
		compatible = "regulator-fixed";
		pinctrl-0 = <&pmx_reg_usb_vbus_pins>;
		pinctrl-names = "default";
		regulator-name = "usb-vbus";
		gpios = <&cp0_gpio1 24 GPIO_ACTIVE_HIGH>;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		enable-active-high;
		regulator-always-on;
	};
};

/* USB Type-C UART console */
&uart0 {
	status = "okay";

	pinctrl-0 = <&uart0_pins>;
	pinctrl-names = "default";
};

/*
 * internal MicroSD slot
 * (Note: not populated on some HW versions)
 */
&ap_sdhci0 {
	status = "okay";

	pinctrl-0 = <&pmx_ap_sdhci0_pins>;
	pinctrl-names = "default";
	bus-width = <4>;
	cd-gpios = <&cp0_gpio1 6 GPIO_ACTIVE_LOW>;
	/*
	 * Not stable in HS modes - phy needs "more calibration", so add
	 * the "slow-mode" and disable SDR104, SDR50 and DDR50 modes.
	 */
	marvell,xenon-phy-slow-mode;
	no-1-8-v;
};

&cp0_pinctrl {
	pinctrl-0 = <&pmx_board_id_pins>;
	pinctrl-names = "default";

	pmx_ap_sdhci0_pins: ap-sdhci0-pins {
		marvell,pins = "mpp6";
		marvell,function = "gpio";
	};

	pmx_cp0_mdio_pins: cp0-mdio-pins {
		marvell,pins = "mpp27", "mpp28";
		marvell,function = "ge";
	};

	pmx_cp0_spi1_pins: cp0-spi1-pins {
		marvell,pins = "mpp47", "mpp48", "mpp49", "mpp50";
		marvell,function = "spi1";
	};

	pmx_cp0_i2c0_pins: cp0-i2c0-pins {
		marvell,pins = "mpp37", "mpp38";
		marvell,function = "i2c0";
	};

	pmx_cp0_i2c1_pins: cp0-i2c1-pins {
		marvell,pins = "mpp2", "mpp3";
		marvell,function = "i2c1";
	};

	pmx_cp0_sdhci0_pins: cp0-sdhci0-pins {
		marvell,pins = "mpp56", "mpp57", "mpp58", "mpp59", "mpp60", "mpp61";
		marvell,function = "sdio";
	};

	pmx_gpio_keys_pins: gpio-keys-pins {
		marvell,pins = "mpp12";
		marvell,function = "gpio";
	};

	pmx_gpio_leds_pins: gpio-leds-pins {
		marvell,pins = "mpp13", "mpp23", "mpp26", "mpp33", "mpp34", "mpp51",
			       "mpp52", "mpp54";
		marvell,function = "gpio";
	};

	pmx_reg_usb_vbus_pins: reg-usb-vbus-pins {
		marvell,pins = "mpp24";
		marvell,function = "gpio";
	};

	pmx_board_id_pins: board-id-pins {
		marvell,pins = "mpp4", "mpp10", "mpp62";
		marvell,function = "gpio";
	};

	pmx_eeprom_wp_pins: eeprom-wp-pins {
		marvell,pins = "mpp55";
		marvell,function = "gpio";
	};
};

&cp0_mdio {
	status = "okay";

	pinctrl-0 = <&pmx_cp0_mdio_pins>;
	pinctrl-names = "default";

	/* Marvell 88E6352 */
	switch@0 {
		compatible = "marvell,mv88e6085";
		reg = <0x0>;

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

			swport0: port@0 {
				reg = <0x0>;
				label = "lan5";
				phy-handle = <&swphy0>;
			};

			swport1: port@1 {
				reg = <0x1>;
				label = "lan4";
				phy-handle = <&swphy1>;
			};

			swport2: port@2 {
				reg = <0x2>;
				label = "lan3";
				phy-handle = <&swphy2>;
			};

			swport3: port@3 {
				reg = <0x3>;
				label = "lan2";
				phy-handle = <&swphy3>;
			};

			swport4: port@4 {
				reg = <0x4>;
				label = "lan1";
				phy-handle = <&swphy4>;
			};

			port@5 {
				reg = <0x5>;
				ethernet = <&cp0_eth0>;
				phy-connection-type = "sgmii";

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

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

			swphy0: switch-phy@0 {
				reg = <0x0>;
			};

			swphy1: switch-phy@1 {
				reg = <0x1>;
			};

			swphy2: switch-phy@2 {
				reg = <0x2>;
			};

			swphy3: switch-phy@3 {
				reg = <0x3>;
			};

			swphy4: switch-phy@4 {
				reg = <0x4>;
			};
		};
	};

	/* Marvell 88E1512 */
	ethphy1: ethernet-phy@1 {
		compatible = "ethernet-phy-id0141,0dd1",
			     "ethernet-phy-ieee802.3-c22";
		reg = <0x1>;
		/*
		 * LED[0] (Green): LINK/ACT
		 * LED[1] (Amber): SPEED 100/1000M
		 */
		marvell,reg-init = <3 16 0 0x61>;
	};
};

&cp0_ethernet {
	status = "okay";
};

/* LAN1-5 (Switch) */
&cp0_eth0 {
	status = "okay";

	phy-connection-type = "sgmii";
	phys = <&cp0_comphy2 0>;

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

/* "WAN" */
&cp0_eth1 {
	status = "okay";

	phy-connection-type = "sgmii";
	phy-handle = <&ethphy1>;
	phys = <&cp0_comphy0 1>;
};

&cp0_gpio1 {
	board-id-1 {
		gpio-hog;
		gpios = <4 GPIO_ACTIVE_HIGH>;
		input;
	};

	board-id-0 {
		gpio-hog;
		gpios = <10 GPIO_ACTIVE_HIGH>;
		input;
	};
};

&cp0_gpio2 {
	board-id-2 {
		gpio-hog;
		gpios = <30 GPIO_ACTIVE_HIGH>;
		input;
	};
};

/* 2x NCT7802Y, EEPROM */
&cp0_i2c0 {
	status = "okay";

	pinctrl-names = "default";
	pinctrl-0 = <&pmx_cp0_i2c0_pins>;
	clock-frequency = <100000>;

	hwmon@28 {
		compatible = "nuvoton,nct7802";
		reg = <0x28>;
	};

	hwmon@29 {
		compatible = "nuvoton,nct7802";
		reg = <0x29>;
	};

	/* Giantec GT24C04A */
	eeprom@54 {
		compatible = "atmel,24c04";
		pinctrl-0 = <&pmx_eeprom_wp_pins>;
		pinctrl-names = "default";
		reg = <0x54>;
		wp-gpios = <&cp0_gpio2 23 GPIO_ACTIVE_HIGH>;
		read-only;
	};
};

/* RTC */
&cp0_i2c1 {
	status = "okay";

	pinctrl-names = "default";
	pinctrl-0 = <&pmx_cp0_i2c1_pins>;
	clock-frequency = <100000>;

	rtc@68 {
		compatible = "dallas,ds1337";
		reg = <0x68>;
	};
};

/* eMMC */
&cp0_sdhci0 {
	status = "okay";

	pinctrl-names = "default";
	pinctrl-0 = <&pmx_cp0_sdhci0_pins>;
	bus-width = <4>;
	non-removable;
};

/*
 * mPCIe slot
 * (Note: not populated on some HW versions)
 */
&cp0_pcie2 {
	status = "okay";

	phys = <&cp0_comphy5 2>;
	phy-names = "cp0-pcie2-x1-phy";
};

&cp0_utmi {
	status = "okay";
};

/* USB 3.0 Type-A */
&cp0_usb3_0 {
	status = "okay";

	dr_mode = "host";
	phys = <&cp0_comphy1 0>, <&cp0_utmi0>;
	phy-names = "cp0-usb3h0-comphy", "utmi";
};
