KVM: Specify byte order for KVM_EXIT_MMIO
[linux/fpc-iii.git] / sound / usb / hiface / chip.c
blobb0dcb3924ce5139df00803072ac36ec4aa460888
1 /*
2 * Linux driver for M2Tech hiFace compatible devices
4 * Copyright 2012-2013 (C) M2TECH S.r.l and Amarula Solutions B.V.
6 * Authors: Michael Trimarchi <michael@amarulasolutions.com>
7 * Antonio Ospite <ao2@amarulasolutions.com>
9 * The driver is based on the work done in TerraTec DMX 6Fire USB
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <sound/initval.h>
21 #include "chip.h"
22 #include "pcm.h"
24 MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
25 MODULE_AUTHOR("Antonio Ospite <ao2@amarulasolutions.com>");
26 MODULE_DESCRIPTION("M2Tech hiFace USB-SPDIF audio driver");
27 MODULE_LICENSE("GPL v2");
28 MODULE_SUPPORTED_DEVICE("{{M2Tech,Young},"
29 "{M2Tech,hiFace},"
30 "{M2Tech,North Star},"
31 "{M2Tech,W4S Young},"
32 "{M2Tech,Corrson},"
33 "{M2Tech,AUDIA},"
34 "{M2Tech,SL Audio},"
35 "{M2Tech,Empirical},"
36 "{M2Tech,Rockna},"
37 "{M2Tech,Pathos},"
38 "{M2Tech,Metronome},"
39 "{M2Tech,CAD},"
40 "{M2Tech,Audio Esclusive},"
41 "{M2Tech,Rotel},"
42 "{M2Tech,Eeaudio},"
43 "{The Chord Company,CHORD},"
44 "{AVA Group A/S,Vitus}}");
46 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
47 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for card */
48 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
50 #define DRIVER_NAME "snd-usb-hiface"
51 #define CARD_NAME "hiFace"
53 module_param_array(index, int, NULL, 0444);
54 MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
55 module_param_array(id, charp, NULL, 0444);
56 MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
57 module_param_array(enable, bool, NULL, 0444);
58 MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
60 static DEFINE_MUTEX(register_mutex);
62 struct hiface_vendor_quirk {
63 const char *device_name;
64 u8 extra_freq;
67 static int hiface_chip_create(struct usb_device *device, int idx,
68 const struct hiface_vendor_quirk *quirk,
69 struct hiface_chip **rchip)
71 struct snd_card *card = NULL;
72 struct hiface_chip *chip;
73 int ret;
74 int len;
76 *rchip = NULL;
78 /* if we are here, card can be registered in alsa. */
79 ret = snd_card_create(index[idx], id[idx], THIS_MODULE, sizeof(*chip), &card);
80 if (ret < 0) {
81 dev_err(&device->dev, "cannot create alsa card.\n");
82 return ret;
85 strlcpy(card->driver, DRIVER_NAME, sizeof(card->driver));
87 if (quirk && quirk->device_name)
88 strlcpy(card->shortname, quirk->device_name, sizeof(card->shortname));
89 else
90 strlcpy(card->shortname, "M2Tech generic audio", sizeof(card->shortname));
92 strlcat(card->longname, card->shortname, sizeof(card->longname));
93 len = strlcat(card->longname, " at ", sizeof(card->longname));
94 if (len < sizeof(card->longname))
95 usb_make_path(device, card->longname + len,
96 sizeof(card->longname) - len);
98 chip = card->private_data;
99 chip->dev = device;
100 chip->card = card;
102 *rchip = chip;
103 return 0;
106 static int hiface_chip_probe(struct usb_interface *intf,
107 const struct usb_device_id *usb_id)
109 const struct hiface_vendor_quirk *quirk = (struct hiface_vendor_quirk *)usb_id->driver_info;
110 int ret;
111 int i;
112 struct hiface_chip *chip;
113 struct usb_device *device = interface_to_usbdev(intf);
115 ret = usb_set_interface(device, 0, 0);
116 if (ret != 0) {
117 dev_err(&device->dev, "can't set first interface for " CARD_NAME " device.\n");
118 return -EIO;
121 /* check whether the card is already registered */
122 chip = NULL;
123 mutex_lock(&register_mutex);
125 for (i = 0; i < SNDRV_CARDS; i++)
126 if (enable[i])
127 break;
129 if (i >= SNDRV_CARDS) {
130 dev_err(&device->dev, "no available " CARD_NAME " audio device\n");
131 ret = -ENODEV;
132 goto err;
135 ret = hiface_chip_create(device, i, quirk, &chip);
136 if (ret < 0)
137 goto err;
139 snd_card_set_dev(chip->card, &intf->dev);
141 ret = hiface_pcm_init(chip, quirk ? quirk->extra_freq : 0);
142 if (ret < 0)
143 goto err_chip_destroy;
145 ret = snd_card_register(chip->card);
146 if (ret < 0) {
147 dev_err(&device->dev, "cannot register " CARD_NAME " card\n");
148 goto err_chip_destroy;
151 mutex_unlock(&register_mutex);
153 usb_set_intfdata(intf, chip);
154 return 0;
156 err_chip_destroy:
157 snd_card_free(chip->card);
158 err:
159 mutex_unlock(&register_mutex);
160 return ret;
163 static void hiface_chip_disconnect(struct usb_interface *intf)
165 struct hiface_chip *chip;
166 struct snd_card *card;
168 chip = usb_get_intfdata(intf);
169 if (!chip)
170 return;
172 card = chip->card;
174 /* Make sure that the userspace cannot create new request */
175 snd_card_disconnect(card);
177 hiface_pcm_abort(chip);
178 snd_card_free_when_closed(card);
181 static const struct usb_device_id device_table[] = {
183 USB_DEVICE(0x04b4, 0x0384),
184 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
185 .device_name = "Young",
186 .extra_freq = 1,
190 USB_DEVICE(0x04b4, 0x930b),
191 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
192 .device_name = "hiFace",
196 USB_DEVICE(0x04b4, 0x931b),
197 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
198 .device_name = "North Star",
202 USB_DEVICE(0x04b4, 0x931c),
203 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
204 .device_name = "W4S Young",
208 USB_DEVICE(0x04b4, 0x931d),
209 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
210 .device_name = "Corrson",
214 USB_DEVICE(0x04b4, 0x931e),
215 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
216 .device_name = "AUDIA",
220 USB_DEVICE(0x04b4, 0x931f),
221 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
222 .device_name = "SL Audio",
226 USB_DEVICE(0x04b4, 0x9320),
227 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
228 .device_name = "Empirical",
232 USB_DEVICE(0x04b4, 0x9321),
233 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
234 .device_name = "Rockna",
238 USB_DEVICE(0x249c, 0x9001),
239 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
240 .device_name = "Pathos",
244 USB_DEVICE(0x249c, 0x9002),
245 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
246 .device_name = "Metronome",
250 USB_DEVICE(0x249c, 0x9006),
251 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
252 .device_name = "CAD",
256 USB_DEVICE(0x249c, 0x9008),
257 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
258 .device_name = "Audio Esclusive",
262 USB_DEVICE(0x249c, 0x931c),
263 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
264 .device_name = "Rotel",
268 USB_DEVICE(0x249c, 0x932c),
269 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
270 .device_name = "Eeaudio",
274 USB_DEVICE(0x245f, 0x931c),
275 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
276 .device_name = "CHORD",
280 USB_DEVICE(0x25c6, 0x9002),
281 .driver_info = (unsigned long)&(const struct hiface_vendor_quirk) {
282 .device_name = "Vitus",
288 MODULE_DEVICE_TABLE(usb, device_table);
290 static struct usb_driver hiface_usb_driver = {
291 .name = DRIVER_NAME,
292 .probe = hiface_chip_probe,
293 .disconnect = hiface_chip_disconnect,
294 .id_table = device_table,
297 module_usb_driver(hiface_usb_driver);