drivers/input/touchscreen/hynitron-cst816x.c

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

File Facts

System
Linux kernel
Corpus path
drivers/input/touchscreen/hynitron-cst816x.c
Extension
.c
Size
5893 bytes
Lines
254
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 cst816x_touch {
	u8 gest;
	u8 active;
	u16 abs_x;
	u16 abs_y;
} __packed;

struct cst816x_priv {
	struct i2c_client *client;
	struct gpio_desc *reset;
	struct input_dev *input;
	unsigned int keycode[CST816X_NUM_KEYS];
	unsigned int keycodemax;
};

static int cst816x_parse_keycodes(struct device *dev, struct cst816x_priv *priv)
{
	int count;
	int error;

	if (device_property_present(dev, "linux,keycodes")) {
		count = device_property_count_u32(dev, "linux,keycodes");
		if (count < 0) {
			error = count;
			dev_err(dev, "failed to count keys: %d\n", error);
			return error;
		} else if (count > ARRAY_SIZE(priv->keycode)) {
			dev_err(dev, "too many keys defined: %d\n", count);
			return -EINVAL;
		}
		priv->keycodemax = count;

		error = device_property_read_u32_array(dev, "linux,keycodes",
						       priv->keycode,
						       priv->keycodemax);
		if (error) {
			dev_err(dev, "failed to read keycodes: %d\n", error);
			return error;
		}
	}

	return 0;
}

static int cst816x_i2c_read_register(struct cst816x_priv *priv, u8 reg,
				     void *buf, size_t len)
{
	struct i2c_msg xfer[] = {
		{
			.addr = priv->client->addr,
			.flags = 0,
			.buf = &reg,
			.len = sizeof(reg),
		},
		{
			.addr = priv->client->addr,
			.flags = I2C_M_RD,
			.buf = buf,
			.len = len,
		},
	};
	int error;
	int ret;

	ret = i2c_transfer(priv->client->adapter, xfer, ARRAY_SIZE(xfer));
	if (ret != ARRAY_SIZE(xfer)) {
		error = ret < 0 ? ret : -EIO;
		dev_err(&priv->client->dev, "i2c rx err: %d\n", error);
		return error;
	}

	return 0;
}

static u8 cst816x_gest_idx(u8 gest)
{
	u8 index;

	switch (gest) {
	case 0x01: /* Slide up gesture */
	case 0x02: /* Slide down gesture */
	case 0x03: /* Slide left gesture */
	case 0x04: /* Slide right gesture */
		index = gest;
		break;
	case 0x0c: /* Long press gesture */
	default:
		index = CST816X_NUM_KEYS;
		break;
	}

Annotation

Implementation Notes