xref: /rk3399_ARM-atf/plat/allwinner/sun50i_a64/sunxi_power.c (revision 4538c4983b2f64160afcbe7a4d36b0810b1c430c)
17c26b6ecSIcenowy Zheng /*
2c0e109f2SSamuel Holland  * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
37c26b6ecSIcenowy Zheng  * Copyright (c) 2018, Icenowy Zheng <icenowy@aosc.io>
47c26b6ecSIcenowy Zheng  *
57c26b6ecSIcenowy Zheng  * SPDX-License-Identifier: BSD-3-Clause
67c26b6ecSIcenowy Zheng  */
77c26b6ecSIcenowy Zheng 
8f953c30fSAndre Przywara #include <errno.h>
909d40e0eSAntonio Nino Diaz 
10ed80c1e2SAndre Przywara #include <libfdt.h>
1109d40e0eSAntonio Nino Diaz 
12f953c30fSAndre Przywara #include <platform_def.h>
1309d40e0eSAntonio Nino Diaz 
1409d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1509d40e0eSAntonio Nino Diaz #include <common/debug.h>
1609d40e0eSAntonio Nino Diaz #include <drivers/allwinner/sunxi_rsb.h>
1709d40e0eSAntonio Nino Diaz #include <drivers/delay_timer.h>
1809d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
1909d40e0eSAntonio Nino Diaz 
20f953c30fSAndre Przywara #include <sunxi_def.h>
21f953c30fSAndre Przywara #include <sunxi_mmap.h>
224ec1a239SAndre Przywara #include <sunxi_private.h>
23f953c30fSAndre Przywara 
24f953c30fSAndre Przywara static enum pmic_type {
25c0e109f2SSamuel Holland 	UNKNOWN,
26f953c30fSAndre Przywara 	GENERIC_H5,
27f953c30fSAndre Przywara 	GENERIC_A64,
283d22228fSAndre Przywara 	REF_DESIGN_H5,	/* regulators controlled by GPIO pins on port L */
29eae5fe79SAndre Przywara 	AXP803_RSB,	/* PMIC connected via RSB on most A64 boards */
30f953c30fSAndre Przywara } pmic;
31f953c30fSAndre Przywara 
32eae5fe79SAndre Przywara #define AXP803_HW_ADDR	0x3a3
33eae5fe79SAndre Przywara #define AXP803_RT_ADDR	0x2d
34eae5fe79SAndre Przywara 
35f953c30fSAndre Przywara /*
36f953c30fSAndre Przywara  * On boards without a proper PMIC we struggle to turn off the system properly.
37f953c30fSAndre Przywara  * Try to turn off as much off the system as we can, to reduce power
38f953c30fSAndre Przywara  * consumption. This should be entered with only one core running and SMP
39f953c30fSAndre Przywara  * disabled.
40f953c30fSAndre Przywara  * This function only cares about peripherals.
41f953c30fSAndre Przywara  */
42f953c30fSAndre Przywara void sunxi_turn_off_soc(uint16_t socid)
43f953c30fSAndre Przywara {
44f953c30fSAndre Przywara 	int i;
45f953c30fSAndre Przywara 
46f953c30fSAndre Przywara 	/** Turn off most peripherals, most importantly DRAM users. **/
47f953c30fSAndre Przywara 	/* Keep DRAM controller running for now. */
48f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x2c0, ~BIT_32(14));
49f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x60, ~BIT_32(14));
50f953c30fSAndre Przywara 	/* Contains msgbox (bit 21) and spinlock (bit 22) */
51f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2c4, 0);
52f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x64, 0);
53f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2c8, 0);
54f953c30fSAndre Przywara 	/* Keep PIO controller running for now. */
55f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x68, ~(BIT_32(5)));
56f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2d0, 0);
57f953c30fSAndre Przywara 	/* Contains UART0 (bit 16) */
58f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2d8, 0);
59f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x6c, 0);
60f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x70, 0);
61f953c30fSAndre Przywara 
62f953c30fSAndre Przywara 	/** Turn off DRAM controller. **/
63f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x2c0, BIT_32(14));
64f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x60, BIT_32(14));
65f953c30fSAndre Przywara 
66f953c30fSAndre Przywara 	/** Migrate CPU and bus clocks away from the PLLs. **/
67f953c30fSAndre Przywara 	/* AHB1: use OSC24M/1, APB1 = AHB1 / 2 */
68f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x54, 0x1000);
69f953c30fSAndre Przywara 	/* APB2: use OSC24M */
70f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x58, 0x1000000);
71f953c30fSAndre Przywara 	/* AHB2: use AHB1 clock */
72f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x5c, 0);
73f953c30fSAndre Przywara 	/* CPU: use OSC24M */
74f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x50, 0x10000);
75f953c30fSAndre Przywara 
76f953c30fSAndre Przywara 	/** Turn off PLLs. **/
77f953c30fSAndre Przywara 	for (i = 0; i < 6; i++)
78f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + i * 8, BIT(31));
79f953c30fSAndre Przywara 	switch (socid) {
80f953c30fSAndre Przywara 	case SUNXI_SOC_H5:
81f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + 0x44, BIT(31));
82f953c30fSAndre Przywara 		break;
83f953c30fSAndre Przywara 	case SUNXI_SOC_A64:
84f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + 0x2c, BIT(31));
85f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + 0x4c, BIT(31));
86f953c30fSAndre Przywara 		break;
87f953c30fSAndre Przywara 	}
88f953c30fSAndre Przywara }
897c26b6ecSIcenowy Zheng 
90eae5fe79SAndre Przywara static int rsb_init(void)
91eae5fe79SAndre Przywara {
92eae5fe79SAndre Przywara 	int ret;
93eae5fe79SAndre Przywara 
94eae5fe79SAndre Przywara 	ret = rsb_init_controller();
95eae5fe79SAndre Przywara 	if (ret)
96eae5fe79SAndre Przywara 		return ret;
97eae5fe79SAndre Przywara 
98eae5fe79SAndre Przywara 	/* Start with 400 KHz to issue the I2C->RSB switch command. */
99eae5fe79SAndre Przywara 	ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 400000);
100eae5fe79SAndre Przywara 	if (ret)
101eae5fe79SAndre Przywara 		return ret;
102eae5fe79SAndre Przywara 
103eae5fe79SAndre Przywara 	/*
104eae5fe79SAndre Przywara 	 * Initiate an I2C transaction to write 0x7c into register 0x3e,
105eae5fe79SAndre Przywara 	 * switching the PMIC to RSB mode.
106eae5fe79SAndre Przywara 	 */
107eae5fe79SAndre Przywara 	ret = rsb_set_device_mode(0x7c3e00);
108eae5fe79SAndre Przywara 	if (ret)
109eae5fe79SAndre Przywara 		return ret;
110eae5fe79SAndre Przywara 
111eae5fe79SAndre Przywara 	/* Now in RSB mode, switch to the recommended 3 MHz. */
112eae5fe79SAndre Przywara 	ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 3000000);
113eae5fe79SAndre Przywara 	if (ret)
114eae5fe79SAndre Przywara 		return ret;
115eae5fe79SAndre Przywara 
116eae5fe79SAndre Przywara 	/* Associate the 8-bit runtime address with the 12-bit bus address. */
117eae5fe79SAndre Przywara 	return rsb_assign_runtime_address(AXP803_HW_ADDR,
118eae5fe79SAndre Przywara 					  AXP803_RT_ADDR);
119eae5fe79SAndre Przywara }
120eae5fe79SAndre Przywara 
121fb4e9786SAndre Przywara static int axp_write(uint8_t reg, uint8_t val)
122fb4e9786SAndre Przywara {
123fb4e9786SAndre Przywara 	return rsb_write(AXP803_RT_ADDR, reg, val);
124fb4e9786SAndre Przywara }
125fb4e9786SAndre Przywara 
126d93eb446SAndre Przywara static int axp_clrsetbits(uint8_t reg, uint8_t clr_mask, uint8_t set_mask)
127eae5fe79SAndre Przywara {
128eae5fe79SAndre Przywara 	uint8_t regval;
129eae5fe79SAndre Przywara 	int ret;
130eae5fe79SAndre Przywara 
131eae5fe79SAndre Przywara 	ret = rsb_read(AXP803_RT_ADDR, reg);
132eae5fe79SAndre Przywara 	if (ret < 0)
133eae5fe79SAndre Przywara 		return ret;
134eae5fe79SAndre Przywara 
135d93eb446SAndre Przywara 	regval = (ret & ~clr_mask) | set_mask;
136eae5fe79SAndre Przywara 
137eae5fe79SAndre Przywara 	return rsb_write(AXP803_RT_ADDR, reg, regval);
138eae5fe79SAndre Przywara }
139eae5fe79SAndre Przywara 
140d93eb446SAndre Przywara #define axp_clrbits(reg, clr_mask) axp_clrsetbits(reg, clr_mask, 0)
141d93eb446SAndre Przywara #define axp_setbits(reg, set_mask) axp_clrsetbits(reg, 0, set_mask)
142d93eb446SAndre Przywara 
143ed80c1e2SAndre Przywara static bool should_enable_regulator(const void *fdt, int node)
144ed80c1e2SAndre Przywara {
145ed80c1e2SAndre Przywara 	if (fdt_getprop(fdt, node, "phandle", NULL) != NULL)
146ed80c1e2SAndre Przywara 		return true;
147ed80c1e2SAndre Przywara 	if (fdt_getprop(fdt, node, "regulator-always-on", NULL) != NULL)
148ed80c1e2SAndre Przywara 		return true;
149ed80c1e2SAndre Przywara 	return false;
150ed80c1e2SAndre Przywara }
151ed80c1e2SAndre Przywara 
152fb4e9786SAndre Przywara /*
153fb4e9786SAndre Przywara  * Retrieve the voltage from a given regulator DTB node.
154fb4e9786SAndre Przywara  * Both the regulator-{min,max}-microvolt properties must be present and
155fb4e9786SAndre Przywara  * have the same value. Return that value in millivolts.
156fb4e9786SAndre Przywara  */
157fb4e9786SAndre Przywara static int fdt_get_regulator_millivolt(const void *fdt, int node)
158fb4e9786SAndre Przywara {
159fb4e9786SAndre Przywara 	const fdt32_t *prop;
160fb4e9786SAndre Przywara 	uint32_t min_volt;
161fb4e9786SAndre Przywara 
162fb4e9786SAndre Przywara 	prop = fdt_getprop(fdt, node, "regulator-min-microvolt", NULL);
163fb4e9786SAndre Przywara 	if (prop == NULL)
164fb4e9786SAndre Przywara 		return -EINVAL;
165fb4e9786SAndre Przywara 	min_volt = fdt32_to_cpu(*prop);
166fb4e9786SAndre Przywara 
167fb4e9786SAndre Przywara 	prop = fdt_getprop(fdt, node, "regulator-max-microvolt", NULL);
168fb4e9786SAndre Przywara 	if (prop == NULL)
169fb4e9786SAndre Przywara 		return -EINVAL;
170fb4e9786SAndre Przywara 
171fb4e9786SAndre Przywara 	if (fdt32_to_cpu(*prop) != min_volt)
172fb4e9786SAndre Przywara 		return -EINVAL;
173fb4e9786SAndre Przywara 
174fb4e9786SAndre Przywara 	return min_volt / 1000;
175fb4e9786SAndre Przywara }
176fb4e9786SAndre Przywara 
177fb4e9786SAndre Przywara #define NO_SPLIT 0xff
178fb4e9786SAndre Przywara 
17950811682SSamuel Holland static const struct axp_regulator {
180fb4e9786SAndre Przywara 	char *dt_name;
181fb4e9786SAndre Przywara 	uint16_t min_volt;
182fb4e9786SAndre Przywara 	uint16_t max_volt;
183fb4e9786SAndre Przywara 	uint16_t step;
184fb4e9786SAndre Przywara 	unsigned char split;
185fb4e9786SAndre Przywara 	unsigned char volt_reg;
186fb4e9786SAndre Przywara 	unsigned char switch_reg;
187fb4e9786SAndre Przywara 	unsigned char switch_bit;
188fb4e9786SAndre Przywara } regulators[] = {
189a561e41bSAndre Przywara 	{"dcdc1", 1600, 3400, 100, NO_SPLIT, 0x20, 0x10, 0},
190a561e41bSAndre Przywara 	{"dcdc5",  800, 1840,  10,       32, 0x24, 0x10, 4},
191793c38f0SAndre Przywara 	{"dcdc6",  600, 1520,  10,       50, 0x25, 0x10, 5},
192fb4e9786SAndre Przywara 	{"dldo1",  700, 3300, 100, NO_SPLIT, 0x15, 0x12, 3},
193fb4e9786SAndre Przywara 	{"dldo2",  700, 4200, 100,       27, 0x16, 0x12, 4},
194fb4e9786SAndre Przywara 	{"dldo3",  700, 3300, 100, NO_SPLIT, 0x17, 0x12, 5},
195c6dc8504SStefan Mavrodiev 	{"dldo4",  700, 3300, 100, NO_SPLIT, 0x18, 0x12, 6},
196fb4e9786SAndre Przywara 	{"fldo1",  700, 1450,  50, NO_SPLIT, 0x1c, 0x13, 2},
197fb4e9786SAndre Przywara 	{}
198fb4e9786SAndre Przywara };
199fb4e9786SAndre Przywara 
200fb4e9786SAndre Przywara static int setup_regulator(const void *fdt, int node,
201fb4e9786SAndre Przywara 			   const struct axp_regulator *reg)
202fb4e9786SAndre Przywara {
203fb4e9786SAndre Przywara 	int mvolt;
204fb4e9786SAndre Przywara 	uint8_t regval;
205fb4e9786SAndre Przywara 
206fb4e9786SAndre Przywara 	if (!should_enable_regulator(fdt, node))
207fb4e9786SAndre Przywara 		return -ENOENT;
208fb4e9786SAndre Przywara 
209fb4e9786SAndre Przywara 	mvolt = fdt_get_regulator_millivolt(fdt, node);
210fb4e9786SAndre Przywara 	if (mvolt < reg->min_volt || mvolt > reg->max_volt)
211fb4e9786SAndre Przywara 		return -EINVAL;
212fb4e9786SAndre Przywara 
213fb4e9786SAndre Przywara 	regval = (mvolt / reg->step) - (reg->min_volt / reg->step);
214fb4e9786SAndre Przywara 	if (regval > reg->split)
215fb4e9786SAndre Przywara 		regval = ((regval - reg->split) / 2) + reg->split;
216fb4e9786SAndre Przywara 
217fb4e9786SAndre Przywara 	axp_write(reg->volt_reg, regval);
218fb4e9786SAndre Przywara 	if (reg->switch_reg < 0xff)
219fb4e9786SAndre Przywara 		axp_setbits(reg->switch_reg, BIT(reg->switch_bit));
220fb4e9786SAndre Przywara 
221fb4e9786SAndre Przywara 	INFO("PMIC: AXP803: %s voltage: %d.%03dV\n", reg->dt_name,
222fb4e9786SAndre Przywara 	     mvolt / 1000, mvolt % 1000);
223fb4e9786SAndre Przywara 
224fb4e9786SAndre Przywara 	return 0;
225fb4e9786SAndre Przywara }
226fb4e9786SAndre Przywara 
227ed80c1e2SAndre Przywara static void setup_axp803_rails(const void *fdt)
228ed80c1e2SAndre Przywara {
229ed80c1e2SAndre Przywara 	int node;
230ccd3ab2dSAndre Przywara 	bool dc1sw = false;
231ed80c1e2SAndre Przywara 
232ed80c1e2SAndre Przywara 	/* locate the PMIC DT node, bail out if not found */
233ed80c1e2SAndre Przywara 	node = fdt_node_offset_by_compatible(fdt, -1, "x-powers,axp803");
234c48d02baSAndre Przywara 	if (node < 0) {
235*4538c498SSamuel Holland 		WARN("PMIC: No PMIC DT node, skipping setup\n");
236ed80c1e2SAndre Przywara 		return;
237ed80c1e2SAndre Przywara 	}
238ed80c1e2SAndre Przywara 
239d93eb446SAndre Przywara 	if (fdt_getprop(fdt, node, "x-powers,drive-vbus-en", NULL)) {
240d93eb446SAndre Przywara 		axp_clrbits(0x8f, BIT(4));
241d93eb446SAndre Przywara 		axp_setbits(0x30, BIT(2));
242d93eb446SAndre Przywara 		INFO("PMIC: AXP803: Enabling DRIVEVBUS\n");
243d93eb446SAndre Przywara 	}
244ed80c1e2SAndre Przywara 
245ed80c1e2SAndre Przywara 	/* descend into the "regulators" subnode */
246c48d02baSAndre Przywara 	node = fdt_subnode_offset(fdt, node, "regulators");
247c48d02baSAndre Przywara 	if (node < 0) {
248*4538c498SSamuel Holland 		WARN("PMIC: No regulators DT node, skipping setup\n");
249c48d02baSAndre Przywara 		return;
250c48d02baSAndre Przywara 	}
251ed80c1e2SAndre Przywara 
252ed80c1e2SAndre Przywara 	/* iterate over all regulators to find used ones */
253ed80c1e2SAndre Przywara 	for (node = fdt_first_subnode(fdt, node);
254c48d02baSAndre Przywara 	     node >= 0;
255ed80c1e2SAndre Przywara 	     node = fdt_next_subnode(fdt, node)) {
25650811682SSamuel Holland 		const struct axp_regulator *reg;
257ed80c1e2SAndre Przywara 		const char *name;
258ed80c1e2SAndre Przywara 		int length;
259ed80c1e2SAndre Przywara 
260ed80c1e2SAndre Przywara 		/* We only care if it's always on or referenced. */
261ed80c1e2SAndre Przywara 		if (!should_enable_regulator(fdt, node))
262ed80c1e2SAndre Przywara 			continue;
263ed80c1e2SAndre Przywara 
264ed80c1e2SAndre Przywara 		name = fdt_get_name(fdt, node, &length);
265fb4e9786SAndre Przywara 		for (reg = regulators; reg->dt_name; reg++) {
266fb4e9786SAndre Przywara 			if (!strncmp(name, reg->dt_name, length)) {
267fb4e9786SAndre Przywara 				setup_regulator(fdt, node, reg);
268fb4e9786SAndre Przywara 				break;
269fb4e9786SAndre Przywara 			}
270fb4e9786SAndre Przywara 		}
271fb4e9786SAndre Przywara 
272ed80c1e2SAndre Przywara 		if (!strncmp(name, "dc1sw", length)) {
273ccd3ab2dSAndre Przywara 			/* Delay DC1SW enablement to avoid overheating. */
274ccd3ab2dSAndre Przywara 			dc1sw = true;
275ed80c1e2SAndre Przywara 			continue;
276ed80c1e2SAndre Przywara 		}
277ed80c1e2SAndre Przywara 	}
278*4538c498SSamuel Holland 
279ccd3ab2dSAndre Przywara 	/*
280ccd3ab2dSAndre Przywara 	 * If DLDO2 is enabled after DC1SW, the PMIC overheats and shuts
281ccd3ab2dSAndre Przywara 	 * down. So always enable DC1SW as the very last regulator.
282ccd3ab2dSAndre Przywara 	 */
283ccd3ab2dSAndre Przywara 	if (dc1sw) {
284ccd3ab2dSAndre Przywara 		INFO("PMIC: AXP803: Enabling DC1SW\n");
285ccd3ab2dSAndre Przywara 		axp_setbits(0x12, BIT(7));
286ccd3ab2dSAndre Przywara 	}
287ed80c1e2SAndre Przywara }
288ed80c1e2SAndre Przywara 
289df301601SAndre Przywara int sunxi_pmic_setup(uint16_t socid, const void *fdt)
2907c26b6ecSIcenowy Zheng {
291eae5fe79SAndre Przywara 	int ret;
292eae5fe79SAndre Przywara 
293f953c30fSAndre Przywara 	switch (socid) {
294f953c30fSAndre Przywara 	case SUNXI_SOC_H5:
295*4538c498SSamuel Holland 		NOTICE("PMIC: Assuming H5 reference regulator design\n");
296*4538c498SSamuel Holland 
2973d22228fSAndre Przywara 		pmic = REF_DESIGN_H5;
298*4538c498SSamuel Holland 
299f953c30fSAndre Przywara 		break;
300f953c30fSAndre Przywara 	case SUNXI_SOC_A64:
301f953c30fSAndre Przywara 		pmic = GENERIC_A64;
302*4538c498SSamuel Holland 
303*4538c498SSamuel Holland 		INFO("PMIC: Probing AXP803 on RSB\n");
304*4538c498SSamuel Holland 
305eae5fe79SAndre Przywara 		ret = sunxi_init_platform_r_twi(socid, true);
306eae5fe79SAndre Przywara 		if (ret)
307eae5fe79SAndre Przywara 			return ret;
308eae5fe79SAndre Przywara 
309eae5fe79SAndre Przywara 		ret = rsb_init();
310eae5fe79SAndre Przywara 		if (ret)
311eae5fe79SAndre Przywara 			return ret;
312eae5fe79SAndre Przywara 
313eae5fe79SAndre Przywara 		pmic = AXP803_RSB;
314eae5fe79SAndre Przywara 
315ed80c1e2SAndre Przywara 		if (fdt)
316ed80c1e2SAndre Przywara 			setup_axp803_rails(fdt);
317ed80c1e2SAndre Przywara 
318f953c30fSAndre Przywara 		break;
319f953c30fSAndre Przywara 	default:
320f953c30fSAndre Przywara 		return -ENODEV;
321f953c30fSAndre Przywara 	}
3227c26b6ecSIcenowy Zheng 	return 0;
3237c26b6ecSIcenowy Zheng }
3245069c1cfSIcenowy Zheng 
3255069c1cfSIcenowy Zheng void __dead2 sunxi_power_down(void)
3265069c1cfSIcenowy Zheng {
327f953c30fSAndre Przywara 	switch (pmic) {
328f953c30fSAndre Przywara 	case GENERIC_H5:
329f953c30fSAndre Przywara 		/* Turn off as many peripherals and clocks as we can. */
330f953c30fSAndre Przywara 		sunxi_turn_off_soc(SUNXI_SOC_H5);
331f953c30fSAndre Przywara 		/* Turn off the pin controller now. */
332f953c30fSAndre Przywara 		mmio_write_32(SUNXI_CCU_BASE + 0x68, 0);
333f953c30fSAndre Przywara 		break;
334f953c30fSAndre Przywara 	case GENERIC_A64:
335f953c30fSAndre Przywara 		/* Turn off as many peripherals and clocks as we can. */
336f953c30fSAndre Przywara 		sunxi_turn_off_soc(SUNXI_SOC_A64);
337f953c30fSAndre Przywara 		/* Turn off the pin controller now. */
338f953c30fSAndre Przywara 		mmio_write_32(SUNXI_CCU_BASE + 0x68, 0);
339f953c30fSAndre Przywara 		break;
3403d22228fSAndre Przywara 	case REF_DESIGN_H5:
3413d22228fSAndre Przywara 		sunxi_turn_off_soc(SUNXI_SOC_H5);
3423d22228fSAndre Przywara 
3433d22228fSAndre Przywara 		/*
3443d22228fSAndre Przywara 		 * Switch PL pins to power off the board:
3453d22228fSAndre Przywara 		 * - PL5 (VCC_IO) -> high
3463d22228fSAndre Przywara 		 * - PL8 (PWR-STB = CPU power supply) -> low
3473d22228fSAndre Przywara 		 * - PL9 (PWR-DRAM) ->low
3483d22228fSAndre Przywara 		 * - PL10 (power LED) -> low
3493d22228fSAndre Przywara 		 * Note: Clearing PL8 will reset the board, so keep it up.
3503d22228fSAndre Przywara 		 */
3513d22228fSAndre Przywara 		sunxi_set_gpio_out('L', 5, 1);
3523d22228fSAndre Przywara 		sunxi_set_gpio_out('L', 9, 0);
3533d22228fSAndre Przywara 		sunxi_set_gpio_out('L', 10, 0);
3543d22228fSAndre Przywara 
3553d22228fSAndre Przywara 		/* Turn off pin controller now. */
3563d22228fSAndre Przywara 		mmio_write_32(SUNXI_CCU_BASE + 0x68, 0);
3573d22228fSAndre Przywara 
3583d22228fSAndre Przywara 		break;
359eae5fe79SAndre Przywara 	case AXP803_RSB:
360eae5fe79SAndre Przywara 		/* (Re-)init RSB in case the rich OS has disabled it. */
361eae5fe79SAndre Przywara 		sunxi_init_platform_r_twi(SUNXI_SOC_A64, true);
362eae5fe79SAndre Przywara 		rsb_init();
363eae5fe79SAndre Przywara 
364eae5fe79SAndre Przywara 		/* Set "power disable control" bit */
365eae5fe79SAndre Przywara 		axp_setbits(0x32, BIT(7));
366eae5fe79SAndre Przywara 		break;
367f953c30fSAndre Przywara 	default:
368f953c30fSAndre Przywara 		break;
369f953c30fSAndre Przywara 	}
370f953c30fSAndre Przywara 
371f953c30fSAndre Przywara 	udelay(1000);
372f953c30fSAndre Przywara 	ERROR("PSCI: Cannot turn off system, halting.\n");
3735069c1cfSIcenowy Zheng 	wfi();
3745069c1cfSIcenowy Zheng 	panic();
3755069c1cfSIcenowy Zheng }
376