1/*
2 * sun9i-a80-cx-a99.dts - Device Tree file for the Sunchip CX-A99 board.
3 *
4 * Copyright (C) 2017 Rask Ingemann Lambertsen <rask@formelder.dk>
5 *
6 * This file is dual-licensed: you can use it either under the terms
7 * of the GPL or the X11 license, at your option. Note that this dual
8 * licensing only applies to this file, and not this project as a
9 * whole.
10 *
11 *  a) This file is free software; you can redistribute it and/or
12 *     modify it under the terms of the GNU General Public License as
13 *     published by the Free Software Foundation; either version 2 of the
14 *     License, or (at your option) any later version.
15 *
16 *     This file is distributed in the hope that it will be useful,
17 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *     GNU General Public License for more details.
20 *
21 * Or, alternatively,
22 *
23 *  b) Permission is hereby granted, free of charge, to any person
24 *     obtaining a copy of this software and associated documentation
25 *     files (the "Software"), to deal in the Software without
26 *     restriction, including without limitation the rights to use,
27 *     copy, modify, merge, publish, distribute, sublicense, and/or
28 *     sell copies of the Software, and to permit persons to whom the
29 *     Software is furnished to do so, subject to the following
30 *     conditions:
31 *
32 *     The above copyright notice and this permission notice shall be
33 *     included in all copies or substantial portions of the Software.
34 *
35 *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
37 *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38 *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
39 *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
40 *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
42 *     OTHER DEALINGS IN THE SOFTWARE.
43 */
44
45/*
46 * The Sunchip CX-A99 board is found in several similar Android media
47 * players, such as:
48 *
49 * Instabox Fantasy A8 (no external antenna)
50 * Jesurun CS-Q8 (ships with larger remote control)
51 * Jesurun Maxone
52 * Rikomagic (RKM) MK80/MK80LE
53 * Tronsmart Draco AW80 Meta/Telos
54 *
55 * See the Sunchip CX-A99 page on the Linux-sunxi wiki for more information.
56 */
57
58/dts-v1/;
59#include "sun9i-a80.dtsi"
60
61#include <dt-bindings/gpio/gpio.h>
62
63/ {
64	model = "Sunchip CX-A99";
65	compatible = "sunchip,cx-a99", "allwinner,sun9i-a80";
66
67	aliases {
68		serial0 = &uart0;
69	};
70
71	chosen {
72		stdout-path = "serial0:115200n8";
73	};
74
75	leds {
76		compatible = "gpio-leds";
77
78		blue {
79			gpios = <&pio 6 10 GPIO_ACTIVE_HIGH>;	/* PG10 */
80			label = "cx-a99:blue:status";
81		};
82
83		red {
84			gpios = <&pio 6 11 GPIO_ACTIVE_HIGH>;	/* PG11 */
85			label = "cx-a99:red:status";
86		};
87	};
88
89	powerseq_wifi: powerseq-wifi {
90		compatible = "mmc-pwrseq-simple";
91		clocks = <&ac100_rtc 1>;
92		clock-names = "ext_clock";
93		reset-gpios = <&r_pio 1 0 GPIO_ACTIVE_LOW>;	/* PM0 */
94		post-power-on-delay-ms = <1>;	/* Minimum 2 cycles. */
95	};
96
97	/* USB 2.0 connector closest to the 12 V power connector. */
98	reg_usb1_vbus: regulator-usb1-vbus {
99		compatible = "regulator-fixed";
100		regulator-name = "usb1-vbus";
101		regulator-min-microvolt = <5000000>;
102		regulator-max-microvolt = <5000000>;
103		gpio = <&r_pio 0 7 /* no flag support */ 0>;	/* PL7 */
104		enable-active-high;
105	};
106
107	/* USB 2.0 connector next to the SD card slot. */
108	reg_usb3_vbus: regulator-usb3-vbus {
109		compatible = "regulator-fixed";
110		regulator-name = "usb3-vbus";
111		regulator-min-microvolt = <5000000>;
112		regulator-max-microvolt = <5000000>;
113		gpio = <&r_pio 0 8 /* no flag support */ 0>;	/* PL8 */
114		enable-active-high;
115	};
116
117	/*
118	 * OZ80120 voltage regulator for the four Cortex-A15 CPU cores.
119	 * Although the regulator can output 750 - 1200 mV, the permissible
120	 * range for the CPU cores is only 800 - 1100 mV.
121	 */
122	reg_vdd_cpub: regulator-vdd-cpub {
123		compatible = "regulator-gpio";
124
125		regulator-always-on;
126		regulator-min-microvolt = < 800000>;
127		regulator-max-microvolt = <1100000>;
128		regulator-name = "vdd-cpub";
129
130		/* Note: GPIO flags are not supported here . */
131		enable-gpio = <&r_pio 0 2 /* flags n/a */ 0>;	/* PL2 */
132		enable-active-high;
133		gpios = <&r_pio 0 3 /* no flag support */ 0>,	/* PL3 */
134			<&r_pio 0 4 /* no flag support */ 0>,	/* PL4 */
135			<&r_pio 0 5 /* no flag support */ 0>;	/* PL5 */
136
137		gpios-states = <1 0 0>;
138		states = <	 750000 0x7
139				 800000 0x3
140				 850000 0x5
141				 900000 0x1
142				 950000 0x6
143				1000000 0x2
144				1100000 0x4
145				1200000 0x0>;
146	};
147};
148
149&ehci0 {
150	status = "okay";
151};
152
153&ehci2 {
154	status = "okay";
155};
156
157/*
158 * SD card slot. Although the GPIO pin for card detection is listed as capable
159 * of generating interrupts in the "A80 User Manual", this doesn't work for
160 * some unknown reason, so poll the GPIO for card detection. This is also what
161 * the vendor sys_config.fex file specifies.
162 */
163&mmc0 {
164	bus-width = <4>;
165	cd-gpios = <&pio 7 17 GPIO_ACTIVE_LOW>;	/* PH17 */
166	broken-cd;				/* Poll. */
167	pinctrl-names = "default";
168	pinctrl-0 = <&mmc0_pins>;
169	vmmc-supply = <&reg_dcdce>;
170	status = "okay";
171};
172
173/* Ampak AP6335 IEEE 802.11 a/b/g/n/ac Wifi. */
174&mmc1 {
175	bus-width = <4>;
176	non-removable;
177	pinctrl-names = "default";
178	pinctrl-0 = <&mmc1_pins>;
179	vmmc-supply = <&reg_cldo3>;	/* See cldo2,cldo3 note. */
180	vqmmc-supply = <&reg_aldo2>;
181	mmc-pwrseq = <&powerseq_wifi>;
182	status = "okay";
183};
184
185/* On-board eMMC card. */
186&mmc2 {
187	bus-width = <8>;
188	non-removable;
189	pinctrl-names = "default";
190	pinctrl-0 = <&mmc2_8bit_pins>;
191	vmmc-supply = <&reg_dcdce>;
192	status = "okay";
193};
194
195&osc32k {
196	clocks = <&ac100_rtc 0>;
197};
198
199&r_ir {
200	status = "okay";
201};
202
203&r_rsb {
204	status = "okay";
205
206	ac100: codec@e89 {
207		compatible = "x-powers,ac100";
208		reg = <0xe89>;
209
210		ac100_codec: codec {
211			compatible = "x-powers,ac100-codec";
212			interrupt-parent = <&r_pio>;
213			interrupts = <0 9 IRQ_TYPE_LEVEL_LOW>;	/* PL9 */
214			#clock-cells = <0>;
215			clock-output-names = "4M_adda";
216		};
217
218		ac100_rtc: rtc {
219			compatible = "x-powers,ac100-rtc";
220			interrupt-parent = <&nmi_intc>;
221			interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
222			clocks = <&ac100_codec>;
223			#clock-cells = <1>;
224			clock-output-names = "cko1_rtc",
225					     "cko2_rtc",
226					     "cko3_rtc";
227		};
228	};
229
230	pmic@745 {
231		compatible = "x-powers,axp808", "x-powers,axp806";
232		x-powers,master-mode;
233		reg = <0x745>;
234		interrupt-parent = <&nmi_intc>;
235		interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
236		interrupt-controller;
237		#interrupt-cells = <1>;
238
239		swin-supply = <&reg_dcdce>;
240
241		regulators {
242			reg_aldo1: aldo1 {
243				regulator-boot-on;
244				regulator-min-microvolt = <3000000>;
245				regulator-max-microvolt = <3000000>;
246				regulator-name = "vcc-3v0";
247			};
248
249			/* Supplies pin groups G and M. */
250			reg_aldo2: aldo2 {
251				regulator-boot-on;
252				regulator-min-microvolt = <1800000>;
253				regulator-max-microvolt = <3600000>;
254				regulator-name = "vddio-wifi-codec";
255			};
256
257			reg_aldo3: aldo3 {
258				regulator-boot-on;
259				regulator-min-microvolt = <2500000>;
260				regulator-max-microvolt = <2500000>;
261				regulator-name = "vddio-gmac";
262			};
263
264			reg_bldo1: bldo1 {
265				regulator-always-on;	/* Hang if disabled */
266				regulator-min-microvolt = <1700000>;
267				regulator-max-microvolt = <1900000>;
268				regulator-name = "vdd18-dll-vcc18-pll";
269			};
270
271			reg_bldo2: bldo2 {
272				regulator-always-on;	/* Hang if disabled */
273				regulator-min-microvolt = < 800000>;
274				regulator-max-microvolt = <1100000>;
275				regulator-name = "vdd-cpus";
276			};
277
278			reg_bldo3: bldo3 {
279				regulator-min-microvolt = <1100000>;
280				regulator-max-microvolt = <1300000>;
281				regulator-name = "vcc12-hsic";
282			};
283
284			reg_bldo4: bldo4 {
285				regulator-boot-on;
286				regulator-min-microvolt = < 800000>;
287				regulator-max-microvolt = <1100000>;
288				regulator-name = "vdd09-hdmi";
289			};
290
291			/* Supplies PLx pins which control some regulators. */
292			reg_cldo1: cldo1 {
293				regulator-always-on;
294				regulator-min-microvolt = <3300000>;
295				regulator-max-microvolt = <3300000>;
296				regulator-name = "vcc-pl-led";
297			};
298
299			/*
300			 * cldo2 and cldo3 are connected in parallel.
301			 * There is currently no way to express that.
302			 * For now, use regulator-always-on on cldo2 and lock
303			 * the voltage on both to 3.3 V.
304			 */
305			reg_cldo2: cldo2 {
306				regulator-always-on;
307				regulator-min-microvolt = <3300000>;
308				regulator-max-microvolt = <3300000>;
309				regulator-name = "vbat2-wifi+bt";
310			};
311
312			reg_cldo3: cldo3 {
313				regulator-min-microvolt = <3300000>;
314				regulator-max-microvolt = <3300000>;
315				regulator-name = "vbat1-wifi+bt";
316			};
317
318			reg_dcdca: dcdca {
319				regulator-always-on;
320				regulator-min-microvolt = < 800000>;
321				regulator-max-microvolt = <1100000>;
322				regulator-name = "vdd-cpua";
323			};
324
325			reg_dcdcb: dcdcb {
326				regulator-always-on;
327				regulator-min-microvolt = <1450000>;
328				regulator-max-microvolt = <1550000>;
329				regulator-name = "vcc-dram";
330			};
331
332			reg_dcdcc: dcdcc {
333				regulator-min-microvolt = < 800000>;
334				regulator-max-microvolt = <1100000>;
335				regulator-name = "vdd-gpu";
336			};
337
338			reg_dcdcd: dcdcd {
339				regulator-always-on;	/* Hang if disabled. */
340				regulator-min-microvolt = < 800000>;
341				regulator-max-microvolt = <1100000>;
342				regulator-name = "vdd-sys";
343			};
344
345			/* Supplies pin groups B-F and H. */
346			reg_dcdce: dcdce {
347				regulator-always-on;
348				regulator-min-microvolt = <3300000>;
349				regulator-max-microvolt = <3300000>;
350				regulator-name = "vcc-io-mmc-spdif";
351			};
352
353			reg_sw: sw {
354				regulator-min-microvolt = <3300000>;
355				regulator-max-microvolt = <3300000>;
356				regulator-name = "vcc-gmac-codec";
357			};
358		};
359	};
360};
361
362/*
363 * 5-pin connector opposite of the SD card slot:
364 * 1 = GND (pointed to by small triangle), 2 = GND, 3 = 3.3 V, 4 = RX, 5 = TX.
365 */
366&uart0 {
367	pinctrl-names = "default";
368	pinctrl-0 = <&uart0_ph_pins>;
369	status = "okay";
370};
371
372&usbphy1 {
373	phy-supply = <&reg_usb1_vbus>;
374	status = "okay";
375};
376
377&usbphy3 {
378	phy-supply = <&reg_usb3_vbus>;
379	status = "okay";
380};
381