From patchwork Fri Aug 16 15:27:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Porter X-Patchwork-Id: 19244 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f71.google.com (mail-vb0-f71.google.com [209.85.212.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E454425E5D for ; Fri, 16 Aug 2013 15:28:03 +0000 (UTC) Received: by mail-vb0-f71.google.com with SMTP id g17sf2351586vbg.6 for ; Fri, 16 Aug 2013 08:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:delivered-to:sender:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=5G4Nk9yhIkxWw11+PkquD7VdFoVaMJ/z3A4L4KO94Lk=; b=0WNb3KwXC8rTJ1QL2syjpaXf6xh0pDbnFsmwC9xb1i2xd1+PgebizVvyRDw35KRnxA UmueVLD+sY4/MNB7fLC7/sBmtiMm85+YMOhlk4MofyFBIgro4S4a+tdlPgqj4+1NjaT7 VW5FASWxagGiXD3ipadhoa0/Kyf7juEuCJs/tbADPEZM7yijt3ar8H7SpSADS93YU2vS ggbsioeWLuBNUkKvA3FCVo+a5eRQ42Xuu3KzlnMfsFu87G0IhyUitZ3Pxx+IzKO+mgGO +3uOqPRBJCcsc7Ll6jowdtrIWXyyZ7l4v2/snCkczjlVcRcigzLZw0/NyFhX9h48ykz4 RaZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:sender:from:to:cc :subject:date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=5G4Nk9yhIkxWw11+PkquD7VdFoVaMJ/z3A4L4KO94Lk=; b=VyKoGBcaXt1CR7/LV3DJwm6rN2/UatHsdOxkZitJ8G0/zynzVBv5Php7BIQtmDxnvE MGEqDQHVmmd0Phz144zBn0RdlqBtHS8S5VeNEIf1woZ+MeC0HMdIfQZljiPzPmwK7fXl atY7BSdK2VOYp/Mtoy5qBm8aLH8VfCYgBzeVIQlVh7GrleVbhEqjwuuw5NcxOlFYUNfB MyZwWX2opC8SdlwtJTtsBUzVHNENREkbduvmJdSyvjNWEcpCZdcoT16R/7rxYLpf1/QF ncC2RicD/ALpEs7vvd+wStyoNoACIjbCbE5h8wlAugj/OId4yj8qOcsXOMKIHK3OUBZm 0K0A== X-Received: by 10.236.193.6 with SMTP id j6mr622094yhn.44.1376666883575; Fri, 16 Aug 2013 08:28:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.101.44 with SMTP id fd12ls769039qeb.98.gmail; Fri, 16 Aug 2013 08:28:03 -0700 (PDT) X-Received: by 10.220.88.13 with SMTP id y13mr1772362vcl.20.1376666883428; Fri, 16 Aug 2013 08:28:03 -0700 (PDT) Received: from mail-vb0-x232.google.com (mail-vb0-x232.google.com [2607:f8b0:400c:c02::232]) by mx.google.com with ESMTPS id aj7si428302vec.135.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Aug 2013 08:28:03 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::232 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::232; Received: by mail-vb0-f50.google.com with SMTP id x14so1687437vbb.23 for ; Fri, 16 Aug 2013 08:28:03 -0700 (PDT) X-Gm-Message-State: ALoCoQkD7ySm7u8uc/bPBTTYHFU/aVKX++P8OUGhUpPCNzLEAIJMTAnPEdLGtiLLg5o2AkAL/z1p X-Received: by 10.220.10.194 with SMTP id q2mr1737968vcq.2.1376666883314; Fri, 16 Aug 2013 08:28:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp74618vcz; Fri, 16 Aug 2013 08:28:02 -0700 (PDT) X-Received: by 10.60.178.164 with SMTP id cz4mr84108oec.87.1376666882549; Fri, 16 Aug 2013 08:28:02 -0700 (PDT) Received: from mail-ie0-x22b.google.com (mail-ie0-x22b.google.com [2607:f8b0:4001:c03::22b]) by mx.google.com with ESMTPS id qq3si1135661oeb.106.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Aug 2013 08:28:02 -0700 (PDT) Received-SPF: pass (google.com: domain of ohiomdp@gmail.com designates 2607:f8b0:4001:c03::22b as permitted sender) client-ip=2607:f8b0:4001:c03::22b; Received: by mail-ie0-f171.google.com with SMTP id 10so3647530ied.16 for ; Fri, 16 Aug 2013 08:28:02 -0700 (PDT) X-Received: by 10.42.250.148 with SMTP id mo20mr1103336icb.34.1376666882057; Fri, 16 Aug 2013 08:28:02 -0700 (PDT) Received: from beef.ohporter.com (cpe-98-27-254-98.neo.res.rr.com. [98.27.254.98]) by mx.google.com with ESMTPSA id ri1sm2161650igc.2.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Aug 2013 08:28:01 -0700 (PDT) Sender: Matt Porter From: Matt Porter To: Felipe Balbi Cc: Greg Kroah-Hartman , Linux USB List , Linux Kernel Mailing List , Linaro Patches Subject: [PATCH 2/2] usb: gadget: ffs: add ACM + FunctionFS configuration Date: Fri, 16 Aug 2013 11:27:48 -0400 Message-Id: <1376666868-32581-3-git-send-email-matt.porter@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1376666868-32581-1-git-send-email-matt.porter@linaro.org> References: <1376666868-32581-1-git-send-email-matt.porter@linaro.org> X-Original-Sender: matt.porter@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::232 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gmail.com Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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