Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * hid.c -- HID Composite driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Based on multi.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/usb/composite.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/usb/g_hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define DRIVER_DESC		"HID Gadget"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define DRIVER_VERSION		"2010/03/16"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "u_hid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define HIDG_VENDOR_NUM		0x0525	/* XXX NetChip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define HIDG_PRODUCT_NUM	0xa4ac	/* Linux-USB HID gadget */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) struct hidg_func_node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct usb_function_instance *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct usb_function *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct hidg_func_descriptor *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static LIST_HEAD(hidg_func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) USB_GADGET_COMPOSITE_OPTIONS();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static struct usb_device_descriptor device_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.bLength =		sizeof device_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.bDescriptorType =	USB_DT_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/* .bcdUSB = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* .bDeviceClass =		USB_CLASS_COMM, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/* .bDeviceSubClass =	0, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/* .bDeviceProtocol =	0, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.bDeviceClass =		USB_CLASS_PER_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.bDeviceSubClass =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.bDeviceProtocol =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* .bMaxPacketSize0 = f(hardware) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* Vendor and product id can be overridden by module parameters.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.idVendor =		cpu_to_le16(HIDG_VENDOR_NUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.idProduct =		cpu_to_le16(HIDG_PRODUCT_NUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/* .bcdDevice = f(hardware) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	/* .iManufacturer = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/* .iProduct = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* NO SERIAL NUMBER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.bNumConfigurations =	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static const struct usb_descriptor_header *otg_desc[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /* string IDs are assigned dynamically */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static struct usb_string strings_dev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	[USB_GADGET_MANUFACTURER_IDX].s = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	[USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	[USB_GADGET_SERIAL_IDX].s = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	{  } /* end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static struct usb_gadget_strings stringtab_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.language	= 0x0409,	/* en-us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.strings	= strings_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static struct usb_gadget_strings *dev_strings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	&stringtab_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) /****************************** Configurations ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int do_config(struct usb_configuration *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct hidg_func_node *e, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (gadget_is_otg(c->cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		c->descriptors = otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	list_for_each_entry(e, &hidg_func_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		e->f = usb_get_function(e->fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (IS_ERR(e->f)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			status = PTR_ERR(e->f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		status = usb_add_function(c, e->f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			usb_put_function(e->f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	list_for_each_entry(n, &hidg_func_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		if (n == e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		usb_remove_function(c, n->f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		usb_put_function(n->f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static struct usb_configuration config_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.label			= "HID Gadget",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.bConfigurationValue	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/* .iConfiguration = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /****************************** Gadget Bind ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int hid_bind(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct usb_gadget *gadget = cdev->gadget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct list_head *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct hidg_func_node *n, *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct f_hid_opts *hid_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int status, funcs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	list_for_each(tmp, &hidg_func_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		funcs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!funcs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	list_for_each_entry(n, &hidg_func_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		n->fi = usb_get_function_instance("hid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (IS_ERR(n->fi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			status = PTR_ERR(n->fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		hid_opts = container_of(n->fi, struct f_hid_opts, func_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		hid_opts->subclass = n->func->subclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		hid_opts->protocol = n->func->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		hid_opts->report_length = n->func->report_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		hid_opts->report_desc_length = n->func->report_desc_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		hid_opts->report_desc = n->func->report_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* Allocate string descriptor numbers ... note that string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * contents can be overridden by the composite_dev glue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	status = usb_string_ids_tab(cdev, strings_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (gadget_is_otg(gadget) && !otg_desc[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		struct usb_descriptor_header *usb_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		usb_desc = usb_otg_descriptor_alloc(gadget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		if (!usb_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		usb_otg_descriptor_init(gadget, usb_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		otg_desc[0] = usb_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		otg_desc[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* register our configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	status = usb_add_config(cdev, &config_driver, do_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		goto free_otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	usb_composite_overwrite_options(cdev, &coverwrite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) free_otg_desc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	kfree(otg_desc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	otg_desc[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	list_for_each_entry(m, &hidg_func_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (m == n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		usb_put_function_instance(m->fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int hid_unbind(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct hidg_func_node *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	list_for_each_entry(n, &hidg_func_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		usb_put_function(n->f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		usb_put_function_instance(n->fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	kfree(otg_desc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	otg_desc[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int hidg_plat_driver_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct hidg_func_descriptor *func = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct hidg_func_node *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (!func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		dev_err(&pdev->dev, "Platform data missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	entry->func = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	list_add_tail(&entry->node, &hidg_func_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int hidg_plat_driver_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct hidg_func_node *e, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	list_for_each_entry_safe(e, n, &hidg_func_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		list_del(&e->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		kfree(e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /****************************** Some noise ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static struct usb_composite_driver hidg_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	.name		= "g_hid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	.dev		= &device_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	.strings	= dev_strings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	.max_speed	= USB_SPEED_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	.bind		= hid_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	.unbind		= hid_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct platform_driver hidg_plat_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.remove		= hidg_plat_driver_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		.name	= "hidg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) MODULE_AUTHOR("Fabien Chouteau, Peter Korsgaard");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int __init hidg_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	status = platform_driver_probe(&hidg_plat_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				hidg_plat_driver_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	status = usb_composite_probe(&hidg_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		platform_driver_unregister(&hidg_plat_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) module_init(hidg_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void __exit hidg_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	usb_composite_unregister(&hidg_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	platform_driver_unregister(&hidg_plat_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) module_exit(hidg_cleanup);