]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Library/MultiPlatformLib/BoardClkGens/BoardClkGens.h
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / MultiPlatformLib / BoardClkGens / BoardClkGens.h
1 /**@file
2 Clock generator setting for multiplatform.
3
4 This file includes package header files, library classes.
5
6 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
7
8 This program and the accompanying materials are licensed and made available under
9 the terms and conditions of the BSD License that accompanies this distribution.
10 The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php.
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #ifndef _BOARD_CLK_GEN_H_
19 #define _BOARD_CLK_GEN_H_
20
21 #include <PiPei.h>
22 #include <Library/HobLib.h>
23 #include <Library/IoLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/SmbusLib.h>
26 #include <Ppi/Smbus.h>
27 #include <IndustryStandard/SmBus.h>
28 #include <Guid/PlatformInfo.h>
29
30
31 #define CLOCK_GENERATOR_ADDRESS 0xd2
32
33 #define CLOCK_GENERATOR_SEETINGS_TABLET {0xB1, 0x82, 0xFF, 0xBF, 0xFF, 0x80}
34 #define CLOCK_GENERATOR_SETTINGS_MOBILE {0xB1, 0x82, 0xFF, 0xBF, 0xFF, 0x80}
35 #define CLOCK_GENERATOR_SETTINGS_DESKTOP {0xB1, 0x82, 0xFF, 0xBF, 0xFF, 0x80}
36
37 typedef enum {
38 ClockGeneratorCk410,
39 ClockGeneratorCk505,
40 ClockGeneratorMax
41 } CLOCK_GENERATOR_TYPE;
42
43 typedef struct {
44 CLOCK_GENERATOR_TYPE ClockType;
45 UINT8 ClockId;
46 UINT8 SpreadSpectrumByteOffset;
47 UINT8 SpreadSpectrumBitOffset;
48 } CLOCK_GENERATOR_DETAILS;
49
50 #define MAX_CLOCK_GENERATOR_BUFFER_LENGTH 0x20
51
52 //
53 // CK410 Definitions
54 //
55 #define CK410_GENERATOR_ID 0x65
56 #define CK410_GENERATOR_SPREAD_SPECTRUM_BYTE 1
57 #define CK410_GENERATOR_SPREAD_SPECTRUM_BIT BIT0
58 #define CK410_GENERATOR_CLOCK_FREERUN_BYTE 4
59 #define CK410_GENERATOR_CLOCK_FREERUN_BIT (BIT0 | BIT1 | BIT2)
60
61 //
62 // CK505 Definitions
63 //
64 #define VF_CK505_GENERATOR_ID 0x5
65 #define CK505_GENERATOR_ID 0x5 // Confirmed readout is 5
66 #define CK505_GENERATOR_SPREAD_SPECTRUM_BYTE 4
67 #define CK505_GENERATOR_SPREAD_SPECTRUM_BIT (BIT0 | BIT1)
68 #define CK505_GENERATOR_PERCENT_SPREAD_BYTE 1
69 #define CK505_GENERATOR_PERCENT_MASK ~(0xE)
70 #define CK505_GENERATOR_PERCENT_250_VALUE 0xC
71 #define CK505_GENERATOR_PERCENT_050_VALUE 0x4
72 #define CK505_GENERATOR_PERCENT_000_VALUE 0x2
73
74 //
75 // IDT Definitions
76 //
77 #define IDT_GENERATOR_ID_REVA 0x1 //IDT Rev A
78 #define IDTRevA_GENERATOR_SPREAD_SPECTRUM_BYTE 0
79 #define IDTRevA_GENERATOR_SPREAD_SPECTRUM_BIT BIT0
80 #define IDTRevA_GENERATOR_PERCENT_SPREAD_BYTE 5
81 #define IDTRevA_GENERATOR_PERCENT_250_VALUE 0xF
82 #define IDTRevA_GENERATOR_PERCENT_050_VALUE 0x3
83 #define IDTRevA_GENERATOR_PERCENT_000_VALUE 0xE
84 #define IDTRevA_GENERATOR_PERCENT_MASK ~(0xF)
85
86 #define IDT_GENERATOR_ID_REVB 0x11 //IDT RevB
87 #define IDT_GENERATOR_ID_REVD 0x21 //IDT RevD
88
89 //
90 // CLOCK CONTROLLER
91 // SmBus address to read DIMM SPD
92 //
93 #define SMBUS_BASE_ADDRESS 0xEFA0
94 #define SMBUS_BUS_DEV_FUNC 0x1F0300
95 #define PLATFORM_NUM_SMBUS_RSVD_ADDRESSES 4
96 #define SMBUS_ADDR_CH_A_1 0xA0
97 #define SMBUS_ADDR_CH_A_2 0xA2
98 #define SMBUS_ADDR_CH_B_1 0xA4
99 #define SMBUS_ADDR_CH_B_2 0xA6
100
101 //
102 // Bits for FWH_DEC_EN1\97Firmware Hub Decode Enable Register (LPC I/F\97D31:F0)
103 //
104 #define B_ICH_LPC_FWH_BIOS_DEC_F0 0x4000
105 #define B_ICH_LPC_FWH_BIOS_DEC_E0 0x1000
106 #define B_ICH_LPC_FWH_BIOS_DEC_E8 0x2000
107 #define B_ICH_LPC_FWH_BIOS_LEG_F 0x0080
108 #define B_ICH_LPC_FWH_BIOS_LEG_E 0x0040
109
110
111 //
112 // An arbitrary maximum length for clock generator buffers
113 //
114 #define MAX_CLOCK_GENERATOR_BUFFER_LENGTH 0x20
115
116 //
117 // SmBus Bus Device Function and Register Definitions
118 //
119 #define SMBUS_BUS_NUM 0
120 #define SMBUS_DEV_NUM 31
121 #define SMBUS_FUNC_NUM 3
122 #define SMBUS_BUS_DEV_FUNC_NUM \
123 SB_PCI_CFG_ADDRESS(SMBUS_BUS_NUM, SMBUS_DEV_NUM, SMBUS_FUNC_NUM, 0)
124
125 //
126 //ICH7: SMBus I/O Space Equates;
127 //
128 #define BIT_SLAVE_ADDR BIT00
129 #define BIT_COMMAND BIT01
130 #define BIT_DATA BIT02
131 #define BIT_COUNT BIT03
132 #define BIT_WORD BIT04
133 #define BIT_CONTROL BIT05
134 #define BIT_PEC BIT06
135 #define BIT_READ BIT07
136 #define SMBUS_IO_READ_BIT BIT00
137
138
139 #define SMB_CMD_QUICK 0x00
140 #define SMB_CMD_BYTE 0x04
141 #define SMB_CMD_BYTE_DATA 0x08
142 #define SMB_CMD_WORD_DATA 0x0C
143 #define SMB_CMD_PROCESS_CALL 0x10
144 #define SMB_CMD_BLOCK 0x14
145 #define SMB_CMD_I2C_READ 0x18
146 #define SMB_CMD_RESERVED 0x1c
147
148 #define HST_STS_BYTE_DONE 0x80
149 #define SMB_HST_STS 0x000
150 #define SMB_HST_CNT 0x002
151 #define SMB_HST_CMD 0x003
152 #define SMB_HST_ADD 0x004
153 #define SMB_HST_DAT_0 0x005
154 #define SMB_HST_DAT_1 0x006
155 #define SMB_HST_BLK_DAT 0x007
156 #define SMB_PEC 0x008
157 #define SMB_RCV_SLVA 0x009
158 #define SMB_SLV_DAT 0x00A
159 #define SMB_AUX_STS 0x00C
160 #define SMB_AUX_CTL 0x00D
161 #define SMB_SMLINK_PIN_CTL 0x00E
162 #define SMB_SMBUS_PIN_CTL 0x00F
163 #define SMB_SLV_STS 0x010
164 #define SMB_SLV_CMD 0x011
165 #define SMB_NTFY_DADDR 0x014
166 #define SMB_NTFY_DLOW 0x016
167 #define SMB_NTFY_DHIGH 0x017
168
169 //
170 // PCI Register Definitions - use SmbusPolicyPpi->PciAddress + offset listed below
171 //
172 #define R_COMMAND 0x04 // PCI Command Register, 16bit
173 #define B_IOSE 0x01 // RW
174 #define R_BASE_ADDRESS 0x20 // PCI BAR for SMBus I/O
175 #define B_BASE_ADDRESS 0xFFE0 // RW
176 #define R_HOST_CONFIGURATION 0x40 // SMBus Host Configuration Register
177 #define B_HST_EN 0x01 // RW
178 #define B_SMB_SMI_EN 0x02 // RW
179 #define B_I2C_EN 0x04 // RW
180 //
181 // I/O Register Definitions - use SmbusPolicyPpi->BaseAddress + offset listed below
182 //
183 #define HOST_STATUS_REGISTER 0x00 // Host Status Register R/W
184 #define HST_STS_HOST_BUSY 0x01 // RO
185 #define HST_STS_INTR 0x02 // R/WC
186 #define HST_STS_DEV_ERR 0x04 // R/WC
187 #define HST_STS_BUS_ERR 0x08 // R/WC
188 #define HST_STS_FAILED 0x10 // R/WC
189 #define SMBUS_B_SMBALERT_STS 0x20 // R/WC
190 #define HST_STS_INUSE 0x40 // R/WC
191 #define SMBUS_B_BYTE_DONE_STS 0x80 // R/WC
192 #define SMBUS_B_HSTS_ALL 0xFF // R/WC
193 #define HOST_CONTROL_REGISTER 0x02 // Host Control Register R/W
194 #define HST_CNT_INTREN 0x01 // RW
195 #define HST_CNT_KILL 0x02 // RW
196 #define SMBUS_B_SMB_CMD 0x1C // RW
197 #define SMBUS_V_SMB_CMD_QUICK 0x00
198 #define SMBUS_V_SMB_CMD_BYTE 0x04
199 #define SMBUS_V_SMB_CMD_BYTE_DATA 0x08
200 #define SMBUS_V_SMB_CMD_WORD_DATA 0x0C
201 #define SMBUS_V_SMB_CMD_PROCESS_CALL 0x10
202 #define SMBUS_V_SMB_CMD_BLOCK 0x14
203 #define SMBUS_V_SMB_CMD_IIC_READ 0x18
204 #define SMBUS_B_LAST_BYTE 0x20 // WO
205 #define HST_CNT_START 0x40 // WO
206 #define HST_CNT_PEC_EN 0x80 // RW
207 #define HOST_COMMAND_REGISTER 0x03 // Host Command Register R/W
208 #define XMIT_SLAVE_ADDRESS_REGISTER 0x04 // Transmit Slave Address Register R/W
209 #define SMBUS_B_RW_SEL 0x01 // RW
210 #define SMBUS_B_ADDRESS 0xFE // RW
211 #define HOST_DATA_0_REGISTER 0x05 // Data 0 Register R/W
212 #define HOST_DATA_1_REGISTER 0x06 // Data 1 Register R/W
213 #define HOST_BLOCK_DATA_BYTE_REGISTER 0x07 // Host Block Data Register R/W
214 #define SMBUS_R_PEC 0x08 // Packet Error Check Data Register R/W
215 #define SMBUS_R_RSA 0x09 // Receive Slave Address Register R/W
216 #define SMBUS_B_SLAVE_ADDR 0x7F // RW
217 #define SMBUS_R_SD 0x0A // Receive Slave Data Register R/W
218 #define SMBUS_R_AUXS 0x0C // Auxiliary Status Register R/WC
219 #define SMBUS_B_CRCE 0x01 //R/WC
220 #define AUXILIARY_CONTROL_REGISTER 0x0D // Auxiliary Control Register R/W
221 #define SMBUS_B_AAC 0x01 //R/W
222 #define SMBUS_B_E32B 0x02 //R/W
223 #define SMBUS_R_SMLC 0x0E // SMLINK Pin Control Register R/W
224 #define SMBUS_B_SMLINK0_CUR_STS 0x01 // RO
225 #define SMBUS_B_SMLINK1_CUR_STS 0x02 // RO
226 #define SMBUS_B_SMLINK_CLK_CTL 0x04 // RW
227 #define SMBUS_R_SMBC 0x0F // SMBus Pin Control Register R/W
228 #define SMBUS_B_SMBCLK_CUR_STS 0x01 // RO
229 #define SMBUS_B_SMBDATA_CUR_STS 0x02 // RO
230 #define SMBUS_B_SMBCLK_CTL 0x04 // RW
231 #define SMBUS_R_SSTS 0x10 // Slave Status Register R/WC
232 #define SMBUS_B_HOST_NOTIFY_STS 0x01 // R/WC
233 #define SMBUS_R_SCMD 0x11 // Slave Command Register R/W
234 #define SMBUS_B_HOST_NOTIFY_INTREN 0x01 // R/W
235 #define SMBUS_B_HOST_NOTIFY_WKEN 0x02 // R/W
236 #define SMBUS_B_SMBALERT_DIS 0x04 // R/W
237 #define SMBUS_R_NDA 0x14 // Notify Device Address Register RO
238 #define SMBUS_B_DEVICE_ADDRESS 0xFE // RO
239 #define SMBUS_R_NDLB 0x16 // Notify Data Low Byte Register RO
240 #define SMBUS_R_NDHB 0x17 // Notify Data High Byte Register RO
241 #define BUS_TRIES 3 // How many times to retry on Bus Errors
242 #define SMBUS_NUM_RESERVED 21 // Number of device addresses that are
243 // reserved by the SMBus spec.
244 #define SMBUS_ADDRESS_ARP 0xC2 >> 1
245 #define SMBUS_DATA_PREPARE_TO_ARP 0x01
246 #define SMBUS_DATA_RESET_DEVICE 0x02
247 #define SMBUS_DATA_GET_UDID_GENERAL 0x03
248 #define SMBUS_DATA_ASSIGN_ADDRESS 0x04
249 #define SMBUS_GET_UDID_LENGTH 17 // 16 byte UDID + 1 byte address
250
251
252 EFI_STATUS
253 ConfigurePlatformClocks (
254 IN EFI_PEI_SERVICES **PeiServices,
255 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
256 IN VOID *SmbusPpi
257 );
258
259
260 #endif