16 // PlatformSpecific - platform-specific interface
17 type PlatformSpecific
interface {
18 GenMacro(id
string, dw0
uint32, dw1
uint32, ownership
uint8) string
19 GroupNameExtract(line
string) (bool, string)
20 KeywordCheck(line
string) bool
23 // padInfo - information about pad
25 // offset : the offset of the register address relative to the base
26 // function : the string that means the pad function
27 // dw0 : DW0 register value
28 // dw1 : DW1 register value
29 // ownership : host software ownership
39 // generate - wrapper for Fprintf(). Writes text to the file specified
40 // in config.OutputGenFile
41 func (info
*padInfo
) generate(lvl
int, line
string, a
...interface{}) {
42 if config
.InfoLevelGet() >= lvl
{
43 fmt
.Fprintf(config
.OutputGenFile
, line
, a
...)
47 // titleFprint - print GPIO group title to file
48 // /* ------- GPIO Group GPP_L ------- */
49 func (info
*padInfo
) titleFprint() {
50 info
.generate(0, "\n\t/* %s */\n", info
.function
)
53 // reservedFprint - print reserved GPIO to file as comment
54 // /* GPP_H17 - RESERVED */
55 func (info
*padInfo
) reservedFprint() {
56 info
.generate(2, "\n")
57 // small comment about reserved port
58 info
.generate(0, "\t/* %s - %s */\n", info
.id
, info
.function
)
61 // padInfoMacroFprint - print information about current pad to file using
63 // PAD_CFG_NF(GPP_F1, 20K_PU, PLTRST, NF1), /* SATAXPCIE4 */
64 // gpio : gpio.c file descriptor
65 // macro : string of the generated macro
66 func (info
*padInfo
) padInfoMacroFprint(macro
string) {
68 "\n\t/* %s - %s */\n\t/* DW0: 0x%0.8x, DW1: 0x%0.8x */\n",
73 info
.generate(0, "\t%s", macro
)
74 if config
.InfoLevelGet() == 1 {
75 info
.generate(1, "\t/* %s */", info
.function
)
77 info
.generate(0, "\n")
80 // ParserData - global data
81 // line : string from the configuration file
82 // padmap : pad info map
83 // RawFmt : flag for generating pads config file with DW0/1 reg raw values
84 // Template : structure template type of ConfigFile
85 type ParserData
struct {
86 platform PlatformSpecific
89 ownership
map[string]uint32
92 // hostOwnershipGet - get the host software ownership value for the corresponding
95 // return the host software ownership form the parser struct
96 func (parser
*ParserData
) hostOwnershipGet(id
string) uint8 {
97 var ownership
uint8 = 0
98 status
, group
:= parser
.platform
.GroupNameExtract(id
)
99 if config
.TemplateGet() == config
.TempInteltool
&& status
{
100 numder
, _
:= strconv
.Atoi(strings
.TrimLeft(id
, group
))
101 if (parser
.ownership
[group
] & (1 << uint8(numder
))) != 0 {
108 // padInfoExtract - adds a new entry to pad info map
109 // return error status
110 func (parser
*ParserData
) padInfoExtract() int {
111 var function
, id
string
113 var template
= map[int]template
{
114 config
.TempInteltool
: useInteltoolLogTemplate
,
115 config
.TempGpioh
: useGpioHTemplate
,
116 config
.TempSpec
: useYourTemplate
,
118 if template
[config
.TemplateGet()](parser
.line
, &function
, &id
, &dw0
, &dw1
) == 0 {
119 pad
:= padInfo
{id
: id
,
123 ownership
: parser
.hostOwnershipGet(id
)}
124 parser
.padmap
= append(parser
.padmap
, pad
)
127 fmt
.Printf("This template (%d) does not match!\n", config
.TemplateGet())
131 // communityGroupExtract
132 func (parser
*ParserData
) communityGroupExtract() {
133 pad
:= padInfo
{function
: parser
.line
}
134 parser
.padmap
= append(parser
.padmap
, pad
)
137 // PlatformSpecificInterfaceSet - specific interface for the platform selected
138 // in the configuration
139 func (parser
*ParserData
) PlatformSpecificInterfaceSet() {
140 var platform
= map[uint8]PlatformSpecific
{
141 config
.SunriseType
: snr
.PlatformSpecific
{},
142 // See platforms/lbg/macro.go
143 config
.LewisburgType
: lbg
.PlatformSpecific
{
144 InheritanceTemplate
: snr
.PlatformSpecific
{},
146 config
.ApolloType
: apl
.PlatformSpecific
{},
147 config
.CannonType
: cnl
.PlatformSpecific
{
148 InheritanceTemplate
: snr
.PlatformSpecific
{},
151 parser
.platform
= platform
[config
.PlatformGet()]
154 // PadMapFprint - print pad info map to file
155 func (parser
*ParserData
) PadMapFprint() {
156 for _
, pad
:= range parser
.padmap
{
163 str
:= parser
.platform
.GenMacro(pad
.id
, pad
.dw0
, pad
.dw1
, pad
.ownership
)
164 pad
.padInfoMacroFprint(str
)
169 // Register - read specific platform registers (32 bits)
170 // line : string from file with pad config map
171 // nameTemplate : register name femplate to filter parsed lines
173 // valid : true if the dump of the register in intertool.log is set in accordance
175 // name : full register name
176 // offset : register offset relative to the base address
177 // value : register value
178 func (parser
*ParserData
) Register(nameTemplate
string) (
179 valid
bool, name
string, offset
uint32, value
uint32) {
180 if strings
.Contains(parser
.line
, nameTemplate
) &&
181 config
.TemplateGet() == config
.TempInteltool
{
182 if registerInfoTemplate(parser
.line
, &name
, &offset
, &value
) == 0 {
183 fmt
.Printf("\n\t/* %s : 0x%x : 0x%x */\n", name
, offset
, value
)
184 return true, name
, offset
, value
187 return false, "ERROR", 0, 0
190 // padOwnershipExtract - extract Host Software Pad Ownership from inteltool dump
191 // return true if success
192 func (parser
*ParserData
) padOwnershipExtract() bool {
194 status
, name
, offset
, value
:= parser
.Register("HOSTSW_OWN_GPP_")
196 _
, group
= parser
.platform
.GroupNameExtract(parser
.line
)
197 parser
.ownership
[group
] = value
198 fmt
.Printf("\n\t/* padOwnershipExtract: [offset 0x%x] %s = 0x%x */\n",
199 offset
, name
, parser
.ownership
[group
])
204 // padConfigurationExtract - reads GPIO configuration registers and returns true if the
205 // information from the inteltool log was successfully parsed.
206 func (parser
*ParserData
) padConfigurationExtract() bool {
207 // Only for Sunrise or CannonLake, and only for inteltool.log file template
208 if config
.TemplateGet() != config
.TempInteltool || config
.IsPlatformApollo() {
211 return parser
.padOwnershipExtract()
214 // Parse pads groupe information in the inteltool log file
215 // ConfigFile : name of inteltool log file
216 func (parser
*ParserData
) Parse() {
217 // Read all lines from inteltool log file
218 fmt
.Println("Parse IntelTool Log File...")
220 // determine the platform type and set the interface for it
221 parser
.PlatformSpecificInterfaceSet()
223 // map of thepad ownership registers for the GPIO controller
224 parser
.ownership
= make(map[string]uint32)
226 scanner
:= bufio
.NewScanner(config
.InputRegDumpFile
)
228 parser
.line
= scanner
.Text()
229 isIncluded
, _
:= common
.KeywordsCheck(parser
.line
, "GPIO Community", "GPIO Group");
231 parser
.communityGroupExtract()
232 } else if !parser
.padConfigurationExtract() && parser
.platform
.KeywordCheck(parser
.line
) {
233 if parser
.padInfoExtract() != 0 {
234 fmt
.Println("...error!")
238 fmt
.Println("...done!")