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>
26 #include <pc80/mc146818rtc.h>
27 #include <pc80/keyboard.h>
32 static void h8_bluetooth_enable(int on
)
40 void h8_trackpoint_enable(int on
)
42 ec_write(H8_TRACKPOINT_CTRL
,
43 on
? H8_TRACKPOINT_ON
: H8_TRACKPOINT_OFF
);
47 /* Controls radio-off pin in WLAN MiniPCIe slot. */
48 void h8_wlan_enable(int on
)
56 /* Controls radio-off pin in WWAN MiniPCIe slot. */
57 static void h8_wwan_enable(int on
)
65 /* Controls radio-off pin in UWB MiniPCIe slot. */
66 static void h8_uwb_enable(int on
)
74 static void h8_fn_ctrl_swap(int on
)
83 SECONDARY_BATTERY
= 0,
87 /* h8 charge priority. Defines if primary or secondary
88 * battery is charged first.
89 * Because NVRAM is complete the otherway around as this register,
92 static void h8_charge_priority(enum battery battery
)
94 if (battery
== PRIMARY_BATTERY
)
100 static void h8_sticky_fn(int on
)
108 static void h8_log_ec_version(void)
114 len
= h8_build_id_and_function_spec_version(ecfw
, sizeof ecfw
- 1);
117 fwvh
= ec_read(0xe9);
118 fwvl
= ec_read(0xe8);
120 printk(BIOS_INFO
, "EC Firmware ID %s, Version %d.%d%d%c\n", ecfw
,
121 fwvh
>> 4, fwvh
& 0x0f, fwvl
>> 4, 0x41 + (fwvl
& 0xf));
124 void h8_set_audio_mute(int mute
)
132 void h8_enable_event(int event
)
134 if (event
< 0 || event
> 127)
137 ec_set_bit(0x10 + (event
>> 3), event
& 7);
140 void h8_disable_event(int event
)
142 if (event
< 0 || event
> 127)
145 ec_clr_bit(0x10 + (event
>> 3), event
& 7);
149 void h8_usb_power_enable(int onoff
)
157 int h8_ultrabay_device_present(void)
159 return ec_read(H8_STATUS1
) & 0x5 ? 0 : 1;
162 u8
h8_build_id_and_function_spec_version(char *buf
, u8 buf_len
)
165 char str
[16 + 1]; /* 16 ASCII chars + \0 */
168 for (i
= 0; i
< 8; i
++) {
169 c
= ec_read(0xf0 + i
);
170 if (c
< 0x20 || c
> 0x7f) {
171 i
= snprintf(str
, sizeof (str
), "*INVALID");
177 /* EC firmware function specification version */
178 i
+= snprintf(str
+ i
, sizeof (str
) - i
, "-%u.%u", ec_read(0xef), ec_read(0xeb));
186 static void h8_smbios_strings(struct device
*dev
, struct smbios_type11
*t
)
188 char tpec
[] = "IBM ThinkPad Embedded Controller -[ ]-";
190 h8_build_id_and_function_spec_version(tpec
+ 35, 17);
192 t
->count
= smbios_add_string(t
->eos
, tpec
);
195 static void h8_init(device_t dev
)
197 pc_keyboard_init(NO_AUX_DEVICE
);
200 struct device_operations h8_dev_ops
= {
201 .get_smbios_strings
= h8_smbios_strings
,
205 /* configure default values or load value from nvram */
206 static void h8_configure(struct ec_lenovo_h8_config
*conf
)
209 u8 beepmask0
, beepmask1
;
211 if (get_option(&val
, "wlan") != CB_SUCCESS
)
215 if (get_option(&val
, "bluetooth") != CB_SUCCESS
)
217 h8_bluetooth_enable(val
);
219 if (get_option(&val
, "wwan") != CB_SUCCESS
)
224 if (get_option(&val
, "uwb") != CB_SUCCESS
)
230 if (get_option(&val
, "fn_ctrl_swap") != CB_SUCCESS
)
232 h8_fn_ctrl_swap(val
);
234 if (get_option(&val
, "sticky_fn") != CB_SUCCESS
)
238 if (get_option(&val
, "first_battery") != CB_SUCCESS
)
239 val
= PRIMARY_BATTERY
;
240 h8_charge_priority(val
);
242 /* configure sound */
243 if (get_option(&val
, "volume") == CB_SUCCESS
)
244 ec_write(H8_VOLUME_CONTROL
, val
);
246 beepmask0
= conf
->beepmask0
;
247 beepmask1
= conf
->beepmask1
;
249 if (conf
->has_power_management_beeps
250 && get_option(&val
, "power_management_beeps") == CB_SUCCESS
256 if (conf
->has_power_management_beeps
) {
257 if (get_option(&val
, "low_battery_beep") != CB_SUCCESS
)
264 ec_write(H8_SOUND_ENABLE0
, beepmask0
);
265 ec_write(H8_SOUND_ENABLE1
, beepmask1
);
266 h8_set_audio_mute(0);
269 static void h8_enable(struct device
*dev
)
271 struct ec_lenovo_h8_config
*conf
= dev
->chip_info
;
275 dev
->ops
= &h8_dev_ops
;
279 ec_write(H8_CONFIG0
, conf
->config0
);
280 config1
= conf
->config1
;
282 if (conf
->has_keyboard_backlight
) {
283 if (get_option(&val
, "backlight") != CB_SUCCESS
)
284 val
= 0; /* Both backlights. */
285 config1
= (config1
& 0xf3) | ((val
& 0x3) << 2);
287 ec_write(H8_CONFIG1
, config1
);
288 ec_write(H8_CONFIG2
, conf
->config2
);
289 ec_write(H8_CONFIG3
, conf
->config3
);
291 ec_write(H8_SOUND_REPEAT
, 0x00);
292 if (!acpi_is_wakeup_s3())
295 /* silence sounds in queue */
296 ec_write(H8_SOUND_REG
, 0x00);
298 ec_write(0x10, conf
->event0_enable
);
299 ec_write(0x11, conf
->event1_enable
);
300 ec_write(0x12, conf
->event2_enable
);
301 ec_write(0x13, conf
->event3_enable
);
302 ec_write(0x14, conf
->event4_enable
);
303 ec_write(0x15, conf
->event5_enable
);
304 ec_write(0x16, conf
->event6_enable
);
305 ec_write(0x17, conf
->event7_enable
);
306 ec_write(0x18, conf
->event8_enable
);
307 ec_write(0x19, conf
->event9_enable
);
308 ec_write(0x1a, conf
->eventa_enable
);
309 ec_write(0x1b, conf
->eventb_enable
);
310 ec_write(0x1c, conf
->eventc_enable
);
311 ec_write(0x1d, conf
->eventd_enable
);
312 ec_write(0x1e, conf
->evente_enable
);
313 ec_write(0x1f, conf
->eventf_enable
);
315 ec_write(H8_FAN_CONTROL
, H8_FAN_CONTROL_AUTO
);
317 h8_trackpoint_enable(1);
318 h8_usb_power_enable(1);
320 #if !IS_ENABLED(CONFIG_H8_DOCK_EARLY_INIT)
321 h8_mainboard_init_dock();
325 struct chip_operations ec_lenovo_h8_ops
= {
326 CHIP_NAME("Lenovo H8 EC")
327 .enable_dev
= h8_enable
,