1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pnp.h>
7 #include <ec/acpi/ec.h>
11 #include <pc80/keyboard.h>
17 void h8_trackpoint_enable(int on
)
19 ec_write(H8_TRACKPOINT_CTRL
,
20 on
? H8_TRACKPOINT_ON
: H8_TRACKPOINT_OFF
);
23 /* Controls radio-off pin in WLAN MiniPCIe slot. */
24 void h8_wlan_enable(int on
)
32 /* Controls radio-off pin in UWB MiniPCIe slot. */
33 static void h8_uwb_enable(int on
)
41 static void h8_fn_ctrl_swap(int on
)
50 SECONDARY_BATTERY
= 0,
54 /* h8 charge priority. Defines if primary or secondary
55 * battery is charged first.
56 * Because NVRAM is complete the otherway around as this register,
59 static void h8_charge_priority(enum battery battery
)
61 if (battery
== PRIMARY_BATTERY
)
67 static void h8_sticky_fn(int on
)
75 static void f1_to_f12_as_primary(int on
)
83 static void h8_log_ec_version(void)
89 len
= h8_build_id_and_function_spec_version(ecfw
, sizeof ecfw
- 1);
95 printk(BIOS_INFO
, "H8: EC Firmware ID %s, Version %d.%d%d%c\n", ecfw
,
96 fwvh
>> 4, fwvh
& 0x0f, fwvl
>> 4, 0x41 + (fwvl
& 0xf));
99 void h8_set_audio_mute(int mute
)
107 void h8_enable_event(int event
)
109 if (event
< 0 || event
> 127)
112 ec_set_bit(0x10 + (event
>> 3), event
& 7);
115 void h8_disable_event(int event
)
117 if (event
< 0 || event
> 127)
120 ec_clr_bit(0x10 + (event
>> 3), event
& 7);
123 void h8_usb_always_on_enable(enum usb_always_on on
)
129 val
= ec_read(H8_USB_ALWAYS_ON
);
131 val
&= ~(H8_USB_ALWAYS_ON_ENABLE
| H8_USB_ALWAYS_ON_AC_ONLY
);
132 ec_write(H8_USB_ALWAYS_ON
, val
);
135 case UAO_AC_AND_BATTERY
:
136 val
= ec_read(H8_USB_ALWAYS_ON
);
137 val
|= H8_USB_ALWAYS_ON_ENABLE
; // Set bit 0
138 val
&= ~H8_USB_ALWAYS_ON_AC_ONLY
; // Clear bits 2 and 3
139 ec_write(H8_USB_ALWAYS_ON
, val
);
143 val
= ec_read(H8_USB_ALWAYS_ON
);
145 val
|= (H8_USB_ALWAYS_ON_ENABLE
| H8_USB_ALWAYS_ON_AC_ONLY
);
146 ec_write(H8_USB_ALWAYS_ON
, val
);
151 void h8_usb_power_enable(int onoff
)
159 int h8_ultrabay_device_present(void)
161 return ec_read(H8_STATUS1
) & 0x5 ? 0 : 1;
164 u8
h8_build_id_and_function_spec_version(char *buf
, u8 buf_len
)
167 char str
[16 + 1]; /* 16 ASCII chars + \0 */
170 for (i
= 0; i
< 8; i
++) {
171 c
= ec_read(0xf0 + i
);
172 if (c
< 0x20 || c
> 0x7f) {
173 i
= snprintf(str
, sizeof(str
), "*INVALID");
179 /* EC firmware function specification version */
180 i
+= snprintf(str
+ i
, sizeof(str
) - i
, "-%u.%u", ec_read(0xef), ec_read(0xeb));
188 #if CONFIG(GENERATE_SMBIOS_TABLES)
189 static void h8_smbios_strings(struct device
*dev
, struct smbios_type11
*t
)
191 char tpec
[] = "IBM ThinkPad Embedded Controller -[ ]-";
193 h8_build_id_and_function_spec_version(tpec
+ 35, 17);
195 t
->count
= smbios_add_string(t
->eos
, tpec
);
199 static void h8_init(struct device
*dev
)
201 pc_keyboard_init(NO_AUX_DEVICE
);
204 #if CONFIG(HAVE_ACPI_TABLES)
205 static const char *h8_acpi_name(const struct device
*dev
)
211 struct device_operations h8_dev_ops
= {
212 #if CONFIG(GENERATE_SMBIOS_TABLES)
213 .get_smbios_strings
= h8_smbios_strings
,
215 #if CONFIG(HAVE_ACPI_TABLES)
216 .acpi_fill_ssdt
= h8_ssdt_generator
,
217 .acpi_name
= h8_acpi_name
,
222 void __weak
h8_mb_init(void){ /* NOOP */ }
224 static void h8_enable(struct device
*dev
)
226 struct ec_lenovo_h8_config
*conf
= dev
->chip_info
;
228 u8 beepmask0
, beepmask1
, reg8
;
230 dev
->ops
= &h8_dev_ops
;
232 ec_clear_out_queue();
235 /* Always enable I/O range 0x1600-0x160f and thermal management */
236 reg8
= conf
->config0
;
237 reg8
|= H8_CONFIG0_SMM_H8_ENABLE
;
238 reg8
|= H8_CONFIG0_TC_ENABLE
;
239 ec_write(H8_CONFIG0
, reg8
);
241 reg8
= conf
->config1
;
242 if (conf
->has_keyboard_backlight
) {
243 /* Default to both backlights */
244 reg8
= (reg8
& 0xf3) | ((get_uint_option("backlight", 0) & 0x3) << 2);
246 ec_write(H8_CONFIG1
, reg8
);
247 ec_write(H8_CONFIG2
, conf
->config2
);
248 ec_write(H8_CONFIG3
, conf
->config3
);
250 beepmask0
= conf
->beepmask0
;
251 beepmask1
= conf
->beepmask1
;
253 if (conf
->has_power_management_beeps
) {
254 if (get_uint_option("power_management_beeps", 1) == 0) {
260 if (conf
->has_power_management_beeps
) {
261 if (get_uint_option("low_battery_beep", 1))
267 ec_write(H8_SOUND_ENABLE0
, beepmask0
);
268 ec_write(H8_SOUND_ENABLE1
, beepmask1
);
270 /* silence sounds in queue */
271 ec_write(H8_SOUND_REPEAT
, 0x00);
272 ec_write(H8_SOUND_REG
, 0x00);
274 ec_write(0x10, conf
->event0_enable
);
275 ec_write(0x11, conf
->event1_enable
);
276 ec_write(0x12, conf
->event2_enable
);
277 ec_write(0x13, conf
->event3_enable
);
278 ec_write(0x14, conf
->event4_enable
);
279 ec_write(0x15, conf
->event5_enable
);
280 ec_write(0x16, conf
->event6_enable
);
281 ec_write(0x17, conf
->event7_enable
);
282 ec_write(0x18, conf
->event8_enable
);
283 ec_write(0x19, conf
->event9_enable
);
284 ec_write(0x1a, conf
->eventa_enable
);
285 ec_write(0x1b, conf
->eventb_enable
);
286 ec_write(0x1c, conf
->eventc_enable
);
287 ec_write(0x1d, conf
->eventd_enable
);
288 ec_write(0x1e, conf
->evente_enable
);
289 ec_write(0x1f, conf
->eventf_enable
);
291 ec_write(H8_FAN_CONTROL
, H8_FAN_CONTROL_AUTO
);
293 h8_usb_always_on_enable(get_uint_option("usb_always_on", 0));
295 h8_wlan_enable(get_uint_option("wlan", 1));
297 h8_trackpoint_enable(1);
298 h8_usb_power_enable(1);
300 unsigned int volume
= get_uint_option("volume", ~0);
301 if (volume
<= 0xff && !acpi_is_wakeup_s3())
302 ec_write(H8_VOLUME_CONTROL
, volume
);
304 val
= (CONFIG(H8_SUPPORT_BT_ON_WIFI
) || h8_has_bdc(dev
)) &&
305 h8_bluetooth_nv_enable();
306 h8_bluetooth_enable(val
);
308 val
= h8_has_wwan(dev
) && h8_wwan_nv_enable();
312 h8_uwb_enable(get_uint_option("uwb", 1));
314 h8_fn_ctrl_swap(get_uint_option("fn_ctrl_swap", CONFIG(H8_FN_CTRL_SWAP
)));
316 h8_sticky_fn(get_uint_option("sticky_fn", 0));
318 if (CONFIG(H8_HAS_PRIMARY_FN_KEYS
))
319 f1_to_f12_as_primary(get_uint_option("f1_to_f12_as_primary", 1));
321 h8_charge_priority(get_uint_option("first_battery", PRIMARY_BATTERY
));
323 h8_set_audio_mute(0);
327 struct chip_operations ec_lenovo_h8_ops
= {
328 CHIP_NAME("Lenovo H8 EC")
329 .enable_dev
= h8_enable
,