gpio_common.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* code to generate common GPIO code for Intel 6/7/8 Series Chipset */
  2. package main
  3. import (
  4. "fmt"
  5. "os"
  6. )
  7. func writeGPIOSet(ctx Context, sb *os.File,
  8. val uint32, set uint, partno int, constraint uint32) {
  9. max := uint(32)
  10. if set == 3 {
  11. max = 12
  12. }
  13. bits := [6][2]string{
  14. {"GPIO_MODE_NATIVE", "GPIO_MODE_GPIO"},
  15. {"GPIO_DIR_OUTPUT", "GPIO_DIR_INPUT"},
  16. {"GPIO_LEVEL_LOW", "GPIO_LEVEL_HIGH"},
  17. {"GPIO_RESET_PWROK", "GPIO_RESET_RSMRST"},
  18. {"GPIO_NO_INVERT", "GPIO_INVERT"},
  19. {"GPIO_NO_BLINK", "GPIO_BLINK"},
  20. }
  21. for i := uint(0); i < max; i++ {
  22. if (constraint>>i)&1 == 1 {
  23. fmt.Fprintf(sb, " .gpio%d = %s,\n",
  24. (set-1)*32+i,
  25. bits[partno][(val>>i)&1])
  26. }
  27. }
  28. }
  29. func GPIO(ctx Context, inteltool InteltoolData) {
  30. var constraint uint32
  31. gpio := Create(ctx, "gpio.c")
  32. defer gpio.Close()
  33. AddBootBlockFile("gpio.c", "")
  34. AddROMStageFile("gpio.c", "")
  35. Add_gpl(gpio)
  36. gpio.WriteString("#include <southbridge/intel/common/gpio.h>\n\n")
  37. addresses := [3][6]int{
  38. {0x00, 0x04, 0x0c, 0x60, 0x2c, 0x18},
  39. {0x30, 0x34, 0x38, 0x64, -1, -1},
  40. {0x40, 0x44, 0x48, 0x68, -1, -1},
  41. }
  42. for set := 1; set <= 3; set++ {
  43. for partno, part := range []string{"mode", "direction", "level", "reset", "invert", "blink"} {
  44. addr := addresses[set-1][partno]
  45. if addr < 0 {
  46. continue
  47. }
  48. fmt.Fprintf(gpio, "static const struct pch_gpio_set%d pch_gpio_set%d_%s = {\n",
  49. set, set, part)
  50. constraint = 0xffffffff
  51. switch part {
  52. case "direction":
  53. /* Ignored on native mode */
  54. constraint = inteltool.GPIO[uint16(addresses[set-1][0])]
  55. case "level":
  56. /* Level doesn't matter for input */
  57. constraint = inteltool.GPIO[uint16(addresses[set-1][0])]
  58. constraint &^= inteltool.GPIO[uint16(addresses[set-1][1])]
  59. case "reset":
  60. /* Only show reset */
  61. constraint = inteltool.GPIO[uint16(addresses[set-1][3])]
  62. case "invert":
  63. /* Only on input and only show inverted GPIO */
  64. constraint = inteltool.GPIO[uint16(addresses[set-1][0])]
  65. constraint &= inteltool.GPIO[uint16(addresses[set-1][1])]
  66. constraint &= inteltool.GPIO[uint16(addresses[set-1][4])]
  67. case "blink":
  68. /* Only on output and only show blinking GPIO */
  69. constraint = inteltool.GPIO[uint16(addresses[set-1][0])]
  70. constraint &^= inteltool.GPIO[uint16(addresses[set-1][1])]
  71. constraint &= inteltool.GPIO[uint16(addresses[set-1][5])]
  72. }
  73. writeGPIOSet(ctx, gpio, inteltool.GPIO[uint16(addr)], uint(set), partno, constraint)
  74. gpio.WriteString("};\n\n")
  75. }
  76. }
  77. gpio.WriteString(`const struct pch_gpio_map mainboard_gpio_map = {
  78. .set1 = {
  79. .mode = &pch_gpio_set1_mode,
  80. .direction = &pch_gpio_set1_direction,
  81. .level = &pch_gpio_set1_level,
  82. .blink = &pch_gpio_set1_blink,
  83. .invert = &pch_gpio_set1_invert,
  84. .reset = &pch_gpio_set1_reset,
  85. },
  86. .set2 = {
  87. .mode = &pch_gpio_set2_mode,
  88. .direction = &pch_gpio_set2_direction,
  89. .level = &pch_gpio_set2_level,
  90. .reset = &pch_gpio_set2_reset,
  91. },
  92. .set3 = {
  93. .mode = &pch_gpio_set3_mode,
  94. .direction = &pch_gpio_set3_direction,
  95. .level = &pch_gpio_set3_level,
  96. .reset = &pch_gpio_set3_reset,
  97. },
  98. };
  99. `)
  100. }