drivers/platform/chrome/wilco_ec/keyboard_leds.c

Source file repositories/reference/linux-study-clean/drivers/platform/chrome/wilco_ec/keyboard_leds.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/chrome/wilco_ec/keyboard_leds.c
Extension
.c
Size
5202 bytes
Lines
204
Domain
Driver Families
Bucket
drivers/platform
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 wilco_keyboard_leds {
	struct wilco_ec_device *ec;
	struct led_classdev keyboard;
};

enum wilco_kbbl_subcommand {
	WILCO_KBBL_SUBCMD_GET_FEATURES = 0x00,
	WILCO_KBBL_SUBCMD_GET_STATE    = 0x01,
	WILCO_KBBL_SUBCMD_SET_STATE    = 0x02,
};

/**
 * struct wilco_keyboard_leds_msg - Message to/from EC for keyboard LED control.
 * @command: Always WILCO_EC_COMMAND_KBBL.
 * @status: Set by EC to 0 on success, 0xFF on failure.
 * @subcmd: One of enum wilco_kbbl_subcommand.
 * @reserved3: Should be 0.
 * @mode: Bit flags for used mode, we want to use WILCO_KBBL_MODE_FLAG_PWM.
 * @reserved5to8: Should be 0.
 * @percent: Brightness in 0-100. Only meaningful in PWM mode.
 * @reserved10to15: Should be 0.
 */
struct wilco_keyboard_leds_msg {
	u8 command;
	u8 status;
	u8 subcmd;
	u8 reserved3;
	u8 mode;
	u8 reserved5to8[4];
	u8 percent;
	u8 reserved10to15[6];
} __packed;

/* Send a request, get a response, and check that the response is good. */
static int send_kbbl_msg(struct wilco_ec_device *ec,
			 struct wilco_keyboard_leds_msg *request,
			 struct wilco_keyboard_leds_msg *response)
{
	struct wilco_ec_message msg;
	int ret;

	memset(&msg, 0, sizeof(msg));
	msg.type = WILCO_EC_MSG_LEGACY;
	msg.request_data = request;
	msg.request_size = sizeof(*request);
	msg.response_data = response;
	msg.response_size = sizeof(*response);

	ret = wilco_ec_mailbox(ec, &msg);
	if (ret < 0) {
		dev_err(ec->dev,
			"Failed sending keyboard LEDs command: %d\n", ret);
		return ret;
	}

	return 0;
}

static int set_kbbl(struct wilco_ec_device *ec, enum led_brightness brightness)
{
	struct wilco_keyboard_leds_msg request;
	struct wilco_keyboard_leds_msg response;
	int ret;

	memset(&request, 0, sizeof(request));
	request.command = WILCO_EC_COMMAND_KBBL;
	request.subcmd  = WILCO_KBBL_SUBCMD_SET_STATE;
	request.mode    = WILCO_KBBL_MODE_FLAG_PWM;
	request.percent = brightness;

	ret = send_kbbl_msg(ec, &request, &response);
	if (ret < 0)
		return ret;

	if (response.status) {
		dev_err(ec->dev,
			"EC reported failure sending keyboard LEDs command: %d\n",
			response.status);
		return -EIO;
	}

	return 0;
}

static int kbbl_exist(struct wilco_ec_device *ec, bool *exists)
{
	struct wilco_keyboard_leds_msg request;
	struct wilco_keyboard_leds_msg response;
	int ret;

Annotation

Implementation Notes