Angel Pons | 210a008 | 2020-04-02 23:48:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <acpi/acpigen.h> |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 6 | #include <arch/cpu.h> |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 7 | #include <bootstate.h> |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 8 | #include <cbmem.h> |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 9 | #include <console/console.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 10 | #include <device/pnp.h> |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 11 | #include <ec/acpi/ec.h> |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 12 | #include <intelblocks/cpulib.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 13 | #include <pc80/keyboard.h> |
| 14 | #include <stdint.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 15 | |
| 16 | #include "commands.h" |
| 17 | #include "ec.h" |
| 18 | #include "chip.h" |
| 19 | |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 20 | /* |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 21 | * 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 Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 26 | * 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 | |
| 31 | static 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 | }; |
| 81 | static const size_t ucsi_region_len = ARRAY_SIZE(ucsi_region_fields); |
| 82 | |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 83 | static void wilco_ec_post_complete(void *unused) |
| 84 | { |
| 85 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE); |
| 86 | } |
| 87 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 88 | wilco_ec_post_complete, NULL); |
| 89 | |
| 90 | static void wilco_ec_post_memory_init(void *unused) |
| 91 | { |
| 92 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT); |
| 93 | } |
| 94 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, |
| 95 | wilco_ec_post_memory_init, NULL); |
| 96 | |
| 97 | static void wilco_ec_post_video_init(void *unused) |
| 98 | { |
| 99 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT); |
| 100 | } |
| 101 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, |
| 102 | wilco_ec_post_video_init, NULL); |
| 103 | |
Duncan Laurie | 1c968c1 | 2019-04-17 15:12:45 -0700 | [diff] [blame] | 104 | static void wilco_ec_post_logo_displayed(void *unused) |
| 105 | { |
| 106 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED); |
| 107 | } |
| 108 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, |
| 109 | wilco_ec_post_logo_displayed, NULL); |
| 110 | |
Duncan Laurie | 3fbe194 | 2018-10-15 13:39:35 -0700 | [diff] [blame] | 111 | static void wilco_ec_resume(void *unused) |
| 112 | { |
| 113 | wilco_ec_send_noargs(KB_RESTORE); |
| 114 | } |
| 115 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL); |
| 116 | |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 117 | static 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 Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 125 | static void wilco_ec_init(struct device *dev) |
| 126 | { |
| 127 | if (!dev->enabled) |
| 128 | return; |
| 129 | |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 130 | /* 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 Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 137 | /* 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 Laurie | 29f2b25 | 2018-10-19 17:01:31 -0700 | [diff] [blame] | 145 | |
| 146 | /* Unmute speakers */ |
| 147 | wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS); |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 148 | |
| 149 | /* Enable WiFi radio */ |
| 150 | wilco_ec_radio_control(RADIO_WIFI, 1); |
Duncan Laurie | 221ebdc | 2018-11-29 17:59:04 -0800 | [diff] [blame] | 151 | |
| 152 | /* Turn on camera power */ |
| 153 | wilco_ec_send(KB_CAMERA, CAMERA_ON); |
Eric Lai | 123b191 | 2020-01-25 22:14:04 +0800 | [diff] [blame] | 154 | |
| 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 Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static 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); |
| 164 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 165 | res->base = base; |
| 166 | res->size = size; |
| 167 | } |
| 168 | |
| 169 | static 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 Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 181 | static void wilco_ec_fill_ssdt_generator(const struct device *dev) |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 182 | { |
| 183 | struct opregion opreg; |
| 184 | void *region_ptr; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 185 | size_t ucsi_alloc_region_len; |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 186 | |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 187 | 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 Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 190 | if (!region_ptr) |
| 191 | return; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 192 | memset(region_ptr, 0, ucsi_alloc_region_len); |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 193 | |
| 194 | opreg.name = "UCSM"; |
| 195 | opreg.regionspace = SYSTEMMEMORY; |
| 196 | opreg.regionoffset = (uintptr_t)region_ptr; |
Bernardo Perez Priego | 1d8568c | 2020-01-14 15:59:19 -0800 | [diff] [blame] | 197 | opreg.regionlen = ucsi_alloc_region_len; |
Duncan Laurie | c145e54 | 2019-04-18 16:37:50 -0700 | [diff] [blame] | 198 | |
| 199 | acpigen_write_scope(acpi_device_path_join(dev, "UCSI")); |
| 200 | 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 | |
| 210 | static const char *wilco_ec_acpi_name(const struct device *dev) |
| 211 | { |
| 212 | return "EC0"; |
| 213 | } |
| 214 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 215 | static struct device_operations ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 216 | .init = wilco_ec_init, |
| 217 | .read_resources = wilco_ec_read_resources, |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 218 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 219 | .acpi_fill_ssdt = wilco_ec_fill_ssdt_generator, |
| 220 | .acpi_name = wilco_ec_acpi_name, |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | static struct pnp_info info[] = { |
| 224 | { NULL, 0, 0, 0, } |
| 225 | }; |
| 226 | |
| 227 | static void wilco_ec_enable_dev(struct device *dev) |
| 228 | { |
| 229 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info); |
| 230 | } |
| 231 | |
| 232 | struct chip_operations ec_google_wilco_ops = { |
| 233 | CHIP_NAME("Google Wilco EC") |
| 234 | .enable_dev = wilco_ec_enable_dev, |
| 235 | }; |