// SPDX-License-Identifier: GPL-2.0+
/*
 * Device Tree file for the Kontron SMARC-sAL28 board.
 *
 * Copyright (C) 2021 Michael Walle <michael@walle.cc>
 *
 */

/dts-v1/;
#include "fsl-ls1028a.dtsi"
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
	model = "Kontron SMARC-sAL28";
	compatible = "kontron,sl28", "fsl,ls1028a";

	aliases {
		crypto = &crypto;
		serial0 = &duart0;
		serial1 = &duart1;
		serial2 = &lpuart1;
		spi0 = &fspi;
		spi1 = &dspi2;
		mmc0 = &esdhc1;
		mmc1 = &esdhc;
		rtc0 = &rtc;
		rtc1 = &ftm_alarm0;
	};

	buttons0 {
		compatible = "gpio-keys";

		power-button {
			interrupts-extended = <&sl28cpld_intc
					       4 IRQ_TYPE_EDGE_BOTH>;
			linux,code = <KEY_POWER>;
			label = "Power";
		};

		sleep-button {
			interrupts-extended = <&sl28cpld_intc
					       5 IRQ_TYPE_EDGE_BOTH>;
			linux,code = <KEY_SLEEP>;
			label = "Sleep";
		};
	};

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

		lid-switch {
			linux,input-type = <EV_SW>;
			linux,code = <SW_LID>;
			gpios = <&sl28cpld_gpio3 4 GPIO_ACTIVE_LOW>;
			label = "Lid";
		};
	};

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

&can0 {
	status = "okay";
};

&dspi2 {
	status = "okay";
};

&duart0 {
	status = "okay";
};

&duart1 {
	status = "okay";
};

&enetc_mdio_pf3 {
	phy0: ethernet-phy@5 {
		reg = <0x5>;
		eee-broken-1000t;
		eee-broken-100tx;
	};
};

&enetc_port0 {
	phy-handle = <&phy0>;
	phy-mode = "sgmii";
	managed = "in-band-status";
	nvmem-cells = <&base_mac_address 0>;
	nvmem-cell-names = "mac-address";
	status = "okay";
};

&esdhc {
	sd-uhs-sdr104;
	sd-uhs-sdr50;
	sd-uhs-sdr25;
	sd-uhs-sdr12;
	status = "okay";
};

&esdhc1 {
	mmc-hs200-1_8v;
	mmc-hs400-1_8v;
	bus-width = <8>;
	status = "okay";
};

&fspi {
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		m25p,fast-read;
		spi-max-frequency = <133000000>;
		reg = <0>;
		/* The following setting enables 1-1-2 (CMD-ADDR-DATA) mode */
		spi-rx-bus-width = <2>; /* 2 SPI Rx lines */
		spi-tx-bus-width = <1>; /* 1 SPI Tx line */

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

			partition@0 {
				reg = <0x000000 0x010000>;
				label = "rcw";
				read-only;
			};

			partition@10000 {
				reg = <0x010000 0x1d0000>;
				label = "failsafe bootloader";
				read-only;
			};

			partition@200000 {
				reg = <0x200000 0x010000>;
				label = "configuration store";
			};

			partition@210000 {
				reg = <0x210000 0x1d0000>;
				label = "bootloader";
			};

			partition@3e0000 {
				reg = <0x3e0000 0x020000>;
				label = "bootloader environment";
			};
		};

		otp-1 {
			compatible = "user-otp";

			nvmem-layout {
				compatible = "kontron,sl28-vpd";

				serial_number: serial-number {
				};

				base_mac_address: base-mac-address {
					#nvmem-cell-cells = <1>;
				};
			};
		};
	};
};

&ftm_alarm0 {
	status = "okay";
};

&gpio1 {
	gpio-line-names =
		"", "", "", "", "", "", "", "",
		"", "", "", "", "", "", "", "",
		"", "", "", "", "", "", "TDO", "TCK",
		"", "", "", "", "", "", "", "";
};

&gpio2 {
	gpio-line-names =
		"", "", "", "", "", "", "TMS", "TDI",
		"", "", "", "", "", "", "", "",
		"", "", "", "", "", "", "", "",
		"", "", "", "", "", "", "", "";
};

