sigh
[coreboot.git] / src / vendorcode / amd / cimx / sb900 / GppHp.c
1 /**
2  * @file
3  *
4  * Config Southbridge GPP controller
5  *
6  * Init GPP features.
7  *
8  * @xrefitem bom "File Content Label" "Release Content"
9  * @e project:      CIMx-SB
10  * @e sub-project
11  * @e \$Revision:$   @e \$Date:$
12  *
13  */
14 /*
15 *****************************************************************************
16 *
17 * Copyright (c) 2011, Advanced Micro Devices, Inc.
18 * All rights reserved.
19
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are met:
22 *     * Redistributions of source code must retain the above copyright
23 *       notice, this list of conditions and the following disclaimer.
24 *     * Redistributions in binary form must reproduce the above copyright
25 *       notice, this list of conditions and the following disclaimer in the
26 *       documentation and/or other materials provided with the distribution.
27 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of 
28 *       its contributors may be used to endorse or promote products derived 
29 *       from this software without specific prior written permission.
30
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
42 ****************************************************************************
43 */
44 #include "SbPlatform.h"
45 #include "cbtypes.h"
46
47 //
48 // Declaration of external functions
49 //
50 VOID  sbGppDynamicPowerSaving (IN AMDSBCFG* pConfig );
51 VOID  sbGppForceGen1 (IN AMDSBCFG* pConfig, IN CONST UINT8 ActivePorts);
52 VOID  sbGppForceGen2 (IN AMDSBCFG* pConfig, IN CONST UINT8 ActivePorts);
53 UINT8 GppPortPollingLtssm (IN AMDSBCFG* pConfig, IN UINT8 ActivePorts, IN BOOLEAN IsGen2);
54 VOID SbStall (IN UINT32 uSec);
55 VOID outPort80 (IN UINT32 pcode);
56
57 // wtf Declaration ...
58 VOID sbGppHotPlugSmiProcess (IN AMDSBCFG* pConfig, IN UINT32 HpPort);
59 VOID sbGppHotUnplugSmiProcess (IN AMDSBCFG* pConfig, IN UINT32 HpPort);
60 VOID sbGppHotplugSmiCallback (IN AMDSBCFG* pConfig, IN BOOLEAN IsPlugged);
61
62 /**
63  * GPP hot plug handler
64  *
65  *
66  * @param[in] pConfig   Southbridge configuration structure pointer.
67  * @param[in] HpPort    The hot plug port number.
68  *
69  */
70
71 VOID sbGppHotPlugSmiProcess (
72   IN       AMDSBCFG*     pConfig,
73   IN       UINT32        HpPort
74   )
75 {
76   UINT8         FailedPort;
77
78   // First restore GPP pads if needed
79   if (pConfig->GppDynamicPowerSaving && pConfig->AlinkPhyPllPowerDown && pConfig->GppPhyPllPowerDown) {
80     rwAlink (SB_ABCFG_REGC0 | (UINT32) (ABCFG << 29), ~(UINT32) (1 << (12 + HpPort)), 0);
81     rwAlink (RC_INDXC_REG65, ~(UINT32) (0x101 << HpPort), 0);
82     SbStall (1000);
83   }
84
85   FailedPort = (UINT8) (1 << HpPort);
86   if (pConfig->GppGen2 && pConfig->GppGen2Strap) {
87     if (GppPortPollingLtssm (pConfig, FailedPort, TRUE)) {
88       sbGppForceGen1 (pConfig, FailedPort);
89       FailedPort = GppPortPollingLtssm (pConfig, FailedPort, FALSE);
90     }
91   } else {
92     sbGppForceGen1 (pConfig, FailedPort);
93     FailedPort = GppPortPollingLtssm (pConfig, FailedPort, FALSE);
94   }
95 }
96
97
98 /**
99  * GPP hot-unplug handler
100  *
101  *
102  * @param[in] pConfig   Southbridge configuration structure pointer.
103  * @param[in] HpPort    The hot plug port number.
104  *
105  */
106 VOID
107 sbGppHotUnplugSmiProcess (
108   IN       AMDSBCFG*     pConfig,
109   IN       UINT32        HpPort
110   )
111 {
112   pConfig->PORTCONFIG[HpPort].PortCfg.PortDetected = FALSE;
113
114   if (pConfig->GppGen2 && pConfig->GppGen2Strap) {
115     sbGppForceGen2 (pConfig, (UINT8) (1 << HpPort));
116   }
117
118   // 5.19.1 GPP Power Saving with Hot Unplug
119   if (pConfig->GppDynamicPowerSaving && pConfig->AlinkPhyPllPowerDown && pConfig->GppPhyPllPowerDown) {
120     rwAlink (SB_RCINDXP_REGA2 | HpPort << 24, ~(UINT32) (BIT17), BIT17);
121     rwAlink (SB_RCINDXP_REGA2 | HpPort << 24, ~(UINT32) (BIT8), BIT8);
122     rwAlink (SB_ABCFG_REGC0 | (UINT32) (ABCFG << 29), ~(UINT32) (1 << (12 + HpPort)), (1 << (12 + HpPort)));
123     rwAlink (SB_RCINDXP_REGA2 | HpPort << 24, ~(UINT32) (BIT17), 0);
124
125     // Finally re-configure GPP pads if needed
126     sbGppDynamicPowerSaving (pConfig);
127   }
128 }
129
130
131 /**
132  * SMI handler for GPP hot-plug
133  *
134  *
135  * @param[in] pConfig     Southbridge configuration structure pointer.
136  * @param[in] IsPlugged   Is a card currently plugged in the GPP port?
137  *
138  */
139 VOID
140 sbGppHotplugSmiCallback (
141   IN       AMDSBCFG* pConfig,
142   IN       BOOLEAN   IsPlugged
143   )
144 {
145   UINT32           portNum;
146   UINT32           HpPort;
147
148   if (!pConfig->GppFunctionEnable) {
149     return;
150   }
151
152   HpPort = 0xff;
153   for (portNum = 0; portNum < MAX_GPP_PORTS; portNum++) {
154     if (pConfig->PORTCONFIG[portNum].PortCfg.PortHotPlug == TRUE) {
155       HpPort = portNum;
156       break;
157     }
158   }
159   if (HpPort == 0xff) {
160     return;
161   }
162
163   if (IsPlugged) {
164     outPort80 (0x9C);
165     sbGppHotPlugSmiProcess (pConfig, HpPort);
166   } else {
167     outPort80 (0x9D);
168     sbGppHotUnplugSmiProcess (pConfig, HpPort);
169   }
170 }
171