// SPDX-License-Identifier: GPL-2.0

#include "pxa3xx.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/interrupt-controller/irq.h>

/ {
	/* Will be overridden by bootloader */
	hw-revision = <0>;

	chosen {
		bootargs = "root=ubi0:RootFS rootfstype=ubifs rw ubi.mtd=3";
		stdout-path = &ffuart;
	};

	memory {
		device_type = "memory";
		reg = <0xa0000000 0x8000000>;	/* 128 MB */
	};

	reg_3v3: regulator-3v3 {
		compatible = "regulator-fixed";
		regulator-name = "3v3-fixed-supply";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};

	reg_1v8: regulator-1v8 {
		compatible = "regulator-fixed";
		regulator-name = "1v8-fixed-supply";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-always-on;
	};

	reg_va_5v0: regulator-va-5v0 {
		compatible = "regulator-fixed";
		regulator-name = "va-5v0-fixed-supply";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&gpio 124 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	ssp_dai0: ssp-dai0 {
		compatible = "mrvl,pxa-ssp-dai";
		pinctrl-names = "default";
		pinctrl-0 = <&ssp0_dai_pins>;
		port = <&ssp1>;
		#sound-dai-cells = <0>;
		dmas = <&pdma 13 3
			&pdma 14 3>;
		dma-names = "rx", "tx";
		clock-names = "extclk";
	};

	ssp_dai1: ssp-dai1 {
		compatible = "mrvl,pxa-ssp-dai";
		pinctrl-names = "default";
		pinctrl-0 = <&ssp1_dai_pins>;
		port = <&ssp2>;
		#sound-dai-cells = <0>;
		dmas = <&pdma 15 3
			&pdma 16 3>;
		dma-names = "rx", "tx";
		clock-names = "extclk";
	};

	spi: spi {
		compatible = "spi-gpio";
		#address-cells = <0x1>;
		#size-cells = <0>;
		pinctrl-names = "default";
		pinctrl-0 = <&spi_pins>;
		gpio-sck = <&gpio 95 GPIO_ACTIVE_HIGH>;
		gpio-miso = <&gpio 98 GPIO_ACTIVE_HIGH>;
		gpio-mosi = <&gpio 97 GPIO_ACTIVE_HIGH>;
		cs-gpios = <
			&gpio 34 GPIO_ACTIVE_HIGH
			&gpio 125 GPIO_ACTIVE_HIGH
			&gpio 96 GPIO_ACTIVE_HIGH
		>;
		num-chipselects = <3>;

		dac: dac@2 {
			compatible = "ti,dac7512";
			reg = <2>;
			spi-max-frequency = <1000000>;
			vcc-supply = <&reg_3v3>;
		};
	};

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

		on-off {
			label = "on_off button";
			gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_F6>;
		};

		rescue-boot {
			label = "rescue boot button";
			gpios = <&gpio 115 GPIO_ACTIVE_HIGH>;
			linux,code = <KEY_F4>;
		};

		setup {
			label = "setup";
			gpios = <&gpio 119 GPIO_ACTIVE_HIGH>;
			linux,code = <KEY_F3>;
		};
	};

	rotary: rotary-encoder {
		compatible = "rotary-encoder";
		gpios = <
			&gpio 19 GPIO_ACTIVE_LOW
			&gpio 20 GPIO_ACTIVE_HIGH
		>;
		linux,axis = <REL_X>;
		rotary-encoder,relative-axis;
	};

	leds: leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&led_pins_a &led_pins_b>;

		left {
			label = "raumfeld:1";
			gpios = <&gpio 36 GPIO_ACTIVE_LOW>;
		};

		right {
			label = "raumfeld:2";
			gpios = <&gpio 35 GPIO_ACTIVE_HIGH>;
		};
	};

	poweroff {
		compatible = "gpio-poweroff";
		pinctrl-names = "default";
		pinctrl-0 = <&poweroff_pins>;
		gpios = <&gpio 16 GPIO_ACTIVE_HIGH>;
	};

	mmc0_pwrseq: mmc-pwrseq {
		compatible = "mmc-pwrseq-simple";
		pinctrl-names = "default";
		pinctrl-0 = <&mmc0_pwrseq_pins>;
		reset-gpios = <
			&gpio 113 GPIO_ACTIVE_LOW	/* W2W_RESET	*/
			&gpio 114 GPIO_ACTIVE_LOW	/* W2W_PDN	*/
		>;
	};

	ethernet: ethernet@10000000 {
		compatible = "smsc,lan9115";
		pinctrl-names = "default";
		pinctrl-0 = <&smsc_pins &smsc_bus_pins>;
		reg = <0x10000000 0x100000>;
		phy-mode = "mii";
		interrupt-parent = <&gpio>;
		interrupts = <40 IRQ_TYPE_EDGE_FALLING>;
		vdd33a-supply = <&reg_3v3>;
		vddvario-supply = <&reg_1v8>;
		reset-gpios = <&gpio 39 GPIO_ACTIVE_LOW>;
		reg-io-width = <4>;
		smsc,save-mac-address;
		smsc,irq-push-pull;
	};
};

