• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package tgl
2
3import (
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
14const (
15	PAD_CFG_DW0_RO_FIELDS = (0x1 << 27) | (0x1 << 24) | (0x3 << 21) | (0xf << 16) | 0xfc
16	PAD_CFG_DW1_RO_FIELDS = 0xfdffc3ff
17)
18
19const (
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
25type InheritanceMacro interface {
26	Pull()
27	GpiMacroAdd()
28	GpoMacroAdd()
29	NativeFunctionMacroAdd()
30	NoConnMacroAdd()
31}
32
33type PlatformSpecific struct {
34	InheritanceMacro
35}
36
37// RemmapRstSrc - remmap Pad Reset Source Config
38func (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 TigerLake Community 2:
46		// https://github.com/coreboot/coreboot/blob/master/src/soc/intel/tigerlake/gpio.c#L21
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	}
57	resetsrc, valid := remapping[dw0.GetResetConfig()]
58	if valid {
59		// dw0.SetResetConfig(resetsrc)
60		ResetConfigFieldVal := (dw0.ValueGet() & 0x3fffffff) | remapping[dw0.GetResetConfig()]
61		dw0.ValueSet(ResetConfigFieldVal)
62	} else {
63		fmt.Println("Invalid Pad Reset Config [ 0x", resetsrc ," ] for ", macro.PadIdGet())
64	}
65	dw0.CntrMaskFieldsClear(common.PadRstCfgMask)
66}
67
68// Adds The Pad Termination (TERM) parameter from PAD_CFG_DW1 to the macro
69// as a new argument
70func (platform PlatformSpecific) Pull() {
71	platform.InheritanceMacro.Pull()
72}
73
74// Adds PAD_CFG_GPI macro with arguments
75func (platform PlatformSpecific) GpiMacroAdd() {
76	platform.InheritanceMacro.GpiMacroAdd()
77}
78
79// Adds PAD_CFG_GPO macro with arguments
80func (platform PlatformSpecific) GpoMacroAdd() {
81	platform.InheritanceMacro.GpoMacroAdd()
82}
83
84// Adds PAD_CFG_NF macro with arguments
85func (platform PlatformSpecific) NativeFunctionMacroAdd() {
86	platform.InheritanceMacro.NativeFunctionMacroAdd()
87}
88
89// Adds PAD_NC macro
90func (platform PlatformSpecific) NoConnMacroAdd() {
91	platform.InheritanceMacro.NoConnMacroAdd()
92}
93
94// GenMacro - generate pad macro
95// dw0 : DW0 config register value
96// dw1 : DW1 config register value
97// return: string of macro
98//         error
99func (PlatformSpecific) GenMacro(id string, dw0 uint32, dw1 uint32, ownership uint8) string {
100	macro := common.GetInstanceMacro(
101		PlatformSpecific{
102			InheritanceMacro: cnl.PlatformSpecific{
103				InheritanceMacro: snr.PlatformSpecific{},
104			},
105		},
106		fields.InterfaceGet(),
107	)
108	macro.Clear()
109	macro.Register(PAD_CFG_DW0).CntrMaskFieldsClear(common.AllFields)
110	macro.Register(PAD_CFG_DW1).CntrMaskFieldsClear(common.AllFields)
111	macro.PadIdSet(id).SetPadOwnership(ownership)
112	macro.Register(PAD_CFG_DW0).ValueSet(dw0).ReadOnlyFieldsSet(PAD_CFG_DW0_RO_FIELDS)
113	macro.Register(PAD_CFG_DW1).ValueSet(dw1).ReadOnlyFieldsSet(PAD_CFG_DW1_RO_FIELDS)
114	return macro.Generate()
115}
116