// SPDX-License-Identifier: GPL-2.0
/*
 * https://beagleboard.org/play
 *
 * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
 * Copyright (C) 2022-2023 Robert Nelson, BeagleBoard.org Foundation
 */

#include "k3-binman.dtsi"

/ {
	/* Keep the LEDs on by default to indicate life */
	leds {
		led-0 {
			default-state = "on";
		};

		led-1 {
			default-state = "on";
		};

		led-2 {
			default-state = "on";
		};

		led-3 {
			default-state = "on";
		};

		led-4 {
			default-state = "on";
		};
	};
};

&sd_pins_default {
	/* Force to use SDCD card detect pin */
	pinctrl-single,pins = <
		AM62X_IOPAD(0x023c, PIN_INPUT, 0) /* (A21) MMC1_CMD */
		AM62X_IOPAD(0x0234, PIN_INPUT, 0) /* (B22) MMC1_CLK */
		AM62X_IOPAD(0x0230, PIN_INPUT, 0) /* (A22) MMC1_DAT0 */
		AM62X_IOPAD(0x022c, PIN_INPUT, 0) /* (B21) MMC1_DAT1 */
		AM62X_IOPAD(0x0228, PIN_INPUT, 0) /* (C21) MMC1_DAT2 */
		AM62X_IOPAD(0x0224, PIN_INPUT, 0) /* (D22) MMC1_DAT3 */
		AM62X_IOPAD(0x0240, PIN_INPUT, 0) /* (D17) MMC1_SDCD.MMC1_SDCD */
	>;
};

&usbss0 {
	bootph-all;
};

&usb0 {
	dr_mode = "peripheral";
	bootph-all;
};

#ifdef CONFIG_TARGET_AM625_A53_BEAGLEPLAY

#define SPL_NODTB "spl/u-boot-spl-nodtb.bin"
#define SPL_AM625_BEAGLEPLAY_DTB "spl/dts/ti/k3-am625-beagleplay.dtb"
#define UBOOT_NODTB "u-boot-nodtb.bin"
#define AM625_BEAGLEPLAY_DTB "dts/upstream/src/arm64/ti/k3-am625-beagleplay.dtb"

&binman {
	tifsstub-gp {
		filename = "tifsstub.bin_gp";
		ti-secure-rom {
			content = <&tifsstub_gp>;
			core = "secure";
			load = <0x60000>;
			sw-rev = <CONFIG_K3_X509_SWRV>;
			keyfile = "ti-degenerate-key.pem";
			tifsstub;
		};
		tifsstub_gp: tifsstub-gp.bin {
			filename = "ti-sysfw/ti-fs-stub-firmware-am62x-gp.bin";
			type = "blob-ext";
			optional;
		};
	};

	ti-spl_unsigned {
		filename = "tispl.bin_unsigned";
		symlink = "tispl.bin";
		pad-byte = <0xff>;

		fit {
			description = "Configuration to load ATF and SPL";
			#address-cells = <1>;

			images {

				atf {
					description = "ARM Trusted Firmware";
					type = "firmware";
					arch = "arm64";
					compression = "none";
					os = "arm-trusted-firmware";
					load = <CONFIG_K3_ATF_LOAD_ADDR>;
					entry = <CONFIG_K3_ATF_LOAD_ADDR>;
					atf-bl31 {
						filename = "bl31.bin";
					};
				};

				tee {
					description = "OP-TEE";
					type = "tee";
					arch = "arm64";
					compression = "none";
					os = "tee";
					load = <CONFIG_K3_OPTEE_LOAD_ADDR>;
					entry = <CONFIG_K3_OPTEE_LOAD_ADDR>;
					tee-os {
						filename = "tee-raw.bin";
					};
				};

				tifsstub-gp {
					description = "tifsstub";
					type = "firmware";
					arch = "arm32";
					compression = "none";
					os = "tifsstub-gp";
					load = <0x9dc00000>;
					entry = <0x9dc00000>;
					blob-ext {
						filename = "tifsstub.bin_gp";
					};
				};

				dm {
					description = "DM binary";
					type = "firmware";
					arch = "arm32";
					compression = "none";
					os = "DM";
					load = <0x89000000>;
					entry = <0x89000000>;
					ti-dm {
						filename = "ti-dm/am62xx/ipc_echo_testb_mcu1_0_release_strip.xer5f";
					};
				};

				spl {
					description = "SPL (64-bit)";
					type = "standalone";
					os = "U-Boot";
					arch = "arm64";
					compression = "none";
					load = <CONFIG_SPL_TEXT_BASE>;
					entry = <CONFIG_SPL_TEXT_BASE>;
					blob {
						filename = "spl/u-boot-spl-nodtb.bin";
					};
				};

				fdt-0 {
					description = "k3-am625-beagleplay";
					type = "flat_dt";
					arch = "arm";
					compression = "none";
					spl_am625_bp_dtb_unsigned: blob {
						filename = SPL_AM625_BEAGLEPLAY_DTB;
					};
				};
			};

			configurations {
				default = "conf-0";

				conf-0 {
					description = "k3-am625-beagleplay";
					firmware = "atf";
					loadables = "tee", "dm", "spl",
					"tifsstub-gp";
					fdt = "fdt-0";
				};
			};
		};
	};

	u-boot_unsigned {
		filename = "u-boot.img_unsigned";
		pad-byte = <0xff>;

		fit {
			description = "FIT image with multiple configurations";

			images {
				uboot {
					description = "U-Boot for AM625 board";
					type = "firmware";
					os = "u-boot";
					arch = "arm";
					compression = "none";
					load = <CONFIG_TEXT_BASE>;
					blob {
						filename = UBOOT_NODTB;
					};
					hash {
						algo = "crc32";
					};
				};

				fdt-0 {
					description = "k3-am625-beagleplay";
					type = "flat_dt";
					arch = "arm";
					compression = "none";
					am625_bp_dtb_unsigned: blob {
						filename = AM625_BEAGLEPLAY_DTB;
					};
					hash {
						algo = "crc32";
					};
				};
			};

			configurations {
				default = "conf-0";

				conf-0 {
					description = "k3-am625-beagleplay";
					firmware = "uboot";
					loadables = "uboot";
					fdt = "fdt-0";
				};
			};
		};
	};
};

