blob: a9caaeca230a84110dede7a91011169e25cd2959 [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 Laurie421a9622018-10-15 02:46:45 +000016#include <bootstate.h>
Duncan Laurieb29e2d52018-10-15 02:40:21 +000017#include <device/pnp.h>
18#include <pc80/keyboard.h>
19#include <stdint.h>
20#include <stdlib.h>
21
22#include "commands.h"
23#include "ec.h"
24#include "chip.h"
25
Duncan Laurie421a9622018-10-15 02:46:45 +000026static void wilco_ec_post_complete(void *unused)
27{
28 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE);
29}
30BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
31 wilco_ec_post_complete, NULL);
32
33static void wilco_ec_post_memory_init(void *unused)
34{
35 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT);
36}
37BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT,
38 wilco_ec_post_memory_init, NULL);
39
40static void wilco_ec_post_video_init(void *unused)
41{
42 wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT);
43}
44BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT,
45 wilco_ec_post_video_init, NULL);
46
Duncan Laurie3fbe1942018-10-15 13:39:35 -070047static void wilco_ec_resume(void *unused)
48{
49 wilco_ec_send_noargs(KB_RESTORE);
50}
51BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL);
52
Duncan Laurieb29e2d52018-10-15 02:40:21 +000053static void wilco_ec_init(struct device *dev)
54{
55 if (!dev->enabled)
56 return;
57
58 /* Print EC firmware information */
59 wilco_ec_print_all_info();
60
61 /* Initialize keyboard, ignore emulated PS/2 mouse */
62 pc_keyboard_init(NO_AUX_DEVICE);
63
64 /* Direct power button to the host for processing */
65 wilco_ec_send(KB_POWER_BUTTON_TO_HOST, 1);
Duncan Laurie29f2b252018-10-19 17:01:31 -070066
67 /* Unmute speakers */
68 wilco_ec_send(KB_HW_MUTE_CONTROL, AUDIO_UNMUTE_125MS);
Duncan Laurie57f22f62018-11-17 12:17:04 -070069
70 /* Enable WiFi radio */
71 wilco_ec_radio_control(RADIO_WIFI, 1);
Duncan Laurie221ebdc2018-11-29 17:59:04 -080072
73 /* Turn on camera power */
74 wilco_ec_send(KB_CAMERA, CAMERA_ON);
Duncan Laurieb29e2d52018-10-15 02:40:21 +000075}
76
77static void wilco_ec_resource(struct device *dev, int index,
78 size_t base, size_t size)
79{
80 struct resource *res = new_resource(dev, index);
81 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
82 res->base = base;
83 res->size = size;
84}
85
86static void wilco_ec_read_resources(struct device *dev)
87{
88 /* ACPI command and data regions */
89 wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8);
90
91 /* Host command and data regions */
92 wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8);
93
94 /* Packet region */
95 wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16);
96}
97
98static struct device_operations ops = {
99 .init = wilco_ec_init,
100 .read_resources = wilco_ec_read_resources,
101 .enable_resources = DEVICE_NOOP,
102 .set_resources = DEVICE_NOOP,
103};
104
105static struct pnp_info info[] = {
106 { NULL, 0, 0, 0, }
107};
108
109static void wilco_ec_enable_dev(struct device *dev)
110{
111 pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info);
112}
113
114struct chip_operations ec_google_wilco_ops = {
115 CHIP_NAME("Google Wilco EC")
116 .enable_dev = wilco_ec_enable_dev,
117};