// SPDX-License-Identifier: GPL-2.0
/*
 * Device Tree file for the Verbatim S08V1901-D1
 * on product packaging called "Verbatim Gigabit Ethernet Hard Drive"
 */

/dts-v1/;

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

/ {
	model = "Verbatim Gigabit Ethernet Hard Drive S08V1901-D1";
	compatible = "verbatim,s08v1901-d1", "cortina,gemini";
	#address-cells = <1>;
	#size-cells = <1>;

	memory@0 {
		/* 64MB SDRAM in 2 x Hynix HY5DU561622ETP-D43 */
		device_type = "memory";
		reg = <0x00000000 0x4000000>;
	};

	chosen {
		bootargs = "console=ttyS0,19200n8 root=/dev/sda1 rw rootwait";
		stdout-path = &uart0;
	};

	gpio_keys {
		compatible = "gpio-keys";

		button-reset {
			debounce-interval = <50>;
			wakeup-source;
			linux,code = <KEY_RESTART>;
			label = "reset";
			gpios = <&gpio1 31 GPIO_ACTIVE_LOW>;
		};
	};

	leds {
		compatible = "gpio-leds";
		led-green-harddisk {
			function = LED_FUNCTION_DISK_ACTIVITY;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
			default-state = "off";
			linux,default-trigger = "disk-activity";
		};
	};

	/*
	 * Fan control candidates: gpio0 10, gpio1 28
	 */

	mdio0: mdio {
		compatible = "virtual,mdio-gpio";
		/* Uses MDC and MDIO */
		gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>, /* MDC */
			<&gpio0 21 GPIO_ACTIVE_HIGH>; /* MDIO */
		#address-cells = <1>;
		#size-cells = <0>;

		/* This is a Realtek RTL8211CL ethernet PHY */
		phy0: ethernet-phy@1 {
			reg = <1>;
		};
	};

	/*
	 * I haven't found a way to control the fan, it appears to be
	 * always on.
	 */
	thermal-zones {
		chassis-thermal {
			/* Poll every 20 seconds */
			polling-delay = <20000>;
			/* Poll every 2nd second when cooling */
			polling-delay-passive = <2000>;
			/*  Use the thermal sensor in the hard drive */
			thermal-sensors = <&drive0>;

			/* Tripping points from the fan.script in the rootfs */
			trips {
				alert: chassis-alert {
					/* At 43 degrees turn on the fan */
					temperature = <43000>;
					hysteresis = <3000>;
					type = "active";
				};
				crit: chassis-crit {
					/* Just shut down at 60 degrees */
					temperature = <60000>;
					hysteresis = <2000>;
					type = "critical";
				};
			};
		};
	};

	soc {
		flash@30000000 {
			/*
			 * This is a Spansion S29GL128P11TFI01 852FB245 A
			 * 128Mbit (16MB) Flash memory.
			 */
			status = "okay";
			reg = <0x30000000 0x01000000>;

			partitions {
				compatible = "redboot-fis";
				/* Eraseblock at 0xfe0000 */
				fis-index-block = <0x7f>;
			};
		};

		syscon: syscon@40000000 {
			pinctrl {
				/*
				 * gpio0agrp cover line 0-4 as line 1 is used for the LED
				 * gpio0hgrp cover line 21, 22 used by MDIO for Marvell PHY
				 */
				gpio0_default_pins: pinctrl-gpio0 {
					mux {
						function = "gpio0";
						groups = "gpio0agrp", "gpio0hgrp";
					};
				};
				gpio1_default_pins: pinctrl-gpio1 {
					/*
					 * Free up the TVC pins at GPIO1 offset 28,29,30,31
					 * line 31 is used for reset key
					 */
					mux {
						function = "gpio1";
						groups = "gpio1dgrp";
					};
				};
				pinctrl-gmii {
					mux {
						function = "gmii";
						groups = "gmii_gmac0_grp";
					};
					/* TODO: investigate vendor registers on boot */
					conf0 {
						pins = "V8 GMAC0 RXDV";
						skew-delay = <0>;
					};
					conf1 {
						pins = "Y7 GMAC0 RXC";
						skew-delay = <15>;
					};
					conf2 {
						pins = "T8 GMAC0 TXEN";
						skew-delay = <7>;
					};
					conf3 {
						pins = "U8 GMAC0 TXC";
						skew-delay = <10>;
					};
					conf4 {
						/* The data lines all have default skew */
						pins = "W8 GMAC0 RXD0", "V9 GMAC0 RXD1",
						       "Y8 GMAC0 RXD2", "U9 GMAC0 RXD3",
						       "T7 GMAC0 TXD0", "U6 GMAC0 TXD1",
						       "V7 GMAC0 TXD2", "U7 GMAC0 TXD3";
						skew-delay = <7>;
					};
				};
			};
		};

		/* Both interfaces brought out on SATA connectors */
		sata: sata@46000000 {
			cortina,gemini-ata-muxmode = <0>;
			cortina,gemini-enable-sata-bridge;
			status = "okay";
		};

		gpio0: gpio@4d000000 {
			pinctrl-names = "default";
			pinctrl-0 = <&gpio0_default_pins>;
		};

		gpio1: gpio@4e000000 {
			pinctrl-names = "default";
			pinctrl-0 = <&gpio1_default_pins>;
		};

		ethernet@60000000 {
			status = "okay";

			ethernet-port@0 {
				phy-mode = "rgmii";
				phy-handle = <&phy0>;
			};
		};

		ide@63000000 {
			status = "okay";
			/*
			 * This drive may have a temperature sensor with a
			 * thermal zone we can use for thermal control of the
			 * chassis temperature using the fan.
			 */
			drive0: ide-port@0 {
				reg = <0>;
				#thermal-sensor-cells = <0>;
			};
		};

		ide@63400000 {
			status = "okay";
		};

		usb@68000000 {
			status = "okay";
		};

		usb@69000000 {
			status = "okay";
		};
	};
};