Debian Codegraph @

util/intelp2m/platforms/apl/apl.go

raw symbols SCIP
1 package apl
2
3 import (
4 "review.coreboot.org/coreboot.git/util/intelp2m/config/p2m"
5 "review.coreboot.org/coreboot.git/util/intelp2m/logs"
6 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common"
7 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits"
8 )
9
10 const (
11 DW0Mask uint32 = (0b1 << 27) | (0b1 << 24) | (0b11 << 21) | (0b1111 << 16) | 0b11111100
12 DW1Mask uint32 = 0b11111111111111000000000011111111
13 )
14
15 var GPPGroups = []string{
16 "GPIO_", "TCK", "TRST_B", "TMS", "TDI", "CX_PMODE", "CX_PREQ_B", "JTAGX", "CX_PRDY_B",
17 "TDO", "CNV_BRI_DT", "CNV_BRI_RSP", "CNV_RGI_DT", "CNV_RGI_RSP", "SVID0_ALERT_B",
18 "SVID0_DATA", "SVID0_CLK", "PMC_SPI_FS", "PMC_SPI_RXD", "PMC_SPI_TXD", "PMC_SPI_CLK",
19 "PMIC_PWRGOOD", "PMIC_RESET_B", "PMIC_THERMTRIP_B", "PMIC_STDBY", "PROCHOT_B",
20 "PMIC_I2C_SCL", "PMIC_I2C_SDA", "FST_SPI_CLK_FB", "OSC_CLK_OUT_", "PMU_AC_PRESENT",
21 "PMU_BATLOW_B", "PMU_PLTRST_B", "PMU_PWRBTN_B", "PMU_RESETBUTTON_B", "PMU_SLP_S0_B",
22 "PMU_SLP_S3_B", "PMU_SLP_S4_B", "PMU_SUSCLK", "PMU_WAKE_B", "SUS_STAT_B", "SUSPWRDNACK",
23 "SMB_ALERTB", "SMB_CLK", "SMB_DATA", "LPC_ILB_SERIRQ", "LPC_CLKOUT", "LPC_AD", "LPC_CLKRUNB",
24 "LPC_FRAMEB",
25 }
26
27 type BasePlatform struct {
28 common.BasePlatform
29 }
30
31 func InitBasePlatform(dw0, dw0mask uint32, dw1, dw1mask uint32) BasePlatform {
32 return BasePlatform{common.InitBasePlatform(dw0, dw0mask, dw1, dw1mask)}
33 }
34
35 func GetPlatform(dw0, dw1 uint32) common.PlatformIf {
36 p := InitBasePlatform(dw0, DW0Mask, dw1, DW1Mask)
37 return &p
38 }
39
40 // RemapResetSource() remaps Pad Reset Source Config
41 func (p *BasePlatform) RemapResetSource(m *common.Macro) {}
42
43 // Pull() adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro
44 func (p *BasePlatform) Pull(m *common.Macro) {
45 const (
46 PULL_NONE = 0b0000 // 0 000: none
47 PULL_DN_5K = 0b0010 // 0 010: 5k wpd (Only available on SMBus GPIOs)
48 PULL_DN_20K = 0b0100 // 0 100: 20k wpd
49 // PULL_NONE = 0b1000 // 1 000: none
50 PULL_UP_1K = 0b1001 // 1 001: 1k wpu (Only available on I2C GPIOs)
51 PULL_UP_2K = 0b1011 // 1 011: 2k wpu (Only available on I2C GPIOs)
52 PULL_UP_20K = 0b1100 // 1 100: 20k wpu
53 PULL_UP_667 = 0b1101 // 1 101: 1k & 2k wpu (Only available on I2C GPIOs)
54 PULL_NATIVE = 0b1111 // 1 111: (optional) Native controller selected by Pad Mode
55 )
56
57 var pull = map[uint32]string{
58 PULL_NONE: "NONE",
59 PULL_DN_5K: "DN_5K",
60 PULL_DN_20K: "DN_20K",
61 PULL_UP_1K: "UP_1K",
62 PULL_UP_2K: "UP_2K",
63 PULL_UP_20K: "UP_20K",
64 PULL_UP_667: "UP_667",
65 PULL_NATIVE: "NATIVE",
66 }
67 dw1 := p.GetRegisterDW1()
68 term, exist := pull[dw1.GetTermination()]
69 if !exist {
70 term = "INVALID"
71 logs.Errorf("%s: DW1 %s: invalid termination value 0b%b",
72 dw1, m.GetPadId(), dw1.GetTermination())
73 }
74 m.Separator().Add(term)
75 }
76
77 // Generate macro to cause peripheral IRQ when configured in GPIO input mode
78 func ioApicRoute(p *BasePlatform, m *common.Macro) bool {
79 if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteIOxAPIC() == 0 {
80 return false
81 }
82 m.Add("_APIC")
83 dw1 := p.GetRegisterDW1()
84 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
85 // e.g. H1_PCH_INT_ODL
86 // PAD_CFG_GPI_APIC_IOS(GPIO_63, NONE, DEEP, LEVEL, INVERT, TxDRxE, DISPUPD),
87 m.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm()
88 } else {
89 // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv)
90 m.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
91 }
92 m.Add("),")
93 return true
94 }
95
96 // Generate macro to cause NMI when configured in GPIO input mode
97 func nmiRoute(p *BasePlatform, m *common.Macro) bool {
98 if dw0 := p.GetRegisterDW0(); dw0.GetGPIOInputRouteNMI() == 0 {
99 return false
100 }
101 // e.g. PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT),
102 m.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
103 return true
104 }
105
106 // Generate macro to cause SCI when configured in GPIO input mode
107 func sciRoute(p *BasePlatform, m *common.Macro) bool {
108 dw0 := p.GetRegisterDW0()
109 if dw0.GetGPIOInputRouteSCI() == 0 {
110 return false
111 }
112
113 dw1 := p.GetRegisterDW1()
114 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
115 // PAD_CFG_GPI_SCI_IOS(GPIO_141, NONE, DEEP, EDGE_SINGLE, INVERT, IGNORE, DISPUPD),
116 m.Add("_SCI_IOS")
117 m.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm()
118 } else if dw0.GetRXLevelEdgeConfiguration()&0x1 != 0 {
119 // e.g. PAD_CFG_GPI_ACPI_SCI(GPP_G2, NONE, DEEP, YES),
120 m.Add("_ACPI_SCI").Add("(").Id().Pull().Rstsrc().Invert()
121 } else {
122 // e.g. PAD_CFG_GPI_SCI(GPP_B18, UP_20K, PLTRST, LEVEL, INVERT),
123 m.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert()
124 }
125 m.Add("),")
126 return true
127 }
128
129 // Generate macro to cause SMI when configured in GPIO input mode
130 func smiRoute(p *BasePlatform, m *common.Macro) bool {
131 dw0 := p.GetRegisterDW0()
132 if dw0.GetGPIOInputRouteSMI() == 0 {
133 return false
134 }
135 dw1 := p.GetRegisterDW1()
136 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
137 // PAD_CFG_GPI_SMI_IOS(GPIO_41, UP_20K, DEEP, EDGE_SINGLE, NONE, IGNORE, SAME),
138 m.Add("_SMI_IOS")
139 m.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm()
140 } else if dw0.GetRXLevelEdgeConfiguration()&0x1 != 0 {
141 // e.g. PAD_CFG_GPI_ACPI_SMI(GPP_I3, NONE, DEEP, YES),
142 m.Add("_ACPI_SMI").Add("(").Id().Pull().Rstsrc().Invert()
143 } else {
144 // e.g. PAD_CFG_GPI_SMI(GPP_E3, NONE, PLTRST, EDGE_SINGLE, NONE),
145 m.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert()
146 }
147 m.Add("),")
148 return true
149 }
150
151 // AddGpiMacro() adds PAD_CFG_GPI macro with arguments
152 func (p *BasePlatform) AddGpiMacro(m *common.Macro) {
153 var ids []string
154
155 m.Set("PAD_CFG_GPI")
156 for routeid, isRoute := range map[string]func(*BasePlatform, *common.Macro) bool{
157 "IOAPIC": ioApicRoute,
158 "SCI": sciRoute,
159 "SMI": smiRoute,
160 "NMI": nmiRoute,
161 } {
162 if isRoute(p, m) {
163 ids = append(ids, routeid)
164 }
165 }
166
167 switch config, argc := p2m.Config, len(ids); argc {
168 case 0:
169 dw1 := p.GetRegisterDW1()
170 isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0
171 isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0
172 if isIOStandbyStateUsed && !isIOStandbyTerminationUsed {
173 m.Add("_TRIG_IOSSTATE_OWN(")
174 // PAD_CFG_GPI_TRIG_IOSSTATE_OWN(pad, pull, rst, trig, iosstate, own)
175 m.Id().Pull().Rstsrc().Trig().IOSstate().Own().Add("),")
176 } else if isIOStandbyTerminationUsed {
177 m.Add("_TRIG_IOS_OWN(")
178 // PAD_CFG_GPI_TRIG_IOS_OWN(pad, pull, rst, trig, iosstate, iosterm, own)
179 m.Id().Pull().Rstsrc().Trig().IOSstate().IOTerm().Own().Add("),")
180 } else {
181 // PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own)
182 m.Add("_TRIG_OWN(").Id().Pull().Rstsrc().Trig().Own().Add("),")
183 }
184 case 1:
185 // GPI with IRQ route
186 if config.IgnoredFields {
187 m.SetOwnershipAcpi()
188 }
189 case 2:
190 // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2)
191 m.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert()
192 m.Add(", " + ids[0] + ", " + ids[1] + "),")
193 if config.IgnoredFields {
194 m.SetOwnershipAcpi()
195 }
196 default:
197 // Clear the control mask so that the check fails and "Advanced" macro is
198 // generated
199 dw0 := p.GetRegisterDW0()
200 dw0.CntrMaskFieldsClear(bits.All32)
201 }
202 }
203
204 // AddGpoMacro() adds PAD_CFG_GPO macro with arguments
205 func (p *BasePlatform) AddGpoMacro(m *common.Macro) {
206 m.Set("PAD_CFG")
207 dw1 := p.GetRegisterDW1()
208 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
209 // PAD_CFG_GPO_IOSSTATE_IOSTERM(GPIO_91, 0, DEEP, NONE, Tx0RxDCRx0, DISPUPD),
210 // PAD_CFG_GPO_IOSSTATE_IOSTERM(pad, val, rst, pull, iosstate, ioterm)
211 m.Add("_GPO_IOSSTATE_IOSTERM(").Id().Val().Rstsrc().Pull().IOSstate().IOTerm()
212 } else {
213 term := dw1.GetTermination()
214 if term != 0 {
215 // e.g. PAD_CFG_TERM_GPO(GPP_B23, 1, DN_20K, DEEP),
216 // PAD_CFG_TERM_GPO(pad, val, pull, rst)
217 m.Add("_TERM")
218 }
219 m.Add("_GPO(").Id().Val()
220 if term != 0 {
221 m.Pull()
222 }
223 m.Rstsrc()
224 }
225 m.Add("),")
226
227 if dw0 := p.GetRegisterDW0(); dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF {
228 // ignore if trig = OFF is not set
229 dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxLevelEdgeConfiguration])
230 }
231 }
232
233 // AddNativeFunctionMacro() adds PAD_CFG_NF macro with arguments
234 func (p *BasePlatform) AddNativeFunctionMacro(m *common.Macro) {
235 m.Set("PAD_CFG_NF")
236 dw1 := p.GetRegisterDW1()
237 isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0
238 isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0
239 if !isIOStandbyTerminationUsed && isIOStandbyStateUsed {
240 if dw1.GetIOStandbyState() == bits.IOStateStandbyIgnore {
241 // PAD_CFG_NF_IOSTANDBY_IGNORE(PMU_SLP_S0_B, NONE, DEEP, NF1),
242 m.Add("_IOSTANDBY_IGNORE(").Id().Pull().Rstsrc().Padfn()
243 } else {
244 // PAD_CFG_NF_IOSSTATE(GPIO_22, UP_20K, DEEP, NF2, TxDRxE),
245 m.Add("_IOSSTATE(").Id().Pull().Rstsrc().Padfn().IOSstate()
246 }
247 } else if isIOStandbyTerminationUsed {
248 // PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_103, NATIVE, DEEP, NF1, MASK, SAME),
249 m.Add("_IOSSTATE_IOSTERM(").Id().Pull().Rstsrc().Padfn().IOSstate().IOTerm()
250 } else {
251 // e.g. PAD_CFG_NF(GPP_D23, NONE, DEEP, NF1)
252 m.Add("(").Id().Pull().Rstsrc().Padfn()
253 }
254 m.Add("),")
255
256 if dw0 := p.GetRegisterDW0(); dw0.GetGPIORxTxDisableStatus() != 0 {
257 // Since the bufbis parameter will be ignored for NF, we should clear
258 // the corresponding bits in the control mask.
259 dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxTxBufDisable])
260 }
261 }
262
263 // AddNoConnMacro() adds PAD_NC macro
264 func (p *BasePlatform) AddNoConnMacro(m *common.Macro) {
265 if dw1 := p.GetRegisterDW1(); dw1.GetIOStandbyState() == bits.IOStateTxDRxE {
266 dw0 := p.GetRegisterDW0()
267 // See comments in sunrise/m.go : AddNoConnMacro()
268 if dw0.GetRXLevelEdgeConfiguration() != bits.TrigOFF {
269 dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0RxLevelEdgeConfiguration])
270 }
271 if dw0.GetResetConfig() != 1 { // 1 = RST_DEEP
272 dw0.CntrMaskFieldsClear(bits.DW0[bits.DW0PadRstCfg])
273 }
274 // PAD_NC(OSC_CLK_OUT_1, DN_20K)
275 m.Set("PAD_NC").Add("(").Id().Pull().Add("),")
276 return
277 }
278 // PAD_CFG_GPIO_HI_Z(GPIO_81, UP_20K, DEEP, HIZCRx0, DISPUPD),
279 if m.Set("PAD_CFG_GPIO_"); m.IsOwnershipDriver() {
280 // PAD_CFG_GPIO_DRIVER_HI_Z(GPIO_55, UP_20K, DEEP, HIZCRx1, ENPU),
281 m.Add("DRIVER_")
282 }
283 m.Add("HI_Z(").Id().Pull().Rstsrc().IOSstate().IOTerm().Add("),")
284 }