// SPDX-License-Identifier: (GPL-2.0+ or MIT)
// Copyright (C) 2022 Samuel Holland <samuel@sholland.org>

#include "sun20i-d1-lichee-rv.dts"

/ {
	aliases {
		ethernet0 = &emac;
		ethernet1 = &xr829;
	};

	dmic_codec: dmic-codec {
		compatible = "dmic-codec";
		num-channels = <2>;
		#sound-dai-cells = <0>;
	};

	dmic-sound {
		compatible = "simple-audio-card";
		simple-audio-card,name = "DMIC";
		#address-cells = <1>;
		#size-cells = <0>;

		simple-audio-card,dai-link@0 {
			reg = <0>;
			format = "pdm";
			frame-master = <&link0_cpu>;
			bitclock-master = <&link0_cpu>;

			link0_cpu: cpu {
				sound-dai = <&dmic>;
			};

			link0_codec: codec {
				sound-dai = <&dmic_codec>;
			};
		};
	};

	/* PC1 is repurposed as BT_WAKE_AP */
	/delete-node/ leds;

	wifi_pwrseq: wifi-pwrseq {
		compatible = "mmc-pwrseq-simple";
		clocks = <&ccu CLK_FANOUT1>;
		clock-names = "ext_clock";
		reset-gpios = <&pio 6 12 GPIO_ACTIVE_LOW>; /* PG12 */
		assigned-clocks = <&ccu CLK_FANOUT1>;
		assigned-clock-rates = <32768>;
		pinctrl-0 = <&clk_pg11_pin>;
		pinctrl-names = "default";
	};
};

&dmic {
	pinctrl-0 = <&dmic_pb11_d0_pin>, <&dmic_pe17_clk_pin>;
	pinctrl-names = "default";
	status = "okay";
};

&ehci1 {
	status = "okay";
};

&emac {
	pinctrl-0 = <&rmii_pe_pins>;
	pinctrl-names = "default";
	phy-handle = <&ext_rmii_phy>;
	phy-mode = "rmii";
	phy-supply = <&reg_vcc_3v3>;
	status = "okay";
};

&mdio {
	ext_rmii_phy: ethernet-phy@1 {
		compatible = "ethernet-phy-ieee802.3-c22";
		reg = <1>;
		reset-gpios = <&pio 4 16 GPIO_ACTIVE_LOW>; /* PE16 */
	};
};

&mmc1 {
	bus-width = <4>;
	mmc-pwrseq = <&wifi_pwrseq>;
	non-removable;
	vmmc-supply = <&reg_vcc_3v3>;
	vqmmc-supply = <&reg_vcc_3v3>;
	pinctrl-0 = <&mmc1_pins>;
	pinctrl-names = "default";
	status = "okay";

	xr829: wifi@1 {
		reg = <1>;
	};
};

&ohci1 {
	status = "okay";
};

&uart1 {
	uart-has-rtscts;
	pinctrl-0 = <&uart1_pg6_pins>, <&uart1_pg8_rts_cts_pins>;
	pinctrl-names = "default";
	status = "okay";

	/* XR829 bluetooth is connected here */
};

&usb_otg {
	status = "disabled";
};

&usbphy {
	/* PD20 and PD21 are repurposed for the LCD panel */
	/delete-property/ usb0_id_det-gpios;
	/delete-property/ usb0_vbus_det-gpios;
	usb1_vbus-supply = <&reg_vcc>;
};