Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18104018 authored by Jack Pham's avatar Jack Pham Committed by Matt Wagantall
Browse files

usb: gadget: android: Convert to new FunctionFS interface



The Gadget FunctionFS driver had recently been converted to a
fully modularized component. Update the hooks from the Android
gadget driver to use the new style interface.

Signed-off-by: default avatarJack Pham <jackp@codeaurora.org>
parent 4394fbd5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -414,6 +414,7 @@ config USB_G_ANDROID
	boolean "Android Composite Gadget"
	select USB_F_ACM
	select USB_LIBCOMPOSITE
	select USB_F_FS
	select USB_U_SERIAL
	help
	  The Android Composite Gadget supports multiple USB
+31 −19
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@

#include "gadget_chips.h"

#include "f_fs.c"
#include "u_fs.h"
#include "f_audio_source.c"
#include "f_mass_storage.c"
#include "f_mtp.c"
@@ -212,22 +212,44 @@ static void android_disable(struct android_dev *dev)
struct functionfs_config {
	bool opened;
	bool enabled;
	struct usb_function *func;
	struct usb_function_instance *fi;
	struct ffs_data *data;
};

static int functionfs_ready_callback(struct ffs_data *ffs);
static void functionfs_closed_callback(struct ffs_data *ffs);

static int ffs_function_init(struct android_usb_function *f,
			     struct usb_composite_dev *cdev)
{
	struct functionfs_config *config;
	struct f_fs_opts *opts;

	f->config = kzalloc(sizeof(struct functionfs_config), GFP_KERNEL);
	if (!f->config)
		return -ENOMEM;

	return functionfs_init();
	config = f->config;

	config->fi = usb_get_function_instance("ffs");
	if (IS_ERR(config->fi))
		return PTR_ERR(config->fi);

	opts = to_f_fs_opts(config->fi);
	opts->dev->ffs_ready_callback = functionfs_ready_callback;
	opts->dev->ffs_closed_callback = functionfs_closed_callback;
	opts->no_configfs = true;

	return ffs_single_dev(opts->dev);
}

static void ffs_function_cleanup(struct android_usb_function *f)
{
	functionfs_cleanup();
	struct functionfs_config *config = f->config;
	if (config)
		usb_put_function_instance(config->fi);

	kfree(f->config);
}

@@ -259,7 +281,11 @@ static int ffs_function_bind_config(struct android_usb_function *f,
				    struct usb_configuration *c)
{
	struct functionfs_config *config = f->config;
	return functionfs_bind_config(c->cdev, c, config->data);
	config->func = usb_get_function(config->fi);
	if (IS_ERR(config->func))
		return PTR_ERR(config->func);

	return usb_add_function(c, config->func);
}

static ssize_t
@@ -322,17 +348,12 @@ static int functionfs_ready_callback(struct ffs_data *ffs)

	mutex_lock(&dev->mutex);

	ret = functionfs_bind(ffs, dev->cdev);
	if (ret)
		goto err;

	config->data = ffs;
	config->opened = true;

	if (config->enabled)
		android_enable(dev);

err:
	mutex_unlock(&dev->mutex);
	return ret;
}
@@ -350,20 +371,11 @@ static void functionfs_closed_callback(struct ffs_data *ffs)
	config->opened = false;
	config->data = NULL;

	functionfs_unbind(ffs);
	usb_put_function(config->func);

	mutex_unlock(&dev->mutex);
}

static void *functionfs_acquire_dev_callback(const char *dev_name)
{
	return 0;
}

static void functionfs_release_dev_callback(struct ffs_data *ffs_data)
{
}

#define MAX_ACM_INSTANCES 4
struct acm_function_config {
	int instances;