1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux driver for TerraTec DMX 6Fire USB
5 * Main routines and module definitions.
7 * Author: Torsten Schenk <torsten.schenk@zoho.com>
8 * Created: Jan 01, 2011
9 * Copyright: (C) Torsten Schenk
19 #include <linux/moduleparam.h>
20 #include <linux/interrupt.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/gfp.h>
24 #include <sound/initval.h>
26 MODULE_AUTHOR("Torsten Schenk <torsten.schenk@zoho.com>");
27 MODULE_DESCRIPTION("TerraTec DMX 6Fire USB audio driver");
28 MODULE_LICENSE("GPL v2");
29 MODULE_SUPPORTED_DEVICE("{{TerraTec,DMX 6Fire USB}}");
31 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-max */
32 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* Id for card */
33 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
; /* Enable card */
34 static struct sfire_chip
*chips
[SNDRV_CARDS
] = SNDRV_DEFAULT_PTR
;
35 static struct usb_device
*devices
[SNDRV_CARDS
] = SNDRV_DEFAULT_PTR
;
37 module_param_array(index
, int, NULL
, 0444);
38 MODULE_PARM_DESC(index
, "Index value for the 6fire sound device");
39 module_param_array(id
, charp
, NULL
, 0444);
40 MODULE_PARM_DESC(id
, "ID string for the 6fire sound device.");
41 module_param_array(enable
, bool, NULL
, 0444);
42 MODULE_PARM_DESC(enable
, "Enable the 6fire sound device.");
44 static DEFINE_MUTEX(register_mutex
);
46 static void usb6fire_chip_abort(struct sfire_chip
*chip
)
50 usb6fire_pcm_abort(chip
);
52 usb6fire_midi_abort(chip
);
54 usb6fire_comm_abort(chip
);
56 usb6fire_control_abort(chip
);
58 snd_card_disconnect(chip
->card
);
59 snd_card_free_when_closed(chip
->card
);
65 static void usb6fire_chip_destroy(struct sfire_chip
*chip
)
69 usb6fire_pcm_destroy(chip
);
71 usb6fire_midi_destroy(chip
);
73 usb6fire_comm_destroy(chip
);
75 usb6fire_control_destroy(chip
);
77 snd_card_free(chip
->card
);
81 static int usb6fire_chip_probe(struct usb_interface
*intf
,
82 const struct usb_device_id
*usb_id
)
86 struct sfire_chip
*chip
= NULL
;
87 struct usb_device
*device
= interface_to_usbdev(intf
);
88 int regidx
= -1; /* index in module parameter array */
89 struct snd_card
*card
= NULL
;
91 /* look if we already serve this card and return if so */
92 mutex_lock(®ister_mutex
);
93 for (i
= 0; i
< SNDRV_CARDS
; i
++) {
94 if (devices
[i
] == device
) {
96 chips
[i
]->intf_count
++;
97 usb_set_intfdata(intf
, chips
[i
]);
98 mutex_unlock(®ister_mutex
);
100 } else if (!devices
[i
] && regidx
< 0)
104 mutex_unlock(®ister_mutex
);
105 dev_err(&intf
->dev
, "too many cards registered.\n");
108 devices
[regidx
] = device
;
109 mutex_unlock(®ister_mutex
);
111 /* check, if firmware is present on device, upload it if not */
112 ret
= usb6fire_fw_init(intf
);
115 else if (ret
== FW_NOT_READY
) /* firmware update performed */
118 /* if we are here, card can be registered in alsa. */
119 if (usb_set_interface(device
, 0, 0) != 0) {
120 dev_err(&intf
->dev
, "can't set first interface.\n");
123 ret
= snd_card_new(&intf
->dev
, index
[regidx
], id
[regidx
],
124 THIS_MODULE
, sizeof(struct sfire_chip
), &card
);
126 dev_err(&intf
->dev
, "cannot create alsa card.\n");
129 strcpy(card
->driver
, "6FireUSB");
130 strcpy(card
->shortname
, "TerraTec DMX6FireUSB");
131 sprintf(card
->longname
, "%s at %d:%d", card
->shortname
,
132 device
->bus
->busnum
, device
->devnum
);
134 chip
= card
->private_data
;
135 chips
[regidx
] = chip
;
137 chip
->regidx
= regidx
;
138 chip
->intf_count
= 1;
141 ret
= usb6fire_comm_init(chip
);
145 ret
= usb6fire_midi_init(chip
);
149 ret
= usb6fire_pcm_init(chip
);
153 ret
= usb6fire_control_init(chip
);
157 ret
= snd_card_register(card
);
159 dev_err(&intf
->dev
, "cannot register card.");
162 usb_set_intfdata(intf
, chip
);
166 usb6fire_chip_destroy(chip
);
170 static void usb6fire_chip_disconnect(struct usb_interface
*intf
)
172 struct sfire_chip
*chip
;
174 chip
= usb_get_intfdata(intf
);
175 if (chip
) { /* if !chip, fw upload has been performed */
177 if (!chip
->intf_count
) {
178 mutex_lock(®ister_mutex
);
179 devices
[chip
->regidx
] = NULL
;
180 chips
[chip
->regidx
] = NULL
;
181 mutex_unlock(®ister_mutex
);
183 chip
->shutdown
= true;
184 usb6fire_chip_abort(chip
);
185 usb6fire_chip_destroy(chip
);
190 static const struct usb_device_id device_table
[] = {
192 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE
,
199 MODULE_DEVICE_TABLE(usb
, device_table
);
201 static struct usb_driver usb_driver
= {
202 .name
= "snd-usb-6fire",
203 .probe
= usb6fire_chip_probe
,
204 .disconnect
= usb6fire_chip_disconnect
,
205 .id_table
= device_table
,
208 module_usb_driver(usb_driver
);