blob: 053a6344f5325fd4de658e7ca82be036f7fb2776 [file] [log] [blame]
Heiko Stübner2b67ba02017-02-18 19:46:32 +01001/*
2 * (C) Copyright 2015 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
Heiko Stübner0d19fbd2017-04-07 12:38:52 +020010#include <syscon.h>
Heiko Stübner2b67ba02017-02-18 19:46:32 +010011#include <sysreset.h>
12#include <asm/io.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/cru_rk3188.h>
Heiko Stübner0d19fbd2017-04-07 12:38:52 +020015#include <asm/arch/grf_rk3188.h>
Heiko Stübner2b67ba02017-02-18 19:46:32 +010016#include <asm/arch/hardware.h>
17#include <linux/err.h>
18
19int rk3188_sysreset_request(struct udevice *dev, enum sysreset_t type)
20{
21 struct rk3188_cru *cru = rockchip_get_cru();
Heiko Stübner0d19fbd2017-04-07 12:38:52 +020022 struct rk3188_grf *grf;
Heiko Stübner2b67ba02017-02-18 19:46:32 +010023
24 if (IS_ERR(cru))
25 return PTR_ERR(cru);
26 switch (type) {
27 case SYSRESET_WARM:
Heiko Stübner0d19fbd2017-04-07 12:38:52 +020028 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
29 if (IS_ERR(grf))
30 return -EPROTONOSUPPORT;
31
32 /*
33 * warm-reset keeps the remap value,
34 * so make sure it's disabled.
35 */
36 rk_clrsetreg(&grf->soc_con0,
37 NOC_REMAP_MASK << NOC_REMAP_SHIFT,
38 0 << NOC_REMAP_SHIFT);
39
Heiko Stübner2b67ba02017-02-18 19:46:32 +010040 rk_clrreg(&cru->cru_mode_con, 0xffff);
41 writel(0xeca8, &cru->cru_glb_srst_snd_value);
42 break;
43 case SYSRESET_COLD:
44 rk_clrreg(&cru->cru_mode_con, 0xffff);
45 writel(0xfdb9, &cru->cru_glb_srst_fst_value);
46 break;
47 default:
48 return -EPROTONOSUPPORT;
49 }
50
51 return -EINPROGRESS;
52}
53
54static struct sysreset_ops rk3188_sysreset = {
55 .request = rk3188_sysreset_request,
56};
57
58U_BOOT_DRIVER(sysreset_rk3188) = {
59 .name = "rk3188_sysreset",
60 .id = UCLASS_SYSRESET,
61 .ops = &rk3188_sysreset,
62};