drivers/i2c/gpiomux: Add chip driver for multiplexed I2C bus
[coreboot.git] / util / intelp2m / main.go
bloba7bbc91079110fda2147e7bf1814ec55aa238b14
1 package main
3 import "flag"
4 import "fmt"
5 import "os"
7 import "./parser"
8 import "./config"
10 // generateOutputFile - generates include file
11 // parser : parser data structure
12 func generateOutputFile(parser *parser.ParserData) (err error) {
14 config.OutputGenFile.WriteString(`/* SPDX-License-Identifier: GPL-2.0-only */
16 #ifndef CFG_GPIO_H
17 #define CFG_GPIO_H
19 #include <gpio.h>
21 /* Pad configuration was generated automatically using intelp2m utility */
22 static const struct pad_config gpio_table[] = {
24 // Add the pads map
25 parser.PadMapFprint()
26 config.OutputGenFile.WriteString(`};
28 #endif /* CFG_GPIO_H */
30 return nil
33 // main
34 func main() {
35 // Command line arguments
36 inputFileName := flag.String("file",
37 "inteltool.log",
38 "the path to the inteltool log file\n")
40 outputFileName := flag.String("o",
41 "generate/gpio.h",
42 "the path to the generated file with GPIO configuration\n")
44 ignFlag := flag.Bool("ign",
45 false,
46 "exclude fields that should be ignored from advanced macros\n")
48 nonCheckFlag := flag.Bool("n",
49 false,
50 "Generate macros without checking.\n" +
51 "\tIn this case, some fields of the configuration registers\n" +
52 "\tDW0 will be ignored.\n")
54 infoLevels := []*bool {
55 flag.Bool("i", false, "Show pads function in the comments"),
56 flag.Bool("ii", false, "Show DW0/DW1 value in the comments"),
57 flag.Bool("iii", false, "Show ignored bit fields in the comments"),
58 flag.Bool("iiii", false, "Show target PAD_CFG() macro in the comments"),
61 template := flag.Int("t", 0, "template type number\n"+
62 "\t0 - inteltool.log (default)\n"+
63 "\t1 - gpio.h\n"+
64 "\t2 - your template\n\t")
66 platform := flag.String("p", "snr", "set platform:\n"+
67 "\tsnr - Sunrise PCH or Skylake/Kaby Lake SoC\n"+
68 "\tlbg - Lewisburg PCH with Xeon SP\n"+
69 "\tapl - Apollo Lake SoC\n"+
70 "\tcnl - CannonLake-LP or Whiskeylake/Coffelake/Cometlake-U SoC\n")
72 filedstyle := flag.String("fld", "none", "set fileds macros style:\n"+
73 "\tcb - use coreboot style for bit fields macros\n"+
74 "\tfsp - use fsp style\n"+
75 "\traw - do not convert, print as is\n")
77 flag.Parse()
79 config.IgnoredFieldsFlagSet(*ignFlag)
80 config.NonCheckingFlagSet(*nonCheckFlag)
82 for level, flag := range infoLevels {
83 if *flag {
84 config.InfoLevelSet(level + 1)
85 fmt.Printf("Info level: Use level %d!\n", level + 1)
86 break
90 if !config.TemplateSet(*template) {
91 fmt.Printf("Error! Unknown template format of input file!\n")
92 os.Exit(1)
95 if valid := config.PlatformSet(*platform); valid != 0 {
96 fmt.Printf("Error: invalid platform -%s!\n", *platform)
97 os.Exit(1)
100 fmt.Println("Log file:", *inputFileName)
101 fmt.Println("Output generated file:", *outputFileName)
103 inputRegDumpFile, err := os.Open(*inputFileName)
104 if err != nil {
105 fmt.Printf("Error: inteltool log file was not found!\n")
106 os.Exit(1)
109 if config.FldStyleSet(*filedstyle) != 0 {
110 fmt.Printf("Error! Unknown bit fields style option -%s!\n", *filedstyle)
111 os.Exit(1)
114 // create dir for output files
115 err = os.MkdirAll("generate", os.ModePerm)
116 if err != nil {
117 fmt.Printf("Error! Can not create a directory for the generated files!\n")
118 os.Exit(1)
121 // create empty gpio.h file
122 outputGenFile, err := os.Create(*outputFileName)
123 if err != nil {
124 fmt.Printf("Error: unable to generate GPIO config file!\n")
125 os.Exit(1)
128 defer inputRegDumpFile.Close()
129 defer outputGenFile.Close()
131 config.OutputGenFile = outputGenFile
132 config.InputRegDumpFile = inputRegDumpFile
134 parser := parser.ParserData{}
135 parser.Parse()
137 // gpio.h
138 err = generateOutputFile(&parser)
139 if err != nil {
140 fmt.Printf("Error! Can not create the file with GPIO configuration!\n")
141 os.Exit(1)