Source
// SPDX-License-Identifier: GPL-2.0+
/*
* HID driver for Google Hammer device.
*
* Copyright (c) 2017 Google Inc.
* Author: Wei-Ning Huang <wnhuang@google.com>
*/
/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*/
/*
* C(hrome)B(ase)A(ttached)S(witch) - switch exported by Chrome EC and reporting
* state of the "Whiskers" base - attached or detached. Whiskers USB device also
* reports position of the keyboard - folded or not. Combining base state and
* position allows us to generate proper "Tablet mode" events.
*/
struct cbas_ec {
struct device *dev; /* The platform device (EC) */
struct input_dev *input;
bool base_present;
struct notifier_block notifier;
};
static struct cbas_ec cbas_ec;
static DEFINE_SPINLOCK(cbas_ec_lock);
static DEFINE_MUTEX(cbas_ec_reglock);
static bool cbas_parse_base_state(const void *data)
{
u32 switches = get_unaligned_le32(data);
return !!(switches & BIT(EC_MKBP_BASE_ATTACHED));
}
static int cbas_ec_query_base(struct cros_ec_device *ec_dev, bool get_state,
bool *state)
{
struct ec_params_mkbp_info *params;
struct cros_ec_command *msg;
int ret;
msg = kzalloc(sizeof(*msg) + max(sizeof(u32), sizeof(*params)),
GFP_KERNEL);
if (!msg)
return -ENOMEM;