drivers/input/touchscreen/egalax_ts_serial.c

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

File Facts

System
Linux kernel
Corpus path
drivers/input/touchscreen/egalax_ts_serial.c
Extension
.c
Size
4425 bytes
Lines
190
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 egalax {
	struct input_dev *input;
	struct serio *serio;
	int idx;
	u8 data[EGALAX_FORMAT_MAX_LENGTH];
	char phys[32];
};

static void egalax_process_data(struct egalax *egalax)
{
	struct input_dev *dev = egalax->input;
	u8 *data = egalax->data;
	u16 x, y;
	u8 shift;
	u8 mask;

	shift = 3 - ((data[0] & EGALAX_FORMAT_RESOLUTION_MASK) >> 1);
	mask = 0xff >> (shift + 1);

	x = (((u16)(data[1] & mask) << 7) | (data[2] & 0x7f)) << shift;
	y = (((u16)(data[3] & mask) << 7) | (data[4] & 0x7f)) << shift;

	input_report_key(dev, BTN_TOUCH, data[0] & EGALAX_FORMAT_TOUCH_BIT);
	input_report_abs(dev, ABS_X, x);
	input_report_abs(dev, ABS_Y, y);
	input_sync(dev);
}

static irqreturn_t egalax_interrupt(struct serio *serio,
				    unsigned char data, unsigned int flags)
{
	struct egalax *egalax = serio_get_drvdata(serio);
	int pkt_len;

	egalax->data[egalax->idx++] = data;

	if (likely(egalax->data[0] & EGALAX_FORMAT_START_BIT)) {
		pkt_len = egalax->data[0] & EGALAX_FORMAT_PRESSURE_BIT ? 6 : 5;
		if (pkt_len == egalax->idx) {
			egalax_process_data(egalax);
			egalax->idx = 0;
		}
	} else {
		dev_dbg(&serio->dev, "unknown/unsynchronized data: %x\n",
			egalax->data[0]);
		egalax->idx = 0;
	}

	return IRQ_HANDLED;
}

/*
 * egalax_connect() is the routine that is called when someone adds a
 * new serio device that supports egalax protocol and registers it as
 * an input device. This is usually accomplished using inputattach.
 */
static int egalax_connect(struct serio *serio, struct serio_driver *drv)
{
	struct egalax *egalax;
	struct input_dev *input_dev;
	int error;

	egalax = kzalloc_obj(*egalax);
	input_dev = input_allocate_device();
	if (!egalax || !input_dev) {
		error = -ENOMEM;
		goto err_free_mem;
	}

	egalax->serio = serio;
	egalax->input = input_dev;
	scnprintf(egalax->phys, sizeof(egalax->phys), "%s/input0", serio->phys);

	input_dev->name = "EETI eGalaxTouch Serial TouchScreen";
	input_dev->phys = egalax->phys;
	input_dev->id.bustype = BUS_RS232;
	input_dev->id.vendor = SERIO_EGALAX;
	input_dev->id.product = 0;
	input_dev->id.version = 0x0001;
	input_dev->dev.parent = &serio->dev;

	input_set_capability(input_dev, EV_KEY, BTN_TOUCH);
	input_set_abs_params(input_dev, ABS_X,
			     EGALAX_MIN_XC, EGALAX_MAX_XC, 0, 0);
	input_set_abs_params(input_dev, ABS_Y,
			     EGALAX_MIN_YC, EGALAX_MAX_YC, 0, 0);

	serio_set_drvdata(serio, egalax);

	error = serio_open(serio, drv);

Annotation

Implementation Notes