2013-08-16 15:28:04

by Matt Porter

[permalink] [raw]
Subject: [PATCH 0/2] g_ffs CDC ACM support

This series fixes a build warning from USB Ethernet module parameters
in g_ffs and adds an additional configuration for CDC ACM + FunctionFS.

Matt Porter (2):
usb: gadget: ffs: fix eth module parameters warning in pure-only
config
usb: gadget: ffs: add ACM + FunctionFS configuration

drivers/usb/gadget/Kconfig | 9 ++++++
drivers/usb/gadget/g_ffs.c | 74 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 81 insertions(+), 2 deletions(-)

--
1.7.9.5


2013-08-16 15:28:40

by Matt Porter

[permalink] [raw]
Subject: [PATCH 2/2] usb: gadget: ffs: add ACM + FunctionFS configuration

Adds an additional configuration to g_ffs to allow for
CDC ACM support in conjuction with FunctionFS. A module
parameter is added to allow for multiple ACM ports to
be instantiated.

Signed-off-by: Matt Porter <[email protected]>
---
drivers/usb/gadget/Kconfig | 9 ++++++
drivers/usb/gadget/g_ffs.c | 71 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 1292a82..fa3c845 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -882,6 +882,15 @@ config USB_FUNCTIONFS_RNDIS
help
Include a configuration with RNDIS function (Ethernet) and the Filesystem.

+config USB_FUNCTIONFS_ACM
+ bool "Include configuration with CDC ACM (Serial)"
+ depends on USB_FUNCTIONFS
+ select USB_U_SERIAL
+ select USB_F_ACM
+ help
+ Include a configuration with CDC ACM function (Serial) and the
+ Function Filesystem.
+
config USB_FUNCTIONFS_GENERIC
bool "Include 'pure' configuration"
depends on USB_FUNCTIONFS
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 686b776..0849d3c 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -53,6 +53,14 @@ USB_ETHERNET_MODULE_PARAMETERS();
struct eth_dev;
#endif

