Commit 1bcce939 authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Felipe Balbi

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

Convert the legacy multi gadget to the new 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 4d1a8f68
...@@ -1038,6 +1038,7 @@ config USB_G_MULTI ...@@ -1038,6 +1038,7 @@ config USB_G_MULTI
select USB_U_ETHER select USB_U_ETHER
select USB_F_ACM select USB_F_ACM
select USB_U_MS select USB_U_MS
select USB_F_MASS_STORAGE
help help
The Multifunction Composite Gadget provides Ethernet (RNDIS The Multifunction Composite Gadget provides Ethernet (RNDIS
and/or CDC Ethernet), mass storage and ACM serial link and/or CDC Ethernet), mass storage and ACM serial link
......
...@@ -33,17 +33,7 @@ MODULE_AUTHOR("Michal Nazarewicz"); ...@@ -33,17 +33,7 @@ MODULE_AUTHOR("Michal Nazarewicz");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/***************************** All the files... *****************************/ #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"
#include "u_ecm.h" #include "u_ecm.h"
#ifdef USB_ETH_RNDIS #ifdef USB_ETH_RNDIS
...@@ -148,9 +138,8 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; ...@@ -148,9 +138,8 @@ 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_instance *fi_acm; static struct usb_function_instance *fi_acm;
static struct usb_function_instance *fi_msg;
/********** RNDIS **********/ /********** RNDIS **********/
...@@ -158,9 +147,11 @@ static struct usb_function_instance *fi_acm; ...@@ -158,9 +147,11 @@ static struct usb_function_instance *fi_acm;
static struct usb_function_instance *fi_rndis; static struct usb_function_instance *fi_rndis;
static struct usb_function *f_acm_rndis; static struct usb_function *f_acm_rndis;
static struct usb_function *f_rndis; static struct usb_function *f_rndis;
static struct usb_function *f_msg_rndis;
static __init int rndis_do_config(struct usb_configuration *c) static __init int rndis_do_config(struct usb_configuration *c)
{ {
struct fsg_opts *fsg_opts;
int ret; int ret;
if (gadget_is_otg(c->cdev->gadget)) { if (gadget_is_otg(c->cdev->gadget)) {
...@@ -186,11 +177,24 @@ static __init int rndis_do_config(struct usb_configuration *c) ...@@ -186,11 +177,24 @@ static __init int rndis_do_config(struct usb_configuration *c)
if (ret) if (ret)
goto err_conf; goto err_conf;
ret = fsg_bind_config(c->cdev, c, &fsg_common); f_msg_rndis = usb_get_function(fi_msg);
if (ret < 0) if (IS_ERR(f_msg_rndis)) {
ret = PTR_ERR(f_msg_rndis);
goto err_fsg; goto err_fsg;
}
fsg_opts = fsg_opts_from_func_inst(fi_msg);
ret = fsg_common_run_thread(fsg_opts->common);
if (ret)
goto err_run;
ret = usb_add_function(c, f_msg_rndis);
if (ret)
goto err_run;
return 0; return 0;
err_run:
usb_put_function(f_msg_rndis);
err_fsg: err_fsg:
usb_remove_function(c, f_acm_rndis); usb_remove_function(c, f_acm_rndis);
err_conf: err_conf:
...@@ -231,9 +235,11 @@ static __ref int rndis_config_register(struct usb_composite_dev *cdev) ...@@ -231,9 +235,11 @@ static __ref int rndis_config_register(struct usb_composite_dev *cdev)
static struct usb_function_instance *fi_ecm; static struct usb_function_instance *fi_ecm;
static struct usb_function *f_acm_multi; static struct usb_function *f_acm_multi;
static struct usb_function *f_ecm; static struct usb_function *f_ecm;
static struct usb_function *f_msg_multi;
static __init int cdc_do_config(struct usb_configuration *c) static __init int cdc_do_config(struct usb_configuration *c)
{ {
struct fsg_opts *fsg_opts;
int ret; int ret;
if (gadget_is_otg(c->cdev->gadget)) { if (gadget_is_otg(c->cdev->gadget)) {
...@@ -260,11 +266,24 @@ static __init int cdc_do_config(struct usb_configuration *c) ...@@ -260,11 +266,24 @@ static __init int cdc_do_config(struct usb_configuration *c)
if (ret) if (ret)
goto err_conf; goto err_conf;
ret = fsg_bind_config(c->cdev, c, &fsg_common); f_msg_multi = usb_get_function(fi_msg);
if (ret < 0) if (IS_ERR(f_msg_multi)) {
ret = PTR_ERR(f_msg_multi);
goto err_fsg; goto err_fsg;
}
fsg_opts = fsg_opts_from_func_inst(fi_msg);
ret = fsg_common_run_thread(fsg_opts->common);
if (ret)
goto err_run;
ret = usb_add_function(c, f_msg_multi);
if (ret)
goto err_run;
return 0; return 0;
err_run:
usb_put_function(f_msg_multi);
err_fsg: err_fsg:
usb_remove_function(c, f_acm_multi); usb_remove_function(c, f_acm_multi);
err_conf: err_conf:
...@@ -311,6 +330,8 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -311,6 +330,8 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
#ifdef USB_ETH_RNDIS #ifdef USB_ETH_RNDIS
struct f_rndis_opts *rndis_opts; struct f_rndis_opts *rndis_opts;
#endif #endif
struct fsg_opts *fsg_opts;
struct fsg_config config;
int status; int status;
if (!can_support_ecm(cdev->gadget)) { if (!can_support_ecm(cdev->gadget)) {
...@@ -373,41 +394,65 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -373,41 +394,65 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
} }
/* set up mass storage function */ /* set up mass storage function */
{ fi_msg = usb_get_function_instance("mass_storage");
void *retp; if (IS_ERR(fi_msg)) {
retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data, status = PTR_ERR(fi_msg);
fsg_num_buffers); goto fail1;
if (IS_ERR(retp)) {
status = PTR_ERR(retp);
goto fail1;
}
} }
fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
fsg_opts = fsg_opts_from_func_inst(fi_msg);
fsg_opts->no_configfs = true;
status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers);
if (status)
goto fail2;
status = fsg_common_set_nluns(fsg_opts->common, config.nluns);
if (status)
goto fail_set_nluns;
status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall);
if (status)
goto fail_set_cdev;
fsg_common_set_sysfs(fsg_opts->common, true);
status = fsg_common_create_luns(fsg_opts->common, &config);
if (status)
goto fail_set_cdev;
fsg_common_set_inquiry_string(fsg_opts->common, config.vendor_name,
config.product_name);
/* allocate string IDs */ /* allocate string IDs */
status = usb_string_ids_tab(cdev, strings_dev); status = usb_string_ids_tab(cdev, strings_dev);
if (unlikely(status < 0)) if (unlikely(status < 0))
goto fail2; goto fail_string_ids;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
/* register configurations */ /* register configurations */
status = rndis_config_register(cdev); status = rndis_config_register(cdev);
if (unlikely(status < 0)) if (unlikely(status < 0))
goto fail2; goto fail_string_ids;
status = cdc_config_register(cdev); status = cdc_config_register(cdev);
if (unlikely(status < 0)) if (unlikely(status < 0))
goto fail2; goto fail_string_ids;
usb_composite_overwrite_options(cdev, &coverwrite); usb_composite_overwrite_options(cdev, &coverwrite);
/* we're done */ /* we're done */
dev_info(&gadget->dev, DRIVER_DESC "\n"); dev_info(&gadget->dev, DRIVER_DESC "\n");
fsg_common_put(&fsg_common);
return 0; return 0;
/* error recovery */ /* error recovery */
fail_string_ids:
fsg_common_remove_luns(fsg_opts->common);
fail_set_cdev:
fsg_common_free_luns(fsg_opts->common);
fail_set_nluns:
fsg_common_free_buffers(fsg_opts->common);
fail2: fail2:
fsg_common_put(&fsg_common); usb_put_function_instance(fi_msg);
fail1: fail1:
usb_put_function_instance(fi_acm); usb_put_function_instance(fi_acm);
fail0: fail0:
...@@ -423,6 +468,13 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -423,6 +468,13 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
static int __exit multi_unbind(struct usb_composite_dev *cdev) static int __exit multi_unbind(struct usb_composite_dev *cdev)
{ {
#ifdef CONFIG_USB_G_MULTI_CDC
usb_put_function(f_msg_multi);
#endif
#ifdef USB_ETH_RNDIS
usb_put_function(f_msg_rndis);
#endif
usb_put_function_instance(fi_msg);
#ifdef CONFIG_USB_G_MULTI_CDC #ifdef CONFIG_USB_G_MULTI_CDC
usb_put_function(f_acm_multi); usb_put_function(f_acm_multi);
#endif #endif
......
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