3rdparty/blobs: Update for current Intel microcode
[coreboot.git] / util / autoport / ec_lenovo.go
blobc2dd333c73b66f57bfb4fcaf049de053c039d003
1 package main
3 import "fmt"
5 func LenovoEC(ctx Context) {
6 ap := Create(ctx, "acpi/platform.asl")
7 defer ap.Close()
9 wakeGPE := 13
11 sbGPE := GuessECGPE(ctx)
12 var GPE int
13 var GPEUnsure bool
14 if sbGPE < 0 {
15 sbGPE = SouthBridge.EncodeGPE(1)
16 GPE = 1
17 GPEUnsure = true
18 SouthBridge.NeedRouteGPIOManually()
19 } else {
20 GPE = SouthBridge.DecodeGPE(sbGPE)
21 GPEUnsure = false
24 SouthBridge.EnableGPE(wakeGPE)
25 SouthBridge.EnableGPE(GPE)
27 GPEDefine := DSDTDefine{
28 Key: "THINKPAD_EC_GPE",
31 GPEDefine.Value = fmt.Sprintf("%d", sbGPE)
32 if GPEUnsure {
33 GPEDefine.Comment = "FIXME: Check this"
36 DSDTDefines = append(DSDTDefines,
37 DSDTDefine{
38 Key: "EC_LENOVO_H8_ME_WORKAROUND",
39 Value: "1",
40 }, GPEDefine)
42 ap.WriteString(
43 `Method(_WAK,1)
45 /* ME may not be up yet. */
46 Store (0, \_TZ.MEB1)
47 Store (0, \_TZ.MEB2)
48 Return(Package(){0,0})
51 Method(_PTS,1)
53 \_SB.PCI0.LPCB.EC.RADI(0)
57 si := Create(ctx, "acpi/superio.asl")
58 defer si.Close()
60 si.WriteString("#include <drivers/pc80/pc/ps2_controller.asl>\n")
62 dock := Create(ctx, "dock.c")
63 defer dock.Close()
65 AddRAMStageFile("dock.c", "")
67 dock.WriteString(
68 `#include <ec/lenovo/h8/h8.h>
70 void h8_mainboard_init_dock (void)
72 /* FIXME: fill this if needed. */
76 /* FIXME:XX Move this to ec/lenovo. */
77 smi := Create(ctx, "smihandler.c")
78 defer smi.Close()
80 AddSMMFile("smihandler.c", "")
82 Add_gpl(smi)
83 smi.WriteString(
84 `#include <arch/io.h>
85 #include <console/console.h>
86 #include <cpu/x86/smm.h>
87 #include <ec/acpi/ec.h>
88 #include <ec/lenovo/h8/h8.h>
89 #include <delay.h>
90 #include <` + SouthBridge.GetGPIOHeader() + ">\n\n")
92 if GPEUnsure {
93 smi.WriteString("/* FIXME: check this */\n")
95 fmt.Fprintf(smi, "#define GPE_EC_SCI %d\n", GPE)
97 smi.WriteString("/* FIXME: check this */\n")
98 fmt.Fprintf(smi, "#define GPE_EC_WAKE %d\n", wakeGPE)
100 smi.WriteString(`
101 static void mainboard_smm_init(void)
103 printk(BIOS_DEBUG, "initializing SMI\n");
104 /* Enable 0x1600/0x1600 register pair */
105 ec_set_bit(0x00, 0x05);
108 int mainboard_io_trap_handler(int smif)
110 static int smm_initialized;
112 if (!smm_initialized) {
113 mainboard_smm_init();
114 smm_initialized = 1;
117 return 0;
120 static void mainboard_smi_handle_ec_sci(void)
122 u8 status = inb(EC_SC);
123 u8 event;
125 if (!(status & EC_SCI_EVT))
126 return;
128 event = ec_query();
129 printk(BIOS_DEBUG, "EC event %02x\n", event);
132 void mainboard_smi_gpi(u32 gpi_sts)
134 if (gpi_sts & (1 << GPE_EC_SCI))
135 mainboard_smi_handle_ec_sci();
138 int mainboard_smi_apmc(u8 data)
140 switch (data) {
141 case APM_CNT_ACPI_ENABLE:
142 /* use 0x1600/0x1604 to prevent races with userspace */
143 ec_set_ports(0x1604, 0x1600);
144 /* route EC_SCI to SCI */
145 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
146 /* discard all events, and enable attention */
147 ec_write(0x80, 0x01);
148 break;
149 case APM_CNT_ACPI_DISABLE:
150 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
151 provide a EC query function */
152 ec_set_ports(0x66, 0x62);
153 /* route EC_SCI to SMI */
154 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
155 /* discard all events, and enable attention */
156 ec_write(0x80, 0x01);
157 break;
158 default:
159 break;
161 return 0;
164 void mainboard_smi_sleep(u8 slp_typ)
166 if (slp_typ == 3) {
167 u8 ec_wake = ec_read(0x32);
168 /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
169 if (ec_wake & 0x14) {
170 /* Redirect EC WAKE GPE to SCI. */
171 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);
177 ec := Create(ctx, "acpi/ec.asl")
178 defer ec.Close()
180 ec.WriteString("#include <ec/lenovo/h8/acpi/ec.asl>\n")
182 KconfigBool["EC_LENOVO_PMH7"] = true
183 KconfigBool["EC_LENOVO_H8"] = true
185 pmh := DevTreeNode{
186 Chip: "ec/lenovo/pmh7",
187 Registers: map[string]string{
188 "backlight_enable": "0x01",
189 "dock_event_enable": "0x01",
191 Children: []DevTreeNode{
192 DevTreeNode{
193 Chip: "pnp",
194 Comment: "dummy",
195 Dev: 0xff,
196 Func: 1,
200 PutChip("lpc", pmh)
202 ecs := ctx.InfoSource.GetEC()
203 h8 := DevTreeNode{
204 Chip: "ec/lenovo/h8",
205 Children: []DevTreeNode{
206 DevTreeNode{
207 Chip: "pnp",
208 Comment: "dummy",
209 Dev: 0xff,
210 Func: 2,
211 IOs: map[uint16]uint16{
212 0x60: 0x62,
213 0x62: 0x66,
214 0x64: 0x1600,
215 0x66: 0x1604,
219 Comment: "FIXME: has_keyboard_backlight, has_power_management_beeps, has_uwb",
220 Registers: map[string]string{
221 "config0": FormatHex8(ecs[0]),
222 "config1": FormatHex8(ecs[1]),
223 "config2": FormatHex8(ecs[2]),
224 "config3": FormatHex8(ecs[3]),
225 "beepmask0": FormatHex8(ecs[4]),
226 "beepmask1": FormatHex8(ecs[5]),
229 for i := 0; i < 0x10; i++ {
230 if ecs[0x10+i] != 0 {
231 h8.Registers[fmt.Sprintf("event%x_enable", i)] = FormatHex8(ecs[0x10+i])
234 PutChip("lpc", h8)
236 eeprom := DevTreeNode{
237 Chip: "drivers/i2c/at24rf08c",
238 Comment: "eeprom, 8 virtual devices, same chip",
239 Children: []DevTreeNode{
240 DevTreeNode{
241 Chip: "i2c",
242 Dev: 0x54,
244 DevTreeNode{
245 Chip: "i2c",
246 Dev: 0x55,
248 DevTreeNode{
249 Chip: "i2c",
250 Dev: 0x56,
252 DevTreeNode{
253 Chip: "i2c",
254 Dev: 0x57,
256 DevTreeNode{
257 Chip: "i2c",
258 Dev: 0x5c,
260 DevTreeNode{
261 Chip: "i2c",
262 Dev: 0x5d,
264 DevTreeNode{
265 Chip: "i2c",
266 Dev: 0x5e,
268 DevTreeNode{
269 Chip: "i2c",
270 Dev: 0x5f,
274 PutChip("smbus", eeprom)