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 int mainboard_io_trap_handler(int smif
)
35 case SMI_DOCK_CONNECT
:
38 if (!dock_connect()) {
40 /* set dock LED to indicate status */
44 /* blink dock LED to indicate failure */
50 case SMI_DOCK_DISCONNECT
:
56 mainboard_smi_save_cmos();
62 /* On success, the IO Trap Handler returns 1
63 * On failure, the IO Trap Handler returns a value != 1 */
67 static void mainboard_smi_brightness_up(void)
71 if ((value
= pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) < 0xf0)
72 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value
+ 0x10) | 0xf);
75 static void mainboard_smi_brightness_down(void)
79 if ((value
= pci_read_config8(PCI_DEV(0, 2, 1), 0xf4)) > 0x10)
80 pci_write_config8(PCI_DEV(0, 2, 1), 0xf4, (value
- 0x10) & 0xf0);
83 static void mainboard_smi_handle_ec_sci(void)
85 u8 status
= inb(EC_SC
);
88 if (!(status
& EC_SCI_EVT
))
92 printk(BIOS_DEBUG
, "EC event %#02x\n", event
);
97 mainboard_smi_brightness_up();
98 mainboard_smi_save_cmos();
100 /* brightness down */
102 mainboard_smi_brightness_down();
103 mainboard_smi_save_cmos();
111 mainboard_io_trap_handler(SMI_DOCK_DISCONNECT
);
116 mainboard_io_trap_handler(SMI_DOCK_CONNECT
);
123 void mainboard_smi_gpi(u32 gpi
)
125 if (gpi
& (1 << GPE_EC_SCI
))
126 mainboard_smi_handle_ec_sci();
129 int mainboard_smi_apmc(u8 data
)
132 case APM_CNT_ACPI_ENABLE
:
133 /* use 0x1600/0x1604 to prevent races with userspace */
134 ec_set_ports(0x1604, 0x1600);
135 /* route H8SCI to SCI */
136 gpi_route_interrupt(GPE_EC_SCI
, GPI_IS_SCI
);
137 /* discard all events, and enable attention */
138 ec_write(0x80, 0x01);
140 case APM_CNT_ACPI_DISABLE
:
141 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
142 provide a EC query function */
143 ec_set_ports(0x66, 0x62);
144 /* route H8SCI# to SMI */
145 gpi_route_interrupt(GPE_EC_SCI
, GPI_IS_SMI
);
146 /* discard all events, and enable attention */
147 ec_write(0x80, 0x01);