// SPDX-License-Identifier: GPL-2.0 OR MIT
/*
 * Copyright (C) 2026 Junhui Liu <junhui.liu@pigmoral.tech>
 */

#include "k1-bananapi-cm6.dtsi"

#include <dt-bindings/leds/common.h>

/ {
	model = "Banana Pi BPI-CM6 IO Board";
	compatible = "bananapi,bpi-cm6-io", "bananapi,bpi-cm6", "spacemit,k1";

	aliases {
		ethernet0 = &eth0;
		ethernet1 = &eth1;
		serial0 = &uart0;
	};

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

	leds {
		compatible = "gpio-leds";

		led0 {
			color = <LED_COLOR_ID_RED>;
			gpios = <&gpio K1_GPIO(96) GPIO_ACTIVE_LOW>;
		};

		led1 {
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio K1_GPIO(97) GPIO_ACTIVE_LOW>;
		};
	};

	pcie_vcc_3v3: regulator-pcie-vcc-3v3 {
		compatible = "regulator-fixed";
		regulator-name = "NGFF_KEYM_VDD";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-boot-on;
		regulator-always-on;
	};

	usb_vbus_5v: regulator-usb-vbus-5v {
		compatible = "regulator-fixed";
		regulator-name = "VBUS_A_B";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&gpio K1_GPIO(124) GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	sd_vcc_3v3: regulator-sd-vcc-3v3 {
		compatible = "regulator-fixed";
		regulator-name = "3.3VS_CARD";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		gpio = <&gpio K1_GPIO(127) GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};
};

&combo_phy {
	status = "okay";
};

&eth0 {
	status = "okay";
};

&eth1 {
	nvmem-cells = <&mac_address 1>;
	nvmem-cell-names = "mac-address";
	phy-handle = <&rgmii1>;
	phy-mode = "rgmii-id";
	pinctrl-names = "default";
	pinctrl-0 = <&gmac1_cfg>;
	rx-internal-delay-ps = <0>;
	tx-internal-delay-ps = <250>;
	status = "okay";

	mdio-bus {
		#address-cells = <0x1>;
		#size-cells = <0x0>;

		reset-gpios = <&gpio K1_GPIO(46) GPIO_ACTIVE_LOW>;
		reset-delay-us = <10000>;
		reset-post-delay-us = <100000>;

		rgmii1: phy@1 {
			reg = <0x1>;
		};
	};
};

&i2c2 {
	eeprom@54 {
		compatible = "atmel,24c08";
		reg = <0x54>;
		vcc-supply = <&buck3_1v8>;
		pagesize = <16>;
		size = <1024>;
	};
};

&pcie1_phy {
	pinctrl-names = "default";
	pinctrl-0 = <&pcie1_3_cfg>;
	status = "okay";
};

&pcie1_port {
	phys = <&pcie1_phy>;
	vpcie3v3-supply = <&pcie_vcc_3v3>;
};

&pcie1 {
	status = "okay";
};

&pcie2_phy {
	pinctrl-names = "default";
	pinctrl-0 = <&pcie2_4_cfg>;
	status = "okay";
};

&pcie2_port {
	phys = <&pcie2_phy>;
	vpcie3v3-supply = <&pcie_vcc_3v3>;
};

&pcie2 {
	status = "okay";
};

&qspi {
	pinctrl-names = "default";
	pinctrl-0 = <&qspi_cfg>;
	status = "okay";
};

&sdhci0 {
	pinctrl-names = "default", "uhs";
	pinctrl-0 = <&mmc1_cfg>;
	pinctrl-1 = <&mmc1_uhs_cfg>;
	bus-width = <4>;
	cd-gpios = <&gpio K1_GPIO(80) (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
	no-mmc;
	no-sdio;
	disable-wp;
	cap-sd-highspeed;
	vmmc-supply = <&sd_vcc_3v3>;
	vqmmc-supply = <&aldo1>;
	sd-uhs-sdr25;
	sd-uhs-sdr50;
	sd-uhs-sdr104;
	status = "okay";
};

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

&usbphy2 {
	status = "okay";
};

&usb_dwc3 {
	dr_mode = "host";
	vbus-supply = <&usb_vbus_5v>;
	status = "okay";
};