1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
* Pure GPIO-based external power detection, buffered to PCH.
* Drive high in S5-S0 when AC_PRESENT is high, otherwise drive low.
*/
#include "chipset.h"
#include "common.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
int extpower_is_present(void)
{
return gpio_get_level(GPIO_AC_PRESENT);
}
/**
* Deferred function to handle external power change
*/
static void extpower_deferred(void)
{
hook_notify(HOOK_AC_CHANGE);
/* Forward notification to host */
if (extpower_is_present())
host_set_single_event(EC_HOST_EVENT_AC_CONNECTED);
else
host_set_single_event(EC_HOST_EVENT_AC_DISCONNECTED);
}
DECLARE_DEFERRED(extpower_deferred);
static void extpower_buffer_to_pch(void)
{
if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) {
/* Drive low in G3 state */
gpio_set_level(GPIO_PCH_ACOK, 0);
} else {
/* Buffer from extpower in S5+ (where 3.3DSW enabled) */
gpio_set_level(GPIO_PCH_ACOK, extpower_is_present());
}
}
DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, extpower_buffer_to_pch, HOOK_PRIO_DEFAULT);
static void extpower_shutdown(void)
{
/* Drive ACOK buffer to PCH low when shutting down */
gpio_set_level(GPIO_PCH_ACOK, 0);
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, extpower_shutdown, HOOK_PRIO_DEFAULT);
void extpower_interrupt(enum gpio_signal signal)
{
extpower_buffer_to_pch();
/* Trigger deferred notification of external power change */
hook_call_deferred(extpower_deferred, 0);
}
static void extpower_init(void)
{
extpower_buffer_to_pch();
/* Enable interrupts, now that we've initialized */
gpio_enable_interrupt(GPIO_AC_PRESENT);
}
DECLARE_HOOK(HOOK_INIT, extpower_init, HOOK_PRIO_DEFAULT);
|