// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * at91-sama5d4ek.dts - Device Tree file for SAMA5D4 Evaluation Kit
 *
 *  Copyright (C) 2014 Atmel,
 *                2014 Nicolas Ferre <nicolas.ferre@atmel.com>
 */
/dts-v1/;
#include "sama5d4.dtsi"

/ {
	model = "Atmel SAMA5D4-EK";
	compatible = "atmel,sama5d4ek", "atmel,sama5d4", "atmel,sama5";

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

	memory@20000000 {
		reg = <0x20000000 0x20000000>;
	};

	clocks {
		slow_xtal {
			clock-frequency = <32768>;
		};

		main_xtal {
			clock-frequency = <12000000>;
		};
	};

	ahb {
		apb {
			adc0: adc@fc034000 {
				pinctrl-names = "default";
				pinctrl-0 = <
					/* external trigger conflicts with USBA_VBUS */
					&pinctrl_adc0_ad0
					&pinctrl_adc0_ad1
					&pinctrl_adc0_ad2
					&pinctrl_adc0_ad3
					&pinctrl_adc0_ad4
					>;
				/* The vref depends on JP22 of EK. If connect 1-2 then use 3.3V. connect 2-3 use 3.0V */
				atmel,adc-vref = <3300>;
				/*atmel,adc-ts-wires = <4>;*/	/* Set up ADC touch screen */
				status = "okay";		/* Enable ADC IIO support */
			};

			mmc0: mmc@f8000000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_mmc0_clk_cmd_dat0 &pinctrl_mmc0_dat1_3 &pinctrl_mmc0_cd>;
				slot@0 {
					reg = <0>;
					bus-width = <4>;
					cd-gpios = <&pioE 5 0>;
				};
			};

			ssc0: ssc@f8008000 {
				status = "okay";
			};

			spi0: spi@f8010000 {
				cs-gpios = <&pioC 3 0>, <0>, <0>, <0>;
				status = "okay";
				flash@0 {
					compatible = "atmel,at25df321a";
					spi-max-frequency = <50000000>;
					reg = <0>;
				};
			};

			i2c0: i2c@f8014000 {
				status = "okay";

				wm8904: codec@1a {
					compatible = "wlf,wm8904";
					reg = <0x1a>;
					clocks = <&pmc PMC_TYPE_SYSTEM 10>;
					clock-names = "mclk";
				};

				qt1070:keyboard@1b {
					compatible = "qt1070";
					reg = <0x1b>;
					interrupt-parent = <&pioE>;
					interrupts = <25 0x0>;
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_qt1070_irq>;
					wakeup-source;
				};

				touchscreen@4c {
					compatible = "atmel,maxtouch";
					reg = <0x4c>;
					interrupt-parent = <&pioE>;
					interrupts = <24 0x0>;
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_mxt_ts>;
				};
			};

			macb0: ethernet@f8020000 {
				pinctrl-0 = <&pinctrl_macb0_rmii &pinctrl_macb0_phy_irq>;
				phy-mode = "rmii";
				status = "okay";

				ethernet-phy@1 {
					reg = <0x1>;
					interrupt-parent = <&pioE>;
					interrupts = <1 IRQ_TYPE_LEVEL_LOW>;
				};
			};

			mmc1: mmc@fc000000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_mmc1_clk_cmd_dat0 &pinctrl_mmc1_dat1_3 &pinctrl_mmc1_cd>;
				status = "okay";
				slot@0 {
					reg = <0>;
					bus-width = <4>;
					cd-gpios = <&pioE 6 0>;
				};
			};

			usart2: serial@fc008000 {
				status = "okay";
			};

			usart3: serial@fc00c000 {
				status = "okay";
			};

			usart4: serial@fc010000 {
				status = "okay";
			};

			tcb2: timer@fc024000 {
				timer@0 {
					compatible = "atmel,tcb-timer";
					reg = <0>;
				};

				timer@1 {
					compatible = "atmel,tcb-timer";
					reg = <1>;
				};
			};

			watchdog@fc068640 {
				status = "okay";
			};

			pinctrl@fc06a000 {
				board {
					pinctrl_macb0_phy_irq: macb0_phy_irq {
						atmel,pins =
							<AT91_PIOE 1 AT91_PERIPH_GPIO AT91_PINCTRL_NONE>;
					};
					pinctrl_mmc0_cd: mmc0_cd {
						atmel,pins =
							<AT91_PIOE 5 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP_DEGLITCH>;
					};
					pinctrl_mmc1_cd: mmc1_cd {
						atmel,pins =
							<AT91_PIOE 6 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP_DEGLITCH>;
					};
					pinctrl_pck2_as_audio_mck: pck2_as_audio_mck {
						atmel,pins =
							<AT91_PIOB 10 AT91_PERIPH_B AT91_PINCTRL_NONE>;
					};
					pinctrl_usba_vbus: usba_vbus {
						atmel,pins =
							<AT91_PIOE 31 AT91_PERIPH_GPIO AT91_PINCTRL_DEGLITCH>;
					};
					pinctrl_key_gpio: key_gpio_0 {
						atmel,pins =
							<AT91_PIOE 13 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP_DEGLITCH>; /* PE13 gpio */
					};
					pinctrl_qt1070_irq: qt1070_irq {
						atmel,pins =
							<AT91_PIOE 25 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP_DEGLITCH>;
					};
					pinctrl_mxt_ts: mxt_irq {
						atmel,pins =
							<AT91_PIOE 24 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP_DEGLITCH>;
					};
				};
			};
		};

		usb0: gadget@400000 {
			atmel,vbus-gpio = <&pioE 31 GPIO_ACTIVE_HIGH>;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_usba_vbus>;
			status = "okay";
		};

		usb1: ohci@500000 {
			num-ports = <3>;
			atmel,vbus-gpio = <0 /* &pioE 10 GPIO_ACTIVE_LOW */
					   &pioE 11 GPIO_ACTIVE_LOW
					   &pioE 12 GPIO_ACTIVE_LOW
					  >;
			status = "okay";
		};

		usb2: ehci@600000 {
			status = "okay";
		};

		ebi: ebi@10000000 {
			pinctrl-0 = <&pinctrl_ebi_cs3 &pinctrl_ebi_nrd_nandoe
				     &pinctrl_ebi_nwe_nandwe &pinctrl_ebi_nandrdy
				     &pinctrl_ebi_data_0_7 &pinctrl_ebi_nand_addr>;
			pinctrl-names = "default";
			status = "okay";

			nand_controller: nand-controller {
				status = "okay";

				nand@3 {
					reg = <0x3 0x0 0x2>;
					atmel,rb = <0>;
					nand-bus-width = <8>;
					nand-ecc-mode = "hw";
					nand-on-flash-bbt;
					label = "atmel_nand";

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

						at91bootstrap@0 {
							label = "at91bootstrap";
							reg = <0x0 0x40000>;
						};

						bootloader@40000 {
							label = "bootloader";
							reg = <0x40000 0x80000>;
						};

						bootloaderenv@c0000 {
							label = "bootloader env";
							reg = <0xc0000 0xc0000>;
						};

						dtb@180000 {
							label = "device tree";
							reg = <0x180000 0x80000>;
						};

						kernel@200000 {
							label = "kernel";
							reg = <0x200000 0x600000>;
						};

						rootfs@800000 {
							label = "rootfs";
							reg = <0x800000 0x0f800000>;
						};
					};
				};
			};
		};
	};

	gpio-keys {
		compatible = "gpio-keys";

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

		button {
			label = "pb_user1";
			gpios = <&pioE 13 GPIO_ACTIVE_HIGH>;
			linux,code = <0x100>;
			wakeup-source;
		};
	};

	leds {
		compatible = "gpio-leds";
		status = "okay";

		led-d8 {
			label = "d8";
			/* PE28, conflicts with usart4 rts pin */
			gpios = <&pioE 28 GPIO_ACTIVE_LOW>;
		};

		led-d9 {
			label = "d9";
			gpios = <&pioE 9 GPIO_ACTIVE_HIGH>;
		};

		led-d10 {
			label = "d10";
			gpios = <&pioE 8 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "heartbeat";
		};
	};

	sound {
		compatible = "atmel,asoc-wm8904";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_pck2_as_audio_mck>;

		atmel,model = "wm8904 @ SAMA5D4EK";
		atmel,audio-routing =
			"Headphone Jack", "HPOUTL",
			"Headphone Jack", "HPOUTR",
			"IN1L", "Line In Jack",
			"IN1R", "Line In Jack";

		atmel,ssc-controller = <&ssc0>;
		atmel,audio-codec = <&wm8904>;
	};
};