638122d943f17174c00660ac3dca75352093ea5a
[coreboot.git] / src / northbridge / amd / lx / pll_reset.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 static void pll_reset(char manualconf)
22 {
23         msr_t msrGlcpSysRstpll;
24
25         msrGlcpSysRstpll = rdmsr(GLCP_SYS_RSTPLL);
26
27         print_debug("_MSR GLCP_SYS_RSTPLL (");
28         print_debug_hex32(GLCP_SYS_RSTPLL);
29         print_debug(") value is: ");
30         print_debug_hex32(msrGlcpSysRstpll.hi);
31         print_debug(":");
32         print_debug_hex32(msrGlcpSysRstpll.lo);
33         print_debug("\n");
34         POST_CODE(POST_PLL_INIT);
35
36         if (!(msrGlcpSysRstpll.lo & (1 << RSTPLL_LOWER_SWFLAGS_SHIFT))) {
37                 print_debug("Configuring PLL\n");
38                 if (manualconf) {
39                         POST_CODE(POST_PLL_MANUAL);
40                         /* CPU and GLIU mult/div (GLMC_CLK = GLIU_CLK / 2)  */
41                         msrGlcpSysRstpll.hi = PLLMSRhi;
42
43                         /* Hold Count - how long we will sit in reset */
44                         msrGlcpSysRstpll.lo = PLLMSRlo;
45                 } else {
46                         /*automatic configuration (straps) */
47                         POST_CODE(POST_PLL_STRAP);
48                         msrGlcpSysRstpll.lo &=
49                             ~(0xFF << RSTPPL_LOWER_HOLD_COUNT_SHIFT);
50                         msrGlcpSysRstpll.lo |=
51                             (0xDE << RSTPPL_LOWER_HOLD_COUNT_SHIFT);
52                         msrGlcpSysRstpll.lo &=
53                             ~(RSTPPL_LOWER_COREBYPASS_SET |
54                               RSTPPL_LOWER_MBBYPASS_SET);
55                         msrGlcpSysRstpll.lo |=
56                             RSTPPL_LOWER_COREPD_SET | RSTPPL_LOWER_CLPD_SET;
57                 }
58                 /* Use SWFLAGS to remember: "we've already been here"  */
59                 msrGlcpSysRstpll.lo |= (1 << RSTPLL_LOWER_SWFLAGS_SHIFT);
60
61                 /* "reset the chip" value */
62                 msrGlcpSysRstpll.lo |= RSTPPL_LOWER_CHIP_RESET_SET;
63                 wrmsr(GLCP_SYS_RSTPLL, msrGlcpSysRstpll);
64
65                 /*      You should never get here..... The chip has reset. */
66                 print_debug("CONFIGURING PLL FAILURE\n");
67                 POST_CODE(POST_PLL_RESET_FAIL);
68                 __asm__ __volatile__("hlt\n");
69
70         }
71         print_debug("Done pll_reset\r\n");
72         return;
73 }
74
75 static unsigned int CPUSpeed(void)
76 {
77         unsigned int speed;
78         msr_t msr;
79
80         msr = rdmsr(GLCP_SYS_RSTPLL);
81         speed = ((((msr.hi >> RSTPLL_UPPER_CPUMULT_SHIFT) & 0x1F) + 1) * 333) / 10;
82         if ((((((msr.hi >> RSTPLL_UPPER_CPUMULT_SHIFT) & 0x1F) + 1) * 333) % 10) > 5) {
83                 ++speed;
84         }
85         return (speed);
86 }
87 static unsigned int GeodeLinkSpeed(void)
88 {
89         unsigned int speed;
90         msr_t msr;
91
92         msr = rdmsr(GLCP_SYS_RSTPLL);
93         speed = ((((msr.hi >> RSTPLL_UPPER_GLMULT_SHIFT) & 0x1F) + 1) * 333) / 10;
94         if ((((((msr.hi >> RSTPLL_UPPER_GLMULT_SHIFT) & 0x1F) + 1) * 333) % 10) > 5) {
95                 ++speed;
96         }
97         return (speed);
98 }
99 static unsigned int PCISpeed(void)
100 {
101         msr_t msr;
102
103         msr = rdmsr(GLCP_SYS_RSTPLL);
104         if (msr.hi & (1 << RSTPPL_LOWER_PCISPEED_SHIFT)) {
105                 return (66);
106         } else {
107                 return (33);
108         }
109 }