mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-04 22:11:41 +00:00
Our code base contains a lot of debug messages in this pattern:
CPRINTF("[%T xxx]\n") or ccprintf("[%T xxx]\n")
The strings are taking up spaces in the EC binaries, so let's refactor
this by adding cprints() and ccprints().
cprints() is just like cprintf(), except that it adds the brackets
and the timestamp. ccprints() is equivalent to cprints(CC_CONSOLE, ...)
This saves us hundreds of bytes in EC binaries.
BUG=chromium:374575
TEST=Build and check flash size
BRANCH=None
Change-Id: Ifafe8dc1b80e698b28ed42b70518c7917b49ee51
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/200490
Reviewed-by: Randall Spangler <rspangler@chromium.org>
142 lines
3.5 KiB
C
142 lines
3.5 KiB
C
/* 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.
|
|
*/
|
|
|
|
/* Power button module for Chrome EC */
|
|
|
|
#include "common.h"
|
|
#include "console.h"
|
|
#include "gpio.h"
|
|
#include "hooks.h"
|
|
#include "host_command.h"
|
|
#include "keyboard_scan.h"
|
|
#include "lid_switch.h"
|
|
#include "power_button.h"
|
|
#include "timer.h"
|
|
#include "util.h"
|
|
|
|
/* Console output macros */
|
|
#define CPUTS(outstr) cputs(CC_SWITCH, outstr)
|
|
#define CPRINTS(format, args...) cprints(CC_SWITCH, format, ## args)
|
|
|
|
#define PWRBTN_DEBOUNCE_US (30 * MSEC) /* Debounce time for power button */
|
|
|
|
static int debounced_power_pressed; /* Debounced power button state */
|
|
static int simulate_power_pressed;
|
|
|
|
/**
|
|
* Get raw power button signal state.
|
|
*
|
|
* @return 1 if power button is pressed, 0 if not pressed.
|
|
*/
|
|
static int raw_power_button_pressed(void)
|
|
{
|
|
if (simulate_power_pressed)
|
|
return 1;
|
|
|
|
#ifndef CONFIG_POWER_BUTTON_IGNORE_LID
|
|
/*
|
|
* Always indicate power button released if the lid is closed.
|
|
* This prevents waking the system if the device is squashed enough to
|
|
* press the power button through the closed lid.
|
|
*/
|
|
if (!lid_is_open())
|
|
return 0;
|
|
#endif
|
|
|
|
return gpio_get_level(GPIO_POWER_BUTTON_L) ? 0 : 1;
|
|
}
|
|
|
|
int power_button_is_pressed(void)
|
|
{
|
|
return debounced_power_pressed;
|
|
}
|
|
|
|
/**
|
|
* Handle power button initialization.
|
|
*/
|
|
static void power_button_init(void)
|
|
{
|
|
if (raw_power_button_pressed())
|
|
debounced_power_pressed = 1;
|
|
|
|
/* Enable interrupts, now that we've initialized */
|
|
gpio_enable_interrupt(GPIO_POWER_BUTTON_L);
|
|
}
|
|
DECLARE_HOOK(HOOK_INIT, power_button_init, HOOK_PRIO_INIT_POWER_BUTTON);
|
|
|
|
/**
|
|
* Handle debounced power button changing state.
|
|
*/
|
|
static void power_button_change_deferred(void)
|
|
{
|
|
const int new_pressed = raw_power_button_pressed();
|
|
|
|
/* Re-enable keyboard scanning if power button is no longer pressed */
|
|
if (!new_pressed)
|
|
keyboard_scan_enable(1, KB_SCAN_DISABLE_POWER_BUTTON);
|
|
|
|
/* If power button hasn't changed state, nothing to do */
|
|
if (new_pressed == debounced_power_pressed)
|
|
return;
|
|
|
|
debounced_power_pressed = new_pressed;
|
|
|
|
CPRINTS("power button %s", new_pressed ? "pressed" : "released");
|
|
|
|
/* Call hooks */
|
|
hook_notify(HOOK_POWER_BUTTON_CHANGE);
|
|
|
|
/* Notify host if power button has been pressed */
|
|
if (new_pressed)
|
|
host_set_single_event(EC_HOST_EVENT_POWER_BUTTON);
|
|
}
|
|
DECLARE_DEFERRED(power_button_change_deferred);
|
|
|
|
void power_button_interrupt(enum gpio_signal signal)
|
|
{
|
|
/*
|
|
* If power button is pressed, disable the matrix scan as soon as
|
|
* possible to reduce the risk of false-reboot triggered by those keys
|
|
* on the same column with refresh key.
|
|
*/
|
|
if (raw_power_button_pressed())
|
|
keyboard_scan_enable(0, KB_SCAN_DISABLE_POWER_BUTTON);
|
|
|
|
/* Reset power button debounce time */
|
|
hook_call_deferred(power_button_change_deferred, PWRBTN_DEBOUNCE_US);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/* Console commands */
|
|
|
|
static int command_powerbtn(int argc, char **argv)
|
|
{
|
|
int ms = 200; /* Press duration in ms */
|
|
char *e;
|
|
|
|
if (argc > 1) {
|
|
ms = strtoi(argv[1], &e, 0);
|
|
if (*e)
|
|
return EC_ERROR_PARAM1;
|
|
}
|
|
|
|
ccprintf("Simulating %d ms power button press.\n", ms);
|
|
simulate_power_pressed = 1;
|
|
hook_call_deferred(power_button_change_deferred, 0);
|
|
|
|
msleep(ms);
|
|
|
|
ccprintf("Simulating power button release.\n");
|
|
simulate_power_pressed = 0;
|
|
hook_call_deferred(power_button_change_deferred, 0);
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
DECLARE_CONSOLE_COMMAND(powerbtn, command_powerbtn,
|
|
"[msec]",
|
|
"Simulate power button press",
|
|
NULL);
|
|
|