Ian Campbell | 2f1afcc | 2014-05-05 11:52:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2012 |
| 3 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 4 | * Berg Xing <bergxing@allwinnertech.com> |
| 5 | * Tom Cubie <tangliang@allwinnertech.com> |
| 6 | * |
| 7 | * Sunxi platform dram register definition. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0+ |
| 10 | */ |
| 11 | |
| 12 | #ifndef _SUNXI_DRAM_H |
| 13 | #define _SUNXI_DRAM_H |
| 14 | |
Hans de Goede | 36b2570 | 2014-12-08 13:38:21 +0100 | [diff] [blame] | 15 | #include <asm/io.h> |
Ian Campbell | 2f1afcc | 2014-05-05 11:52:25 +0100 | [diff] [blame] | 16 | #include <linux/types.h> |
| 17 | |
Hans de Goede | 5037c45 | 2014-11-02 20:31:16 +0100 | [diff] [blame] | 18 | /* dram regs definition */ |
Hans de Goede | 3152122 | 2014-10-25 20:27:23 +0200 | [diff] [blame] | 19 | #if defined(CONFIG_MACH_SUN6I) |
| 20 | #include <asm/arch/dram_sun6i.h> |
| 21 | #else |
Hans de Goede | 5037c45 | 2014-11-02 20:31:16 +0100 | [diff] [blame] | 22 | #include <asm/arch/dram_sun4i.h> |
Hans de Goede | 3152122 | 2014-10-25 20:27:23 +0200 | [diff] [blame] | 23 | #endif |
Ian Campbell | 2f1afcc | 2014-05-05 11:52:25 +0100 | [diff] [blame] | 24 | |
Hans de Goede | b29de01 | 2014-12-08 13:58:53 +0100 | [diff] [blame^] | 25 | #define MCTL_MEM_FILL_MATCH_COUNT 64 |
| 26 | |
Ian Campbell | 2f1afcc | 2014-05-05 11:52:25 +0100 | [diff] [blame] | 27 | unsigned long sunxi_dram_init(void); |
Ian Campbell | 2f1afcc | 2014-05-05 11:52:25 +0100 | [diff] [blame] | 28 | |
Hans de Goede | 36b2570 | 2014-12-08 13:38:21 +0100 | [diff] [blame] | 29 | /* |
| 30 | * Wait up to 1s for value to be set in given part of reg. |
| 31 | */ |
| 32 | static inline void mctl_await_completion(u32 *reg, u32 mask, u32 val) |
| 33 | { |
| 34 | unsigned long tmo = timer_get_us() + 1000000; |
| 35 | |
| 36 | while ((readl(reg) & mask) != val) { |
| 37 | if (timer_get_us() > tmo) |
| 38 | panic("Timeout initialising DRAM\n"); |
| 39 | } |
| 40 | } |
| 41 | |
Hans de Goede | b29de01 | 2014-12-08 13:58:53 +0100 | [diff] [blame^] | 42 | /* |
| 43 | * Fill beginning of DRAM with "random" data for mctl_mem_matches() |
| 44 | */ |
| 45 | static inline void mctl_mem_fill(void) |
| 46 | { |
| 47 | int i; |
| 48 | |
| 49 | for (i = 0; i < MCTL_MEM_FILL_MATCH_COUNT; i++) |
| 50 | writel(0xaa55aa55 + i, CONFIG_SYS_SDRAM_BASE + i * 4); |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Test if memory at offset offset matches memory at begin of DRAM |
| 55 | */ |
| 56 | static inline bool mctl_mem_matches(u32 offset) |
| 57 | { |
| 58 | int i, matches = 0; |
| 59 | |
| 60 | for (i = 0; i < MCTL_MEM_FILL_MATCH_COUNT; i++) { |
| 61 | if (readl(CONFIG_SYS_SDRAM_BASE + i * 4) == |
| 62 | readl(CONFIG_SYS_SDRAM_BASE + offset + i * 4)) |
| 63 | matches++; |
| 64 | } |
| 65 | |
| 66 | return matches == MCTL_MEM_FILL_MATCH_COUNT; |
| 67 | } |
| 68 | |
Ian Campbell | 2f1afcc | 2014-05-05 11:52:25 +0100 | [diff] [blame] | 69 | #endif /* _SUNXI_DRAM_H */ |