drivers/platform/arm64/lenovo-yoga-c630.c

Source file repositories/reference/linux-study-clean/drivers/platform/arm64/lenovo-yoga-c630.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/arm64/lenovo-yoga-c630.c
Extension
.c
Size
6054 bytes
Lines
258
Domain
Driver Families
Bucket
drivers/platform
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 yoga_c630_ec {
	struct i2c_client *client;
	struct mutex lock;
	struct blocking_notifier_head notifier_list;
};

static int yoga_c630_ec_request(struct yoga_c630_ec *ec, u8 *req, size_t req_len,
				u8 *resp, size_t resp_len)
{
	int ret;

	lockdep_assert_held(&ec->lock);

	ret = i2c_smbus_write_i2c_block_data(ec->client, LENOVO_EC_REQUEST_REG,
					     req_len, req);
	if (ret < 0)
		return ret;

	return i2c_smbus_read_i2c_block_data(ec->client, LENOVO_EC_RESPONSE_REG,
					     resp_len, resp);
}

int yoga_c630_ec_read8(struct yoga_c630_ec *ec, u8 addr)
{
	u8 req[2] = { LENOVO_EC_READ_REG, };
	int ret;
	u8 val;

	guard(mutex)(&ec->lock);

	req[1] = addr;
	ret = yoga_c630_ec_request(ec, req, sizeof(req), &val, 1);
	if (ret < 0)
		return ret;

	return val;
}
EXPORT_SYMBOL_GPL(yoga_c630_ec_read8);

int yoga_c630_ec_read16(struct yoga_c630_ec *ec, u8 addr)
{
	u8 req[2] = { LENOVO_EC_READ_REG, };
	int ret;
	u8 msb;
	u8 lsb;

	/* don't overflow the address */
	if (addr == 0xff)
		return -EINVAL;

	guard(mutex)(&ec->lock);

	req[1] = addr;
	ret = yoga_c630_ec_request(ec, req, sizeof(req), &lsb, 1);
	if (ret < 0)
		return ret;

	req[1] = addr + 1;
	ret = yoga_c630_ec_request(ec, req, sizeof(req), &msb, 1);
	if (ret < 0)
		return ret;

	return msb << 8 | lsb;
}
EXPORT_SYMBOL_GPL(yoga_c630_ec_read16);

u16 yoga_c630_ec_ucsi_get_version(struct yoga_c630_ec *ec)
{
	u8 req[3] = { 0xb3, 0xf2, };
	int ret;
	u8 msb;
	u8 lsb;

	guard(mutex)(&ec->lock);

	req[2] = LENOVO_EC_UCSI_VERSION;
	ret = yoga_c630_ec_request(ec, req, sizeof(req), &lsb, 1);
	if (ret < 0)
		return ret;

	req[2] = LENOVO_EC_UCSI_VERSION + 1;
	ret = yoga_c630_ec_request(ec, req, sizeof(req), &msb, 1);
	if (ret < 0)
		return ret;

	return msb << 8 | lsb;
}
EXPORT_SYMBOL_GPL(yoga_c630_ec_ucsi_get_version);

int yoga_c630_ec_ucsi_write(struct yoga_c630_ec *ec,

Annotation

Implementation Notes