drivers/hid/hid-sensor-custom.c

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

File Facts

System
Linux kernel
Corpus path
drivers/hid/hid-sensor-custom.c
Extension
.c
Size
29599 bytes
Lines
1075
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 hid_sensor_custom_fops = {
	.open =  hid_sensor_custom_open,
	.read =  hid_sensor_custom_read,
	.release = hid_sensor_custom_release,
	.poll = hid_sensor_custom_poll,
	.llseek = noop_llseek,
};

static int hid_sensor_custom_dev_if_add(struct hid_sensor_custom *sensor_inst)
{
	int ret;

	ret = kfifo_alloc(&sensor_inst->data_fifo, HID_CUSTOM_FIFO_SIZE,
			  GFP_KERNEL);
	if (ret)
		return ret;

	init_waitqueue_head(&sensor_inst->wait);

	sensor_inst->custom_dev.minor = MISC_DYNAMIC_MINOR;
	sensor_inst->custom_dev.name = dev_name(&sensor_inst->pdev->dev);
	sensor_inst->custom_dev.fops = &hid_sensor_custom_fops;
	ret = misc_register(&sensor_inst->custom_dev);
	if (ret) {
		kfifo_free(&sensor_inst->data_fifo);
		return ret;
	}
	return 0;
}

static void hid_sensor_custom_dev_if_remove(struct hid_sensor_custom
								*sensor_inst)
{
	wake_up(&sensor_inst->wait);
	misc_deregister(&sensor_inst->custom_dev);
	kfifo_free(&sensor_inst->data_fifo);

}

/*
 * Match a known custom sensor.
 * tag and luid is mandatory.
 */
struct hid_sensor_custom_match {
	const char *tag;
	const char *luid;
	const char *model;
	const char *manufacturer;
	bool check_dmi;
	struct dmi_system_id dmi;
};

/*
 * Custom sensor properties used for matching.
 */
struct hid_sensor_custom_properties {
	u16 serial_num[HID_CUSTOM_MAX_FEATURE_BYTES];
	u16 model[HID_CUSTOM_MAX_FEATURE_BYTES];
	u16 manufacturer[HID_CUSTOM_MAX_FEATURE_BYTES];
};

static const struct hid_sensor_custom_match hid_sensor_custom_known_table[] = {
	/*
	 * Intel Integrated Sensor Hub (ISH)
	 */
	{	/* Intel ISH hinge */
		.tag = "INT",
		.luid = "020B000000000000",
		.manufacturer = "INTEL",
	},
	/*
	 * Lenovo Intelligent Sensing Solution (LISS)
	 */
	{	/* ambient light */
		.tag = "LISS",
		.luid = "0041010200000082",
		.model = "STK3X3X Sensor",
		.manufacturer = "Vendor 258",
		.check_dmi = true,
		.dmi.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
		}
	},
	{	/* human presence */
		.tag = "LISS",
		.luid = "0226000171AC0081",
		.model = "VL53L1_HOD Sensor",
		.manufacturer = "ST_MICRO",
		.check_dmi = true,
		.dmi.matches = {

Annotation

Implementation Notes