blob: 09211f82abc79ca1996b1ea1b358978eb49b3858 [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 Lauriec145e542019-04-18 16:37:50 -070017#include <arch/acpi_device.h>
18#include <arch/acpigen.h>
Duncan Laurie421a9622018-10-15 02:46:45 +000019#include <bootstate.h>
Duncan Lauriec145e542019-04-18 16:37:50 -070020#include <cbmem.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000021#include <device/pnp.h>
Duncan Laurie90a96c72019-03-13 17:35:22 -070022#include <ec/acpi/ec.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000023#include <pc80/keyboard.h>
24#include <stdint.h>
25#include <stdlib.h>
26
27#include "commands.h"
28#include "ec.h"
29#include "chip.h"
30
Duncan Lauriec145e542019-04-18 16:37:50 -070031/*
32 * The UCSI fields are defined in the UCSI specification at
33 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html
34 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/bios-implementation-of-ucsi.html
35 */
36
37static struct fieldlist ucsi_region_fields[] = {
38 FIELDLIST_NAMESTR("VER0", 8),
39 FIELDLIST_NAMESTR("VER1", 8),
40 FIELDLIST_NAMESTR("RSV0", 8),
41 FIELDLIST_NAMESTR("RSV1", 8),
42 FIELDLIST_NAMESTR("CCI0", 8),
43 FIELDLIST_NAMESTR("CCI1", 8),
44 FIELDLIST_NAMESTR("CCI2", 8),
45 FIELDLIST_NAMESTR("CCI3", 8),
46 FIELDLIST_NAMESTR("CTL0", 8),
47 FIELDLIST_NAMESTR("CTL1", 8),
48 FIELDLIST_NAMESTR("CTL2", 8),
49 FIELDLIST_NAMESTR("CTL3", 8),
50 FIELDLIST_NAMESTR("CTL4", 8),
51 FIELDLIST_NAMESTR("CTL5", 8),
52 FIELDLIST_NAMESTR("CTL6", 8),
53 FIELDLIST_NAMESTR("CTL7", 8),
54 FIELDLIST_NAMESTR("MGI0", 8),
55 FIELDLIST_NAMESTR("MGI1", 8),
56 FIELDLIST_NAMESTR("MGI2", 8),
57 FIELDLIST_NAMESTR("MGI3", 8),
58 FIELDLIST_NAMESTR("MGI4", 8),
59 FIELDLIST_NAMESTR("MGI5", 8),
60 FIELDLIST_NAMESTR("MGI6", 8),
61 FIELDLIST_NAMESTR("MGI7", 8),
62 FIELDLIST_NAMESTR("MGI8", 8),
63 FIELDLIST_NAMESTR("MGI9", 8),
64 FIELDLIST_NAMESTR("MGIA", 8),
65 FIELDLIST_NAMESTR("MGIB", 8),
66 FIELDLIST_NAMESTR("MGIC", 8),
67 FIELDLIST_NAMESTR("MGID", 8),
68 FIELDLIST_NAMESTR("MGIE", 8),
69 FIELDLIST_NAMESTR("MGIF", 8),
70 FIELDLIST_NAMESTR("MGO0", 8),
71 FIELDLIST_NAMESTR("MGO1", 8),
72 FIELDLIST_NAMESTR("MGO2", 8),
73 FIELDLIST_NAMESTR("MGO3", 8),
74 FIELDLIST_NAMESTR("MGO4", 8),
75 FIELDLIST_NAMESTR("MGO5", 8),
76 FIELDLIST_NAMESTR("MGO6", 8),
77 FIELDLIST_NAMESTR("MGO7", 8),
78 FIELDLIST_NAMESTR("MGO8", 8),
79 FIELDLIST_NAMESTR("MGO9", 8),
80 FIELDLIST_NAMESTR("MGOA", 8),
81 FIELDLIST_NAMESTR("MGOB", 8),
82 FIELDLIST_NAMESTR("MGOC", 8),
83 FIELDLIST_NAMESTR("MGOD", 8),
84 FIELDLIST_NAMESTR("MGOE", 8),
85 FIELDLIST_NAMESTR("MGOF", 8),
86};
87static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields);
88
Duncan Laurie421a9622018-10-15 02:46:45 +000089static void wilco_ec_post_complete(void *unused)
90{
91 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
92}
93BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
94 wilco_ec_post_complete, NULL);
95
96static void wilco_ec_post_memory_init(void *unused)
97{
98 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
99}
100BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
101 wilco_ec_post_memory_init, NULL);
102
103static void wilco_ec_post_video_init(void *unused)
104{
105 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
106}
107BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
108 wilco_ec_post_video_init, NULL);
109
Duncan Laurie1c968c12019-04-17 15:12:45 -0700110static void wilco_ec_post_logo_displayed(void *unused)
111{
112 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED);
113}
114BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT,
115 wilco_ec_post_logo_displayed, NULL);
116
Duncan Laurie3fbe1942018-10-15 13:39:35 -0700117static void wilco_ec_resume(void *unused)
118{
119 wilco_ec_send_noargs(KB_RESTORE);
120}
121BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
122
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000123static void wilco_ec_init(struct device *dev)
124{
125 if (!dev->enabled)
126 return;
127
Duncan Laurie90a96c72019-03-13 17:35:22 -0700128 /* Disable S0ix support in EC RAM with ACPI EC interface */
129 if (!acpi_is_wakeup_s3()) {
130 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
131 CONFIG_EC_BASE_ACPI_DATA);
132 ec_write(EC_RAM_S0IX_SUPPORT, 0);
133 }
134
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000135 /* Print EC firmware information */
136 wilco_ec_print_all_info();
137
138 /* Initialize keyboard, ignore emulated PS/2 mouse */
139 pc_keyboard_init(NO_AUX_DEVICE);
140
141 /* Direct power button to the host for processing */
142 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -0700143
144 /* Unmute speakers */
145 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -0700146
147 /* Enable WiFi radio */
148 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -0800149
150 /* Turn on camera power */
151 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000152}
153
154static void wilco_ec_resource(struct device *dev, int index,
155 size_t base, size_t size)
156{
157 struct resource *res = new_resource(dev, index);
158 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
159 res->base = base;
160 res->size = size;
161}
162
163static void wilco_ec_read_resources(struct device *dev)
164{
165 /* ACPI command and data regions */
166 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
167
168 /* Host command and data regions */
169 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
170
171 /* Packet region */
172 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
173}
174
Duncan Lauriec145e542019-04-18 16:37:50 -0700175static void wilco_ec_fill_ssdt_generator(struct device *dev)
176{
177 struct opregion opreg;
178 void *region_ptr;
179
180 if (!dev->enabled)
181 return;
182
183 region_ptr = cbmem_add(CBMEM_ID_ACPI_UCSI, ucsi_region_len);
184 if (!region_ptr)
185 return;
186 memset(region_ptr, 0, ucsi_region_len);
187
188 opreg.name = "UCSM";
189 opreg.regionspace = SYSTEMMEMORY;
190 opreg.regionoffset = (uintptr_t)region_ptr;
191 opreg.regionlen = ucsi_region_len;
192
193 acpigen_write_scope(acpi_device_path_join(dev, "UCSI"));
194 acpigen_write_name("_CRS");
195 acpigen_write_resourcetemplate_header();
196 acpigen_write_mem32fixed(1, (uintptr_t)region_ptr, ucsi_region_len);
197 acpigen_write_resourcetemplate_footer();
198 acpigen_write_opregion(&opreg);
199 acpigen_write_field(opreg.name, ucsi_region_fields, ucsi_region_len,
200 FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE);
201 acpigen_pop_len(); /* Scope */
202}
203
204static const char *wilco_ec_acpi_name(const struct device *dev)
205{
206 return "EC0";
207}
208
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000209static struct device_operations ops = {
Duncan Lauriec145e542019-04-18 16:37:50 -0700210 .init = wilco_ec_init,
211 .read_resources = wilco_ec_read_resources,
212 .enable_resources = DEVICE_NOOP,
213 .set_resources = DEVICE_NOOP,
214 .acpi_fill_ssdt_generator = wilco_ec_fill_ssdt_generator,
215 .acpi_name = wilco_ec_acpi_name,
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000216};
217
218static struct pnp_info info[] = {
219 { NULL, 0, 0, 0, }
220};
221
222static void wilco_ec_enable_dev(struct device *dev)
223{
224 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
225}
226
227struct chip_operations ec_google_wilco_ops = {
228 CHIP_NAME("Google Wilco EC")
229 .enable_dev = wilco_ec_enable_dev,
230};