Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 1 | /* |
| 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 Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 16 | #include <arch/acpi.h> |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 17 | #include <arch/acpi_device.h> |
| 18 | #include <arch/acpigen.h> |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 19 | #include <bootstate.h> |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 20 | #include <cbmem.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 21 | #include <device/pnp.h> |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 22 | #include <ec/acpi/ec.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 23 | #include <pc80/keyboard.h> |
| 24 | #include <stdint.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 25 | |
| 26 | #include "commands.h" |
| 27 | #include "ec.h" |
| 28 | #include "chip.h" |
| 29 | |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 30 | /* |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 31 | * 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 Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 36 | * 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 | |
| 41 | static 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 | }; |
| 91 | static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields); |
| 92 | |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 93 | static void wilco_ec_post_complete(void *unused) |
| 94 | { |
| 95 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE); |
| 96 | } |
| 97 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 98 | wilco_ec_post_complete, NULL); |
| 99 | |
| 100 | static void wilco_ec_post_memory_init(void *unused) |
| 101 | { |
| 102 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT); |
| 103 | } |
| 104 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, |
| 105 | wilco_ec_post_memory_init, NULL); |
| 106 | |
| 107 | static void wilco_ec_post_video_init(void *unused) |
| 108 | { |
| 109 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT); |
| 110 | } |
| 111 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, |
| 112 | wilco_ec_post_video_init, NULL); |
| 113 | |
Duncan Laurie | 1c968c1 | 2019-04-17 15:12:45 -0700 | [diff] [blame] | 114 | static void wilco_ec_post_logo_displayed(void *unused) |
| 115 | { |
| 116 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED); |
| 117 | } |
| 118 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, |
| 119 | wilco_ec_post_logo_displayed, NULL); |
| 120 | |
Duncan Laurie | 3fbe194 | 2018-10-15 13:39:35 -0700 | [diff] [blame] | 121 | static void wilco_ec_resume(void *unused) |
| 122 | { |
| 123 | wilco_ec_send_noargs(KB_RESTORE); |
| 124 | } |
| 125 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL); |
| 126 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 127 | static void wilco_ec_init(struct device *dev) |
| 128 | { |
| 129 | if (!dev->enabled) |
| 130 | return; |
| 131 | |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 132 | /* 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 Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 139 | /* 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 Laurie | 29f2b25 | 2018-10-19 17:01:31 -0700 | [diff] [blame] | 147 | |
| 148 | /* Unmute speakers */ |
| 149 | wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS); |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 150 | |
| 151 | /* Enable WiFi radio */ |
| 152 | wilco_ec_radio_control(RADIO_WIFI, 1); |
Duncan Laurie | 221ebdc | 2018-11-29 17:59:04 -0800 | [diff] [blame] | 153 | |
| 154 | /* Turn on camera power */ |
| 155 | wilco_ec_send(KB_CAMERA, CAMERA_ON); |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static 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 | |
| 167 | static 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 Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 179 | static void wilco_ec_fill_ssdt_generator(struct device *dev) |
| 180 | { |
| 181 | struct opregion opreg; |
| 182 | void *region_ptr; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 183 | size_t ucsi_alloc_region_len; |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 184 | |
| 185 | if (!dev->enabled) |
| 186 | return; |
| 187 | |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 188 | 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 Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 191 | if (!region_ptr) |
| 192 | return; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 193 | memset(region_ptr, 0, ucsi_alloc_region_len); |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 194 | |
| 195 | opreg.name = "UCSM"; |
| 196 | opreg.regionspace = SYSTEMMEMORY; |
| 197 | opreg.regionoffset = (uintptr_t)region_ptr; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 198 | opreg.regionlen = ucsi_alloc_region_len; |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 199 | |
| 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 | |
| 211 | static const char *wilco_ec_acpi_name(const struct device *dev) |
| 212 | { |
| 213 | return "EC0"; |
| 214 | } |
| 215 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 216 | static struct device_operations ops = { |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 217 | .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 Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | static struct pnp_info info[] = { |
| 226 | { NULL, 0, 0, 0, } |
| 227 | }; |
| 228 | |
| 229 | static void wilco_ec_enable_dev(struct device *dev) |
| 230 | { |
| 231 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info); |
| 232 | } |
| 233 | |
| 234 | struct chip_operations ec_google_wilco_ops = { |
| 235 | CHIP_NAME("Google Wilco EC") |
| 236 | .enable_dev = wilco_ec_enable_dev, |
| 237 | }; |