blob: b357de32358c61758e7fe75221690813855a7d71 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekf2f08642018-01-10 09:36:09 +01002/*
3 * Copyright 2018 Xilinx, Inc.
4 *
5 * Michal Simek <michal.simek@xilinx.com>
Michal Simekf2f08642018-01-10 09:36:09 +01006 */
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/psu_init_gpl.h>
10
11#define PSU_MASK_POLL_TIME 1100000
12
13int __maybe_unused mask_pollonvalue(unsigned long add, u32 mask, u32 value)
14{
15 int i = 0;
16
17 while ((__raw_readl(add) & mask) != value) {
18 if (i == PSU_MASK_POLL_TIME)
19 return 0;
20 i++;
21 }
22 return 1;
23}
24
25__weak int mask_poll(u32 add, u32 mask)
26{
27 int i = 0;
28 unsigned long addr = add;
29
30 while (!(__raw_readl(addr) & mask)) {
31 if (i == PSU_MASK_POLL_TIME)
32 return 0;
33 i++;
34 }
35 return 1;
36}
37
38__weak u32 mask_read(u32 add, u32 mask)
39{
40 unsigned long addr = add;
41
42 return __raw_readl(addr) & mask;
43}
44
45__weak void mask_delay(u32 delay)
46{
47 udelay(delay);
48}
49
50__weak void psu_mask_write(unsigned long offset, unsigned long mask,
51 unsigned long val)
52{
53 unsigned long regval = 0;
54
55 regval = readl(offset);
56 regval &= ~(mask);
57 regval |= (val & mask);
58 writel(regval, offset);
59}
60
61__weak void prog_reg(unsigned long addr, unsigned long mask,
62 unsigned long shift, unsigned long value)
63{
64 int rdata = 0;
65
66 rdata = readl(addr);
67 rdata = rdata & (~mask);
68 rdata = rdata | (value << shift);
69 writel(rdata, addr);
70}
71
72__weak int psu_init(void)
73{
74 /*
75 * This function is overridden by the one in
76 * board/xilinx/zynqmp/(platform)/psu_init_gpl.c, if it exists.
77 */
78 return -1;
79}