Commit e6c661ef authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Felipe Balbi

usb: gadget: acm_ms: convert to new interface of f_mass_storage

Convert the legacy acm_ms gadget to use the new function interface
of f_mass_storage, so that later the compatibility layer in
f_mass_storage can be removed.
Signed-off-by: default avatarAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent ef0aa4b9
...@@ -1021,6 +1021,7 @@ config USB_G_ACM_MS ...@@ -1021,6 +1021,7 @@ config USB_G_ACM_MS
select USB_U_SERIAL select USB_U_SERIAL
select USB_F_ACM select USB_F_ACM
select USB_U_MS select USB_U_MS
select USB_F_MASS_STORAGE
help help
This driver provides two functions in one configuration: This driver provides two functions in one configuration:
a mass storage, and a CDC ACM (serial port) link. a mass storage, and a CDC ACM (serial port) link.
......
...@@ -31,17 +31,7 @@ ...@@ -31,17 +31,7 @@
#define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */ #define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */
#define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/ #define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/
/*-------------------------------------------------------------------------*/ #include "f_mass_storage.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.
*/
#define USB_FMS_INCLUDED
#include "f_mass_storage.c"
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
USB_GADGET_COMPOSITE_OPTIONS(); USB_GADGET_COMPOSITE_OPTIONS();
...@@ -121,16 +111,19 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; ...@@ -121,16 +111,19 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
static struct fsg_common fsg_common;
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static struct usb_function *f_acm; static struct usb_function *f_acm;
static struct usb_function_instance *f_acm_inst; static struct usb_function_instance *f_acm_inst;
static struct usb_function_instance *fi_msg;
static struct usb_function *f_msg;
/* /*
* We _always_ have both ACM and mass storage functions. * We _always_ have both ACM and mass storage functions.
*/ */
static int __init acm_ms_do_config(struct usb_configuration *c) static int __init acm_ms_do_config(struct usb_configuration *c)
{ {
struct fsg_opts *opts;
int status; int status;
if (gadget_is_otg(c->cdev->gadget)) { if (gadget_is_otg(c->cdev->gadget)) {
...@@ -138,31 +131,37 @@ static int __init acm_ms_do_config(struct usb_configuration *c) ...@@ -138,31 +131,37 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
f_acm_inst = usb_get_function_instance("acm"); opts = fsg_opts_from_func_inst(fi_msg);
if (IS_ERR(f_acm_inst))
return PTR_ERR(f_acm_inst);
f_acm = usb_get_function(f_acm_inst); f_acm = usb_get_function(f_acm_inst);
if (IS_ERR(f_acm)) { if (IS_ERR(f_acm))
status = PTR_ERR(f_acm); return PTR_ERR(f_acm);
goto err_func;
f_msg = usb_get_function(fi_msg);
if (IS_ERR(f_msg)) {
status = PTR_ERR(f_msg);
goto put_acm;
} }
status = usb_add_function(c, f_acm); status = usb_add_function(c, f_acm);
if (status < 0) if (status < 0)
goto err_conf; goto put_msg;
status = fsg_bind_config(c->cdev, c, &fsg_common); status = fsg_common_run_thread(opts->common);
if (status < 0) if (status)
goto err_fsg; goto remove_acm;
status = usb_add_function(c, f_msg);
if (status)
goto remove_acm;
return 0; return 0;
err_fsg: remove_acm:
usb_remove_function(c, f_acm); usb_remove_function(c, f_acm);
err_conf: put_msg:
usb_put_function(f_msg);
put_acm:
usb_put_function(f_acm); usb_put_function(f_acm);
err_func:
usb_put_function_instance(f_acm_inst);
return status; return status;
} }
...@@ -178,46 +177,82 @@ static struct usb_configuration acm_ms_config_driver = { ...@@ -178,46 +177,82 @@ static struct usb_configuration acm_ms_config_driver = {
static int __init acm_ms_bind(struct usb_composite_dev *cdev) static int __init acm_ms_bind(struct usb_composite_dev *cdev)
{ {
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
struct fsg_opts *opts;
struct fsg_config config;
int status; int status;
void *retp;
/* set up mass storage function */ f_acm_inst = usb_get_function_instance("acm");
retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data, if (IS_ERR(f_acm_inst))
fsg_num_buffers); return PTR_ERR(f_acm_inst);
if (IS_ERR(retp)) {
status = PTR_ERR(retp); fi_msg = usb_get_function_instance("mass_storage");
return PTR_ERR(retp); if (IS_ERR(fi_msg)) {
status = PTR_ERR(fi_msg);
goto fail_get_msg;
} }
/* set up mass storage function */
fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
opts = fsg_opts_from_func_inst(fi_msg);
opts->no_configfs = true;
status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers);
if (status)
goto fail;
status = fsg_common_set_nluns(opts->common, config.nluns);
if (status)
goto fail_set_nluns;
status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
if (status)
goto fail_set_cdev;
fsg_common_set_sysfs(opts->common, true);
status = fsg_common_create_luns(opts->common, &config);
if (status)
goto fail_set_cdev;
fsg_common_set_inquiry_string(opts->common, config.vendor_name,
config.product_name);
/* /*
* Allocate string descriptor numbers ... note that string * Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue. * contents can be overridden by the composite_dev glue.
*/ */
status = usb_string_ids_tab(cdev, strings_dev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto fail1; goto fail_string_ids;
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
/* register our configuration */ /* register our configuration */
status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
if (status < 0) if (status < 0)
goto fail1; goto fail_string_ids;
usb_composite_overwrite_options(cdev, &coverwrite); usb_composite_overwrite_options(cdev, &coverwrite);
dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
DRIVER_DESC); DRIVER_DESC);
fsg_common_put(&fsg_common);
return 0; return 0;
/* error recovery */ /* error recovery */
fail1: fail_string_ids:
fsg_common_put(&fsg_common); fsg_common_remove_luns(opts->common);
fail_set_cdev:
fsg_common_free_luns(opts->common);
fail_set_nluns:
fsg_common_free_buffers(opts->common);
fail:
usb_put_function_instance(fi_msg);
fail_get_msg:
usb_put_function_instance(f_acm_inst);
return status; return status;
} }
static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
{ {
usb_put_function(f_msg);
usb_put_function_instance(fi_msg);
usb_put_function(f_acm); usb_put_function(f_acm);
usb_put_function_instance(f_acm_inst); usb_put_function_instance(f_acm_inst);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment