4975b8ab4e5142663175600b5c62557d5da7aac8
[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
55
56 /**
57  * GPP hot plug handler
58  *
59  *
60  * @param[in] pConfig   Southbridge configuration structure pointer.
61  * @param[in] HpPort    The hot plug port number.
62  *
63  */
64 VOID
65 sbGppHotPlugSmiProcess (
66   IN       AMDSBCFG*     pConfig,
67   IN       UINT32        HpPort
68   )
69 {
70   UINT8         FailedPort;
71
72   // First restore GPP pads if needed
73   if (pConfig->GppDynamicPowerSaving && pConfig->AlinkPhyPllPowerDown && pConfig->GppPhyPllPowerDown) {
74     rwAlink (SB_ABCFG_REGC0 | (UINT32) (ABCFG << 29), ~(UINT32) (1 << (12 + HpPort)), 0);
75     rwAlink (RC_INDXC_REG65, ~(UINT32) (0x101 << HpPort), 0);
76     SbStall (1000);
77   }
78
79   FailedPort = (UINT8) (1 << HpPort);
80   if (pConfig->GppGen2 && pConfig->GppGen2Strap) {
81     if (GppPortPollingLtssm (pConfig, FailedPort, TRUE)) {
82       sbGppForceGen1 (pConfig, FailedPort);
83       FailedPort = GppPortPollingLtssm (pConfig, FailedPort, FALSE);
84     }
85   } else {
86     sbGppForceGen1 (pConfig, FailedPort);
87     FailedPort = GppPortPollingLtssm (pConfig, FailedPort, FALSE);
88   }
89 }
90
91
92 /**
93  * GPP hot-unplug handler
94  *
95  *
96  * @param[in] pConfig   Southbridge configuration structure pointer.
97  * @param[in] HpPort    The hot plug port number.
98  *
99  */
100 VOID
101 sbGppHotUnplugSmiProcess (
102   IN       AMDSBCFG*     pConfig,
103   IN       UINT32        HpPort
104   )
105 {
106   pConfig->PORTCONFIG[HpPort].PortCfg.PortDetected = FALSE;
107
108   if (pConfig->GppGen2 && pConfig->GppGen2Strap) {
109     sbGppForceGen2 (pConfig, (UINT8) (1 << HpPort));
110   }
111
112   // 5.19.1 GPP Power Saving with Hot Unplug
113   if (pConfig->GppDynamicPowerSaving && pConfig->AlinkPhyPllPowerDown && pConfig->GppPhyPllPowerDown) {
114     rwAlink (SB_RCINDXP_REGA2 | HpPort << 24, ~(UINT32) (BIT17), BIT17);
115     rwAlink (SB_RCINDXP_REGA2 | HpPort << 24, ~(UINT32) (BIT8), BIT8);
116     rwAlink (SB_ABCFG_REGC0 | (UINT32) (ABCFG << 29), ~(UINT32) (1 << (12 + HpPort)), (1 << (12 + HpPort)));
117     rwAlink (SB_RCINDXP_REGA2 | HpPort << 24, ~(UINT32) (BIT17), 0);
118
119     // Finally re-configure GPP pads if needed
120     sbGppDynamicPowerSaving (pConfig);
121   }
122 }
123
124
125 /**
126  * SMI handler for GPP hot-plug
127  *
128  *
129  * @param[in] pConfig     Southbridge configuration structure pointer.
130  * @param[in] IsPlugged   Is a card currently plugged in the GPP port?
131  *
132  */
133 VOID
134 sbGppHotplugSmiCallback (
135   IN       AMDSBCFG* pConfig,
136   IN       BOOLEAN   IsPlugged
137   )
138 {
139   UINT32           portNum;
140   UINT32           HpPort;
141
142   if (!pConfig->GppFunctionEnable) {
143     return;
144   }
145
146   HpPort = 0xff;
147   for (portNum = 0; portNum < MAX_GPP_PORTS; portNum++) {
148     if (pConfig->PORTCONFIG[portNum].PortCfg.PortHotPlug == TRUE) {
149       HpPort = portNum;
150       break;
151     }
152   }
153   if (HpPort == 0xff) {
154     return;
155   }
156
157   if (IsPlugged) {
158     outPort80 (0x9C);
159     sbGppHotPlugSmiProcess (pConfig, HpPort);
160   } else {
161     outPort80 (0x9D);
162     sbGppHotUnplugSmiProcess (pConfig, HpPort);
163   }
164 }
165