blob: 09a758ff6e893286ae388b2450fc0a0529e0d962 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese05b0ef42013-04-09 21:06:08 +00002/*
3 * Copyright 2013 Stefan Roese <sr@denx.de>
Stefan Roese05b0ef42013-04-09 21:06:08 +00004 */
5
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06007#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +02009#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090012#include <linux/errno.h>
Stefan Roese05b0ef42013-04-09 21:06:08 +000013#include <asm/io.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020014#include <asm/mach-imx/regs-common.h>
Stefan Roese05b0ef42013-04-09 21:06:08 +000015
Ye Life96e152019-01-04 09:10:20 +000016DECLARE_GLOBAL_DATA_PTR;
17
Stefan Roese05b0ef42013-04-09 21:06:08 +000018/* 1 second delay should be plenty of time for block reset. */
19#define RESET_MAX_TIMEOUT 1000000
20
21#define MXS_BLOCK_SFTRST (1 << 31)
22#define MXS_BLOCK_CLKGATE (1 << 30)
23
24int mxs_wait_mask_set(struct mxs_register_32 *reg, uint32_t mask, unsigned
25 int timeout)
26{
27 while (--timeout) {
28 if ((readl(&reg->reg) & mask) == mask)
29 break;
30 udelay(1);
31 }
32
33 return !timeout;
34}
35
36int mxs_wait_mask_clr(struct mxs_register_32 *reg, uint32_t mask, unsigned
37 int timeout)
38{
39 while (--timeout) {
40 if ((readl(&reg->reg) & mask) == 0)
41 break;
42 udelay(1);
43 }
44
45 return !timeout;
46}
47
48int mxs_reset_block(struct mxs_register_32 *reg)
49{
50 /* Clear SFTRST */
51 writel(MXS_BLOCK_SFTRST, &reg->reg_clr);
52
53 if (mxs_wait_mask_clr(reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
54 return 1;
55
56 /* Clear CLKGATE */
57 writel(MXS_BLOCK_CLKGATE, &reg->reg_clr);
58
59 /* Set SFTRST */
60 writel(MXS_BLOCK_SFTRST, &reg->reg_set);
61
62 /* Wait for CLKGATE being set */
63 if (mxs_wait_mask_set(reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
64 return 1;
65
66 /* Clear SFTRST */
67 writel(MXS_BLOCK_SFTRST, &reg->reg_clr);
68
69 if (mxs_wait_mask_clr(reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
70 return 1;
71
72 /* Clear CLKGATE */
73 writel(MXS_BLOCK_CLKGATE, &reg->reg_clr);
74
75 if (mxs_wait_mask_clr(reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
76 return 1;
77
78 return 0;
79}