1// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2019 BayLibre, SAS
4 * Author: Neil Armstrong <narmstrong@baylibre.com>
5 * Copyright (c) 2019 Christian Hewitt <christianshewitt@gmail.com>
6 */
7
8#include <dt-bindings/input/input.h>
9#include <dt-bindings/leds/common.h>
10#include <dt-bindings/gpio/meson-g12a-gpio.h>
11#include <dt-bindings/sound/meson-g12a-tohdmitx.h>
12
13/ {
14	aliases {
15		serial0 = &uart_AO;
16		ethernet0 = &ethmac;
17		rtc0 = &rtc;
18		rtc1 = &vrtc;
19	};
20
21	chosen {
22		stdout-path = "serial0:115200n8";
23	};
24
25	memory@0 {
26		device_type = "memory";
27		reg = <0x0 0x0 0x0 0x80000000>;
28	};
29
30	adc-keys {
31		compatible = "adc-keys";
32		io-channels = <&saradc 2>;
33		io-channel-names = "buttons";
34		keyup-threshold-microvolt = <1710000>;
35
36		button-function {
37			label = "Function";
38			linux,code = <KEY_FN>;
39			press-threshold-microvolt = <10000>;
40		};
41	};
42
43	leds {
44		compatible = "gpio-leds";
45
46		led-white {
47			color = <LED_COLOR_ID_WHITE>;
48			function = LED_FUNCTION_STATUS;
49			gpios = <&gpio_ao GPIOAO_4 GPIO_ACTIVE_HIGH>;
50			linux,default-trigger = "heartbeat";
51		};
52
53		led-red {
54			color = <LED_COLOR_ID_RED>;
55			function = LED_FUNCTION_STATUS;
56			gpios = <&gpio_expander 5 GPIO_ACTIVE_HIGH>;
57		};
58	};
59
60	emmc_pwrseq: emmc-pwrseq {
61		compatible = "mmc-pwrseq-emmc";
62		reset-gpios = <&gpio BOOT_12 GPIO_ACTIVE_LOW>;
63	};
64
65	gpio-keys-polled {
66		compatible = "gpio-keys-polled";
67		poll-interval = <100>;
68
69		power-button {
70			label = "power";
71			linux,code = <KEY_POWER>;
72			gpios = <&gpio_ao GPIOAO_7 GPIO_ACTIVE_LOW>;
73		};
74	};
75
76	sdio_pwrseq: sdio-pwrseq {
77		compatible = "mmc-pwrseq-simple";
78		reset-gpios = <&gpio GPIOX_6 GPIO_ACTIVE_LOW>;
79		clocks = <&wifi32k>;
80		clock-names = "ext_clock";
81	};
82
83	dc_in: regulator-dc_in {
84		compatible = "regulator-fixed";
85		regulator-name = "DC_IN";
86		regulator-min-microvolt = <5000000>;
87		regulator-max-microvolt = <5000000>;
88		regulator-always-on;
89	};
90
91	vcc_5v: regulator-vcc_5v {
92		compatible = "regulator-fixed";
93		regulator-name = "VCC_5V";
94		regulator-min-microvolt = <5000000>;
95		regulator-max-microvolt = <5000000>;
96		vin-supply = <&dc_in>;
97
98		gpio = <&gpio GPIOH_8 GPIO_OPEN_DRAIN>;
99		enable-active-high;
100	};
101
102	vcc_1v8: regulator-vcc_1v8 {
103		compatible = "regulator-fixed";
104		regulator-name = "VCC_1V8";
105		regulator-min-microvolt = <1800000>;
106		regulator-max-microvolt = <1800000>;
107		vin-supply = <&vcc_3v3>;
108		regulator-always-on;
109	};
110
111	vcc_3v3: regulator-vcc_3v3 {
112		compatible = "regulator-fixed";
113		regulator-name = "VCC_3V3";
114		regulator-min-microvolt = <3300000>;
115		regulator-max-microvolt = <3300000>;
116		vin-supply = <&vsys_3v3>;
117		regulator-always-on;
118		/* FIXME: actually controlled by VDDCPU_B_EN */
119	};
120
121	vddao_1v8: regulator-vddao_1v8 {
122		compatible = "regulator-fixed";
123		regulator-name = "VDDIO_AO1V8";
124		regulator-min-microvolt = <1800000>;
125		regulator-max-microvolt = <1800000>;
126		vin-supply = <&vsys_3v3>;
127		regulator-always-on;
128	};
129
130	emmc_1v8: regulator-emmc_1v8 {
131		compatible = "regulator-fixed";
132		regulator-name = "EMMC_AO1V8";
133		regulator-min-microvolt = <1800000>;
134		regulator-max-microvolt = <1800000>;
135		vin-supply = <&vcc_3v3>;
136		regulator-always-on;
137	};
138
139	vsys_3v3: regulator-vsys_3v3 {
140		compatible = "regulator-fixed";
141		regulator-name = "VSYS_3V3";
142		regulator-min-microvolt = <3300000>;
143		regulator-max-microvolt = <3300000>;
144		vin-supply = <&dc_in>;
145		regulator-always-on;
146	};
147
148	usb_pwr: regulator-usb_pwr {
149		compatible = "regulator-fixed";
150		regulator-name = "USB_PWR";
151		regulator-min-microvolt = <5000000>;
152		regulator-max-microvolt = <5000000>;
153		vin-supply = <&vcc_5v>;
154
155		gpio = <&gpio GPIOA_6 GPIO_ACTIVE_HIGH>;
156		enable-active-high;
157	};
158
159	hdmi-connector {
160		compatible = "hdmi-connector";
161		type = "a";
162
163		port {
164			hdmi_connector_in: endpoint {
165				remote-endpoint = <&hdmi_tx_tmds_out>;
166			};
167		};
168	};
169
170
171	sound {
172		compatible = "amlogic,axg-sound-card";
173		model = "KHADAS-VIM3";
174		audio-aux-devs = <&tdmin_a>, <&tdmout_a>;
175		audio-routing = "TDMOUT_A IN 0", "FRDDR_A OUT 0",
176				"TDMOUT_A IN 1", "FRDDR_B OUT 0",
177				"TDMOUT_A IN 2", "FRDDR_C OUT 0",
178				"TDM_A Playback", "TDMOUT_A OUT",
179				"TDMIN_A IN 0", "TDM_A Capture",
180				"TDMIN_A IN 3", "TDM_A Loopback",
181				"TODDR_A IN 0", "TDMIN_A OUT",
182				"TODDR_B IN 0", "TDMIN_A OUT",
183				"TODDR_C IN 0", "TDMIN_A OUT";
184
185		assigned-clocks = <&clkc CLKID_MPLL2>,
186				  <&clkc CLKID_MPLL0>,
187				  <&clkc CLKID_MPLL1>;
188		assigned-clock-parents = <0>, <0>, <0>;
189		assigned-clock-rates = <294912000>,
190				       <270950400>,
191				       <393216000>;
192
193		dai-link-0 {
194			sound-dai = <&frddr_a>;
195		};
196
197		dai-link-1 {
198			sound-dai = <&frddr_b>;
199		};
200
201		dai-link-2 {
202			sound-dai = <&frddr_c>;
203		};
204
205		dai-link-3 {
206			sound-dai = <&toddr_a>;
207		};
208
209		dai-link-4 {
210			sound-dai = <&toddr_b>;
211		};
212
213		dai-link-5 {
214			sound-dai = <&toddr_c>;
215		};
216
217		/* 8ch hdmi interface */
218		dai-link-6 {
219			sound-dai = <&tdmif_a>;
220			dai-format = "i2s";
221			dai-tdm-slot-tx-mask-0 = <1 1>;
222			dai-tdm-slot-tx-mask-1 = <1 1>;
223			dai-tdm-slot-tx-mask-2 = <1 1>;
224			dai-tdm-slot-tx-mask-3 = <1 1>;
225			mclk-fs = <256>;
226
227			codec {
228				sound-dai = <&tohdmitx TOHDMITX_I2S_IN_A>;
229			};
230		};
231
232		/* hdmi glue */
233		dai-link-7 {
234			sound-dai = <&tohdmitx TOHDMITX_I2S_OUT>;
235
236			codec {
237				sound-dai = <&hdmi_tx>;
238			};
239		};
240	};
241
242	wifi32k: wifi32k {
243		compatible = "pwm-clock";
244		#clock-cells = <0>;
245		clock-frequency = <32768>;
246		pwms = <&pwm_ef 0 30518 0>; /* PWM_E at 32.768KHz */
247	};
248};
249
250&arb {
251	status = "okay";
252};
253
254&clkc_audio {
255	status = "okay";
256};
257
258&cec_AO {
259	pinctrl-0 = <&cec_ao_a_h_pins>;
260	pinctrl-names = "default";
261	status = "disabled";
262	hdmi-phandle = <&hdmi_tx>;
263};
264
265&cecb_AO {
266	pinctrl-0 = <&cec_ao_b_h_pins>;
267	pinctrl-names = "default";
268	status = "okay";
269	hdmi-phandle = <&hdmi_tx>;
270};
271
272&cpu_thermal {
273	trips {
274		cpu_active: cpu-active {
275			temperature = <80000>; /* millicelsius */
276			hysteresis = <2000>; /* millicelsius */
277			type = "active";
278		};
279	};
280
281	cooling-maps {
282		map {
283			trip = <&cpu_active>;
284			cooling-device = <&khadas_mcu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
285		};
286	};
287};
288
289&ext_mdio {
290	external_phy: ethernet-phy@0 {
291		/* Realtek RTL8211F (0x001cc916) */
292		reg = <0>;
293		max-speed = <1000>;
294
295		interrupt-parent = <&gpio_intc>;
296		/* MAC_INTR on GPIOZ_14 */
297		interrupts = <26 IRQ_TYPE_LEVEL_LOW>;
298	};
299};
300
301&ethmac {
302	pinctrl-0 = <&eth_pins>, <&eth_rgmii_pins>;
303	pinctrl-names = "default";
304	status = "okay";
305	phy-mode = "rgmii";
306	phy-handle = <&external_phy>;
307	amlogic,tx-delay-ns = <2>;
308};
309
310&frddr_a {
311	status = "okay";
312};
313
314&frddr_b {
315	status = "okay";
316};
317
318&frddr_c {
319	status = "okay";
320};
321
322&hdmi_tx {
323	status = "okay";
324	pinctrl-0 = <&hdmitx_hpd_pins>, <&hdmitx_ddc_pins>;
325	pinctrl-names = "default";
326	hdmi-supply = <&vcc_5v>;
327};
328
329&hdmi_tx_tmds_port {
330	hdmi_tx_tmds_out: endpoint {
331		remote-endpoint = <&hdmi_connector_in>;
332	};
333};
334
335&i2c_AO {
336	status = "okay";
337	pinctrl-0 = <&i2c_ao_sck_pins>, <&i2c_ao_sda_pins>;
338	pinctrl-names = "default";
339
340	khadas_mcu: system-controller@18 {
341		compatible = "khadas,mcu";
342		reg = <0x18>;
343		#cooling-cells = <2>;
344	};
345
346	gpio_expander: gpio-controller@20 {
347		compatible = "ti,tca6408";
348		reg = <0x20>;
349		vcc-supply = <&vcc_3v3>;
350		gpio-controller;
351		#gpio-cells = <2>;
352	};
353
354	rtc: rtc@51 {
355		compatible = "haoyu,hym8563";
356		reg = <0x51>;
357		#clock-cells = <0>;
358	};
359};
360
361&ir {
362	status = "okay";
363	pinctrl-0 = <&remote_input_ao_pins>;
364	pinctrl-names = "default";
365	linux,rc-map-name = "rc-khadas";
366};
367
368&pcie {
369	reset-gpios = <&gpio GPIOA_8 GPIO_ACTIVE_LOW>;
370};
371
372&pwm_ef {
373	status = "okay";
374	pinctrl-0 = <&pwm_e_pins>;
375	pinctrl-names = "default";
376};
377
378&saradc {
379	status = "okay";
380	vref-supply = <&vddao_1v8>;
381};
382
383/* SDIO */
384&sd_emmc_a {
385	status = "okay";
386	pinctrl-0 = <&sdio_pins>;
387	pinctrl-1 = <&sdio_clk_gate_pins>;
388	pinctrl-names = "default", "clk-gate";
389	#address-cells = <1>;
390	#size-cells = <0>;
391
392	bus-width = <4>;
393	cap-sd-highspeed;
394	max-frequency = <100000000>;
395
396	non-removable;
397	disable-wp;
398
399	/* WiFi firmware requires power to be kept while in suspend */
400	keep-power-in-suspend;
401
402	mmc-pwrseq = <&sdio_pwrseq>;
403
404	vmmc-supply = <&vsys_3v3>;
405	vqmmc-supply = <&vddao_1v8>;
406
407	brcmf: wifi@1 {
408		reg = <1>;
409		compatible = "brcm,bcm4329-fmac";
410	};
411};
412
413/* SD card */
414&sd_emmc_b {
415	status = "okay";
416	pinctrl-0 = <&sdcard_c_pins>;
417	pinctrl-1 = <&sdcard_clk_gate_c_pins>;
418	pinctrl-names = "default", "clk-gate";
419
420	bus-width = <4>;
421	cap-sd-highspeed;
422	max-frequency = <50000000>;
423	disable-wp;
424
425	cd-gpios = <&gpio GPIOC_6 GPIO_ACTIVE_LOW>;
426	vmmc-supply = <&vsys_3v3>;
427	vqmmc-supply = <&vsys_3v3>;
428};
429
430/* eMMC */
431&sd_emmc_c {
432	status = "okay";
433	pinctrl-0 = <&emmc_ctrl_pins>, <&emmc_data_8b_pins>, <&emmc_ds_pins>;
434	pinctrl-1 = <&emmc_clk_gate_pins>;
435	pinctrl-names = "default", "clk-gate";
436
437	bus-width = <8>;
438	cap-mmc-highspeed;
439	mmc-ddr-1_8v;
440	mmc-hs200-1_8v;
441	max-frequency = <200000000>;
442	disable-wp;
443
444	mmc-pwrseq = <&emmc_pwrseq>;
445	vmmc-supply = <&vcc_3v3>;
446	vqmmc-supply = <&emmc_1v8>;
447};
448
449/*
450 * EMMC_D4, EMMC_D5, EMMC_D6 and EMMC_D7 pins are shared between SPI NOR CS
451 * and eMMC Data 4 to 7 pins.
452 * Replace emmc_data_8b_pins to emmc_data_4b_pins from sd_emmc_c pinctrl-0,
453 * and change bus-width to 4 then spifc can be enabled.
454 */
455&spifc {
456	status = "disabled";
457	pinctrl-0 = <&nor_pins>;
458	pinctrl-names = "default";
459
460	w25q128: flash@0 {
461		#address-cells = <1>;
462		#size-cells = <1>;
463		compatible = "winbond,w25q128fw", "jedec,spi-nor";
464		reg = <0>;
465		spi-max-frequency = <104000000>;
466	};
467};
468
469&tdmif_a {
470	status = "okay";
471};
472
473&tdmin_a {
474	status = "okay";
475};
476
477&tdmout_a {
478	status = "okay";
479};
480
481&toddr_a {
482	status = "okay";
483};
484
485&toddr_b {
486	status = "okay";
487};
488
489&toddr_c {
490	status = "okay";
491};
492
493&tohdmitx {
494	status = "okay";
495};
496
497&uart_A {
498	status = "okay";
499	pinctrl-0 = <&uart_a_pins>, <&uart_a_cts_rts_pins>;
500	pinctrl-names = "default";
501	uart-has-rtscts;
502
503	bluetooth {
504		compatible = "brcm,bcm43438-bt";
505		shutdown-gpios = <&gpio GPIOX_17 GPIO_ACTIVE_HIGH>;
506		max-speed = <2000000>;
507		clocks = <&wifi32k>;
508		clock-names = "lpo";
509	};
510};
511
512&uart_AO {
513	status = "okay";
514	pinctrl-0 = <&uart_ao_a_pins>;
515	pinctrl-names = "default";
516};
517
518&usb2_phy0 {
519	phy-supply = <&dc_in>;
520};
521
522&usb2_phy1 {
523	phy-supply = <&usb_pwr>;
524};
525
526&usb3_pcie_phy {
527	phy-supply = <&usb_pwr>;
528};
529
530&usb {
531	status = "okay";
532	dr_mode = "peripheral";
533};
534