Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 15 | #include <arch/acpi.h> |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 16 | #include <arch/acpi_device.h> |
| 17 | #include <arch/acpigen.h> |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 18 | #include <arch/cpu.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> |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 21 | #include <console/console.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 22 | #include <device/pnp.h> |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 23 | #include <ec/acpi/ec.h> |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 24 | #include <intelblocks/cpulib.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 25 | #include <pc80/keyboard.h> |
| 26 | #include <stdint.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 27 | |
| 28 | #include "commands.h" |
| 29 | #include "ec.h" |
| 30 | #include "chip.h" |
| 31 | |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 32 | /* |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 33 | * Setting minimum length of UCSI_ACPI will ensure this region is placed out of IMD Small. |
| 34 | * Having this region out of IMD Small will prevent any memory mapping conflicts. |
| 35 | */ |
| 36 | #define UCSI_MIN_ALLOC_REGION_LEN CBMEM_SM_ROOT_SIZE |
| 37 | /* |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 38 | * The UCSI fields are defined in the UCSI specification at |
| 39 | * https://www.intel.com/content/www/us/en/io/universal-serial-bus/usb-type-c-ucsi-spec.html |
| 40 | * https://www.intel.com/content/www/us/en/io/universal-serial-bus/bios-implementation-of-ucsi.html |
| 41 | */ |
| 42 | |
| 43 | static struct fieldlist ucsi_region_fields[] = { |
| 44 | FIELDLIST_NAMESTR("VER0", 8), |
| 45 | FIELDLIST_NAMESTR("VER1", 8), |
| 46 | FIELDLIST_NAMESTR("RSV0", 8), |
| 47 | FIELDLIST_NAMESTR("RSV1", 8), |
| 48 | FIELDLIST_NAMESTR("CCI0", 8), |
| 49 | FIELDLIST_NAMESTR("CCI1", 8), |
| 50 | FIELDLIST_NAMESTR("CCI2", 8), |
| 51 | FIELDLIST_NAMESTR("CCI3", 8), |
| 52 | FIELDLIST_NAMESTR("CTL0", 8), |
| 53 | FIELDLIST_NAMESTR("CTL1", 8), |
| 54 | FIELDLIST_NAMESTR("CTL2", 8), |
| 55 | FIELDLIST_NAMESTR("CTL3", 8), |
| 56 | FIELDLIST_NAMESTR("CTL4", 8), |
| 57 | FIELDLIST_NAMESTR("CTL5", 8), |
| 58 | FIELDLIST_NAMESTR("CTL6", 8), |
| 59 | FIELDLIST_NAMESTR("CTL7", 8), |
| 60 | FIELDLIST_NAMESTR("MGI0", 8), |
| 61 | FIELDLIST_NAMESTR("MGI1", 8), |
| 62 | FIELDLIST_NAMESTR("MGI2", 8), |
| 63 | FIELDLIST_NAMESTR("MGI3", 8), |
| 64 | FIELDLIST_NAMESTR("MGI4", 8), |
| 65 | FIELDLIST_NAMESTR("MGI5", 8), |
| 66 | FIELDLIST_NAMESTR("MGI6", 8), |
| 67 | FIELDLIST_NAMESTR("MGI7", 8), |
| 68 | FIELDLIST_NAMESTR("MGI8", 8), |
| 69 | FIELDLIST_NAMESTR("MGI9", 8), |
| 70 | FIELDLIST_NAMESTR("MGIA", 8), |
| 71 | FIELDLIST_NAMESTR("MGIB", 8), |
| 72 | FIELDLIST_NAMESTR("MGIC", 8), |
| 73 | FIELDLIST_NAMESTR("MGID", 8), |
| 74 | FIELDLIST_NAMESTR("MGIE", 8), |
| 75 | FIELDLIST_NAMESTR("MGIF", 8), |
| 76 | FIELDLIST_NAMESTR("MGO0", 8), |
| 77 | FIELDLIST_NAMESTR("MGO1", 8), |
| 78 | FIELDLIST_NAMESTR("MGO2", 8), |
| 79 | FIELDLIST_NAMESTR("MGO3", 8), |
| 80 | FIELDLIST_NAMESTR("MGO4", 8), |
| 81 | FIELDLIST_NAMESTR("MGO5", 8), |
| 82 | FIELDLIST_NAMESTR("MGO6", 8), |
| 83 | FIELDLIST_NAMESTR("MGO7", 8), |
| 84 | FIELDLIST_NAMESTR("MGO8", 8), |
| 85 | FIELDLIST_NAMESTR("MGO9", 8), |
| 86 | FIELDLIST_NAMESTR("MGOA", 8), |
| 87 | FIELDLIST_NAMESTR("MGOB", 8), |
| 88 | FIELDLIST_NAMESTR("MGOC", 8), |
| 89 | FIELDLIST_NAMESTR("MGOD", 8), |
| 90 | FIELDLIST_NAMESTR("MGOE", 8), |
| 91 | FIELDLIST_NAMESTR("MGOF", 8), |
| 92 | }; |
| 93 | static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields); |
| 94 | |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 95 | static void wilco_ec_post_complete(void *unused) |
| 96 | { |
| 97 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE); |
| 98 | } |
| 99 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 100 | wilco_ec_post_complete, NULL); |
| 101 | |
| 102 | static void wilco_ec_post_memory_init(void *unused) |
| 103 | { |
| 104 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT); |
| 105 | } |
| 106 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, |
| 107 | wilco_ec_post_memory_init, NULL); |
| 108 | |
| 109 | static void wilco_ec_post_video_init(void *unused) |
| 110 | { |
| 111 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT); |
| 112 | } |
| 113 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, |
| 114 | wilco_ec_post_video_init, NULL); |
| 115 | |
Duncan Laurie | 1c968c1 | 2019-04-17 15:12:45 -0700 | [diff] [blame] | 116 | static void wilco_ec_post_logo_displayed(void *unused) |
| 117 | { |
| 118 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED); |
| 119 | } |
| 120 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, |
| 121 | wilco_ec_post_logo_displayed, NULL); |
| 122 | |
Duncan Laurie | 3fbe194 | 2018-10-15 13:39:35 -0700 | [diff] [blame] | 123 | static void wilco_ec_resume(void *unused) |
| 124 | { |
| 125 | wilco_ec_send_noargs(KB_RESTORE); |
| 126 | } |
| 127 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL); |
| 128 | |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 129 | static int wilco_set_cpu_id(void) |
| 130 | { |
| 131 | uint32_t cpu_phy_cores, cpu_virtual_cores; |
| 132 | |
| 133 | cpu_read_topology(&cpu_phy_cores, &cpu_virtual_cores); |
| 134 | return wilco_ec_set_cpuid(cpu_get_cpuid(), cpu_phy_cores, 0); |
| 135 | } |
| 136 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 137 | static void wilco_ec_init(struct device *dev) |
| 138 | { |
| 139 | if (!dev->enabled) |
| 140 | return; |
| 141 | |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 142 | /* Disable S0ix support in EC RAM with ACPI EC interface */ |
| 143 | if (!acpi_is_wakeup_s3()) { |
| 144 | ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND, |
| 145 | CONFIG_EC_BASE_ACPI_DATA); |
| 146 | ec_write(EC_RAM_S0IX_SUPPORT, 0); |
| 147 | } |
| 148 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 149 | /* Print EC firmware information */ |
| 150 | wilco_ec_print_all_info(); |
| 151 | |
| 152 | /* Initialize keyboard, ignore emulated PS/2 mouse */ |
| 153 | pc_keyboard_init(NO_AUX_DEVICE); |
| 154 | |
| 155 | /* Direct power button to the host for processing */ |
| 156 | wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1); |
Duncan Laurie | 29f2b25 | 2018-10-19 17:01:31 -0700 | [diff] [blame] | 157 | |
| 158 | /* Unmute speakers */ |
| 159 | wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS); |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 160 | |
| 161 | /* Enable WiFi radio */ |
| 162 | wilco_ec_radio_control(RADIO_WIFI, 1); |
Duncan Laurie | 221ebdc | 2018-11-29 17:59:04 -0800 | [diff] [blame] | 163 | |
| 164 | /* Turn on camera power */ |
| 165 | wilco_ec_send(KB_CAMERA, CAMERA_ON); |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 166 | |
| 167 | /* Set cpu id and phy cores */ |
| 168 | if (wilco_set_cpu_id()) |
| 169 | printk(BIOS_ERR, "EC: use default cpu power table\n"); |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void wilco_ec_resource(struct device *dev, int index, |
| 173 | size_t base, size_t size) |
| 174 | { |
| 175 | struct resource *res = new_resource(dev, index); |
| 176 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 177 | res->base = base; |
| 178 | res->size = size; |
| 179 | } |
| 180 | |
| 181 | static void wilco_ec_read_resources(struct device *dev) |
| 182 | { |
| 183 | /* ACPI command and data regions */ |
| 184 | wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8); |
| 185 | |
| 186 | /* Host command and data regions */ |
| 187 | wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8); |
| 188 | |
| 189 | /* Packet region */ |
| 190 | wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16); |
| 191 | } |
| 192 | |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 193 | static void wilco_ec_fill_ssdt_generator(struct device *dev) |
| 194 | { |
| 195 | struct opregion opreg; |
| 196 | void *region_ptr; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 197 | size_t ucsi_alloc_region_len; |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 198 | |
| 199 | if (!dev->enabled) |
| 200 | return; |
| 201 | |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 202 | ucsi_alloc_region_len = ucsi_region_len < UCSI_MIN_ALLOC_REGION_LEN ? |
| 203 | UCSI_MIN_ALLOC_REGION_LEN : ucsi_region_len; |
| 204 | region_ptr = cbmem_add(CBMEM_ID_ACPI_UCSI, ucsi_alloc_region_len); |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 205 | if (!region_ptr) |
| 206 | return; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 207 | memset(region_ptr, 0, ucsi_alloc_region_len); |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 208 | |
| 209 | opreg.name = "UCSM"; |
| 210 | opreg.regionspace = SYSTEMMEMORY; |
| 211 | opreg.regionoffset = (uintptr_t)region_ptr; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 212 | opreg.regionlen = ucsi_alloc_region_len; |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 213 | |
| 214 | acpigen_write_scope(acpi_device_path_join(dev, "UCSI")); |
| 215 | acpigen_write_name("_CRS"); |
| 216 | acpigen_write_resourcetemplate_header(); |
| 217 | acpigen_write_mem32fixed(1, (uintptr_t)region_ptr, ucsi_region_len); |
| 218 | acpigen_write_resourcetemplate_footer(); |
| 219 | acpigen_write_opregion(&opreg); |
| 220 | acpigen_write_field(opreg.name, ucsi_region_fields, ucsi_region_len, |
| 221 | FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE); |
| 222 | acpigen_pop_len(); /* Scope */ |
| 223 | } |
| 224 | |
| 225 | static const char *wilco_ec_acpi_name(const struct device *dev) |
| 226 | { |
| 227 | return "EC0"; |
| 228 | } |
| 229 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 230 | static struct device_operations ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame^] | 231 | .init = wilco_ec_init, |
| 232 | .read_resources = wilco_ec_read_resources, |
| 233 | .enable_resources = DEVICE_NOOP, |
| 234 | .set_resources = DEVICE_NOOP, |
| 235 | .acpi_fill_ssdt = wilco_ec_fill_ssdt_generator, |
| 236 | .acpi_name = wilco_ec_acpi_name, |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | static struct pnp_info info[] = { |
| 240 | { NULL, 0, 0, 0, } |
| 241 | }; |
| 242 | |
| 243 | static void wilco_ec_enable_dev(struct device *dev) |
| 244 | { |
| 245 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info); |
| 246 | } |
| 247 | |
| 248 | struct chip_operations ec_google_wilco_ops = { |
| 249 | CHIP_NAME("Google Wilco EC") |
| 250 | .enable_dev = wilco_ec_enable_dev, |
| 251 | }; |