// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/*
 * Copyright (C) 2023 Jisheng Zhang <jszhang@kernel.org>
 * Copyright (C) 2023 Drew Fustini <dfustini@baylibre.com>
 */

/dts-v1/;

#include "th1520.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>

/ {
	model = "BeagleV Ahead";
	compatible = "beagle,beaglev-ahead", "thead,th1520";

	aliases {
		ethernet0 = &gmac0;
		gpio0 = &gpio0;
		gpio1 = &gpio1;
		gpio2 = &gpio2;
		gpio3 = &gpio3;
		gpio4 = &gpio4;
		gpio5 = &aogpio;
		serial0 = &uart0;
		serial1 = &uart1;
		serial2 = &uart2;
		serial3 = &uart3;
		serial4 = &uart4;
		serial5 = &uart5;
		spi0 = &spi0;
	};

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

	memory@0 {
		device_type = "memory";
		reg = <0x0  0x00000000  0x1 0x00000000>;
	};

	leds {
		pinctrl-names = "default";
		pinctrl-0 = <&led_pins>;
		compatible = "gpio-leds";

		led-1 {
			gpios = <&gpio4 8 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			label = "led1";
		};

		led-2 {
			gpios = <&gpio4 9 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			label = "led2";
		};

		led-3 {
			gpios = <&gpio4 10 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			label = "led3";
		};

		led-4 {
			gpios = <&gpio4 11 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			label = "led4";
		};

		led-5 {
			gpios = <&gpio4 12 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			label = "led5";
		};
	};
};

&osc {
	clock-frequency = <24000000>;
};

&osc_32k {
	clock-frequency = <32768>;
};

&dmac0 {
	status = "okay";
};

&emmc {
	bus-width = <8>;
	max-frequency = <198000000>;
	mmc-hs400-1_8v;
	non-removable;
	no-sdio;
	no-sd;
	status = "okay";
};

&gmac0 {
	pinctrl-names = "default";
	pinctrl-0 = <&gmac0_pins>;
	phy-handle = <&phy0>;
	phy-mode = "rgmii-id";
	status = "okay";
};

&mdio0 {
	phy0: ethernet-phy@1 {
		reg = <1>;
		interrupt-parent = <&gpio3>;
		interrupts = <22 IRQ_TYPE_LEVEL_LOW>;
		reset-gpios = <&gpio3 21 GPIO_ACTIVE_LOW>;
		reset-delay-us = <10000>;
		reset-post-delay-us = <50000>;
	};
};

&padctrl_aosys {
	led_pins: led-0 {
		led-pins {
			pins = "AUDIO_PA8",  /* GPIO4_8 */
			       "AUDIO_PA9",  /* GPIO4_9 */
			       "AUDIO_PA10", /* GPIO4_10 */
			       "AUDIO_PA11", /* GPIO4_11 */
			       "AUDIO_PA12"; /* GPIO4_12 */
			bias-disable;
			drive-strength = <3>;
			input-disable;
			input-schmitt-disable;
			slew-rate = <0>;
		};
	};
};

&padctrl0_apsys {
	gmac0_pins: gmac0-0 {
		tx-pins {
			pins = "GMAC0_TX_CLK",
			       "GMAC0_TXEN",
			       "GMAC0_TXD0",
			       "GMAC0_TXD1",
			       "GMAC0_TXD2",
			       "GMAC0_TXD3";
			function = "gmac0";
			bias-disable;
			drive-strength = <25>;
			input-disable;
			input-schmitt-disable;
			slew-rate = <0>;
		};

		rx-pins {
			pins = "GMAC0_RX_CLK",
			       "GMAC0_RXDV",
			       "GMAC0_RXD0",
			       "GMAC0_RXD1",
			       "GMAC0_RXD2",
			       "GMAC0_RXD3";
			function = "gmac0";
			bias-disable;
			drive-strength = <1>;
			input-enable;
			input-schmitt-disable;
			slew-rate = <0>;
		};

		mdc-pins {
			pins = "GMAC0_MDC";
			function = "gmac0";
			bias-disable;
			drive-strength = <13>;
			input-disable;
			input-schmitt-disable;
			slew-rate = <0>;
		};

		mdio-pins {
			pins = "GMAC0_MDIO";
			function = "gmac0";
			bias-disable;
			drive-strength = <13>;
			input-enable;
			input-schmitt-enable;
			slew-rate = <0>;
		};

		phy-reset-pins {
			pins = "GMAC0_COL"; /* GPIO3_21 */
			bias-disable;
			drive-strength = <3>;
			input-disable;
			input-schmitt-disable;
			slew-rate = <0>;
		};

		phy-interrupt-pins {
			pins = "GMAC0_CRS"; /* GPIO3_22 */
			function = "gpio";
			bias-pull-up;
			drive-strength = <1>;
			input-enable;
			input-schmitt-enable;
			slew-rate = <0>;
		};
	};

	uart0_pins: uart0-0 {
		tx-pins {
			pins = "UART0_TXD";
			function = "uart";
			bias-disable;
			drive-strength = <3>;
			input-disable;
			input-schmitt-disable;
			slew-rate = <0>;
		};

		rx-pins {
			pins = "UART0_RXD";
			function = "uart";
			bias-pull-up;
			drive-strength = <1>;
			input-enable;
			input-schmitt-enable;
			slew-rate = <0>;
		};
	};
};

&sdio0 {
	bus-width = <4>;
	max-frequency = <198000000>;
	status = "okay";
};

&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_pins>;
	status = "okay";
};