Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | f2f0864 | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2018 Xilinx, Inc. |
| 4 | * |
Michal Simek | a8c9436 | 2023-07-10 14:35:49 +0200 | [diff] [blame] | 5 | * Michal Simek <michal.simek@amd.com> |
Michal Simek | f2f0864 | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 6 | */ |
Michal Simek | f2f0864 | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 7 | #include <asm/io.h> |
| 8 | #include <asm/arch/psu_init_gpl.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 9 | #include <linux/delay.h> |
Michal Simek | f2f0864 | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 10 | |
| 11 | #define PSU_MASK_POLL_TIME 1100000 |
| 12 | |
| 13 | int __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 Simek | ef95501 | 2019-12-03 15:02:50 +0100 | [diff] [blame] | 80 | |
| 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 | } |