blob: 354817a037808d6dd3692b755793fb9e9fce6e52 [file] [log] [blame]
Frank Wunderlich36b8b5d2019-11-22 15:32:24 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019 Frank Wunderlich <frank-w@public-files.de>
4 */
5
6#include <common.h>
7#include <command.h>
8#include <asm/io.h>
Simon Glassc05ed002020-05-10 11:40:11 -06009#include <linux/delay.h>
Frank Wunderlich36b8b5d2019-11-22 15:32:24 +010010
11#define PWRAP_BASE 0x1000d000
12#define PWRAP_WACS2_CMD 0x9c
13
14#define PWRAP_CALC(adr, wdata) ((1 << 31) | (((adr) >> 1) << 16) | (wdata))
15
16#define MT6323_PWRC_BASE 0x8000
17#define RTC_BBPU 0x0000
18#define RTC_BBPU_KEY (0x43 << 8)
19#define RTC_WRTGR 0x003c
20
Simon Glass09140112020-05-10 11:40:03 -060021int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Frank Wunderlich36b8b5d2019-11-22 15:32:24 +010022{
23 u32 addr, val;
24
25 addr = PWRAP_BASE + PWRAP_WACS2_CMD;
26 val = PWRAP_CALC(MT6323_PWRC_BASE + RTC_BBPU, RTC_BBPU_KEY);
27 writel(val, addr);
28
29 mdelay(10);
30
31 val = PWRAP_CALC(MT6323_PWRC_BASE + RTC_WRTGR, 1);
32 writel(val, addr);
33
34 // wait some time and then print error
35 mdelay(10000);
36 printf("Failed to power off!!!\n");
37 return 1;
38}