// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * acme-rfid.dts - Device Tree file for Acme RFID
 *
 *  Copyright (C) 2015 Atmel,
 *                2015 Nicolas Ferre <nicolas.ferre@atmel.com>
 * 	
 *  Copyright (C) 2024 Sergio Tanzilli <tanzilli@acmesystems.it>
 */
/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> 

/ {
	model = "Acme Systems RFID";
	compatible = "atmel,sama5d2-roadrunner", "atmel,sama5d2", "atmel,sama5";

	aliases {
		spi0 = &spi5;
	};


	chosen {
		stdout-path = "serial0:115200n8";
		bootargs = "mem=256M console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait net.ifnames=0";
	};

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

		main_xtal {
			clock-frequency = <12000000>;
		};
	};
 
	ahb {
		usb0: gadget@300000 {
			status = "disabled";
		};

		usb1: ohci@400000 {
			num-ports = <3>;
			status = "okay";
		};

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

		sdmmc1: sdio-host@b0000000 {
			bus-width = <4>;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_sdmmc1_default>;
			status = "okay"; /* conflict with qspi0 */
		};

		apb {
			macb0: ethernet@f8008000 {
				pinctrl-names = "default";
				/* pinctrl-0 = <&pinctrl_macb0_default &pinctrl_macb0_phy_irq>; */
				pinctrl-0 = <&pinctrl_macb0_default>; 
				phy-mode = "rmii";
				status = "okay";

				#address-cells = <1>;
				#size-cells = <0>;

				/*
				nvmem-cells = <&eth0_addr>;
				nvmem-cell-names = "mac-address";


				ethernet-phy@1 {
					reg = <0x1>;
				}; 
				*/
			};

			/* Lettore RFID */ 
			flx3: flexcom@fc014000 {
				atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_SPI>;
				status = "okay";

				spi5: spi@400 {
					dmas = <0>, <0>;
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_flx3_default>;
					status = "okay"; 
				
					device@0 { 
						compatible = "linux,spidev";  
						reg = <0>; 
						spi-max-frequency = <1000000>; 
					};
				};
			};

			/* Acme Sensor */ 
			flx4: flexcom@fc018000 {
				atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_SPI>;
				status = "okay";

				i2c6: i2c@600 {
					dmas = <0>, <0>;
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_flx4_default>;
					status = "okay";
				};
			};

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

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

			/* Debug port */	
			uart1: serial@f8020000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_uart1_default>;
				atmel,use-dma-rx;
				atmel,use-dma-tx;
				status = "okay";
			};

			shdwc@f8048010 {
				atmel,shdwc-debouncer = <976>;
				atmel,wakeup-rtc-timer;

				input@0 {
					reg = <0>;
					atmel,wakeup-type = "low";
				};
			};

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

			pinctrl@fc038000 {

				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_PC9__GPIO>;
					bias-disable;
				};
				*/

				pinctrl_sdmmc1_default: sdmmc1_default {
					cmd_data {
						pinmux = <PIN_PA28__SDMMC1_CMD>,
							 <PIN_PA18__SDMMC1_DAT0>,
							 <PIN_PA19__SDMMC1_DAT1>,
							 <PIN_PA20__SDMMC1_DAT2>,
							 <PIN_PA21__SDMMC1_DAT3>;
						bias-pull-up;
					};

					conf-ck_cd {
						pinmux = <PIN_PA22__SDMMC1_CK>,
							 <PIN_PA30__SDMMC1_CD>;
						bias-disable;
					};
				};


				pinctrl_uart1_default: uart1_default {
					pinmux = <PIN_PD2__URXD1>,
						 <PIN_PD3__UTXD1>;
					bias-disable;
				};

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

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

				pinctrl_flx3_default: flx3_spi_default {
					pinmux = <PIN_PA15__FLEXCOM3_IO0>,
						 <PIN_PA13__FLEXCOM3_IO1>,
						 <PIN_PA14__FLEXCOM3_IO2>,
						 <PIN_PA16__FLEXCOM3_IO3>;
					bias-disable;
				};

				pinctrl_flx4_default: flx4_i2c_default {
					pinmux = <PIN_PC28__FLEXCOM4_IO0>,
						 <PIN_PC29__FLEXCOM4_IO1>;
					bias-disable;
				};			
			};
		};
	};
};
