/*
 * Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <atmel/samd21.dtsi>
#include <atmel/samx2xx18.dtsi>
#include "arduino_mkrzero-pinctrl.dtsi"
#include "arduino_mkr_connector.dtsi"

/ {
	model = "Arduino MKR Zero";
	compatible = "arduino,mkrzero";

	chosen {
		zephyr,console = &sercom5;
		zephyr,shell-uart = &sercom5;
		zephyr,sram = &sram0;
		zephyr,flash = &flash0;
		zephyr,code-partition = &code_partition;
	};

	leds {
		compatible = "gpio-leds";
		led0: led_0 {
			gpios = <&portb 8 0>;
			label = "LED";
		};
	};

	aliases {
		led0 = &led0;
		sdhc0 = &sdhc0;
	};
};

&cpu0 {
	clock-frequency = <48000000>;
};

&sercom0 {
	status = "okay";
	compatible = "atmel,sam0-i2c";
	clock-frequency = <I2C_BITRATE_FAST>;
	#address-cells = <1>;
	#size-cells = <0>;

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

	atecc508a@c0 {
		compatible = "atmel,atecc508";
		reg = <0xc0>;
	};

};

&sercom1 {
	status = "okay";
	compatible = "atmel,sam0-spi";
	dipo = <3>;
	dopo = <0>;
	#address-cells = <1>;
	#size-cells = <0>;

	pinctrl-0 = <&sercom1_spi_default>;
	pinctrl-names = "default";
};

&sercom2 {
	status = "okay";
	compatible = "atmel,sam0-spi";
	dipo = <3>;
	dopo = <0>;
	#address-cells = <1>;
	#size-cells = <0>;

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

	cs-gpios = <&porta 14 GPIO_ACTIVE_LOW>;

	sdhc0: sdhc@0 {
		compatible = "zephyr,sdhc-spi-slot";
		reg = <0>;
		status = "okay";
		spi-max-frequency = <1000000>;
		mmc {
			compatible = "zephyr,sdmmc-disk";
			status = "okay";
		};
	};
};

&sercom5 {
	status = "okay";
	compatible = "atmel,sam0-uart";
	current-speed = <115200>;
	rxpo = <3>;
	txpo = <1>;

	pinctrl-0 = <&sercom5_uart_default>;
	pinctrl-names = "default";
};

&dac0 {
	status = "okay";

	pinctrl-0 = <&dac_default>;
	pinctrl-names = "default";
};

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

		boot_partition: partition@0 {
			label = "bootloader";
			reg = <0x00000000 0x2000>;
			read-only;
		};

		code_partition: partition@2000 {
			label = "code";
			reg = <0x2000 0x3A000>;
			read-only;
		};

		/*
		 * The final 16 KiB is reserved for the application.
		 * Storage partition will be used by FCB/LittleFS/NVS
		 * if enabled.
		 */
		storage_partition: partition@3c000 {
			label = "storage";
			reg = <0x0003c000 0x00004000>;
		};
	};
};

zephyr_udc0: &usb0 {
	status = "okay";

	pinctrl-0 = <&usb_dc_default>;
	pinctrl-names = "default";
};