1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux driver for M2Tech hiFace compatible devices
5 * Copyright 2012-2013 (C) M2TECH S.r.l and Amarula Solutions B.V.
7 * Authors: Michael Trimarchi <michael@amarulasolutions.com>
8 * Antonio Ospite <ao2@amarulasolutions.com>
10 * The driver is based on the work done in TerraTec DMX 6Fire USB
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <sound/initval.h>
20 MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
21 MODULE_AUTHOR("Antonio Ospite <ao2@amarulasolutions.com>");
22 MODULE_DESCRIPTION("M2Tech hiFace USB-SPDIF audio driver");
23 MODULE_LICENSE("GPL v2");
24 MODULE_SUPPORTED_DEVICE("{{M2Tech,Young},"
26 "{M2Tech,North Star},"
36 "{M2Tech,Audio Esclusive},"
39 "{The Chord Company,CHORD},"
40 "{AVA Group A/S,Vitus}}");
42 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
43 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for card */
44 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
46 #define DRIVER_NAME "snd-usb-hiface"
47 #define CARD_NAME "hiFace"
49 module_param_array(index, int, NULL, 0444);
50 MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
51 module_param_array(id, charp, NULL, 0444);
52 MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
53 module_param_array(enable, bool, NULL, 0444);
54 MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
56 static DEFINE_MUTEX(register_mutex);
58 struct hiface_vendor_quirk {
59 const char *device_name;
63 static int hiface_chip_create(struct usb_interface *intf,
64 struct usb_device *device, int idx,
65 const struct hiface_vendor_quirk *quirk,
66 struct hiface_chip **rchip)
68 struct snd_card *card = NULL;
69 struct hiface_chip *chip;
75 /* if we are here, card can be registered in alsa. */
76 ret = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE,
77 sizeof(*chip), &card);
79 dev_err(&device->dev, "cannot create alsa card.\n");
83 strlcpy(card->driver, DRIVER_NAME, sizeof(card->driver));
85 if (quirk && quirk->device_name)
86 strlcpy(card->shortname, quirk->device_name, sizeof(card->shortname));
88 strlcpy(card->shortname, "M2Tech generic audio", sizeof(card->shortname));
90 strlcat(card->longname, card->shortname, sizeof(card->longname));
91 len = strlcat(card->longname, " at ", sizeof(card->longname));
92 if (len < sizeof(card->longname))
93 usb_make_path(device, card->longname + len,
94 sizeof(card->longname) - len);
96 chip = card->private_data;
104 static int hiface_chip_probe(struct usb_interface *intf,
105 const struct usb_device_id *usb_id)
107 const struct hiface_vendor_quirk *quirk = (struct hiface_vendor_quirk *)usb_id->driver_info;
110 struct hiface_chip *chip;
111 struct usb_device *device = interface_to_usbdev(intf);
113 ret = usb_set_interface(device, 0, 0);
115 dev_err(&device->dev, "can't set first interface for " CARD_NAME " device.\n");
119 /* check whether the card is already registered */
121 mutex_lock(®ister_mutex);
123 for (i = 0; i < SNDRV_CARDS; i++)
127 if (i >= SNDRV_CARDS) {
128 dev_err(&device->dev, "no available " CARD_NAME " audio device\n");
133 ret = hiface_chip_create(intf, device, i, quirk, &chip);
137 ret = hiface_pcm_init(chip, quirk ? quirk->extra_freq : 0);
139 goto err_chip_destroy;
141 ret = snd_card_register(chip->card);
143 dev_err(&device->dev, "cannot register " CARD_NAME " card\n");
144 goto err_chip_destroy;
147 mutex_unlock(®ister_mutex);
149 usb_set_intfdata(intf, chip);
153 snd_card_free(chip->card);
155 mutex_unlock(®ister_mutex);
159 static void hiface_chip_disconnect(struct usb_interface *intf)
161 struct hiface_chip *chip;
162 struct snd_card *card;
164 chip = usb_get_intfdata(intf);
170 /* Make sure that the userspace cannot create new request */
171 snd_card_disconnect(card);
173 hiface_pcm_abort(chip);
174 snd_card_free_when_closed(card);
177 static const struct usb_device_id device_table[] = {
179 USB_DEVICE(0x04b4, 0x0384),
180 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
181 .device_name = "Young",
186 USB_DEVICE(0x04b4, 0x930b),
187 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
188 .device_name = "hiFace",
192 USB_DEVICE(0x04b4, 0x931b),
193 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
194 .device_name = "North Star",
198 USB_DEVICE(0x04b4, 0x931c),
199 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
200 .device_name = "W4S Young",
204 USB_DEVICE(0x04b4, 0x931d),
205 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
206 .device_name = "Corrson",
210 USB_DEVICE(0x04b4, 0x931e),
211 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
212 .device_name = "AUDIA",
216 USB_DEVICE(0x04b4, 0x931f),
217 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
218 .device_name = "SL Audio",
222 USB_DEVICE(0x04b4, 0x9320),
223 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
224 .device_name = "Empirical",
228 USB_DEVICE(0x04b4, 0x9321),
229 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
230 .device_name = "Rockna",
234 USB_DEVICE(0x249c, 0x9001),
235 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
236 .device_name = "Pathos",
240 USB_DEVICE(0x249c, 0x9002),
241 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
242 .device_name = "Metronome",
246 USB_DEVICE(0x249c, 0x9006),
247 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
248 .device_name = "CAD",
252 USB_DEVICE(0x249c, 0x9008),
253 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
254 .device_name = "Audio Esclusive",
258 USB_DEVICE(0x249c, 0x931c),
259 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
260 .device_name = "Rotel",
264 USB_DEVICE(0x249c, 0x932c),
265 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
266 .device_name = "Eeaudio",
270 USB_DEVICE(0x245f, 0x931c),
271 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
272 .device_name = "CHORD",
276 USB_DEVICE(0x25c6, 0x9002),
277 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
278 .device_name = "Vitus",
284 MODULE_DEVICE_TABLE(usb, device_table);
286 static struct usb_driver hiface_usb_driver = {
288 .probe = hiface_chip_probe,
289 .disconnect = hiface_chip_disconnect,
290 .id_table = device_table,
293 module_usb_driver(hiface_usb_driver);