// SPDX-License-Identifier: GPL-2.0+/* * f_hid.c -- USB HID function driver * * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.com> */#include<linux/kernel.h>#include<linux/module.h>#include<linux/hid.h>#include<linux/idr.h>#include<linux/cdev.h>#include<linux/mutex.h>#include<linux/poll.h>#include<linux/uaccess.h>#include<linux/wait.h>#include<linux/sched.h>#include<linux/usb/g_hid.h>#include"u_f.h"#include"u_hid.h"#define HIDG_MINORS 4staticintmajor,minors;staticstructclass*hidg_class;staticDEFINE_IDA(hidg_ida);staticDEFINE_MUTEX(hidg_ida_lock);/* protects access to hidg_ida *//*-------------------------------------------------------------------------*//* HID gadget struct */structf_hidg_req_list{structusb_request*req;unsignedintpos;structlist_headlist;};structf_hidg{/* configuration */unsignedcharbInterfaceSubClass;unsignedcharbInterfaceProtocol;unsignedcharprotocol;unsignedcharidle;unsignedshortreport_desc_length;char*report_desc;unsignedshortreport_length;/* * use_out_ep - if true, the OUT Endpoint (interrupt out method) * will be used to receive reports from the host * using functions with the "intout" suffix. * Otherwise, the OUT Endpoint will not be configured * and the SETUP/SET_REPORT method ("ssreport" suffix) * will be used to receive reports. */booluse_out_ep;/* recv report */spinlock_tread_spinlock;wait_queue_head_tread_queue;/* recv report - interrupt out only (use_out_ep == 1) */structlist_headcompleted_out_req;unsignedintqlen;/* recv report - setup set_report only (use_out_ep == 0) */char*set_report_buf;unsignedintset_report_length;/* send report */spinlock_twrite_spinlock;boolwrite_pending;wait_queue_head_twrite_queue;structusb_request*req;intminor;structcdevcdev;structusb_functionfunc;structusb_ep*in_ep;structusb_ep*out_ep;};staticinlinestructf_hidg*func_to_hidg(structusb_function