drivers/input/touchscreen/st1232.c

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

File Facts

System
Linux kernel
Corpus path
drivers/input/touchscreen/st1232.c
Extension
.c
Size
12029 bytes
Lines
487
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 st_chip_info {
	bool	have_z;
	u16	max_area;
	u16	max_fingers;
};

struct st1232_ts_data {
	struct i2c_client *client;
	struct input_dev *input_dev;
	struct touchscreen_properties prop;
	struct dev_pm_qos_request low_latency_req;
	struct gpio_desc *reset_gpio;
	const struct st_chip_info *chip_info;
	struct list_head touch_overlay_list;
	int read_buf_len;
	u8 *read_buf;
	u8 fw_version;
	u32 fw_revision;
};

static ssize_t fw_version_show(struct device *dev,
			       struct device_attribute *attr, char *buf)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct st1232_ts_data *st1232_ts = i2c_get_clientdata(client);

	return sysfs_emit(buf, "%u\n", st1232_ts->fw_version);
}

static ssize_t fw_revision_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct st1232_ts_data *st1232_ts = i2c_get_clientdata(client);

	return sysfs_emit(buf, "%08x\n", st1232_ts->fw_revision);
}

static DEVICE_ATTR_RO(fw_version);
static DEVICE_ATTR_RO(fw_revision);

static struct attribute *st1232_attrs[] = {
	&dev_attr_fw_version.attr,
	&dev_attr_fw_revision.attr,
	NULL,
};
ATTRIBUTE_GROUPS(st1232);

static int st1232_ts_read_data(struct st1232_ts_data *ts, u8 reg,
			       unsigned int n)
{
	struct i2c_client *client = ts->client;
	struct i2c_msg msg[] = {
		{
			.addr	= client->addr,
			.len	= sizeof(reg),
			.buf	= &reg,
		},
		{
			.addr	= client->addr,
			.flags	= I2C_M_RD | I2C_M_DMA_SAFE,
			.len	= n,
			.buf	= ts->read_buf,
		}
	};
	int ret;

	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
	if (ret != ARRAY_SIZE(msg))
		return ret < 0 ? ret : -EIO;

	return 0;
}

static int st1232_ts_wait_ready(struct st1232_ts_data *ts)
{
	unsigned int retries;
	int error;

	for (retries = 100; retries; retries--) {
		error = st1232_ts_read_data(ts, REG_STATUS, 1);
		if (!error) {
			switch (ts->read_buf[0]) {
			case STATUS_NORMAL | ERROR_NONE:
			case STATUS_IDLE | ERROR_NONE:
				return 0;
			}
		}

		usleep_range(1000, 2000);

Annotation

Implementation Notes