Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * nokia.c -- Nokia Composite Gadget Driver |
| 3 | * |
| 4 | * Copyright (C) 2008-2010 Nokia Corporation |
| 5 | * Contact: Felipe Balbi <felipe.balbi@nokia.com> |
| 6 | * |
| 7 | * This gadget driver borrows from serial.c which is: |
| 8 | * |
| 9 | * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com) |
| 10 | * Copyright (C) 2008 by David Brownell |
| 11 | * Copyright (C) 2008 by Nokia Corporation |
| 12 | * |
| 13 | * This software is distributed under the terms of the GNU General |
| 14 | * Public License ("GPL") as published by the Free Software Foundation, |
| 15 | * version 2 of that License. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 19 | #include <linux/module.h> |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 20 | #include <linux/device.h> |
| 21 | |
| 22 | #include "u_serial.h" |
| 23 | #include "u_ether.h" |
| 24 | #include "u_phonet.h" |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 25 | #include "u_ecm.h" |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 26 | #include "gadget_chips.h" |
| 27 | |
| 28 | /* Defines */ |
| 29 | |
| 30 | #define NOKIA_VERSION_NUM 0x0211 |
| 31 | #define NOKIA_LONG_NAME "N900 (PC-Suite Mode)" |
| 32 | |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 33 | USB_GADGET_COMPOSITE_OPTIONS(); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 34 | |
Andrzej Pietrasiewicz | f1a1823 | 2013-05-23 09:22:03 +0200 | [diff] [blame] | 35 | USB_ETHERNET_MODULE_PARAMETERS(); |
| 36 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 37 | #define NOKIA_VENDOR_ID 0x0421 /* Nokia */ |
| 38 | #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */ |
| 39 | |
| 40 | /* string IDs are assigned dynamically */ |
| 41 | |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 42 | #define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 43 | |
| 44 | static char manufacturer_nokia[] = "Nokia"; |
| 45 | static const char product_nokia[] = NOKIA_LONG_NAME; |
| 46 | static const char description_nokia[] = "PC-Suite Configuration"; |
| 47 | |
| 48 | static struct usb_string strings_dev[] = { |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 49 | [USB_GADGET_MANUFACTURER_IDX].s = manufacturer_nokia, |
| 50 | [USB_GADGET_PRODUCT_IDX].s = NOKIA_LONG_NAME, |
| 51 | [USB_GADGET_SERIAL_IDX].s = "", |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 52 | [STRING_DESCRIPTION_IDX].s = description_nokia, |
| 53 | { } /* end of list */ |
| 54 | }; |
| 55 | |
| 56 | static struct usb_gadget_strings stringtab_dev = { |
| 57 | .language = 0x0409, /* en-us */ |
| 58 | .strings = strings_dev, |
| 59 | }; |
| 60 | |
| 61 | static struct usb_gadget_strings *dev_strings[] = { |
| 62 | &stringtab_dev, |
| 63 | NULL, |
| 64 | }; |
| 65 | |
| 66 | static struct usb_device_descriptor device_desc = { |
| 67 | .bLength = USB_DT_DEVICE_SIZE, |
| 68 | .bDescriptorType = USB_DT_DEVICE, |
| 69 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
| 70 | .bDeviceClass = USB_CLASS_COMM, |
| 71 | .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID), |
| 72 | .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID), |
Sebastian Andrzej Siewior | ed9cbda | 2012-09-10 09:16:07 +0200 | [diff] [blame] | 73 | .bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM), |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 74 | /* .iManufacturer = DYNAMIC */ |
| 75 | /* .iProduct = DYNAMIC */ |
| 76 | .bNumConfigurations = 1, |
| 77 | }; |
| 78 | |
| 79 | /*-------------------------------------------------------------------------*/ |
| 80 | |
| 81 | /* Module */ |
| 82 | MODULE_DESCRIPTION("Nokia composite gadget driver for N900"); |
| 83 | MODULE_AUTHOR("Felipe Balbi"); |
| 84 | MODULE_LICENSE("GPL"); |
| 85 | |
| 86 | /*-------------------------------------------------------------------------*/ |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 87 | static struct usb_function *f_acm_cfg1; |
| 88 | static struct usb_function *f_acm_cfg2; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 89 | static struct usb_function *f_ecm_cfg1; |
| 90 | static struct usb_function *f_ecm_cfg2; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 91 | static struct usb_function *f_obex1_cfg1; |
| 92 | static struct usb_function *f_obex2_cfg1; |
| 93 | static struct usb_function *f_obex1_cfg2; |
| 94 | static struct usb_function *f_obex2_cfg2; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 95 | static struct usb_function *f_phonet_cfg1; |
| 96 | static struct usb_function *f_phonet_cfg2; |
Andrzej Pietrasiewicz | 0189e63 | 2013-05-23 10:51:10 +0200 | [diff] [blame] | 97 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 98 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 99 | static struct usb_configuration nokia_config_500ma_driver = { |
| 100 | .label = "Bus Powered", |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 101 | .bConfigurationValue = 1, |
| 102 | /* .iConfiguration = DYNAMIC */ |
| 103 | .bmAttributes = USB_CONFIG_ATT_ONE, |
Sebastian Andrzej Siewior | 8f900a9 | 2012-12-03 20:07:05 +0100 | [diff] [blame] | 104 | .MaxPower = 500, |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | static struct usb_configuration nokia_config_100ma_driver = { |
| 108 | .label = "Self Powered", |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 109 | .bConfigurationValue = 2, |
| 110 | /* .iConfiguration = DYNAMIC */ |
| 111 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, |
Sebastian Andrzej Siewior | 8f900a9 | 2012-12-03 20:07:05 +0100 | [diff] [blame] | 112 | .MaxPower = 100, |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 113 | }; |
| 114 | |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 115 | static struct usb_function_instance *fi_acm; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 116 | static struct usb_function_instance *fi_ecm; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 117 | static struct usb_function_instance *fi_obex1; |
| 118 | static struct usb_function_instance *fi_obex2; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 119 | static struct usb_function_instance *fi_phonet; |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 120 | |
| 121 | static int __init nokia_bind_config(struct usb_configuration *c) |
| 122 | { |
| 123 | struct usb_function *f_acm; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 124 | struct usb_function *f_phonet = NULL; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 125 | struct usb_function *f_obex1 = NULL; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 126 | struct usb_function *f_ecm; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 127 | struct usb_function *f_obex2 = NULL; |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 128 | int status = 0; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 129 | int obex1_stat = 0; |
| 130 | int obex2_stat = 0; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 131 | int phonet_stat = 0; |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 132 | |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 133 | if (!IS_ERR(fi_phonet)) { |
| 134 | f_phonet = usb_get_function(fi_phonet); |
| 135 | if (IS_ERR(f_phonet)) |
| 136 | pr_debug("could not get phonet function\n"); |
| 137 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 138 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 139 | if (!IS_ERR(fi_obex1)) { |
| 140 | f_obex1 = usb_get_function(fi_obex1); |
| 141 | if (IS_ERR(f_obex1)) |
| 142 | pr_debug("could not get obex function 0\n"); |
| 143 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 144 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 145 | if (!IS_ERR(fi_obex2)) { |
| 146 | f_obex2 = usb_get_function(fi_obex2); |
| 147 | if (IS_ERR(f_obex2)) |
| 148 | pr_debug("could not get obex function 1\n"); |
| 149 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 150 | |
| 151 | f_acm = usb_get_function(fi_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 152 | if (IS_ERR(f_acm)) { |
| 153 | status = PTR_ERR(f_acm); |
| 154 | goto err_get_acm; |
| 155 | } |
| 156 | |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 157 | f_ecm = usb_get_function(fi_ecm); |
| 158 | if (IS_ERR(f_ecm)) { |
| 159 | status = PTR_ERR(f_ecm); |
| 160 | goto err_get_ecm; |
| 161 | } |
| 162 | |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 163 | if (!IS_ERR_OR_NULL(f_phonet)) { |
| 164 | phonet_stat = usb_add_function(c, f_phonet); |
| 165 | if (phonet_stat) |
| 166 | pr_debug("could not add phonet function\n"); |
| 167 | } |
| 168 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 169 | if (!IS_ERR_OR_NULL(f_obex1)) { |
| 170 | obex1_stat = usb_add_function(c, f_obex1); |
| 171 | if (obex1_stat) |
| 172 | pr_debug("could not add obex function 0\n"); |
| 173 | } |
| 174 | |
| 175 | if (!IS_ERR_OR_NULL(f_obex2)) { |
| 176 | obex2_stat = usb_add_function(c, f_obex2); |
| 177 | if (obex2_stat) |
| 178 | pr_debug("could not add obex function 1\n"); |
| 179 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 180 | |
| 181 | status = usb_add_function(c, f_acm); |
| 182 | if (status) |
| 183 | goto err_conf; |
| 184 | |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 185 | status = usb_add_function(c, f_ecm); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 186 | if (status) { |
| 187 | pr_debug("could not bind ecm config %d\n", status); |
| 188 | goto err_ecm; |
| 189 | } |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 190 | if (c == &nokia_config_500ma_driver) { |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 191 | f_acm_cfg1 = f_acm; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 192 | f_ecm_cfg1 = f_ecm; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 193 | f_phonet_cfg1 = f_phonet; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 194 | f_obex1_cfg1 = f_obex1; |
| 195 | f_obex2_cfg1 = f_obex2; |
| 196 | } else { |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 197 | f_acm_cfg2 = f_acm; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 198 | f_ecm_cfg2 = f_ecm; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 199 | f_phonet_cfg2 = f_phonet; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 200 | f_obex1_cfg2 = f_obex1; |
| 201 | f_obex2_cfg2 = f_obex2; |
| 202 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 203 | |
| 204 | return status; |
| 205 | err_ecm: |
| 206 | usb_remove_function(c, f_acm); |
| 207 | err_conf: |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 208 | if (!obex2_stat) |
| 209 | usb_remove_function(c, f_obex2); |
| 210 | if (!obex1_stat) |
| 211 | usb_remove_function(c, f_obex1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 212 | if (!phonet_stat) |
| 213 | usb_remove_function(c, f_phonet); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 214 | usb_put_function(f_ecm); |
| 215 | err_get_ecm: |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 216 | usb_put_function(f_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 217 | err_get_acm: |
| 218 | if (!IS_ERR_OR_NULL(f_obex2)) |
| 219 | usb_put_function(f_obex2); |
| 220 | if (!IS_ERR_OR_NULL(f_obex1)) |
| 221 | usb_put_function(f_obex1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 222 | if (!IS_ERR_OR_NULL(f_phonet)) |
| 223 | usb_put_function(f_phonet); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 224 | return status; |
| 225 | } |
| 226 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 227 | static int __init nokia_bind(struct usb_composite_dev *cdev) |
| 228 | { |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 229 | struct usb_gadget *gadget = cdev->gadget; |
| 230 | int status; |
| 231 | |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 232 | status = usb_string_ids_tab(cdev, strings_dev); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 233 | if (status < 0) |
| 234 | goto err_usb; |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 235 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
| 236 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 237 | status = strings_dev[STRING_DESCRIPTION_IDX].id; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 238 | nokia_config_500ma_driver.iConfiguration = status; |
| 239 | nokia_config_100ma_driver.iConfiguration = status; |
| 240 | |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 241 | if (!gadget_supports_altsettings(gadget)) { |
| 242 | status = -ENODEV; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 243 | goto err_usb; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 244 | } |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 245 | |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 246 | fi_phonet = usb_get_function_instance("phonet"); |
| 247 | if (IS_ERR(fi_phonet)) |
| 248 | pr_debug("could not find phonet function\n"); |
| 249 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 250 | fi_obex1 = usb_get_function_instance("obex"); |
| 251 | if (IS_ERR(fi_obex1)) |
| 252 | pr_debug("could not find obex function 1\n"); |
| 253 | |
| 254 | fi_obex2 = usb_get_function_instance("obex"); |
| 255 | if (IS_ERR(fi_obex2)) |
| 256 | pr_debug("could not find obex function 2\n"); |
| 257 | |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 258 | fi_acm = usb_get_function_instance("acm"); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 259 | if (IS_ERR(fi_acm)) { |
| 260 | status = PTR_ERR(fi_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 261 | goto err_obex2_inst; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | fi_ecm = usb_get_function_instance("ecm"); |
| 265 | if (IS_ERR(fi_ecm)) { |
| 266 | status = PTR_ERR(fi_ecm); |
| 267 | goto err_acm_inst; |
| 268 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 269 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 270 | /* finally register the configuration */ |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 271 | status = usb_add_config(cdev, &nokia_config_500ma_driver, |
| 272 | nokia_bind_config); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 273 | if (status < 0) |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 274 | goto err_ecm_inst; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 275 | |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 276 | status = usb_add_config(cdev, &nokia_config_100ma_driver, |
| 277 | nokia_bind_config); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 278 | if (status < 0) |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 279 | goto err_put_cfg1; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 280 | |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 281 | usb_composite_overwrite_options(cdev, &coverwrite); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 282 | dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); |
| 283 | |
| 284 | return 0; |
| 285 | |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 286 | err_put_cfg1: |
| 287 | usb_put_function(f_acm_cfg1); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 288 | if (!IS_ERR_OR_NULL(f_obex1_cfg1)) |
| 289 | usb_put_function(f_obex1_cfg1); |
| 290 | if (!IS_ERR_OR_NULL(f_obex2_cfg1)) |
| 291 | usb_put_function(f_obex2_cfg1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 292 | if (!IS_ERR_OR_NULL(f_phonet_cfg1)) |
| 293 | usb_put_function(f_phonet_cfg1); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 294 | usb_put_function(f_ecm_cfg1); |
| 295 | err_ecm_inst: |
| 296 | usb_put_function_instance(fi_ecm); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 297 | err_acm_inst: |
| 298 | usb_put_function_instance(fi_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 299 | err_obex2_inst: |
| 300 | if (!IS_ERR(fi_obex2)) |
| 301 | usb_put_function_instance(fi_obex2); |
| 302 | if (!IS_ERR(fi_obex1)) |
| 303 | usb_put_function_instance(fi_obex1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 304 | if (!IS_ERR(fi_phonet)) |
| 305 | usb_put_function_instance(fi_phonet); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 306 | err_usb: |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 307 | return status; |
| 308 | } |
| 309 | |
| 310 | static int __exit nokia_unbind(struct usb_composite_dev *cdev) |
| 311 | { |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 312 | if (!IS_ERR_OR_NULL(f_obex1_cfg2)) |
| 313 | usb_put_function(f_obex1_cfg2); |
| 314 | if (!IS_ERR_OR_NULL(f_obex2_cfg2)) |
| 315 | usb_put_function(f_obex2_cfg2); |
| 316 | if (!IS_ERR_OR_NULL(f_obex1_cfg1)) |
| 317 | usb_put_function(f_obex1_cfg1); |
| 318 | if (!IS_ERR_OR_NULL(f_obex2_cfg1)) |
| 319 | usb_put_function(f_obex2_cfg1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 320 | if (!IS_ERR_OR_NULL(f_phonet_cfg1)) |
| 321 | usb_put_function(f_phonet_cfg1); |
| 322 | if (!IS_ERR_OR_NULL(f_phonet_cfg2)) |
| 323 | usb_put_function(f_phonet_cfg2); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 324 | usb_put_function(f_acm_cfg1); |
| 325 | usb_put_function(f_acm_cfg2); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 326 | usb_put_function(f_ecm_cfg1); |
| 327 | usb_put_function(f_ecm_cfg2); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 328 | |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 329 | usb_put_function_instance(fi_ecm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 330 | if (!IS_ERR(fi_obex2)) |
| 331 | usb_put_function_instance(fi_obex2); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 332 | if (!IS_ERR(fi_obex1)) |
| 333 | usb_put_function_instance(fi_obex1); |
| 334 | if (!IS_ERR(fi_phonet)) |
| 335 | usb_put_function_instance(fi_phonet); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 336 | usb_put_function_instance(fi_acm); |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 337 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Sebastian Andrzej Siewior | c2ec75c | 2012-09-06 20:11:03 +0200 | [diff] [blame] | 341 | static __refdata struct usb_composite_driver nokia_driver = { |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 342 | .name = "g_nokia", |
| 343 | .dev = &device_desc, |
| 344 | .strings = dev_strings, |
Tatyana Brokhman | 35a0e0b | 2011-06-29 16:41:49 +0300 | [diff] [blame] | 345 | .max_speed = USB_SPEED_HIGH, |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 346 | .bind = nokia_bind, |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 347 | .unbind = __exit_p(nokia_unbind), |
| 348 | }; |
| 349 | |
| 350 | static int __init nokia_init(void) |
| 351 | { |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 352 | return usb_composite_probe(&nokia_driver); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 353 | } |
| 354 | module_init(nokia_init); |
| 355 | |
| 356 | static void __exit nokia_cleanup(void) |
| 357 | { |
| 358 | usb_composite_unregister(&nokia_driver); |
| 359 | } |
| 360 | module_exit(nokia_cleanup); |