1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <device/pci_ops.h>
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
8 #include <southbridge/intel/common/pmutil.h>
9 #include <ec/acpi/ec.h>
11 #include <ec/lenovo/h8/h8.h>
18 static void mainboard_smi_save_cmos(void)
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
));
32 static void mainboard_smi_dock_connect(void)
36 if (!dock_connect()) {
38 /* set dock LED to indicate status */
42 /* blink dock LED to indicate failure */
48 static void mainboard_smi_dock_disconnect(void)
54 int mainboard_io_trap_handler(int smif
)
57 case SMI_DOCK_CONNECT
:
58 mainboard_smi_dock_connect();
61 case SMI_DOCK_DISCONNECT
:
62 mainboard_smi_dock_disconnect();
66 mainboard_smi_save_cmos();
72 /* On success, the IO Trap Handler returns 1
73 * On failure, the IO Trap Handler returns a value != 1 */
77 static void mainboard_smi_brightness_up(void)
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);
85 static void mainboard_smi_brightness_down(void)
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);
93 static void mainboard_smi_handle_ec_sci(void)
95 u8 status
= inb(EC_SC
);
98 if (!(status
& EC_SCI_EVT
))
102 printk(BIOS_DEBUG
, "EC event %#02x\n", event
);
107 mainboard_smi_brightness_up();
108 mainboard_smi_save_cmos();
110 /* brightness down */
112 mainboard_smi_brightness_down();
113 mainboard_smi_save_cmos();
121 mainboard_smi_dock_disconnect();
126 mainboard_smi_dock_connect();
133 void mainboard_smi_gpi(u32 gpi
)
135 if (gpi
& (1 << GPE_EC_SCI
))
136 mainboard_smi_handle_ec_sci();
139 int mainboard_smi_apmc(u8 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);
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);