blob: 5729b4aa27204f58c78b2e279c6db853c3adf4aa [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>
Eric Lai123b1912020-01-25 22:14:04 +080019#include <arch/cpu.h>
Duncan Laurie421a9622018-10-15 02:46:45 +000020#include <bootstate.h>
Duncan Lauriec145e542019-04-18 16:37:50 -070021#include <cbmem.h>
Eric Lai123b1912020-01-25 22:14:04 +080022#include <console/console.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000023#include <device/pnp.h>
Duncan Laurie90a96c72019-03-13 17:35:22 -070024#include <ec/acpi/ec.h>
Eric Lai123b1912020-01-25 22:14:04 +080025#include <intelblocks/cpulib.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000026#include <pc80/keyboard.h>
27#include <stdint.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000028
29#include "commands.h"
30#include "ec.h"
31#include "chip.h"
32
Duncan Lauriec145e542019-04-18 16:37:50 -070033/*
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -080034 * Setting minimum length of UCSI_ACPI will ensure this region is placed out of IMD Small.
35 * Having this region out of IMD Small will prevent any memory mapping conflicts.
36 */
37#define UCSI_MIN_ALLOC_REGION_LEN CBMEM_SM_ROOT_SIZE
38/*
Duncan Lauriec145e542019-04-18 16:37:50 -070039 * The UCSI fields are defined in the UCSI specification at
40 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html
41 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/bios-implementation-of-ucsi.html
42 */
43
44static struct fieldlist ucsi_region_fields[] = {
45 FIELDLIST_NAMESTR("VER0", 8),
46 FIELDLIST_NAMESTR("VER1", 8),
47 FIELDLIST_NAMESTR("RSV0", 8),
48 FIELDLIST_NAMESTR("RSV1", 8),
49 FIELDLIST_NAMESTR("CCI0", 8),
50 FIELDLIST_NAMESTR("CCI1", 8),
51 FIELDLIST_NAMESTR("CCI2", 8),
52 FIELDLIST_NAMESTR("CCI3", 8),
53 FIELDLIST_NAMESTR("CTL0", 8),
54 FIELDLIST_NAMESTR("CTL1", 8),
55 FIELDLIST_NAMESTR("CTL2", 8),
56 FIELDLIST_NAMESTR("CTL3", 8),
57 FIELDLIST_NAMESTR("CTL4", 8),
58 FIELDLIST_NAMESTR("CTL5", 8),
59 FIELDLIST_NAMESTR("CTL6", 8),
60 FIELDLIST_NAMESTR("CTL7", 8),
61 FIELDLIST_NAMESTR("MGI0", 8),
62 FIELDLIST_NAMESTR("MGI1", 8),
63 FIELDLIST_NAMESTR("MGI2", 8),
64 FIELDLIST_NAMESTR("MGI3", 8),
65 FIELDLIST_NAMESTR("MGI4", 8),
66 FIELDLIST_NAMESTR("MGI5", 8),
67 FIELDLIST_NAMESTR("MGI6", 8),
68 FIELDLIST_NAMESTR("MGI7", 8),
69 FIELDLIST_NAMESTR("MGI8", 8),
70 FIELDLIST_NAMESTR("MGI9", 8),
71 FIELDLIST_NAMESTR("MGIA", 8),
72 FIELDLIST_NAMESTR("MGIB", 8),
73 FIELDLIST_NAMESTR("MGIC", 8),
74 FIELDLIST_NAMESTR("MGID", 8),
75 FIELDLIST_NAMESTR("MGIE", 8),
76 FIELDLIST_NAMESTR("MGIF", 8),
77 FIELDLIST_NAMESTR("MGO0", 8),
78 FIELDLIST_NAMESTR("MGO1", 8),
79 FIELDLIST_NAMESTR("MGO2", 8),
80 FIELDLIST_NAMESTR("MGO3", 8),
81 FIELDLIST_NAMESTR("MGO4", 8),
82 FIELDLIST_NAMESTR("MGO5", 8),
83 FIELDLIST_NAMESTR("MGO6", 8),
84 FIELDLIST_NAMESTR("MGO7", 8),
85 FIELDLIST_NAMESTR("MGO8", 8),
86 FIELDLIST_NAMESTR("MGO9", 8),
87 FIELDLIST_NAMESTR("MGOA", 8),
88 FIELDLIST_NAMESTR("MGOB", 8),
89 FIELDLIST_NAMESTR("MGOC", 8),
90 FIELDLIST_NAMESTR("MGOD", 8),
91 FIELDLIST_NAMESTR("MGOE", 8),
92 FIELDLIST_NAMESTR("MGOF", 8),
93};
94static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields);
95
Duncan Laurie421a9622018-10-15 02:46:45 +000096static void wilco_ec_post_complete(void *unused)
97{
98 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
99}
100BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
101 wilco_ec_post_complete, NULL);
102
103static void wilco_ec_post_memory_init(void *unused)
104{
105 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
106}
107BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
108 wilco_ec_post_memory_init, NULL);
109
110static void wilco_ec_post_video_init(void *unused)
111{
112 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
113}
114BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
115 wilco_ec_post_video_init, NULL);
116
Duncan Laurie1c968c12019-04-17 15:12:45 -0700117static void wilco_ec_post_logo_displayed(void *unused)
118{
119 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED);
120}
121BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT,
122 wilco_ec_post_logo_displayed, NULL);
123
Duncan Laurie3fbe1942018-10-15 13:39:35 -0700124static void wilco_ec_resume(void *unused)
125{
126 wilco_ec_send_noargs(KB_RESTORE);
127}
128BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
129
Eric Lai123b1912020-01-25 22:14:04 +0800130static int wilco_set_cpu_id(void)
131{
132 uint32_t cpu_phy_cores, cpu_virtual_cores;
133
134 cpu_read_topology(&cpu_phy_cores, &cpu_virtual_cores);
135 return wilco_ec_set_cpuid(cpu_get_cpuid(), cpu_phy_cores, 0);
136}
137
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000138static void wilco_ec_init(struct device *dev)
139{
140 if (!dev->enabled)
141 return;
142
Duncan Laurie90a96c72019-03-13 17:35:22 -0700143 /* Disable S0ix support in EC RAM with ACPI EC interface */
144 if (!acpi_is_wakeup_s3()) {
145 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
146 CONFIG_EC_BASE_ACPI_DATA);
147 ec_write(EC_RAM_S0IX_SUPPORT, 0);
148 }
149
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000150 /* Print EC firmware information */
151 wilco_ec_print_all_info();
152
153 /* Initialize keyboard, ignore emulated PS/2 mouse */
154 pc_keyboard_init(NO_AUX_DEVICE);
155
156 /* Direct power button to the host for processing */
157 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -0700158
159 /* Unmute speakers */
160 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -0700161
162 /* Enable WiFi radio */
163 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -0800164
165 /* Turn on camera power */
166 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Eric Lai123b1912020-01-25 22:14:04 +0800167
168 /* Set cpu id and phy cores */
169 if (wilco_set_cpu_id())
170 printk(BIOS_ERR, "EC: use default cpu power table\n");
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000171}
172
173static void wilco_ec_resource(struct device *dev, int index,
174 size_t base, size_t size)
175{
176 struct resource *res = new_resource(dev, index);
177 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
178 res->base = base;
179 res->size = size;
180}
181
182static void wilco_ec_read_resources(struct device *dev)
183{
184 /* ACPI command and data regions */
185 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
186
187 /* Host command and data regions */
188 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
189
190 /* Packet region */
191 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
192}
193
Duncan Lauriec145e542019-04-18 16:37:50 -0700194static void wilco_ec_fill_ssdt_generator(struct device *dev)
195{
196 struct opregion opreg;
197 void *region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800198 size_t ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700199
200 if (!dev->enabled)
201 return;
202
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800203 ucsi_alloc_region_len = ucsi_region_len < UCSI_MIN_ALLOC_REGION_LEN ?
204 UCSI_MIN_ALLOC_REGION_LEN : ucsi_region_len;
205 region_ptr = cbmem_add(CBMEM_ID_ACPI_UCSI, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700206 if (!region_ptr)
207 return;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800208 memset(region_ptr, 0, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700209
210 opreg.name = "UCSM";
211 opreg.regionspace = SYSTEMMEMORY;
212 opreg.regionoffset = (uintptr_t)region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800213 opreg.regionlen = ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700214
215 acpigen_write_scope(acpi_device_path_join(dev, "UCSI"));
216 acpigen_write_name("_CRS");
217 acpigen_write_resourcetemplate_header();
218 acpigen_write_mem32fixed(1, (uintptr_t)region_ptr, ucsi_region_len);
219 acpigen_write_resourcetemplate_footer();
220 acpigen_write_opregion(&opreg);
221 acpigen_write_field(opreg.name, ucsi_region_fields, ucsi_region_len,
222 FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE);
223 acpigen_pop_len(); /* Scope */
224}
225
226static const char *wilco_ec_acpi_name(const struct device *dev)
227{
228 return "EC0";
229}
230
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000231static struct device_operations ops = {
Duncan Lauriec145e542019-04-18 16:37:50 -0700232 .init = wilco_ec_init,
233 .read_resources = wilco_ec_read_resources,
234 .enable_resources = DEVICE_NOOP,
235 .set_resources = DEVICE_NOOP,
236 .acpi_fill_ssdt_generator = wilco_ec_fill_ssdt_generator,
237 .acpi_name = wilco_ec_acpi_name,
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000238};
239
240static struct pnp_info info[] = {
241 { NULL, 0, 0, 0, }
242};
243
244static void wilco_ec_enable_dev(struct device *dev)
245{
246 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
247}
248
249struct chip_operations ec_google_wilco_ops = {
250 CHIP_NAME("Google Wilco EC")
251 .enable_dev = wilco_ec_enable_dev,
252};