Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux
[linux-2.6.git] / drivers / staging / line6 / podhd.c
blob7ef45437b4f2392726ea7c7493495c049ce170f8
1 /*
2 * Line6 Pod HD
4 * Copyright (C) 2011 Stefan Hajnoczi <stefanha@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
12 #include <sound/core.h>
13 #include <sound/pcm.h>
15 #include "audio.h"
16 #include "driver.h"
17 #include "pcm.h"
18 #include "podhd.h"
20 #define PODHD_BYTES_PER_FRAME 6 /* 24bit audio (stereo) */
22 static struct snd_ratden podhd_ratden = {
23 .num_min = 48000,
24 .num_max = 48000,
25 .num_step = 1,
26 .den = 1,
29 static struct line6_pcm_properties podhd_pcm_properties = {
30 .snd_line6_playback_hw = {
31 .info = (SNDRV_PCM_INFO_MMAP |
32 SNDRV_PCM_INFO_INTERLEAVED |
33 SNDRV_PCM_INFO_BLOCK_TRANSFER |
34 SNDRV_PCM_INFO_MMAP_VALID |
35 SNDRV_PCM_INFO_PAUSE |
36 #ifdef CONFIG_PM
37 SNDRV_PCM_INFO_RESUME |
38 #endif
39 SNDRV_PCM_INFO_SYNC_START),
40 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
41 .rates = SNDRV_PCM_RATE_48000,
42 .rate_min = 48000,
43 .rate_max = 48000,
44 .channels_min = 2,
45 .channels_max = 2,
46 .buffer_bytes_max = 60000,
47 .period_bytes_min = 64,
48 .period_bytes_max = 8192,
49 .periods_min = 1,
50 .periods_max = 1024},
51 .snd_line6_capture_hw = {
52 .info = (SNDRV_PCM_INFO_MMAP |
53 SNDRV_PCM_INFO_INTERLEAVED |
54 SNDRV_PCM_INFO_BLOCK_TRANSFER |
55 SNDRV_PCM_INFO_MMAP_VALID |
56 #ifdef CONFIG_PM
57 SNDRV_PCM_INFO_RESUME |
58 #endif
59 SNDRV_PCM_INFO_SYNC_START),
60 .formats = SNDRV_PCM_FMTBIT_S24_3LE,
61 .rates = SNDRV_PCM_RATE_48000,
62 .rate_min = 48000,
63 .rate_max = 48000,
64 .channels_min = 2,
65 .channels_max = 2,
66 .buffer_bytes_max = 60000,
67 .period_bytes_min = 64,
68 .period_bytes_max = 8192,
69 .periods_min = 1,
70 .periods_max = 1024},
71 .snd_line6_rates = {
72 .nrats = 1,
73 .rats = &podhd_ratden},
74 .bytes_per_frame = PODHD_BYTES_PER_FRAME
78 POD HD destructor.
80 static void podhd_destruct(struct usb_interface *interface)
82 struct usb_line6_podhd *podhd = usb_get_intfdata(interface);
84 if (podhd == NULL)
85 return;
86 line6_cleanup_audio(&podhd->line6);
90 Try to init POD HD device.
92 static int podhd_try_init(struct usb_interface *interface,
93 struct usb_line6_podhd *podhd)
95 int err;
96 struct usb_line6 *line6 = &podhd->line6;
98 if ((interface == NULL) || (podhd == NULL))
99 return -ENODEV;
101 /* initialize audio system: */
102 err = line6_init_audio(line6);
103 if (err < 0)
104 return err;
106 /* initialize MIDI subsystem: */
107 err = line6_init_midi(line6);
108 if (err < 0)
109 return err;
111 /* initialize PCM subsystem: */
112 err = line6_init_pcm(line6, &podhd_pcm_properties);
113 if (err < 0)
114 return err;
116 /* register USB audio system: */
117 err = line6_register_audio(line6);
118 return err;
122 Init POD HD device (and clean up in case of failure).
124 int line6_podhd_init(struct usb_interface *interface,
125 struct usb_line6_podhd *podhd)
127 int err = podhd_try_init(interface, podhd);
129 if (err < 0)
130 podhd_destruct(interface);
132 return err;
136 POD HD device disconnected.
138 void line6_podhd_disconnect(struct usb_interface *interface)
140 struct usb_line6_podhd *podhd;
142 if (interface == NULL)
143 return;
144 podhd = usb_get_intfdata(interface);
146 if (podhd != NULL) {
147 struct snd_line6_pcm *line6pcm = podhd->line6.line6pcm;
149 if (line6pcm != NULL)
150 line6_pcm_disconnect(line6pcm);
153 podhd_destruct(interface);