&ffuart {
	status = "okay";
};

&pwri2c {
	status = "okay";

	max8660: regulator@34 {
		compatible = "maxim,max8660";
		reg = <0x34>;

		regulators {
			regulator-v3 {
				regulator-compatible = "V3(DCDC)";
				regulator-min-microvolt = <725000>;
				regulator-max-microvolt = <1800000>;
			};

			regulator-v4 {
				regulator-compatible = "V4(DCDC)";
				regulator-min-microvolt = <725000>;
				regulator-max-microvolt = <1800000>;
			};

			regulator-v5 {
				regulator-compatible = "V5(LDO)";
				regulator-min-microvolt = <1700000>;
				regulator-max-microvolt = <2000000>;
			};

			reg_vcc_sdio: regulator-v6 {
				regulator-compatible = "V6(LDO)";
				regulator-min-microvolt = <3300000>;
				regulator-max-microvolt = <3300000>;
			};

			regulator-v7 {
				regulator-compatible = "V7(LDO)";
				regulator-min-microvolt = <1800000>;
				regulator-max-microvolt = <3300000>;
			};
		};
	};
};

&pxai2c1 {
	status = "okay";
	mrvl,i2c-fast-mode;
	pinctrl-names = "default";
	pinctrl-0 = <&pxai2c1_pins>;
};

&ssp1 {
	status = "okay";
};

&ssp2 {
	status = "okay";
};

&nand_controller {
	status = "okay";

	nand@0 {
		reg = <0>;
		nand-rb = <0>;
		nand-ecc-mode = "hw";
		marvell,nand-keep-config;

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

			partition@0 {
				label = "Bootloader";
				reg = <0x0000000 0xa0000>;
				read-only;
			};

			partition@a0000 {
				label = "BootloaderEnvironment";
				reg = <0x0a0000 0x20000>;
			};

			partition@c0000 {
				label = "BootloaderSplashScreen";
				reg = <0x0c0000 0x60000>;
			};

			partition@120000 {
				label = "UBI";
				reg = <0x120000 0x7ee0000>;
			};
		};
	};
};

&usb0 {
	status = "okay";
	marvell,enable-port1;
	marvell,port-mode = <2>; /* PMM_GLOBAL_MODE */
	pinctrl-names = "default";
	pinctrl-0 = <&pxa3xx_ohci_pins>;
};

&mmc0 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&mmc0_pins>;
	pxa-mmc,detect-delay-ms = <200>;
	vmmc-supply = <&reg_vcc_sdio>;
	mmc-pwrseq = <&mmc0_pwrseq>;
	non-removable;
	bus-width = <4>;
};

