blob: 9b0be19f9a18921a7cd6c55b48c4217dd7934bcb [file] [log] [blame]
Duncan Laurieb29e2d52018-10-15 02:40:21 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2018 Google LLC
5 *
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
9 *
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.
14 */
15
Duncan Laurie90a96c72019-03-13 17:35:22 -070016#include <arch/acpi.h>
Duncan Laurie421a9622018-10-15 02:46:45 +000017#include <bootstate.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000018#include <device/pnp.h>
Duncan Laurie90a96c72019-03-13 17:35:22 -070019#include <ec/acpi/ec.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000020#include <pc80/keyboard.h>
21#include <stdint.h>
22#include <stdlib.h>
23
24#include "commands.h"
25#include "ec.h"
26#include "chip.h"
27
Duncan Laurie421a9622018-10-15 02:46:45 +000028static void wilco_ec_post_complete(void *unused)
29{
30 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
31}
32BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
33 wilco_ec_post_complete, NULL);
34
35static void wilco_ec_post_memory_init(void *unused)
36{
37 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
38}
39BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
40 wilco_ec_post_memory_init, NULL);
41
42static void wilco_ec_post_video_init(void *unused)
43{
44 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
45}
46BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
47 wilco_ec_post_video_init, NULL);
48
Duncan Laurie1c968c12019-04-17 15:12:45 -070049static void wilco_ec_post_logo_displayed(void *unused)
50{
51 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED);
52}
53BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT,
54 wilco_ec_post_logo_displayed, NULL);
55
Duncan Laurie3fbe1942018-10-15 13:39:35 -070056static void wilco_ec_resume(void *unused)
57{
58 wilco_ec_send_noargs(KB_RESTORE);
59}
60BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
61
Duncan Laurieb29e2d52018-10-15 02:40:21 +000062static void wilco_ec_init(struct device *dev)
63{
64 if (!dev->enabled)
65 return;
66
Duncan Laurie90a96c72019-03-13 17:35:22 -070067 /* Disable S0ix support in EC RAM with ACPI EC interface */
68 if (!acpi_is_wakeup_s3()) {
69 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
70 CONFIG_EC_BASE_ACPI_DATA);
71 ec_write(EC_RAM_S0IX_SUPPORT, 0);
72 }
73
Duncan Laurieb29e2d52018-10-15 02:40:21 +000074 /* Print EC firmware information */
75 wilco_ec_print_all_info();
76
77 /* Initialize keyboard, ignore emulated PS/2 mouse */
78 pc_keyboard_init(NO_AUX_DEVICE);
79
80 /* Direct power button to the host for processing */
81 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -070082
83 /* Unmute speakers */
84 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -070085
86 /* Enable WiFi radio */
87 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -080088
89 /* Turn on camera power */
90 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Duncan Laurieb29e2d52018-10-15 02:40:21 +000091}
92
93static void wilco_ec_resource(struct device *dev, int index,
94 size_t base, size_t size)
95{
96 struct resource *res = new_resource(dev, index);
97 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
98 res->base = base;
99 res->size = size;
100}
101
102static void wilco_ec_read_resources(struct device *dev)
103{
104 /* ACPI command and data regions */
105 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
106
107 /* Host command and data regions */
108 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
109
110 /* Packet region */
111 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
112}
113
114static struct device_operations ops = {
115 .init = wilco_ec_init,
116 .read_resources = wilco_ec_read_resources,
117 .enable_resources = DEVICE_NOOP,
118 .set_resources = DEVICE_NOOP,
119};
120
121static struct pnp_info info[] = {
122 { NULL, 0, 0, 0, }
123};
124
125static void wilco_ec_enable_dev(struct device *dev)
126{
127 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
128}
129
130struct chip_operations ec_google_wilco_ops = {
131 CHIP_NAME("Google Wilco EC")
132 .enable_dev = wilco_ec_enable_dev,
133};