blob: 4a760a9f5903da48d32aa8f69b1d7dbdb9b498da [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: Intel */
Bin Menge159cdf2015-02-05 23:42:23 +08002/*
3 * Copyright (C) 2013, Intel Corporation
4 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
5 *
6 * Ported from Intel released Quark UEFI BIOS
7 * QuarkSocPkg/QuarkNorthCluster/MemoryInit/Pei
Bin Menge159cdf2015-02-05 23:42:23 +08008 */
9
10#ifndef _MRC_UTIL_H_
11#define _MRC_UTIL_H_
12
13/* Turn on this macro to enable MRC debugging output */
14#undef MRC_DEBUG
15
16/* MRC Debug Support */
17#define DPF debug_cond
18
19/* debug print type */
20
21#ifdef MRC_DEBUG
22#define D_ERROR 0x0001
23#define D_INFO 0x0002
24#define D_REGRD 0x0004
25#define D_REGWR 0x0008
26#define D_FCALL 0x0010
27#define D_TRN 0x0020
28#define D_TIME 0x0040
29#else
30#define D_ERROR 0
31#define D_INFO 0
32#define D_REGRD 0
33#define D_REGWR 0
34#define D_FCALL 0
35#define D_TRN 0
36#define D_TIME 0
37#endif
38
39#define ENTERFN(...) debug_cond(D_FCALL, "<%s>\n", __func__)
40#define LEAVEFN(...) debug_cond(D_FCALL, "</%s>\n", __func__)
41#define REPORTFN(...) debug_cond(D_FCALL, "<%s/>\n", __func__)
42
Bin Menge159cdf2015-02-05 23:42:23 +080043/* Message Bus Port */
44#define MEM_CTLR 0x01
45#define HOST_BRIDGE 0x03
46#define MEM_MGR 0x05
47#define HTE 0x11
48#define DDRPHY 0x12
49
50/* number of sample points */
51#define SAMPLE_CNT 3
52/* number of PIs to increment per sample */
53#define SAMPLE_DLY 26
54
55enum {
56 /* indicates to decrease delays when looking for edge */
57 BACKWARD,
58 /* indicates to increase delays when looking for edge */
59 FORWARD
60};
61
62enum {
63 RCVN,
64 WDQS,
65 WDQX,
66 RDQS,
67 VREF,
68 WCMD,
69 WCTL,
70 WCLK,
71 MAX_ALGOS,
72};
73
74void mrc_write_mask(u32 unit, u32 addr, u32 data, u32 mask);
75void mrc_alt_write_mask(u32 unit, u32 addr, u32 data, u32 mask);
76void mrc_post_code(uint8_t major, uint8_t minor);
77void delay_n(uint32_t ns);
78void delay_u(uint32_t ms);
79void select_mem_mgr(void);
80void select_hte(void);
81void dram_init_command(uint32_t data);
82void dram_wake_command(void);
83void training_message(uint8_t channel, uint8_t rank, uint8_t byte_lane);
84
85void set_rcvn(uint8_t channel, uint8_t rank,
86 uint8_t byte_lane, uint32_t pi_count);
87uint32_t get_rcvn(uint8_t channel, uint8_t rank, uint8_t byte_lane);
88void set_rdqs(uint8_t channel, uint8_t rank,
89 uint8_t byte_lane, uint32_t pi_count);
90uint32_t get_rdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane);
91void set_wdqs(uint8_t channel, uint8_t rank,
92 uint8_t byte_lane, uint32_t pi_count);
93uint32_t get_wdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane);
94void set_wdq(uint8_t channel, uint8_t rank,
95 uint8_t byte_lane, uint32_t pi_count);
96uint32_t get_wdq(uint8_t channel, uint8_t rank, uint8_t byte_lane);
97void set_wcmd(uint8_t channel, uint32_t pi_count);
98uint32_t get_wcmd(uint8_t channel);
99void set_wclk(uint8_t channel, uint8_t rank, uint32_t pi_count);
100uint32_t get_wclk(uint8_t channel, uint8_t rank);
101void set_wctl(uint8_t channel, uint8_t rank, uint32_t pi_count);
102uint32_t get_wctl(uint8_t channel, uint8_t rank);
103void set_vref(uint8_t channel, uint8_t byte_lane, uint32_t setting);
104uint32_t get_vref(uint8_t channel, uint8_t byte_lane);
105
106uint32_t get_addr(uint8_t channel, uint8_t rank);
107uint32_t sample_dqs(struct mrc_params *mrc_params, uint8_t channel,
108 uint8_t rank, bool rcvn);
109void find_rising_edge(struct mrc_params *mrc_params, uint32_t delay[],
110 uint8_t channel, uint8_t rank, bool rcvn);
111uint32_t byte_lane_mask(struct mrc_params *mrc_params);
112uint32_t check_rw_coarse(struct mrc_params *mrc_params, uint32_t address);
113uint32_t check_bls_ex(struct mrc_params *mrc_params, uint32_t address);
114void lfsr32(uint32_t *lfsr_ptr);
115void clear_pointers(void);
116void print_timings(struct mrc_params *mrc_params);
117
118#endif /* _MRC_UTIL_H_ */