// SPDX-License-Identifier: GPL-2.0+ OR MIT
/*
 * MacBook Pro (14/16-inch, 2021)
 *
 * This file contains the parts common to J314 and J316 devices with both t6000 and t6001.
 *
 * target-type: J314s / J314c / J316s / J316c
 *
 * Copyright The Asahi Linux Contributors
 */

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

/ {
	chassis-type = "laptop";

	aliases {
		atcphy0 = &atcphy0;
		atcphy1 = &atcphy1;
		atcphy2 = &atcphy2;
		atcphy3 = &atcphy3;
		bluetooth0 = &bluetooth0;
		serial0 = &serial0;
		wifi0 = &wifi0;
	};

	chosen {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		stdout-path = "serial0";

		framebuffer0: framebuffer@0 {
			compatible = "apple,simple-framebuffer", "simple-framebuffer";
			reg = <0 0 0 0>; /* To be filled by loader */
			/* Format properties will be added by loader */
			status = "disabled";
		};
	};

	memory@10000000000 {
		device_type = "memory";
		reg = <0x100 0 0x2 0>; /* To be filled by loader */
	};

	led-controller {
		compatible = "pwm-leds";
		led-0 {
			pwms = <&fpwm0 0 40000>;
			label = "kbd_backlight";
			function = LED_FUNCTION_KBD_BACKLIGHT;
			color = <LED_COLOR_ID_WHITE>;
			max-brightness = <255>;
			default-state = "keep";
		};
	};
};

&serial0 {
	status = "okay";
};

/* USB Type C */
&i2c0 {
	hpm0: usb-pd@38 {
		compatible = "apple,cd321x";
		reg = <0x38>;
		interrupt-parent = <&pinctrl_ap>;
		interrupts = <174 IRQ_TYPE_LEVEL_LOW>;
		interrupt-names = "irq";

		typec0: connector {
			compatible = "usb-c-connector";
			label = "USB-C Left Rear";
			power-role = "dual";
			data-role = "dual";

			ports {
				#address-cells = <1>;
				#size-cells = <0>;
				port@0 {
					reg = <0>;
					typec0_connector_hs: endpoint {
						remote-endpoint = <&dwc3_0_hs>;
					};
				};
				port@1 {
					reg = <1>;
					typec0_connector_ss: endpoint {
						remote-endpoint = <&atcphy0_typec_lanes>;
					};
				};
			};
		};
	};

	hpm1: usb-pd@3f {
		compatible = "apple,cd321x";
		reg = <0x3f>;
		interrupt-parent = <&pinctrl_ap>;
		interrupts = <174 IRQ_TYPE_LEVEL_LOW>;
		interrupt-names = "irq";

		typec1: connector {
			compatible = "usb-c-connector";
			label = "USB-C Left Front";
			power-role = "dual";
			data-role = "dual";

			ports {
				#address-cells = <1>;
				#size-cells = <0>;
				port@0 {
					reg = <0>;
					typec1_connector_hs: endpoint {
						remote-endpoint = <&dwc3_1_hs>;
					};
				};
				port@1 {
					reg = <1>;
					typec1_connector_ss: endpoint {
						remote-endpoint = <&atcphy1_typec_lanes>;
					};
				};
			};
		};
	};

	hpm2: usb-pd@3b {
		compatible = "apple,cd321x";
		reg = <0x3b>;
		interrupt-parent = <&pinctrl_ap>;
		interrupts = <174 IRQ_TYPE_LEVEL_LOW>;
		interrupt-names = "irq";

		typec2: connector {
			compatible = "usb-c-connector";
			label = "USB-C Right";
			power-role = "dual";
			data-role = "dual";

			ports {
				#address-cells = <1>;
				#size-cells = <0>;
				port@0 {
					reg = <0>;
					typec2_connector_hs: endpoint {
						remote-endpoint = <&dwc3_2_hs>;
					};
				};
				port@1 {
					reg = <1>;
					typec2_connector_ss: endpoint {
						remote-endpoint = <&atcphy2_typec_lanes>;
					};
				};
			};
		};
	};

	/* MagSafe port */
	hpm5: usb-pd@3a {
		compatible = "apple,cd321x";
		reg = <0x3a>;
		interrupt-parent = <&pinctrl_ap>;
		interrupts = <174 IRQ_TYPE_LEVEL_LOW>;
		interrupt-names = "irq";
	};
};

