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)  * multi.c -- Multifunction Composite driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008 David Brownell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2008 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2009 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Michal Nazarewicz (mina86@mina86.com)
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "u_serial.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #if defined USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #  undef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #ifdef CONFIG_USB_G_MULTI_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #  define USB_ETH_RNDIS y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #endif
^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 DRIVER_DESC		"Multifunction Composite Gadget"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) MODULE_AUTHOR("Michal Nazarewicz");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "f_mass_storage.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "u_ecm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #  include "u_rndis.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #  include "rndis.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "u_ether.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) USB_GADGET_COMPOSITE_OPTIONS();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) USB_ETHERNET_MODULE_PARAMETERS();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /***************************** Device Descriptor ****************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define MULTI_VENDOR_NUM	0x1d6b	/* Linux Foundation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define MULTI_PRODUCT_NUM	0x0104	/* Multifunction Composite Gadget */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	__MULTI_NO_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #ifdef CONFIG_USB_G_MULTI_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	MULTI_RNDIS_CONFIG_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	MULTI_CDC_CONFIG_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static struct usb_device_descriptor device_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.bLength =		sizeof device_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.bDescriptorType =	USB_DT_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* .bcdUSB = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.bDeviceClass =		USB_CLASS_MISC /* 0xEF */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.bDeviceSubClass =	2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.bDeviceProtocol =	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* Vendor and product id can be overridden by module parameters.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.idVendor =		cpu_to_le16(MULTI_VENDOR_NUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.idProduct =		cpu_to_le16(MULTI_PRODUCT_NUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static const struct usb_descriptor_header *otg_desc[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	MULTI_STRING_RNDIS_CONFIG_IDX = USB_GADGET_FIRST_AVAIL_IDX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	MULTI_STRING_CDC_CONFIG_IDX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static struct usb_string strings_dev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	[USB_GADGET_MANUFACTURER_IDX].s = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	[USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	[USB_GADGET_SERIAL_IDX].s = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	[MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	[MULTI_STRING_CDC_CONFIG_IDX].s   = "Multifunction with CDC ECM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	{  } /* end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static struct usb_gadget_strings *dev_strings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	&(struct usb_gadget_strings){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		.language	= 0x0409,	/* en-us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		.strings	= strings_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /****************************** Configurations ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #ifdef CONFIG_USB_GADGET_DEBUG_FILES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * Number of buffers we will use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * 2 is usually enough for good buffering pipeline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define fsg_num_buffers	CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct usb_function_instance *fi_acm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static struct usb_function_instance *fi_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /********** RNDIS **********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static struct usb_function_instance *fi_rndis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static struct usb_function *f_acm_rndis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static struct usb_function *f_rndis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static struct usb_function *f_msg_rndis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int rndis_do_config(struct usb_configuration *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (gadget_is_otg(c->cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		c->descriptors = otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	f_rndis = usb_get_function(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (IS_ERR(f_rndis))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return PTR_ERR(f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ret = usb_add_function(c, f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		goto err_func_rndis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	f_acm_rndis = usb_get_function(fi_acm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (IS_ERR(f_acm_rndis)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		ret = PTR_ERR(f_acm_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		goto err_func_acm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	ret = usb_add_function(c, f_acm_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		goto err_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	f_msg_rndis = usb_get_function(fi_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (IS_ERR(f_msg_rndis)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		ret = PTR_ERR(f_msg_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		goto err_fsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	ret = usb_add_function(c, f_msg_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		goto err_run;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) err_run:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	usb_put_function(f_msg_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) err_fsg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	usb_remove_function(c, f_acm_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) err_conf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	usb_put_function(f_acm_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) err_func_acm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	usb_remove_function(c, f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) err_func_rndis:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	usb_put_function(f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return ret;
^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) static __ref int rndis_config_register(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	static struct usb_configuration config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		.bConfigurationValue	= MULTI_RNDIS_CONFIG_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	config.label          = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return usb_add_config(cdev, &config, rndis_do_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static __ref int rndis_config_register(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /********** CDC ECM **********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static struct usb_function_instance *fi_ecm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static struct usb_function *f_acm_multi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static struct usb_function *f_ecm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static struct usb_function *f_msg_multi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static int cdc_do_config(struct usb_configuration *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (gadget_is_otg(c->cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		c->descriptors = otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	f_ecm = usb_get_function(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (IS_ERR(f_ecm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return PTR_ERR(f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	ret = usb_add_function(c, f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		goto err_func_ecm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/* implicit port_num is zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	f_acm_multi = usb_get_function(fi_acm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (IS_ERR(f_acm_multi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		ret = PTR_ERR(f_acm_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		goto err_func_acm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	ret = usb_add_function(c, f_acm_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		goto err_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	f_msg_multi = usb_get_function(fi_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (IS_ERR(f_msg_multi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		ret = PTR_ERR(f_msg_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		goto err_fsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	ret = usb_add_function(c, f_msg_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		goto err_run;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) err_run:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	usb_put_function(f_msg_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) err_fsg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	usb_remove_function(c, f_acm_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) err_conf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	usb_put_function(f_acm_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) err_func_acm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	usb_remove_function(c, f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) err_func_ecm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	usb_put_function(f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static __ref int cdc_config_register(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	static struct usb_configuration config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		.bConfigurationValue	= MULTI_CDC_CONFIG_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
^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) 	config.label          = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return usb_add_config(cdev, &config, cdc_do_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static __ref int cdc_config_register(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /****************************** Gadget Bind ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static int __ref multi_bind(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	struct usb_gadget *gadget = cdev->gadget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct f_ecm_opts *ecm_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	struct f_rndis_opts *rndis_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct fsg_opts *fsg_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct fsg_config config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (!can_support_ecm(cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		dev_err(&gadget->dev, "controller '%s' not usable\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			gadget->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	fi_ecm = usb_get_function_instance("ecm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (IS_ERR(fi_ecm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		return PTR_ERR(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	gether_set_qmult(ecm_opts->net, qmult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!gether_set_host_addr(ecm_opts->net, host_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		pr_info("using host ethernet address: %s", host_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		pr_info("using self ethernet address: %s", dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	fi_rndis = usb_get_function_instance("rndis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (IS_ERR(fi_rndis)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		status = PTR_ERR(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	gether_set_qmult(rndis_opts->net, qmult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (!gether_set_host_addr(rndis_opts->net, host_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		pr_info("using host ethernet address: %s", host_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (!gether_set_dev_addr(rndis_opts->net, dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		pr_info("using self ethernet address: %s", dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 * If both ecm and rndis are selected then:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 *	1) rndis borrows the net interface from ecm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	 *	2) since the interface is shared it must not be bound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	 *	twice - in ecm's _and_ rndis' binds, so do it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	gether_set_gadget(ecm_opts->net, cdev->gadget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	status = gether_register_netdev(ecm_opts->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		goto fail0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	rndis_borrow_net(fi_rndis, ecm_opts->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	ecm_opts->bound = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	/* set up serial link layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	fi_acm = usb_get_function_instance("acm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	if (IS_ERR(fi_acm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		status = PTR_ERR(fi_acm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		goto fail0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	/* set up mass storage function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	fi_msg = usb_get_function_instance("mass_storage");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (IS_ERR(fi_msg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		status = PTR_ERR(fi_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	fsg_opts = fsg_opts_from_func_inst(fi_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	fsg_opts->no_configfs = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		goto fail_set_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	fsg_common_set_sysfs(fsg_opts->common, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	status = fsg_common_create_luns(fsg_opts->common, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		goto fail_set_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	fsg_common_set_inquiry_string(fsg_opts->common, config.vendor_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				      config.product_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* allocate string IDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	status = usb_string_ids_tab(cdev, strings_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (unlikely(status < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		goto fail_string_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (gadget_is_otg(gadget) && !otg_desc[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		struct usb_descriptor_header *usb_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		usb_desc = usb_otg_descriptor_alloc(gadget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		if (!usb_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			goto fail_string_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		usb_otg_descriptor_init(gadget, usb_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		otg_desc[0] = usb_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		otg_desc[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	/* register configurations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	status = rndis_config_register(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	if (unlikely(status < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		goto fail_otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	status = cdc_config_register(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (unlikely(status < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		goto fail_otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	usb_composite_overwrite_options(cdev, &coverwrite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	/* we're done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	dev_info(&gadget->dev, DRIVER_DESC "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	/* error recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) fail_otg_desc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	kfree(otg_desc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	otg_desc[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) fail_string_ids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	fsg_common_remove_luns(fsg_opts->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) fail_set_cdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	fsg_common_free_buffers(fsg_opts->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	usb_put_function_instance(fi_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	usb_put_function_instance(fi_acm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) fail0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	usb_put_function_instance(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	usb_put_function_instance(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static int multi_unbind(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	usb_put_function(f_msg_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	usb_put_function(f_msg_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	usb_put_function_instance(fi_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	usb_put_function(f_acm_multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	usb_put_function(f_acm_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	usb_put_function_instance(fi_acm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	usb_put_function(f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	usb_put_function_instance(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #ifdef CONFIG_USB_G_MULTI_CDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	usb_put_function(f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	usb_put_function_instance(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	kfree(otg_desc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	otg_desc[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /****************************** Some noise ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static struct usb_composite_driver multi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	.name		= "g_multi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	.dev		= &device_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	.strings	= dev_strings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	.max_speed	= USB_SPEED_SUPER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	.bind		= multi_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	.unbind		= multi_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	.needs_serial	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) module_usb_composite_driver(multi_driver);