drivers/input/keyboard/lkkbd.c

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

File Facts

System
Linux kernel
Corpus path
drivers/input/keyboard/lkkbd.c
Extension
.c
Size
17628 bytes
Lines
722
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 lkkbd {
	unsigned short keycode[LK_NUM_KEYCODES];
	int ignore_bytes;
	unsigned char id[LK_NUM_IGNORE_BYTES];
	struct input_dev *dev;
	struct serio *serio;
	struct work_struct tq;
	char name[64];
	char phys[32];
	char type;
	int bell_volume;
	int keyclick_volume;
	int ctrlclick_volume;
};

#ifdef LKKBD_DEBUG
/*
 * Responses from the keyboard and mapping back to their names.
 */
static struct {
	unsigned char value;
	unsigned char *name;
} lk_response[] = {
#define RESPONSE(x) { .value = (x), .name = #x, }
	RESPONSE(LK_STUCK_KEY),
	RESPONSE(LK_SELFTEST_FAILED),
	RESPONSE(LK_ALL_KEYS_UP),
	RESPONSE(LK_METRONOME),
	RESPONSE(LK_OUTPUT_ERROR),
	RESPONSE(LK_INPUT_ERROR),
	RESPONSE(LK_KBD_LOCKED),
	RESPONSE(LK_KBD_TEST_MODE_ACK),
	RESPONSE(LK_PREFIX_KEY_DOWN),
	RESPONSE(LK_MODE_CHANGE_ACK),
	RESPONSE(LK_RESPONSE_RESERVED),
#undef RESPONSE
};

static unsigned char *response_name(unsigned char value)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(lk_response); i++)
		if (lk_response[i].value == value)
			return lk_response[i].name;

	return "<unknown>";
}
#endif /* LKKBD_DEBUG */

/*
 * Calculate volume parameter byte for a given volume.
 */
static unsigned char volume_to_hw(int volume_percent)
{
	unsigned char ret = 0;

	if (volume_percent < 0)
		volume_percent = 0;
	if (volume_percent > 100)
		volume_percent = 100;

	if (volume_percent >= 0)
		ret = 7;
	if (volume_percent >= 13)	/* 12.5 */
		ret = 6;
	if (volume_percent >= 25)
		ret = 5;
	if (volume_percent >= 38)	/* 37.5 */
		ret = 4;
	if (volume_percent >= 50)
		ret = 3;
	if (volume_percent >= 63)	/* 62.5 */
		ret = 2;		/* This is the default volume */
	if (volume_percent >= 75)
		ret = 1;
	if (volume_percent >= 88)	/* 87.5 */
		ret = 0;

	ret |= 0x80;

	return ret;
}

static void lkkbd_detection_done(struct lkkbd *lk)
{
	int i;

	/*
	 * Reset setting for Compose key. Let Compose be KEY_COMPOSE.

Annotation

Implementation Notes