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 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | #include <asm/io.h> |
| 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 | |
| 20 | int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 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 | } |