Angel Pons | 1c505f8 | 2020-11-11 20:55:35 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <commonlib/helpers.h> |
| 4 | #include <console/console.h> |
| 5 | #include <delay.h> |
| 6 | #include <types.h> |
| 7 | |
| 8 | #include "raminit_native.h" |
| 9 | #include "raminit_common.h" |
| 10 | #include "raminit_tables.h" |
| 11 | #include "sandybridge.h" |
| 12 | |
| 13 | /* FIXME: no support for 3-channel chipsets */ |
| 14 | |
| 15 | /* Number of programmed IOSAV subsequences. */ |
| 16 | static unsigned int ssq_count = 0; |
| 17 | |
Angel Pons | 8f0757e | 2020-11-11 23:03:36 +0100 | [diff] [blame] | 18 | void iosav_write_sequence(const int ch, const struct iosav_ssq *seq, const unsigned int length) |
Angel Pons | 1c505f8 | 2020-11-11 20:55:35 +0100 | [diff] [blame] | 19 | { |
Angel Pons | 8f0757e | 2020-11-11 23:03:36 +0100 | [diff] [blame] | 20 | for (unsigned int i = 0; i < length; i++) { |
| 21 | MCHBAR32(IOSAV_n_SP_CMD_CTRL_ch(ch, i)) = seq[i].sp_cmd_ctrl.raw; |
| 22 | MCHBAR32(IOSAV_n_SUBSEQ_CTRL_ch(ch, i)) = seq[i].subseq_ctrl.raw; |
| 23 | MCHBAR32(IOSAV_n_SP_CMD_ADDR_ch(ch, i)) = seq[i].sp_cmd_addr.raw; |
| 24 | MCHBAR32(IOSAV_n_ADDR_UPDATE_ch(ch, i)) = seq[i].addr_update.raw; |
| 25 | } |
Angel Pons | 1c505f8 | 2020-11-11 20:55:35 +0100 | [diff] [blame] | 26 | |
Angel Pons | 8f0757e | 2020-11-11 23:03:36 +0100 | [diff] [blame] | 27 | ssq_count = length; |
Angel Pons | 1c505f8 | 2020-11-11 20:55:35 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void iosav_run_queue(const int ch, const u8 loops, const u8 as_timer) |
| 31 | { |
Angel Pons | 8f0757e | 2020-11-11 23:03:36 +0100 | [diff] [blame] | 32 | /* Should never happen */ |
| 33 | if (ssq_count == 0) |
| 34 | return; |
Angel Pons | 1c505f8 | 2020-11-11 20:55:35 +0100 | [diff] [blame] | 35 | |
Angel Pons | 8f0757e | 2020-11-11 23:03:36 +0100 | [diff] [blame] | 36 | MCHBAR32(IOSAV_SEQ_CTL_ch(ch)) = loops | ((ssq_count - 1) << 18) | (as_timer << 22); |
Angel Pons | 1c505f8 | 2020-11-11 20:55:35 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void iosav_run_once(const int ch) |
| 40 | { |
| 41 | iosav_run_queue(ch, 1, 0); |
| 42 | } |
| 43 | |
| 44 | void wait_for_iosav(int channel) |
| 45 | { |
| 46 | while (1) { |
| 47 | if (MCHBAR32(IOSAV_STATUS_ch(channel)) & 0x50) |
| 48 | return; |
| 49 | } |
| 50 | } |
Angel Pons | ffd5015 | 2020-11-12 11:03:10 +0100 | [diff] [blame^] | 51 | |
| 52 | void iosav_write_zqcs_sequence(int channel, int slotrank, u32 gap, u32 post, u32 wrap) |
| 53 | { |
| 54 | const struct iosav_ssq sequence[] = ZQCS_SEQUENCE(slotrank, gap, post, wrap); |
| 55 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 56 | } |
| 57 | |
| 58 | void iosav_write_prea_sequence(int channel, int slotrank, u32 post, u32 wrap) |
| 59 | { |
| 60 | const struct iosav_ssq sequence[] = PREA_SEQUENCE(post, wrap); |
| 61 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 62 | } |
| 63 | |
| 64 | void iosav_write_read_mpr_sequence( |
| 65 | int channel, int slotrank, u32 tMOD, u32 loops, u32 gap, u32 loops2, u32 post2) |
| 66 | { |
| 67 | const struct iosav_ssq sequence[] = READ_MPR_SEQUENCE(tMOD, loops, gap, loops2, post2); |
| 68 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 69 | } |
| 70 | |
| 71 | void iosav_write_misc_write_sequence(ramctr_timing *ctrl, int channel, int slotrank, |
| 72 | u32 gap0, u32 loops0, u32 gap1, u32 loops2, u32 wrap2) |
| 73 | { |
| 74 | const struct iosav_ssq sequence[] = |
| 75 | MISC_WRITE_SEQUENCE(gap0, loops0, gap1, loops2, wrap2); |
| 76 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 77 | } |
| 78 | |
| 79 | void iosav_write_command_training_sequence( |
| 80 | ramctr_timing *ctrl, int channel, int slotrank, unsigned int address) |
| 81 | { |
| 82 | const struct iosav_ssq sequence[] = COMMAND_TRAINING_SEQUENCE(address); |
| 83 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 84 | } |
| 85 | |
| 86 | void iosav_write_data_write_sequence(ramctr_timing *ctrl, int channel, int slotrank) |
| 87 | { |
| 88 | const struct iosav_ssq sequence[] = WRITE_DATA_SEQUENCE; |
| 89 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 90 | } |
| 91 | |
| 92 | void iosav_write_aggressive_write_read_sequence(ramctr_timing *ctrl, int channel, int slotrank) |
| 93 | { |
| 94 | const struct iosav_ssq sequence[] = AGGRESSIVE_WRITE_READ_SEQUENCE; |
| 95 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 96 | } |
| 97 | |
| 98 | void iosav_write_memory_test_sequence(ramctr_timing *ctrl, int channel, int slotrank) |
| 99 | { |
| 100 | const struct iosav_ssq sequence[] = MEMORY_TEST_SEQUENCE; |
| 101 | iosav_write_sequence(channel, sequence, ARRAY_SIZE(sequence)); |
| 102 | } |