Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 4 | #include <device/pci_def.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 5 | #include <spd.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 6 | |
Elyes HAOUAS | a1e22b8 | 2019-03-18 22:49:36 +0100 | [diff] [blame] | 7 | #include "delay.h" |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 8 | #include "gm45.h" |
| 9 | |
| 10 | void raminit_thermal(const sysinfo_t *sysinfo) |
| 11 | { |
| 12 | const mem_clock_t freq = sysinfo->selected_timings.mem_clock; |
| 13 | int x; |
| 14 | FOR_EACH_POPULATED_CHANNEL(sysinfo->dimms, x) { |
| 15 | const chip_width_t width = sysinfo->dimms[x].chip_width; |
| 16 | const chip_capacity_t size = sysinfo->dimms[x].chip_capacity; |
| 17 | if ((freq == MEM_CLOCK_1067MT) && (width == CHIP_WIDTH_x16)) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 18 | mchbar_write32(CxDTPEW(x), 0x0d0b0403); |
| 19 | mchbar_write32(CxDTPEW(x) + 4, 0x060d); |
| 20 | mchbar_write32(CxDTAEW(x), 0x2d0b221a); |
| 21 | mchbar_write32(CxDTAEW(x) + 4, 0xc779956e); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 22 | } else |
| 23 | if ((freq == MEM_CLOCK_1067MT) && (width == CHIP_WIDTH_x8)) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 24 | mchbar_write32(CxDTPEW(x), 0x06040101); |
| 25 | mchbar_write32(CxDTPEW(x) + 4, 0x0506); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 26 | if (size == CHIP_CAP_2G) |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 27 | mchbar_write32(CxDTAEW(x), 0xa1071416); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 28 | else |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 29 | mchbar_write32(CxDTAEW(x), 0x1a071416); |
| 30 | mchbar_write32(CxDTAEW(x) + 4, 0x7246643f); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 31 | } else |
| 32 | if ((freq == MEM_CLOCK_800MT) && (width == CHIP_WIDTH_x16)) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 33 | mchbar_write32(CxDTPEW(x), 0x06030100); |
| 34 | mchbar_write32(CxDTPEW(x) + 4, 0x0506); |
| 35 | mchbar_write32(CxDTAEW(x), 0x3e081714); |
| 36 | mchbar_write32(CxDTAEW(x) + 4, 0xbb79a171); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 37 | } else |
| 38 | if ((freq == MEM_CLOCK_800MT) && (width == CHIP_WIDTH_x8)) { |
| 39 | if (size <= CHIP_CAP_512M) |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 40 | mchbar_write32(CxDTPEW(x), 0x05050101); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 41 | else |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 42 | mchbar_write32(CxDTPEW(x), 0x05060101); |
| 43 | mchbar_write32(CxDTPEW(x) + 4, 0x0503); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 44 | if (size == CHIP_CAP_2G) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 45 | mchbar_write32(CxDTAEW(x), 0x57051010); |
| 46 | mchbar_write32(CxDTAEW(x) + 4, 0x5fd15dde); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 47 | } else |
| 48 | if (size == CHIP_CAP_1G) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 49 | mchbar_write32(CxDTAEW(x), 0x3306130e); |
| 50 | mchbar_write32(CxDTAEW(x) + 4, 0x5763485d); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 51 | } else |
| 52 | if (size <= CHIP_CAP_512M) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 53 | mchbar_write32(CxDTAEW(x), 0x1e08170d); |
| 54 | mchbar_write32(CxDTAEW(x) + 4, 0x502f3827); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 55 | } |
| 56 | } else |
| 57 | if ((freq == MEM_CLOCK_667MT) && (width == CHIP_WIDTH_x16)) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 58 | mchbar_write32(CxDTPEW(x), 0x02000000); |
| 59 | mchbar_write32(CxDTPEW(x) + 4, 0x0402); |
| 60 | mchbar_write32(CxDTAEW(x), 0x46061111); |
| 61 | mchbar_write32(CxDTAEW(x) + 4, 0xb579a772); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 62 | } else |
| 63 | if ((freq == MEM_CLOCK_667MT) && (width == CHIP_WIDTH_x8)) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 64 | mchbar_write32(CxDTPEW(x), 0x04070101); |
| 65 | mchbar_write32(CxDTPEW(x) + 4, 0x0501); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 66 | if (size == CHIP_CAP_2G) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 67 | mchbar_write32(CxDTAEW(x), 0x32040e0d); |
| 68 | mchbar_write32(CxDTAEW(x) + 4, 0x55ff59ff); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 69 | } else |
| 70 | if (size == CHIP_CAP_1G) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 71 | mchbar_write32(CxDTAEW(x), 0x3f05120a); |
| 72 | mchbar_write32(CxDTAEW(x) + 4, 0x49713a6c); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 73 | } else |
| 74 | if (size <= CHIP_CAP_512M) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 75 | mchbar_write32(CxDTAEW(x), 0x20081808); |
| 76 | mchbar_write32(CxDTAEW(x) + 4, 0x3f23221b); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | /* also L-Shaped */ |
| 81 | if (sysinfo->selected_timings.channel_mode == |
| 82 | CHANNEL_MODE_DUAL_INTERLEAVED) { |
| 83 | if (freq == MEM_CLOCK_1067MT) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 84 | mchbar_write32(CxGTEW(x), 0xc8f81717); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 85 | } else |
| 86 | if (freq == MEM_CLOCK_800MT) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 87 | mchbar_write32(CxGTEW(x), 0x96ba1717); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 88 | } else |
| 89 | if (freq == MEM_CLOCK_667MT) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 90 | mchbar_write32(CxGTEW(x), 0x7d9b1717); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 91 | } |
| 92 | } else { |
| 93 | if (freq == MEM_CLOCK_1067MT) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 94 | mchbar_write32(CxGTEW(x), 0x53661717); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 95 | } else |
| 96 | if (freq == MEM_CLOCK_800MT) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 97 | mchbar_write32(CxGTEW(x), 0x886e1717); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 98 | } else |
| 99 | if (freq == MEM_CLOCK_667MT) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 100 | mchbar_write32(CxGTEW(x), 0x38621717); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // always? |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 106 | mchbar_write32(CxDTC(0), 0x00004020); |
| 107 | mchbar_write32(CxDTC(1), 0x00004020); |
| 108 | mchbar_write32(CxGTC(0), 0x00304848); |
| 109 | mchbar_write32(CxGTC(1), 0x00304848); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 110 | |
| 111 | /* enable thermal sensors */ |
| 112 | u32 tmp; |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 113 | tmp = mchbar_read32(0x1290) & 0xfff8; |
| 114 | mchbar_write32(0x1290, tmp | 0xa4810007); |
| 115 | tmp = mchbar_read32(0x1390) & 0xfff8; |
| 116 | mchbar_write32(0x1390, tmp | 0xa4810007); |
| 117 | tmp = mchbar_read32(0x12b4) & 0xfff8; |
| 118 | mchbar_write32(0x12b4, tmp | 0xa2810007); |
| 119 | tmp = mchbar_read32(0x13b4) & 0xfff8; |
| 120 | mchbar_write32(0x13b4, tmp | 0xa2810007); |
| 121 | mchbar_write8(0x1070, 1); |
| 122 | mchbar_write8(0x1080, 6); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 123 | if (sysinfo->gfx_type == GMCH_PM45) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 124 | mchbar_write16(0x1001, 0); |
| 125 | mchbar_write8(0x1007, 0); |
| 126 | mchbar_write32(0x1010, 0); |
| 127 | mchbar_write32(0x1014, 0); |
| 128 | mchbar_write8(0x101c, 0x98); |
| 129 | mchbar_write16(0x1041, 0x9200); |
| 130 | mchbar_write8(0x1047, 0); |
| 131 | mchbar_write32(0x1050, 0x2309); |
| 132 | mchbar_write32(0x1054, 0); |
| 133 | mchbar_write8(0x105c, 0x98); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 134 | } else { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 135 | mchbar_write16(0x1001, 0x9200); |
| 136 | mchbar_write8(0x1007, 0); |
| 137 | mchbar_write32(0x1010, 0x2309); |
| 138 | mchbar_write32(0x1014, 0); |
| 139 | mchbar_write8(0x101c, 0x98); |
| 140 | mchbar_write16(0x1041, 0); |
| 141 | mchbar_write8(0x1047, 0); |
| 142 | mchbar_write32(0x1050, 0); |
| 143 | mchbar_write32(0x1054, 0); |
| 144 | mchbar_write8(0x105c, 0x98); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 147 | mchbar_setbits32(0x1010, 1 << 31); |
| 148 | mchbar_setbits32(0x1050, 1 << 31); |
| 149 | mchbar_setbits32(CxGTC(0), 1 << 31); |
| 150 | mchbar_setbits32(CxGTC(1), 1 << 31); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 151 | |
| 152 | if (sysinfo->gs45_low_power_mode) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 153 | mchbar_write32(0x11b0, 0xa000083a); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 154 | } else if (sysinfo->gfx_type == GMCH_GM49) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 155 | mchbar_write32(0x11b0, 0x2000383a); |
| 156 | mchbar_clrbits16(0x1190, 1 << 15); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 157 | } else if ((sysinfo->gfx_type != GMCH_PM45) && |
| 158 | (sysinfo->gfx_type != GMCH_UNKNOWN)) { |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 159 | mchbar_write32(0x11b0, 0xa000383a); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | switch (sysinfo->selected_timings.fsb_clock) { |
Felix Singer | 893d77e | 2023-12-08 11:00:26 +0100 | [diff] [blame] | 163 | case FSB_CLOCK_667MHz: |
| 164 | mchbar_write32(0x11d0, 0x0fd88000); |
| 165 | break; |
| 166 | case FSB_CLOCK_800MHz: |
| 167 | mchbar_write32(0x11d0, 0x1303c000); |
| 168 | break; |
| 169 | case FSB_CLOCK_1067MHz: |
| 170 | mchbar_write32(0x11d0, 0x194a0000); |
| 171 | break; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 172 | } |
Angel Pons | 3f1f8ef | 2021-03-27 13:52:43 +0100 | [diff] [blame] | 173 | tmp = mchbar_read32(0x11d4) & ~0x1f; |
| 174 | mchbar_write32(0x11d4, tmp | 4); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 175 | } |