Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * usbusy2y.c - ALSA USB US-428 Driver |
| 3 | * |
Karsten Wiese | 230cd5e | 2005-04-20 10:12:35 +0200 | [diff] [blame] | 4 | 2005-04-14 Karsten Wiese |
| 5 | Version 0.8.7.2: |
| 6 | Call snd_card_free() instead of snd_card_free_in_thread() to prevent oops with dead keyboard symptom. |
| 7 | Tested ok with kernel 2.6.12-rc2. |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | 2004-12-14 Karsten Wiese |
| 10 | Version 0.8.7.1: |
| 11 | snd_pcm_open for rawusb pcm-devices now returns -EBUSY if called without rawusb's hwdep device being open. |
| 12 | |
| 13 | 2004-12-02 Karsten Wiese |
| 14 | Version 0.8.7: |
| 15 | Use macro usb_maxpacket() for portability. |
| 16 | |
| 17 | 2004-10-26 Karsten Wiese |
| 18 | Version 0.8.6: |
| 19 | wake_up() process waiting in usX2Y_urbs_start() on error. |
| 20 | |
| 21 | 2004-10-21 Karsten Wiese |
| 22 | Version 0.8.5: |
| 23 | nrpacks is runtime or compiletime configurable now with tested values from 1 to 4. |
| 24 | |
| 25 | 2004-10-03 Karsten Wiese |
| 26 | Version 0.8.2: |
| 27 | Avoid any possible racing while in prepare callback. |
| 28 | |
| 29 | 2004-09-30 Karsten Wiese |
| 30 | Version 0.8.0: |
| 31 | Simplified things and made ohci work again. |
| 32 | |
| 33 | 2004-09-20 Karsten Wiese |
| 34 | Version 0.7.3: |
| 35 | Use usb_kill_urb() instead of deprecated (kernel 2.6.9) usb_unlink_urb(). |
| 36 | |
| 37 | 2004-07-13 Karsten Wiese |
| 38 | Version 0.7.1: |
| 39 | Don't sleep in START/STOP callbacks anymore. |
| 40 | us428 channels C/D not handled just for this version, sorry. |
| 41 | |
| 42 | 2004-06-21 Karsten Wiese |
| 43 | Version 0.6.4: |
| 44 | Temporarely suspend midi input |
| 45 | to sanely call usb_set_interface() when setting format. |
| 46 | |
| 47 | 2004-06-12 Karsten Wiese |
| 48 | Version 0.6.3: |
| 49 | Made it thus the following rule is enforced: |
| 50 | "All pcm substreams of one usX2Y have to operate at the same rate & format." |
| 51 | |
| 52 | 2004-04-06 Karsten Wiese |
| 53 | Version 0.6.0: |
| 54 | Runs on 2.6.5 kernel without any "--with-debug=" things. |
| 55 | us224 reported running. |
| 56 | |
| 57 | 2004-01-14 Karsten Wiese |
| 58 | Version 0.5.1: |
| 59 | Runs with 2.6.1 kernel. |
| 60 | |
| 61 | 2003-12-30 Karsten Wiese |
| 62 | Version 0.4.1: |
| 63 | Fix 24Bit 4Channel capturing for the us428. |
| 64 | |
| 65 | 2003-11-27 Karsten Wiese, Martin Langer |
| 66 | Version 0.4: |
| 67 | us122 support. |
| 68 | us224 could be tested by uncommenting the sections containing USB_ID_US224 |
| 69 | |
| 70 | 2003-11-03 Karsten Wiese |
| 71 | Version 0.3: |
| 72 | 24Bit support. |
| 73 | "arecord -D hw:1 -c 2 -r 48000 -M -f S24_3LE|aplay -D hw:1 -c 2 -r 48000 -M -f S24_3LE" works. |
| 74 | |
| 75 | 2003-08-22 Karsten Wiese |
| 76 | Version 0.0.8: |
| 77 | Removed EZUSB Firmware. First Stage Firmwaredownload is now done by tascam-firmware downloader. |
| 78 | See: |
| 79 | http://usb-midi-fw.sourceforge.net/tascam-firmware.tar.gz |
| 80 | |
| 81 | 2003-06-18 Karsten Wiese |
| 82 | Version 0.0.5: |
| 83 | changed to compile with kernel 2.4.21 and alsa 0.9.4 |
| 84 | |
| 85 | 2002-10-16 Karsten Wiese |
| 86 | Version 0.0.4: |
| 87 | compiles again with alsa-current. |
| 88 | USB_ISO_ASAP not used anymore (most of the time), instead |
| 89 | urb->start_frame is calculated here now, some calls inside usb-driver don't need to happen anymore. |
| 90 | |
| 91 | To get the best out of this: |
| 92 | Disable APM-support in the kernel as APM-BIOS calls (once each second) hard disable interrupt for many precious milliseconds. |
| 93 | This helped me much on my slowish PII 400 & PIII 500. |
| 94 | ACPI yet untested but might cause the same bad behaviour. |
| 95 | Use a kernel with lowlatency and preemptiv patches applied. |
| 96 | To autoload snd-usb-midi append a line |
| 97 | post-install snd-usb-us428 modprobe snd-usb-midi |
| 98 | to /etc/modules.conf. |
| 99 | |
| 100 | known problems: |
| 101 | sliders, knobs, lights not yet handled except MASTER Volume slider. |
| 102 | "pcm -c 2" doesn't work. "pcm -c 2 -m direct_interleaved" does. |
| 103 | KDE3: "Enable full duplex operation" deadlocks. |
| 104 | |
| 105 | |
| 106 | 2002-08-31 Karsten Wiese |
| 107 | Version 0.0.3: audio also simplex; |
| 108 | simplifying: iso urbs only 1 packet, melted structs. |
| 109 | ASYNC_UNLINK not used anymore: no more crashes so far..... |
| 110 | for alsa 0.9 rc3. |
| 111 | |
| 112 | 2002-08-09 Karsten Wiese |
| 113 | Version 0.0.2: midi works with snd-usb-midi, audio (only fullduplex now) with i.e. bristol. |
| 114 | The firmware has been sniffed from win2k us-428 driver 3.09. |
| 115 | |
| 116 | * Copyright (c) 2002 - 2004 Karsten Wiese |
| 117 | * |
| 118 | * This program is free software; you can redistribute it and/or modify |
| 119 | * it under the terms of the GNU General Public License as published by |
| 120 | * the Free Software Foundation; either version 2 of the License, or |
| 121 | * (at your option) any later version. |
| 122 | * |
| 123 | * This program is distributed in the hope that it will be useful, |
| 124 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 125 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 126 | * GNU General Public License for more details. |
| 127 | * |
| 128 | * You should have received a copy of the GNU General Public License |
| 129 | * along with this program; if not, write to the Free Software |
| 130 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 131 | */ |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #include <linux/init.h> |
| 134 | #include <linux/module.h> |
| 135 | #include <linux/moduleparam.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 136 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #include <linux/interrupt.h> |
| 138 | #include <linux/usb.h> |
| 139 | #include <sound/core.h> |
| 140 | #include <sound/initval.h> |
| 141 | #include <sound/pcm.h> |
| 142 | |
| 143 | #include <sound/rawmidi.h> |
| 144 | #include "usx2y.h" |
| 145 | #include "usbusx2y.h" |
| 146 | #include "usX2Yhwdep.h" |
| 147 | |
| 148 | |
| 149 | |
| 150 | MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>"); |
Karsten Wiese | 230cd5e | 2005-04-20 10:12:35 +0200 | [diff] [blame] | 151 | MODULE_DESCRIPTION("TASCAM "NAME_ALLCAPS" Version 0.8.7.2"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | MODULE_LICENSE("GPL"); |
| 153 | MODULE_SUPPORTED_DEVICE("{{TASCAM(0x1604), "NAME_ALLCAPS"(0x8001)(0x8005)(0x8007) }}"); |
| 154 | |
| 155 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ |
| 156 | static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 157 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | module_param_array(index, int, NULL, 0444); |
| 160 | MODULE_PARM_DESC(index, "Index value for "NAME_ALLCAPS"."); |
| 161 | module_param_array(id, charp, NULL, 0444); |
| 162 | MODULE_PARM_DESC(id, "ID string for "NAME_ALLCAPS"."); |
| 163 | module_param_array(enable, bool, NULL, 0444); |
| 164 | MODULE_PARM_DESC(enable, "Enable "NAME_ALLCAPS"."); |
| 165 | |
| 166 | |
| 167 | static int snd_usX2Y_card_used[SNDRV_CARDS]; |
| 168 | |
| 169 | static void usX2Y_usb_disconnect(struct usb_device* usb_device, void* ptr); |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 170 | static void snd_usX2Y_card_private_free(struct snd_card *card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * pipe 4 is used for switching the lamps, setting samplerate, volumes .... |
| 174 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 175 | static void i_usX2Y_Out04Int(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
| 177 | #ifdef CONFIG_SND_DEBUG |
| 178 | if (urb->status) { |
| 179 | int i; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 180 | struct usX2Ydev *usX2Y = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | for (i = 0; i < 10 && usX2Y->AS04.urb[i] != urb; i++); |
| 182 | snd_printdd("i_usX2Y_Out04Int() urb %i status=%i\n", i, urb->status); |
| 183 | } |
| 184 | #endif |
| 185 | } |
| 186 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 187 | static void i_usX2Y_In04Int(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
| 189 | int err = 0; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 190 | struct usX2Ydev *usX2Y = urb->context; |
| 191 | struct us428ctls_sharedmem *us428ctls = usX2Y->us428ctls_sharedmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | usX2Y->In04IntCalls++; |
| 194 | |
| 195 | if (urb->status) { |
| 196 | snd_printdd("Interrupt Pipe 4 came back with status=%i\n", urb->status); |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | // printk("%i:0x%02X ", 8, (int)((unsigned char*)usX2Y->In04Buf)[8]); Master volume shows 0 here if fader is at max during boot ?!? |
| 201 | if (us428ctls) { |
| 202 | int diff = -1; |
| 203 | if (-2 == us428ctls->CtlSnapShotLast) { |
| 204 | diff = 0; |
| 205 | memcpy(usX2Y->In04Last, usX2Y->In04Buf, sizeof(usX2Y->In04Last)); |
| 206 | us428ctls->CtlSnapShotLast = -1; |
| 207 | } else { |
| 208 | int i; |
| 209 | for (i = 0; i < 21; i++) { |
| 210 | if (usX2Y->In04Last[i] != ((char*)usX2Y->In04Buf)[i]) { |
| 211 | if (diff < 0) |
| 212 | diff = i; |
| 213 | usX2Y->In04Last[i] = ((char*)usX2Y->In04Buf)[i]; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | if (0 <= diff) { |
| 218 | int n = us428ctls->CtlSnapShotLast + 1; |
| 219 | if (n >= N_us428_ctl_BUFS || n < 0) |
| 220 | n = 0; |
| 221 | memcpy(us428ctls->CtlSnapShot + n, usX2Y->In04Buf, sizeof(us428ctls->CtlSnapShot[0])); |
| 222 | us428ctls->CtlSnapShotDiffersAt[n] = diff; |
| 223 | us428ctls->CtlSnapShotLast = n; |
| 224 | wake_up(&usX2Y->us428ctls_wait_queue_head); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | |
| 229 | if (usX2Y->US04) { |
| 230 | if (0 == usX2Y->US04->submitted) |
Hannes Eder | 3a755ec | 2009-02-25 22:28:26 +0100 | [diff] [blame] | 231 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | err = usb_submit_urb(usX2Y->US04->urb[usX2Y->US04->submitted++], GFP_ATOMIC); |
Hannes Eder | 3a755ec | 2009-02-25 22:28:26 +0100 | [diff] [blame] | 233 | } while (!err && usX2Y->US04->submitted < usX2Y->US04->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } else |
| 235 | if (us428ctls && us428ctls->p4outLast >= 0 && us428ctls->p4outLast < N_us428_p4out_BUFS) { |
| 236 | if (us428ctls->p4outLast != us428ctls->p4outSent) { |
| 237 | int j, send = us428ctls->p4outSent + 1; |
| 238 | if (send >= N_us428_p4out_BUFS) |
| 239 | send = 0; |
| 240 | for (j = 0; j < URBS_AsyncSeq && !err; ++j) |
| 241 | if (0 == usX2Y->AS04.urb[j]->status) { |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 242 | struct us428_p4out *p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost. |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 243 | usb_fill_bulk_urb(usX2Y->AS04.urb[j], usX2Y->dev, |
| 244 | usb_sndbulkpipe(usX2Y->dev, 0x04), &p4out->val.vol, |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 245 | p4out->type == eLT_Light ? sizeof(struct us428_lights) : 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | i_usX2Y_Out04Int, usX2Y); |
| 247 | err = usb_submit_urb(usX2Y->AS04.urb[j], GFP_ATOMIC); |
| 248 | us428ctls->p4outSent = send; |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
Takashi Iwai | d3d579f | 2005-10-21 16:20:11 +0200 | [diff] [blame] | 254 | if (err) |
| 255 | snd_printk(KERN_ERR "In04Int() usb_submit_urb err=%i\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 257 | urb->dev = usX2Y->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | usb_submit_urb(urb, GFP_ATOMIC); |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Prepare some urbs |
| 263 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 264 | int usX2Y_AsyncSeq04_init(struct usX2Ydev *usX2Y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | int err = 0, |
| 267 | i; |
| 268 | |
| 269 | if (NULL == (usX2Y->AS04.buffer = kmalloc(URB_DataLen_AsyncSeq*URBS_AsyncSeq, GFP_KERNEL))) { |
| 270 | err = -ENOMEM; |
| 271 | } else |
| 272 | for (i = 0; i < URBS_AsyncSeq; ++i) { |
| 273 | if (NULL == (usX2Y->AS04.urb[i] = usb_alloc_urb(0, GFP_KERNEL))) { |
| 274 | err = -ENOMEM; |
| 275 | break; |
| 276 | } |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 277 | usb_fill_bulk_urb( usX2Y->AS04.urb[i], usX2Y->dev, |
| 278 | usb_sndbulkpipe(usX2Y->dev, 0x04), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0, |
| 280 | i_usX2Y_Out04Int, usX2Y |
| 281 | ); |
| 282 | } |
| 283 | return err; |
| 284 | } |
| 285 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 286 | int usX2Y_In04_init(struct usX2Ydev *usX2Y) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (! (usX2Y->In04urb = usb_alloc_urb(0, GFP_KERNEL))) |
| 289 | return -ENOMEM; |
| 290 | |
| 291 | if (! (usX2Y->In04Buf = kmalloc(21, GFP_KERNEL))) { |
| 292 | usb_free_urb(usX2Y->In04urb); |
| 293 | return -ENOMEM; |
| 294 | } |
| 295 | |
| 296 | init_waitqueue_head(&usX2Y->In04WaitQueue); |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 297 | usb_fill_int_urb(usX2Y->In04urb, usX2Y->dev, usb_rcvintpipe(usX2Y->dev, 0x4), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | usX2Y->In04Buf, 21, |
| 299 | i_usX2Y_In04Int, usX2Y, |
| 300 | 10); |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 301 | return usb_submit_urb(usX2Y->In04urb, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 304 | static void usX2Y_unlinkSeq(struct snd_usX2Y_AsyncSeq *S) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 306 | int i; |
| 307 | for (i = 0; i < URBS_AsyncSeq; ++i) { |
| 308 | if (S[i].urb) { |
| 309 | usb_kill_urb(S->urb[i]); |
| 310 | usb_free_urb(S->urb[i]); |
| 311 | S->urb[i] = NULL; |
| 312 | } |
| 313 | } |
| 314 | kfree(S->buffer); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | static struct usb_device_id snd_usX2Y_usb_id_table[] = { |
| 319 | { |
| 320 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 321 | .idVendor = 0x1604, |
| 322 | .idProduct = USB_ID_US428 |
| 323 | }, |
| 324 | { |
| 325 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 326 | .idVendor = 0x1604, |
| 327 | .idProduct = USB_ID_US122 |
| 328 | }, |
| 329 | { |
| 330 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE, |
| 331 | .idVendor = 0x1604, |
| 332 | .idProduct = USB_ID_US224 |
| 333 | }, |
| 334 | { /* terminator */ } |
| 335 | }; |
| 336 | |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 337 | static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
| 339 | int dev; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 340 | struct snd_card * card; |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 341 | int err; |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | for (dev = 0; dev < SNDRV_CARDS; ++dev) |
| 344 | if (enable[dev] && !snd_usX2Y_card_used[dev]) |
| 345 | break; |
| 346 | if (dev >= SNDRV_CARDS) |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 347 | return -ENODEV; |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 348 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, |
| 349 | sizeof(struct usX2Ydev), &card); |
| 350 | if (err < 0) |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 351 | return err; |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 352 | snd_usX2Y_card_used[usX2Y(card)->card_index = dev] = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | card->private_free = snd_usX2Y_card_private_free; |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 354 | usX2Y(card)->dev = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | init_waitqueue_head(&usX2Y(card)->prepare_wait_queue); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 356 | mutex_init(&usX2Y(card)->prepare_mutex); |
Clemens Ladisch | d82af9f | 2009-11-16 12:23:46 +0100 | [diff] [blame] | 357 | INIT_LIST_HEAD(&usX2Y(card)->midi_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | strcpy(card->driver, "USB "NAME_ALLCAPS""); |
| 359 | sprintf(card->shortname, "TASCAM "NAME_ALLCAPS""); |
| 360 | sprintf(card->longname, "%s (%x:%x if %d at %03d/%03d)", |
| 361 | card->shortname, |
| 362 | le16_to_cpu(device->descriptor.idVendor), |
| 363 | le16_to_cpu(device->descriptor.idProduct), |
| 364 | 0,//us428(card)->usbmidi.ifnum, |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 365 | usX2Y(card)->dev->bus->busnum, usX2Y(card)->dev->devnum |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | ); |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 367 | *cardp = card; |
| 368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 372 | static int usX2Y_usb_probe(struct usb_device *device, |
| 373 | struct usb_interface *intf, |
| 374 | const struct usb_device_id *device_id, |
| 375 | struct snd_card **cardp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
| 377 | int err; |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 378 | struct snd_card * card; |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 379 | |
| 380 | *cardp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | if (le16_to_cpu(device->descriptor.idVendor) != 0x1604 || |
| 382 | (le16_to_cpu(device->descriptor.idProduct) != USB_ID_US122 && |
| 383 | le16_to_cpu(device->descriptor.idProduct) != USB_ID_US224 && |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 384 | le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428)) |
| 385 | return -EINVAL; |
| 386 | |
| 387 | err = usX2Y_create_card(device, &card); |
| 388 | if (err < 0) |
| 389 | return err; |
Takashi Iwai | 3f5d346 | 2009-07-02 11:51:44 +0200 | [diff] [blame] | 390 | snd_card_set_dev(card, &intf->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | if ((err = usX2Y_hwdep_new(card, device)) < 0 || |
| 392 | (err = snd_card_register(card)) < 0) { |
| 393 | snd_card_free(card); |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 394 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 396 | *cardp = card; |
| 397 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /* |
| 401 | * new 2.5 USB kernel API |
| 402 | */ |
| 403 | static int snd_usX2Y_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 404 | { |
Takashi Iwai | 51721f7 | 2008-12-28 16:55:08 +0100 | [diff] [blame] | 405 | struct snd_card *card; |
| 406 | int err; |
| 407 | |
| 408 | err = usX2Y_usb_probe(interface_to_usbdev(intf), intf, id, &card); |
| 409 | if (err < 0) |
| 410 | return err; |
| 411 | dev_set_drvdata(&intf->dev, card); |
| 412 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static void snd_usX2Y_disconnect(struct usb_interface *intf) |
| 416 | { |
| 417 | usX2Y_usb_disconnect(interface_to_usbdev(intf), |
Julia Lawall | f4e9749 | 2009-01-01 18:14:35 +0100 | [diff] [blame] | 418 | usb_get_intfdata(intf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | MODULE_DEVICE_TABLE(usb, snd_usX2Y_usb_id_table); |
| 422 | static struct usb_driver snd_usX2Y_usb_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | .name = "snd-usb-usx2y", |
| 424 | .probe = snd_usX2Y_probe, |
| 425 | .disconnect = snd_usX2Y_disconnect, |
| 426 | .id_table = snd_usX2Y_usb_id_table, |
| 427 | }; |
| 428 | |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 429 | static void snd_usX2Y_card_private_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
| 431 | kfree(usX2Y(card)->In04Buf); |
| 432 | usb_free_urb(usX2Y(card)->In04urb); |
| 433 | if (usX2Y(card)->us428ctls_sharedmem) |
| 434 | snd_free_pages(usX2Y(card)->us428ctls_sharedmem, sizeof(*usX2Y(card)->us428ctls_sharedmem)); |
Clemens Ladisch | a014bba | 2009-11-16 12:26:30 +0100 | [diff] [blame] | 435 | if (usX2Y(card)->card_index >= 0 && usX2Y(card)->card_index < SNDRV_CARDS) |
| 436 | snd_usX2Y_card_used[usX2Y(card)->card_index] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Frees the device. |
| 441 | */ |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 442 | static void usX2Y_usb_disconnect(struct usb_device *device, void* ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
| 444 | if (ptr) { |
Takashi Iwai | bbe85bb | 2005-11-17 15:08:26 +0100 | [diff] [blame] | 445 | struct snd_card *card = ptr; |
| 446 | struct usX2Ydev *usX2Y = usX2Y(card); |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 447 | struct list_head *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | usX2Y->chip_status = USX2Y_STAT_CHIP_HUP; |
| 449 | usX2Y_unlinkSeq(&usX2Y->AS04); |
| 450 | usb_kill_urb(usX2Y->In04urb); |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 451 | snd_card_disconnect(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /* release the midi resources */ |
Clemens Ladisch | d82af9f | 2009-11-16 12:23:46 +0100 | [diff] [blame] | 453 | list_for_each(p, &usX2Y->midi_list) { |
Clemens Ladisch | ee73339 | 2005-04-25 10:34:13 +0200 | [diff] [blame] | 454 | snd_usbmidi_disconnect(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | if (usX2Y->us428ctls_sharedmem) |
| 457 | wake_up(&usX2Y->us428ctls_wait_queue_head); |
Takashi Iwai | cb43237 | 2005-11-17 10:48:52 +0100 | [diff] [blame] | 458 | snd_card_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Greg Kroah-Hartman | 424f075 | 2011-11-18 09:50:44 -0800 | [diff] [blame] | 462 | module_usb_driver(snd_usX2Y_usb_driver); |