1// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
4 * Copyright (c) 2024 Uwe Kleine-König
5 */
6
7/dts-v1/;
8
9#include <dt-bindings/input/input.h>
10#include <dt-bindings/leds/common.h>
11#include <dt-bindings/gpio/gpio.h>
12#include "rk3568.dtsi"
13
14/ {
15	model = "Qnap TS-433-4G NAS System 4-Bay";
16	compatible = "qnap,ts433", "rockchip,rk3568";
17
18	aliases {
19		ethernet0 = &gmac0;
20		mmc0 = &sdhci;
21		rtc0 = &rtc_rv8263;
22	};
23
24	chosen {
25		stdout-path = "serial2:115200n8";
26	};
27
28	keys {
29		compatible = "gpio-keys";
30		pinctrl-0 = <&copy_button_pin>, <&reset_button_pin>;
31		pinctrl-names = "default";
32
33		key-copy {
34			label = "copy";
35			gpios = <&gpio0 RK_PB6 GPIO_ACTIVE_LOW>;
36			linux,code = <KEY_COPY>;
37		};
38
39		key-reset {
40			label = "reset";
41			gpios = <&gpio0 RK_PB5 GPIO_ACTIVE_LOW>;
42			linux,code = <KEY_RESTART>;
43		};
44	};
45
46	leds {
47		compatible = "gpio-leds";
48
49		led-0 {
50			color = <LED_COLOR_ID_GREEN>;
51			function = LED_FUNCTION_DISK;
52			gpios = <&gpio1 RK_PD5 GPIO_ACTIVE_LOW>;
53			label = "hdd1:green:disk";
54			linux,default-trigger = "disk-activity";
55			pinctrl-names = "default";
56			pinctrl-0 = <&hdd1_led_pin>;
57		};
58
59		led-1 {
60			color = <LED_COLOR_ID_GREEN>;
61			function = LED_FUNCTION_DISK;
62			gpios = <&gpio1 RK_PD6 GPIO_ACTIVE_LOW>;
63			label = "hdd2:green:disk";
64			linux,default-trigger = "disk-activity";
65			pinctrl-names = "default";
66			pinctrl-0 = <&hdd2_led_pin>;
67		};
68
69		led-2 {
70			color = <LED_COLOR_ID_GREEN>;
71			function = LED_FUNCTION_DISK;
72			gpios = <&gpio1 RK_PD7 GPIO_ACTIVE_LOW>;
73			label = "hdd3:green:disk";
74			linux,default-trigger = "disk-activity";
75			pinctrl-names = "default";
76			pinctrl-0 = <&hdd3_led_pin>;
77		};
78
79		led-3 {
80			color = <LED_COLOR_ID_GREEN>;
81			function = LED_FUNCTION_DISK;
82			gpios = <&gpio2 RK_PA0 GPIO_ACTIVE_LOW>;
83			label = "hdd4:green:disk";
84			linux,default-trigger = "disk-activity";
85			pinctrl-names = "default";
86			pinctrl-0 = <&hdd4_led_pin>;
87		};
88	};
89
90	dc_12v: regulator-dc-12v {
91		compatible = "regulator-fixed";
92		regulator-name = "dc_12v";
93		regulator-always-on;
94		regulator-boot-on;
95		regulator-min-microvolt = <12000000>;
96		regulator-max-microvolt = <12000000>;
97	};
98
99	vcc3v3_pcie: regulator-vcc3v3-pcie {
100		compatible = "regulator-fixed";
101		regulator-name = "vcc3v3_pcie";
102		regulator-min-microvolt = <3300000>;
103		regulator-max-microvolt = <3300000>;
104		enable-active-high;
105		gpios = <&gpio0 RK_PD4 GPIO_ACTIVE_HIGH>;
106		vin-supply = <&dc_12v>;
107	};
108
109	vcc3v3_sys: regulator-vcc3v3-sys {
110		compatible = "regulator-fixed";
111		regulator-name = "vcc3v3_sys";
112		regulator-always-on;
113		regulator-boot-on;
114		regulator-min-microvolt = <3300000>;
115		regulator-max-microvolt = <3300000>;
116		vin-supply = <&dc_12v>;
117	};
118
119	vcc5v0_host: regulator-vcc5v0-host {
120		compatible = "regulator-fixed";
121		enable-active-high;
122		pinctrl-names = "default";
123		pinctrl-0 = <&vcc5v0_host_en>;
124		gpio = <&gpio0 RK_PA6 GPIO_ACTIVE_HIGH>;
125		regulator-name = "vcc5v0_host";
126		regulator-always-on;
127		regulator-boot-on;
128		regulator-min-microvolt = <5000000>;
129		regulator-max-microvolt = <5000000>;
130		vin-supply = <&vcc5v0_usb>;
131	};
132
133	vcc5v0_otg: regulator-vcc5v0-otg {
134		compatible = "regulator-fixed";
135		enable-active-high;
136		gpio = <&gpio0 RK_PA5 GPIO_ACTIVE_HIGH>;
137		pinctrl-names = "default";
138		pinctrl-0 = <&vcc5v0_otg_en>;
139		regulator-name = "vcc5v0_otg";
140		regulator-always-on;
141		regulator-boot-on;
142		regulator-min-microvolt = <5000000>;
143		regulator-max-microvolt = <5000000>;
144		vin-supply = <&vcc5v0_usb>;
145	};
146
147	vcc5v0_sys: regulator-vcc5v0-sys {
148		compatible = "regulator-fixed";
149		regulator-name = "vcc5v0_sys";
150		regulator-always-on;
151		regulator-boot-on;
152		regulator-min-microvolt = <5000000>;
153		regulator-max-microvolt = <5000000>;
154		vin-supply = <&dc_12v>;
155	};
156
157	vcc5v0_usb: regulator-vcc5v0-usb {
158		compatible = "regulator-fixed";
159		regulator-name = "vcc5v0_usb";
160		regulator-always-on;
161		regulator-boot-on;
162		regulator-min-microvolt = <5000000>;
163		regulator-max-microvolt = <5000000>;
164		vin-supply = <&dc_12v>;
165	};
166};
167
168/* connected to usb_host0_xhci */
169&combphy0 {
170	status = "okay";
171};
172
173/* connected to sata1 */
174&combphy1 {
175	status = "okay";
176};
177
178/* connected to sata2 */
179&combphy2 {
180	status = "okay";
181};
182
183&cpu0 {
184	cpu-supply = <&vdd_cpu>;
185};
186
187&cpu1 {
188	cpu-supply = <&vdd_cpu>;
189};
190
191&cpu2 {
192	cpu-supply = <&vdd_cpu>;
193};
194
195&cpu3 {
196	cpu-supply = <&vdd_cpu>;
197};
198
199&gmac0 {
200	assigned-clocks = <&cru SCLK_GMAC0_RX_TX>, <&cru SCLK_GMAC0>;
201	assigned-clock-parents = <&cru SCLK_GMAC0_RGMII_SPEED>, <&cru CLK_MAC0_2TOP>;
202	assigned-clock-rates = <0>, <125000000>;
203	clock_in_out = "output";
204	phy-handle = <&rgmii_phy0>;
205	phy-mode = "rgmii-id";
206	pinctrl-names = "default";
207	pinctrl-0 = <&gmac0_miim
208		     &gmac0_tx_bus2
209		     &gmac0_rx_bus2
210		     &gmac0_rgmii_clk
211		     &gmac0_rgmii_bus>;
212	status = "okay";
213};
214
215&gpu {
216	mali-supply = <&vdd_gpu>;
217	status = "okay";
218};
219
220&i2c0 {
221	status = "okay";
222
223	pmic@20 {
224		compatible = "rockchip,rk809";
225		reg = <0x20>;
226		interrupt-parent = <&gpio0>;
227		interrupts = <RK_PA3 IRQ_TYPE_LEVEL_LOW>;
228		#clock-cells = <1>;
229		pinctrl-names = "default";
230		pinctrl-0 = <&pmic_int_l>;
231		system-power-controller;
232		vcc1-supply = <&vcc3v3_sys>;
233		vcc2-supply = <&vcc3v3_sys>;
234		vcc3-supply = <&vcc3v3_sys>;
235		vcc4-supply = <&vcc3v3_sys>;
236		vcc5-supply = <&vcc3v3_sys>;
237		vcc6-supply = <&vcc3v3_sys>;
238		vcc7-supply = <&vcc3v3_sys>;
239		vcc8-supply = <&vcc3v3_sys>;
240		vcc9-supply = <&vcc3v3_sys>;
241		wakeup-source;
242
243		regulators {
244			vdd_logic: DCDC_REG1 {
245				regulator-name = "vdd_logic";
246				regulator-always-on;
247				regulator-boot-on;
248				regulator-initial-mode = <0x2>;
249				regulator-min-microvolt = <500000>;
250				regulator-max-microvolt = <1350000>;
251				regulator-ramp-delay = <6001>;
252
253				regulator-state-mem {
254					regulator-off-in-suspend;
255				};
256			};
257
258			vdd_gpu: DCDC_REG2 {
259				regulator-name = "vdd_gpu";
260				regulator-always-on;
261				regulator-initial-mode = <0x2>;
262				regulator-min-microvolt = <500000>;
263				regulator-max-microvolt = <1350000>;
264				regulator-ramp-delay = <6001>;
265
266				regulator-state-mem {
267					regulator-off-in-suspend;
268				};
269			};
270
271			vcc_ddr: DCDC_REG3 {
272				regulator-name = "vcc_ddr";
273				regulator-always-on;
274				regulator-boot-on;
275				regulator-initial-mode = <0x2>;
276
277				regulator-state-mem {
278					regulator-on-in-suspend;
279				};
280			};
281
282			vdd_npu: DCDC_REG4 {
283				regulator-name = "vdd_npu";
284				regulator-initial-mode = <0x2>;
285				regulator-min-microvolt = <500000>;
286				regulator-max-microvolt = <1350000>;
287				regulator-ramp-delay = <6001>;
288
289				regulator-state-mem {
290					regulator-off-in-suspend;
291				};
292			};
293
294			vcc_1v8: DCDC_REG5 {
295				regulator-name = "vcc_1v8";
296				regulator-always-on;
297				regulator-boot-on;
298				regulator-min-microvolt = <1800000>;
299				regulator-max-microvolt = <1800000>;
300
301				regulator-state-mem {
302					regulator-off-in-suspend;
303				};
304			};
305
306			vdda0v9_image: LDO_REG1 {
307				regulator-name = "vdda0v9_image";
308				regulator-always-on;
309				regulator-min-microvolt = <900000>;
310				regulator-max-microvolt = <900000>;
311
312				regulator-state-mem {
313					regulator-off-in-suspend;
314				};
315			};
316
317			vdda_0v9: LDO_REG2 {
318				regulator-name = "vdda_0v9";
319				regulator-always-on;
320				regulator-boot-on;
321				regulator-min-microvolt = <900000>;
322				regulator-max-microvolt = <900000>;
323
324				regulator-state-mem {
325					regulator-off-in-suspend;
326				};
327			};
328
329			vdda0v9_pmu: LDO_REG3 {
330				regulator-name = "vdda0v9_pmu";
331				regulator-always-on;
332				regulator-boot-on;
333				regulator-min-microvolt = <900000>;
334				regulator-max-microvolt = <900000>;
335
336				regulator-state-mem {
337					regulator-on-in-suspend;
338					regulator-suspend-microvolt = <900000>;
339				};
340			};
341
342			vccio_acodec: LDO_REG4 {
343				regulator-name = "vccio_acodec";
344				regulator-always-on;
345				regulator-boot-on;
346				regulator-min-microvolt = <3300000>;
347				regulator-max-microvolt = <3300000>;
348
349				regulator-state-mem {
350					regulator-off-in-suspend;
351				};
352			};
353
354			vccio_sd: LDO_REG5 {
355				regulator-name = "vccio_sd";
356				regulator-min-microvolt = <1800000>;
357				regulator-max-microvolt = <3300000>;
358
359				regulator-state-mem {
360					regulator-off-in-suspend;
361				};
362			};
363
364			vcc3v3_pmu: LDO_REG6 {
365				regulator-name = "vcc3v3_pmu";
366				regulator-always-on;
367				regulator-boot-on;
368				regulator-min-microvolt = <3300000>;
369				regulator-max-microvolt = <3300000>;
370
371				regulator-state-mem {
372					regulator-on-in-suspend;
373					regulator-suspend-microvolt = <3300000>;
374				};
375			};
376
377			vcca_1v8: LDO_REG7 {
378				regulator-name = "vcca_1v8";
379				regulator-always-on;
380				regulator-boot-on;
381				regulator-min-microvolt = <1800000>;
382				regulator-max-microvolt = <1800000>;
383
384				regulator-state-mem {
385					regulator-off-in-suspend;
386				};
387			};
388
389			vcca1v8_pmu: LDO_REG8 {
390				regulator-name = "vcca1v8_pmu";
391				regulator-always-on;
392				regulator-boot-on;
393				regulator-min-microvolt = <1800000>;
394				regulator-max-microvolt = <1800000>;
395
396				regulator-state-mem {
397					regulator-on-in-suspend;
398					regulator-suspend-microvolt = <1800000>;
399				};
400			};
401
402			vcca1v8_image: LDO_REG9 {
403				regulator-name = "vcca1v8_image";
404				regulator-always-on;
405				regulator-min-microvolt = <1800000>;
406				regulator-max-microvolt = <1800000>;
407
408				regulator-state-mem {
409					regulator-off-in-suspend;
410				};
411			};
412
413			vcc_3v3: SWITCH_REG1 {
414				regulator-name = "vcc_3v3";
415				regulator-always-on;
416				regulator-boot-on;
417
418				regulator-state-mem {
419					regulator-off-in-suspend;
420				};
421			};
422
423			vcc3v3_sd: SWITCH_REG2 {
424				regulator-name = "vcc3v3_sd";
425				/*
426				 * turning this off, breaks access to both
427				 * PCIe controllers, refclk generator perhaps
428				 */
429				regulator-always-on;
430				regulator-boot-on;
431
432				regulator-state-mem {
433					regulator-off-in-suspend;
434				};
435			};
436		};
437	};
438
439	vdd_cpu: regulator@40 {
440		compatible = "silergy,syr827";
441		reg = <0x40>;
442		fcs,suspend-voltage-selector = <1>;
443		regulator-name = "vdd_cpu";
444		regulator-always-on;
445		regulator-boot-on;
446		regulator-min-microvolt = <712500>;
447		regulator-max-microvolt = <1390000>;
448		regulator-ramp-delay = <2300>;
449		vin-supply = <&vcc5v0_sys>;
450	};
451};
452
453&i2c1 {
454	status = "okay";
455
456	rtc_rv8263: rtc@51 {
457		compatible = "microcrystal,rv8263";
458		reg = <0x51>;
459		wakeup-source;
460	};
461
462	/* eeprom for vital-product-data on the mainboard */
463	eeprom@54 {
464		compatible = "giantec,gt24c04a", "atmel,24c04";
465		reg = <0x54>;
466		label = "VPD_MB";
467		num-addresses = <2>;
468		pagesize = <16>;
469		read-only;
470	};
471
472	/* eeprom for vital-product-data on the backplane */
473	eeprom@56 {
474		compatible = "giantec,gt24c04a", "atmel,24c04";
475		reg = <0x56>;
476		label = "VPD_BP";
477		num-addresses = <2>;
478		pagesize = <16>;
479		read-only;
480	};
481};
482
483&mdio0 {
484	rgmii_phy0: ethernet-phy@0 {
485		compatible = "ethernet-phy-ieee802.3-c22";
486		reg = <0x0>;
487	};
488};
489
490/*
491 * The MCU can provide system temperature too, but only by polling and of
492 * course also cannot set trip points. So attach to the cpu thermal-zone
493 * instead to control the fan.
494 */
495&cpu_thermal {
496	trips {
497		case_fan0: case-fan0 {
498			hysteresis = <2000>;
499			temperature = <35000>;
500			type = "active";
501		};
502
503		case_fan1: case-fan1 {
504			hysteresis = <2000>;
505			temperature = <45000>;
506			type = "active";
507		};
508
509		case_fan2: case-fan2 {
510			hysteresis = <2000>;
511			temperature = <65000>;
512			type = "active";
513		};
514	};
515
516	cooling-maps {
517		/*
518		 * Always provide some air movement, due to small case
519		 * full of harddrives.
520		 */
521		map1 {
522			cooling-device = <&fan THERMAL_NO_LIMIT 1>;
523			trip = <&case_fan0>;
524		};
525
526		map2 {
527			cooling-device = <&fan 2 3>;
528			trip = <&case_fan1>;
529		};
530
531		map3 {
532			cooling-device = <&fan 4 THERMAL_NO_LIMIT>;
533			trip = <&case_fan2>;
534		};
535	};
536};
537
538&pcie30phy {
539	data-lanes = <1 2>;
540	status = "okay";
541};
542
543/* Connected to a JMicron AHCI SATA controller */
544&pcie3x1 {
545	reset-gpios = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
546	vpcie3v3-supply = <&vcc3v3_pcie>;
547	status = "okay";
548};
549
550/* Connected to the 2.5G NIC for the upper network jack */
551&pcie3x2 {
552	num-lanes = <1>;
553	reset-gpios = <&gpio2 RK_PD6 GPIO_ACTIVE_HIGH>;
554	vpcie3v3-supply = <&vcc3v3_pcie>;
555	status = "okay";
556};
557
558&pinctrl {
559	keys {
560		copy_button_pin: copy-button-pin {
561			rockchip,pins = <0 RK_PB6 RK_FUNC_GPIO &pcfg_pull_up>;
562		};
563
564		reset_button_pin: reset-button-pin {
565			rockchip,pins = <0 RK_PB5 RK_FUNC_GPIO &pcfg_pull_up>;
566		};
567	};
568
569	leds {
570		hdd1_led_pin: hdd1-led-pin {
571			rockchip,pins = <1 RK_PD5 RK_FUNC_GPIO &pcfg_pull_up>;
572		};
573
574		hdd2_led_pin: hdd2-led-pin {
575			rockchip,pins = <1 RK_PD6 RK_FUNC_GPIO &pcfg_pull_up>;
576		};
577
578		hdd3_led_pin: hdd3-led-pin {
579			rockchip,pins = <1 RK_PD7 RK_FUNC_GPIO &pcfg_pull_up>;
580		};
581
582		hdd4_led_pin: hdd4_led-pin {
583			rockchip,pins = <2 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>;
584		};
585	};
586
587	pmic {
588		pmic_int_l: pmic-int-l {
589			rockchip,pins = <0 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>;
590		};
591	};
592
593	usb {
594		vcc5v0_host_en: vcc5v0-host-en {
595			rockchip,pins = <0 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>;
596		};
597
598		vcc5v0_otg_en: vcc5v0-otg-en {
599			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>;
600		};
601	};
602};
603
604&pmu_io_domains {
605	vccio4-supply = <&vcc_1v8>;
606	vccio6-supply = <&vcc_1v8>;
607	status = "okay";
608};
609
610&sata1 {
611	status = "okay";
612};
613
614&sata2 {
615	status = "okay";
616};
617
618&sdhci {
619	bus-width = <8>;
620	max-frequency = <200000000>;
621	non-removable;
622	status = "okay";
623};
624
625&tsadc {
626	rockchip,hw-tshut-mode = <1>;
627	rockchip,hw-tshut-polarity = <0>;
628	status = "okay";
629};
630
631/*
632 * Connected to an MCU, that provides access to more LEDs,
633 * buzzer, fan control and more.
634 */
635&uart0 {
636	status = "okay";
637
638	mcu {
639		compatible = "qnap,ts433-mcu";
640
641		fan: fan-0 {
642			#cooling-cells = <2>;
643			cooling-levels = <0 64 89 128 166 204 221 238>;
644		};
645	};
646};
647
648/*
649 * Pins available on CN3 connector at TTL voltage level (3V3).
650 * ,_  _.
651 * |1234|  1=TX 2=VCC
652 * `----'  3=RX 4=GND
653 */
654&uart2 {
655	status = "okay";
656};
657
658&usb2phy0 {
659	status = "okay";
660};
661
662/* connected to usb_host0_xhci */
663&usb2phy0_otg {
664	phy-supply = <&vcc5v0_otg>;
665	status = "okay";
666};
667
668&usb2phy1 {
669	status = "okay";
670};
671
672/* connected to usb_host1_ehci/ohci */
673&usb2phy1_host {
674	phy-supply = <&vcc5v0_host>;
675	status = "okay";
676};
677
678/* connected to usb_host0_ehci/ohci */
679&usb2phy1_otg {
680	phy-supply = <&vcc5v0_host>;
681	status = "okay";
682};
683
684/* right port backside */
685&usb_host0_ehci {
686	status = "okay";
687};
688
689&usb_host0_ohci {
690	status = "okay";
691};
692
693/* front port */
694&usb_host0_xhci {
695	dr_mode = "host";
696	status = "okay";
697};
698
699/* left port backside */
700&usb_host1_ehci {
701	status = "okay";
702};
703
704&usb_host1_ohci {
705	status = "okay";
706};
707