drivers/platform/arm64/lenovo-thinkpad-t14s.c

Source file repositories/reference/linux-study-clean/drivers/platform/arm64/lenovo-thinkpad-t14s.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/arm64/lenovo-thinkpad-t14s.c
Extension
.c
Size
17359 bytes
Lines
663
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 t14s_ec_led_classdev {
	struct led_classdev led_classdev;
	int led;
	enum t14s_ec_led_status_t cache;
	struct t14s_ec *ec;
};

struct t14s_ec {
	struct regmap *regmap;
	struct device *dev;
	struct t14s_ec_led_classdev led_pwr_btn;
	struct t14s_ec_led_classdev led_chrg_orange;
	struct t14s_ec_led_classdev led_chrg_white;
	struct t14s_ec_led_classdev led_lid_logo_dot;
	struct led_classdev kbd_backlight;
	struct led_classdev led_mic_mute;
	struct led_classdev led_spk_mute;
	struct input_dev *inputdev;
};

static const struct regmap_config t14s_ec_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = 0xff,
};

static int t14s_ec_write(void *context, unsigned int reg,
				  unsigned int val)
{
	struct t14s_ec *ec = context;
	struct i2c_client *client = to_i2c_client(ec->dev);
	u8 buf[5] = {T14S_EC_CMD_ECWR, reg, 0x00, 0x01, val};
	int ret;

	ret = i2c_master_send(client, buf, sizeof(buf));
	if (ret < 0)
		return ret;

	fsleep(10000);
	return 0;
}

static int t14s_ec_read(void *context, unsigned int reg,
				 unsigned int *val)
{
	struct t14s_ec *ec = context;
	struct i2c_client *client = to_i2c_client(ec->dev);
	u8 buf[4] = {T14S_EC_CMD_ECRD, reg, 0x00, 0x01};
	struct i2c_msg request, response;
	u8 result;
	int ret;

	request.addr = client->addr;
	request.flags = I2C_M_STOP;
	request.len = sizeof(buf);
	request.buf = buf;
	response.addr = client->addr;
	response.flags = I2C_M_RD;
	response.len = 1;
	response.buf = &result;

	i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT);

	ret = __i2c_transfer(client->adapter, &request, 1);
	if (ret < 0)
		goto out;

	ret = __i2c_transfer(client->adapter, &response, 1);
	if (ret < 0)
		goto out;

	*val = result;
	ret = 0;

out:
	i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT);
	fsleep(10000);
	return ret;
}

static const struct regmap_bus t14s_ec_regmap_bus = {
	.reg_write = t14s_ec_write,
	.reg_read = t14s_ec_read,
};

static int t14s_ec_read_evt(struct t14s_ec *ec, u8 *val)
{
	struct i2c_client *client = to_i2c_client(ec->dev);
	u8 buf[4] = {T14S_EC_CMD_EVT, 0x00, 0x00, 0x01};
	struct i2c_msg request, response;

Annotation

Implementation Notes