Debian Codegraph @

src/mainboard/lenovo/x60/smihandler.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <arch/io.h>
4 #include <device/pci_ops.h>
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
7 #include <soc/nvs.h>
8 #include <southbridge/intel/common/pmutil.h>
9 #include <ec/acpi/ec.h>
10 #include <option.h>
11 #include <ec/lenovo/h8/h8.h>
12 #include <delay.h>
13 #include "dock.h"
14 #include "smi.h"
15
16 #define GPE_EC_SCI 12
17
18 static void mainboard_smi_save_cmos(void)
19 {
20 u8 tmp70, tmp72;
21
22 tmp70 = inb(0x70);
23 tmp72 = inb(0x72);
24
25 set_uint_option("tft_brightness", pci_read_config8(PCI_DEV(0, 2, 1), 0xf4));
26 set_uint_option("volume", ec_read(H8_VOLUME_CONTROL));
27
28 outb(tmp70, 0x70);
29 outb(tmp72, 0x72);
30 }
31
32 static void mainboard_smi_dock_connect(void)
33 {
34 ec_clr_bit(0x03, 2);
35 mdelay(250);
36 if (!dock_connect()) {
37 ec_set_bit(0x03, 2);
38 /* set dock LED to indicate status */
39 ec_write(0x0c, 0x09);
40 ec_write(0x0c, 0x88);
41 } else {
42 /* blink dock LED to indicate failure */
43 ec_write(0x0c, 0x08);
44 ec_write(0x0c, 0xc9);
45 }
46 }
47
48 static void mainboard_smi_dock_disconnect(void)
49 {
50 ec_clr_bit(0x03, 2);
51 dock_disconnect();
52 }
53
54 int mainboard_io_trap_handler(int smif)
55 {
56 switch (smif) {
57 case SMI_DOCK_CONNECT:
58 mainboard_smi_dock_connect();
59 break;
60
61 case SMI_DOCK_DISCONNECT:
62 mainboard_smi_dock_disconnect();
63 break;
64
65 case SMI_SAVE_CMOS:
66 mainboard_smi_save_cmos();
67 break;
68 default:
69 return 0;
70 }
71
72 /* On success, the IO Trap Handler returns 1
73 * On failure, the IO Trap Handler returns a value != 1 */
74 return 1;
75 }
76
77 static void mainboard_smi_brightness_up(void)
78 {
79 u8 value;
80
81 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) < 0xf0)
82 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value + 0x10) | 0xf);
83 }
84
85 static void mainboard_smi_brightness_down(void)
86 {
87 u8 value;
88
89 if ((value = pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) > 0x10)
90 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value - 0x10) & 0xf0);
91 }
92
93 static void mainboard_smi_handle_ec_sci(void)
94 {
95 u8 status = inb(EC_SC);
96 u8 event;
97
98 if (!(status & EC_SCI_EVT))
99 return;
100
101 event = ec_query();
102 printk(BIOS_DEBUG, "EC event %#02x\n", event);
103
104 switch (event) {
105 /* brightness up */
106 case 0x14:
107 mainboard_smi_brightness_up();
108 mainboard_smi_save_cmos();
109 break;
110 /* brightness down */
111 case 0x15:
112 mainboard_smi_brightness_down();
113 mainboard_smi_save_cmos();
114 break;
115 /* Fn-F9 key */
116 case 0x18:
117 /* Power loss */
118 case 0x27:
119 /* Undock Key */
120 case 0x50:
121 mainboard_smi_dock_disconnect();
122 break;
123 /* Dock Event */
124 case 0x37:
125 case 0x58:
126 mainboard_smi_dock_connect();
127 break;
128 default:
129 break;
130 }
131 }
132
133 void mainboard_smi_gpi(u32 gpi)
134 {
135 if (gpi & (1 << GPE_EC_SCI))
136 mainboard_smi_handle_ec_sci();
137 }
138
139 int mainboard_smi_apmc(u8 data)
140 {
141 switch (data) {
142 case APM_CNT_ACPI_ENABLE:
143 /* use 0x1600/0x1604 to prevent races with userspace */
144 ec_set_ports(0x1604, 0x1600);
145 /* route H8SCI to SCI */
146 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
147 /* discard all events, and enable attention */
148 ec_write(0x80, 0x01);
149 break;
150 case APM_CNT_ACPI_DISABLE:
151 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
152 provide a EC query function */
153 ec_set_ports(0x66, 0x62);
154 /* route H8SCI# to SMI */
155 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
156 /* discard all events, and enable attention */
157 ec_write(0x80, 0x01);
158 break;
159 default:
160 break;
161 }
162 return 0;
163 }