Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
usb: gadget: Make old-style configfs disableable
Browse files Browse the repository at this point in the history
* As seen in 990 kernel
* Should allow us to use standard usb gadget HAL

Change-Id: Ica01364942961a3e55624803ce95aca0b42e6ecf
  • Loading branch information
Linux4 authored and Royna2544 committed Apr 30, 2024
1 parent 4bdca84 commit 5454da6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion drivers/usb/gadget/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ config USB_OLD_CONFIGFS
depends on USB_CONFIGFS
default n
help
It supports old style configfs
It supports old style configfs

config USB_G_ANDROID
bool "Android Composite Gadget"
Expand Down
43 changes: 28 additions & 15 deletions drivers/usb/gadget/configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ struct gadget_info {
spinlock_t spinlock;
bool unbind;
#ifdef CONFIG_USB_CONFIGFS_UEVENT
bool enabled;
bool connected;
bool sw_connected;
struct work_struct work;
struct device *dev;
#endif
#ifdef CONFIG_USB_OLD_CONFIGFS
bool enabled;
struct list_head linked_func;
bool symboliclink_change_mode;
#endif
Expand Down Expand Up @@ -366,6 +368,7 @@ static int unregister_gadget(struct gadget_info *gi)
return 0;
}

#ifdef CONFIG_USB_OLD_CONFIGFS
static void clear_current_usb_link(struct usb_composite_dev *cdev)
{
struct usb_configuration *c;
Expand All @@ -386,14 +389,15 @@ static void clear_current_usb_link(struct usb_composite_dev *cdev)
}
}
}
#endif

static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
const char *page, size_t len)
{
struct gadget_info *gi = to_gadget_info(item);
char *name;
int ret;
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
struct usb_composite_dev *cdev;
#endif

Expand All @@ -415,7 +419,7 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
if (name[len - 1] == '\n')
name[len - 1] = '\0';

#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
cdev = &gi->cdev;
if (!cdev) {
printk("usb: %s : cdev is null, name = %s \n",__func__, name);
Expand All @@ -430,7 +434,7 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
if (ret)
goto err;
kfree(name);
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
if (!list_empty(&gi->linked_func) && gi->symboliclink_change_mode) {
pr_info("usb: %s: GSI_image : Clear cfg->func_list\n", __func__);
clear_current_usb_link(cdev);
Expand All @@ -447,7 +451,7 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
gi->composite.gadget_driver.udc_name = NULL;
goto err;
}
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
if (gi->symboliclink_change_mode) {
pr_info("usb: %s : gi->symboliclink_change_mode = %d\n", __func__,
gi->symboliclink_change_mode);
Expand Down Expand Up @@ -564,7 +568,7 @@ static void set_unique_rndis_mac_address(
}
#endif

#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
static int check_symboliclink_change_mode (struct config_usb_cfg *cfg)
{
struct gadget_config_name *cn;
Expand Down Expand Up @@ -635,7 +639,7 @@ static int config_usb_cfg_link(
struct usb_function_instance, group);
struct usb_function_instance *a_fi;
struct usb_function *f;
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
int is_vts_mtp = 0;
#endif
int ret;
Expand All @@ -657,7 +661,7 @@ static int config_usb_cfg_link(

list_for_each_entry(f, &cfg->func_list, list) {
if (f->fi == fi) {
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
pr_info("usb: %s : usb function instance already exist (GSI)~\n", __func__);
gi->symboliclink_change_mode = 1;
if (list_empty(&gi->linked_func)) {
Expand Down Expand Up @@ -692,7 +696,7 @@ static int config_usb_cfg_link(
set_unique_rndis_mac_address(gi, fi);
}
#endif
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
/* Go through all configs, attach all functions */
is_vts_mtp = check_symboliclink_change_mode(cfg);
if (is_vts_mtp) {
Expand Down Expand Up @@ -728,7 +732,7 @@ static int config_usb_cfg_link(
goto out;
}

#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
list_add_tail(&f->list, &gi->linked_func);
#else
/* stash the function until we bind it to the gadget */
Expand Down Expand Up @@ -1914,8 +1918,10 @@ static int android_setup(struct usb_gadget *gadget,
struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
int value = -EOPNOTSUPP;
struct usb_function_instance *fi;
#ifdef CONFIG_USB_OLD_CONFIGFS
struct usb_configuration *configuration;
struct usb_function *f;
#endif
#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
struct usb_request *req = cdev->req;

Expand All @@ -1935,6 +1941,7 @@ static int android_setup(struct usb_gadget *gadget,
break;
}
}
#ifdef CONFIG_USB_OLD_CONFIGFS
list_for_each_entry(configuration, &cdev->configs, list) {
list_for_each_entry(f, &configuration->functions, list) {
if (f != NULL && f->ctrlrequest != NULL) {
Expand All @@ -1944,6 +1951,8 @@ static int android_setup(struct usb_gadget *gadget,
}
}
}
#endif

#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
if (value < 0)
value = terminal_ctrl_request(cdev, c);
Expand Down Expand Up @@ -2052,6 +2061,8 @@ static const struct usb_gadget_driver configfs_driver_template = {
};

#ifdef CONFIG_USB_CONFIGFS_UEVENT

#ifdef CONFIG_USB_OLD_CONFIGFS
static ssize_t
functions_show(struct device *pdev, struct device_attribute *attr, char *buf)
{
Expand Down Expand Up @@ -2225,6 +2236,10 @@ static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
mutex_unlock(&dev->lock);
return size;
}
static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show,
functions_store);
static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
#endif

static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
char *buf)
Expand All @@ -2251,10 +2266,6 @@ static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
out:
return sprintf(buf, "%s\n", state);
}

static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show,
functions_store);
static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
static DEVICE_ATTR(state, S_IRUGO, state_show, NULL);

#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
Expand All @@ -2271,8 +2282,10 @@ static DEVICE_ATTR(bcdUSB, S_IRUGO, bcdUSB_show, NULL);

static struct device_attribute *android_usb_attributes[] = {
&dev_attr_state,
#ifdef CONFIG_USB_OLD_CONFIGFS
&dev_attr_enable,
&dev_attr_functions,
#endif
#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
&dev_attr_bcdUSB,
#endif
Expand Down Expand Up @@ -2368,7 +2381,7 @@ static struct config_group *gadgets_make(
mutex_init(&gi->lock);
INIT_LIST_HEAD(&gi->string_list);
INIT_LIST_HEAD(&gi->available_func);
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#ifdef CONFIG_USB_OLD_CONFIGFS
INIT_LIST_HEAD(&gi->linked_func);
#endif

Expand Down
6 changes: 6 additions & 0 deletions drivers/usb/gadget/function/f_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3539,16 +3539,22 @@ static void ffs_func_unbind(struct usb_configuration *c,
static struct usb_function *ffs_alloc(struct usb_function_instance *fi)
{
struct ffs_function *func;
#ifdef CONFIG_USB_OLD_CONFIGFS
struct ffs_dev *dev;
#endif

ENTER();

func = kzalloc(sizeof(*func), GFP_KERNEL);
if (unlikely(!func))
return ERR_PTR(-ENOMEM);

#ifdef CONFIG_USB_OLD_CONFIGFS
dev = to_f_fs_opts(fi)->dev;
func->function.name = dev->name;
#else
func->function.name = "Function FS Gadget";
#endif

func->function.bind = ffs_func_bind;
func->function.unbind = ffs_func_unbind;
Expand Down

0 comments on commit 5454da6

Please sign in to comment.