drivers/input/keyboard/cros_ec_keyb.c

Source file repositories/reference/linux-study-clean/drivers/input/keyboard/cros_ec_keyb.c

File Facts

System
Linux kernel
Corpus path
drivers/input/keyboard/cros_ec_keyb.c
Extension
.c
Size
25188 bytes
Lines
948
Domain
Driver Families
Bucket
drivers/input
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct cros_ec_keyb {
	unsigned int rows;
	unsigned int cols;
	int row_shift;
	bool ghost_filter;
	u8 valid_keys[CROS_EC_KEYBOARD_COLS_MAX];
	u8 old_kb_state[CROS_EC_KEYBOARD_COLS_MAX];

	struct device *dev;
	struct cros_ec_device *ec;

	struct input_dev *idev;
	struct input_dev *bs_idev;
	struct notifier_block notifier;

	struct vivaldi_data vdata;

	bool has_fn_map;
	bool fn_active;
	bool fn_combo_active;
};

/**
 * struct cros_ec_bs_map - Mapping between Linux keycodes and EC button/switch
 *	bitmap #defines
 *
 * @ev_type: The type of the input event to generate (e.g., EV_KEY).
 * @code: A linux keycode
 * @bit: A #define like EC_MKBP_POWER_BUTTON or EC_MKBP_LID_OPEN
 * @inverted: If the #define and EV_SW have opposite meanings, this is true.
 *            Only applicable to switches.
 */
struct cros_ec_bs_map {
	unsigned int ev_type;
	unsigned int code;
	u8 bit;
	bool inverted;
};

/* cros_ec_keyb_bs - Map EC button/switch #defines into kernel ones */
static const struct cros_ec_bs_map cros_ec_keyb_bs[] = {
	/* Buttons */
	{
		.ev_type	= EV_KEY,
		.code		= KEY_POWER,
		.bit		= EC_MKBP_POWER_BUTTON,
	},
	{
		.ev_type	= EV_KEY,
		.code		= KEY_VOLUMEUP,
		.bit		= EC_MKBP_VOL_UP,
	},
	{
		.ev_type	= EV_KEY,
		.code		= KEY_VOLUMEDOWN,
		.bit		= EC_MKBP_VOL_DOWN,
	},
	{
		.ev_type        = EV_KEY,
		.code           = KEY_BRIGHTNESSUP,
		.bit            = EC_MKBP_BRI_UP,
	},
	{
		.ev_type        = EV_KEY,
		.code           = KEY_BRIGHTNESSDOWN,
		.bit            = EC_MKBP_BRI_DOWN,
	},
	{
		.ev_type        = EV_KEY,
		.code           = KEY_SCREENLOCK,
		.bit            = EC_MKBP_SCREEN_LOCK,
	},

	/* Switches */
	{
		.ev_type	= EV_SW,
		.code		= SW_LID,
		.bit		= EC_MKBP_LID_OPEN,
		.inverted	= true,
	},
	{
		.ev_type	= EV_SW,
		.code		= SW_TABLET_MODE,
		.bit		= EC_MKBP_TABLET_MODE,
	},
};

/*
 * Returns true when there is at least one combination of pressed keys that
 * results in ghosting.

Annotation

Implementation Notes