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 | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 16 | #include <bootstate.h> |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 17 | #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 Laurie | 421a962 | 2018-10-15 02:46:45 +0000 | [diff] [blame] | 26 | static void wilco_ec_post_complete(void *unused) |
| 27 | { |
| 28 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_POST_COMPLETE); |
| 29 | } |
| 30 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 31 | wilco_ec_post_complete, NULL); |
| 32 | |
| 33 | static void wilco_ec_post_memory_init(void *unused) |
| 34 | { |
| 35 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_MEMORY_INIT); |
| 36 | } |
| 37 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, |
| 38 | wilco_ec_post_memory_init, NULL); |
| 39 | |
| 40 | static void wilco_ec_post_video_init(void *unused) |
| 41 | { |
| 42 | wilco_ec_send(KB_BIOS_PROGRESS, BIOS_PROGRESS_VIDEO_INIT); |
| 43 | } |
| 44 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, |
| 45 | wilco_ec_post_video_init, NULL); |
| 46 | |
Duncan Laurie | 3fbe194 | 2018-10-15 13:39:35 -0700 | [diff] [blame] | 47 | static void wilco_ec_resume(void *unused) |
| 48 | { |
| 49 | wilco_ec_send_noargs(KB_RESTORE); |
| 50 | } |
| 51 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, wilco_ec_resume, NULL); |
| 52 | |
Duncan Laurie | b29e2d5 | 2018-10-15 02:40:21 +0000 | [diff] [blame] | 53 | static 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); |
| 66 | } |
| 67 | |
| 68 | static void wilco_ec_resource(struct device *dev, int index, |
| 69 | size_t base, size_t size) |
| 70 | { |
| 71 | struct resource *res = new_resource(dev, index); |
| 72 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 73 | res->base = base; |
| 74 | res->size = size; |
| 75 | } |
| 76 | |
| 77 | static void wilco_ec_read_resources(struct device *dev) |
| 78 | { |
| 79 | /* ACPI command and data regions */ |
| 80 | wilco_ec_resource(dev, 0, CONFIG_EC_BASE_ACPI_DATA, 8); |
| 81 | |
| 82 | /* Host command and data regions */ |
| 83 | wilco_ec_resource(dev, 1, CONFIG_EC_BASE_HOST_DATA, 8); |
| 84 | |
| 85 | /* Packet region */ |
| 86 | wilco_ec_resource(dev, 2, CONFIG_EC_BASE_PACKET, 16); |
| 87 | } |
| 88 | |
| 89 | static struct device_operations ops = { |
| 90 | .init = wilco_ec_init, |
| 91 | .read_resources = wilco_ec_read_resources, |
| 92 | .enable_resources = DEVICE_NOOP, |
| 93 | .set_resources = DEVICE_NOOP, |
| 94 | }; |
| 95 | |
| 96 | static struct pnp_info info[] = { |
| 97 | { NULL, 0, 0, 0, } |
| 98 | }; |
| 99 | |
| 100 | static void wilco_ec_enable_dev(struct device *dev) |
| 101 | { |
| 102 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(info), info); |
| 103 | } |
| 104 | |
| 105 | struct chip_operations ec_google_wilco_ops = { |
| 106 | CHIP_NAME("Google Wilco EC") |
| 107 | .enable_dev = wilco_ec_enable_dev, |
| 108 | }; |