// SPDX-License-Identifier: (GPL-2.0+ OR X11)
/*
 * at91-sama5d2_ptc_ek.dts - Device Tree file for SAMA5D2 PTC EK board
 *
 *  Copyright (C) 2017 Microchip/Atmel,
 *		  2017 Wenyou Yang <wenyou.yang@microchip.com>
 *		  2017 Ludovic Desroches <ludovic.desroches@microchip.com>
 */
/dts-v1/;
#include "sama5d2.dtsi"
#include "sama5d2-pinfunc.h"
#include <dt-bindings/mfd/atmel-flexcom.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/pinctrl/at91.h>

/ {
	model = "Atmel SAMA5D2 PTC EK";
	compatible = "atmel,sama5d2-ptc_ek", "atmel,sama5d2", "atmel,sama5";

	aliases {
		serial0 = &uart0;	/* DBGU */
		i2c0 = &i2c0;	/* mikroBUS 1 */
		i2c1 = &i2c1;	/* XPRO EXT1 */
		i2c2 = &i2c2;
	};

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

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

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

	ahb {
		usb0: gadget@300000 {
			atmel,vbus-gpio = <&pioA PIN_PB11 GPIO_ACTIVE_HIGH>;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_usba_vbus>;
			status = "okay";
		};

		usb1: ohci@400000 {
			num-ports = <3>;
			atmel,vbus-gpio = <0
					   &pioA PIN_PB12 GPIO_ACTIVE_HIGH
					   0
					  >;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_usb_default>;
			status = "okay";
		};

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

		ebi: ebi@10000000 {
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_nand_default>;
			status = "okay"; /* conflicts with sdmmc1 and qspi0 */

			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 = "bootstrap";
							reg = <0x0 0x40000>;
						};

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

						bootloaderenvred@100000 {
							label = "bootloader env redundant";
							reg = <0x100000 0x40000>;
						};

						bootloaderenv@140000 {
							label = "bootloader env";
							reg = <0x140000 0x40000>;
						};

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

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

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

		sdmmc0: sdio-host@a0000000 {
			bus-width = <8>;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_sdmmc0_default>;
			status = "okay";
		};

		apb {
			spi0: spi@f8000000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_spi0_default>;
				status = "okay";
			};

			macb0: ethernet@f8008000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_macb0_default &pinctrl_macb0_phy_irq>;
				#address-cells = <1>;
				#size-cells = <0>;
				phy-mode = "rmii";
				status = "okay";

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

			tcb0: timer@f800c000 {
				timer0: timer@0 {
					compatible = "atmel,tcb-timer";
					reg = <0>;
				};

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

			uart0: serial@f801c000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_uart0_default>;
				atmel,use-dma-rx;
				atmel,use-dma-tx;
				status = "okay";
			};

			uart2: serial@f8024000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_uart2_default>;
				atmel,use-dma-rx;
				atmel,use-dma-tx;
				status = "okay";
			};

			i2c0: i2c@f8028000 {
				dmas = <0>, <0>;
				pinctrl-names = "default", "gpio";
				pinctrl-0 = <&pinctrl_i2c0_default>;
				pinctrl-1 = <&pinctrl_i2c0_gpio>;
				sda-gpios = <&pioA PIN_PD21 GPIO_ACTIVE_HIGH>;
				scl-gpios = <&pioA PIN_PD22 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
				status = "okay";
			};

			flx0: flexcom@f8034000 {
				atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_TWI>;
				status = "okay";

				i2c2: i2c@600 {
					dmas = <0>, <0>;
					pinctrl-names = "default", "gpio";
					pinctrl-0 = <&pinctrl_flx0_default>;
					pinctrl-1 = <&pinctrl_flx0_gpio>;
					sda-gpios = <&pioA PIN_PB28 GPIO_ACTIVE_HIGH>;
					scl-gpios = <&pioA PIN_PB29 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
					status = "okay";
				};
			};

			poweroff@f8048010 {
				debounce-delay-us = <976>;

				input@0 {
					reg = <0>;
				};
			};

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

			spi1: spi@fc000000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_spi1_default>;
				status = "okay";
			};

			i2c1: i2c@fc028000 {
				dmas = <0>, <0>;
				pinctrl-names = "default", "gpio";
				pinctrl-0 = <&pinctrl_i2c1_default>;
				pinctrl-1 = <&pinctrl_i2c1_gpio>;
				sda-gpios = <&pioA PIN_PC6 GPIO_ACTIVE_HIGH>;
				scl-gpios = <&pioA PIN_PC7 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
				status = "okay";

				at24@50 {
					compatible = "atmel,24c02";
					reg = <0x50>;
					pagesize = <8>;
				};
			};

			pinctrl@fc038000 {
				pinctrl_flx0_default: flx0_default {
					pinmux = <PIN_PB28__FLEXCOM0_IO0>,
						 <PIN_PB29__FLEXCOM0_IO1>;
					bias-disable;
				};

				pinctrl_flx0_gpio: flx0_gpio {
					pinmux = <PIN_PB28__GPIO>,
						 <PIN_PB29__GPIO>;
					bias-disable;
				};

				pinctrl_i2c0_default: i2c0_default {
					pinmux = <PIN_PD21__TWD0>,
						 <PIN_PD22__TWCK0>;
					bias-disable;
				};

				pinctrl_i2c0_gpio: i2c0_gpio {
					pinmux = <PIN_PD21__GPIO>,
						 <PIN_PD22__GPIO>;
					bias-disable;
				};

				pinctrl_i2c1_default: i2c1_default {
					pinmux = <PIN_PC6__TWD1>,
						 <PIN_PC7__TWCK1>;
					bias-disable;
				};

				pinctrl_i2c1_gpio: i2c1_gpio {
					pinmux = <PIN_PC6__GPIO>,
						 <PIN_PC7__GPIO>;
					bias-disable;
				};

				pinctrl_key_gpio_default: key_gpio_default {
					pinmux = <PIN_PA10__GPIO>;
					bias-pull-up;
				};

				pinctrl_led_gpio_default: led_gpio_default {
					pinmux = <PIN_PB6__GPIO>,
						 <PIN_PB8__GPIO>,
						 <PIN_PB10__GPIO>;
					bias-pull-up;
				};

				pinctrl_macb0_default: macb0_default {
					pinmux = <PIN_PB14__GTXCK>,
						 <PIN_PB15__GTXEN>,
						 <PIN_PB16__GRXDV>,
						 <PIN_PB17__GRXER>,
						 <PIN_PB18__GRX0>,
						 <PIN_PB19__GRX1>,
						 <PIN_PB20__GTX0>,
						 <PIN_PB21__GTX1>,
						 <PIN_PB22__GMDC>,
						 <PIN_PB23__GMDIO>;
					bias-disable;
				};

				pinctrl_macb0_phy_irq: macb0_phy_irq {
					pinmux = <PIN_PB24__GPIO>;
					bias-disable;
				};

				pinctrl_nand_default: nand_default {
					re_we_data {
						pinmux = <PIN_PA22__D0>,
							 <PIN_PA23__D1>,
							 <PIN_PA24__D2>,
							 <PIN_PA25__D3>,
							 <PIN_PA26__D4>,
							 <PIN_PA27__D5>,
							 <PIN_PA28__D6>,
							 <PIN_PA29__D7>,
							 <PIN_PA30__NWE_NANDWE>,
							 <PIN_PB2__NRD_NANDOE>;
						bias-pull-up;
						atmel,drive-strength = <ATMEL_PIO_DRVSTR_ME>;
					};

					ale_cle_rdy_cs {
						pinmux = <PIN_PB0__A21_NANDALE>,
							 <PIN_PB1__A22_NANDCLE>,
							 <PIN_PC8__NANDRDY>,
							 <PIN_PA31__NCS3>;
						bias-pull-up;
					};
				};

				pinctrl_sdmmc0_default: sdmmc0_default {
					cmd_data {
						pinmux = <PIN_PA1__SDMMC0_CMD>,
							 <PIN_PA2__SDMMC0_DAT0>,
							 <PIN_PA3__SDMMC0_DAT1>,
							 <PIN_PA4__SDMMC0_DAT2>,
							 <PIN_PA5__SDMMC0_DAT3>,
							 <PIN_PA6__SDMMC0_DAT4>,
							 <PIN_PA7__SDMMC0_DAT5>,
							 <PIN_PA8__SDMMC0_DAT6>,
							 <PIN_PA9__SDMMC0_DAT7>;
						bias-pull-up;
					};

					ck_cd_vddsel {
						pinmux = <PIN_PA0__SDMMC0_CK>,
							 <PIN_PA11__SDMMC0_VDDSEL>,
							 <PIN_PA13__SDMMC0_CD>;
						bias-disable;
					};
				};

				pinctrl_spi0_default: spi0_default {
					pinmux = <PIN_PA14__SPI0_SPCK>,
						 <PIN_PA15__SPI0_MOSI>,
						 <PIN_PA16__SPI0_MISO>,
						 <PIN_PA17__SPI0_NPCS0>;
					bias-disable;
				};

				pinctrl_spi1_default: spi1_default {
					pinmux = <PIN_PC1__SPI1_SPCK>,
						 <PIN_PC2__SPI1_MOSI>,
						 <PIN_PC3__SPI1_MISO>,
						 <PIN_PC4__SPI1_NPCS0>;
					bias-disable;
				};

				pinctrl_uart0_default: uart0_default {
					pinmux = <PIN_PB26__URXD0>,
						 <PIN_PB27__UTXD0>;
					bias-disable;
				};

				pinctrl_uart2_default: uart2_default {
					pinmux = <PIN_PD23__URXD2>,
						 <PIN_PD24__UTXD2>;
					bias-disable;
				};

				pinctrl_usb_default: usb_default {
					pinmux = <PIN_PB12__GPIO>;
					bias-disable;
				};

				pinctrl_usba_vbus: usba_vbus {
					pinmux = <PIN_PB11__GPIO>;
					bias-disable;
				};

			};

		};
	};

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

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

		button-1 {
			label = "PB_USER";
			gpios = <&pioA PIN_PA10 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_PROG1>;
			wakeup-source;
		};
	};

	leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_led_gpio_default>;
		status = "okay";

		led-red {
			label = "red";
			gpios = <&pioA PIN_PB10 GPIO_ACTIVE_HIGH>;
		};

		led-green {
			label = "green";
			gpios = <&pioA PIN_PB8 GPIO_ACTIVE_HIGH>;
		};

		led-blue {
			label = "blue";
			gpios = <&pioA PIN_PB6 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "heartbeat";
		};
	};
};
