drivers/input/touchscreen/usbtouchscreen.c

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

File Facts

System
Linux kernel
Corpus path
drivers/input/touchscreen/usbtouchscreen.c
Extension
.c
Size
45530 bytes
Lines
1801
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 usbtouch_device_info {
	int min_xc, max_xc;
	int min_yc, max_yc;
	int min_press, max_press;
	int rept_size;

	/*
	 * Always service the USB devices irq not just when the input device is
	 * open. This is useful when devices have a watchdog which prevents us
	 * from periodically polling the device. Leave this unset unless your
	 * touchscreen device requires it, as it does consume more of the USB
	 * bandwidth.
	 */
	bool irq_always;

	/*
	 * used to get the packet len. possible return values:
	 * > 0: packet len
	 * = 0: skip one byte
	 * < 0: -return value more bytes needed
	 */
	int  (*get_pkt_len) (unsigned char *pkt, int len);

	int  (*read_data)   (struct usbtouch_usb *usbtouch, unsigned char *pkt);
	int  (*alloc)       (struct usbtouch_usb *usbtouch);
	int  (*init)        (struct usbtouch_usb *usbtouch);
	void (*exit)	    (struct usbtouch_usb *usbtouch);
};

/* a usbtouch device */
struct usbtouch_usb {
	unsigned char *data;
	dma_addr_t data_dma;
	int data_size;
	unsigned char *buffer;
	int buf_len;
	struct urb *irq;
	struct usb_interface *interface;
	struct input_dev *input;
	const struct usbtouch_device_info *type;
	struct mutex pm_mutex;  /* serialize access to open/suspend */
	bool is_open;
	char name[128];
	char phys[64];
	void *priv;

	int x, y;
	int touch, press;

	void (*process_pkt)(struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
};


/*****************************************************************************
 * e2i Part
 */

#ifdef CONFIG_TOUCHSCREEN_USB_E2I
static int e2i_init(struct usbtouch_usb *usbtouch)
{
	int ret;
	struct usb_device *udev = interface_to_usbdev(usbtouch->interface);

	ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
	                      0x01, 0x02, 0x0000, 0x0081,
	                      NULL, 0, USB_CTRL_SET_TIMEOUT);

	dev_dbg(&usbtouch->interface->dev,
		"%s - usb_control_msg - E2I_RESET - bytes|err: %d\n",
		__func__, ret);
	return ret;
}

static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
{
	int tmp = (pkt[0] << 8) | pkt[1];
	dev->x  = (pkt[2] << 8) | pkt[3];
	dev->y  = (pkt[4] << 8) | pkt[5];

	tmp = tmp - 0xA000;
	dev->touch = (tmp > 0);
	dev->press = (tmp > 0 ? tmp : 0);

	return 1;
}

static const struct usbtouch_device_info e2i_dev_info = {
	.min_xc		= 0x0,
	.max_xc		= 0x7fff,
	.min_yc		= 0x0,

Annotation

Implementation Notes