2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <arch/acpi.h>
18 #include <console/console.h>
19 #include <device/device.h>
20 #include <device/pnp.h>
21 #include <ec/acpi/ec.h>
25 #include <pc80/mc146818rtc.h>
26 #include <pc80/keyboard.h>
31 void h8_trackpoint_enable(int on
)
33 ec_write(H8_TRACKPOINT_CTRL
,
34 on
? H8_TRACKPOINT_ON
: H8_TRACKPOINT_OFF
);
38 /* Controls radio-off pin in WLAN MiniPCIe slot. */
39 void h8_wlan_enable(int on
)
47 /* Controls radio-off pin in WWAN MiniPCIe slot. */
48 static void h8_wwan_enable(int on
)
56 /* Controls radio-off pin in UWB MiniPCIe slot. */
57 static void h8_uwb_enable(int on
)
65 static void h8_fn_ctrl_swap(int on
)
74 SECONDARY_BATTERY
= 0,
78 /* h8 charge priority. Defines if primary or secondary
79 * battery is charged first.
80 * Because NVRAM is complete the otherway around as this register,
83 static void h8_charge_priority(enum battery battery
)
85 if (battery
== PRIMARY_BATTERY
)
91 static void h8_sticky_fn(int on
)
99 static void h8_log_ec_version(void)
105 len
= h8_build_id_and_function_spec_version(ecfw
, sizeof ecfw
- 1);
108 fwvh
= ec_read(0xe9);
109 fwvl
= ec_read(0xe8);
111 printk(BIOS_INFO
, "EC Firmware ID %s, Version %d.%d%d%c\n", ecfw
,
112 fwvh
>> 4, fwvh
& 0x0f, fwvl
>> 4, 0x41 + (fwvl
& 0xf));
115 void h8_set_audio_mute(int mute
)
123 void h8_enable_event(int event
)
125 if (event
< 0 || event
> 127)
128 ec_set_bit(0x10 + (event
>> 3), event
& 7);
131 void h8_disable_event(int event
)
133 if (event
< 0 || event
> 127)
136 ec_clr_bit(0x10 + (event
>> 3), event
& 7);
140 void h8_usb_power_enable(int onoff
)
148 int h8_ultrabay_device_present(void)
150 return ec_read(H8_STATUS1
) & 0x5 ? 0 : 1;
153 u8
h8_build_id_and_function_spec_version(char *buf
, u8 buf_len
)
156 char str
[16 + 1]; /* 16 ASCII chars + \0 */
159 for (i
= 0; i
< 8; i
++) {
160 c
= ec_read(0xf0 + i
);
161 if (c
< 0x20 || c
> 0x7f) {
162 i
= snprintf(str
, sizeof (str
), "*INVALID");
168 /* EC firmware function specification version */
169 i
+= snprintf(str
+ i
, sizeof (str
) - i
, "-%u.%u", ec_read(0xef), ec_read(0xeb));
177 #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES)
178 static void h8_smbios_strings(struct device
*dev
, struct smbios_type11
*t
)
180 char tpec
[] = "IBM ThinkPad Embedded Controller -[ ]-";
182 h8_build_id_and_function_spec_version(tpec
+ 35, 17);
184 t
->count
= smbios_add_string(t
->eos
, tpec
);
188 static void h8_init(device_t dev
)
190 pc_keyboard_init(NO_AUX_DEVICE
);
193 struct device_operations h8_dev_ops
= {
194 #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES)
195 .get_smbios_strings
= h8_smbios_strings
,
200 static void h8_enable(struct device
*dev
)
202 struct ec_lenovo_h8_config
*conf
= dev
->chip_info
;
204 u8 beepmask0
, beepmask1
, reg8
;
206 dev
->ops
= &h8_dev_ops
;
210 /* Always enable I/O range 0x1600-0x160f and thermal management */
211 reg8
= conf
->config0
;
212 reg8
|= H8_CONFIG0_SMM_H8_ENABLE
;
213 reg8
|= H8_CONFIG0_TC_ENABLE
;
214 ec_write(H8_CONFIG0
, reg8
);
216 reg8
= conf
->config1
;
217 if (conf
->has_keyboard_backlight
) {
218 if (get_option(&val
, "backlight") != CB_SUCCESS
)
219 val
= 0; /* Both backlights. */
220 reg8
= (reg8
& 0xf3) | ((val
& 0x3) << 2);
222 ec_write(H8_CONFIG1
, reg8
);
223 ec_write(H8_CONFIG2
, conf
->config2
);
224 ec_write(H8_CONFIG3
, conf
->config3
);
226 beepmask0
= conf
->beepmask0
;
227 beepmask1
= conf
->beepmask1
;
229 if (conf
->has_power_management_beeps
230 && get_option(&val
, "power_management_beeps") == CB_SUCCESS
236 if (conf
->has_power_management_beeps
) {
237 if (get_option(&val
, "low_battery_beep") != CB_SUCCESS
)
245 ec_write(H8_SOUND_ENABLE0
, beepmask0
);
246 ec_write(H8_SOUND_ENABLE1
, beepmask1
);
248 /* silence sounds in queue */
249 ec_write(H8_SOUND_REPEAT
, 0x00);
250 ec_write(H8_SOUND_REG
, 0x00);
252 ec_write(0x10, conf
->event0_enable
);
253 ec_write(0x11, conf
->event1_enable
);
254 ec_write(0x12, conf
->event2_enable
);
255 ec_write(0x13, conf
->event3_enable
);
256 ec_write(0x14, conf
->event4_enable
);
257 ec_write(0x15, conf
->event5_enable
);
258 ec_write(0x16, conf
->event6_enable
);
259 ec_write(0x17, conf
->event7_enable
);
260 ec_write(0x18, conf
->event8_enable
);
261 ec_write(0x19, conf
->event9_enable
);
262 ec_write(0x1a, conf
->eventa_enable
);
263 ec_write(0x1b, conf
->eventb_enable
);
264 ec_write(0x1c, conf
->eventc_enable
);
265 ec_write(0x1d, conf
->eventd_enable
);
266 ec_write(0x1e, conf
->evente_enable
);
267 ec_write(0x1f, conf
->eventf_enable
);
269 ec_write(H8_FAN_CONTROL
, H8_FAN_CONTROL_AUTO
);
270 ec_write(H8_USB_ALWAYS_ON
, ec_read(H8_USB_ALWAYS_ON
) &
271 ~H8_USB_ALWAYS_ON_ENABLE
);
273 if (get_option(&val
, "wlan") != CB_SUCCESS
)
277 h8_trackpoint_enable(1);
278 h8_usb_power_enable(1);
280 if (get_option(&val
, "volume") == CB_SUCCESS
&& !acpi_is_wakeup_s3())
281 ec_write(H8_VOLUME_CONTROL
, val
);
283 val
= h8_has_bdc(dev
) && h8_bluetooth_nv_enable();
284 h8_bluetooth_enable(val
);
286 if (get_option(&val
, "wwan") != CB_SUCCESS
)
292 if (get_option(&val
, "uwb") != CB_SUCCESS
)
298 if (get_option(&val
, "fn_ctrl_swap") != CB_SUCCESS
)
300 h8_fn_ctrl_swap(val
);
302 if (get_option(&val
, "sticky_fn") != CB_SUCCESS
)
306 if (get_option(&val
, "first_battery") != CB_SUCCESS
)
307 val
= PRIMARY_BATTERY
;
308 h8_charge_priority(val
);
310 h8_set_audio_mute(0);
312 #if !IS_ENABLED(CONFIG_H8_DOCK_EARLY_INIT)
313 h8_mainboard_init_dock();
317 struct chip_operations ec_lenovo_h8_ops
= {
318 CHIP_NAME("Lenovo H8 EC")
319 .enable_dev
= h8_enable
,