uboot/drivers/power/mt6323.c
<<
>>
Prefs
   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#include <linux/delay.h>
  10
  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
  21int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  22{
  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}
  39