drivers/input/touchscreen/himax_hx852x.c

Source file repositories/reference/linux-study-clean/drivers/input/touchscreen/himax_hx852x.c

File Facts

System
Linux kernel
Corpus path
drivers/input/touchscreen/himax_hx852x.c
Extension
.c
Size
12863 bytes
Lines
504
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 hx852x {
	struct i2c_client *client;
	struct input_dev *input_dev;
	struct touchscreen_properties props;
	struct gpio_desc *reset_gpiod;
	struct regulator_bulk_data supplies[2];
	unsigned int max_fingers;
	unsigned int keycount;
	unsigned int keycodes[HX852X_MAX_KEY_COUNT];
};

struct hx852x_config {
	u8 rx_num;
	u8 tx_num;
	u8 max_pt;
	u8 padding1[3];
	__be16 x_res;
	__be16 y_res;
	u8 padding2[2];
} __packed __aligned(4);

struct hx852x_coord {
	__be16 x;
	__be16 y;
} __packed __aligned(4);

struct hx852x_touch_info {
	u8 finger_num;
	__le16 finger_pressed;
	u8 padding;
} __packed __aligned(4);

static int hx852x_i2c_read(struct hx852x *hx, u8 cmd, void *data, u16 len)
{
	struct i2c_client *client = hx->client;
	int error;
	int ret;

	struct i2c_msg msg[] = {
		{
			.addr = client->addr,
			.flags = 0,
			.len = 1,
			.buf = &cmd,
		},
		{
			.addr = client->addr,
			.flags = I2C_M_RD,
			.len = len,
			.buf = data,
		},
	};

	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
	if (ret != ARRAY_SIZE(msg)) {
		error = ret < 0 ? ret : -EIO;
		dev_err(&client->dev, "failed to read %#x: %d\n", cmd, error);
		return error;
	}

	return 0;
}

static int hx852x_power_on(struct hx852x *hx)
{
	struct device *dev = &hx->client->dev;
	int error;

	error = regulator_bulk_enable(ARRAY_SIZE(hx->supplies), hx->supplies);
	if (error) {
		dev_err(dev, "failed to enable regulators: %d\n", error);
		return error;
	}

	gpiod_set_value_cansleep(hx->reset_gpiod, 1);
	msleep(20);
	gpiod_set_value_cansleep(hx->reset_gpiod, 0);
	msleep(50);

	return 0;
}

static int hx852x_start(struct hx852x *hx)
{
	struct device *dev = &hx->client->dev;
	int error;

	error = i2c_smbus_write_byte(hx->client, HX852X_TS_SLEEP_OUT);
	if (error) {
		dev_err(dev, "failed to send TS_SLEEP_OUT: %d\n", error);

Annotation

Implementation Notes