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