&nco_clkref {
	clock-frequency = <1068000000>;
};

/* PCIe devices */
&port00 {
	/* WLAN */
	bus-range = <1 1>;
	wifi0: wifi@0,0 {
		compatible = "pci14e4,4433";
		reg = <0x10000 0x0 0x0 0x0 0x0>;
		/* To be filled by the loader */
		local-mac-address = [00 10 18 00 00 10];
		apple,antenna-sku = "XX";
	};

	bluetooth0: bluetooth@0,1 {
		compatible = "pci14e4,5f71";
		reg = <0x10100 0x0 0x0 0x0 0x0>;
		/* To be filled by the loader */
		local-bd-address = [00 00 00 00 00 00];
	};
};

&port01 {
	/* SD card reader */
	bus-range = <2 2>;
	sdhci0: mmc@0,0 {
		compatible = "pci17a0,9755";
		reg = <0x20000 0x0 0x0 0x0 0x0>;
		cd-inverted;
		wp-inverted;
	};
};

&fpwm0 {
	status = "okay";
};

/* USB controllers */
&dwc3_0 {
	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;
			dwc3_0_hs: endpoint {
				remote-endpoint = <&typec0_connector_hs>;
			};
		};

		port@1 {
			reg = <1>;
			dwc3_0_ss: endpoint {
				remote-endpoint = <&atcphy0_usb3>;
			};
		};
	};
};

&dwc3_1 {
	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;
			dwc3_1_hs: endpoint {
				remote-endpoint = <&typec1_connector_hs>;
			};
		};

		port@1 {
			reg = <1>;
			dwc3_1_ss: endpoint {
				remote-endpoint = <&atcphy1_usb3>;
			};
		};
	};
};

&dwc3_2 {
	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;
			dwc3_2_hs: endpoint {
				remote-endpoint = <&typec2_connector_hs>;
			};
		};

		port@1 {
			reg = <1>;
			dwc3_2_ss: endpoint {
				remote-endpoint = <&atcphy2_usb3>;
			};
		};
	};
};

/*
 * ps_atc3_usb_aon power-domain is always-on to keep dwc3 working over suspend.
 * atc3 is used exclusively for the DP-to-HDMI so do not keep this always on.
 */
&ps_atc3_usb_aon {
	/delete-property/ apple,always-on;
};

/* ATC3 is used for DisplayPort -> HDMI only */
&dwc3_3_dart_0 {
	status = "disabled";
};

&dwc3_3_dart_1 {
	status = "disabled";
};

&dwc3_3 {
	status = "disabled";
};

/* Delete unused dwc3_3 to prevent dt_disable_missing_devs() from disabling
 * atcphy3 via phandle references from a disablecd device.
 */
/delete-node/ &dwc3_3;

/* Type-C PHYs */
&atcphy0 {
	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;
			atcphy0_typec_lanes: endpoint {
				remote-endpoint = <&typec0_connector_ss>;
			};
		};

		port@1 {
			reg = <1>;
			atcphy0_usb3: endpoint {
				remote-endpoint = <&dwc3_0_ss>;
			};
		};
	};
};

&atcphy1 {
	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;
			atcphy1_typec_lanes: endpoint {
				remote-endpoint = <&typec1_connector_ss>;
			};
		};

		port@1 {
			reg = <1>;
			atcphy1_usb3: endpoint {
				remote-endpoint = <&dwc3_1_ss>;
			};
		};
	};
};

&atcphy2 {
	ports {
		#address-cells = <1>;
		#size-cells = <0>;

		port@0 {
			reg = <0>;
			atcphy2_typec_lanes: endpoint {
				remote-endpoint = <&typec2_connector_ss>;
			};
		};

		port@1 {
			reg = <1>;
			atcphy2_usb3: endpoint {
				remote-endpoint = <&dwc3_2_ss>;
			};
		};
	};
};

&atcphy3 {
	status = "disabled";
};

#include "spi1-nvram.dtsi"
