blob: c8319833c3e7f7e3ece4ba36726bb0f7bd47a042 [file] [log] [blame]
Patrick Georgi406313d2015-07-20 22:01:32 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2015 Google Inc.
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.
Patrick Georgi406313d2015-07-20 22:01:32 +020015 */
16
Aaron Durbin30b0c7a2016-07-13 13:01:13 -050017#include <arch/acpi.h>
Patrick Georgi406313d2015-07-20 22:01:32 +020018#include <arch/io.h>
19#include <console/console.h>
20#include <cpu/x86/smm.h>
21#include <elog.h>
Aaron Durbin3969df82016-07-14 01:09:34 -050022#include <ec/google/chromeec/smm.h>
Aaron Durbince6c3562015-11-11 16:46:27 -060023#include <gpio.h>
Patrick Georgi406313d2015-07-20 22:01:32 +020024#include <soc/iomap.h>
25#include <soc/nvs.h>
26#include <soc/pm.h>
27#include <soc/smm.h>
28#include "ec.h"
Duncan Laurie56260852015-08-17 09:53:22 -070029#include "gpio.h"
Patrick Georgi406313d2015-07-20 22:01:32 +020030
31int mainboard_io_trap_handler(int smif)
32{
33 switch (smif) {
34 case 0x99:
35 printk(BIOS_DEBUG, "Sample\n");
36 smm_get_gnvs()->smif = 0;
37 break;
38 default:
39 return 0;
40 }
41
42 /* On success, the IO Trap Handler returns 0
43 * On failure, the IO Trap Handler returns a value != 0
44 *
45 * For now, we force the return value to 0 and log all traps to
46 * see what's going on.
47 */
48 return 1;
49}
50
Aaron Durbin50ed38f2015-08-08 01:25:21 -050051void mainboard_smi_gpi_handler(const struct gpi_status *sts)
Patrick Georgi406313d2015-07-20 22:01:32 +020052{
Aaron Durbin3969df82016-07-14 01:09:34 -050053 if (gpi_status_get(sts, EC_SMI_GPI))
54 chromeec_smi_process_events();
Aaron Durbince6c3562015-11-11 16:46:27 -060055}
56
57static void mainboard_gpio_smi_sleep(u8 slp_typ)
58{
59 int i;
60
61 /* Power down the rails on any sleep type. */
62 gpio_t active_high_signals[] = {
63 EN_PP3300_KEPLER,
64 EN_PP3300_DX_TOUCH,
65 EN_PP3300_DX_EMMC,
66 EN_PP1800_DX_EMMC,
67 EN_PP3300_DX_CAM,
68 };
69
70 for (i = 0; i < ARRAY_SIZE(active_high_signals); i++)
71 gpio_set(active_high_signals[i], 0);
72}
73
74void mainboard_smi_sleep(u8 slp_typ)
75{
76 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC))
Aaron Durbin3969df82016-07-14 01:09:34 -050077 chromeec_smi_sleep(slp_typ, MAINBOARD_EC_S3_WAKE_EVENTS,
78 MAINBOARD_EC_S5_WAKE_EVENTS);
Aaron Durbince6c3562015-11-11 16:46:27 -060079
80 mainboard_gpio_smi_sleep(slp_typ);
Patrick Georgi406313d2015-07-20 22:01:32 +020081}
82
83int mainboard_smi_apmc(u8 apmc)
84{
Aaron Durbin3969df82016-07-14 01:09:34 -050085 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC))
86 chromeec_smi_apmc(apmc, MAINBOARD_EC_SCI_EVENTS,
87 MAINBOARD_EC_SMI_EVENTS);
Patrick Georgi406313d2015-07-20 22:01:32 +020088 return 0;
89}