Filip LewiĆski | 7898594 | 2024-04-15 16:46:04 +0200 | [diff] [blame^] | 1 | package mtl |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "fmt" |
| 6 | |
| 7 | "review.coreboot.org/coreboot.git/util/intelp2m/platforms/common" |
| 8 | "review.coreboot.org/coreboot.git/util/intelp2m/platforms/snr" |
| 9 | "review.coreboot.org/coreboot.git/util/intelp2m/platforms/cnl" |
| 10 | "review.coreboot.org/coreboot.git/util/intelp2m/config" |
| 11 | "review.coreboot.org/coreboot.git/util/intelp2m/fields" |
| 12 | ) |
| 13 | |
| 14 | const ( |
| 15 | PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc |
| 16 | PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff |
| 17 | ) |
| 18 | |
| 19 | const ( |
| 20 | PAD_CFG_DW0 = common.PAD_CFG_DW0 |
| 21 | PAD_CFG_DW1 = common.PAD_CFG_DW1 |
| 22 | MAX_DW_NUM = common.MAX_DW_NUM |
| 23 | ) |
| 24 | |
| 25 | type InheritanceMacro interface { |
| 26 | Pull() |
| 27 | GpiMacroAdd() |
| 28 | GpoMacroAdd() |
| 29 | NativeFunctionMacroAdd() |
| 30 | NoConnMacroAdd() |
| 31 | } |
| 32 | |
| 33 | type PlatformSpecific struct { |
| 34 | InheritanceMacro |
| 35 | } |
| 36 | |
| 37 | // RemmapRstSrc - remmap Pad Reset Source Config |
| 38 | func (PlatformSpecific) RemmapRstSrc() { |
| 39 | macro := common.GetMacro() |
| 40 | if config.TemplateGet() != config.TempInteltool { |
| 41 | // Use reset source remapping only if the input file is inteltool.log dump |
| 42 | return |
| 43 | } |
| 44 | if strings.Contains(macro.PadIdGet(), "GPD") { |
| 45 | // See reset map for the MeteorLake GPD group at |
| 46 | // https://github.com/coreboot/coreboot/blob/master/src/soc/intel/meteorlake/gpio.c#L10 |
| 47 | // remmap is not required because it is the same as common. |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | dw0 := macro.Register(PAD_CFG_DW0) |
| 52 | var remapping = map[uint8]uint32{ |
| 53 | 0: common.RST_RSMRST << common.PadRstCfgShift, |
| 54 | 1: common.RST_DEEP << common.PadRstCfgShift, |
| 55 | 2: common.RST_PLTRST << common.PadRstCfgShift, |
| 56 | 3: common.RST_PWROK << common.PadRstCfgShift, |
| 57 | } |
| 58 | resetsrc, valid := remapping[dw0.GetResetConfig()] |
| 59 | if valid { |
| 60 | // dw0.SetResetConfig(resetsrc) |
| 61 | ResetConfigFieldVal := (dw0.ValueGet() & 0x3fffffff) | remapping[dw0.GetResetConfig()] |
| 62 | dw0.ValueSet(ResetConfigFieldVal) |
| 63 | } else { |
| 64 | fmt.Println("Invalid Pad Reset Config [ 0x", resetsrc ," ] for ", macro.PadIdGet()) |
| 65 | } |
| 66 | dw0.CntrMaskFieldsClear(common.PadRstCfgMask) |
| 67 | } |
| 68 | |
| 69 | // Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro |
| 70 | // as a new argument |
| 71 | func (platform PlatformSpecific) Pull() { |
| 72 | platform.InheritanceMacro.Pull() |
| 73 | } |
| 74 | |
| 75 | // Adds PAD_CFG_GPI macro with arguments |
| 76 | func (platform PlatformSpecific) GpiMacroAdd() { |
| 77 | platform.InheritanceMacro.GpiMacroAdd() |
| 78 | } |
| 79 | |
| 80 | // Adds PAD_CFG_GPO macro with arguments |
| 81 | func (platform PlatformSpecific) GpoMacroAdd() { |
| 82 | platform.InheritanceMacro.GpoMacroAdd() |
| 83 | } |
| 84 | |
| 85 | // Adds PAD_CFG_NF macro with arguments |
| 86 | func (platform PlatformSpecific) NativeFunctionMacroAdd() { |
| 87 | platform.InheritanceMacro.NativeFunctionMacroAdd() |
| 88 | } |
| 89 | |
| 90 | // Adds PAD_NC macro |
| 91 | func (platform PlatformSpecific) NoConnMacroAdd() { |
| 92 | platform.InheritanceMacro.NoConnMacroAdd() |
| 93 | } |
| 94 | |
| 95 | |
| 96 | // GenMacro - generate pad macro |
| 97 | // dw0 : DW0 config register value |
| 98 | // dw1 : DW1 config register value |
| 99 | // return: string of macro |
| 100 | // error |
| 101 | func (PlatformSpecific) GenMacro(id string, dw0 uint32, dw1 uint32, ownership uint8) string { |
| 102 | macro := common.GetInstanceMacro( |
| 103 | PlatformSpecific{ |
| 104 | InheritanceMacro: cnl.PlatformSpecific{ |
| 105 | InheritanceMacro: snr.PlatformSpecific{}, |
| 106 | }, |
| 107 | }, |
| 108 | fields.InterfaceGet(), |
| 109 | ) |
| 110 | macro.Clear() |
| 111 | macro.Register(PAD_CFG_DW0).CntrMaskFieldsClear(common.AllFields) |
| 112 | macro.Register(PAD_CFG_DW1).CntrMaskFieldsClear(common.AllFields) |
| 113 | macro.PadIdSet(id).SetPadOwnership(ownership) |
| 114 | macro.Register(PAD_CFG_DW0).ValueSet(dw0).ReadOnlyFieldsSet(PAD_CFG_DW0_RO_FIELDS) |
| 115 | macro.Register(PAD_CFG_DW1).ValueSet(dw1).ReadOnlyFieldsSet(PAD_CFG_DW1_RO_FIELDS) |
| 116 | return macro.Generate() |
| 117 | } |