xref: /rk3399_ARM-atf/plat/allwinner/sun50i_a64/sunxi_power.c (revision d93eb4467a0ca09d359f242b19f584a58e4e805b)
17c26b6ecSIcenowy Zheng /*
27c26b6ecSIcenowy Zheng  * Copyright (c) 2017-2018, 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 
8eae5fe79SAndre Przywara #include <allwinner/sunxi_rsb.h>
95069c1cfSIcenowy Zheng #include <arch_helpers.h>
107c26b6ecSIcenowy Zheng #include <debug.h>
11f953c30fSAndre Przywara #include <delay_timer.h>
12f953c30fSAndre Przywara #include <errno.h>
13ed80c1e2SAndre Przywara #include <libfdt.h>
14f953c30fSAndre Przywara #include <mmio.h>
15f953c30fSAndre Przywara #include <platform_def.h>
16f953c30fSAndre Przywara #include <sunxi_def.h>
17f953c30fSAndre Przywara #include <sunxi_mmap.h>
184ec1a239SAndre Przywara #include <sunxi_private.h>
19f953c30fSAndre Przywara 
20f953c30fSAndre Przywara static enum pmic_type {
21f953c30fSAndre Przywara 	GENERIC_H5,
22f953c30fSAndre Przywara 	GENERIC_A64,
233d22228fSAndre Przywara 	REF_DESIGN_H5,	/* regulators controlled by GPIO pins on port L */
24eae5fe79SAndre Przywara 	AXP803_RSB,	/* PMIC connected via RSB on most A64 boards */
25f953c30fSAndre Przywara } pmic;
26f953c30fSAndre Przywara 
27eae5fe79SAndre Przywara #define AXP803_HW_ADDR	0x3a3
28eae5fe79SAndre Przywara #define AXP803_RT_ADDR	0x2d
29eae5fe79SAndre Przywara 
30f953c30fSAndre Przywara /*
31f953c30fSAndre Przywara  * On boards without a proper PMIC we struggle to turn off the system properly.
32f953c30fSAndre Przywara  * Try to turn off as much off the system as we can, to reduce power
33f953c30fSAndre Przywara  * consumption. This should be entered with only one core running and SMP
34f953c30fSAndre Przywara  * disabled.
35f953c30fSAndre Przywara  * This function only cares about peripherals.
36f953c30fSAndre Przywara  */
37f953c30fSAndre Przywara void sunxi_turn_off_soc(uint16_t socid)
38f953c30fSAndre Przywara {
39f953c30fSAndre Przywara 	int i;
40f953c30fSAndre Przywara 
41f953c30fSAndre Przywara 	/** Turn off most peripherals, most importantly DRAM users. **/
42f953c30fSAndre Przywara 	/* Keep DRAM controller running for now. */
43f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x2c0, ~BIT_32(14));
44f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x60, ~BIT_32(14));
45f953c30fSAndre Przywara 	/* Contains msgbox (bit 21) and spinlock (bit 22) */
46f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2c4, 0);
47f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x64, 0);
48f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2c8, 0);
49f953c30fSAndre Przywara 	/* Keep PIO controller running for now. */
50f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x68, ~(BIT_32(5)));
51f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2d0, 0);
52f953c30fSAndre Przywara 	/* Contains UART0 (bit 16) */
53f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x2d8, 0);
54f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x6c, 0);
55f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x70, 0);
56f953c30fSAndre Przywara 
57f953c30fSAndre Przywara 	/** Turn off DRAM controller. **/
58f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x2c0, BIT_32(14));
59f953c30fSAndre Przywara 	mmio_clrbits_32(SUNXI_CCU_BASE + 0x60, BIT_32(14));
60f953c30fSAndre Przywara 
61f953c30fSAndre Przywara 	/** Migrate CPU and bus clocks away from the PLLs. **/
62f953c30fSAndre Przywara 	/* AHB1: use OSC24M/1, APB1 = AHB1 / 2 */
63f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x54, 0x1000);
64f953c30fSAndre Przywara 	/* APB2: use OSC24M */
65f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x58, 0x1000000);
66f953c30fSAndre Przywara 	/* AHB2: use AHB1 clock */
67f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x5c, 0);
68f953c30fSAndre Przywara 	/* CPU: use OSC24M */
69f953c30fSAndre Przywara 	mmio_write_32(SUNXI_CCU_BASE + 0x50, 0x10000);
70f953c30fSAndre Przywara 
71f953c30fSAndre Przywara 	/** Turn off PLLs. **/
72f953c30fSAndre Przywara 	for (i = 0; i < 6; i++)
73f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + i * 8, BIT(31));
74f953c30fSAndre Przywara 	switch (socid) {
75f953c30fSAndre Przywara 	case SUNXI_SOC_H5:
76f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + 0x44, BIT(31));
77f953c30fSAndre Przywara 		break;
78f953c30fSAndre Przywara 	case SUNXI_SOC_A64:
79f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + 0x2c, BIT(31));
80f953c30fSAndre Przywara 		mmio_clrbits_32(SUNXI_CCU_BASE + 0x4c, BIT(31));
81f953c30fSAndre Przywara 		break;
82f953c30fSAndre Przywara 	}
83f953c30fSAndre Przywara }
847c26b6ecSIcenowy Zheng 
85eae5fe79SAndre Przywara static int rsb_init(void)
86eae5fe79SAndre Przywara {
87eae5fe79SAndre Przywara 	int ret;
88eae5fe79SAndre Przywara 
89eae5fe79SAndre Przywara 	ret = rsb_init_controller();
90eae5fe79SAndre Przywara 	if (ret)
91eae5fe79SAndre Przywara 		return ret;
92eae5fe79SAndre Przywara 
93eae5fe79SAndre Przywara 	/* Start with 400 KHz to issue the I2C->RSB switch command. */
94eae5fe79SAndre Przywara 	ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 400000);
95eae5fe79SAndre Przywara 	if (ret)
96eae5fe79SAndre Przywara 		return ret;
97eae5fe79SAndre Przywara 
98eae5fe79SAndre Przywara 	/*
99eae5fe79SAndre Przywara 	 * Initiate an I2C transaction to write 0x7c into register 0x3e,
100eae5fe79SAndre Przywara 	 * switching the PMIC to RSB mode.
101eae5fe79SAndre Przywara 	 */
102eae5fe79SAndre Przywara 	ret = rsb_set_device_mode(0x7c3e00);
103eae5fe79SAndre Przywara 	if (ret)
104eae5fe79SAndre Przywara 		return ret;
105eae5fe79SAndre Przywara 
106eae5fe79SAndre Przywara 	/* Now in RSB mode, switch to the recommended 3 MHz. */
107eae5fe79SAndre Przywara 	ret = rsb_set_bus_speed(SUNXI_OSC24M_CLK_IN_HZ, 3000000);
108eae5fe79SAndre Przywara 	if (ret)
109eae5fe79SAndre Przywara 		return ret;
110eae5fe79SAndre Przywara 
111eae5fe79SAndre Przywara 	/* Associate the 8-bit runtime address with the 12-bit bus address. */
112eae5fe79SAndre Przywara 	return rsb_assign_runtime_address(AXP803_HW_ADDR,
113eae5fe79SAndre Przywara 					  AXP803_RT_ADDR);
114eae5fe79SAndre Przywara }
115eae5fe79SAndre Przywara 
116fb4e9786SAndre Przywara static int axp_write(uint8_t reg, uint8_t val)
117fb4e9786SAndre Przywara {
118fb4e9786SAndre Przywara 	return rsb_write(AXP803_RT_ADDR, reg, val);
119fb4e9786SAndre Przywara }
120fb4e9786SAndre Przywara 
121*d93eb446SAndre Przywara static int axp_clrsetbits(uint8_t reg, uint8_t clr_mask, uint8_t set_mask)
122eae5fe79SAndre Przywara {
123eae5fe79SAndre Przywara 	uint8_t regval;
124eae5fe79SAndre Przywara 	int ret;
125eae5fe79SAndre Przywara 
126eae5fe79SAndre Przywara 	ret = rsb_read(AXP803_RT_ADDR, reg);
127eae5fe79SAndre Przywara 	if (ret < 0)
128eae5fe79SAndre Przywara 		return ret;
129eae5fe79SAndre Przywara 
130*d93eb446SAndre Przywara 	regval = (ret & ~clr_mask) | set_mask;
131eae5fe79SAndre Przywara 
132eae5fe79SAndre Przywara 	return rsb_write(AXP803_RT_ADDR, reg, regval);
133eae5fe79SAndre Przywara }
134eae5fe79SAndre Przywara 
135*d93eb446SAndre Przywara #define axp_clrbits(reg, clr_mask) axp_clrsetbits(reg, clr_mask, 0)
136*d93eb446SAndre Przywara #define axp_setbits(reg, set_mask) axp_clrsetbits(reg, 0, set_mask)
137*d93eb446SAndre Przywara 
138ed80c1e2SAndre Przywara static bool should_enable_regulator(const void *fdt, int node)
139ed80c1e2SAndre Przywara {
140ed80c1e2SAndre Przywara 	if (fdt_getprop(fdt, node, "phandle", NULL) != NULL)
141ed80c1e2SAndre Przywara 		return true;
142ed80c1e2SAndre Przywara 	if (fdt_getprop(fdt, node, "regulator-always-on", NULL) != NULL)
143ed80c1e2SAndre Przywara 		return true;
144ed80c1e2SAndre Przywara 	return false;
145ed80c1e2SAndre Przywara }
146ed80c1e2SAndre Przywara 
147fb4e9786SAndre Przywara /*
148fb4e9786SAndre Przywara  * Retrieve the voltage from a given regulator DTB node.
149fb4e9786SAndre Przywara  * Both the regulator-{min,max}-microvolt properties must be present and
150fb4e9786SAndre Przywara  * have the same value. Return that value in millivolts.
151fb4e9786SAndre Przywara  */
152fb4e9786SAndre Przywara static int fdt_get_regulator_millivolt(const void *fdt, int node)
153fb4e9786SAndre Przywara {
154fb4e9786SAndre Przywara 	const fdt32_t *prop;
155fb4e9786SAndre Przywara 	uint32_t min_volt;
156fb4e9786SAndre Przywara 
157fb4e9786SAndre Przywara 	prop = fdt_getprop(fdt, node, "regulator-min-microvolt", NULL);
158fb4e9786SAndre Przywara 	if (prop == NULL)
159fb4e9786SAndre Przywara 		return -EINVAL;
160fb4e9786SAndre Przywara 	min_volt = fdt32_to_cpu(*prop);
161fb4e9786SAndre Przywara 
162fb4e9786SAndre Przywara 	prop = fdt_getprop(fdt, node, "regulator-max-microvolt", NULL);
163fb4e9786SAndre Przywara 	if (prop == NULL)
164fb4e9786SAndre Przywara 		return -EINVAL;
165fb4e9786SAndre Przywara 
166fb4e9786SAndre Przywara 	if (fdt32_to_cpu(*prop) != min_volt)
167fb4e9786SAndre Przywara 		return -EINVAL;
168fb4e9786SAndre Przywara 
169fb4e9786SAndre Przywara 	return min_volt / 1000;
170fb4e9786SAndre Przywara }
171fb4e9786SAndre Przywara 
172fb4e9786SAndre Przywara #define NO_SPLIT 0xff
173fb4e9786SAndre Przywara 
174fb4e9786SAndre Przywara struct axp_regulator {
175fb4e9786SAndre Przywara 	char *dt_name;
176fb4e9786SAndre Przywara 	uint16_t min_volt;
177fb4e9786SAndre Przywara 	uint16_t max_volt;
178fb4e9786SAndre Przywara 	uint16_t step;
179fb4e9786SAndre Przywara 	unsigned char split;
180fb4e9786SAndre Przywara 	unsigned char volt_reg;
181fb4e9786SAndre Przywara 	unsigned char switch_reg;
182fb4e9786SAndre Przywara 	unsigned char switch_bit;
183fb4e9786SAndre Przywara } regulators[] = {
184fb4e9786SAndre Przywara 	{"dcdc1", 1600, 3400, 100, NO_SPLIT, 0x20, 0xff, 9},
185fb4e9786SAndre Przywara 	{"dcdc5",  800, 1840,  10,       32, 0x24, 0xff, 9},
186fb4e9786SAndre Przywara 	{"dldo1",  700, 3300, 100, NO_SPLIT, 0x15, 0x12, 3},
187fb4e9786SAndre Przywara 	{"dldo2",  700, 4200, 100,       27, 0x16, 0x12, 4},
188fb4e9786SAndre Przywara 	{"dldo3",  700, 3300, 100, NO_SPLIT, 0x17, 0x12, 5},
189fb4e9786SAndre Przywara 	{"fldo1",  700, 1450,  50, NO_SPLIT, 0x1c, 0x13, 2},
190fb4e9786SAndre Przywara 	{}
191fb4e9786SAndre Przywara };
192fb4e9786SAndre Przywara 
193fb4e9786SAndre Przywara static int setup_regulator(const void *fdt, int node,
194fb4e9786SAndre Przywara 			   const struct axp_regulator *reg)
195fb4e9786SAndre Przywara {
196fb4e9786SAndre Przywara 	int mvolt;
197fb4e9786SAndre Przywara 	uint8_t regval;
198fb4e9786SAndre Przywara 
199fb4e9786SAndre Przywara 	if (!should_enable_regulator(fdt, node))
200fb4e9786SAndre Przywara 		return -ENOENT;
201fb4e9786SAndre Przywara 
202fb4e9786SAndre Przywara 	mvolt = fdt_get_regulator_millivolt(fdt, node);
203fb4e9786SAndre Przywara 	if (mvolt < reg->min_volt || mvolt > reg->max_volt)
204fb4e9786SAndre Przywara 		return -EINVAL;
205fb4e9786SAndre Przywara 
206fb4e9786SAndre Przywara 	regval = (mvolt / reg->step) - (reg->min_volt / reg->step);
207fb4e9786SAndre Przywara 	if (regval > reg->split)
208fb4e9786SAndre Przywara 		regval = ((regval - reg->split) / 2) + reg->split;
209fb4e9786SAndre Przywara 
210fb4e9786SAndre Przywara 	axp_write(reg->volt_reg, regval);
211fb4e9786SAndre Przywara 	if (reg->switch_reg < 0xff)
212fb4e9786SAndre Przywara 		axp_setbits(reg->switch_reg, BIT(reg->switch_bit));
213fb4e9786SAndre Przywara 
214fb4e9786SAndre Przywara 	INFO("PMIC: AXP803: %s voltage: %d.%03dV\n", reg->dt_name,
215fb4e9786SAndre Przywara 	     mvolt / 1000, mvolt % 1000);
216fb4e9786SAndre Przywara 
217fb4e9786SAndre Przywara 	return 0;
218fb4e9786SAndre Przywara }
219fb4e9786SAndre Przywara 
220ed80c1e2SAndre Przywara static void setup_axp803_rails(const void *fdt)
221ed80c1e2SAndre Przywara {
222ed80c1e2SAndre Przywara 	int node;
223ccd3ab2dSAndre Przywara 	bool dc1sw = false;
224ed80c1e2SAndre Przywara 
225ed80c1e2SAndre Przywara 	/* locate the PMIC DT node, bail out if not found */
226ed80c1e2SAndre Przywara 	node = fdt_node_offset_by_compatible(fdt, -1, "x-powers,axp803");
227ed80c1e2SAndre Przywara 	if (node == -FDT_ERR_NOTFOUND) {
228ed80c1e2SAndre Przywara 		WARN("BL31: PMIC: No AXP803 DT node, skipping initial setup.\n");
229ed80c1e2SAndre Przywara 		return;
230ed80c1e2SAndre Przywara 	}
231ed80c1e2SAndre Przywara 
232*d93eb446SAndre Przywara 	if (fdt_getprop(fdt, node, "x-powers,drive-vbus-en", NULL)) {
233*d93eb446SAndre Przywara 		axp_clrbits(0x8f, BIT(4));
234*d93eb446SAndre Przywara 		axp_setbits(0x30, BIT(2));
235*d93eb446SAndre Przywara 		INFO("PMIC: AXP803: Enabling DRIVEVBUS\n");
236*d93eb446SAndre Przywara 	}
237ed80c1e2SAndre Przywara 
238ed80c1e2SAndre Przywara 	/* descend into the "regulators" subnode */
239ed80c1e2SAndre Przywara 	node = fdt_first_subnode(fdt, node);
240ed80c1e2SAndre Przywara 
241ed80c1e2SAndre Przywara 	/* iterate over all regulators to find used ones */
242ed80c1e2SAndre Przywara 	for (node = fdt_first_subnode(fdt, node);
243ed80c1e2SAndre Przywara 	     node != -FDT_ERR_NOTFOUND;
244ed80c1e2SAndre Przywara 	     node = fdt_next_subnode(fdt, node)) {
245fb4e9786SAndre Przywara 		struct axp_regulator *reg;
246ed80c1e2SAndre Przywara 		const char *name;
247ed80c1e2SAndre Przywara 		int length;
248ed80c1e2SAndre Przywara 
249ed80c1e2SAndre Przywara 		/* We only care if it's always on or referenced. */
250ed80c1e2SAndre Przywara 		if (!should_enable_regulator(fdt, node))
251ed80c1e2SAndre Przywara 			continue;
252ed80c1e2SAndre Przywara 
253ed80c1e2SAndre Przywara 		name = fdt_get_name(fdt, node, &length);
254fb4e9786SAndre Przywara 		for (reg = regulators; reg->dt_name; reg++) {
255fb4e9786SAndre Przywara 			if (!strncmp(name, reg->dt_name, length)) {
256fb4e9786SAndre Przywara 				setup_regulator(fdt, node, reg);
257fb4e9786SAndre Przywara 				break;
258fb4e9786SAndre Przywara 			}
259fb4e9786SAndre Przywara 		}
260fb4e9786SAndre Przywara 
261ed80c1e2SAndre Przywara 		if (!strncmp(name, "dc1sw", length)) {
262ccd3ab2dSAndre Przywara 			/* Delay DC1SW enablement to avoid overheating. */
263ccd3ab2dSAndre Przywara 			dc1sw = true;
264ed80c1e2SAndre Przywara 			continue;
265ed80c1e2SAndre Przywara 		}
266ed80c1e2SAndre Przywara 	}
267ccd3ab2dSAndre Przywara 	/*
268ccd3ab2dSAndre Przywara 	 * If DLDO2 is enabled after DC1SW, the PMIC overheats and shuts
269ccd3ab2dSAndre Przywara 	 * down. So always enable DC1SW as the very last regulator.
270ccd3ab2dSAndre Przywara 	 */
271ccd3ab2dSAndre Przywara 	if (dc1sw) {
272ccd3ab2dSAndre Przywara 		INFO("PMIC: AXP803: Enabling DC1SW\n");
273ccd3ab2dSAndre Przywara 		axp_setbits(0x12, BIT(7));
274ccd3ab2dSAndre Przywara 	}
275ed80c1e2SAndre Przywara }
276ed80c1e2SAndre Przywara 
277df301601SAndre Przywara int sunxi_pmic_setup(uint16_t socid, const void *fdt)
2787c26b6ecSIcenowy Zheng {
279eae5fe79SAndre Przywara 	int ret;
280eae5fe79SAndre Przywara 
281f953c30fSAndre Przywara 	switch (socid) {
282f953c30fSAndre Przywara 	case SUNXI_SOC_H5:
2833d22228fSAndre Przywara 		pmic = REF_DESIGN_H5;
2843d22228fSAndre Przywara 		NOTICE("BL31: PMIC: Defaulting to PortL GPIO according to H5 reference design.\n");
285f953c30fSAndre Przywara 		break;
286f953c30fSAndre Przywara 	case SUNXI_SOC_A64:
287f953c30fSAndre Przywara 		pmic = GENERIC_A64;
288eae5fe79SAndre Przywara 		ret = sunxi_init_platform_r_twi(socid, true);
289eae5fe79SAndre Przywara 		if (ret)
290eae5fe79SAndre Przywara 			return ret;
291eae5fe79SAndre Przywara 
292eae5fe79SAndre Przywara 		ret = rsb_init();
293eae5fe79SAndre Przywara 		if (ret)
294eae5fe79SAndre Przywara 			return ret;
295eae5fe79SAndre Przywara 
296eae5fe79SAndre Przywara 		pmic = AXP803_RSB;
297eae5fe79SAndre Przywara 		NOTICE("BL31: PMIC: Detected AXP803 on RSB.\n");
298eae5fe79SAndre Przywara 
299ed80c1e2SAndre Przywara 		if (fdt)
300ed80c1e2SAndre Przywara 			setup_axp803_rails(fdt);
301ed80c1e2SAndre Przywara 
302f953c30fSAndre Przywara 		break;
303f953c30fSAndre Przywara 	default:
304f953c30fSAndre Przywara 		NOTICE("BL31: PMIC: No support for Allwinner %x SoC.\n", socid);
305f953c30fSAndre Przywara 		return -ENODEV;
306f953c30fSAndre Przywara 	}
3077c26b6ecSIcenowy Zheng 	return 0;
3087c26b6ecSIcenowy Zheng }
3095069c1cfSIcenowy Zheng 
3105069c1cfSIcenowy Zheng void __dead2 sunxi_power_down(void)
3115069c1cfSIcenowy Zheng {
312f953c30fSAndre Przywara 	switch (pmic) {
313f953c30fSAndre Przywara 	case GENERIC_H5:
314f953c30fSAndre Przywara 		/* Turn off as many peripherals and clocks as we can. */
315f953c30fSAndre Przywara 		sunxi_turn_off_soc(SUNXI_SOC_H5);
316f953c30fSAndre Przywara 		/* Turn off the pin controller now. */
317f953c30fSAndre Przywara 		mmio_write_32(SUNXI_CCU_BASE + 0x68, 0);
318f953c30fSAndre Przywara 		break;
319f953c30fSAndre Przywara 	case GENERIC_A64:
320f953c30fSAndre Przywara 		/* Turn off as many peripherals and clocks as we can. */
321f953c30fSAndre Przywara 		sunxi_turn_off_soc(SUNXI_SOC_A64);
322f953c30fSAndre Przywara 		/* Turn off the pin controller now. */
323f953c30fSAndre Przywara 		mmio_write_32(SUNXI_CCU_BASE + 0x68, 0);
324f953c30fSAndre Przywara 		break;
3253d22228fSAndre Przywara 	case REF_DESIGN_H5:
3263d22228fSAndre Przywara 		sunxi_turn_off_soc(SUNXI_SOC_H5);
3273d22228fSAndre Przywara 
3283d22228fSAndre Przywara 		/*
3293d22228fSAndre Przywara 		 * Switch PL pins to power off the board:
3303d22228fSAndre Przywara 		 * - PL5 (VCC_IO) -> high
3313d22228fSAndre Przywara 		 * - PL8 (PWR-STB = CPU power supply) -> low
3323d22228fSAndre Przywara 		 * - PL9 (PWR-DRAM) ->low
3333d22228fSAndre Przywara 		 * - PL10 (power LED) -> low
3343d22228fSAndre Przywara 		 * Note: Clearing PL8 will reset the board, so keep it up.
3353d22228fSAndre Przywara 		 */
3363d22228fSAndre Przywara 		sunxi_set_gpio_out('L', 5, 1);
3373d22228fSAndre Przywara 		sunxi_set_gpio_out('L', 9, 0);
3383d22228fSAndre Przywara 		sunxi_set_gpio_out('L', 10, 0);
3393d22228fSAndre Przywara 
3403d22228fSAndre Przywara 		/* Turn off pin controller now. */
3413d22228fSAndre Przywara 		mmio_write_32(SUNXI_CCU_BASE + 0x68, 0);
3423d22228fSAndre Przywara 
3433d22228fSAndre Przywara 		break;
344eae5fe79SAndre Przywara 	case AXP803_RSB:
345eae5fe79SAndre Przywara 		/* (Re-)init RSB in case the rich OS has disabled it. */
346eae5fe79SAndre Przywara 		sunxi_init_platform_r_twi(SUNXI_SOC_A64, true);
347eae5fe79SAndre Przywara 		rsb_init();
348eae5fe79SAndre Przywara 
349eae5fe79SAndre Przywara 		/* Set "power disable control" bit */
350eae5fe79SAndre Przywara 		axp_setbits(0x32, BIT(7));
351eae5fe79SAndre Przywara 		break;
352f953c30fSAndre Przywara 	default:
353f953c30fSAndre Przywara 		break;
354f953c30fSAndre Przywara 	}
355f953c30fSAndre Przywara 
356f953c30fSAndre Przywara 	udelay(1000);
357f953c30fSAndre Przywara 	ERROR("PSCI: Cannot turn off system, halting.\n");
3585069c1cfSIcenowy Zheng 	wfi();
3595069c1cfSIcenowy Zheng 	panic();
3605069c1cfSIcenowy Zheng }
361