drivers/hid/hid-picolcd_debugfs.c

Source file repositories/reference/linux-study-clean/drivers/hid/hid-picolcd_debugfs.c

File Facts

System
Linux kernel
Corpus path
drivers/hid/hid-picolcd_debugfs.c
Extension
.c
Size
26917 bytes
Lines
887
Domain
Driver Families
Bucket
drivers/hid
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations picolcd_debug_reset_fops = {
	.owner    = THIS_MODULE,
	.open     = picolcd_debug_reset_open,
	.read     = seq_read,
	.llseek   = seq_lseek,
	.write    = picolcd_debug_reset_write,
	.release  = single_release,
};

/*
 * The "eeprom" file
 */
static ssize_t picolcd_debug_eeprom_read(struct file *f, char __user *u,
		size_t s, loff_t *off)
{
	struct picolcd_data *data = f->private_data;
	struct picolcd_pending *resp;
	u8 raw_data[3];
	ssize_t ret = -EIO;

	if (s == 0)
		return -EINVAL;
	if (*off > 0x0ff)
		return 0;

	/* prepare buffer with info about what we want to read (addr & len) */
	raw_data[0] = *off & 0xff;
	raw_data[1] = (*off >> 8) & 0xff;
	raw_data[2] = s < 20 ? s : 20;
	if (*off + raw_data[2] > 0xff)
		raw_data[2] = 0x100 - *off;
	resp = picolcd_send_and_wait(data->hdev, REPORT_EE_READ, raw_data,
			sizeof(raw_data));
	if (!resp)
		return -EIO;

	if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
		/* successful read :) */
		ret = resp->raw_data[2];
		if (ret > s)
			ret = s;
		if (copy_to_user(u, resp->raw_data+3, ret))
			ret = -EFAULT;
		else
			*off += ret;
	} /* anything else is some kind of IO error */

	kfree(resp);
	return ret;
}

static ssize_t picolcd_debug_eeprom_write(struct file *f, const char __user *u,
		size_t s, loff_t *off)
{
	struct picolcd_data *data = f->private_data;
	struct picolcd_pending *resp;
	ssize_t ret = -EIO;
	u8 raw_data[23];

	if (s == 0)
		return -EINVAL;
	if (*off > 0x0ff)
		return -ENOSPC;

	memset(raw_data, 0, sizeof(raw_data));
	raw_data[0] = *off & 0xff;
	raw_data[1] = (*off >> 8) & 0xff;
	raw_data[2] = min_t(size_t, 20, s);
	if (*off + raw_data[2] > 0xff)
		raw_data[2] = 0x100 - *off;

	if (copy_from_user(raw_data+3, u, min((u8)20, raw_data[2])))
		return -EFAULT;
	resp = picolcd_send_and_wait(data->hdev, REPORT_EE_WRITE, raw_data,
			sizeof(raw_data));

	if (!resp)
		return -EIO;

	if (resp->in_report && resp->in_report->id == REPORT_EE_DATA) {
		/* check if written data matches */
		if (memcmp(raw_data, resp->raw_data, 3+raw_data[2]) == 0) {
			*off += raw_data[2];
			ret = raw_data[2];
		}
	}
	kfree(resp);
	return ret;
}

Annotation

Implementation Notes