mkbp: Extend EC_CMD_MKBP_GET_INFO.

- Added ability to query the buttons and switches.
- Added ability to report the available buttons or switches.

BUG=chromium:626863
BRANCH=None
TEST=make -j buildall

CQ-DEPEND=CL:358633
CQ-DEPEND=CL:358634
CQ-DEPEND=CL:358989

Change-Id: Ie821491269e8d09578eba92127895c0b6b8e91a9
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/358926
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Aseda Aboagye
2016-07-08 09:24:20 -07:00
committed by chrome-bot
parent 0325284e17
commit 824f9fadc2
2 changed files with 152 additions and 12 deletions

View File

@@ -326,21 +326,110 @@ void keyboard_send_battery_key(void)
/*****************************************************************************/
/* Host commands */
static int keyboard_get_info(struct host_cmd_handler_args *args)
static uint32_t get_supported_buttons(void)
{
struct ec_response_mkbp_info *r = args->response;
uint32_t val = 0;
#ifdef CONFIG_BUTTON_COUNT
int i;
r->rows = KEYBOARD_ROWS;
r->cols = KEYBOARD_COLS;
r->switches = 0;
for (i = 0; i < CONFIG_BUTTON_COUNT; i++) {
if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_UP)
val |= (1 << EC_MKBP_VOL_UP);
if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_DOWN)
val |= (1 << EC_MKBP_VOL_DOWN);
}
#endif
#ifdef CONFIG_POWER_BUTTON
val |= (1 << EC_MKBP_POWER_BUTTON);
#endif
return val;
}
args->response_size = sizeof(*r);
static uint32_t get_supported_switches(void)
{
uint32_t val = 0;
#ifdef CONFIG_LID_SWITCH
val |= (1 << EC_MKBP_LID_OPEN);
#endif
return val;
}
static int mkbp_get_info(struct host_cmd_handler_args *args)
{
const struct ec_params_mkbp_info *p = args->params;
if (args->params_size == 0 || p->info_type == EC_MKBP_INFO_KBD) {
struct ec_response_mkbp_info *r = args->response;
/* Version 0 just returns info about the keyboard. */
r->rows = KEYBOARD_ROWS;
r->cols = KEYBOARD_COLS;
/* This used to be "switches" which was previously 0. */
r->reserved = 0;
args->response_size = sizeof(struct ec_response_mkbp_info);
} else {
union ec_response_get_next_data *r = args->response;
/* Version 1 (other than EC_MKBP_INFO_KBD) */
switch (p->info_type) {
case EC_MKBP_INFO_SUPPORTED:
switch (p->event_type) {
case EC_MKBP_EVENT_BUTTON:
r->buttons = get_supported_buttons();
args->response_size = sizeof(r->buttons);
break;
case EC_MKBP_EVENT_SWITCH:
r->switches = get_supported_switches();
args->response_size = sizeof(r->switches);
break;
default:
/* Don't care for now for other types. */
return EC_RES_INVALID_PARAM;
}
break;
case EC_MKBP_INFO_CURRENT:
switch (p->event_type) {
case EC_MKBP_EVENT_KEY_MATRIX:
memcpy(r->key_matrix, keyboard_scan_get_state(),
sizeof(r->key_matrix));
args->response_size = sizeof(r->key_matrix);
break;
case EC_MKBP_EVENT_HOST_EVENT:
r->host_event = host_get_events();
args->response_size = sizeof(r->host_event);
break;
case EC_MKBP_EVENT_BUTTON:
r->buttons = mkbp_button_state;
args->response_size = sizeof(r->buttons);
break;
case EC_MKBP_EVENT_SWITCH:
r->switches = mkbp_switch_state;
args->response_size = sizeof(r->switches);
break;
default:
/* Doesn't make sense for other event types. */
return EC_RES_INVALID_PARAM;
}
break;
default:
/* Unsupported query. */
return EC_RES_ERROR;
}
}
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_MKBP_INFO,
keyboard_get_info,
EC_VER_MASK(0));
DECLARE_HOST_COMMAND(EC_CMD_MKBP_INFO, mkbp_get_info,
EC_VER_MASK(0) | EC_VER_MASK(1));
static void set_keyscan_config(const struct ec_mkbp_config *src,
struct ec_mkbp_protocol_config *dst,

View File

@@ -2382,18 +2382,69 @@ struct ec_response_tmp006_get_raw {
*
* Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
* expected response size.
*
* NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
* to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
* EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
*/
#define EC_CMD_MKBP_STATE 0x60
/* Provide information about the matrix : number of rows and columns */
/*
* Provide information about various MKBP things. See enum ec_mkbp_info_type.
*/
#define EC_CMD_MKBP_INFO 0x61
struct ec_response_mkbp_info {
uint32_t rows;
uint32_t cols;
uint8_t switches;
/* Formerly "switches", which was 0. */
uint8_t reserved;
} __packed;
struct ec_params_mkbp_info {
uint8_t info_type;
uint8_t event_type;
} __packed;
enum ec_mkbp_info_type {
/*
* Info about the keyboard matrix: number of rows and columns.
*
* Returns struct ec_response_mkbp_info.
*/
EC_MKBP_INFO_KBD = 0,
/*
* For buttons and switches, info about which specifically are
* supported. event_type must be set to one of the values in enum
* ec_mkbp_event.
*
* For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
* bitmask indicating which buttons or switches are present. See the
* bit inidices below.
*/
EC_MKBP_INFO_SUPPORTED = 1,
/*
* Instantaneous state of buttons and switches.
*
* event_type must be set to one of the values in enum ec_mkbp_event.
*
* For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
* indicating the current state of the keyboard matrix.
*
* For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
* event state.
*
* For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
* state of supported buttons.
*
* For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
* state of supported switches.
*/
EC_MKBP_INFO_CURRENT = 2,
};
/* Simulate key press */
#define EC_CMD_MKBP_SIMULATE_KEY 0x62
@@ -2559,7 +2610,7 @@ struct ec_response_get_next_event {
union ec_response_get_next_data data;
} __packed;
/* Bit definitions for buttons and switches.*/
/* Bit indices for buttons and switches.*/
/* Buttons */
#define EC_MKBP_POWER_BUTTON 0
#define EC_MKBP_VOL_UP 1