aboutsummaryrefslogtreecommitdiff
path: root/plat/marvell/armada/a8k/a80x0_puzzle/board/system_power.c
blob: 5147dd5192b2ebd7bf8950699eddb12371018549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (C) 2020 Sartura Ltd.
 * Author: Luka Kovacic <luka.kovacic@sartura.hr>
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 * https://spdx.org/licenses
 */

#include <armada_common.h>
#include <common/debug.h>
#include <drivers/delay_timer.h>
#include <drivers/ti/uart/uart_16550.h>
#include <drivers/console.h>
#include <plat_marvell.h>

/*****************************************************************************
 * Platform specific power off functions
 * Power off PSU / Send command to power management MCU / ...
 *****************************************************************************
 */

unsigned char add_xor_checksum(unsigned char *buf, unsigned char xor_len)
{
	unsigned char xor_sum = 0;
	unsigned int i;

	for (i = 0; i < xor_len; i++)
		xor_sum ^= buf[i];

	return xor_sum;
}

int system_power_off(void)
{
	static console_t console;

	/* WT61P803 MCU system_off_now command */
	unsigned char system_off_now[4] = { '@', 'C', '0' };
	int i, len;

	len = sizeof(system_off_now);
	system_off_now[len - 1] = add_xor_checksum(system_off_now, len);

	console_16550_register(PLAT_MARVELL_BOOT_UART_BASE + 0x100,
		PLAT_MARVELL_BOOT_UART_CLK_IN_HZ, 115200, &console);

	/* Send system_off_now to console */
	for (i = 0; i < len; i++) {
		console.putc(system_off_now[i],	&console);
		udelay(1000);
	}

	console.flush(&console);
	(void)console_unregister(&console);

	mdelay(100);

	return 0;
}