aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/nokia.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/nokia.c')
-rw-r--r--drivers/usb/gadget/nokia.c95
1 files changed, 62 insertions, 33 deletions
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index def37403989a..3b344b41a167 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -37,11 +37,9 @@
37 * the runtime footprint, and giving us at least some parts of what 37 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
39 */ 39 */
40#define USB_FACM_INCLUDED 40#define USBF_OBEX_INCLUDED
41#include "f_acm.c"
42#include "f_ecm.c" 41#include "f_ecm.c"
43#include "f_obex.c" 42#include "f_obex.c"
44#include "f_serial.c"
45#include "f_phonet.c" 43#include "f_phonet.c"
46#include "u_ether.c" 44#include "u_ether.c"
47 45
@@ -98,20 +96,40 @@ MODULE_AUTHOR("Felipe Balbi");
98MODULE_LICENSE("GPL"); 96MODULE_LICENSE("GPL");
99 97
100/*-------------------------------------------------------------------------*/ 98/*-------------------------------------------------------------------------*/
101 99static struct usb_function *f_acm_cfg1;
100static struct usb_function *f_acm_cfg2;
102static u8 hostaddr[ETH_ALEN]; 101static u8 hostaddr[ETH_ALEN];
102static struct eth_dev *the_dev;
103 103
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
111static unsigned char tty_lines[TTY_PORTS_MAX]; 110static unsigned char tty_lines[TTY_PORTS_MAX];
112 111
112static struct usb_configuration nokia_config_500ma_driver = {
113 .label = "Bus Powered",
114 .bConfigurationValue = 1,
115 /* .iConfiguration = DYNAMIC */
116 .bmAttributes = USB_CONFIG_ATT_ONE,
117 .MaxPower = 500,
118};
119
120static struct usb_configuration nokia_config_100ma_driver = {
121 .label = "Self Powered",
122 .bConfigurationValue = 2,
123 /* .iConfiguration = DYNAMIC */
124 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
125 .MaxPower = 100,
126};
127
128static struct usb_function_instance *fi_acm;
129
113static int __init nokia_bind_config(struct usb_configuration *c) 130static int __init nokia_bind_config(struct usb_configuration *c)
114{ 131{
132 struct usb_function *f_acm;
115 int status = 0; 133 int status = 0;
116 134
117 status = phonet_bind_config(c); 135 status = phonet_bind_config(c);
@@ -126,33 +144,32 @@ static int __init nokia_bind_config(struct usb_configuration *c)
126 if (status) 144 if (status)
127 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 145 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
128 146
129 status = acm_bind_config(c, tty_lines[TTY_PORT_ACM]); 147 f_acm = usb_get_function(fi_acm);
130 if (status) 148 if (IS_ERR(f_acm))
131 printk(KERN_DEBUG "could not bind acm config\n"); 149 return PTR_ERR(f_acm);
132 150
133 status = ecm_bind_config(c, hostaddr); 151 status = usb_add_function(c, f_acm);
134 if (status) 152 if (status)
135 printk(KERN_DEBUG "could not bind ecm config\n"); 153 goto err_conf;
154
155 status = ecm_bind_config(c, hostaddr, the_dev);
156 if (status) {
157 pr_debug("could not bind ecm config %d\n", status);
158 goto err_ecm;
159 }
160 if (c == &nokia_config_500ma_driver)
161 f_acm_cfg1 = f_acm;
162 else
163 f_acm_cfg2 = f_acm;
136 164
137 return status; 165 return status;
166err_ecm:
167 usb_remove_function(c, f_acm);
168err_conf:
169 usb_put_function(f_acm);
170 return status;
138} 171}
139 172
140static struct usb_configuration nokia_config_500ma_driver = {
141 .label = "Bus Powered",
142 .bConfigurationValue = 1,
143 /* .iConfiguration = DYNAMIC */
144 .bmAttributes = USB_CONFIG_ATT_ONE,
145 .MaxPower = 500,
146};
147
148static struct usb_configuration nokia_config_100ma_driver = {
149 .label = "Self Powered",
150 .bConfigurationValue = 2,
151 /* .iConfiguration = DYNAMIC */
152 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
153 .MaxPower = 100,
154};
155
156static int __init nokia_bind(struct usb_composite_dev *cdev) 173static int __init nokia_bind(struct usb_composite_dev *cdev)
157{ 174{
158 struct usb_gadget *gadget = cdev->gadget; 175 struct usb_gadget *gadget = cdev->gadget;
@@ -169,9 +186,11 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
169 goto err_ether; 186 goto err_ether;
170 } 187 }
171 188
172 status = gether_setup(cdev->gadget, hostaddr); 189 the_dev = gether_setup(cdev->gadget, hostaddr);
173 if (status < 0) 190 if (IS_ERR(the_dev)) {
191 status = PTR_ERR(the_dev);
174 goto err_ether; 192 goto err_ether;
193 }
175 194
176 status = usb_string_ids_tab(cdev, strings_dev); 195 status = usb_string_ids_tab(cdev, strings_dev);
177 if (status < 0) 196 if (status < 0)
@@ -185,24 +204,32 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
185 if (!gadget_supports_altsettings(gadget)) 204 if (!gadget_supports_altsettings(gadget))
186 goto err_usb; 205 goto err_usb;
187 206
207 fi_acm = usb_get_function_instance("acm");
208 if (IS_ERR(fi_acm))
209 goto err_usb;
210
188 /* finally register the configuration */ 211 /* finally register the configuration */
189 status = usb_add_config(cdev, &nokia_config_500ma_driver, 212 status = usb_add_config(cdev, &nokia_config_500ma_driver,
190 nokia_bind_config); 213 nokia_bind_config);
191 if (status < 0) 214 if (status < 0)
192 goto err_usb; 215 goto err_acm_inst;
193 216
194 status = usb_add_config(cdev, &nokia_config_100ma_driver, 217 status = usb_add_config(cdev, &nokia_config_100ma_driver,
195 nokia_bind_config); 218 nokia_bind_config);
196 if (status < 0) 219 if (status < 0)
197 goto err_usb; 220 goto err_put_cfg1;
198 221
199 usb_composite_overwrite_options(cdev, &coverwrite); 222 usb_composite_overwrite_options(cdev, &coverwrite);
200 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); 223 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
201 224
202 return 0; 225 return 0;
203 226
227err_put_cfg1:
228 usb_put_function(f_acm_cfg1);
229err_acm_inst:
230 usb_put_function_instance(fi_acm);
204err_usb: 231err_usb:
205 gether_cleanup(); 232 gether_cleanup(the_dev);
206err_ether: 233err_ether:
207 cur_line--; 234 cur_line--;
208 while (cur_line >= 0) 235 while (cur_line >= 0)
@@ -217,12 +244,15 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev)
217{ 244{
218 int i; 245 int i;
219 246
247 usb_put_function(f_acm_cfg1);
248 usb_put_function(f_acm_cfg2);
249 usb_put_function_instance(fi_acm);
220 gphonet_cleanup(); 250 gphonet_cleanup();
221 251
222 for (i = 0; i < TTY_PORTS_MAX; i++) 252 for (i = 0; i < TTY_PORTS_MAX; i++)
223 gserial_free_line(tty_lines[i]); 253 gserial_free_line(tty_lines[i]);
224 254
225 gether_cleanup(); 255 gether_cleanup(the_dev);
226 256
227 return 0; 257 return 0;
228} 258}
@@ -247,4 +277,3 @@ static void __exit nokia_cleanup(void)
247 usb_composite_unregister(&nokia_driver); 277 usb_composite_unregister(&nokia_driver);
248} 278}
249module_exit(nokia_cleanup); 279module_exit(nokia_cleanup);
250