blob: 3c70294d061b21695109c22c5709e0a2d0ec351f [file] [log] [blame]
Angel Pons210a0082020-04-02 23:48:24 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurieb29e2d52018-10-15 02:40:21 +00002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi_device.h>
Elyes Haouas6dc65d92022-10-31 14:08:51 +01004#include <acpi/acpi.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpigen.h>
Duncan Laurie421a9622018-10-15 02:46:45 +00006#include <bootstate.h>
Duncan Lauriec145e542019-04-18 16:37:50 -07007#include <cbmem.h>
Eric Lai123b1912020-01-25 22:14:04 +08008#include <console/console.h>
Elyes Haouas6dc65d92022-10-31 14:08:51 +01009#include <cpu/cpu.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000010#include <device/pnp.h>
Duncan Laurie90a96c72019-03-13 17:35:22 -070011#include <ec/acpi/ec.h>
Eric Lai123b1912020-01-25 22:14:04 +080012#include <intelblocks/cpulib.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000013#include <pc80/keyboard.h>
14#include <stdint.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000015
16#include "commands.h"
17#include "ec.h"
18#include "chip.h"
19
Duncan Lauriec145e542019-04-18 16:37:50 -070020/*
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -080021 * Setting minimum length of UCSI_ACPI will ensure this region is placed out of IMD Small.
22 * Having this region out of IMD Small will prevent any memory mapping conflicts.
23 */
24#define UCSI_MIN_ALLOC_REGION_LEN CBMEM_SM_ROOT_SIZE
25/*
Duncan Lauriec145e542019-04-18 16:37:50 -070026 * The UCSI fields are defined in the UCSI specification at
27 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html
28 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/bios-implementation-of-ucsi.html
29 */
30
31static struct fieldlist ucsi_region_fields[] = {
32 FIELDLIST_NAMESTR("VER0", 8),
33 FIELDLIST_NAMESTR("VER1", 8),
34 FIELDLIST_NAMESTR("RSV0", 8),
35 FIELDLIST_NAMESTR("RSV1", 8),
36 FIELDLIST_NAMESTR("CCI0", 8),
37 FIELDLIST_NAMESTR("CCI1", 8),
38 FIELDLIST_NAMESTR("CCI2", 8),
39 FIELDLIST_NAMESTR("CCI3", 8),
40 FIELDLIST_NAMESTR("CTL0", 8),
41 FIELDLIST_NAMESTR("CTL1", 8),
42 FIELDLIST_NAMESTR("CTL2", 8),
43 FIELDLIST_NAMESTR("CTL3", 8),
44 FIELDLIST_NAMESTR("CTL4", 8),
45 FIELDLIST_NAMESTR("CTL5", 8),
46 FIELDLIST_NAMESTR("CTL6", 8),
47 FIELDLIST_NAMESTR("CTL7", 8),
48 FIELDLIST_NAMESTR("MGI0", 8),
49 FIELDLIST_NAMESTR("MGI1", 8),
50 FIELDLIST_NAMESTR("MGI2", 8),
51 FIELDLIST_NAMESTR("MGI3", 8),
52 FIELDLIST_NAMESTR("MGI4", 8),
53 FIELDLIST_NAMESTR("MGI5", 8),
54 FIELDLIST_NAMESTR("MGI6", 8),
55 FIELDLIST_NAMESTR("MGI7", 8),
56 FIELDLIST_NAMESTR("MGI8", 8),
57 FIELDLIST_NAMESTR("MGI9", 8),
58 FIELDLIST_NAMESTR("MGIA", 8),
59 FIELDLIST_NAMESTR("MGIB", 8),
60 FIELDLIST_NAMESTR("MGIC", 8),
61 FIELDLIST_NAMESTR("MGID", 8),
62 FIELDLIST_NAMESTR("MGIE", 8),
63 FIELDLIST_NAMESTR("MGIF", 8),
64 FIELDLIST_NAMESTR("MGO0", 8),
65 FIELDLIST_NAMESTR("MGO1", 8),
66 FIELDLIST_NAMESTR("MGO2", 8),
67 FIELDLIST_NAMESTR("MGO3", 8),
68 FIELDLIST_NAMESTR("MGO4", 8),
69 FIELDLIST_NAMESTR("MGO5", 8),
70 FIELDLIST_NAMESTR("MGO6", 8),
71 FIELDLIST_NAMESTR("MGO7", 8),
72 FIELDLIST_NAMESTR("MGO8", 8),
73 FIELDLIST_NAMESTR("MGO9", 8),
74 FIELDLIST_NAMESTR("MGOA", 8),
75 FIELDLIST_NAMESTR("MGOB", 8),
76 FIELDLIST_NAMESTR("MGOC", 8),
77 FIELDLIST_NAMESTR("MGOD", 8),
78 FIELDLIST_NAMESTR("MGOE", 8),
79 FIELDLIST_NAMESTR("MGOF", 8),
80};
81static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields);
82
Duncan Laurie421a9622018-10-15 02:46:45 +000083static void wilco_ec_post_complete(void *unused)
84{
85 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
86}
87BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
88 wilco_ec_post_complete, NULL);
89
90static void wilco_ec_post_memory_init(void *unused)
91{
92 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
93}
94BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
95 wilco_ec_post_memory_init, NULL);
96
97static void wilco_ec_post_video_init(void *unused)
98{
99 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
100}
101BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
102 wilco_ec_post_video_init, NULL);
103
Duncan Laurie1c968c12019-04-17 15:12:45 -0700104static void wilco_ec_post_logo_displayed(void *unused)
105{
106 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED);
107}
108BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT,
109 wilco_ec_post_logo_displayed, NULL);
110
Duncan Laurie3fbe1942018-10-15 13:39:35 -0700111static void wilco_ec_resume(void *unused)
112{
113 wilco_ec_send_noargs(KB_RESTORE);
114}
115BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
116
Eric Lai123b1912020-01-25 22:14:04 +0800117static int wilco_set_cpu_id(void)
118{
119 uint32_t cpu_phy_cores, cpu_virtual_cores;
120
121 cpu_read_topology(&cpu_phy_cores, &cpu_virtual_cores);
122 return wilco_ec_set_cpuid(cpu_get_cpuid(), cpu_phy_cores, 0);
123}
124
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000125static void wilco_ec_init(struct device *dev)
126{
127 if (!dev->enabled)
128 return;
129
Duncan Laurie90a96c72019-03-13 17:35:22 -0700130 /* Disable S0ix support in EC RAM with ACPI EC interface */
131 if (!acpi_is_wakeup_s3()) {
132 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
133 CONFIG_EC_BASE_ACPI_DATA);
134 ec_write(EC_RAM_S0IX_SUPPORT, 0);
135 }
136
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000137 /* Print EC firmware information */
138 wilco_ec_print_all_info();
139
140 /* Initialize keyboard, ignore emulated PS/2 mouse */
141 pc_keyboard_init(NO_AUX_DEVICE);
142
143 /* Direct power button to the host for processing */
144 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -0700145
146 /* Unmute speakers */
147 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -0700148
149 /* Enable WiFi radio */
150 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -0800151
152 /* Turn on camera power */
153 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Eric Lai123b1912020-01-25 22:14:04 +0800154
155 /* Set cpu id and phy cores */
156 if (wilco_set_cpu_id())
157 printk(BIOS_ERR, "EC: use default cpu power table\n");
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000158}
159
160static void wilco_ec_resource(struct device *dev, int index,
161 size_t base, size_t size)
162{
163 struct resource *res = new_resource(dev, index);
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000164 res->base = base;
165 res->size = size;
Kyösti Mälkki4e4edf72022-05-26 19:03:55 +0300166 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000167}
168
169static void wilco_ec_read_resources(struct device *dev)
170{
171 /* ACPI command and data regions */
172 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
173
174 /* Host command and data regions */
175 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
176
177 /* Packet region */
178 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
179}
180
Furquan Shaikh7536a392020-04-24 21:59:21 -0700181static void wilco_ec_fill_ssdt_generator(const struct device *dev)
Duncan Lauriec145e542019-04-18 16:37:50 -0700182{
183 struct opregion opreg;
184 void *region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800185 size_t ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700186
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800187 ucsi_alloc_region_len = ucsi_region_len < UCSI_MIN_ALLOC_REGION_LEN ?
188 UCSI_MIN_ALLOC_REGION_LEN : ucsi_region_len;
189 region_ptr = cbmem_add(CBMEM_ID_ACPI_UCSI, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700190 if (!region_ptr)
191 return;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800192 memset(region_ptr, 0, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700193
194 opreg.name = "UCSM";
195 opreg.regionspace = SYSTEMMEMORY;
196 opreg.regionoffset = (uintptr_t)region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800197 opreg.regionlen = ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700198
CoolStar4a587b82023-03-26 03:52:54 -0700199 acpigen_write_scope("\\_SB.UCSI");
Duncan Lauriec145e542019-04-18 16:37:50 -0700200 acpigen_write_name("_CRS");
201 acpigen_write_resourcetemplate_header();
202 acpigen_write_mem32fixed(1, (uintptr_t)region_ptr, ucsi_region_len);
203 acpigen_write_resourcetemplate_footer();
204 acpigen_write_opregion(&opreg);
205 acpigen_write_field(opreg.name, ucsi_region_fields, ucsi_region_len,
206 FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE);
207 acpigen_pop_len(); /* Scope */
208}
209
210static const char *wilco_ec_acpi_name(const struct device *dev)
211{
212 return "EC0";
213}
214
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000215static struct device_operations ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200216 .init = wilco_ec_init,
217 .read_resources = wilco_ec_read_resources,
Nico Huber2f8ba692020-04-05 14:05:24 +0200218 .set_resources = noop_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200219 .acpi_fill_ssdt = wilco_ec_fill_ssdt_generator,
220 .acpi_name = wilco_ec_acpi_name,
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000221};
222
223static struct pnp_info info[] = {
224 { NULL, 0, 0, 0, }
225};
226
227static void wilco_ec_enable_dev(struct device *dev)
228{
229 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
230}
231
232struct chip_operations ec_google_wilco_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900233 .name = "Google Wilco EC",
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000234 .enable_dev = wilco_ec_enable_dev,
235};