blob: 0858e1c3bfd9e9ec8125a42c206ae2a6fcbe11d1 [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 Laurie421a9622018-10-15 02:46:45 +000017#include <bootstate.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000018#include <device/pnp.h>
Duncan Laurie90a96c72019-03-13 17:35:22 -070019#include <ec/acpi/ec.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000020#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 Laurie421a9622018-10-15 02:46:45 +000028static void wilco_ec_post_complete(void *unused)
29{
30 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
31}
32BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
33 wilco_ec_post_complete, NULL);
34
35static void wilco_ec_post_memory_init(void *unused)
36{
37 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
38}
39BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
40 wilco_ec_post_memory_init, NULL);
41
42static void wilco_ec_post_video_init(void *unused)
43{
44 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
45}
46BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
47 wilco_ec_post_video_init, NULL);
48
Duncan Laurie3fbe1942018-10-15 13:39:35 -070049static void wilco_ec_resume(void *unused)
50{
51 wilco_ec_send_noargs(KB_RESTORE);
52}
53BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
54
Duncan Laurieb29e2d52018-10-15 02:40:21 +000055static void wilco_ec_init(struct device *dev)
56{
57 if (!dev->enabled)
58 return;
59
Duncan Laurie90a96c72019-03-13 17:35:22 -070060 /* Disable S0ix support in EC RAM with ACPI EC interface */
61 if (!acpi_is_wakeup_s3()) {
62 ec_set_ports(CONFIG_EC_BASE_ACPI_COMMAND,
63 CONFIG_EC_BASE_ACPI_DATA);
64 ec_write(EC_RAM_S0IX_SUPPORT, 0);
65 }
66
Duncan Laurieb29e2d52018-10-15 02:40:21 +000067 /* Print EC firmware information */
68 wilco_ec_print_all_info();
69
70 /* Initialize keyboard, ignore emulated PS/2 mouse */
71 pc_keyboard_init(NO_AUX_DEVICE);
72
73 /* Direct power button to the host for processing */
74 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -070075
76 /* Unmute speakers */
77 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -070078
79 /* Enable WiFi radio */
80 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -080081
82 /* Turn on camera power */
83 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Duncan Laurieb29e2d52018-10-15 02:40:21 +000084}
85
86static void wilco_ec_resource(struct device *dev, int index,
87 size_t base, size_t size)
88{
89 struct resource *res = new_resource(dev, index);
90 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
91 res->base = base;
92 res->size = size;
93}
94
95static void wilco_ec_read_resources(struct device *dev)
96{
97 /* ACPI command and data regions */
98 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
99
100 /* Host command and data regions */
101 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
102
103 /* Packet region */
104 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
105}
106
107static struct device_operations ops = {
108 .init = wilco_ec_init,
109 .read_resources = wilco_ec_read_resources,
110 .enable_resources = DEVICE_NOOP,
111 .set_resources = DEVICE_NOOP,
112};
113
114static struct pnp_info info[] = {
115 { NULL, 0, 0, 0, }
116};
117
118static void wilco_ec_enable_dev(struct device *dev)
119{
120 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
121}
122
123struct chip_operations ec_google_wilco_ops = {
124 CHIP_NAME("Google Wilco EC")
125 .enable_dev = wilco_ec_enable_dev,
126};