&pinctrl {
	poweroff_pins: poweroff-pins {
		pinctrl-single,pins = <MFP_PIN_PXA300(16) MFP_AF0>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_FLOAT);
	};

	led_pins_a: led-pins-a {
		pinctrl-single,pins = <MFP_PIN_PXA300(35) MFP_AF0>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_PULL_LOW);
	};

	led_pins_b: led-pins-b {
		pinctrl-single,pins = <MFP_PIN_PXA300(36) MFP_AF0>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_DRIVE_HIGH);
	};

	pxai2c1_pins: pxai2c1-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(21) MFP_AF1	/* I2C_SCL	*/
			MFP_PIN_PXA300(22) MFP_AF1	/* I2C_SDA	*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_PULL_HIGH);
	};

	gpio_keys_pins: gpio-keys-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(14) MFP_AF0	/* on-off	*/
			MFP_PIN_PXA300(115) MFP_AF0	/* rescue boot	*/
			MFP_PIN_PXA300(119) MFP_AF0	/* setup	*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_FLOAT);
	};

	spi_pins: spi-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(95) MFP_AF0	/* SCK		*/
			MFP_PIN_PXA300(97) MFP_AF0	/* MOSI		*/
			MFP_PIN_PXA300(98) MFP_AF0	/* MISO		*/
			MFP_PIN_PXA300(34) MFP_AF0	/* CS#0		*/
			MFP_PIN_PXA300(125) MFP_AF0	/* CS#1		*/
			MFP_PIN_PXA300(96) MFP_AF0	/* CS#2		*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_PULL_LOW);
	};

	pxa3xx_ohci_pins: pxa3xx-ohci-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300_2(0) MFP_AF1	/* USBHPEN	*/
			MFP_PIN_PXA300_2(1) MFP_AF1	/* USBHPWR	*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_PULL_LOW);
	};

	smsc_pins: smsc-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(39) MFP_AF0	/* RESET	*/
			MFP_PIN_PXA300(40) MFP_AF0	/* IRQ		*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_PULL_LOW);
	};

	smsc_bus_pins: smsc-bus-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(1) MFP_AF1	/* nCS2		*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_FLOAT);
	};

	mmc0_pins: mmc0-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(3) MFP_AF4	/* MMC1_DAT0	*/
			MFP_PIN_PXA300(4) MFP_AF4	/* MMC1_DAT1	*/
			MFP_PIN_PXA300(5) MFP_AF4	/* MMC1_DAT2	*/
			MFP_PIN_PXA300(6) MFP_AF4	/* MMC1_DAT3	*/
			MFP_PIN_PXA300(7) MFP_AF4	/* MMC1_CLK	*/
			MFP_PIN_PXA300(8) MFP_AF4	/* MMC1_CMD	*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_DRIVE_HIGH);
	};

	mmc0_pwrseq_pins: mmc0-pwrseq-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(113) MFP_AF0	/* W2W_RESET	*/
			MFP_PIN_PXA300(114) MFP_AF0	/* W2W_PDN	*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_FLOAT);
	};

	ssp0_dai_pins: ssp0-dai-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(85) MFP_AF1	/* SSP1_SCLK	*/
			MFP_PIN_PXA300(86) MFP_AF1	/* SSP1_FRM	*/
			MFP_PIN_PXA300(87) MFP_AF1	/* SSP1_TXD	*/
			MFP_PIN_PXA300(88) MFP_AF1	/* SSP1_RXD	*/
			MFP_PIN_PXA300(89) MFP_AF1	/* SSP1_EXTCLK	*/
			MFP_PIN_PXA300(90) MFP_AF1	/* SSP1_SYSCLK	*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_PULL_LOW);
	};

	ssp1_dai_pins: ssp1-dai-pins {
		pinctrl-single,pins = <
			MFP_PIN_PXA300(25) MFP_AF2	/* SSP2_SCLK	*/
			MFP_PIN_PXA300(26) MFP_AF2	/* SSP2_FRM	*/
			MFP_PIN_PXA300(27) MFP_AF2	/* SSP2_TXD	*/
			MFP_PIN_PXA300(29) MFP_AF2	/* SSP2_EXTCLK	*/
		>;
		pinctrl-single,low-power-mode = MFP_LPM(MFP_LPM_PULL_LOW);
	};
};
