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 | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 17 | #include <bootstate.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 18 | #include <device/pnp.h> |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 19 | #include <ec/acpi/ec.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 20 | #include <pc80/keyboard.h> |
| 21 | #include <stdint.h> |
| 22 | #include <stdlib.h> |
| 23 | |
| 24 | #include "commands.h" |
| 25 | #include "ec.h" |
| 26 | #include "chip.h" |
| 27 | |
Duncan Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 28 | static void wilco_ec_post_complete(void *unused) |
| 29 | { |
| 30 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE); |
| 31 | } |
| 32 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 33 | wilco_ec_post_complete, NULL); |
| 34 | |
| 35 | static void wilco_ec_post_memory_init(void *unused) |
| 36 | { |
| 37 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT); |
| 38 | } |
| 39 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, |
| 40 | wilco_ec_post_memory_init, NULL); |
| 41 | |
| 42 | static void wilco_ec_post_video_init(void *unused) |
| 43 | { |
| 44 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT); |
| 45 | } |
| 46 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, |
| 47 | wilco_ec_post_video_init, NULL); |
| 48 | |
Duncan Laurie | 1c968c1 | 2019-04-17 15:12:45 -0700 | [diff] [blame^] | 49 | static void wilco_ec_post_logo_displayed(void *unused) |
| 50 | { |
| 51 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_LOGO_DISPLAYED); |
| 52 | } |
| 53 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, |
| 54 | wilco_ec_post_logo_displayed, NULL); |
| 55 | |
Duncan Laurie | 3fbe194 | 2018-10-15 13:39:35 -0700 | [diff] [blame] | 56 | static void wilco_ec_resume(void *unused) |
| 57 | { |
| 58 | wilco_ec_send_noargs(KB_RESTORE); |
| 59 | } |
| 60 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL); |
| 61 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 62 | static void wilco_ec_init(struct device *dev) |
| 63 | { |
| 64 | if (!dev->enabled) |
| 65 | return; |
| 66 | |
Duncan Laurie | 90a96c7 | 2019-03-13 17:35:22 -0700 | [diff] [blame] | 67 | /* Disable S0ix support in EC RAM with ACPI EC interface */ |
| 68 | if (!acpi_is_wakeup_s3()) { |
| 69 | ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND, |
| 70 | CONFIG_EC_BASE_ACPI_DATA); |
| 71 | ec_write(EC_RAM_S0IX_SUPPORT, 0); |
| 72 | } |
| 73 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 74 | /* Print EC firmware information */ |
| 75 | wilco_ec_print_all_info(); |
| 76 | |
| 77 | /* Initialize keyboard, ignore emulated PS/2 mouse */ |
| 78 | pc_keyboard_init(NO_AUX_DEVICE); |
| 79 | |
| 80 | /* Direct power button to the host for processing */ |
| 81 | wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1); |
Duncan Laurie | 29f2b25 | 2018-10-19 17:01:31 -0700 | [diff] [blame] | 82 | |
| 83 | /* Unmute speakers */ |
| 84 | wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS); |
Duncan Laurie | 57f22f6 | 2018-11-17 12:17:04 -0700 | [diff] [blame] | 85 | |
| 86 | /* Enable WiFi radio */ |
| 87 | wilco_ec_radio_control(RADIO_WIFI, 1); |
Duncan Laurie | 221ebdc | 2018-11-29 17:59:04 -0800 | [diff] [blame] | 88 | |
| 89 | /* Turn on camera power */ |
| 90 | wilco_ec_send(KB_CAMERA, CAMERA_ON); |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static void wilco_ec_resource(struct device *dev, int index, |
| 94 | size_t base, size_t size) |
| 95 | { |
| 96 | struct resource *res = new_resource(dev, index); |
| 97 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 98 | res->base = base; |
| 99 | res->size = size; |
| 100 | } |
| 101 | |
| 102 | static void wilco_ec_read_resources(struct device *dev) |
| 103 | { |
| 104 | /* ACPI command and data regions */ |
| 105 | wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8); |
| 106 | |
| 107 | /* Host command and data regions */ |
| 108 | wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8); |
| 109 | |
| 110 | /* Packet region */ |
| 111 | wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16); |
| 112 | } |
| 113 | |
| 114 | static struct device_operations ops = { |
| 115 | .init = wilco_ec_init, |
| 116 | .read_resources = wilco_ec_read_resources, |
| 117 | .enable_resources = DEVICE_NOOP, |
| 118 | .set_resources = DEVICE_NOOP, |
| 119 | }; |
| 120 | |
| 121 | static struct pnp_info info[] = { |
| 122 | { NULL, 0, 0, 0, } |
| 123 | }; |
| 124 | |
| 125 | static void wilco_ec_enable_dev(struct device *dev) |
| 126 | { |
| 127 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info); |
| 128 | } |
| 129 | |
| 130 | struct chip_operations ec_google_wilco_ops = { |
| 131 | CHIP_NAME("Google Wilco EC") |
| 132 | .enable_dev = wilco_ec_enable_dev, |
| 133 | }; |