Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 5 | * Copyright 2014 Google Inc. |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
| 18 | #include <console/console.h> |
| 19 | #include <cpu/x86/smm.h> |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 20 | #include <soc/pm.h> |
| 21 | #include <soc/smm.h> |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 22 | #include <elog.h> |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 23 | #include <ec/google/chromeec/ec.h> |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 24 | #include <soc/gpio.h> |
| 25 | #include <soc/iomap.h> |
| 26 | #include <soc/nvs.h> |
| 27 | #include <soc/pm.h> |
| 28 | #include <soc/smm.h> |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 29 | #include "ec.h" |
| 30 | |
| 31 | /* Codec enable: GPIO45 */ |
| 32 | #define GPIO_PP3300_CODEC_EN 45 |
| 33 | /* WLAN / BT enable: GPIO46 */ |
| 34 | #define GPIO_WLAN_DISABLE_L 46 |
| 35 | |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 36 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 37 | static u8 mainboard_smi_ec(void) |
| 38 | { |
| 39 | u8 cmd = google_chromeec_get_event(); |
| 40 | u32 pm1_cnt; |
| 41 | |
| 42 | #if CONFIG_ELOG_GSMI |
| 43 | /* Log this event */ |
| 44 | if (cmd) |
| 45 | elog_add_event_byte(ELOG_TYPE_EC_EVENT, cmd); |
| 46 | #endif |
| 47 | |
| 48 | switch (cmd) { |
| 49 | case EC_HOST_EVENT_LID_CLOSED: |
| 50 | printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n"); |
| 51 | |
| 52 | /* Go to S5 */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 53 | pm1_cnt = inl(ACPI_BASE_ADDRESS + PM1_CNT); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 54 | pm1_cnt |= (0xf << 10); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 55 | outl(pm1_cnt, ACPI_BASE_ADDRESS + PM1_CNT); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 56 | break; |
| 57 | } |
| 58 | |
| 59 | return cmd; |
| 60 | } |
| 61 | |
| 62 | /* gpi_sts is GPIO 47:32 */ |
| 63 | void mainboard_smi_gpi(u32 gpi_sts) |
| 64 | { |
| 65 | if (gpi_sts & (1 << (EC_SMI_GPI - 32))) { |
| 66 | /* Process all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 67 | while (mainboard_smi_ec() != 0) |
| 68 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | void mainboard_smi_sleep(u8 slp_typ) |
| 73 | { |
| 74 | /* Disable USB charging if required */ |
| 75 | switch (slp_typ) { |
| 76 | case 3: |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 77 | if (smm_get_gnvs()->s3u0 == 0) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 78 | google_chromeec_set_usb_charge_mode( |
| 79 | 0, USB_CHARGE_MODE_DISABLED); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 80 | google_chromeec_set_usb_charge_mode( |
| 81 | 1, USB_CHARGE_MODE_DISABLED); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 82 | } |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 83 | |
| 84 | set_gpio(GPIO_PP3300_CODEC_EN, 0); |
| 85 | set_gpio(GPIO_WLAN_DISABLE_L, 0); |
| 86 | |
| 87 | /* Enable wake events */ |
| 88 | google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS); |
| 89 | break; |
| 90 | case 5: |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 91 | if (smm_get_gnvs()->s5u0 == 0) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 92 | google_chromeec_set_usb_charge_mode( |
| 93 | 0, USB_CHARGE_MODE_DISABLED); |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 94 | google_chromeec_set_usb_charge_mode( |
| 95 | 1, USB_CHARGE_MODE_DISABLED); |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 96 | } |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 97 | |
| 98 | set_gpio(GPIO_PP3300_CODEC_EN, 0); |
| 99 | set_gpio(GPIO_WLAN_DISABLE_L, 0); |
| 100 | |
| 101 | /* Enable wake events */ |
| 102 | google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS); |
| 103 | break; |
| 104 | } |
| 105 | |
| 106 | /* Disable SCI and SMI events */ |
| 107 | google_chromeec_set_smi_mask(0); |
| 108 | google_chromeec_set_sci_mask(0); |
| 109 | |
| 110 | /* Clear pending events that may trigger immediate wake */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 111 | while (google_chromeec_get_event() != 0) |
| 112 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 113 | } |
| 114 | |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 115 | int mainboard_smi_apmc(u8 apmc) |
| 116 | { |
| 117 | switch (apmc) { |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 118 | case APM_CNT_ACPI_ENABLE: |
| 119 | google_chromeec_set_smi_mask(0); |
| 120 | /* Clear all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 121 | while (google_chromeec_get_event() != 0) |
| 122 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 123 | google_chromeec_set_sci_mask(MAINBOARD_EC_SCI_EVENTS); |
| 124 | break; |
| 125 | case APM_CNT_ACPI_DISABLE: |
| 126 | google_chromeec_set_sci_mask(0); |
| 127 | /* Clear all pending events */ |
Marc Jones | d862121 | 2015-06-09 21:18:38 -0600 | [diff] [blame] | 128 | while (google_chromeec_get_event() != 0) |
| 129 | ; |
Marc Jones | 07cf24c | 2015-06-09 14:42:55 -0600 | [diff] [blame] | 130 | google_chromeec_set_smi_mask(MAINBOARD_EC_SMI_EVENTS); |
| 131 | break; |
| 132 | } |
| 133 | return 0; |
| 134 | } |