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" |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 27 | #include "f_mass_storage.h" |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 28 | |
| 29 | /* Defines */ |
| 30 | |
| 31 | #define NOKIA_VERSION_NUM 0x0211 |
| 32 | #define NOKIA_LONG_NAME "N900 (PC-Suite Mode)" |
| 33 | |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 34 | USB_GADGET_COMPOSITE_OPTIONS(); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 35 | |
Andrzej Pietrasiewicz | f1a1823 | 2013-05-23 09:22:03 +0200 | [diff] [blame] | 36 | USB_ETHERNET_MODULE_PARAMETERS(); |
| 37 | |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 38 | static struct fsg_module_parameters fsg_mod_data = { |
| 39 | .stall = 0, |
| 40 | .luns = 2, |
| 41 | .removable_count = 2, |
| 42 | .removable = { 1, 1, }, |
| 43 | }; |
| 44 | |
| 45 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
| 46 | |
| 47 | static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; |
| 48 | |
| 49 | #else |
| 50 | |
| 51 | /* |
| 52 | * Number of buffers we will use. |
| 53 | * 2 is usually enough for good buffering pipeline |
| 54 | */ |
| 55 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS |
| 56 | |
| 57 | #endif /* CONFIG_USB_DEBUG */ |
| 58 | |
| 59 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); |
| 60 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 61 | #define NOKIA_VENDOR_ID 0x0421 /* Nokia */ |
| 62 | #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */ |
| 63 | |
| 64 | /* string IDs are assigned dynamically */ |
| 65 | |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 66 | #define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 67 | |
| 68 | static char manufacturer_nokia[] = "Nokia"; |
| 69 | static const char product_nokia[] = NOKIA_LONG_NAME; |
| 70 | static const char description_nokia[] = "PC-Suite Configuration"; |
| 71 | |
| 72 | static struct usb_string strings_dev[] = { |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 73 | [USB_GADGET_MANUFACTURER_IDX].s = manufacturer_nokia, |
| 74 | [USB_GADGET_PRODUCT_IDX].s = NOKIA_LONG_NAME, |
| 75 | [USB_GADGET_SERIAL_IDX].s = "", |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 76 | [STRING_DESCRIPTION_IDX].s = description_nokia, |
| 77 | { } /* end of list */ |
| 78 | }; |
| 79 | |
| 80 | static struct usb_gadget_strings stringtab_dev = { |
| 81 | .language = 0x0409, /* en-us */ |
| 82 | .strings = strings_dev, |
| 83 | }; |
| 84 | |
| 85 | static struct usb_gadget_strings *dev_strings[] = { |
| 86 | &stringtab_dev, |
| 87 | NULL, |
| 88 | }; |
| 89 | |
| 90 | static struct usb_device_descriptor device_desc = { |
| 91 | .bLength = USB_DT_DEVICE_SIZE, |
| 92 | .bDescriptorType = USB_DT_DEVICE, |
| 93 | .bcdUSB = __constant_cpu_to_le16(0x0200), |
| 94 | .bDeviceClass = USB_CLASS_COMM, |
| 95 | .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID), |
| 96 | .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID), |
Sebastian Andrzej Siewior | ed9cbda | 2012-09-10 09:16:07 +0200 | [diff] [blame] | 97 | .bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM), |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 98 | /* .iManufacturer = DYNAMIC */ |
| 99 | /* .iProduct = DYNAMIC */ |
| 100 | .bNumConfigurations = 1, |
| 101 | }; |
| 102 | |
| 103 | /*-------------------------------------------------------------------------*/ |
| 104 | |
| 105 | /* Module */ |
| 106 | MODULE_DESCRIPTION("Nokia composite gadget driver for N900"); |
| 107 | MODULE_AUTHOR("Felipe Balbi"); |
| 108 | MODULE_LICENSE("GPL"); |
| 109 | |
| 110 | /*-------------------------------------------------------------------------*/ |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 111 | static struct usb_function *f_acm_cfg1; |
| 112 | static struct usb_function *f_acm_cfg2; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 113 | static struct usb_function *f_ecm_cfg1; |
| 114 | static struct usb_function *f_ecm_cfg2; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 115 | static struct usb_function *f_obex1_cfg1; |
| 116 | static struct usb_function *f_obex2_cfg1; |
| 117 | static struct usb_function *f_obex1_cfg2; |
| 118 | static struct usb_function *f_obex2_cfg2; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 119 | static struct usb_function *f_phonet_cfg1; |
| 120 | static struct usb_function *f_phonet_cfg2; |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 121 | static struct usb_function *f_msg_cfg1; |
| 122 | static struct usb_function *f_msg_cfg2; |
Andrzej Pietrasiewicz | 0189e63 | 2013-05-23 10:51:10 +0200 | [diff] [blame] | 123 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 124 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 125 | static struct usb_configuration nokia_config_500ma_driver = { |
| 126 | .label = "Bus Powered", |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 127 | .bConfigurationValue = 1, |
| 128 | /* .iConfiguration = DYNAMIC */ |
| 129 | .bmAttributes = USB_CONFIG_ATT_ONE, |
Sebastian Andrzej Siewior | 8f900a9 | 2012-12-03 20:07:05 +0100 | [diff] [blame] | 130 | .MaxPower = 500, |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | static struct usb_configuration nokia_config_100ma_driver = { |
| 134 | .label = "Self Powered", |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 135 | .bConfigurationValue = 2, |
| 136 | /* .iConfiguration = DYNAMIC */ |
| 137 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, |
Sebastian Andrzej Siewior | 8f900a9 | 2012-12-03 20:07:05 +0100 | [diff] [blame] | 138 | .MaxPower = 100, |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 139 | }; |
| 140 | |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 141 | static struct usb_function_instance *fi_acm; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 142 | static struct usb_function_instance *fi_ecm; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 143 | static struct usb_function_instance *fi_obex1; |
| 144 | static struct usb_function_instance *fi_obex2; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 145 | static struct usb_function_instance *fi_phonet; |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 146 | static struct usb_function_instance *fi_msg; |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 147 | |
Arnd Bergmann | c94e289f | 2015-04-11 00:14:21 +0200 | [diff] [blame] | 148 | static int nokia_bind_config(struct usb_configuration *c) |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 149 | { |
| 150 | struct usb_function *f_acm; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 151 | struct usb_function *f_phonet = NULL; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 152 | struct usb_function *f_obex1 = NULL; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 153 | struct usb_function *f_ecm; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 154 | struct usb_function *f_obex2 = NULL; |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 155 | struct usb_function *f_msg; |
| 156 | struct fsg_opts *fsg_opts; |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 157 | int status = 0; |
Andrzej Pietrasiewicz | 45ab460 | 2013-12-13 14:46:40 +0100 | [diff] [blame] | 158 | int obex1_stat = -1; |
| 159 | int obex2_stat = -1; |
| 160 | int phonet_stat = -1; |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 161 | |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 162 | if (!IS_ERR(fi_phonet)) { |
| 163 | f_phonet = usb_get_function(fi_phonet); |
| 164 | if (IS_ERR(f_phonet)) |
| 165 | pr_debug("could not get phonet function\n"); |
| 166 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 167 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 168 | if (!IS_ERR(fi_obex1)) { |
| 169 | f_obex1 = usb_get_function(fi_obex1); |
| 170 | if (IS_ERR(f_obex1)) |
| 171 | pr_debug("could not get obex function 0\n"); |
| 172 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 173 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 174 | if (!IS_ERR(fi_obex2)) { |
| 175 | f_obex2 = usb_get_function(fi_obex2); |
| 176 | if (IS_ERR(f_obex2)) |
| 177 | pr_debug("could not get obex function 1\n"); |
| 178 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 179 | |
| 180 | f_acm = usb_get_function(fi_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 181 | if (IS_ERR(f_acm)) { |
| 182 | status = PTR_ERR(f_acm); |
| 183 | goto err_get_acm; |
| 184 | } |
| 185 | |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 186 | f_ecm = usb_get_function(fi_ecm); |
| 187 | if (IS_ERR(f_ecm)) { |
| 188 | status = PTR_ERR(f_ecm); |
| 189 | goto err_get_ecm; |
| 190 | } |
| 191 | |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 192 | f_msg = usb_get_function(fi_msg); |
| 193 | if (IS_ERR(f_msg)) { |
| 194 | status = PTR_ERR(f_msg); |
| 195 | goto err_get_msg; |
| 196 | } |
| 197 | |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 198 | if (!IS_ERR_OR_NULL(f_phonet)) { |
| 199 | phonet_stat = usb_add_function(c, f_phonet); |
| 200 | if (phonet_stat) |
| 201 | pr_debug("could not add phonet function\n"); |
| 202 | } |
| 203 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 204 | if (!IS_ERR_OR_NULL(f_obex1)) { |
| 205 | obex1_stat = usb_add_function(c, f_obex1); |
| 206 | if (obex1_stat) |
| 207 | pr_debug("could not add obex function 0\n"); |
| 208 | } |
| 209 | |
| 210 | if (!IS_ERR_OR_NULL(f_obex2)) { |
| 211 | obex2_stat = usb_add_function(c, f_obex2); |
| 212 | if (obex2_stat) |
| 213 | pr_debug("could not add obex function 1\n"); |
| 214 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 215 | |
| 216 | status = usb_add_function(c, f_acm); |
| 217 | if (status) |
| 218 | goto err_conf; |
| 219 | |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 220 | status = usb_add_function(c, f_ecm); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 221 | if (status) { |
| 222 | pr_debug("could not bind ecm config %d\n", status); |
| 223 | goto err_ecm; |
| 224 | } |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 225 | |
| 226 | fsg_opts = fsg_opts_from_func_inst(fi_msg); |
| 227 | |
| 228 | status = fsg_common_run_thread(fsg_opts->common); |
| 229 | if (status) |
| 230 | goto err_msg; |
| 231 | |
| 232 | status = usb_add_function(c, f_msg); |
| 233 | if (status) |
| 234 | goto err_msg; |
| 235 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 236 | if (c == &nokia_config_500ma_driver) { |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 237 | f_acm_cfg1 = f_acm; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 238 | f_ecm_cfg1 = f_ecm; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 239 | f_phonet_cfg1 = f_phonet; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 240 | f_obex1_cfg1 = f_obex1; |
| 241 | f_obex2_cfg1 = f_obex2; |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 242 | f_msg_cfg1 = f_msg; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 243 | } else { |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 244 | f_acm_cfg2 = f_acm; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 245 | f_ecm_cfg2 = f_ecm; |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 246 | f_phonet_cfg2 = f_phonet; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 247 | f_obex1_cfg2 = f_obex1; |
| 248 | f_obex2_cfg2 = f_obex2; |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 249 | f_msg_cfg2 = f_msg; |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 250 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 251 | |
| 252 | return status; |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 253 | err_msg: |
| 254 | usb_remove_function(c, f_ecm); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 255 | err_ecm: |
| 256 | usb_remove_function(c, f_acm); |
| 257 | err_conf: |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 258 | if (!obex2_stat) |
| 259 | usb_remove_function(c, f_obex2); |
| 260 | if (!obex1_stat) |
| 261 | usb_remove_function(c, f_obex1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 262 | if (!phonet_stat) |
| 263 | usb_remove_function(c, f_phonet); |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 264 | usb_put_function(f_msg); |
| 265 | err_get_msg: |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 266 | usb_put_function(f_ecm); |
| 267 | err_get_ecm: |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 268 | usb_put_function(f_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 269 | err_get_acm: |
| 270 | if (!IS_ERR_OR_NULL(f_obex2)) |
| 271 | usb_put_function(f_obex2); |
| 272 | if (!IS_ERR_OR_NULL(f_obex1)) |
| 273 | usb_put_function(f_obex1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 274 | if (!IS_ERR_OR_NULL(f_phonet)) |
| 275 | usb_put_function(f_phonet); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 276 | return status; |
| 277 | } |
| 278 | |
Arnd Bergmann | c94e289f | 2015-04-11 00:14:21 +0200 | [diff] [blame] | 279 | static int nokia_bind(struct usb_composite_dev *cdev) |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 280 | { |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 281 | struct usb_gadget *gadget = cdev->gadget; |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 282 | struct fsg_opts *fsg_opts; |
| 283 | struct fsg_config fsg_config; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 284 | int status; |
| 285 | |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 286 | status = usb_string_ids_tab(cdev, strings_dev); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 287 | if (status < 0) |
| 288 | goto err_usb; |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 289 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
| 290 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 291 | status = strings_dev[STRING_DESCRIPTION_IDX].id; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 292 | nokia_config_500ma_driver.iConfiguration = status; |
| 293 | nokia_config_100ma_driver.iConfiguration = status; |
| 294 | |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 295 | if (!gadget_supports_altsettings(gadget)) { |
| 296 | status = -ENODEV; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 297 | goto err_usb; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 298 | } |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 299 | |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 300 | fi_phonet = usb_get_function_instance("phonet"); |
| 301 | if (IS_ERR(fi_phonet)) |
| 302 | pr_debug("could not find phonet function\n"); |
| 303 | |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 304 | fi_obex1 = usb_get_function_instance("obex"); |
| 305 | if (IS_ERR(fi_obex1)) |
| 306 | pr_debug("could not find obex function 1\n"); |
| 307 | |
| 308 | fi_obex2 = usb_get_function_instance("obex"); |
| 309 | if (IS_ERR(fi_obex2)) |
| 310 | pr_debug("could not find obex function 2\n"); |
| 311 | |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 312 | fi_acm = usb_get_function_instance("acm"); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 313 | if (IS_ERR(fi_acm)) { |
| 314 | status = PTR_ERR(fi_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 315 | goto err_obex2_inst; |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | fi_ecm = usb_get_function_instance("ecm"); |
| 319 | if (IS_ERR(fi_ecm)) { |
| 320 | status = PTR_ERR(fi_ecm); |
| 321 | goto err_acm_inst; |
| 322 | } |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 323 | |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 324 | fi_msg = usb_get_function_instance("mass_storage"); |
| 325 | if (IS_ERR(fi_msg)) { |
| 326 | status = PTR_ERR(fi_msg); |
| 327 | goto err_ecm_inst; |
| 328 | } |
| 329 | |
| 330 | /* set up mass storage function */ |
| 331 | fsg_config_from_params(&fsg_config, &fsg_mod_data, fsg_num_buffers); |
| 332 | fsg_config.vendor_name = "Nokia"; |
| 333 | fsg_config.product_name = "N900"; |
| 334 | |
| 335 | fsg_opts = fsg_opts_from_func_inst(fi_msg); |
| 336 | fsg_opts->no_configfs = true; |
| 337 | |
| 338 | status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers); |
| 339 | if (status) |
| 340 | goto err_msg_inst; |
| 341 | |
| 342 | status = fsg_common_set_nluns(fsg_opts->common, fsg_config.nluns); |
| 343 | if (status) |
| 344 | goto err_msg_buf; |
| 345 | |
| 346 | status = fsg_common_set_cdev(fsg_opts->common, cdev, fsg_config.can_stall); |
| 347 | if (status) |
| 348 | goto err_msg_set_nluns; |
| 349 | |
| 350 | fsg_common_set_sysfs(fsg_opts->common, true); |
| 351 | |
| 352 | status = fsg_common_create_luns(fsg_opts->common, &fsg_config); |
| 353 | if (status) |
| 354 | goto err_msg_set_nluns; |
| 355 | |
| 356 | fsg_common_set_inquiry_string(fsg_opts->common, fsg_config.vendor_name, |
| 357 | fsg_config.product_name); |
| 358 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 359 | /* finally register the configuration */ |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 360 | status = usb_add_config(cdev, &nokia_config_500ma_driver, |
| 361 | nokia_bind_config); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 362 | if (status < 0) |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 363 | goto err_msg_set_cdev; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 364 | |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 365 | status = usb_add_config(cdev, &nokia_config_100ma_driver, |
| 366 | nokia_bind_config); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 367 | if (status < 0) |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 368 | goto err_put_cfg1; |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 369 | |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 370 | usb_composite_overwrite_options(cdev, &coverwrite); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 371 | dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); |
| 372 | |
| 373 | return 0; |
| 374 | |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 375 | err_put_cfg1: |
| 376 | usb_put_function(f_acm_cfg1); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 377 | if (!IS_ERR_OR_NULL(f_obex1_cfg1)) |
| 378 | usb_put_function(f_obex1_cfg1); |
| 379 | if (!IS_ERR_OR_NULL(f_obex2_cfg1)) |
| 380 | usb_put_function(f_obex2_cfg1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 381 | if (!IS_ERR_OR_NULL(f_phonet_cfg1)) |
| 382 | usb_put_function(f_phonet_cfg1); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 383 | usb_put_function(f_ecm_cfg1); |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 384 | err_msg_set_cdev: |
| 385 | fsg_common_remove_luns(fsg_opts->common); |
| 386 | err_msg_set_nluns: |
| 387 | fsg_common_free_luns(fsg_opts->common); |
| 388 | err_msg_buf: |
| 389 | fsg_common_free_buffers(fsg_opts->common); |
| 390 | err_msg_inst: |
| 391 | usb_put_function_instance(fi_msg); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 392 | err_ecm_inst: |
| 393 | usb_put_function_instance(fi_ecm); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 394 | err_acm_inst: |
| 395 | usb_put_function_instance(fi_acm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 396 | err_obex2_inst: |
| 397 | if (!IS_ERR(fi_obex2)) |
| 398 | usb_put_function_instance(fi_obex2); |
| 399 | if (!IS_ERR(fi_obex1)) |
| 400 | usb_put_function_instance(fi_obex1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 401 | if (!IS_ERR(fi_phonet)) |
| 402 | usb_put_function_instance(fi_phonet); |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 403 | err_usb: |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 404 | return status; |
| 405 | } |
| 406 | |
Arnd Bergmann | c94e289f | 2015-04-11 00:14:21 +0200 | [diff] [blame] | 407 | static int nokia_unbind(struct usb_composite_dev *cdev) |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 408 | { |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 409 | if (!IS_ERR_OR_NULL(f_obex1_cfg2)) |
| 410 | usb_put_function(f_obex1_cfg2); |
| 411 | if (!IS_ERR_OR_NULL(f_obex2_cfg2)) |
| 412 | usb_put_function(f_obex2_cfg2); |
| 413 | if (!IS_ERR_OR_NULL(f_obex1_cfg1)) |
| 414 | usb_put_function(f_obex1_cfg1); |
| 415 | if (!IS_ERR_OR_NULL(f_obex2_cfg1)) |
| 416 | usb_put_function(f_obex2_cfg1); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 417 | if (!IS_ERR_OR_NULL(f_phonet_cfg1)) |
| 418 | usb_put_function(f_phonet_cfg1); |
| 419 | if (!IS_ERR_OR_NULL(f_phonet_cfg2)) |
| 420 | usb_put_function(f_phonet_cfg2); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 421 | usb_put_function(f_acm_cfg1); |
| 422 | usb_put_function(f_acm_cfg2); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 423 | usb_put_function(f_ecm_cfg1); |
| 424 | usb_put_function(f_ecm_cfg2); |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 425 | usb_put_function(f_msg_cfg1); |
| 426 | usb_put_function(f_msg_cfg2); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 427 | |
Pali Rohár | 5ea7509 | 2015-06-08 08:20:05 +0200 | [diff] [blame^] | 428 | usb_put_function_instance(fi_msg); |
Andrzej Pietrasiewicz | b904d08 | 2013-05-23 10:51:14 +0200 | [diff] [blame] | 429 | usb_put_function_instance(fi_ecm); |
Andrzej Pietrasiewicz | 3a34344 | 2013-05-23 10:51:08 +0200 | [diff] [blame] | 430 | if (!IS_ERR(fi_obex2)) |
| 431 | usb_put_function_instance(fi_obex2); |
Andrzej Pietrasiewicz | 83167f1 | 2013-05-23 10:51:12 +0200 | [diff] [blame] | 432 | if (!IS_ERR(fi_obex1)) |
| 433 | usb_put_function_instance(fi_obex1); |
| 434 | if (!IS_ERR(fi_phonet)) |
| 435 | usb_put_function_instance(fi_phonet); |
Sebastian Andrzej Siewior | 1576182 | 2013-01-25 14:09:17 +0100 | [diff] [blame] | 436 | usb_put_function_instance(fi_acm); |
Sebastian Andrzej Siewior | 19b10a8 | 2012-12-23 21:10:06 +0100 | [diff] [blame] | 437 | |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 438 | return 0; |
| 439 | } |
| 440 | |
Arnd Bergmann | c94e289f | 2015-04-11 00:14:21 +0200 | [diff] [blame] | 441 | static struct usb_composite_driver nokia_driver = { |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 442 | .name = "g_nokia", |
| 443 | .dev = &device_desc, |
| 444 | .strings = dev_strings, |
Tatyana Brokhman | 35a0e0b | 2011-06-29 16:41:49 +0300 | [diff] [blame] | 445 | .max_speed = USB_SPEED_HIGH, |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 446 | .bind = nokia_bind, |
Arnd Bergmann | c94e289f | 2015-04-11 00:14:21 +0200 | [diff] [blame] | 447 | .unbind = nokia_unbind, |
Felipe Balbi | f358f5b | 2010-01-05 16:10:13 +0200 | [diff] [blame] | 448 | }; |
| 449 | |
Tobias Klauser | 909346a | 2014-07-09 18:09:56 +0200 | [diff] [blame] | 450 | module_usb_composite_driver(nokia_driver); |