Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Conexant Cx231xx audio extension |
| 3 | * |
| 4 | * Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
| 5 | * Based on em28xx driver |
| 6 | * |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
Mauro Carvalho Chehab | 589dadf | 2014-11-01 08:09:44 -0300 | [diff] [blame] | 23 | #include "cx231xx.h" |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/sound.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/soundcard.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/vmalloc.h> |
| 31 | #include <linux/proc_fs.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <sound/core.h> |
| 34 | #include <sound/pcm.h> |
| 35 | #include <sound/pcm_params.h> |
| 36 | #include <sound/info.h> |
| 37 | #include <sound/initval.h> |
| 38 | #include <sound/control.h> |
| 39 | #include <media/v4l2-common.h> |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 40 | |
| 41 | static int debug; |
| 42 | module_param(debug, int, 0644); |
| 43 | MODULE_PARM_DESC(debug, "activates debug info"); |
| 44 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 45 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 46 | |
| 47 | static int cx231xx_isoc_audio_deinit(struct cx231xx *dev) |
| 48 | { |
| 49 | int i; |
| 50 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 51 | dev_dbg(dev->dev, "Stopping isoc\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 52 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 53 | for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 54 | if (dev->adev.urb[i]) { |
| 55 | if (!irqs_disabled()) |
| 56 | usb_kill_urb(dev->adev.urb[i]); |
| 57 | else |
| 58 | usb_unlink_urb(dev->adev.urb[i]); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 59 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 60 | usb_free_urb(dev->adev.urb[i]); |
| 61 | dev->adev.urb[i] = NULL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 62 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 63 | kfree(dev->adev.transfer_buffer[i]); |
| 64 | dev->adev.transfer_buffer[i] = NULL; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 65 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 71 | static int cx231xx_bulk_audio_deinit(struct cx231xx *dev) |
| 72 | { |
| 73 | int i; |
| 74 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 75 | dev_dbg(dev->dev, "Stopping bulk\n"); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 76 | |
| 77 | for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { |
| 78 | if (dev->adev.urb[i]) { |
| 79 | if (!irqs_disabled()) |
| 80 | usb_kill_urb(dev->adev.urb[i]); |
| 81 | else |
| 82 | usb_unlink_urb(dev->adev.urb[i]); |
| 83 | |
| 84 | usb_free_urb(dev->adev.urb[i]); |
| 85 | dev->adev.urb[i] = NULL; |
| 86 | |
| 87 | kfree(dev->adev.transfer_buffer[i]); |
| 88 | dev->adev.transfer_buffer[i] = NULL; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 95 | static void cx231xx_audio_isocirq(struct urb *urb) |
| 96 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 97 | struct cx231xx *dev = urb->context; |
| 98 | int i; |
| 99 | unsigned int oldptr; |
| 100 | int period_elapsed = 0; |
| 101 | int status; |
| 102 | unsigned char *cp; |
| 103 | unsigned int stride; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 104 | struct snd_pcm_substream *substream; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 105 | struct snd_pcm_runtime *runtime; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 106 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 107 | if (dev->state & DEV_DISCONNECTED) |
| 108 | return; |
| 109 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 110 | switch (urb->status) { |
| 111 | case 0: /* success */ |
| 112 | case -ETIMEDOUT: /* NAK */ |
| 113 | break; |
| 114 | case -ECONNRESET: /* kill */ |
| 115 | case -ENOENT: |
| 116 | case -ESHUTDOWN: |
| 117 | return; |
| 118 | default: /* error */ |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 119 | dev_dbg(dev->dev, "urb completition error %d.\n", |
Mauro Carvalho Chehab | 56d8a3b | 2014-11-02 07:44:47 -0300 | [diff] [blame] | 120 | urb->status); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 121 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 122 | } |
| 123 | |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 124 | if (atomic_read(&dev->stream_started) == 0) |
| 125 | return; |
| 126 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 127 | if (dev->adev.capture_pcm_substream) { |
| 128 | substream = dev->adev.capture_pcm_substream; |
| 129 | runtime = substream->runtime; |
| 130 | stride = runtime->frame_bits >> 3; |
| 131 | |
| 132 | for (i = 0; i < urb->number_of_packets; i++) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 133 | int length = urb->iso_frame_desc[i].actual_length / |
| 134 | stride; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 135 | cp = (unsigned char *)urb->transfer_buffer + |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 136 | urb->iso_frame_desc[i].offset; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 137 | |
| 138 | if (!length) |
| 139 | continue; |
| 140 | |
| 141 | oldptr = dev->adev.hwptr_done_capture; |
| 142 | if (oldptr + length >= runtime->buffer_size) { |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 143 | unsigned int cnt; |
| 144 | |
| 145 | cnt = runtime->buffer_size - oldptr; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 146 | memcpy(runtime->dma_area + oldptr * stride, cp, |
| 147 | cnt * stride); |
| 148 | memcpy(runtime->dma_area, cp + cnt * stride, |
| 149 | length * stride - cnt * stride); |
| 150 | } else { |
| 151 | memcpy(runtime->dma_area + oldptr * stride, cp, |
| 152 | length * stride); |
| 153 | } |
| 154 | |
| 155 | snd_pcm_stream_lock(substream); |
| 156 | |
| 157 | dev->adev.hwptr_done_capture += length; |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 158 | if (dev->adev.hwptr_done_capture >= |
| 159 | runtime->buffer_size) |
| 160 | dev->adev.hwptr_done_capture -= |
| 161 | runtime->buffer_size; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 162 | |
| 163 | dev->adev.capture_transfer_done += length; |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 164 | if (dev->adev.capture_transfer_done >= |
| 165 | runtime->period_size) { |
| 166 | dev->adev.capture_transfer_done -= |
| 167 | runtime->period_size; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 168 | period_elapsed = 1; |
| 169 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 170 | snd_pcm_stream_unlock(substream); |
| 171 | } |
| 172 | if (period_elapsed) |
| 173 | snd_pcm_period_elapsed(substream); |
| 174 | } |
| 175 | urb->status = 0; |
| 176 | |
| 177 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 178 | if (status < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 179 | dev_err(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 180 | "resubmit of audio urb failed (error=%i)\n", |
| 181 | status); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 182 | } |
| 183 | return; |
| 184 | } |
| 185 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 186 | static void cx231xx_audio_bulkirq(struct urb *urb) |
| 187 | { |
| 188 | struct cx231xx *dev = urb->context; |
| 189 | unsigned int oldptr; |
| 190 | int period_elapsed = 0; |
| 191 | int status; |
| 192 | unsigned char *cp; |
| 193 | unsigned int stride; |
| 194 | struct snd_pcm_substream *substream; |
| 195 | struct snd_pcm_runtime *runtime; |
| 196 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 197 | if (dev->state & DEV_DISCONNECTED) |
| 198 | return; |
| 199 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 200 | switch (urb->status) { |
| 201 | case 0: /* success */ |
| 202 | case -ETIMEDOUT: /* NAK */ |
| 203 | break; |
| 204 | case -ECONNRESET: /* kill */ |
| 205 | case -ENOENT: |
| 206 | case -ESHUTDOWN: |
| 207 | return; |
| 208 | default: /* error */ |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 209 | dev_dbg(dev->dev, "urb completition error %d.\n", |
Mauro Carvalho Chehab | 56d8a3b | 2014-11-02 07:44:47 -0300 | [diff] [blame] | 210 | urb->status); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 211 | break; |
| 212 | } |
| 213 | |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 214 | if (atomic_read(&dev->stream_started) == 0) |
| 215 | return; |
| 216 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 217 | if (dev->adev.capture_pcm_substream) { |
| 218 | substream = dev->adev.capture_pcm_substream; |
| 219 | runtime = substream->runtime; |
| 220 | stride = runtime->frame_bits >> 3; |
| 221 | |
| 222 | if (1) { |
| 223 | int length = urb->actual_length / |
| 224 | stride; |
| 225 | cp = (unsigned char *)urb->transfer_buffer; |
| 226 | |
| 227 | oldptr = dev->adev.hwptr_done_capture; |
| 228 | if (oldptr + length >= runtime->buffer_size) { |
| 229 | unsigned int cnt; |
| 230 | |
| 231 | cnt = runtime->buffer_size - oldptr; |
| 232 | memcpy(runtime->dma_area + oldptr * stride, cp, |
| 233 | cnt * stride); |
| 234 | memcpy(runtime->dma_area, cp + cnt * stride, |
| 235 | length * stride - cnt * stride); |
| 236 | } else { |
| 237 | memcpy(runtime->dma_area + oldptr * stride, cp, |
| 238 | length * stride); |
| 239 | } |
| 240 | |
| 241 | snd_pcm_stream_lock(substream); |
| 242 | |
| 243 | dev->adev.hwptr_done_capture += length; |
| 244 | if (dev->adev.hwptr_done_capture >= |
| 245 | runtime->buffer_size) |
| 246 | dev->adev.hwptr_done_capture -= |
| 247 | runtime->buffer_size; |
| 248 | |
| 249 | dev->adev.capture_transfer_done += length; |
| 250 | if (dev->adev.capture_transfer_done >= |
| 251 | runtime->period_size) { |
| 252 | dev->adev.capture_transfer_done -= |
| 253 | runtime->period_size; |
| 254 | period_elapsed = 1; |
| 255 | } |
| 256 | snd_pcm_stream_unlock(substream); |
| 257 | } |
| 258 | if (period_elapsed) |
| 259 | snd_pcm_period_elapsed(substream); |
| 260 | } |
| 261 | urb->status = 0; |
| 262 | |
| 263 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 264 | if (status < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 265 | dev_err(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 266 | "resubmit of audio urb failed (error=%i)\n", |
| 267 | status); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 268 | } |
| 269 | return; |
| 270 | } |
| 271 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 272 | static int cx231xx_init_audio_isoc(struct cx231xx *dev) |
| 273 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 274 | int i, errCode; |
| 275 | int sb_size; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 276 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 277 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 278 | "%s: Starting ISO AUDIO transfers\n", __func__); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 279 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 280 | if (dev->state & DEV_DISCONNECTED) |
| 281 | return -ENODEV; |
| 282 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 283 | sb_size = CX231XX_ISO_NUM_AUDIO_PACKETS * dev->adev.max_pkt_size; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 284 | |
| 285 | for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { |
| 286 | struct urb *urb; |
| 287 | int j, k; |
| 288 | |
| 289 | dev->adev.transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC); |
| 290 | if (!dev->adev.transfer_buffer[i]) |
| 291 | return -ENOMEM; |
| 292 | |
| 293 | memset(dev->adev.transfer_buffer[i], 0x80, sb_size); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 294 | urb = usb_alloc_urb(CX231XX_ISO_NUM_AUDIO_PACKETS, GFP_ATOMIC); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 295 | if (!urb) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 296 | dev_err(dev->dev, "usb_alloc_urb failed!\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 297 | for (j = 0; j < i; j++) { |
| 298 | usb_free_urb(dev->adev.urb[j]); |
| 299 | kfree(dev->adev.transfer_buffer[j]); |
| 300 | } |
| 301 | return -ENOMEM; |
| 302 | } |
| 303 | |
| 304 | urb->dev = dev->udev; |
| 305 | urb->context = dev; |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 306 | urb->pipe = usb_rcvisocpipe(dev->udev, |
| 307 | dev->adev.end_point_addr); |
David Dillow | cd5534b | 2012-06-18 00:15:21 -0300 | [diff] [blame] | 308 | urb->transfer_flags = URB_ISO_ASAP; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 309 | urb->transfer_buffer = dev->adev.transfer_buffer[i]; |
| 310 | urb->interval = 1; |
| 311 | urb->complete = cx231xx_audio_isocirq; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 312 | urb->number_of_packets = CX231XX_ISO_NUM_AUDIO_PACKETS; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 313 | urb->transfer_buffer_length = sb_size; |
| 314 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 315 | for (j = k = 0; j < CX231XX_ISO_NUM_AUDIO_PACKETS; |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 316 | j++, k += dev->adev.max_pkt_size) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 317 | urb->iso_frame_desc[j].offset = k; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 318 | urb->iso_frame_desc[j].length = dev->adev.max_pkt_size; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 319 | } |
| 320 | dev->adev.urb[i] = urb; |
| 321 | } |
| 322 | |
| 323 | for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { |
| 324 | errCode = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC); |
| 325 | if (errCode < 0) { |
| 326 | cx231xx_isoc_audio_deinit(dev); |
| 327 | return errCode; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | return errCode; |
| 332 | } |
| 333 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 334 | static int cx231xx_init_audio_bulk(struct cx231xx *dev) |
| 335 | { |
| 336 | int i, errCode; |
| 337 | int sb_size; |
| 338 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 339 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 340 | "%s: Starting BULK AUDIO transfers\n", __func__); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 341 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 342 | if (dev->state & DEV_DISCONNECTED) |
| 343 | return -ENODEV; |
| 344 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 345 | sb_size = CX231XX_NUM_AUDIO_PACKETS * dev->adev.max_pkt_size; |
| 346 | |
| 347 | for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { |
| 348 | struct urb *urb; |
| 349 | int j; |
| 350 | |
| 351 | dev->adev.transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC); |
| 352 | if (!dev->adev.transfer_buffer[i]) |
| 353 | return -ENOMEM; |
| 354 | |
| 355 | memset(dev->adev.transfer_buffer[i], 0x80, sb_size); |
| 356 | urb = usb_alloc_urb(CX231XX_NUM_AUDIO_PACKETS, GFP_ATOMIC); |
| 357 | if (!urb) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 358 | dev_err(dev->dev, "usb_alloc_urb failed!\n"); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 359 | for (j = 0; j < i; j++) { |
| 360 | usb_free_urb(dev->adev.urb[j]); |
| 361 | kfree(dev->adev.transfer_buffer[j]); |
| 362 | } |
| 363 | return -ENOMEM; |
| 364 | } |
| 365 | |
| 366 | urb->dev = dev->udev; |
| 367 | urb->context = dev; |
| 368 | urb->pipe = usb_rcvbulkpipe(dev->udev, |
| 369 | dev->adev.end_point_addr); |
David Dillow | cd5534b | 2012-06-18 00:15:21 -0300 | [diff] [blame] | 370 | urb->transfer_flags = 0; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 371 | urb->transfer_buffer = dev->adev.transfer_buffer[i]; |
| 372 | urb->complete = cx231xx_audio_bulkirq; |
| 373 | urb->transfer_buffer_length = sb_size; |
| 374 | |
| 375 | dev->adev.urb[i] = urb; |
| 376 | |
| 377 | } |
| 378 | |
| 379 | for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { |
| 380 | errCode = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC); |
| 381 | if (errCode < 0) { |
| 382 | cx231xx_bulk_audio_deinit(dev); |
| 383 | return errCode; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | return errCode; |
| 388 | } |
| 389 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 390 | static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, |
| 391 | size_t size) |
| 392 | { |
| 393 | struct snd_pcm_runtime *runtime = subs->runtime; |
Mauro Carvalho Chehab | 56d8a3b | 2014-11-02 07:44:47 -0300 | [diff] [blame] | 394 | struct cx231xx *dev = snd_pcm_substream_chip(subs); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 395 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 396 | dev_dbg(dev->dev, "Allocating vbuffer\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 397 | if (runtime->dma_area) { |
| 398 | if (runtime->dma_bytes > size) |
| 399 | return 0; |
| 400 | |
| 401 | vfree(runtime->dma_area); |
| 402 | } |
| 403 | runtime->dma_area = vmalloc(size); |
| 404 | if (!runtime->dma_area) |
| 405 | return -ENOMEM; |
| 406 | |
| 407 | runtime->dma_bytes = size; |
| 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static struct snd_pcm_hardware snd_cx231xx_hw_capture = { |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 413 | .info = SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 414 | SNDRV_PCM_INFO_MMAP | |
| 415 | SNDRV_PCM_INFO_INTERLEAVED | |
| 416 | SNDRV_PCM_INFO_MMAP_VALID, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 417 | |
| 418 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 419 | |
| 420 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_KNOT, |
| 421 | |
| 422 | .rate_min = 48000, |
| 423 | .rate_max = 48000, |
| 424 | .channels_min = 2, |
| 425 | .channels_max = 2, |
| 426 | .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */ |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 427 | .period_bytes_min = 64, /* 12544/2, */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 428 | .period_bytes_max = 12544, |
| 429 | .periods_min = 2, |
Mauro Carvalho Chehab | cde4362 | 2009-03-03 13:31:36 -0300 | [diff] [blame] | 430 | .periods_max = 98, /* 12544, */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | static int snd_cx231xx_capture_open(struct snd_pcm_substream *substream) |
| 434 | { |
| 435 | struct cx231xx *dev = snd_pcm_substream_chip(substream); |
| 436 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 437 | int ret = 0; |
| 438 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 439 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | 56d8a3b | 2014-11-02 07:44:47 -0300 | [diff] [blame] | 440 | "opening device and trying to acquire exclusive lock\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 441 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 442 | if (dev->state & DEV_DISCONNECTED) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 443 | dev_err(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 444 | "Can't open. the device was removed.\n"); |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 445 | return -ENODEV; |
| 446 | } |
| 447 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 448 | /* set alternate setting for audio interface */ |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 449 | /* 1 - 48000 samples per sec */ |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 450 | mutex_lock(&dev->lock); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 451 | if (dev->USE_ISO) |
| 452 | ret = cx231xx_set_alt_setting(dev, INDEX_AUDIO, 1); |
| 453 | else |
| 454 | ret = cx231xx_set_alt_setting(dev, INDEX_AUDIO, 0); |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 455 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 456 | if (ret < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 457 | dev_err(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 458 | "failed to set alternate setting !\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 459 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 460 | return ret; |
| 461 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 462 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 463 | runtime->hw = snd_cx231xx_hw_capture; |
| 464 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 465 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 466 | /* inform hardware to start streaming */ |
| 467 | ret = cx231xx_capture_start(dev, 1, Audio); |
| 468 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 469 | dev->adev.users++; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 470 | mutex_unlock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 471 | |
| 472 | snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); |
| 473 | dev->adev.capture_pcm_substream = substream; |
| 474 | runtime->private_data = dev; |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static int snd_cx231xx_pcm_close(struct snd_pcm_substream *substream) |
| 480 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 481 | int ret; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 482 | struct cx231xx *dev = snd_pcm_substream_chip(substream); |
| 483 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 484 | dev_dbg(dev->dev, "closing device\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 485 | |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 486 | /* inform hardware to stop streaming */ |
| 487 | mutex_lock(&dev->lock); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 488 | ret = cx231xx_capture_start(dev, 0, Audio); |
| 489 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 490 | /* set alternate setting for audio interface */ |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 491 | /* 1 - 48000 samples per sec */ |
| 492 | ret = cx231xx_set_alt_setting(dev, INDEX_AUDIO, 0); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 493 | if (ret < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 494 | dev_err(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 495 | "failed to set alternate setting !\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 496 | |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 497 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 498 | return ret; |
| 499 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 500 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 501 | dev->adev.users--; |
Jean-Baptiste Theou | 9dd7344 | 2016-01-08 20:02:03 -0200 | [diff] [blame] | 502 | if (substream->runtime->dma_area) { |
| 503 | dev_dbg(dev->dev, "freeing\n"); |
| 504 | vfree(substream->runtime->dma_area); |
| 505 | substream->runtime->dma_area = NULL; |
| 506 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 507 | mutex_unlock(&dev->lock); |
| 508 | |
| 509 | if (dev->adev.users == 0 && dev->adev.shutdown == 1) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 510 | dev_dbg(dev->dev, "audio users: %d\n", dev->adev.users); |
| 511 | dev_dbg(dev->dev, "disabling audio stream!\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 512 | dev->adev.shutdown = 0; |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 513 | dev_dbg(dev->dev, "released lock\n"); |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 514 | if (atomic_read(&dev->stream_started) > 0) { |
| 515 | atomic_set(&dev->stream_started, 0); |
| 516 | schedule_work(&dev->wq_trigger); |
| 517 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 518 | } |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static int snd_cx231xx_hw_capture_params(struct snd_pcm_substream *substream, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 523 | struct snd_pcm_hw_params *hw_params) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 524 | { |
Mauro Carvalho Chehab | 56d8a3b | 2014-11-02 07:44:47 -0300 | [diff] [blame] | 525 | struct cx231xx *dev = snd_pcm_substream_chip(substream); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 526 | int ret; |
| 527 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 528 | dev_dbg(dev->dev, "Setting capture parameters\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 529 | |
| 530 | ret = snd_pcm_alloc_vmalloc_buffer(substream, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 531 | params_buffer_bytes(hw_params)); |
Hans Verkuil | da98350 | 2012-05-14 10:14:53 -0300 | [diff] [blame] | 532 | #if 0 |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 533 | /* TODO: set up cx231xx audio chip to deliver the correct audio format, |
| 534 | current default is 48000hz multiplexed => 96000hz mono |
| 535 | which shouldn't matter since analogue TV only supports mono */ |
Hans Verkuil | da98350 | 2012-05-14 10:14:53 -0300 | [diff] [blame] | 536 | unsigned int channels, rate, format; |
| 537 | |
| 538 | format = params_format(hw_params); |
| 539 | rate = params_rate(hw_params); |
| 540 | channels = params_channels(hw_params); |
| 541 | #endif |
| 542 | |
| 543 | return ret; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static int snd_cx231xx_hw_capture_free(struct snd_pcm_substream *substream) |
| 547 | { |
| 548 | struct cx231xx *dev = snd_pcm_substream_chip(substream); |
| 549 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 550 | dev_dbg(dev->dev, "Stop capture, if needed\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 551 | |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 552 | if (atomic_read(&dev->stream_started) > 0) { |
| 553 | atomic_set(&dev->stream_started, 0); |
| 554 | schedule_work(&dev->wq_trigger); |
| 555 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | static int snd_cx231xx_prepare(struct snd_pcm_substream *substream) |
| 561 | { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 562 | struct cx231xx *dev = snd_pcm_substream_chip(substream); |
| 563 | |
| 564 | dev->adev.hwptr_done_capture = 0; |
| 565 | dev->adev.capture_transfer_done = 0; |
| 566 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 570 | static void audio_trigger(struct work_struct *work) |
| 571 | { |
| 572 | struct cx231xx *dev = container_of(work, struct cx231xx, wq_trigger); |
| 573 | |
| 574 | if (atomic_read(&dev->stream_started)) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 575 | dev_dbg(dev->dev, "starting capture"); |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 576 | if (is_fw_load(dev) == 0) |
| 577 | cx25840_call(dev, core, load_fw); |
| 578 | if (dev->USE_ISO) |
| 579 | cx231xx_init_audio_isoc(dev); |
| 580 | else |
| 581 | cx231xx_init_audio_bulk(dev); |
| 582 | } else { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 583 | dev_dbg(dev->dev, "stopping capture"); |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 584 | cx231xx_isoc_audio_deinit(dev); |
| 585 | } |
| 586 | } |
| 587 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 588 | static int snd_cx231xx_capture_trigger(struct snd_pcm_substream *substream, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 589 | int cmd) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 590 | { |
| 591 | struct cx231xx *dev = snd_pcm_substream_chip(substream); |
Hans Verkuil | da98350 | 2012-05-14 10:14:53 -0300 | [diff] [blame] | 592 | int retval = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 593 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 594 | if (dev->state & DEV_DISCONNECTED) |
| 595 | return -ENODEV; |
| 596 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 597 | spin_lock(&dev->adev.slock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 598 | switch (cmd) { |
| 599 | case SNDRV_PCM_TRIGGER_START: |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 600 | atomic_set(&dev->stream_started, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 601 | break; |
| 602 | case SNDRV_PCM_TRIGGER_STOP: |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 603 | atomic_set(&dev->stream_started, 0); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 604 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 605 | default: |
| 606 | retval = -EINVAL; |
Hans Verkuil | da98350 | 2012-05-14 10:14:53 -0300 | [diff] [blame] | 607 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 608 | } |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 609 | spin_unlock(&dev->adev.slock); |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 610 | |
| 611 | schedule_work(&dev->wq_trigger); |
| 612 | |
Hans Verkuil | da98350 | 2012-05-14 10:14:53 -0300 | [diff] [blame] | 613 | return retval; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static snd_pcm_uframes_t snd_cx231xx_capture_pointer(struct snd_pcm_substream |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 617 | *substream) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 618 | { |
| 619 | struct cx231xx *dev; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 620 | unsigned long flags; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 621 | snd_pcm_uframes_t hwptr_done; |
| 622 | |
| 623 | dev = snd_pcm_substream_chip(substream); |
| 624 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 625 | spin_lock_irqsave(&dev->adev.slock, flags); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 626 | hwptr_done = dev->adev.hwptr_done_capture; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 627 | spin_unlock_irqrestore(&dev->adev.slock, flags); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 628 | |
| 629 | return hwptr_done; |
| 630 | } |
| 631 | |
| 632 | static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs, |
| 633 | unsigned long offset) |
| 634 | { |
| 635 | void *pageptr = subs->runtime->dma_area + offset; |
| 636 | |
| 637 | return vmalloc_to_page(pageptr); |
| 638 | } |
| 639 | |
| 640 | static struct snd_pcm_ops snd_cx231xx_pcm_capture = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 641 | .open = snd_cx231xx_capture_open, |
| 642 | .close = snd_cx231xx_pcm_close, |
| 643 | .ioctl = snd_pcm_lib_ioctl, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 644 | .hw_params = snd_cx231xx_hw_capture_params, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 645 | .hw_free = snd_cx231xx_hw_capture_free, |
| 646 | .prepare = snd_cx231xx_prepare, |
| 647 | .trigger = snd_cx231xx_capture_trigger, |
| 648 | .pointer = snd_cx231xx_capture_pointer, |
| 649 | .page = snd_pcm_get_vmalloc_page, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 650 | }; |
| 651 | |
| 652 | static int cx231xx_audio_init(struct cx231xx *dev) |
| 653 | { |
| 654 | struct cx231xx_audio *adev = &dev->adev; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 655 | struct snd_pcm *pcm; |
| 656 | struct snd_card *card; |
| 657 | static int devnr; |
| 658 | int err; |
| 659 | struct usb_interface *uif; |
| 660 | int i, isoc_pipe = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 661 | |
| 662 | if (dev->has_alsa_audio != 1) { |
| 663 | /* This device does not support the extension (in this case |
| 664 | the device is expecting the snd-usb-audio module or |
| 665 | doesn't have analog audio support at all) */ |
| 666 | return 0; |
| 667 | } |
| 668 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 669 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 670 | "probing for cx231xx non standard usbaudio\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 671 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 672 | err = snd_card_new(dev->dev, index[devnr], "Cx231xx Audio", |
Takashi Iwai | e735688 | 2014-01-29 14:48:43 +0100 | [diff] [blame] | 673 | THIS_MODULE, 0, &card); |
Mauro Carvalho Chehab | a938b8c | 2009-04-06 21:25:29 -0300 | [diff] [blame] | 674 | if (err < 0) |
| 675 | return err; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 676 | |
| 677 | spin_lock_init(&adev->slock); |
| 678 | err = snd_pcm_new(card, "Cx231xx Audio", 0, 0, 1, &pcm); |
| 679 | if (err < 0) { |
| 680 | snd_card_free(card); |
| 681 | return err; |
| 682 | } |
| 683 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 684 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 685 | &snd_cx231xx_pcm_capture); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 686 | pcm->info_flags = 0; |
| 687 | pcm->private_data = dev; |
| 688 | strcpy(pcm->name, "Conexant cx231xx Capture"); |
Dan Carpenter | 935539c | 2010-03-22 12:39:09 -0300 | [diff] [blame] | 689 | strcpy(card->driver, "Cx231xx-Audio"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 690 | strcpy(card->shortname, "Cx231xx Audio"); |
| 691 | strcpy(card->longname, "Conexant cx231xx Audio"); |
| 692 | |
Mauro Carvalho Chehab | 61b04cb | 2010-09-27 03:07:22 -0300 | [diff] [blame] | 693 | INIT_WORK(&dev->wq_trigger, audio_trigger); |
| 694 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 695 | err = snd_card_register(card); |
| 696 | if (err < 0) { |
| 697 | snd_card_free(card); |
| 698 | return err; |
| 699 | } |
| 700 | adev->sndcard = card; |
| 701 | adev->udev = dev->udev; |
| 702 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 703 | /* compute alternate max packet sizes for Audio */ |
| 704 | uif = |
| 705 | dev->udev->actconfig->interface[dev->current_pcb_config. |
| 706 | hs_config_info[0].interface_info. |
| 707 | audio_index + 1]; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 708 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 709 | adev->end_point_addr = |
Hans Verkuil | 69a11a3 | 2013-02-07 15:28:53 -0300 | [diff] [blame] | 710 | uif->altsetting[0].endpoint[isoc_pipe].desc. |
| 711 | bEndpointAddress; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 712 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 713 | adev->num_alt = uif->num_altsetting; |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 714 | dev_info(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 715 | "audio EndPoint Addr 0x%x, Alternate settings: %i\n", |
Mauro Carvalho Chehab | ed0e372 | 2014-11-01 08:59:03 -0300 | [diff] [blame] | 716 | adev->end_point_addr, adev->num_alt); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 717 | adev->alt_max_pkt_size = kmalloc(32 * adev->num_alt, GFP_KERNEL); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 718 | |
Mauro Carvalho Chehab | ed0e372 | 2014-11-01 08:59:03 -0300 | [diff] [blame] | 719 | if (adev->alt_max_pkt_size == NULL) |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 720 | return -ENOMEM; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 721 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 722 | for (i = 0; i < adev->num_alt; i++) { |
| 723 | u16 tmp = |
| 724 | le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc. |
| 725 | wMaxPacketSize); |
| 726 | adev->alt_max_pkt_size[i] = |
| 727 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 728 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 729 | "audio alternate setting %i, max size= %i\n", i, |
| 730 | adev->alt_max_pkt_size[i]); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 731 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 732 | |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | static int cx231xx_audio_fini(struct cx231xx *dev) |
| 737 | { |
| 738 | if (dev == NULL) |
| 739 | return 0; |
| 740 | |
| 741 | if (dev->has_alsa_audio != 1) { |
| 742 | /* This device does not support the extension (in this case |
| 743 | the device is expecting the snd-usb-audio module or |
| 744 | doesn't have analog audio support at all) */ |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | if (dev->adev.sndcard) { |
| 749 | snd_card_free(dev->adev.sndcard); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 750 | kfree(dev->adev.alt_max_pkt_size); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 751 | dev->adev.sndcard = NULL; |
| 752 | } |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | static struct cx231xx_ops audio_ops = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 758 | .id = CX231XX_AUDIO, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 759 | .name = "Cx231xx Audio Extension", |
| 760 | .init = cx231xx_audio_init, |
| 761 | .fini = cx231xx_audio_fini, |
| 762 | }; |
| 763 | |
| 764 | static int __init cx231xx_alsa_register(void) |
| 765 | { |
| 766 | return cx231xx_register_extension(&audio_ops); |
| 767 | } |
| 768 | |
| 769 | static void __exit cx231xx_alsa_unregister(void) |
| 770 | { |
| 771 | cx231xx_unregister_extension(&audio_ops); |
| 772 | } |
| 773 | |
| 774 | MODULE_LICENSE("GPL"); |
| 775 | MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>"); |
| 776 | MODULE_DESCRIPTION("Cx231xx Audio driver"); |
| 777 | |
| 778 | module_init(cx231xx_alsa_register); |
| 779 | module_exit(cx231xx_alsa_unregister); |