2010-11-12 20:29:28 +07:00
|
|
|
/*
|
|
|
|
* g_ffs.c -- user mode file system API for USB composite function controllers
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Samsung Electronics
|
2012-01-13 21:05:16 +07:00
|
|
|
* Author: Michal Nazarewicz <mina86@mina86.com>
|
2010-11-12 20:29:28 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2010-11-17 23:09:47 +07:00
|
|
|
#define pr_fmt(fmt) "g_ffs: " fmt
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/utsname.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kbuild is not very cooperative with respect to linking separately
|
|
|
|
* compiled library objects into one module. So for now we won't use
|
|
|
|
* separate compilation ... ensuring init/exit sections work to shrink
|
|
|
|
* the runtime footprint, and giving us at least some parts of what
|
|
|
|
* a "gcc --combine ... part1.c part2.c part3.c ... " build would.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "composite.c"
|
|
|
|
#include "usbstring.c"
|
|
|
|
#include "config.c"
|
|
|
|
#include "epautoconf.c"
|
|
|
|
|
|
|
|
#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
|
|
|
|
# if defined USB_ETH_RNDIS
|
|
|
|
# undef USB_ETH_RNDIS
|
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_USB_FUNCTIONFS_RNDIS
|
|
|
|
# define USB_ETH_RNDIS y
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# include "f_ecm.c"
|
|
|
|
# include "f_subset.c"
|
|
|
|
# ifdef USB_ETH_RNDIS
|
|
|
|
# include "f_rndis.c"
|
|
|
|
# include "rndis.c"
|
|
|
|
# endif
|
|
|
|
# include "u_ether.c"
|
|
|
|
|
|
|
|
static u8 gfs_hostaddr[ETH_ALEN];
|
2010-06-25 21:29:27 +07:00
|
|
|
# ifdef CONFIG_USB_FUNCTIONFS_ETH
|
|
|
|
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
|
2010-05-05 17:53:15 +07:00
|
|
|
# endif
|
2010-06-25 21:29:27 +07:00
|
|
|
#else
|
2010-05-05 17:53:15 +07:00
|
|
|
# define gether_cleanup() do { } while (0)
|
|
|
|
# define gether_setup(gadget, hostaddr) ((int)0)
|
2010-06-25 21:29:27 +07:00
|
|
|
# define gfs_hostaddr NULL
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "f_fs.c"
|
|
|
|
|
|
|
|
#define DRIVER_NAME "g_ffs"
|
|
|
|
#define DRIVER_DESC "USB Function Filesystem"
|
|
|
|
#define DRIVER_VERSION "24 Aug 2004"
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_AUTHOR("Michal Nazarewicz");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2010-08-12 22:43:48 +07:00
|
|
|
#define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */
|
|
|
|
#define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
#define GFS_MAX_DEVS 10
|
|
|
|
|
|
|
|
struct gfs_ffs_obj {
|
|
|
|
const char *name;
|
|
|
|
bool mounted;
|
|
|
|
bool desc_ready;
|
|
|
|
struct ffs_data *ffs_data;
|
|
|
|
};
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
static struct usb_device_descriptor gfs_dev_desc = {
|
|
|
|
.bLength = sizeof gfs_dev_desc,
|
|
|
|
.bDescriptorType = USB_DT_DEVICE,
|
|
|
|
|
|
|
|
.bcdUSB = cpu_to_le16(0x0200),
|
|
|
|
.bDeviceClass = USB_CLASS_PER_INTERFACE,
|
|
|
|
|
2010-08-12 22:43:48 +07:00
|
|
|
.idVendor = cpu_to_le16(GFS_VENDOR_ID),
|
|
|
|
.idProduct = cpu_to_le16(GFS_PRODUCT_ID),
|
2010-05-05 17:53:15 +07:00
|
|
|
};
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
static char *func_names[GFS_MAX_DEVS];
|
|
|
|
static unsigned int func_num;
|
|
|
|
|
2010-08-12 22:43:48 +07:00
|
|
|
module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644);
|
|
|
|
MODULE_PARM_DESC(bDeviceClass, "USB Device class");
|
|
|
|
module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644);
|
|
|
|
MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass");
|
|
|
|
module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
|
|
|
|
MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol");
|
2012-05-14 20:51:52 +07:00
|
|
|
module_param_array_named(functions, func_names, charp, &func_num, 0);
|
|
|
|
MODULE_PARM_DESC(functions, "USB Functions list");
|
2010-05-05 17:53:15 +07:00
|
|
|
|
|
|
|
static const struct usb_descriptor_header *gfs_otg_desc[] = {
|
|
|
|
(const struct usb_descriptor_header *)
|
|
|
|
&(const struct usb_otg_descriptor) {
|
|
|
|
.bLength = sizeof(struct usb_otg_descriptor),
|
|
|
|
.bDescriptorType = USB_DT_OTG,
|
|
|
|
|
2010-08-12 22:43:48 +07:00
|
|
|
/*
|
|
|
|
* REVISIT SRP-only hardware is possible, although
|
|
|
|
* it would not be called "OTG" ...
|
|
|
|
*/
|
2010-05-05 17:53:15 +07:00
|
|
|
.bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
|
|
|
|
},
|
|
|
|
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-11-12 20:29:28 +07:00
|
|
|
/* String IDs are assigned dynamically */
|
2010-05-05 17:53:15 +07:00
|
|
|
static struct usb_string gfs_strings[] = {
|
|
|
|
#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
|
2010-06-25 21:29:27 +07:00
|
|
|
{ .s = "FunctionFS + RNDIS" },
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USB_FUNCTIONFS_ETH
|
2010-06-25 21:29:27 +07:00
|
|
|
{ .s = "FunctionFS + ECM" },
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
|
2010-06-25 21:29:27 +07:00
|
|
|
{ .s = "FunctionFS" },
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|
|
|
|
{ } /* end of list */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings *gfs_dev_strings[] = {
|
|
|
|
&(struct usb_gadget_strings) {
|
|
|
|
.language = 0x0409, /* en-us */
|
|
|
|
.strings = gfs_strings,
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2010-06-25 21:29:27 +07:00
|
|
|
struct gfs_configuration {
|
|
|
|
struct usb_configuration c;
|
|
|
|
int (*eth)(struct usb_configuration *c, u8 *ethaddr);
|
|
|
|
} gfs_configurations[] = {
|
2010-05-05 17:53:15 +07:00
|
|
|
#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
|
2010-06-25 21:29:27 +07:00
|
|
|
{
|
|
|
|
.eth = rndis_bind_config,
|
|
|
|
},
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_USB_FUNCTIONFS_ETH
|
2010-06-25 21:29:27 +07:00
|
|
|
{
|
|
|
|
.eth = eth_bind_config,
|
|
|
|
},
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
|
2010-06-25 21:29:27 +07:00
|
|
|
{
|
|
|
|
},
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|
2010-06-25 21:29:27 +07:00
|
|
|
};
|
2010-05-05 17:53:15 +07:00
|
|
|
|
|
|
|
static int gfs_bind(struct usb_composite_dev *cdev);
|
|
|
|
static int gfs_unbind(struct usb_composite_dev *cdev);
|
2010-06-25 21:29:27 +07:00
|
|
|
static int gfs_do_config(struct usb_configuration *c);
|
2010-05-05 17:53:15 +07:00
|
|
|
|
|
|
|
static struct usb_composite_driver gfs_driver = {
|
2010-08-12 22:43:48 +07:00
|
|
|
.name = DRIVER_NAME,
|
2010-05-05 17:53:15 +07:00
|
|
|
.dev = &gfs_dev_desc,
|
|
|
|
.strings = gfs_dev_strings,
|
2011-06-29 20:41:49 +07:00
|
|
|
.max_speed = USB_SPEED_HIGH,
|
2010-05-05 17:53:15 +07:00
|
|
|
.unbind = gfs_unbind,
|
2010-08-12 22:43:48 +07:00
|
|
|
.iProduct = DRIVER_DESC,
|
2010-05-05 17:53:15 +07:00
|
|
|
};
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
static DEFINE_MUTEX(gfs_lock);
|
|
|
|
static unsigned int missing_funcs;
|
|
|
|
static bool gfs_ether_setup;
|
|
|
|
static bool gfs_registered;
|
|
|
|
static bool gfs_single_func;
|
|
|
|
static struct gfs_ffs_obj *ffs_tab;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2012-03-12 18:55:42 +07:00
|
|
|
static int __init gfs_init(void)
|
2010-05-05 17:53:15 +07:00
|
|
|
{
|
2012-05-14 20:51:52 +07:00
|
|
|
int i;
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
ENTER();
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
if (!func_num) {
|
|
|
|
gfs_single_func = true;
|
|
|
|
func_num = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ffs_tab = kcalloc(func_num, sizeof *ffs_tab, GFP_KERNEL);
|
|
|
|
if (!ffs_tab)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!gfs_single_func)
|
|
|
|
for (i = 0; i < func_num; i++)
|
|
|
|
ffs_tab[i].name = func_names[i];
|
|
|
|
|
|
|
|
missing_funcs = func_num;
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
return functionfs_init();
|
|
|
|
}
|
|
|
|
module_init(gfs_init);
|
|
|
|
|
2012-03-12 18:55:42 +07:00
|
|
|
static void __exit gfs_exit(void)
|
2010-05-05 17:53:15 +07:00
|
|
|
{
|
|
|
|
ENTER();
|
2012-05-14 20:51:52 +07:00
|
|
|
mutex_lock(&gfs_lock);
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
if (gfs_registered)
|
2010-05-05 17:53:15 +07:00
|
|
|
usb_composite_unregister(&gfs_driver);
|
2012-05-14 20:51:52 +07:00
|
|
|
gfs_registered = false;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
|
|
|
functionfs_cleanup();
|
2012-05-14 20:51:52 +07:00
|
|
|
|
|
|
|
mutex_unlock(&gfs_lock);
|
|
|
|
kfree(ffs_tab);
|
2010-05-05 17:53:15 +07:00
|
|
|
}
|
|
|
|
module_exit(gfs_exit);
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
static struct gfs_ffs_obj *gfs_find_dev(const char *dev_name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ENTER();
|
|
|
|
|
|
|
|
if (gfs_single_func)
|
|
|
|
return &ffs_tab[0];
|
|
|
|
|
|
|
|
for (i = 0; i < func_num; i++)
|
|
|
|
if (strcmp(ffs_tab[i].name, dev_name) == 0)
|
|
|
|
return &ffs_tab[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
static int functionfs_ready_callback(struct ffs_data *ffs)
|
|
|
|
{
|
2012-05-14 20:51:52 +07:00
|
|
|
struct gfs_ffs_obj *ffs_obj;
|
2010-05-05 17:53:15 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ENTER();
|
2012-05-14 20:51:52 +07:00
|
|
|
mutex_lock(&gfs_lock);
|
|
|
|
|
|
|
|
ffs_obj = ffs->private_data;
|
|
|
|
if (!ffs_obj) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WARN_ON(ffs_obj->desc_ready)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
ffs_obj->desc_ready = true;
|
|
|
|
ffs_obj->ffs_data = ffs;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
if (--missing_funcs) {
|
|
|
|
ret = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gfs_registered) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
gfs_registered = true;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2010-08-12 22:43:54 +07:00
|
|
|
ret = usb_composite_probe(&gfs_driver, gfs_bind);
|
2010-05-05 17:53:15 +07:00
|
|
|
if (unlikely(ret < 0))
|
2012-05-14 20:51:52 +07:00
|
|
|
gfs_registered = false;
|
|
|
|
|
|
|
|
done:
|
|
|
|
mutex_unlock(&gfs_lock);
|
2010-05-05 17:53:15 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void functionfs_closed_callback(struct ffs_data *ffs)
|
|
|
|
{
|
2012-05-14 20:51:52 +07:00
|
|
|
struct gfs_ffs_obj *ffs_obj;
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
ENTER();
|
2012-05-14 20:51:52 +07:00
|
|
|
mutex_lock(&gfs_lock);
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
ffs_obj = ffs->private_data;
|
|
|
|
if (!ffs_obj)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ffs_obj->desc_ready = false;
|
|
|
|
missing_funcs++;
|
|
|
|
|
|
|
|
if (gfs_registered)
|
2010-05-05 17:53:15 +07:00
|
|
|
usb_composite_unregister(&gfs_driver);
|
2012-05-14 20:51:52 +07:00
|
|
|
gfs_registered = false;
|
|
|
|
|
|
|
|
done:
|
|
|
|
mutex_unlock(&gfs_lock);
|
2010-05-05 17:53:15 +07:00
|
|
|
}
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
static void *functionfs_acquire_dev_callback(const char *dev_name)
|
2010-05-05 17:53:15 +07:00
|
|
|
{
|
2012-05-14 20:51:52 +07:00
|
|
|
struct gfs_ffs_obj *ffs_dev;
|
|
|
|
|
|
|
|
ENTER();
|
|
|
|
mutex_lock(&gfs_lock);
|
|
|
|
|
|
|
|
ffs_dev = gfs_find_dev(dev_name);
|
|
|
|
if (!ffs_dev) {
|
|
|
|
ffs_dev = ERR_PTR(-ENODEV);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ffs_dev->mounted) {
|
|
|
|
ffs_dev = ERR_PTR(-EBUSY);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
ffs_dev->mounted = true;
|
|
|
|
|
|
|
|
done:
|
|
|
|
mutex_unlock(&gfs_lock);
|
|
|
|
return ffs_dev;
|
2010-05-05 17:53:15 +07:00
|
|
|
}
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
static void functionfs_release_dev_callback(struct ffs_data *ffs_data)
|
|
|
|
{
|
|
|
|
struct gfs_ffs_obj *ffs_dev;
|
|
|
|
|
|
|
|
ENTER();
|
|
|
|
mutex_lock(&gfs_lock);
|
|
|
|
|
|
|
|
ffs_dev = ffs_data->private_data;
|
|
|
|
if (ffs_dev)
|
|
|
|
ffs_dev->mounted = false;
|
|
|
|
|
|
|
|
mutex_unlock(&gfs_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is assumed that gfs_bind is called from a context where gfs_lock is held
|
|
|
|
*/
|
2010-05-05 17:53:15 +07:00
|
|
|
static int gfs_bind(struct usb_composite_dev *cdev)
|
|
|
|
{
|
2010-06-25 21:29:27 +07:00
|
|
|
int ret, i;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
|
|
|
ENTER();
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
if (missing_funcs)
|
2010-05-05 17:53:15 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = gether_setup(cdev->gadget, gfs_hostaddr);
|
|
|
|
if (unlikely(ret < 0))
|
|
|
|
goto error_quick;
|
2012-05-14 20:51:52 +07:00
|
|
|
gfs_ether_setup = true;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2010-06-25 21:29:27 +07:00
|
|
|
ret = usb_string_ids_tab(cdev, gfs_strings);
|
2010-05-05 17:53:15 +07:00
|
|
|
if (unlikely(ret < 0))
|
|
|
|
goto error;
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
for (i = func_num; --i; ) {
|
|
|
|
ret = functionfs_bind(ffs_tab[i].ffs_data, cdev);
|
|
|
|
if (unlikely(ret < 0)) {
|
|
|
|
while (++i < func_num)
|
|
|
|
functionfs_unbind(ffs_tab[i].ffs_data);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2010-06-25 21:29:27 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) {
|
|
|
|
struct gfs_configuration *c = gfs_configurations + i;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2010-08-12 22:43:48 +07:00
|
|
|
c->c.label = gfs_strings[i].s;
|
|
|
|
c->c.iConfiguration = gfs_strings[i].id;
|
2010-06-25 21:29:27 +07:00
|
|
|
c->c.bConfigurationValue = 1 + i;
|
|
|
|
c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER;
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2010-08-12 22:43:55 +07:00
|
|
|
ret = usb_add_config(cdev, &c->c, gfs_do_config);
|
2010-06-25 21:29:27 +07:00
|
|
|
if (unlikely(ret < 0))
|
|
|
|
goto error_unbind;
|
|
|
|
}
|
2010-05-05 17:53:15 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_unbind:
|
2012-05-14 20:51:52 +07:00
|
|
|
for (i = 0; i < func_num; i++)
|
|
|
|
functionfs_unbind(ffs_tab[i].ffs_data);
|
2010-05-05 17:53:15 +07:00
|
|
|
error:
|
|
|
|
gether_cleanup();
|
|
|
|
error_quick:
|
2012-05-14 20:51:52 +07:00
|
|
|
gfs_ether_setup = false;
|
2010-05-05 17:53:15 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
/*
|
|
|
|
* It is assumed that gfs_unbind is called from a context where gfs_lock is held
|
|
|
|
*/
|
2010-05-05 17:53:15 +07:00
|
|
|
static int gfs_unbind(struct usb_composite_dev *cdev)
|
|
|
|
{
|
2012-05-14 20:51:52 +07:00
|
|
|
int i;
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
ENTER();
|
|
|
|
|
2010-08-12 22:43:48 +07:00
|
|
|
/*
|
|
|
|
* We may have been called in an error recovery from
|
2010-05-05 17:53:15 +07:00
|
|
|
* composite_bind() after gfs_unbind() failure so we need to
|
|
|
|
* check if gfs_ffs_data is not NULL since gfs_bind() handles
|
|
|
|
* all error recovery itself. I'd rather we werent called
|
|
|
|
* from composite on orror recovery, but what you're gonna
|
2010-08-12 22:43:48 +07:00
|
|
|
* do...?
|
|
|
|
*/
|
2012-05-14 20:51:52 +07:00
|
|
|
if (gfs_ether_setup)
|
2010-05-05 17:53:15 +07:00
|
|
|
gether_cleanup();
|
2012-05-14 20:51:52 +07:00
|
|
|
gfs_ether_setup = false;
|
|
|
|
|
|
|
|
for (i = func_num; --i; )
|
|
|
|
if (ffs_tab[i].ffs_data)
|
|
|
|
functionfs_unbind(ffs_tab[i].ffs_data);
|
2010-05-05 17:53:15 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
/*
|
|
|
|
* It is assumed that gfs_do_config is called from a context where
|
|
|
|
* gfs_lock is held
|
|
|
|
*/
|
2010-06-25 21:29:27 +07:00
|
|
|
static int gfs_do_config(struct usb_configuration *c)
|
2010-05-05 17:53:15 +07:00
|
|
|
{
|
2010-06-25 21:29:27 +07:00
|
|
|
struct gfs_configuration *gc =
|
|
|
|
container_of(c, struct gfs_configuration, c);
|
2012-05-14 20:51:52 +07:00
|
|
|
int i;
|
2010-05-05 17:53:15 +07:00
|
|
|
int ret;
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
if (missing_funcs)
|
2010-05-05 17:53:15 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (gadget_is_otg(c->cdev->gadget)) {
|
|
|
|
c->descriptors = gfs_otg_desc;
|
|
|
|
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
|
|
|
|
}
|
|
|
|
|
2010-06-25 21:29:27 +07:00
|
|
|
if (gc->eth) {
|
|
|
|
ret = gc->eth(c, gfs_hostaddr);
|
2010-05-05 17:53:15 +07:00
|
|
|
if (unlikely(ret < 0))
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-05-14 20:51:52 +07:00
|
|
|
for (i = 0; i < func_num; i++) {
|
|
|
|
ret = functionfs_bind_config(c->cdev, c, ffs_tab[i].ffs_data);
|
|
|
|
if (unlikely(ret < 0))
|
|
|
|
return ret;
|
|
|
|
}
|
2010-05-05 17:53:15 +07:00
|
|
|
|
2010-08-12 22:43:48 +07:00
|
|
|
/*
|
|
|
|
* After previous do_configs there may be some invalid
|
2010-06-14 15:43:34 +07:00
|
|
|
* pointers in c->interface array. This happens every time
|
|
|
|
* a user space function with fewer interfaces than a user
|
|
|
|
* space function that was run before the new one is run. The
|
|
|
|
* compasit's set_config() assumes that if there is no more
|
|
|
|
* then MAX_CONFIG_INTERFACES interfaces in a configuration
|
|
|
|
* then there is a NULL pointer after the last interface in
|
2010-08-12 22:43:48 +07:00
|
|
|
* c->interface array. We need to make sure this is true.
|
|
|
|
*/
|
2010-06-14 15:43:34 +07:00
|
|
|
if (c->next_interface_id < ARRAY_SIZE(c->interface))
|
|
|
|
c->interface[c->next_interface_id] = NULL;
|
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_USB_FUNCTIONFS_ETH
|
2010-08-12 22:43:48 +07:00
|
|
|
|
2010-06-25 21:29:27 +07:00
|
|
|
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
|
2010-05-05 17:53:15 +07:00
|
|
|
{
|
2010-06-25 21:29:27 +07:00
|
|
|
return can_support_ecm(c->cdev->gadget)
|
|
|
|
? ecm_bind_config(c, ethaddr)
|
|
|
|
: geth_bind_config(c, ethaddr);
|
2010-05-05 17:53:15 +07:00
|
|
|
}
|
2010-08-12 22:43:48 +07:00
|
|
|
|
2010-05-05 17:53:15 +07:00
|
|
|
#endif
|