aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2012-12-23 15:10:18 -0500
committerFelipe Balbi <balbi@ti.com>2013-04-03 07:43:31 -0400
commitc4ed4ac198495895fd1620cba15184c3b2d399dc (patch)
tree4b6d1601559aed0d29f8348c7460828d1ec27d85 /drivers/usb/gadget
parentd6a0143985489e470a118605352f4b18df0ce142 (diff)
usb: gadget: push tty port allocation from gadget into f_acm
It possible to allocate the tty port number within the "instance" structure of the function and there is no need to expose this information within the gadget and therefore it is removed here. This patch converts only f_acm and all its users. The other gadgets will follow once the function is converted to the function interface. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/acm_ms.c15
-rw-r--r--drivers/usb/gadget/cdc2.c13
-rw-r--r--drivers/usb/gadget/f_acm.c7
-rw-r--r--drivers/usb/gadget/multi.c14
-rw-r--r--drivers/usb/gadget/nokia.c4
-rw-r--r--drivers/usb/gadget/serial.c20
6 files changed, 19 insertions, 54 deletions
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 8f2b0e391534..4b947bb50f62 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -109,7 +109,6 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
109static struct fsg_common fsg_common; 109static struct fsg_common fsg_common;
110 110
111/*-------------------------------------------------------------------------*/ 111/*-------------------------------------------------------------------------*/
112static unsigned char tty_line;
113static struct usb_function *f_acm; 112static struct usb_function *f_acm;
114static struct usb_function_instance *f_acm_inst; 113static struct usb_function_instance *f_acm_inst;
115/* 114/*
@@ -117,7 +116,6 @@ static struct usb_function_instance *f_acm_inst;
117 */ 116 */
118static int __init acm_ms_do_config(struct usb_configuration *c) 117static int __init acm_ms_do_config(struct usb_configuration *c)
119{ 118{
120 struct f_serial_opts *opts;
121 int status; 119 int status;
122 120
123 if (gadget_is_otg(c->cdev->gadget)) { 121 if (gadget_is_otg(c->cdev->gadget)) {
@@ -129,9 +127,6 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
129 if (IS_ERR(f_acm_inst)) 127 if (IS_ERR(f_acm_inst))
130 return PTR_ERR(f_acm_inst); 128 return PTR_ERR(f_acm_inst);
131 129
132 opts = container_of(f_acm_inst, struct f_serial_opts, func_inst);
133 opts->port_num = tty_line;
134
135 f_acm = usb_get_function(f_acm_inst); 130 f_acm = usb_get_function(f_acm_inst);
136 if (IS_ERR(f_acm)) { 131 if (IS_ERR(f_acm)) {
137 status = PTR_ERR(f_acm); 132 status = PTR_ERR(f_acm);
@@ -171,16 +166,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
171 int status; 166 int status;
172 void *retp; 167 void *retp;
173 168
174 /* set up serial link layer */
175 status = gserial_alloc_line(&tty_line);
176 if (status < 0)
177 return status;
178
179 /* set up mass storage function */ 169 /* set up mass storage function */
180 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 170 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
181 if (IS_ERR(retp)) { 171 if (IS_ERR(retp)) {
182 status = PTR_ERR(retp); 172 status = PTR_ERR(retp);
183 goto fail0; 173 return PTR_ERR(retp);
184 } 174 }
185 175
186 /* 176 /*
@@ -207,8 +197,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
207 /* error recovery */ 197 /* error recovery */
208fail1: 198fail1:
209 fsg_common_put(&fsg_common); 199 fsg_common_put(&fsg_common);
210fail0:
211 gserial_free_line(tty_line);
212 return status; 200 return status;
213} 201}
214 202
@@ -216,7 +204,6 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
216{ 204{
217 usb_put_function(f_acm); 205 usb_put_function(f_acm);
218 usb_put_function_instance(f_acm_inst); 206 usb_put_function_instance(f_acm_inst);
219 gserial_free_line(tty_line);
220 return 0; 207 return 0;
221} 208}
222 209
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 61023aae9865..c6ee6f1558c3 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -108,13 +108,11 @@ static struct eth_dev *the_dev;
108static struct usb_function *f_acm; 108static struct usb_function *f_acm;
109static struct usb_function_instance *fi_serial; 109static struct usb_function_instance *fi_serial;
110 110
111static unsigned char tty_line;
112/* 111/*
113 * We _always_ have both CDC ECM and CDC ACM functions. 112 * We _always_ have both CDC ECM and CDC ACM functions.
114 */ 113 */
115static int __init cdc_do_config(struct usb_configuration *c) 114static int __init cdc_do_config(struct usb_configuration *c)
116{ 115{
117 struct f_serial_opts *opts;
118 int status; 116 int status;
119 117
120 if (gadget_is_otg(c->cdev->gadget)) { 118 if (gadget_is_otg(c->cdev->gadget)) {
@@ -130,9 +128,6 @@ static int __init cdc_do_config(struct usb_configuration *c)
130 if (IS_ERR(fi_serial)) 128 if (IS_ERR(fi_serial))
131 return PTR_ERR(fi_serial); 129 return PTR_ERR(fi_serial);
132 130
133 opts = container_of(fi_serial, struct f_serial_opts, func_inst);
134 opts->port_num = tty_line;
135
136 f_acm = usb_get_function(fi_serial); 131 f_acm = usb_get_function(fi_serial);
137 if (IS_ERR(f_acm)) 132 if (IS_ERR(f_acm))
138 goto err_func_acm; 133 goto err_func_acm;
@@ -173,11 +168,6 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
173 if (IS_ERR(the_dev)) 168 if (IS_ERR(the_dev))
174 return PTR_ERR(the_dev); 169 return PTR_ERR(the_dev);
175 170
176 /* set up serial link layer */
177 status = gserial_alloc_line(&tty_line);
178 if (status < 0)
179 goto fail0;
180
181 /* Allocate string descriptor numbers ... note that string 171 /* Allocate string descriptor numbers ... note that string
182 * contents can be overridden by the composite_dev glue. 172 * contents can be overridden by the composite_dev glue.
183 */ 173 */
@@ -200,8 +190,6 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
200 return 0; 190 return 0;
201 191
202fail1: 192fail1:
203 gserial_free_line(tty_line);
204fail0:
205 gether_cleanup(the_dev); 193 gether_cleanup(the_dev);
206 return status; 194 return status;
207} 195}
@@ -210,7 +198,6 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
210{ 198{
211 usb_put_function(f_acm); 199 usb_put_function(f_acm);
212 usb_put_function_instance(fi_serial); 200 usb_put_function_instance(fi_serial);
213 gserial_free_line(tty_line);
214 gether_cleanup(the_dev); 201 gether_cleanup(the_dev);
215 return 0; 202 return 0;
216} 203}
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 61b33d23be72..ba7daaaad148 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -768,17 +768,24 @@ static void acm_free_instance(struct usb_function_instance *fi)
768 struct f_serial_opts *opts; 768 struct f_serial_opts *opts;
769 769
770 opts = container_of(fi, struct f_serial_opts, func_inst); 770 opts = container_of(fi, struct f_serial_opts, func_inst);
771 gserial_free_line(opts->port_num);
771 kfree(opts); 772 kfree(opts);
772} 773}
773 774
774static struct usb_function_instance *acm_alloc_instance(void) 775static struct usb_function_instance *acm_alloc_instance(void)
775{ 776{
776 struct f_serial_opts *opts; 777 struct f_serial_opts *opts;
778 int ret;
777 779
778 opts = kzalloc(sizeof(*opts), GFP_KERNEL); 780 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
779 if (!opts) 781 if (!opts)
780 return ERR_PTR(-ENOMEM); 782 return ERR_PTR(-ENOMEM);
781 opts->func_inst.free_func_inst = acm_free_instance; 783 opts->func_inst.free_func_inst = acm_free_instance;
784 ret = gserial_alloc_line(&opts->port_num);
785 if (ret) {
786 kfree(opts);
787 return ERR_PTR(ret);
788 }
782 return &opts->func_inst; 789 return &opts->func_inst;
783} 790}
784DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func); 791DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 34427553271e..a74ebefc7682 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -135,7 +135,6 @@ static struct fsg_common fsg_common;
135 135
136static u8 hostaddr[ETH_ALEN]; 136static u8 hostaddr[ETH_ALEN];
137 137
138static unsigned char tty_line;
139static struct usb_function_instance *fi_acm; 138static struct usb_function_instance *fi_acm;
140static struct eth_dev *the_dev; 139static struct eth_dev *the_dev;
141 140
@@ -270,7 +269,6 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
270static int __ref multi_bind(struct usb_composite_dev *cdev) 269static int __ref multi_bind(struct usb_composite_dev *cdev)
271{ 270{
272 struct usb_gadget *gadget = cdev->gadget; 271 struct usb_gadget *gadget = cdev->gadget;
273 struct f_serial_opts *opts;
274 int status; 272 int status;
275 273
276 if (!can_support_ecm(cdev->gadget)) { 274 if (!can_support_ecm(cdev->gadget)) {
@@ -285,19 +283,12 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
285 return PTR_ERR(the_dev); 283 return PTR_ERR(the_dev);
286 284
287 /* set up serial link layer */ 285 /* set up serial link layer */
288 status = gserial_alloc_line(&tty_line);
289 if (status < 0)
290 goto fail0;
291
292 fi_acm = usb_get_function_instance("acm"); 286 fi_acm = usb_get_function_instance("acm");
293 if (IS_ERR(fi_acm)) { 287 if (IS_ERR(fi_acm)) {
294 status = PTR_ERR(fi_acm); 288 status = PTR_ERR(fi_acm);
295 goto fail0dot5; 289 goto fail0;
296 } 290 }
297 291
298 opts = container_of(fi_acm, struct f_serial_opts, func_inst);
299 opts->port_num = tty_line;
300
301 /* set up mass storage function */ 292 /* set up mass storage function */
302 { 293 {
303 void *retp; 294 void *retp;
@@ -335,8 +326,6 @@ fail2:
335 fsg_common_put(&fsg_common); 326 fsg_common_put(&fsg_common);
336fail1: 327fail1:
337 usb_put_function_instance(fi_acm); 328 usb_put_function_instance(fi_acm);
338fail0dot5:
339 gserial_free_line(tty_line);
340fail0: 329fail0:
341 gether_cleanup(the_dev); 330 gether_cleanup(the_dev);
342 return status; 331 return status;
@@ -351,7 +340,6 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
351 usb_put_function(f_acm_rndis); 340 usb_put_function(f_acm_rndis);
352#endif 341#endif
353 usb_put_function_instance(fi_acm); 342 usb_put_function_instance(fi_acm);
354 gserial_free_line(tty_line);
355 gether_cleanup(the_dev); 343 gether_cleanup(the_dev);
356 return 0; 344 return 0;
357} 345}
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 0c13ddd78bef..b5fbf1a1cb3c 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -104,7 +104,6 @@ static struct eth_dev *the_dev;
104enum { 104enum {
105 TTY_PORT_OBEX0, 105 TTY_PORT_OBEX0,
106 TTY_PORT_OBEX1, 106 TTY_PORT_OBEX1,
107 TTY_PORT_ACM,
108 TTY_PORTS_MAX, 107 TTY_PORTS_MAX,
109}; 108};
110 109
@@ -174,7 +173,6 @@ err_conf:
174static int __init nokia_bind(struct usb_composite_dev *cdev) 173static int __init nokia_bind(struct usb_composite_dev *cdev)
175{ 174{
176 struct usb_gadget *gadget = cdev->gadget; 175 struct usb_gadget *gadget = cdev->gadget;
177 struct f_serial_opts *opts;
178 int status; 176 int status;
179 int cur_line; 177 int cur_line;
180 178
@@ -209,8 +207,6 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
209 fi_acm = usb_get_function_instance("acm"); 207 fi_acm = usb_get_function_instance("acm");
210 if (IS_ERR(fi_acm)) 208 if (IS_ERR(fi_acm))
211 goto err_usb; 209 goto err_usb;
212 opts = container_of(fi_acm, struct f_serial_opts, func_inst);
213 opts->port_num = tty_lines[TTY_PORT_ACM];
214 210
215 /* finally register the configuration */ 211 /* finally register the configuration */
216 status = usb_add_config(cdev, &nokia_config_500ma_driver, 212 status = usb_add_config(cdev, &nokia_config_500ma_driver,
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 68d7bb06ebcb..c48ca1eb5442 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -169,15 +169,12 @@ static int serial_register_ports(struct usb_composite_dev *cdev,
169 goto out; 169 goto out;
170 170
171 for (i = 0; i < n_ports; i++) { 171 for (i = 0; i < n_ports; i++) {
172 struct f_serial_opts *opts;
173 172
174 fi_serial[i] = usb_get_function_instance(f_name); 173 fi_serial[i] = usb_get_function_instance(f_name);
175 if (IS_ERR(fi_serial[i])) { 174 if (IS_ERR(fi_serial[i])) {
176 ret = PTR_ERR(fi_serial[i]); 175 ret = PTR_ERR(fi_serial[i]);
177 goto fail; 176 goto fail;
178 } 177 }
179 opts = container_of(fi_serial[i], struct f_serial_opts, func_inst);
180 opts->port_num = tty_lines[i];
181 178
182 f_serial[i] = usb_get_function(fi_serial[i]); 179 f_serial[i] = usb_get_function(fi_serial[i]);
183 if (IS_ERR(f_serial[i])) { 180 if (IS_ERR(f_serial[i])) {
@@ -212,12 +209,14 @@ out:
212static int __init gs_bind(struct usb_composite_dev *cdev) 209static int __init gs_bind(struct usb_composite_dev *cdev)
213{ 210{
214 int status; 211 int status;
215 int cur_line; 212 int cur_line = 0;
216 213
217 for (cur_line = 0; cur_line < n_ports; cur_line++) { 214 if (!use_acm) {
218 status = gserial_alloc_line(&tty_lines[cur_line]); 215 for (cur_line = 0; cur_line < n_ports; cur_line++) {
219 if (status) 216 status = gserial_alloc_line(&tty_lines[cur_line]);
220 goto fail; 217 if (status)
218 goto fail;
219 }
221 } 220 }
222 221
223 /* Allocate string descriptor numbers ... note that string 222 /* Allocate string descriptor numbers ... note that string
@@ -258,7 +257,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
258 257
259fail: 258fail:
260 cur_line--; 259 cur_line--;
261 while (cur_line >= 0) 260 while (cur_line >= 0 && !use_acm)
262 gserial_free_line(tty_lines[cur_line--]); 261 gserial_free_line(tty_lines[cur_line--]);
263 return status; 262 return status;
264} 263}
@@ -270,7 +269,8 @@ static int gs_unbind(struct usb_composite_dev *cdev)
270 for (i = 0; i < n_ports; i++) { 269 for (i = 0; i < n_ports; i++) {
271 usb_put_function(f_serial[i]); 270 usb_put_function(f_serial[i]);
272 usb_put_function_instance(fi_serial[i]); 271 usb_put_function_instance(fi_serial[i]);
273 gserial_free_line(tty_lines[i]); 272 if (!use_acm)
273 gserial_free_line(tty_lines[i]);
274 } 274 }
275 return 0; 275 return 0;
276} 276}