aboutsummaryrefslogtreecommitdiff
path: root/drivers/power/mt6323.c
blob: 566be5f39e5da9c8931829ee480096c7ab38632b (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
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2019 Frank Wunderlich <frank-w@public-files.de>
 */

#include <common.h>
#include <command.h>
#include <asm/io.h>

#define PWRAP_BASE		0x1000d000
#define PWRAP_WACS2_CMD		0x9c

#define PWRAP_CALC(adr, wdata) ((1 << 31) | (((adr) >> 1) << 16) | (wdata))

#define MT6323_PWRC_BASE	0x8000
#define RTC_BBPU		0x0000
#define RTC_BBPU_KEY		(0x43 << 8)
#define RTC_WRTGR		0x003c

int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	u32 addr, val;

	addr = PWRAP_BASE + PWRAP_WACS2_CMD;
	val = PWRAP_CALC(MT6323_PWRC_BASE + RTC_BBPU, RTC_BBPU_KEY);
	writel(val, addr);

	mdelay(10);

	val = PWRAP_CALC(MT6323_PWRC_BASE + RTC_WRTGR, 1);
	writel(val, addr);

	// wait some time and then print error
	mdelay(10000);
	printf("Failed to power off!!!\n");
	return 1;
}