&i2c0 {
	status = "okay";

	rtc: rtc@32 {
		compatible = "microcrystal,rv8803";
		reg = <0x32>;
	};

	sl28cpld@4a {
		compatible = "kontron,sl28cpld";
		reg = <0x4a>;
		#address-cells = <1>;
		#size-cells = <0>;

		watchdog@4 {
			compatible = "kontron,sl28cpld-wdt";
			reg = <0x4>;
			kontron,assert-wdt-timeout-pin;
		};

		hwmon@b {
			compatible = "kontron,sl28cpld-fan";
			reg = <0xb>;
		};

		sl28cpld_pwm0: pwm@c {
			compatible = "kontron,sl28cpld-pwm";
			reg = <0xc>;
			#pwm-cells = <2>;
		};

		sl28cpld_pwm1: pwm@e {
			compatible = "kontron,sl28cpld-pwm";
			reg = <0xe>;
			#pwm-cells = <2>;
		};

		sl28cpld_gpio0: gpio@10 {
			compatible = "kontron,sl28cpld-gpio";
			reg = <0x10>;
			interrupts-extended = <&gpio2 6
					       IRQ_TYPE_EDGE_FALLING>;

			gpio-controller;
			#gpio-cells = <2>;
			gpio-line-names =
				"GPIO0_CAM0_PWR_N", "GPIO1_CAM1_PWR_N",
				"GPIO2_CAM0_RST_N", "GPIO3_CAM1_RST_N",
				"GPIO4_HDA_RST_N", "GPIO5_PWM_OUT",
				"GPIO6_TACHIN", "GPIO7";

			interrupt-controller;
			#interrupt-cells = <2>;
		};

		sl28cpld_gpio1: gpio@15 {
			compatible = "kontron,sl28cpld-gpio";
			reg = <0x15>;
			interrupts-extended = <&gpio2 6
					       IRQ_TYPE_EDGE_FALLING>;

			gpio-controller;
			#gpio-cells = <2>;
			gpio-line-names =
				"GPIO8", "GPIO9", "GPIO10", "GPIO11",
				"", "", "", "";

			interrupt-controller;
			#interrupt-cells = <2>;
		};

		sl28cpld_gpio2: gpio@1a {
			compatible = "kontron,sl28cpld-gpo";
			reg = <0x1a>;

			gpio-controller;
			#gpio-cells = <2>;
			gpio-line-names =
				"LCD0 voltage enable",
				"LCD0 backlight enable",
				"eMMC reset", "LVDS bridge reset",
				"LVDS bridge power-down",
				"SDIO power enable",
				"", "";
		};

		sl28cpld_gpio3: gpio@1b {
			compatible = "kontron,sl28cpld-gpi";
			reg = <0x1b>;

			gpio-controller;
			#gpio-cells = <2>;
			gpio-line-names =
				"Power button", "Force recovery", "Sleep",
				"Battery low", "Lid state", "Charging",
				"Charger present", "";
		};

		sl28cpld_intc: interrupt-controller@1c {
			compatible = "kontron,sl28cpld-intc";
			reg = <0x1c>;
			interrupts-extended = <&gpio2 6
					       IRQ_TYPE_EDGE_FALLING>;

			interrupt-controller;
			#interrupt-cells = <2>;
		};
	};

	eeprom@50 {
		compatible = "atmel,24c32";
		reg = <0x50>;
		pagesize = <32>;
	};
};

&i2c3 {
	status = "okay";
};

&i2c4 {
	status = "okay";

	eeprom@50 {
		compatible = "atmel,24c32";
		reg = <0x50>;
		pagesize = <32>;
	};
};

&lpuart1 {
	status = "okay";
};

&mscc_felix_port4 {
	dsa-tag-protocol = "ocelot-8021q";
};

&mscc_felix_port5 {
	dsa-tag-protocol = "ocelot-8021q";
};

&usb0 {
	status = "okay";
};

&usb1 {
	dr_mode = "host";
	status = "okay";
};
