blob: b44cbd6c64cde7255f89702f05541018fd6116d6 [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>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000025
26#include "commands.h"
27#include "ec.h"
28#include "chip.h"
29
Duncan Lauriec145e542019-04-18 16:37:50 -070030/*
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -080031 * Setting minimum length of UCSI_ACPI will ensure this region is placed out of IMD Small.
32 * Having this region out of IMD Small will prevent any memory mapping conflicts.
33 */
34#define UCSI_MIN_ALLOC_REGION_LEN CBMEM_SM_ROOT_SIZE
35/*
Duncan Lauriec145e542019-04-18 16:37:50 -070036 * The UCSI fields are defined in the UCSI specification at
37 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html
38 * https://www.intel.com/content/www/us/en/io/universal-serial-bus/bios-implementation-of-ucsi.html
39 */
40
41static struct fieldlist ucsi_region_fields[] = {
42 FIELDLIST_NAMESTR("VER0", 8),
43 FIELDLIST_NAMESTR("VER1", 8),
44 FIELDLIST_NAMESTR("RSV0", 8),
45 FIELDLIST_NAMESTR("RSV1", 8),
46 FIELDLIST_NAMESTR("CCI0", 8),
47 FIELDLIST_NAMESTR("CCI1", 8),
48 FIELDLIST_NAMESTR("CCI2", 8),
49 FIELDLIST_NAMESTR("CCI3", 8),
50 FIELDLIST_NAMESTR("CTL0", 8),
51 FIELDLIST_NAMESTR("CTL1", 8),
52 FIELDLIST_NAMESTR("CTL2", 8),
53 FIELDLIST_NAMESTR("CTL3", 8),
54 FIELDLIST_NAMESTR("CTL4", 8),
55 FIELDLIST_NAMESTR("CTL5", 8),
56 FIELDLIST_NAMESTR("CTL6", 8),
57 FIELDLIST_NAMESTR("CTL7", 8),
58 FIELDLIST_NAMESTR("MGI0", 8),
59 FIELDLIST_NAMESTR("MGI1", 8),
60 FIELDLIST_NAMESTR("MGI2", 8),
61 FIELDLIST_NAMESTR("MGI3", 8),
62 FIELDLIST_NAMESTR("MGI4", 8),
63 FIELDLIST_NAMESTR("MGI5", 8),
64 FIELDLIST_NAMESTR("MGI6", 8),
65 FIELDLIST_NAMESTR("MGI7", 8),
66 FIELDLIST_NAMESTR("MGI8", 8),
67 FIELDLIST_NAMESTR("MGI9", 8),
68 FIELDLIST_NAMESTR("MGIA", 8),
69 FIELDLIST_NAMESTR("MGIB", 8),
70 FIELDLIST_NAMESTR("MGIC", 8),
71 FIELDLIST_NAMESTR("MGID", 8),
72 FIELDLIST_NAMESTR("MGIE", 8),
73 FIELDLIST_NAMESTR("MGIF", 8),
74 FIELDLIST_NAMESTR("MGO0", 8),
75 FIELDLIST_NAMESTR("MGO1", 8),
76 FIELDLIST_NAMESTR("MGO2", 8),
77 FIELDLIST_NAMESTR("MGO3", 8),
78 FIELDLIST_NAMESTR("MGO4", 8),
79 FIELDLIST_NAMESTR("MGO5", 8),
80 FIELDLIST_NAMESTR("MGO6", 8),
81 FIELDLIST_NAMESTR("MGO7", 8),
82 FIELDLIST_NAMESTR("MGO8", 8),
83 FIELDLIST_NAMESTR("MGO9", 8),
84 FIELDLIST_NAMESTR("MGOA", 8),
85 FIELDLIST_NAMESTR("MGOB", 8),
86 FIELDLIST_NAMESTR("MGOC", 8),
87 FIELDLIST_NAMESTR("MGOD", 8),
88 FIELDLIST_NAMESTR("MGOE", 8),
89 FIELDLIST_NAMESTR("MGOF", 8),
90};
91static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields);
92
Duncan Laurie421a9622018-10-15 02:46:45 +000093static void wilco_ec_post_complete(void *unused)
94{
95 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
96}
97BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
98 wilco_ec_post_complete, NULL);
99
100static void wilco_ec_post_memory_init(void *unused)
101{
102 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
103}
104BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
105 wilco_ec_post_memory_init, NULL);
106
107static void wilco_ec_post_video_init(void *unused)
108{
109 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
110}
111BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
112 wilco_ec_post_video_init, NULL);
113
Duncan Laurie1c968c12019-04-17 15:12:45 -0700114static void wilco_ec_post_logo_displayed(void *unused)
115{
116 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED);
117}
118BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT,
119 wilco_ec_post_logo_displayed, NULL);
120
Duncan Laurie3fbe1942018-10-15 13:39:35 -0700121static void wilco_ec_resume(void *unused)
122{
123 wilco_ec_send_noargs(KB_RESTORE);
124}
125BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
126
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000127static void wilco_ec_init(struct device *dev)
128{
129 if (!dev->enabled)
130 return;
131
Duncan Laurie90a96c72019-03-13 17:35:22 -0700132 /* Disable S0ix support in EC RAM with ACPI EC interface */
133 if (!acpi_is_wakeup_s3()) {
134 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
135 CONFIG_EC_BASE_ACPI_DATA);
136 ec_write(EC_RAM_S0IX_SUPPORT, 0);
137 }
138
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000139 /* Print EC firmware information */
140 wilco_ec_print_all_info();
141
142 /* Initialize keyboard, ignore emulated PS/2 mouse */
143 pc_keyboard_init(NO_AUX_DEVICE);
144
145 /* Direct power button to the host for processing */
146 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -0700147
148 /* Unmute speakers */
149 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -0700150
151 /* Enable WiFi radio */
152 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -0800153
154 /* Turn on camera power */
155 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000156}
157
158static void wilco_ec_resource(struct device *dev, int index,
159 size_t base, size_t size)
160{
161 struct resource *res = new_resource(dev, index);
162 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
163 res->base = base;
164 res->size = size;
165}
166
167static void wilco_ec_read_resources(struct device *dev)
168{
169 /* ACPI command and data regions */
170 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
171
172 /* Host command and data regions */
173 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
174
175 /* Packet region */
176 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
177}
178
Duncan Lauriec145e542019-04-18 16:37:50 -0700179static void wilco_ec_fill_ssdt_generator(struct device *dev)
180{
181 struct opregion opreg;
182 void *region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800183 size_t ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700184
185 if (!dev->enabled)
186 return;
187
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800188 ucsi_alloc_region_len = ucsi_region_len < UCSI_MIN_ALLOC_REGION_LEN ?
189 UCSI_MIN_ALLOC_REGION_LEN : ucsi_region_len;
190 region_ptr = cbmem_add(CBMEM_ID_ACPI_UCSI, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700191 if (!region_ptr)
192 return;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800193 memset(region_ptr, 0, ucsi_alloc_region_len);
Duncan Lauriec145e542019-04-18 16:37:50 -0700194
195 opreg.name = "UCSM";
196 opreg.regionspace = SYSTEMMEMORY;
197 opreg.regionoffset = (uintptr_t)region_ptr;
Bernardo Perez Priego1d8568c2020-01-14 15:59:19 -0800198 opreg.regionlen = ucsi_alloc_region_len;
Duncan Lauriec145e542019-04-18 16:37:50 -0700199
200 acpigen_write_scope(acpi_device_path_join(dev, "UCSI"));
201 acpigen_write_name("_CRS");
202 acpigen_write_resourcetemplate_header();
203 acpigen_write_mem32fixed(1, (uintptr_t)region_ptr, ucsi_region_len);
204 acpigen_write_resourcetemplate_footer();
205 acpigen_write_opregion(&opreg);
206 acpigen_write_field(opreg.name, ucsi_region_fields, ucsi_region_len,
207 FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE);
208 acpigen_pop_len(); /* Scope */
209}
210
211static const char *wilco_ec_acpi_name(const struct device *dev)
212{
213 return "EC0";
214}
215
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000216static struct device_operations ops = {
Duncan Lauriec145e542019-04-18 16:37:50 -0700217 .init = wilco_ec_init,
218 .read_resources = wilco_ec_read_resources,
219 .enable_resources = DEVICE_NOOP,
220 .set_resources = DEVICE_NOOP,
221 .acpi_fill_ssdt_generator = wilco_ec_fill_ssdt_generator,
222 .acpi_name = wilco_ec_acpi_name,
Duncan Laurieb29e2d52018-10-15 02:40:21 +0000223};
224
225static struct pnp_info info[] = {
226 { NULL, 0, 0, 0, }
227};
228
229static void wilco_ec_enable_dev(struct device *dev)
230{
231 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
232}
233
234struct chip_operations ec_google_wilco_ops = {
235 CHIP_NAME("Google Wilco EC")
236 .enable_dev = wilco_ec_enable_dev,
237};