From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Tue, 30 May 2023 10:18:55 +0800
Subject: add bigtreetech-cb1 dts

---
 arch/arm64/boot/dts/allwinner/Makefile                             |   2 +
 arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-emmc.dts |  44 ++
 arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-sd.dts   |  35 +
 arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1.dtsi     | 327 ++++++++++
 4 files changed, 408 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/Makefile b/arch/arm64/boot/dts/allwinner/Makefile
index 4d4d2e5c01f2..74a6e5e0d7b3 100644
--- a/arch/arm64/boot/dts/allwinner/Makefile
+++ b/arch/arm64/boot/dts/allwinner/Makefile
@@ -50,6 +50,8 @@ dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h6-tanix-tx6.dtb
 dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h6-tanix-tx6-mini.dtb
 dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h616-orangepi-zero2.dtb
 dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h616-x96-mate.dtb
+dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h616-bigtreetech-cb1-sd.dtb
+dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h616-bigtreetech-cb1-emmc.dtb
 dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h618-orangepi-zero3.dtb
 
 subdir-y	:= $(dts-dirs) overlay
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-emmc.dts b/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-emmc.dts
new file mode 100644
index 000000000000..f878c23f1d90
--- /dev/null
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-emmc.dts
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+/*
+ * Copyright (C) 2023 Alan.Ma <tech@biqu3d.com>.
+ */
+
+/dts-v1/;
+
+#include "sun50i-h616-bigtreetech-cb1.dtsi"
+
+&mmc2 {
+	vmmc-supply = <&reg_dldo1>;
+
+	no-1-8-v;
+	bus-width = <8>;
+	non-removable;
+	status = "okay";
+};
+
+&ws2812 {
+	gpios = <&pio 8 15 GPIO_ACTIVE_LOW>; /* PI15 */
+};
+
+&i2c_gpio {
+	gpios = <&pio 8 6 GPIO_ACTIVE_HIGH>, /* SDA PI6 */
+			<&pio 8 4 GPIO_ACTIVE_HIGH>; /* SCL PI4 */
+};
+
+&can0_pin_irq {
+	pins = "PI3";
+};
+
+&can {
+	interrupts = <8 3 0x08>; /* PI3 IRQ_TYPE_LEVEL_LOW */
+};
+
+&tft_35 {
+	dc-gpios  = <&pio 8 15 GPIO_ACTIVE_HIGH>; /* PI15 */
+};
+
+&spi1 {
+	cs-gpios = <&pio 8 5 GPIO_ACTIVE_HIGH>, /* PI5 */
+			   <&pio 8 14 GPIO_ACTIVE_HIGH>, /* PI14 */
+			   <&pio 8 7 GPIO_ACTIVE_HIGH>; /* PI7 */
+};
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-sd.dts b/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-sd.dts
new file mode 100644
index 000000000000..e18dd854d74b
--- /dev/null
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1-sd.dts
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+/*
+ * Copyright (C) 2023 Alan.Ma <tech@biqu3d.com>.
+ */
+
+/dts-v1/;
+
+#include "sun50i-h616-bigtreetech-cb1.dtsi"
+
+&ws2812 {
+	gpios = <&pio 2 14 GPIO_ACTIVE_LOW>; /* PC14 */
+};
+
+&i2c_gpio {
+	gpios = <&pio 2 12 GPIO_ACTIVE_HIGH>, /* SDA PC12 */
+			<&pio 2 10 GPIO_ACTIVE_HIGH>; /* SCL PC10 */
+};
+
+&can0_pin_irq {
+	pins = "PC9";
+};
+
+&can {
+	interrupts = <2 9 0x08>; /* PC9 IRQ_TYPE_LEVEL_LOW */
+};
+
+&tft_35 {
+	dc-gpios  = <&pio 2 14 GPIO_ACTIVE_HIGH>; /* PC14 */
+};
+
+&spi1 {
+	cs-gpios = <&pio 2 11 GPIO_ACTIVE_HIGH>, /* PC11 */
+			   <&pio 2 7 GPIO_ACTIVE_HIGH>, /* PC7 */
+			   <&pio 2 13 GPIO_ACTIVE_HIGH>; /* PC13 */
+};
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1.dtsi
new file mode 100644
index 000000000000..8a18476307ff
--- /dev/null
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h616-bigtreetech-cb1.dtsi
@@ -0,0 +1,327 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+/*
+ * Copyright (C) 2023 Alan.Ma <tech@biqu3d.com>.
+ */
+
+/dts-v1/;
+
+#include "sun50i-h616.dtsi"
+#include "sun50i-h616-cpu-opp.dtsi"
+
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/leds/common.h>
+
+/ {
+	model = "BigTreeTech CB1";
+	compatible = "bigtreetech,cb1", "allwinner,sun50i-h616";
+
+	aliases {
+		ethernet0 = &emac1;
+		serial0 = &uart0;
+	};
+
+	chosen {
+		stdout-path = "serial0:115200n8";
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		act_led: led-0 {
+			gpios = <&pio 7 5 GPIO_ACTIVE_LOW>; /* PH5 */
+			linux,default-trigger = "heartbeat";
+		};
+
+		gpio_1 {
+			function = "wifi_power";
+			gpios = <&pio 5 6 GPIO_ACTIVE_HIGH>; /* PF6 */
+			default-state = "on";
+		};
+
+		gpio_2 {
+			function = "wifi_wake";
+			gpios = <&pio 6 15 GPIO_ACTIVE_HIGH>; /* PG15 */
+			default-state = "on";
+		};
+	};
+
+	reg_vcc5v: regulator-vcc5v {
+		/* board wide 5V supply directly from the USB-C socket */
+		compatible = "regulator-fixed";
+		regulator-name = "vcc-5v";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-always-on;
+	};
+
+	reg_usb1_vbus: regulator-usb1-vbus {
+		compatible = "regulator-fixed";
+		regulator-name = "usb1-vbus";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		vin-supply = <&reg_vcc5v>;
+		enable-active-high;
+	};
+
+	reg_vcc33_wifi: vcc33-wifi {
+		/* Always on 3.3V regulator for WiFi and BT */
+		compatible = "regulator-fixed";
+		regulator-name = "vcc33-wifi";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+		regulator-always-on;
+		vin-supply = <&reg_vcc5v>;
+	};
+
+	reg_vcc_wifi_io: vcc-wifi-io {
+		/* Always on 1.8V/300mA regulator for WiFi and BT IO */
+		compatible = "regulator-fixed";
+		regulator-name = "vcc-wifi-io";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <1800000>;
+		regulator-always-on;
+		vin-supply = <&reg_vcc33_wifi>;
+	};
+
+	wifi_pwrseq: wifi-pwrseq {
+		compatible = "mmc-pwrseq-simple";
+		clocks = <&rtc 1>;
+		clock-names = "osc32k-out";
+		reset-gpios = <&pio 6 18 GPIO_ACTIVE_LOW>;  /* PG18 */
+		post-power-on-delay-ms = <200>;
+	};
+
+	ws2812: ws2812 {
+		compatible = "rgb-ws2812";
+		pinctrl-names = "default";
+		rgb_cnt = <2>;
+		rgb_value = <0x010000 0x010000>;
+		status = "disabled";
+	};
+
+	i2c_gpio: i2c-gpio {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "i2c-gpio";
+		status = "disabled";
+
+		i2c-gpio,delay-us = <3>; /* 100 kHz */
+
+		tft_tp: ns2009@48 {
+			compatible = "ti,tsc2007";
+			reg = <0x48>;
+			status = "disabled";
+			ti,x-plate-ohms = <660>;
+			ti,rt-thr = <3000>;
+			ti,fuzzx = <32>;
+			ti,fuzzy = <16>;
+			i2c,ignore-nak = <1>;
+		};
+
+		light: bh1750@5c {
+			compatible = "rohm,bh1750";
+			reg = <0x5c>;
+			status = "disabled";
+		};
+	};
+
+	mcp2515_clock: mcp2515_clock {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency  = <12000000>;
+	};
+};
+
+&mmc0 {
+	vmmc-supply = <&reg_dldo1>;
+	broken-cd;
+	bus-width = <4>;
+	max-frequency = <50000000>;
+	status = "okay";
+};
+
+&mmc1 {
+	vmmc-supply = <&reg_vcc33_wifi>;
+	vqmmc-supply = <&reg_vcc_wifi_io>;
+	mmc-pwrseq = <&wifi_pwrseq>;
+	bus-width = <4>;
+	max-frequency = <25000000>;
+	non-removable;
+	mmc-ddr-1_8v;
+	status = "okay";
+};
+
+&pio {
+	can0_pin_irq: can0_pin_irq {
+		function = "irq";
+		bias-pull-up;
+	};
+};
+
+&spi1 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	status = "disabled";
+	pinctrl-names = "default";
+	pinctrl-0 = <&spi1_pins>;
+
+	can: mcp2515@0 {
+		status = "disabled";
+		compatible = "microchip,mcp2515";
+		reg = <0x0>;
+		clocks = <&mcp2515_clock>;
+		spi-max-frequency = <12500000>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&can0_pin_irq>;
+		interrupt-parent = <&pio>;
+		vdd-supply = <&reg_vcc33_wifi>;
+		xceiver-supply = <&reg_vcc33_wifi>;
+	};
+
+	tft_35: st7789v@1 {
+		status = "disabled";
+		compatible = "sitronix,st7796s";
+		reg = <1>;
+		spi-max-frequency =<12500000>;
+		fps =<60>;
+		buswidth = <8>;
+		rotate =<0>;
+		width = <480>;
+		height = <320>;
+		bpp = <24>;
+		bgr;
+		regwidth = <8>;
+		debug = <0x00>;	 //0x20 show fps
+		txbuflen = <307200>;
+		spi-cpol;
+		spi-cpha;
+	};
+};
+
+&r_i2c {
+	status = "okay";
+
+	axp313a: pmic@36 {
+		compatible = "x-powers,axp313a";
+		reg = <0x36>;
+		wakeup-source;
+
+		regulators{
+			reg_dcdc1: dcdc1 {
+				regulator-name = "axp313a-dcdc1";
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+				regulator-step-delay-us = <25>;
+				regulator-final-delay-us = <50>;
+				regulator-always-on;
+			};
+
+			reg_dcdc2: dcdc2 {
+				regulator-name = "axp313a-dcdc2";
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <1540000>;
+				regulator-step-delay-us = <25>;
+				regulator-final-delay-us = <50>;
+				regulator-ramp-delay = <200>;
+				regulator-always-on;
+			};
+
+			reg_dcdc3: dcdc3 {
+				regulator-name = "axp313a-dcdc3";
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <1840000>;
+				regulator-step-delay-us = <25>;
+				regulator-final-delay-us = <50>;
+				regulator-always-on;
+			};
+
+			reg_aldo1: aldo1 {
+				regulator-name = "axp313a-aldo1";
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-step-delay-us = <25>;
+				regulator-final-delay-us = <50>;
+				regulator-always-on;
+			};
+
+			reg_dldo1: dldo1 {
+				regulator-name = "axp313a-dldo1";
+				regulator-min-microvolt = <3300000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-step-delay-us = <25>;
+				regulator-final-delay-us = <50>;
+				regulator-always-on;
+			};
+		};
+	};
+};
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+	status = "okay";
+};
+
+&gpu {
+	mali-supply = <&reg_dcdc3>;
+	status = "okay";
+};
+
+&uart0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart0_ph_pins>;
+	status = "okay";
+};
+
+&usbphy {
+	usb1_vbus-supply = <&reg_usb1_vbus>;
+	status = "okay";
+};
+
+&ehci0 {
+	status = "okay";
+};
+
+&ohci0 {
+	status = "okay";
+};
+
+&ehci1 {
+	status = "okay";
+};
+
+&ohci1 {
+	status = "okay";
+};
+
+&ehci2 {
+	status = "okay";
+};
+
+&ohci2 {
+	status = "okay";
+};
+
+&ehci3 {
+	status = "okay";
+};
+
+&ohci3 {
+	status = "okay";
+};
+
+&usbotg {
+	/*
+	 * PHY0 pins are connected to a USB-C socket, but a role switch
+	 * is not implemented: both CC pins are pulled to GND.
+	 * The VBUS pins power the device, so a fixed peripheral mode
+	 * is the best choice.
+	 * The board can be powered via GPIOs, in this case port0 *can*
+	 * act as a host (with a cable/adapter ignoring CC), as VBUS is
+	 * then provided by the GPIOs. Any user of this setup would
+	 * need to adjust the DT accordingly: dr_mode set to "host",
+	 * enabling OHCI0 and EHCI0.
+	 */
+	dr_mode = "peripheral";
+	status = "okay";
+};
-- 
Armbian

