aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2013-05-23 04:51:08 -0400
committerFelipe Balbi <balbi@ti.com>2013-06-10 10:28:51 -0400
commit3a34344979617f1b0df2c4191778009dba4e5e50 (patch)
tree0f188facb84a89b7655019e03be7de5e8b357164
parent1af877c409985fdf8f4d3cf14e8d08fb1038a0a4 (diff)
usb: gadget: nokia: convert to new interface of f_obex
preparation to use configfs-based approach on g_nokia.ko Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r--drivers/usb/gadget/Kconfig1
-rw-r--r--drivers/usb/gadget/nokia.c122
2 files changed, 85 insertions, 38 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index fcc3bfb61935..277eb5d1ff93 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -857,6 +857,7 @@ config USB_G_NOKIA
857 select USB_U_SERIAL 857 select USB_U_SERIAL
858 select USB_U_ETHER 858 select USB_U_ETHER
859 select USB_F_ACM 859 select USB_F_ACM
860 select USB_F_OBEX
860 help 861 help
861 The Nokia composite gadget provides support for acm, obex 862 The Nokia composite gadget provides support for acm, obex
862 and phonet in only one composite gadget driver. 863 and phonet in only one composite gadget driver.
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 8e42c88b453b..a69e8bfb3ecb 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/module.h>
19#include <linux/device.h> 20#include <linux/device.h>
20 21
21#include "u_serial.h" 22#include "u_serial.h"
@@ -39,8 +40,6 @@
39 */ 40 */
40#define USBF_ECM_INCLUDED 41#define USBF_ECM_INCLUDED
41#include "f_ecm.c" 42#include "f_ecm.c"
42#define USBF_OBEX_INCLUDED
43#include "f_obex.c"
44#include "f_phonet.c" 43#include "f_phonet.c"
45#include "u_ether.h" 44#include "u_ether.h"
46 45
@@ -102,16 +101,12 @@ MODULE_LICENSE("GPL");
102static struct usb_function *f_acm_cfg1; 101static struct usb_function *f_acm_cfg1;
103static struct usb_function *f_acm_cfg2; 102static struct usb_function *f_acm_cfg2;
104static u8 host_mac[ETH_ALEN]; 103static u8 host_mac[ETH_ALEN];
104static struct usb_function *f_obex1_cfg1;
105static struct usb_function *f_obex2_cfg1;
106static struct usb_function *f_obex1_cfg2;
107static struct usb_function *f_obex2_cfg2;
105static struct eth_dev *the_dev; 108static struct eth_dev *the_dev;
106 109
107enum {
108 TTY_PORT_OBEX0,
109 TTY_PORT_OBEX1,
110 TTY_PORTS_MAX,
111};
112
113static unsigned char tty_lines[TTY_PORTS_MAX];
114
115static struct usb_configuration nokia_config_500ma_driver = { 110static struct usb_configuration nokia_config_500ma_driver = {
116 .label = "Bus Powered", 111 .label = "Bus Powered",
117 .bConfigurationValue = 1, 112 .bConfigurationValue = 1,
@@ -129,27 +124,51 @@ static struct usb_configuration nokia_config_100ma_driver = {
129}; 124};
130 125
131static struct usb_function_instance *fi_acm; 126static struct usb_function_instance *fi_acm;
127static struct usb_function_instance *fi_obex1;
128static struct usb_function_instance *fi_obex2;
132 129
133static int __init nokia_bind_config(struct usb_configuration *c) 130static int __init nokia_bind_config(struct usb_configuration *c)
134{ 131{
135 struct usb_function *f_acm; 132 struct usb_function *f_acm;
133 struct usb_function *f_obex1 = NULL;
134 struct usb_function *f_obex2 = NULL;
136 int status = 0; 135 int status = 0;
136 int obex1_stat = 0;
137 int obex2_stat = 0;
137 138
138 status = phonet_bind_config(c); 139 status = phonet_bind_config(c);
139 if (status) 140 if (status)
140 printk(KERN_DEBUG "could not bind phonet config\n"); 141 pr_debug("could not bind phonet config\n");
141 142
142 status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX0]); 143 if (!IS_ERR(fi_obex1)) {
143 if (status) 144 f_obex1 = usb_get_function(fi_obex1);
144 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 145 if (IS_ERR(f_obex1))
146 pr_debug("could not get obex function 0\n");
147 }
145 148
146 status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX1]); 149 if (!IS_ERR(fi_obex2)) {
147 if (status) 150 f_obex2 = usb_get_function(fi_obex2);
148 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 151 if (IS_ERR(f_obex2))
152 pr_debug("could not get obex function 1\n");
153 }
149 154
150 f_acm = usb_get_function(fi_acm); 155 f_acm = usb_get_function(fi_acm);
151 if (IS_ERR(f_acm)) 156 if (IS_ERR(f_acm)) {
152 return PTR_ERR(f_acm); 157 status = PTR_ERR(f_acm);
158 goto err_get_acm;
159 }
160
161 if (!IS_ERR_OR_NULL(f_obex1)) {
162 obex1_stat = usb_add_function(c, f_obex1);
163 if (obex1_stat)
164 pr_debug("could not add obex function 0\n");
165 }
166
167 if (!IS_ERR_OR_NULL(f_obex2)) {
168 obex2_stat = usb_add_function(c, f_obex2);
169 if (obex2_stat)
170 pr_debug("could not add obex function 1\n");
171 }
153 172
154 status = usb_add_function(c, f_acm); 173 status = usb_add_function(c, f_acm);
155 if (status) 174 if (status)
@@ -160,16 +179,30 @@ static int __init nokia_bind_config(struct usb_configuration *c)
160 pr_debug("could not bind ecm config %d\n", status); 179 pr_debug("could not bind ecm config %d\n", status);
161 goto err_ecm; 180 goto err_ecm;
162 } 181 }
163 if (c == &nokia_config_500ma_driver) 182 if (c == &nokia_config_500ma_driver) {
164 f_acm_cfg1 = f_acm; 183 f_acm_cfg1 = f_acm;
165 else 184 f_obex1_cfg1 = f_obex1;
185 f_obex2_cfg1 = f_obex2;
186 } else {
166 f_acm_cfg2 = f_acm; 187 f_acm_cfg2 = f_acm;
188 f_obex1_cfg2 = f_obex1;
189 f_obex2_cfg2 = f_obex2;
190 }
167 191
168 return status; 192 return status;
169err_ecm: 193err_ecm:
170 usb_remove_function(c, f_acm); 194 usb_remove_function(c, f_acm);
171err_conf: 195err_conf:
196 if (!obex2_stat)
197 usb_remove_function(c, f_obex2);
198 if (!obex1_stat)
199 usb_remove_function(c, f_obex1);
172 usb_put_function(f_acm); 200 usb_put_function(f_acm);
201err_get_acm:
202 if (!IS_ERR_OR_NULL(f_obex2))
203 usb_put_function(f_obex2);
204 if (!IS_ERR_OR_NULL(f_obex1))
205 usb_put_function(f_obex1);
173 return status; 206 return status;
174} 207}
175 208
@@ -177,18 +210,11 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
177{ 210{
178 struct usb_gadget *gadget = cdev->gadget; 211 struct usb_gadget *gadget = cdev->gadget;
179 int status; 212 int status;
180 int cur_line;
181 213
182 status = gphonet_setup(cdev->gadget); 214 status = gphonet_setup(cdev->gadget);
183 if (status < 0) 215 if (status < 0)
184 goto err_phonet; 216 goto err_phonet;
185 217
186 for (cur_line = 0; cur_line < TTY_PORTS_MAX; cur_line++) {
187 status = gserial_alloc_line(&tty_lines[cur_line]);
188 if (status)
189 goto err_ether;
190 }
191
192 the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, 218 the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac,
193 qmult); 219 qmult);
194 if (IS_ERR(the_dev)) { 220 if (IS_ERR(the_dev)) {
@@ -208,9 +234,17 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
208 if (!gadget_supports_altsettings(gadget)) 234 if (!gadget_supports_altsettings(gadget))
209 goto err_usb; 235 goto err_usb;
210 236
237 fi_obex1 = usb_get_function_instance("obex");
238 if (IS_ERR(fi_obex1))
239 pr_debug("could not find obex function 1\n");
240
241 fi_obex2 = usb_get_function_instance("obex");
242 if (IS_ERR(fi_obex2))
243 pr_debug("could not find obex function 2\n");
244
211 fi_acm = usb_get_function_instance("acm"); 245 fi_acm = usb_get_function_instance("acm");
212 if (IS_ERR(fi_acm)) 246 if (IS_ERR(fi_acm))
213 goto err_usb; 247 goto err_obex2_inst;
214 248
215 /* finally register the configuration */ 249 /* finally register the configuration */
216 status = usb_add_config(cdev, &nokia_config_500ma_driver, 250 status = usb_add_config(cdev, &nokia_config_500ma_driver,
@@ -230,15 +264,20 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
230 264
231err_put_cfg1: 265err_put_cfg1:
232 usb_put_function(f_acm_cfg1); 266 usb_put_function(f_acm_cfg1);
267 if (!IS_ERR_OR_NULL(f_obex1_cfg1))
268 usb_put_function(f_obex1_cfg1);
269 if (!IS_ERR_OR_NULL(f_obex2_cfg1))
270 usb_put_function(f_obex2_cfg1);
233err_acm_inst: 271err_acm_inst:
234 usb_put_function_instance(fi_acm); 272 usb_put_function_instance(fi_acm);
273err_obex2_inst:
274 if (!IS_ERR(fi_obex2))
275 usb_put_function_instance(fi_obex2);
276 if (!IS_ERR(fi_obex1))
277 usb_put_function_instance(fi_obex1);
235err_usb: 278err_usb:
236 gether_cleanup(the_dev); 279 gether_cleanup(the_dev);
237err_ether: 280err_ether:
238 cur_line--;
239 while (cur_line >= 0)
240 gserial_free_line(tty_lines[cur_line--]);
241
242 gphonet_cleanup(); 281 gphonet_cleanup();
243err_phonet: 282err_phonet:
244 return status; 283 return status;
@@ -246,16 +285,23 @@ err_phonet:
246 285
247static int __exit nokia_unbind(struct usb_composite_dev *cdev) 286static int __exit nokia_unbind(struct usb_composite_dev *cdev)
248{ 287{
249 int i; 288 if (!IS_ERR_OR_NULL(f_obex1_cfg2))
250 289 usb_put_function(f_obex1_cfg2);
290 if (!IS_ERR_OR_NULL(f_obex2_cfg2))
291 usb_put_function(f_obex2_cfg2);
292 if (!IS_ERR_OR_NULL(f_obex1_cfg1))
293 usb_put_function(f_obex1_cfg1);
294 if (!IS_ERR_OR_NULL(f_obex2_cfg1))
295 usb_put_function(f_obex2_cfg1);
251 usb_put_function(f_acm_cfg1); 296 usb_put_function(f_acm_cfg1);
252 usb_put_function(f_acm_cfg2); 297 usb_put_function(f_acm_cfg2);
298 if (!IS_ERR(fi_obex1))
299 usb_put_function_instance(fi_obex1);
300 if (!IS_ERR(fi_obex2))
301 usb_put_function_instance(fi_obex2);
253 usb_put_function_instance(fi_acm); 302 usb_put_function_instance(fi_acm);
254 gphonet_cleanup(); 303 gphonet_cleanup();
255 304
256 for (i = 0; i < TTY_PORTS_MAX; i++)
257 gserial_free_line(tty_lines[i]);
258
259 gether_cleanup(the_dev); 305 gether_cleanup(the_dev);
260 306
261 return 0; 307 return 0;