blob: acbd4871e4f9b2c8f85788850961b01daef9edc9 [file] [log] [blame]
Duncan Laurieb29e2d52018-10-15 02:40:21 +00001/*
2 * This file is part of the coreboot project.
3 *
Duncan Laurieb29e2d52018-10-15 02:40:21 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
Duncan Laurie90a96c72019-03-13 17:35:22 -070015#include <arch/acpi.h>
Duncan Lauriec145e542019-04-18 16:37:50 -070016#include <arch/acpi_device.h>
17#include <arch/acpigen.h>
Eric Lai123b1912020-01-25 22:14:04 +080018#include <arch/cpu.h>
Duncan Laurie421a9622018-10-15 02:46:45 +000019#include <bootstate.h>
Duncan Lauriec145e542019-04-18 16:37:50 -070020#include <cbmem.h>
Eric Lai123b1912020-01-25 22:14:04 +080021#include <console/console.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000022#include <device/pnp.h>
Duncan Laurie90a96c72019-03-13 17:35:22 -070023#include <ec/acpi/ec.h>
Eric Lai123b1912020-01-25 22:14:04 +080024#include <intelblocks/cpulib.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000025#include <pc80/keyboard.h>
26#include <stdint.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000027
28#include "commands.h"
29#include "ec.h"
30#include "chip.h"
31
Duncan Lauriec145e542019-04-18 16:37:50 -070032/*
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -080033 * Setting minimum length of UCSI_ACPI will ensure this region is placed out of IMD Small.
34 * Having this region out of IMD Small will prevent any memory mapping conflicts.
35 */
36#define UCSI_MIN_ALLOC_REGION_LEN CBMEM_SM_ROOT_SIZE
37/*
Duncan Lauriec145e542019-04-18 16:37:50 -070038 * The UCSI fields are defined in the UCSI specification at
39 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html
40 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/bios-implementation-of-ucsi.html
41 */
42
43static struct fieldlist ucsi_region_fields[] = {
44 FIELDLIST_NAMESTR("VER0", 8),
45 FIELDLIST_NAMESTR("VER1", 8),
46 FIELDLIST_NAMESTR("RSV0", 8),
47 FIELDLIST_NAMESTR("RSV1", 8),
48 FIELDLIST_NAMESTR("CCI0", 8),
49 FIELDLIST_NAMESTR("CCI1", 8),
50 FIELDLIST_NAMESTR("CCI2", 8),
51 FIELDLIST_NAMESTR("CCI3", 8),
52 FIELDLIST_NAMESTR("CTL0", 8),
53 FIELDLIST_NAMESTR("CTL1", 8),
54 FIELDLIST_NAMESTR("CTL2", 8),
55 FIELDLIST_NAMESTR("CTL3", 8),
56 FIELDLIST_NAMESTR("CTL4", 8),
57 FIELDLIST_NAMESTR("CTL5", 8),
58 FIELDLIST_NAMESTR("CTL6", 8),
59 FIELDLIST_NAMESTR("CTL7", 8),
60 FIELDLIST_NAMESTR("MGI0", 8),
61 FIELDLIST_NAMESTR("MGI1", 8),
62 FIELDLIST_NAMESTR("MGI2", 8),
63 FIELDLIST_NAMESTR("MGI3", 8),
64 FIELDLIST_NAMESTR("MGI4", 8),
65 FIELDLIST_NAMESTR("MGI5", 8),
66 FIELDLIST_NAMESTR("MGI6", 8),
67 FIELDLIST_NAMESTR("MGI7", 8),
68 FIELDLIST_NAMESTR("MGI8", 8),
69 FIELDLIST_NAMESTR("MGI9", 8),
70 FIELDLIST_NAMESTR("MGIA", 8),
71 FIELDLIST_NAMESTR("MGIB", 8),
72 FIELDLIST_NAMESTR("MGIC", 8),
73 FIELDLIST_NAMESTR("MGID", 8),
74 FIELDLIST_NAMESTR("MGIE", 8),
75 FIELDLIST_NAMESTR("MGIF", 8),
76 FIELDLIST_NAMESTR("MGO0", 8),
77 FIELDLIST_NAMESTR("MGO1", 8),
78 FIELDLIST_NAMESTR("MGO2", 8),
79 FIELDLIST_NAMESTR("MGO3", 8),
80 FIELDLIST_NAMESTR("MGO4", 8),
81 FIELDLIST_NAMESTR("MGO5", 8),
82 FIELDLIST_NAMESTR("MGO6", 8),
83 FIELDLIST_NAMESTR("MGO7", 8),
84 FIELDLIST_NAMESTR("MGO8", 8),
85 FIELDLIST_NAMESTR("MGO9", 8),
86 FIELDLIST_NAMESTR("MGOA", 8),
87 FIELDLIST_NAMESTR("MGOB", 8),
88 FIELDLIST_NAMESTR("MGOC", 8),
89 FIELDLIST_NAMESTR("MGOD", 8),
90 FIELDLIST_NAMESTR("MGOE", 8),
91 FIELDLIST_NAMESTR("MGOF", 8),
92};
93static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields);
94
Duncan Laurie421a9622018-10-15 02:46:45 +000095static void wilco_ec_post_complete(void *unused)
96{
97 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
98}
99BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
100 wilco_ec_post_complete, NULL);
101
102static void wilco_ec_post_memory_init(void *unused)
103{
104 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
105}
106BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
107 wilco_ec_post_memory_init, NULL);
108
109static void wilco_ec_post_video_init(void *unused)
110{
111 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
112}
113BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
114 wilco_ec_post_video_init, NULL);
115
Duncan Laurie1c968c12019-04-17 15:12:45 -0700116static void wilco_ec_post_logo_displayed(void *unused)
117{
118 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED);
119}
120BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT,
121 wilco_ec_post_logo_displayed, NULL);
122
Duncan Laurie3fbe1942018-10-15 13:39:35 -0700123static void wilco_ec_resume(void *unused)
124{
125 wilco_ec_send_noargs(KB_RESTORE);
126}
127BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
128
Eric Lai123b1912020-01-25 22:14:04 +0800129static int wilco_set_cpu_id(void)
130{
131 uint32_t cpu_phy_cores, cpu_virtual_cores;
132
133 cpu_read_topology(&cpu_phy_cores, &cpu_virtual_cores);
134 return wilco_ec_set_cpuid(cpu_get_cpuid(), cpu_phy_cores, 0);
135}
136
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000137static void wilco_ec_init(struct device *dev)
138{
139 if (!dev->enabled)
140 return;
141
Duncan Laurie90a96c72019-03-13 17:35:22 -0700142 /* Disable S0ix support in EC RAM with ACPI EC interface */
143 if (!acpi_is_wakeup_s3()) {
144 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
145 CONFIG_EC_BASE_ACPI_DATA);
146 ec_write(EC_RAM_S0IX_SUPPORT, 0);
147 }
148
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000149 /* Print EC firmware information */
150 wilco_ec_print_all_info();
151
152 /* Initialize keyboard, ignore emulated PS/2 mouse */
153 pc_keyboard_init(NO_AUX_DEVICE);
154
155 /* Direct power button to the host for processing */
156 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -0700157
158 /* Unmute speakers */
159 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -0700160
161 /* Enable WiFi radio */
162 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -0800163
164 /* Turn on camera power */
165 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Eric Lai123b1912020-01-25 22:14:04 +0800166
167 /* Set cpu id and phy cores */
168 if (wilco_set_cpu_id())
169 printk(BIOS_ERR, "EC: use default cpu power table\n");
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000170}
171
172static void wilco_ec_resource(struct device *dev, int index,
173 size_t base, size_t size)
174{
175 struct resource *res = new_resource(dev, index);
176 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
177 res->base = base;
178 res->size = size;
179}
180
181static void wilco_ec_read_resources(struct device *dev)
182{
183 /* ACPI command and data regions */
184 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
185
186 /* Host command and data regions */
187 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
188
189 /* Packet region */
190 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
191}
192
Duncan Lauriec145e542019-04-18 16:37:50 -0700193static void wilco_ec_fill_ssdt_generator(struct device *dev)
194{
195 struct opregion opreg;
196 void *region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800197 size_t ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700198
199 if (!dev->enabled)
200 return;
201
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800202 ucsi_alloc_region_len = ucsi_region_len < UCSI_MIN_ALLOC_REGION_LEN ?
203 UCSI_MIN_ALLOC_REGION_LEN : ucsi_region_len;
204 region_ptr = cbmem_add(CBMEM_ID_ACPI_UCSI, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700205 if (!region_ptr)
206 return;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800207 memset(region_ptr, 0, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700208
209 opreg.name = "UCSM";
210 opreg.regionspace = SYSTEMMEMORY;
211 opreg.regionoffset = (uintptr_t)region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800212 opreg.regionlen = ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700213
214 acpigen_write_scope(acpi_device_path_join(dev, "UCSI"));
215 acpigen_write_name("_CRS");
216 acpigen_write_resourcetemplate_header();
217 acpigen_write_mem32fixed(1, (uintptr_t)region_ptr, ucsi_region_len);
218 acpigen_write_resourcetemplate_footer();
219 acpigen_write_opregion(&opreg);
220 acpigen_write_field(opreg.name, ucsi_region_fields, ucsi_region_len,
221 FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE);
222 acpigen_pop_len(); /* Scope */
223}
224
225static const char *wilco_ec_acpi_name(const struct device *dev)
226{
227 return "EC0";
228}
229
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000230static struct device_operations ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200231 .init = wilco_ec_init,
232 .read_resources = wilco_ec_read_resources,
233 .enable_resources = DEVICE_NOOP,
234 .set_resources = DEVICE_NOOP,
235 .acpi_fill_ssdt = wilco_ec_fill_ssdt_generator,
236 .acpi_name = wilco_ec_acpi_name,
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000237};
238
239static struct pnp_info info[] = {
240 { NULL, 0, 0, 0, }
241};
242
243static void wilco_ec_enable_dev(struct device *dev)
244{
245 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
246}
247
248struct chip_operations ec_google_wilco_ops = {
249 CHIP_NAME("Google Wilco EC")
250 .enable_dev = wilco_ec_enable_dev,
251};