blob: dd6cbcf18206573c0783d6e4397be3fb47b3e243 [file] [log] [blame]
Frank Wunderlich06aeb742019-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
Frank Wunderlich06aeb742019-11-22 15:32:24 +01006#include <command.h>
7#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -06008#include <linux/delay.h>
Frank Wunderlich06aeb742019-11-22 15:32:24 +01009
10#define PWRAP_BASE 0x1000d000
11#define PWRAP_WACS2_CMD 0x9c
12
13#define PWRAP_CALC(adr, wdata) ((1 << 31) | (((adr) >> 1) << 16) | (wdata))
14
15#define MT6323_PWRC_BASE 0x8000
16#define RTC_BBPU 0x0000
17#define RTC_BBPU_KEY (0x43 << 8)
18#define RTC_WRTGR 0x003c
19
Simon Glassed38aef2020-05-10 11:40:03 -060020int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Frank Wunderlich06aeb742019-11-22 15:32:24 +010021{
22 u32 addr, val;
23
24 addr = PWRAP_BASE + PWRAP_WACS2_CMD;
25 val = PWRAP_CALC(MT6323_PWRC_BASE + RTC_BBPU, RTC_BBPU_KEY);
26 writel(val, addr);
27
28 mdelay(10);
29
30 val = PWRAP_CALC(MT6323_PWRC_BASE + RTC_WRTGR, 1);
31 writel(val, addr);
32
33 // wait some time and then print error
34 mdelay(10000);
35 printf("Failed to power off!!!\n");
36 return 1;
37}