blob: 5b4d66359bfb6c01281cd3e50ce0b882be81ee2a [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 *
Michal Simeka8c94362023-07-10 14:35:49 +02005 * Michal Simek <michal.simek@amd.com>
Michal Simekf2f08642018-01-10 09:36:09 +01006 */
Michal Simekf2f08642018-01-10 09:36:09 +01007#include <asm/io.h>
8#include <asm/arch/psu_init_gpl.h>
Simon Glassdbd79542020-05-10 11:40:11 -06009#include <linux/delay.h>
Michal Simekf2f08642018-01-10 09:36:09 +010010
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}
Michal Simekef955012019-12-03 15:02:50 +010080
81__weak unsigned long psu_post_config_data(void)
82{
83 /*
84 * This function is overridden by the one in
85 * board/xilinx/zynqmp/(platform)/psu_init_gpl.c, if it exists.
86 */
87 return 0;
88}