blob: 7de4e0235e077f28ed076f7380e7ecc5cd3424f3 [file] [log] [blame]
Angel Pons210a0082020-04-02 23:48:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurieb29e2d52018-10-15 02:40:21 +00003
Duncan Laurie90a96c72019-03-13 17:35:22 -07004#include <arch/acpi.h>
Duncan Lauriec145e542019-04-18 16:37:50 -07005#include <arch/acpi_device.h>
6#include <arch/acpigen.h>
Eric Lai123b1912020-01-25 22:14:04 +08007#include <arch/cpu.h>
Duncan Laurie421a9622018-10-15 02:46:45 +00008#include <bootstate.h>
Duncan Lauriec145e542019-04-18 16:37:50 -07009#include <cbmem.h>
Eric Lai123b1912020-01-25 22:14:04 +080010#include <console/console.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000011#include <device/pnp.h>
Duncan Laurie90a96c72019-03-13 17:35:22 -070012#include <ec/acpi/ec.h>
Eric Lai123b1912020-01-25 22:14:04 +080013#include <intelblocks/cpulib.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000014#include <pc80/keyboard.h>
15#include <stdint.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000016
17#include "commands.h"
18#include "ec.h"
19#include "chip.h"
20
Duncan Lauriec145e542019-04-18 16:37:50 -070021/*
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -080022 * Setting minimum length of UCSI_ACPI will ensure this region is placed out of IMD Small.
23 * Having this region out of IMD Small will prevent any memory mapping conflicts.
24 */
25#define UCSI_MIN_ALLOC_REGION_LEN CBMEM_SM_ROOT_SIZE
26/*
Duncan Lauriec145e542019-04-18 16:37:50 -070027 * The UCSI fields are defined in the UCSI specification at
28 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html
29 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/bios-implementation-of-ucsi.html
30 */
31
32static struct fieldlist ucsi_region_fields[] = {
33 FIELDLIST_NAMESTR("VER0", 8),
34 FIELDLIST_NAMESTR("VER1", 8),
35 FIELDLIST_NAMESTR("RSV0", 8),
36 FIELDLIST_NAMESTR("RSV1", 8),
37 FIELDLIST_NAMESTR("CCI0", 8),
38 FIELDLIST_NAMESTR("CCI1", 8),
39 FIELDLIST_NAMESTR("CCI2", 8),
40 FIELDLIST_NAMESTR("CCI3", 8),
41 FIELDLIST_NAMESTR("CTL0", 8),
42 FIELDLIST_NAMESTR("CTL1", 8),
43 FIELDLIST_NAMESTR("CTL2", 8),
44 FIELDLIST_NAMESTR("CTL3", 8),
45 FIELDLIST_NAMESTR("CTL4", 8),
46 FIELDLIST_NAMESTR("CTL5", 8),
47 FIELDLIST_NAMESTR("CTL6", 8),
48 FIELDLIST_NAMESTR("CTL7", 8),
49 FIELDLIST_NAMESTR("MGI0", 8),
50 FIELDLIST_NAMESTR("MGI1", 8),
51 FIELDLIST_NAMESTR("MGI2", 8),
52 FIELDLIST_NAMESTR("MGI3", 8),
53 FIELDLIST_NAMESTR("MGI4", 8),
54 FIELDLIST_NAMESTR("MGI5", 8),
55 FIELDLIST_NAMESTR("MGI6", 8),
56 FIELDLIST_NAMESTR("MGI7", 8),
57 FIELDLIST_NAMESTR("MGI8", 8),
58 FIELDLIST_NAMESTR("MGI9", 8),
59 FIELDLIST_NAMESTR("MGIA", 8),
60 FIELDLIST_NAMESTR("MGIB", 8),
61 FIELDLIST_NAMESTR("MGIC", 8),
62 FIELDLIST_NAMESTR("MGID", 8),
63 FIELDLIST_NAMESTR("MGIE", 8),
64 FIELDLIST_NAMESTR("MGIF", 8),
65 FIELDLIST_NAMESTR("MGO0", 8),
66 FIELDLIST_NAMESTR("MGO1", 8),
67 FIELDLIST_NAMESTR("MGO2", 8),
68 FIELDLIST_NAMESTR("MGO3", 8),
69 FIELDLIST_NAMESTR("MGO4", 8),
70 FIELDLIST_NAMESTR("MGO5", 8),
71 FIELDLIST_NAMESTR("MGO6", 8),
72 FIELDLIST_NAMESTR("MGO7", 8),
73 FIELDLIST_NAMESTR("MGO8", 8),
74 FIELDLIST_NAMESTR("MGO9", 8),
75 FIELDLIST_NAMESTR("MGOA", 8),
76 FIELDLIST_NAMESTR("MGOB", 8),
77 FIELDLIST_NAMESTR("MGOC", 8),
78 FIELDLIST_NAMESTR("MGOD", 8),
79 FIELDLIST_NAMESTR("MGOE", 8),
80 FIELDLIST_NAMESTR("MGOF", 8),
81};
82static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields);
83
Duncan Laurie421a9622018-10-15 02:46:45 +000084static void wilco_ec_post_complete(void *unused)
85{
86 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
87}
88BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
89 wilco_ec_post_complete, NULL);
90
91static void wilco_ec_post_memory_init(void *unused)
92{
93 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
94}
95BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
96 wilco_ec_post_memory_init, NULL);
97
98static void wilco_ec_post_video_init(void *unused)
99{
100 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
101}
102BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
103 wilco_ec_post_video_init, NULL);
104
Duncan Laurie1c968c12019-04-17 15:12:45 -0700105static void wilco_ec_post_logo_displayed(void *unused)
106{
107 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED);
108}
109BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT,
110 wilco_ec_post_logo_displayed, NULL);
111
Duncan Laurie3fbe1942018-10-15 13:39:35 -0700112static void wilco_ec_resume(void *unused)
113{
114 wilco_ec_send_noargs(KB_RESTORE);
115}
116BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
117
Eric Lai123b1912020-01-25 22:14:04 +0800118static int wilco_set_cpu_id(void)
119{
120 uint32_t cpu_phy_cores, cpu_virtual_cores;
121
122 cpu_read_topology(&cpu_phy_cores, &cpu_virtual_cores);
123 return wilco_ec_set_cpuid(cpu_get_cpuid(), cpu_phy_cores, 0);
124}
125
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000126static void wilco_ec_init(struct device *dev)
127{
128 if (!dev->enabled)
129 return;
130
Duncan Laurie90a96c72019-03-13 17:35:22 -0700131 /* Disable S0ix support in EC RAM with ACPI EC interface */
132 if (!acpi_is_wakeup_s3()) {
133 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
134 CONFIG_EC_BASE_ACPI_DATA);
135 ec_write(EC_RAM_S0IX_SUPPORT, 0);
136 }
137
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000138 /* Print EC firmware information */
139 wilco_ec_print_all_info();
140
141 /* Initialize keyboard, ignore emulated PS/2 mouse */
142 pc_keyboard_init(NO_AUX_DEVICE);
143
144 /* Direct power button to the host for processing */
145 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -0700146
147 /* Unmute speakers */
148 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -0700149
150 /* Enable WiFi radio */
151 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -0800152
153 /* Turn on camera power */
154 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Eric Lai123b1912020-01-25 22:14:04 +0800155
156 /* Set cpu id and phy cores */
157 if (wilco_set_cpu_id())
158 printk(BIOS_ERR, "EC: use default cpu power table\n");
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000159}
160
161static void wilco_ec_resource(struct device *dev, int index,
162 size_t base, size_t size)
163{
164 struct resource *res = new_resource(dev, index);
165 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
166 res->base = base;
167 res->size = size;
168}
169
170static void wilco_ec_read_resources(struct device *dev)
171{
172 /* ACPI command and data regions */
173 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
174
175 /* Host command and data regions */
176 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
177
178 /* Packet region */
179 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
180}
181
Duncan Lauriec145e542019-04-18 16:37:50 -0700182static void wilco_ec_fill_ssdt_generator(struct device *dev)
183{
184 struct opregion opreg;
185 void *region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800186 size_t ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700187
188 if (!dev->enabled)
189 return;
190
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800191 ucsi_alloc_region_len = ucsi_region_len < UCSI_MIN_ALLOC_REGION_LEN ?
192 UCSI_MIN_ALLOC_REGION_LEN : ucsi_region_len;
193 region_ptr = cbmem_add(CBMEM_ID_ACPI_UCSI, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700194 if (!region_ptr)
195 return;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800196 memset(region_ptr, 0, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700197
198 opreg.name = "UCSM";
199 opreg.regionspace = SYSTEMMEMORY;
200 opreg.regionoffset = (uintptr_t)region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800201 opreg.regionlen = ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700202
203 acpigen_write_scope(acpi_device_path_join(dev, "UCSI"));
204 acpigen_write_name("_CRS");
205 acpigen_write_resourcetemplate_header();
206 acpigen_write_mem32fixed(1, (uintptr_t)region_ptr, ucsi_region_len);
207 acpigen_write_resourcetemplate_footer();
208 acpigen_write_opregion(&opreg);
209 acpigen_write_field(opreg.name, ucsi_region_fields, ucsi_region_len,
210 FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE);
211 acpigen_pop_len(); /* Scope */
212}
213
214static const char *wilco_ec_acpi_name(const struct device *dev)
215{
216 return "EC0";
217}
218
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000219static struct device_operations ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200220 .init = wilco_ec_init,
221 .read_resources = wilco_ec_read_resources,
Nico Huber2f8ba692020-04-05 14:05:24 +0200222 .set_resources = noop_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200223 .acpi_fill_ssdt = wilco_ec_fill_ssdt_generator,
224 .acpi_name = wilco_ec_acpi_name,
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000225};
226
227static struct pnp_info info[] = {
228 { NULL, 0, 0, 0, }
229};
230
231static void wilco_ec_enable_dev(struct device *dev)
232{
233 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
234}
235
236struct chip_operations ec_google_wilco_ops = {
237 CHIP_NAME("Google Wilco EC")
238 .enable_dev = wilco_ec_enable_dev,
239};