aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/gmidi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/gmidi.c')
-rw-r--r--drivers/usb/gadget/gmidi.c61
1 files changed, 16 insertions, 45 deletions
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 681bd038b1d8..881aab86ae99 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -22,7 +22,6 @@
22 22
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/utsname.h>
26#include <linux/module.h> 25#include <linux/module.h>
27#include <linux/device.h> 26#include <linux/device.h>
28 27
@@ -31,16 +30,13 @@
31#include <sound/rawmidi.h> 30#include <sound/rawmidi.h>
32 31
33#include <linux/usb/ch9.h> 32#include <linux/usb/ch9.h>
33#include <linux/usb/composite.h>
34#include <linux/usb/gadget.h> 34#include <linux/usb/gadget.h>
35#include <linux/usb/audio.h> 35#include <linux/usb/audio.h>
36#include <linux/usb/midi.h> 36#include <linux/usb/midi.h>
37 37
38#include "gadget_chips.h" 38#include "gadget_chips.h"
39 39
40#include "composite.c"
41#include "usbstring.c"
42#include "config.c"
43#include "epautoconf.c"
44#include "f_midi.c" 40#include "f_midi.c"
45 41
46/*-------------------------------------------------------------------------*/ 42/*-------------------------------------------------------------------------*/
@@ -51,6 +47,8 @@ MODULE_LICENSE("GPL v2");
51static const char shortname[] = "g_midi"; 47static const char shortname[] = "g_midi";
52static const char longname[] = "MIDI Gadget"; 48static const char longname[] = "MIDI Gadget";
53 49
50USB_GADGET_COMPOSITE_OPTIONS();
51
54static int index = SNDRV_DEFAULT_IDX1; 52static int index = SNDRV_DEFAULT_IDX1;
55module_param(index, int, S_IRUGO); 53module_param(index, int, S_IRUGO);
56MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter."); 54MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter.");
@@ -85,9 +83,7 @@ MODULE_PARM_DESC(out_ports, "Number of MIDI output ports");
85 83
86/* string IDs are assigned dynamically */ 84/* string IDs are assigned dynamically */
87 85
88#define STRING_MANUFACTURER_IDX 0 86#define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX
89#define STRING_PRODUCT_IDX 1
90#define STRING_DESCRIPTION_IDX 2
91 87
92static struct usb_device_descriptor device_desc = { 88static struct usb_device_descriptor device_desc = {
93 .bLength = USB_DT_DEVICE_SIZE, 89 .bLength = USB_DT_DEVICE_SIZE,
@@ -102,8 +98,9 @@ static struct usb_device_descriptor device_desc = {
102}; 98};
103 99
104static struct usb_string strings_dev[] = { 100static struct usb_string strings_dev[] = {
105 [STRING_MANUFACTURER_IDX].s = "Grey Innovation", 101 [USB_GADGET_MANUFACTURER_IDX].s = "Grey Innovation",
106 [STRING_PRODUCT_IDX].s = "MIDI Gadget", 102 [USB_GADGET_PRODUCT_IDX].s = "MIDI Gadget",
103 [USB_GADGET_SERIAL_IDX].s = "",
107 [STRING_DESCRIPTION_IDX].s = "MIDI", 104 [STRING_DESCRIPTION_IDX].s = "MIDI",
108 { } /* end of list */ 105 { } /* end of list */
109}; 106};
@@ -140,61 +137,35 @@ static int __init midi_bind_config(struct usb_configuration *c)
140 137
141static int __init midi_bind(struct usb_composite_dev *cdev) 138static int __init midi_bind(struct usb_composite_dev *cdev)
142{ 139{
143 struct usb_gadget *gadget = cdev->gadget; 140 int status;
144 int gcnum, status;
145
146 status = usb_string_id(cdev);
147 if (status < 0)
148 return status;
149 strings_dev[STRING_MANUFACTURER_IDX].id = status;
150 device_desc.iManufacturer = status;
151 141
152 status = usb_string_id(cdev); 142 status = usb_string_ids_tab(cdev, strings_dev);
153 if (status < 0) 143 if (status < 0)
154 return status; 144 return status;
155 strings_dev[STRING_PRODUCT_IDX].id = status; 145 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
156 device_desc.iProduct = status; 146 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
157 147 midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;
158 /* config description */
159 status = usb_string_id(cdev);
160 if (status < 0)
161 return status;
162 strings_dev[STRING_DESCRIPTION_IDX].id = status;
163
164 midi_config.iConfiguration = status;
165
166 gcnum = usb_gadget_controller_number(gadget);
167 if (gcnum < 0) {
168 /* gmidi is so simple (no altsettings) that
169 * it SHOULD NOT have problems with bulk-capable hardware.
170 * so warn about unrecognized controllers, don't panic.
171 */
172 pr_warning("%s: controller '%s' not recognized\n",
173 __func__, gadget->name);
174 device_desc.bcdDevice = cpu_to_le16(0x9999);
175 } else {
176 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
177 }
178 148
179 status = usb_add_config(cdev, &midi_config, midi_bind_config); 149 status = usb_add_config(cdev, &midi_config, midi_bind_config);
180 if (status < 0) 150 if (status < 0)
181 return status; 151 return status;
182 152 usb_composite_overwrite_options(cdev, &coverwrite);
183 pr_info("%s\n", longname); 153 pr_info("%s\n", longname);
184 return 0; 154 return 0;
185} 155}
186 156
187static struct usb_composite_driver midi_driver = { 157static __refdata struct usb_composite_driver midi_driver = {
188 .name = (char *) longname, 158 .name = (char *) longname,
189 .dev = &device_desc, 159 .dev = &device_desc,
190 .strings = dev_strings, 160 .strings = dev_strings,
191 .max_speed = USB_SPEED_HIGH, 161 .max_speed = USB_SPEED_HIGH,
162 .bind = midi_bind,
192 .unbind = __exit_p(midi_unbind), 163 .unbind = __exit_p(midi_unbind),
193}; 164};
194 165
195static int __init midi_init(void) 166static int __init midi_init(void)
196{ 167{
197 return usb_composite_probe(&midi_driver, midi_bind); 168 return usb_composite_probe(&midi_driver);
198} 169}
199module_init(midi_init); 170module_init(midi_init);
200 171