soc/mediatek/mt8196: Add PMIC MT6373 driver
[coreboot.git] / util / intelp2m / platforms / apl / macro.go
blob31972777d344c6a927e090cff95933a10c00fadd
1 package apl
3 import (
4 "fmt"
5 "strconv"
7 "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common"
8 "review.coreboot.org/coreboot.git/util/intelp2m/config"
9 "review.coreboot.org/coreboot.git/util/intelp2m/fields"
12 const (
13 PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc
14 PAD_CFG_DW1_RO_FIELDS = 0xfffc00ff
17 const (
18 PAD_CFG_DW0 = common.PAD_CFG_DW0
19 PAD_CFG_DW1 = common.PAD_CFG_DW1
20 MAX_DW_NUM = common.MAX_DW_NUM
23 const (
24 PULL_NONE = 0x0 // 0 000: none
25 PULL_DN_5K = 0x2 // 0 010: 5k wpd (Only available on SMBus GPIOs)
26 PULL_DN_20K = 0x4 // 0 100: 20k wpd
27 // PULL_NONE = 0x8 // 1 000: none
28 PULL_UP_1K = 0x9 // 1 001: 1k wpu (Only available on I2C GPIOs)
29 PULL_UP_2K = 0xb // 1 011: 2k wpu (Only available on I2C GPIOs)
30 PULL_UP_20K = 0xc // 1 100: 20k wpu
31 PULL_UP_667 = 0xd // 1 101: 1k & 2k wpu (Only available on I2C GPIOs)
32 PULL_NATIVE = 0xf // 1 111: (optional) Native controller selected by Pad Mode
35 type PlatformSpecific struct {}
37 // RemmapRstSrc - remmap Pad Reset Source Config
38 // remmap is not required because it is the same as common.
39 func (PlatformSpecific) RemmapRstSrc() {}
41 // Adds The Pad Termination (TERM) parameter from DW1 to the macro as a new argument
42 // return: macro
43 func (PlatformSpecific) Pull() {
44 macro := common.GetMacro()
45 dw1 := macro.Register(PAD_CFG_DW1)
46 var pull = map[uint8]string{
47 PULL_NONE: "NONE",
48 PULL_DN_5K: "DN_5K",
49 PULL_DN_20K: "DN_20K",
50 PULL_UP_1K: "UP_1K",
51 PULL_UP_2K: "UP_2K",
52 PULL_UP_20K: "UP_20K",
53 PULL_UP_667: "UP_667",
54 PULL_NATIVE: "NATIVE",
57 terminationFieldValue := dw1.GetTermination()
58 str, valid := pull[terminationFieldValue]
59 if !valid {
60 str = strconv.Itoa(int(terminationFieldValue))
61 fmt.Println("Error", macro.PadIdGet(), " invalid TERM value = ", str)
63 macro.Separator().Add(str)
66 // Generate macro to cause peripheral IRQ when configured in GPIO input mode
67 func ioApicRoute() bool {
68 macro := common.GetMacro()
69 dw0 := macro.Register(PAD_CFG_DW0)
70 dw1 := macro.Register(PAD_CFG_DW1)
71 if dw0.GetGPIOInputRouteIOxAPIC() == 0 {
72 return false
74 macro.Add("_APIC")
75 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
76 // e.g. H1_PCH_INT_ODL
77 // PAD_CFG_GPI_APIC_IOS(GPIO_63, NONE, DEEP, LEVEL, INVERT, TxDRxE, DISPUPD),
78 macro.Add("_IOS(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm()
79 } else {
80 // PAD_CFG_GPI_APIC(pad, pull, rst, trig, inv)
81 macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
83 macro.Add("),")
84 return true
87 // Generate macro to cause NMI when configured in GPIO input mode
88 func nmiRoute() bool {
89 macro := common.GetMacro()
90 if macro.Register(PAD_CFG_DW0).GetGPIOInputRouteNMI() == 0 {
91 return false
93 // e.g. PAD_CFG_GPI_NMI(GPIO_24, UP_20K, DEEP, LEVEL, INVERT),
94 macro.Add("_NMI").Add("(").Id().Pull().Rstsrc().Trig().Invert().Add("),")
95 return true
98 // Generate macro to cause SCI when configured in GPIO input mode
99 func sciRoute() bool {
100 macro := common.GetMacro()
101 dw0 := macro.Register(PAD_CFG_DW0)
102 dw1 := macro.Register(PAD_CFG_DW0)
103 if dw0.GetGPIOInputRouteSCI() == 0 {
104 return false
106 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
107 // PAD_CFG_GPI_SCI_IOS(GPIO_141, NONE, DEEP, EDGE_SINGLE, INVERT, IGNORE, DISPUPD),
108 macro.Add("_SCI_IOS")
109 macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm()
110 } else if dw0.GetRXLevelEdgeConfiguration() & 0x1 != 0 {
111 // e.g. PAD_CFG_GPI_ACPI_SCI(GPP_G2, NONE, DEEP, YES),
112 macro.Add("_ACPI_SCI").Add("(").Id().Pull().Rstsrc().Invert()
113 } else {
114 // e.g. PAD_CFG_GPI_SCI(GPP_B18, UP_20K, PLTRST, LEVEL, INVERT),
115 macro.Add("_SCI").Add("(").Id().Pull().Rstsrc().Trig().Invert()
117 macro.Add("),")
118 return true
121 // Generate macro to cause SMI when configured in GPIO input mode
122 func smiRoute() bool {
123 macro := common.GetMacro()
124 dw0 := macro.Register(PAD_CFG_DW0)
125 dw1 := macro.Register(PAD_CFG_DW1)
126 if dw0.GetGPIOInputRouteSMI() == 0 {
127 return false
129 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
130 // PAD_CFG_GPI_SMI_IOS(GPIO_41, UP_20K, DEEP, EDGE_SINGLE, NONE, IGNORE, SAME),
131 macro.Add("_SMI_IOS")
132 macro.Add("(").Id().Pull().Rstsrc().Trig().Invert().IOSstate().IOTerm()
133 } else if dw0.GetRXLevelEdgeConfiguration() & 0x1 != 0 {
134 // e.g. PAD_CFG_GPI_ACPI_SMI(GPP_I3, NONE, DEEP, YES),
135 macro.Add("_ACPI_SMI").Add("(").Id().Pull().Rstsrc().Invert()
136 } else {
137 // e.g. PAD_CFG_GPI_SMI(GPP_E3, NONE, PLTRST, EDGE_SINGLE, NONE),
138 macro.Add("_SMI").Add("(").Id().Pull().Rstsrc().Trig().Invert()
140 macro.Add("),")
141 return true
144 // Generate macro for GPI port
145 func (PlatformSpecific) GpiMacroAdd() {
146 macro := common.GetMacro()
147 var ids []string
148 macro.Set("PAD_CFG_GPI")
149 for routeid, isRoute := range map[string]func() (bool) {
150 "IOAPIC": ioApicRoute,
151 "SCI": sciRoute,
152 "SMI": smiRoute,
153 "NMI": nmiRoute,
155 if isRoute() {
156 ids = append(ids, routeid)
160 switch argc := len(ids); argc {
161 case 0:
162 dw1 := macro.Register(PAD_CFG_DW1)
163 isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0
164 isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0
165 if isIOStandbyStateUsed && !isIOStandbyTerminationUsed {
166 macro.Add("_TRIG_IOSSTATE_OWN(")
167 // PAD_CFG_GPI_TRIG_IOSSTATE_OWN(pad, pull, rst, trig, iosstate, own)
168 macro.Id().Pull().Rstsrc().Trig().IOSstate().Own().Add("),")
169 } else if isIOStandbyTerminationUsed {
170 macro.Add("_TRIG_IOS_OWN(")
171 // PAD_CFG_GPI_TRIG_IOS_OWN(pad, pull, rst, trig, iosstate, iosterm, own)
172 macro.Id().Pull().Rstsrc().Trig().IOSstate().IOTerm().Own().Add("),")
173 } else {
174 // PAD_CFG_GPI_TRIG_OWN(pad, pull, rst, trig, own)
175 macro.Add("_TRIG_OWN(").Id().Pull().Rstsrc().Trig().Own().Add("),")
177 case 1:
178 // GPI with IRQ route
179 if config.AreFieldsIgnored() {
180 macro.SetPadOwnership(common.PAD_OWN_ACPI)
182 case 2:
183 // PAD_CFG_GPI_DUAL_ROUTE(pad, pull, rst, trig, inv, route1, route2)
184 macro.Set("PAD_CFG_GPI_DUAL_ROUTE(").Id().Pull().Rstsrc().Trig().Invert()
185 macro.Add(", " + ids[0] + ", " + ids[1] + "),")
186 if config.AreFieldsIgnored() {
187 macro.SetPadOwnership(common.PAD_OWN_ACPI)
189 default:
190 // Clear the control mask so that the check fails and "Advanced" macro is
191 // generated
192 macro.Register(PAD_CFG_DW0).CntrMaskFieldsClear(common.AllFields)
197 // Adds PAD_CFG_GPO macro with arguments
198 func (PlatformSpecific) GpoMacroAdd() {
199 macro := common.GetMacro()
200 dw0 := macro.Register(PAD_CFG_DW0)
201 dw1 := macro.Register(PAD_CFG_DW1)
202 term := dw1.GetTermination()
204 macro.Set("PAD_CFG")
205 if dw1.GetIOStandbyState() != 0 || dw1.GetIOStandbyTermination() != 0 {
206 // PAD_CFG_GPO_IOSSTATE_IOSTERM(GPIO_91, 0, DEEP, NONE, Tx0RxDCRx0, DISPUPD),
207 // PAD_CFG_GPO_IOSSTATE_IOSTERM(pad, val, rst, pull, iosstate, ioterm)
208 macro.Add("_GPO_IOSSTATE_IOSTERM(").Id().Val().Rstsrc().Pull().IOSstate().IOTerm()
209 } else {
210 if term != 0 {
211 // e.g. PAD_CFG_TERM_GPO(GPP_B23, 1, DN_20K, DEEP),
212 // PAD_CFG_TERM_GPO(pad, val, pull, rst)
213 macro.Add("_TERM")
215 macro.Add("_GPO(").Id().Val()
216 if term != 0 {
217 macro.Pull()
219 macro.Rstsrc()
221 macro.Add("),")
223 if dw0.GetRXLevelEdgeConfiguration() != common.TRIG_OFF {
224 // ignore if trig = OFF is not set
225 dw0.CntrMaskFieldsClear(common.RxLevelEdgeConfigurationMask)
229 // Adds PAD_CFG_NF macro with arguments
230 func (PlatformSpecific) NativeFunctionMacroAdd() {
231 macro := common.GetMacro()
232 dw1 := macro.Register(PAD_CFG_DW1)
233 isIOStandbyStateUsed := dw1.GetIOStandbyState() != 0
234 isIOStandbyTerminationUsed := dw1.GetIOStandbyTermination() != 0
236 macro.Set("PAD_CFG_NF")
237 if !isIOStandbyTerminationUsed && isIOStandbyStateUsed {
238 if dw1.GetIOStandbyState() == common.StandbyIgnore {
239 // PAD_CFG_NF_IOSTANDBY_IGNORE(PMU_SLP_S0_B, NONE, DEEP, NF1),
240 macro.Add("_IOSTANDBY_IGNORE(").Id().Pull().Rstsrc().Padfn()
241 } else {
242 // PAD_CFG_NF_IOSSTATE(GPIO_22, UP_20K, DEEP, NF2, TxDRxE),
243 macro.Add("_IOSSTATE(").Id().Pull().Rstsrc().Padfn().IOSstate()
245 } else if isIOStandbyTerminationUsed {
246 // PAD_CFG_NF_IOSSTATE_IOSTERM(GPIO_103, NATIVE, DEEP, NF1, MASK, SAME),
247 macro.Add("_IOSSTATE_IOSTERM(").Id().Pull().Rstsrc().Padfn().IOSstate().IOTerm()
248 } else {
249 // e.g. PAD_CFG_NF(GPP_D23, NONE, DEEP, NF1)
250 macro.Add("(").Id().Pull().Rstsrc().Padfn()
252 macro.Add("),")
254 if dw0 := macro.Register(PAD_CFG_DW0); dw0.GetGPIORxTxDisableStatus() != 0 {
255 // Since the bufbis parameter will be ignored for NF, we should clear
256 // the corresponding bits in the control mask.
257 dw0.CntrMaskFieldsClear(common.RxTxBufDisableMask)
261 // Adds PAD_NC macro
262 func (PlatformSpecific) NoConnMacroAdd() {
263 macro := common.GetMacro()
264 dw1 := macro.Register(PAD_CFG_DW1)
266 if dw1.GetIOStandbyState() == common.TxDRxE {
267 dw0 := macro.Register(PAD_CFG_DW0)
269 // See comments in sunrise/macro.go : NoConnMacroAdd()
270 if dw0.GetRXLevelEdgeConfiguration() != common.TRIG_OFF {
271 dw0.CntrMaskFieldsClear(common.RxLevelEdgeConfigurationMask)
273 if dw0.GetResetConfig() != 1 { // 1 = RST_DEEP
274 dw0.CntrMaskFieldsClear(common.PadRstCfgMask)
277 // PAD_NC(OSC_CLK_OUT_1, DN_20K)
278 macro.Set("PAD_NC").Add("(").Id().Pull().Add("),")
279 return
281 // PAD_CFG_GPIO_HI_Z(GPIO_81, UP_20K, DEEP, HIZCRx0, DISPUPD),
282 macro.Set("PAD_CFG_GPIO_")
283 if macro.IsOwnershipDriver() {
284 // PAD_CFG_GPIO_DRIVER_HI_Z(GPIO_55, UP_20K, DEEP, HIZCRx1, ENPU),
285 macro.Add("DRIVER_")
287 macro.Add("HI_Z(").Id().Pull().Rstsrc().IOSstate().IOTerm().Add("),")
290 // GenMacro - generate pad macro
291 // dw0 : DW0 config register value
292 // dw1 : DW1 config register value
293 // return: string of macro
294 // error
295 func (PlatformSpecific) GenMacro(id string, dw0 uint32, dw1 uint32, ownership uint8) string {
296 macro := common.GetInstanceMacro(PlatformSpecific{}, fields.InterfaceGet())
297 // use platform-specific interface in Macro struct
298 macro.PadIdSet(id).SetPadOwnership(ownership)
299 macro.Register(PAD_CFG_DW0).CntrMaskFieldsClear(common.AllFields)
300 macro.Register(PAD_CFG_DW1).CntrMaskFieldsClear(common.AllFields)
301 macro.Register(PAD_CFG_DW0).ValueSet(dw0).ReadOnlyFieldsSet(PAD_CFG_DW0_RO_FIELDS)
302 macro.Register(PAD_CFG_DW1).ValueSet(dw1).ReadOnlyFieldsSet(PAD_CFG_DW1_RO_FIELDS)
303 return macro.Generate()