3rdparty/fsp: Update submodule to upstream master
[coreboot2.git] / util / intelp2m / platforms / common / register.go
blob2aa51b92e9fa592d2a4e186f67650538b8dc0454
1 package common
3 // Bit field constants for PAD_CFG_DW0 register
4 const (
5 AllFields uint32 = 0xffffffff
7 PadRstCfgShift uint8 = 30
8 PadRstCfgMask uint32 = 0x3 << PadRstCfgShift
10 RxPadStateSelectShift uint8 = 29
11 RxPadStateSelectMask uint32 = 0x1 << RxPadStateSelectShift
13 RxRawOverrideTo1Shift uint8 = 28
14 RxRawOverrideTo1Mask uint32 = 0x1 << RxRawOverrideTo1Shift
16 RxLevelEdgeConfigurationShift uint8 = 25
17 RxLevelEdgeConfigurationMask uint32 = 0x3 << RxLevelEdgeConfigurationShift
19 RxInvertShift uint8 = 23
20 RxInvertMask uint32 = 0x1 << RxInvertShift
22 RxTxEnableConfigShift uint8 = 21
23 RxTxEnableConfigMask uint32 = 0x3 << RxTxEnableConfigShift
25 InputRouteIOxApicShift uint8 = 20
26 InputRouteIOxApicMask uint32 = 0x1 << InputRouteIOxApicShift
28 InputRouteSCIShift uint8 = 19
29 InputRouteSCIMask uint32 = 0x1 << InputRouteSCIShift
31 InputRouteSMIShift uint8 = 18
32 InputRouteSMIMask uint32 = 0x1 << InputRouteSMIShift
34 InputRouteNMIShift uint8 = 17
35 InputRouteNMIMask uint32 = 0x1 << InputRouteNMIShift
37 PadModeShift uint8 = 10
38 PadModeMask uint32 = 0x7 << PadModeShift
40 RxTxBufDisableShift uint8 = 8
41 RxTxBufDisableMask uint32 = 0x3 << RxTxBufDisableShift
43 RxStateShift uint8 = 1
44 RxStateMask uint32 = 0x1 << RxStateShift
46 TxStateMask uint32 = 0x1
49 // config DW registers
50 const (
51 PAD_CFG_DW0 = 0
52 PAD_CFG_DW1 = 1
53 MAX_DW_NUM = 2
56 // Register - configuration data structure based on DW0/1 dw value
57 // value : register value
58 // mask : bit fileds mask
59 // roFileds : read only fields mask
60 type Register struct {
61 value uint32
62 mask uint32
63 roFileds uint32
66 func (reg *Register) ValueSet(value uint32) *Register {
67 reg.value = value
68 return reg
71 func (reg *Register) ValueGet() uint32 {
72 return reg.value
75 func (reg *Register) ReadOnlyFieldsSet(fileldMask uint32) *Register {
76 reg.roFileds = fileldMask
77 return reg
80 func (reg *Register) ReadOnlyFieldsGet() uint32 {
81 return reg.roFileds
84 // Check the mask of the new macro
85 // Returns true if the macro is generated correctly
86 func (reg *Register) MaskCheck() bool {
87 mask := ^(reg.mask | reg.roFileds)
88 return reg.value&mask == 0
91 // getResetConfig - get Reset Configuration from PADRSTCFG field in PAD_CFG_DW0_GPx register
92 func (reg *Register) getFieldVal(mask uint32, shift uint8) uint8 {
93 reg.mask |= mask
94 return uint8((reg.value & mask) >> shift)
97 // CntrMaskFieldsClear - clear filed in control mask
98 // fieldMask - mask of the field to be cleared
99 func (reg *Register) CntrMaskFieldsClear(fieldMask uint32) {
100 reg.mask &= ^fieldMask;
103 // IgnoredFieldsGet - return mask of unchecked (ignored) fields.
104 // These bit fields were not read when the macro was
105 // generated.
106 // return
107 // mask of ignored bit field
108 func (reg *Register) IgnoredFieldsGet() uint32 {
109 mask := reg.mask | reg.roFileds
110 return reg.value & ^mask
113 // getResetConfig - returns type reset source for corresponding pad
114 // PADRSTCFG field in PAD_CFG_DW0 register
115 func (reg *Register) GetResetConfig() uint8 {
116 return reg.getFieldVal(PadRstCfgMask, PadRstCfgShift)
119 // getRXPadStateSelect - returns RX Pad State (RXINV)
120 // 0 = Raw RX pad state directly from RX buffer
121 // 1 = Internal RX pad state
122 func (reg *Register) GetRXPadStateSelect() uint8 {
123 return reg.getFieldVal(RxPadStateSelectMask, RxPadStateSelectShift)
126 // getRXRawOverrideStatus - returns 1 if the selected pad state is being
127 // overridden to '1' (RXRAW1 field)
128 func (reg *Register) GetRXRawOverrideStatus() uint8 {
129 return reg.getFieldVal(RxRawOverrideTo1Mask, RxRawOverrideTo1Shift)
132 // getRXLevelEdgeConfiguration - returns RX Level/Edge Configuration (RXEVCFG)
133 // 0h = Level, 1h = Edge, 2h = Drive '0', 3h = Reserved (implement as setting 0h)
134 func (reg *Register) GetRXLevelEdgeConfiguration() uint8 {
135 return reg.getFieldVal(RxLevelEdgeConfigurationMask, RxLevelEdgeConfigurationShift)
138 // GetRxInvert - returns RX Invert state (RXINV)
139 // 1 - Inversion, 0 - No inversion
140 func (reg *Register) GetRxInvert() uint8 {
141 return reg.getFieldVal(RxInvertMask, RxInvertShift)
144 // getRxTxEnableConfig - returns RX/TX Enable Config (RXTXENCFG)
145 // 0 = Function defined in Pad Mode controls TX and RX Enables
146 // 1 = Function controls TX Enable and RX Disabled with RX drive 0 internally
147 // 2 = Function controls TX Enable and RX Disabled with RX drive 1 internally
148 // 3 = Function controls TX Enabled and RX is always enabled
149 func (reg *Register) GetRxTxEnableConfig() uint8 {
150 return reg.getFieldVal(RxTxEnableConfigMask, RxTxEnableConfigShift)
153 // getGPIOInputRouteIOxAPIC - returns 1 if the pad can be routed to cause
154 // peripheral IRQ when configured in GPIO input mode.
155 func (reg *Register) GetGPIOInputRouteIOxAPIC() uint8 {
156 return reg.getFieldVal(InputRouteIOxApicMask, InputRouteIOxApicShift)
159 // getGPIOInputRouteSCI - returns 1 if the pad can be routed to cause SCI when
160 // configured in GPIO input mode.
161 func (reg *Register) GetGPIOInputRouteSCI() uint8 {
162 return reg.getFieldVal(InputRouteSCIMask, InputRouteSCIShift)
165 // getGPIOInputRouteSMI - returns 1 if the pad can be routed to cause SMI when
166 // configured in GPIO input mode
167 func (reg *Register) GetGPIOInputRouteSMI() uint8 {
168 return reg.getFieldVal(InputRouteSMIMask, InputRouteSMIShift)
171 // getGPIOInputRouteNMI - returns 1 if the pad can be routed to cause NMI when
172 // configured in GPIO input mode
173 func (reg *Register) GetGPIOInputRouteNMI() uint8 {
174 return reg.getFieldVal(InputRouteNMIMask, InputRouteNMIShift)
177 // getPadMode - reutrns pad mode or one of the native functions
178 // 0h = GPIO control the Pad.
179 // 1h = native function 1, if applicable, controls the Pad
180 // 2h = native function 2, if applicable, controls the Pad
181 // 3h = native function 3, if applicable, controls the Pad
182 // 4h = enable GPIO blink/PWM capability if applicable
183 func (reg *Register) GetPadMode() uint8 {
184 return reg.getFieldVal(PadModeMask, PadModeShift)
187 // getGPIORxTxDisableStatus - returns GPIO RX/TX buffer state (GPIORXDIS | GPIOTXDIS)
188 // 0 - both are enabled, 1 - TX Disable, 2 - RX Disable, 3 - both are disabled
189 func (reg *Register) GetGPIORxTxDisableStatus() uint8 {
190 return reg.getFieldVal(RxTxBufDisableMask, RxTxBufDisableShift)
193 // getGPIORXState - returns GPIO RX State (GPIORXSTATE)
194 func (reg *Register) GetGPIORXState() uint8 {
195 return reg.getFieldVal(RxStateMask, RxStateShift)
198 // getGPIOTXState - returns GPIO TX State (GPIOTXSTATE)
199 func (reg *Register) GetGPIOTXState() uint8 {
200 return reg.getFieldVal(TxStateMask, 0)
203 // Bit field constants for PAD_CFG_DW1 register
204 const (
205 PadTolShift uint8 = 25
206 PadTolMask uint32 = 0x1 << PadTolShift
208 IOStandbyStateShift uint8 = 14
209 IOStandbyStateMask uint32 = 0xF << IOStandbyStateShift
211 TermShift uint8 = 10
212 TermMask uint32 = 0xF << TermShift
214 IOStandbyTerminationShift uint8 = 8
215 IOStandbyTerminationMask uint32 = 0x3 << IOStandbyTerminationShift
217 InterruptSelectMask uint32 = 0xFF
220 // GetPadTol
221 func (reg *Register) GetPadTol() uint8 {
222 return reg.getFieldVal(PadTolMask, PadTolShift)
225 // getIOStandbyState - return IO Standby State (IOSSTATE)
226 // 0 = Tx enabled driving last value driven, Rx enabled
227 // 1 = Tx enabled driving 0, Rx disabled and Rx driving 0 back to its controller internally
228 // 2 = Tx enabled driving 0, Rx disabled and Rx driving 1 back to its controller internally
229 // 3 = Tx enabled driving 1, Rx disabled and Rx driving 0 back to its controller internally
230 // 4 = Tx enabled driving 1, Rx disabled and Rx driving 1 back to its controller internally
231 // 5 = Tx enabled driving 0, Rx enabled
232 // 6 = Tx enabled driving 1, Rx enabled
233 // 7 = Hi-Z, Rx driving 0 back to its controller internally
234 // 8 = Hi-Z, Rx driving 1 back to its controller internally
235 // 9 = Tx disabled, Rx enabled
236 // 15 = IO-Standby is ignored for this pin (same as functional mode)
237 // Others reserved
238 func (reg *Register) GetIOStandbyState() uint8 {
239 return reg.getFieldVal(IOStandbyStateMask, IOStandbyStateShift)
242 // getIOStandbyTermination - return IO Standby Termination (IOSTERM)
243 // 0 = Same as functional mode (no change)
244 // 1 = Disable Pull-up and Pull-down (no on-die termination)
245 // 2 = Enable Pull-down
246 // 3 = Enable Pull-up
247 func (reg *Register) GetIOStandbyTermination() uint8 {
248 return reg.getFieldVal(IOStandbyTerminationMask, IOStandbyTerminationShift)
251 // getTermination - returns the pad termination state defines the different weak
252 // pull-up and pull-down settings that are supported by the buffer
253 // 0000 = none; 0010 = 5k PD; 0100 = 20k PD; 1010 = 5k PU; 1100 = 20k PU;
254 // 1111 = Native controller selected
255 func (reg *Register) GetTermination() uint8 {
256 return reg.getFieldVal(TermMask, TermShift)
259 // getInterruptSelect - returns Interrupt Line number from the GPIO controller
260 func (reg *Register) GetInterruptSelect() uint8 {
261 return reg.getFieldVal(InterruptSelectMask, 0)