Frank Wunderlich | 06aeb74 | 2019-11-22 15:32:24 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2019 Frank Wunderlich <frank-w@public-files.de> |
| 4 | */ |
| 5 | |
Frank Wunderlich | 06aeb74 | 2019-11-22 15:32:24 +0100 | [diff] [blame] | 6 | #include <command.h> |
| 7 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 8 | #include <linux/delay.h> |
Frank Wunderlich | 06aeb74 | 2019-11-22 15:32:24 +0100 | [diff] [blame] | 9 | |
| 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 20 | int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Frank Wunderlich | 06aeb74 | 2019-11-22 15:32:24 +0100 | [diff] [blame] | 21 | { |
| 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 | } |