+static int acm_ports = 1;
+#ifdef CONFIG_USB_FUNCTIONFS_ACM
+# include "u_serial.h"
+static int acm_bind_config(struct usb_configuration *c, int ports);
+module_param(acm_ports, int, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(acm_ports, "Number of ACM serial ports to instantiate");
+#endif
+
#include "f_fs.c"

#define DRIVER_NAME "g_ffs"
@@ -127,6 +135,9 @@ static struct usb_string gfs_strings[] = {
#ifdef CONFIG_USB_FUNCTIONFS_ETH
{ .s = "FunctionFS + ECM" },
#endif
+#ifdef CONFIG_USB_FUNCTIONFS_ACM
+ { .s = "FunctionFS + ACM" },
+#endif
#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
{ .s = "FunctionFS" },
#endif
@@ -145,6 +156,7 @@ struct gfs_configuration {
struct usb_configuration c;
int (*eth)(struct usb_configuration *c, u8 *ethaddr,
struct eth_dev *dev);
+ int (*acm)(struct usb_configuration *c, int ports);
} gfs_configurations[] = {
#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
{
@@ -158,6 +170,12 @@ struct gfs_configuration {
},
#endif

+#ifdef CONFIG_USB_FUNCTIONFS_ACM
+ {
+ .acm = acm_bind_config,
+ },
+#endif
+
#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
{
},
@@ -456,6 +474,12 @@ static int gfs_do_config(struct usb_configuration *c)
return ret;
}

+ if (gc->acm) {
+ ret = gc->acm(c, acm_ports);
+ if (unlikely(ret < 0))
+ return ret;
+ }
+
for (i = 0; i < func_num; i++) {
ret = functionfs_bind_config(c->cdev, c, ffs_tab[i].ffs_data);
if (unlikely(ret < 0))
@@ -489,3 +513,50 @@ static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
}

#endif
+
+#ifdef CONFIG_USB_FUNCTIONFS_ACM
+
+static struct usb_function_instance *fi[MAX_U_SERIAL_PORTS];
+static struct usb_function *f[MAX_U_SERIAL_PORTS];
+
+static int acm_bind_config(struct usb_configuration *c, int ports)
+{
+ int i, ret;
+
+ for (i = 0; i < ports; i++) {
+ fi[i] = usb_get_function_instance("acm");
+ if (IS_ERR(fi[i])) {
+ ret = PTR_ERR(fi[i]);
+ goto err_get_fi;
+ }
+
+ f[i] = usb_get_function(fi[i]);
+ if (IS_ERR(f[i])) {
+ ret = PTR_ERR(f[i]);
+ goto err_get_f;
+ }
+
+ ret = usb_add_function(c, f[i]);
+ if (ret)
+ goto err_add_f;
+ }
+
+ return 0;
+
+err_add_f:
+ usb_put_function(f[i]);
+err_get_f:
+ usb_put_function_instance(fi[i]);
+err_get_fi:
+ i--;
+ while (i >= 0) {
+ usb_remove_function(c, f[i]);
+ usb_put_function(f[i]);
+ usb_put_function_instance(fi[i]);
+ i--;
+ }
+
+ return ret;
+}
+
+#endif
--
1.7.9.5

2013-08-16 15:28:36

by Matt Porter

[permalink] [raw]
Subject: [PATCH 1/2] usb: gadget: ffs: fix eth module parameters warning in pure-only config

Fixes the build warning spewed out by USB_ETHERNET_MODULE_PARAMETERS()
which was unconditionally included even when ethernet configs are
disabled.

Signed-off-by: Matt Porter <[email protected]>
---
drivers/usb/gadget/g_ffs.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 5327c82..686b776 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -45,6 +45,7 @@ static struct eth_dev *the_dev;
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev);
# endif
+USB_ETHERNET_MODULE_PARAMETERS();
#else
# define the_dev NULL
# define gether_cleanup(dev) do { } while (0)
@@ -76,8 +77,6 @@ struct gfs_ffs_obj {

USB_GADGET_COMPOSITE_OPTIONS();

-USB_ETHERNET_MODULE_PARAMETERS();
-
static struct usb_device_descriptor gfs_dev_desc = {
.bLength = sizeof gfs_dev_desc,
.bDescriptorType = USB_DT_DEVICE,
--
1.7.9.5

2013-08-16 15:32:56

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH 2/2] usb: gadget: ffs: add ACM + FunctionFS configuration

On Fri, Aug 16, 2013 at 11:27:48AM -0400, Matt Porter wrote:
> Adds an additional configuration to g_ffs to allow for
> CDC ACM support in conjuction with FunctionFS. A module
> parameter is added to allow for multiple ACM ports to
> be instantiated.
>
> Signed-off-by: Matt Porter <[email protected]>

the whole idea of the configfs interface was that we wouldn't add this
sort of patch to the kernel anymore. What's wrong with building your
device through configfs in userland ?

--
balbi


Attachments:
(No filename) (498.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-08-16 15:48:40

by Matt Porter

[permalink] [raw]
Subject: Re: [PATCH 2/2] usb: gadget: ffs: add ACM + FunctionFS configuration

On 08/16/2013 11:32 AM, Felipe Balbi wrote:
> On Fri, Aug 16, 2013 at 11:27:48AM -0400, Matt Porter wrote:
>> Adds an additional configuration to g_ffs to allow for
>> CDC ACM support in conjuction with FunctionFS. A module
>> parameter is added to allow for multiple ACM ports to
>> be instantiated.
>>
>> Signed-off-by: Matt Porter <[email protected]>
>
> the whole idea of the configfs interface was that we wouldn't add this
> sort of patch to the kernel anymore. What's wrong with building your
> device through configfs in userland ?
>

That would be nice. Unless I missed it, we don't have support for ffs
via the gadget configfs framework. That's what drove this as I wanted
ACM + a ffs driven function. I'll look into adding an ffs option.

Thanks,
Matt