#include "k3-binman-capsule.dtsi"

// Capsule update GUIDs in string form.  See beagleplay.h
#define BEAGLEPLAY_SPL_IMAGE_GUID_STR "b2e7cc49-1a5a-4036-ae01-3387c3bef657"
#define BEAGLEPLAY_UBOOT_IMAGE_GUID_STR "92c92b11-a7ee-486f-aaa2-713d84425b0e"

&capsule_tispl {
	efi-capsule {
		image-guid = BEAGLEPLAY_SPL_IMAGE_GUID_STR;

		blob {
			filename = "tispl.bin_unsigned";
		};
	};
};

&capsule_uboot {
	efi-capsule {
		image-guid = BEAGLEPLAY_UBOOT_IMAGE_GUID_STR;

		blob {
			filename = "u-boot.img_unsigned";
		};
	};
};

#endif

&main_bcdma {
	reg = <0x00 0x485c0100 0x00 0x100>,
	      <0x00 0x4c000000 0x00 0x20000>,
	      <0x00 0x4a820000 0x00 0x20000>,
	      <0x00 0x4aa40000 0x00 0x20000>,
	      <0x00 0x4bc00000 0x00 0x100000>,
	      <0x00 0x48600000 0x00 0x8000>,
	      <0x00 0x484a4000 0x00 0x2000>,
	      <0x00 0x484c2000 0x00 0x2000>;
	reg-names = "gcfg", "bchanrt", "rchanrt", "tchanrt", "ringrt",
		    "cfg", "tchan", "rchan";
};

&main_pktdma {
	reg = <0x00 0x485c0000 0x00 0x100>,
	      <0x00 0x4a800000 0x00 0x20000>,
	      <0x00 0x4aa00000 0x00 0x40000>,
	      <0x00 0x4b800000 0x00 0x400000>,
	      <0x00 0x485e0000 0x00 0x20000>,
	      <0x00 0x484a0000 0x00 0x4000>,
	      <0x00 0x484c0000 0x00 0x2000>,
	      <0x00 0x48430000 0x00 0x4000>;
	reg-names = "gcfg", "rchanrt", "tchanrt", "ringrt", "cfg",
		    "tchan", "rchan", "rflow";
	bootph-all;
};

&mdio0_pins_default {
	bootph-all;
};

&cpsw3g_mdio {
	bootph-all;
};

&cpsw3g_phy0 {
	bootph-all;
};

&rgmii1_pins_default {
	bootph-all;
};

&cpsw3g {
	bootph-all;

	ethernet-ports {
		bootph-all;
	};
};

&phy_gmii_sel {
	bootph-all;
};

&cpsw_port1 {
	bootph-all;
};

&cpsw_port2 {
	status = "disabled";
};
