Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BRIEF MODULE DESCRIPTION |
| 3 | * Driver for AMD Au1000 MIPS Processor, AC'97 Sound Port |
| 4 | * |
| 5 | * Copyright 2004 Cooper Street Innovations Inc. |
| 6 | * Author: Charles Eidsness <charles@cooper-street.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 14 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 15 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 16 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 19 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License along |
| 25 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 26 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | * |
| 28 | * History: |
| 29 | * |
| 30 | * 2004-09-09 Charles Eidsness -- Original verion -- based on |
| 31 | * sa11xx-uda1341.c ALSA driver and the |
| 32 | * au1000.c OSS driver. |
| 33 | * 2004-09-09 Matt Porter -- Added support for ALSA 1.0.6 |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | #include <linux/ioport.h> |
| 38 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/init.h> |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 40 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/slab.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 42 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <sound/core.h> |
| 44 | #include <sound/initval.h> |
| 45 | #include <sound/pcm.h> |
Sergei Shtylylov | d8327c7 | 2006-03-20 18:38:21 +0100 | [diff] [blame] | 46 | #include <sound/pcm_params.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <sound/ac97_codec.h> |
| 48 | #include <asm/mach-au1x00/au1000.h> |
| 49 | #include <asm/mach-au1x00/au1000_dma.h> |
| 50 | |
| 51 | MODULE_AUTHOR("Charles Eidsness <charles@cooper-street.com>"); |
| 52 | MODULE_DESCRIPTION("Au1000 AC'97 ALSA Driver"); |
| 53 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | MODULE_SUPPORTED_DEVICE("{{AMD,Au1000 AC'97}}"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define PLAYBACK 0 |
| 57 | #define CAPTURE 1 |
| 58 | #define AC97_SLOT_3 0x01 |
| 59 | #define AC97_SLOT_4 0x02 |
| 60 | #define AC97_SLOT_6 0x08 |
| 61 | #define AC97_CMD_IRQ 31 |
| 62 | #define READ 0 |
| 63 | #define WRITE 1 |
| 64 | #define READ_WAIT 2 |
| 65 | #define RW_DONE 3 |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | struct au1000_period |
| 68 | { |
| 69 | u32 start; |
| 70 | u32 relative_end; /*realtive to start of buffer*/ |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 71 | struct au1000_period * next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /*Au1000 AC97 Port Control Reisters*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | struct au1000_ac97_reg { |
| 76 | u32 volatile config; |
| 77 | u32 volatile status; |
| 78 | u32 volatile data; |
| 79 | u32 volatile cmd; |
| 80 | u32 volatile cntrl; |
| 81 | }; |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | struct audio_stream { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 84 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | int dma; |
| 86 | spinlock_t dma_lock; |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 87 | struct au1000_period * buffer; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 88 | unsigned int period_size; |
| 89 | unsigned int periods; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 92 | struct snd_au1000 { |
| 93 | struct snd_card *card; |
| 94 | struct au1000_ac97_reg volatile *ac97_ioport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | struct resource *ac97_res_port; |
| 97 | spinlock_t ac97_lock; |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 98 | struct snd_ac97 *ac97; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 100 | struct snd_pcm *pcm; |
| 101 | struct audio_stream *stream[2]; /* playback & capture */ |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 102 | int dmaid[2]; /* tx(0)/rx(1) DMA ids */ |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 103 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /*--------------------------- Local Functions --------------------------------*/ |
| 106 | static void |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 107 | au1000_set_ac97_xmit_slots(struct snd_au1000 *au1000, long xmit_slots) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
| 109 | u32 volatile ac97_config; |
| 110 | |
| 111 | spin_lock(&au1000->ac97_lock); |
| 112 | ac97_config = au1000->ac97_ioport->config; |
| 113 | ac97_config = ac97_config & ~AC97C_XMIT_SLOTS_MASK; |
| 114 | ac97_config |= (xmit_slots << AC97C_XMIT_SLOTS_BIT); |
| 115 | au1000->ac97_ioport->config = ac97_config; |
| 116 | spin_unlock(&au1000->ac97_lock); |
| 117 | } |
| 118 | |
| 119 | static void |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 120 | au1000_set_ac97_recv_slots(struct snd_au1000 *au1000, long recv_slots) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
| 122 | u32 volatile ac97_config; |
| 123 | |
| 124 | spin_lock(&au1000->ac97_lock); |
| 125 | ac97_config = au1000->ac97_ioport->config; |
| 126 | ac97_config = ac97_config & ~AC97C_RECV_SLOTS_MASK; |
| 127 | ac97_config |= (recv_slots << AC97C_RECV_SLOTS_BIT); |
| 128 | au1000->ac97_ioport->config = ac97_config; |
| 129 | spin_unlock(&au1000->ac97_lock); |
| 130 | } |
| 131 | |
| 132 | |
| 133 | static void |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 134 | au1000_release_dma_link(struct audio_stream *stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 136 | struct au1000_period * pointer; |
| 137 | struct au1000_period * pointer_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 139 | stream->period_size = 0; |
| 140 | stream->periods = 0; |
| 141 | pointer = stream->buffer; |
| 142 | if (! pointer) |
| 143 | return; |
| 144 | do { |
| 145 | pointer_next = pointer->next; |
| 146 | kfree(pointer); |
| 147 | pointer = pointer_next; |
| 148 | } while (pointer != stream->buffer); |
| 149 | stream->buffer = NULL; |
| 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 152 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 153 | au1000_setup_dma_link(struct audio_stream *stream, unsigned int period_bytes, |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 154 | unsigned int periods) |
| 155 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 156 | struct snd_pcm_substream *substream = stream->substream; |
| 157 | struct snd_pcm_runtime *runtime = substream->runtime; |
Sergei Shtylylov | d8327c7 | 2006-03-20 18:38:21 +0100 | [diff] [blame] | 158 | struct au1000_period *pointer; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 159 | unsigned long dma_start; |
| 160 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 162 | dma_start = virt_to_phys(runtime->dma_area); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 164 | if (stream->period_size == period_bytes && |
| 165 | stream->periods == periods) |
| 166 | return 0; /* not changed */ |
| 167 | |
| 168 | au1000_release_dma_link(stream); |
| 169 | |
| 170 | stream->period_size = period_bytes; |
| 171 | stream->periods = periods; |
| 172 | |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 173 | stream->buffer = kmalloc(sizeof(struct au1000_period), GFP_KERNEL); |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 174 | if (! stream->buffer) |
| 175 | return -ENOMEM; |
| 176 | pointer = stream->buffer; |
| 177 | for (i = 0; i < periods; i++) { |
| 178 | pointer->start = (u32)(dma_start + (i * period_bytes)); |
| 179 | pointer->relative_end = (u32) (((i+1) * period_bytes) - 0x1); |
| 180 | if (i < periods - 1) { |
| 181 | pointer->next = kmalloc(sizeof(struct au1000_period), GFP_KERNEL); |
| 182 | if (! pointer->next) { |
| 183 | au1000_release_dma_link(stream); |
| 184 | return -ENOMEM; |
| 185 | } |
| 186 | pointer = pointer->next; |
| 187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 189 | pointer->next = stream->buffer; |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static void |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 194 | au1000_dma_stop(struct audio_stream *stream) |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 195 | { |
Takashi Iwai | 5e246b8 | 2008-08-08 17:12:47 +0200 | [diff] [blame] | 196 | if (snd_BUG_ON(!stream->buffer)) |
| 197 | return; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 198 | disable_dma(stream->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static void |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 202 | au1000_dma_start(struct audio_stream *stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Takashi Iwai | 5e246b8 | 2008-08-08 17:12:47 +0200 | [diff] [blame] | 204 | if (snd_BUG_ON(!stream->buffer)) |
| 205 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 207 | init_dma(stream->dma); |
| 208 | if (get_dma_active_buffer(stream->dma) == 0) { |
| 209 | clear_dma_done0(stream->dma); |
| 210 | set_dma_addr0(stream->dma, stream->buffer->start); |
| 211 | set_dma_count0(stream->dma, stream->period_size >> 1); |
| 212 | set_dma_addr1(stream->dma, stream->buffer->next->start); |
| 213 | set_dma_count1(stream->dma, stream->period_size >> 1); |
| 214 | } else { |
| 215 | clear_dma_done1(stream->dma); |
| 216 | set_dma_addr1(stream->dma, stream->buffer->start); |
| 217 | set_dma_count1(stream->dma, stream->period_size >> 1); |
| 218 | set_dma_addr0(stream->dma, stream->buffer->next->start); |
| 219 | set_dma_count0(stream->dma, stream->period_size >> 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 221 | enable_dma_buffers(stream->dma); |
| 222 | start_dma(stream->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 226 | au1000_dma_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 228 | struct audio_stream *stream = (struct audio_stream *) dev_id; |
| 229 | struct snd_pcm_substream *substream = stream->substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
| 231 | spin_lock(&stream->dma_lock); |
| 232 | switch (get_dma_buffer_done(stream->dma)) { |
| 233 | case DMA_D0: |
| 234 | stream->buffer = stream->buffer->next; |
| 235 | clear_dma_done0(stream->dma); |
| 236 | set_dma_addr0(stream->dma, stream->buffer->next->start); |
| 237 | set_dma_count0(stream->dma, stream->period_size >> 1); |
| 238 | enable_dma_buffer0(stream->dma); |
| 239 | break; |
| 240 | case DMA_D1: |
| 241 | stream->buffer = stream->buffer->next; |
| 242 | clear_dma_done1(stream->dma); |
| 243 | set_dma_addr1(stream->dma, stream->buffer->next->start); |
| 244 | set_dma_count1(stream->dma, stream->period_size >> 1); |
| 245 | enable_dma_buffer1(stream->dma); |
| 246 | break; |
| 247 | case (DMA_D0 | DMA_D1): |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | printk(KERN_ERR "DMA %d missed interrupt.\n",stream->dma); |
| 249 | au1000_dma_stop(stream); |
| 250 | au1000_dma_start(stream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | break; |
| 252 | case (~DMA_D0 & ~DMA_D1): |
| 253 | printk(KERN_ERR "DMA %d empty irq.\n",stream->dma); |
| 254 | } |
| 255 | spin_unlock(&stream->dma_lock); |
| 256 | snd_pcm_period_elapsed(substream); |
| 257 | return IRQ_HANDLED; |
| 258 | } |
| 259 | |
| 260 | /*-------------------------- PCM Audio Streams -------------------------------*/ |
| 261 | |
| 262 | static unsigned int rates[] = {8000, 11025, 16000, 22050}; |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 263 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
Tobias Klauser | 2ad3479 | 2006-09-29 02:00:20 -0700 | [diff] [blame] | 264 | .count = ARRAY_SIZE(rates), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | .list = rates, |
| 266 | .mask = 0, |
| 267 | }; |
| 268 | |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 269 | static struct snd_pcm_hardware snd_au1000_hw = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
| 271 | .info = (SNDRV_PCM_INFO_INTERLEAVED | \ |
| 272 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID), |
| 273 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 274 | .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | |
| 275 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050), |
| 276 | .rate_min = 8000, |
| 277 | .rate_max = 22050, |
| 278 | .channels_min = 1, |
| 279 | .channels_max = 2, |
| 280 | .buffer_bytes_max = 128*1024, |
| 281 | .period_bytes_min = 32, |
| 282 | .period_bytes_max = 16*1024, |
| 283 | .periods_min = 8, |
| 284 | .periods_max = 255, |
| 285 | .fifo_size = 16, |
| 286 | }; |
| 287 | |
| 288 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 289 | snd_au1000_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 291 | struct snd_au1000 *au1000 = substream->pcm->private_data; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | au1000->stream[PLAYBACK]->substream = substream; |
| 294 | au1000->stream[PLAYBACK]->buffer = NULL; |
| 295 | substream->private_data = au1000->stream[PLAYBACK]; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 296 | substream->runtime->hw = snd_au1000_hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return (snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 298 | SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0); |
| 299 | } |
| 300 | |
| 301 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 302 | snd_au1000_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 304 | struct snd_au1000 *au1000 = substream->pcm->private_data; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | au1000->stream[CAPTURE]->substream = substream; |
| 307 | au1000->stream[CAPTURE]->buffer = NULL; |
| 308 | substream->private_data = au1000->stream[CAPTURE]; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 309 | substream->runtime->hw = snd_au1000_hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return (snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 311 | SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 315 | snd_au1000_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 317 | struct snd_au1000 *au1000 = substream->pcm->private_data; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | au1000->stream[PLAYBACK]->substream = NULL; |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 324 | snd_au1000_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 326 | struct snd_au1000 *au1000 = substream->pcm->private_data; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | au1000->stream[CAPTURE]->substream = NULL; |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 333 | snd_au1000_hw_params(struct snd_pcm_substream *substream, |
| 334 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 336 | struct audio_stream *stream = substream->private_data; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 337 | int err; |
| 338 | |
| 339 | err = snd_pcm_lib_malloc_pages(substream, |
| 340 | params_buffer_bytes(hw_params)); |
| 341 | if (err < 0) |
| 342 | return err; |
| 343 | return au1000_setup_dma_link(stream, |
| 344 | params_period_bytes(hw_params), |
| 345 | params_periods(hw_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 349 | snd_au1000_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 351 | struct audio_stream *stream = substream->private_data; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 352 | au1000_release_dma_link(stream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return snd_pcm_lib_free_pages(substream); |
| 354 | } |
| 355 | |
| 356 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 357 | snd_au1000_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 359 | struct snd_au1000 *au1000 = substream->pcm->private_data; |
| 360 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 362 | if (runtime->channels == 1) |
| 363 | au1000_set_ac97_xmit_slots(au1000, AC97_SLOT_4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | else |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 365 | au1000_set_ac97_xmit_slots(au1000, AC97_SLOT_3 | AC97_SLOT_4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | snd_ac97_set_rate(au1000->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 371 | snd_au1000_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 373 | struct snd_au1000 *au1000 = substream->pcm->private_data; |
| 374 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 376 | if (runtime->channels == 1) |
| 377 | au1000_set_ac97_recv_slots(au1000, AC97_SLOT_4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | else |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 379 | au1000_set_ac97_recv_slots(au1000, AC97_SLOT_3 | AC97_SLOT_4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | snd_ac97_set_rate(au1000->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 385 | snd_au1000_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 387 | struct audio_stream *stream = substream->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | int err = 0; |
| 389 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 390 | spin_lock(&stream->dma_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | switch (cmd) { |
| 392 | case SNDRV_PCM_TRIGGER_START: |
| 393 | au1000_dma_start(stream); |
| 394 | break; |
| 395 | case SNDRV_PCM_TRIGGER_STOP: |
| 396 | au1000_dma_stop(stream); |
| 397 | break; |
| 398 | default: |
| 399 | err = -EINVAL; |
| 400 | break; |
| 401 | } |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 402 | spin_unlock(&stream->dma_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return err; |
| 404 | } |
| 405 | |
| 406 | static snd_pcm_uframes_t |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 407 | snd_au1000_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 409 | struct audio_stream *stream = substream->private_data; |
| 410 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | long location; |
| 412 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 413 | spin_lock(&stream->dma_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | location = get_dma_residue(stream->dma); |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 415 | spin_unlock(&stream->dma_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | location = stream->buffer->relative_end - location; |
| 417 | if (location == -1) |
| 418 | location = 0; |
| 419 | return bytes_to_frames(runtime,location); |
| 420 | } |
| 421 | |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 422 | static struct snd_pcm_ops snd_card_au1000_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | .open = snd_au1000_playback_open, |
| 424 | .close = snd_au1000_playback_close, |
| 425 | .ioctl = snd_pcm_lib_ioctl, |
| 426 | .hw_params = snd_au1000_hw_params, |
| 427 | .hw_free = snd_au1000_hw_free, |
| 428 | .prepare = snd_au1000_playback_prepare, |
| 429 | .trigger = snd_au1000_trigger, |
| 430 | .pointer = snd_au1000_pointer, |
| 431 | }; |
| 432 | |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 433 | static struct snd_pcm_ops snd_card_au1000_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | .open = snd_au1000_capture_open, |
| 435 | .close = snd_au1000_capture_close, |
| 436 | .ioctl = snd_pcm_lib_ioctl, |
| 437 | .hw_params = snd_au1000_hw_params, |
| 438 | .hw_free = snd_au1000_hw_free, |
| 439 | .prepare = snd_au1000_capture_prepare, |
| 440 | .trigger = snd_au1000_trigger, |
| 441 | .pointer = snd_au1000_pointer, |
| 442 | }; |
| 443 | |
Bill Pemberton | e0f8cb5 | 2012-12-06 12:35:15 -0500 | [diff] [blame] | 444 | static int |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 445 | snd_au1000_pcm_new(struct snd_au1000 *au1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 447 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | int err; |
| 449 | unsigned long flags; |
| 450 | |
| 451 | if ((err = snd_pcm_new(au1000->card, "AU1000 AC97 PCM", 0, 1, 1, &pcm)) < 0) |
| 452 | return err; |
| 453 | |
| 454 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, |
| 455 | snd_dma_continuous_data(GFP_KERNEL), 128*1024, 128*1024); |
| 456 | |
| 457 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 458 | &snd_card_au1000_playback_ops); |
| 459 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 460 | &snd_card_au1000_capture_ops); |
| 461 | |
| 462 | pcm->private_data = au1000; |
| 463 | pcm->info_flags = 0; |
| 464 | strcpy(pcm->name, "Au1000 AC97 PCM"); |
| 465 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 466 | spin_lock_init(&au1000->stream[PLAYBACK]->dma_lock); |
| 467 | spin_lock_init(&au1000->stream[CAPTURE]->dma_lock); |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | flags = claim_dma_lock(); |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 470 | au1000->stream[PLAYBACK]->dma = request_au1000_dma(au1000->dmaid[0], |
Yong Zhang | 88e24c3 | 2011-09-22 16:59:20 +0800 | [diff] [blame] | 471 | "AC97 TX", au1000_dma_interrupt, 0, |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 472 | au1000->stream[PLAYBACK]); |
| 473 | if (au1000->stream[PLAYBACK]->dma < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | release_dma_lock(flags); |
| 475 | return -EBUSY; |
| 476 | } |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 477 | au1000->stream[CAPTURE]->dma = request_au1000_dma(au1000->dmaid[1], |
Yong Zhang | 88e24c3 | 2011-09-22 16:59:20 +0800 | [diff] [blame] | 478 | "AC97 RX", au1000_dma_interrupt, 0, |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 479 | au1000->stream[CAPTURE]); |
| 480 | if (au1000->stream[CAPTURE]->dma < 0){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | release_dma_lock(flags); |
| 482 | return -EBUSY; |
| 483 | } |
| 484 | /* enable DMA coherency in read/write DMA channels */ |
| 485 | set_dma_mode(au1000->stream[PLAYBACK]->dma, |
| 486 | get_dma_mode(au1000->stream[PLAYBACK]->dma) & ~DMA_NC); |
| 487 | set_dma_mode(au1000->stream[CAPTURE]->dma, |
| 488 | get_dma_mode(au1000->stream[CAPTURE]->dma) & ~DMA_NC); |
| 489 | release_dma_lock(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | au1000->pcm = pcm; |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | |
| 495 | /*-------------------------- AC97 CODEC Control ------------------------------*/ |
| 496 | |
| 497 | static unsigned short |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 498 | snd_au1000_ac97_read(struct snd_ac97 *ac97, unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 500 | struct snd_au1000 *au1000 = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | u32 volatile cmd; |
| 502 | u16 volatile data; |
| 503 | int i; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 504 | |
Konstantin Baydarov | 708f997 | 2005-10-27 17:25:02 +0200 | [diff] [blame] | 505 | spin_lock(&au1000->ac97_lock); |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 506 | /* would rather use the interrupt than this polling but it works and I can't |
| 507 | get the interrupt driven case to work efficiently */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | for (i = 0; i < 0x5000; i++) |
| 509 | if (!(au1000->ac97_ioport->status & AC97C_CP)) |
| 510 | break; |
| 511 | if (i == 0x5000) |
| 512 | printk(KERN_ERR "au1000 AC97: AC97 command read timeout\n"); |
| 513 | |
| 514 | cmd = (u32) reg & AC97C_INDEX_MASK; |
| 515 | cmd |= AC97C_READ; |
| 516 | au1000->ac97_ioport->cmd = cmd; |
| 517 | |
| 518 | /* now wait for the data */ |
| 519 | for (i = 0; i < 0x5000; i++) |
| 520 | if (!(au1000->ac97_ioport->status & AC97C_CP)) |
| 521 | break; |
| 522 | if (i == 0x5000) { |
| 523 | printk(KERN_ERR "au1000 AC97: AC97 command read timeout\n"); |
Julia Lawall | 1efddcc | 2010-05-26 17:59:27 +0200 | [diff] [blame] | 524 | spin_unlock(&au1000->ac97_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | data = au1000->ac97_ioport->cmd & 0xffff; |
Konstantin Baydarov | 708f997 | 2005-10-27 17:25:02 +0200 | [diff] [blame] | 529 | spin_unlock(&au1000->ac97_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | return data; |
| 532 | |
| 533 | } |
| 534 | |
| 535 | |
| 536 | static void |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 537 | snd_au1000_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 539 | struct snd_au1000 *au1000 = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | u32 cmd; |
| 541 | int i; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 542 | |
Konstantin Baydarov | 708f997 | 2005-10-27 17:25:02 +0200 | [diff] [blame] | 543 | spin_lock(&au1000->ac97_lock); |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 544 | /* would rather use the interrupt than this polling but it works and I can't |
| 545 | get the interrupt driven case to work efficiently */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | for (i = 0; i < 0x5000; i++) |
| 547 | if (!(au1000->ac97_ioport->status & AC97C_CP)) |
| 548 | break; |
| 549 | if (i == 0x5000) |
| 550 | printk(KERN_ERR "au1000 AC97: AC97 command write timeout\n"); |
| 551 | |
| 552 | cmd = (u32) reg & AC97C_INDEX_MASK; |
| 553 | cmd &= ~AC97C_READ; |
| 554 | cmd |= ((u32) val << AC97C_WD_BIT); |
| 555 | au1000->ac97_ioport->cmd = cmd; |
Konstantin Baydarov | 708f997 | 2005-10-27 17:25:02 +0200 | [diff] [blame] | 556 | spin_unlock(&au1000->ac97_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 559 | /*------------------------------ Setup / Destroy ----------------------------*/ |
| 560 | |
| 561 | static void snd_au1000_free(struct snd_card *card) |
| 562 | { |
| 563 | struct snd_au1000 *au1000 = card->private_data; |
| 564 | |
| 565 | if (au1000->stream[PLAYBACK]) { |
| 566 | if (au1000->stream[PLAYBACK]->dma >= 0) |
| 567 | free_au1000_dma(au1000->stream[PLAYBACK]->dma); |
| 568 | kfree(au1000->stream[PLAYBACK]); |
| 569 | } |
| 570 | |
| 571 | if (au1000->stream[CAPTURE]) { |
| 572 | if (au1000->stream[CAPTURE]->dma >= 0) |
| 573 | free_au1000_dma(au1000->stream[CAPTURE]->dma); |
| 574 | kfree(au1000->stream[CAPTURE]); |
| 575 | } |
| 576 | |
| 577 | if (au1000->ac97_res_port) { |
| 578 | /* put internal AC97 block into reset */ |
| 579 | if (au1000->ac97_ioport) { |
| 580 | au1000->ac97_ioport->cntrl = AC97C_RS; |
| 581 | iounmap(au1000->ac97_ioport); |
| 582 | au1000->ac97_ioport = NULL; |
| 583 | } |
| 584 | release_and_free_resource(au1000->ac97_res_port); |
| 585 | au1000->ac97_res_port = NULL; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | static struct snd_ac97_bus_ops ops = { |
| 590 | .write = snd_au1000_ac97_write, |
| 591 | .read = snd_au1000_ac97_read, |
| 592 | }; |
| 593 | |
| 594 | static int au1000_ac97_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
| 596 | int err; |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 597 | void __iomem *io; |
| 598 | struct resource *r; |
| 599 | struct snd_card *card; |
| 600 | struct snd_au1000 *au1000; |
Takashi Iwai | a0d6f88 | 2005-11-17 15:12:31 +0100 | [diff] [blame] | 601 | struct snd_ac97_bus *pbus; |
| 602 | struct snd_ac97_template ac97; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Takashi Iwai | bee1bb1 | 2014-01-29 14:34:47 +0100 | [diff] [blame] | 604 | err = snd_card_new(&pdev->dev, -1, "AC97", THIS_MODULE, |
| 605 | sizeof(struct snd_au1000), &card); |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 606 | if (err < 0) |
| 607 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 609 | au1000 = card->private_data; |
| 610 | au1000->card = card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | spin_lock_init(&au1000->ac97_lock); |
| 612 | |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 613 | /* from here on let ALSA call the special freeing function */ |
| 614 | card->private_free = snd_au1000_free; |
| 615 | |
| 616 | /* TX DMA ID */ |
| 617 | r = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 618 | if (!r) { |
| 619 | err = -ENODEV; |
| 620 | snd_printk(KERN_INFO "no TX DMA platform resource!\n"); |
| 621 | goto out; |
| 622 | } |
| 623 | au1000->dmaid[0] = r->start; |
| 624 | |
| 625 | /* RX DMA ID */ |
| 626 | r = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
| 627 | if (!r) { |
| 628 | err = -ENODEV; |
| 629 | snd_printk(KERN_INFO "no RX DMA platform resource!\n"); |
| 630 | goto out; |
| 631 | } |
| 632 | au1000->dmaid[1] = r->start; |
| 633 | |
| 634 | au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream), |
| 635 | GFP_KERNEL); |
| 636 | if (!au1000->stream[PLAYBACK]) |
| 637 | goto out; |
| 638 | au1000->stream[PLAYBACK]->dma = -1; |
| 639 | |
| 640 | au1000->stream[CAPTURE] = kmalloc(sizeof(struct audio_stream), |
| 641 | GFP_KERNEL); |
| 642 | if (!au1000->stream[CAPTURE]) |
| 643 | goto out; |
| 644 | au1000->stream[CAPTURE]->dma = -1; |
| 645 | |
| 646 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 647 | if (!r) |
| 648 | goto out; |
| 649 | |
| 650 | err = -EBUSY; |
Benoit Taine | 82285f2 | 2014-05-28 17:14:06 +0200 | [diff] [blame] | 651 | au1000->ac97_res_port = request_mem_region(r->start, resource_size(r), |
| 652 | pdev->name); |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 653 | if (!au1000->ac97_res_port) { |
| 654 | snd_printk(KERN_ERR "ALSA AC97: can't grab AC97 port\n"); |
| 655 | goto out; |
| 656 | } |
| 657 | |
Benoit Taine | 82285f2 | 2014-05-28 17:14:06 +0200 | [diff] [blame] | 658 | io = ioremap(r->start, resource_size(r)); |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 659 | if (!io) |
| 660 | goto out; |
| 661 | |
| 662 | au1000->ac97_ioport = (struct au1000_ac97_reg *)io; |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | /* configure pins for AC'97 |
| 665 | TODO: move to board_setup.c */ |
| 666 | au_writel(au_readl(SYS_PINFUNC) & ~0x02, SYS_PINFUNC); |
| 667 | |
| 668 | /* Initialise Au1000's AC'97 Control Block */ |
| 669 | au1000->ac97_ioport->cntrl = AC97C_RS | AC97C_CE; |
| 670 | udelay(10); |
| 671 | au1000->ac97_ioport->cntrl = AC97C_CE; |
| 672 | udelay(10); |
| 673 | |
| 674 | /* Initialise External CODEC -- cold reset */ |
| 675 | au1000->ac97_ioport->config = AC97C_RESET; |
| 676 | udelay(10); |
| 677 | au1000->ac97_ioport->config = 0x0; |
| 678 | mdelay(5); |
| 679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | /* Initialise AC97 middle-layer */ |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 681 | err = snd_ac97_bus(au1000->card, 0, &ops, au1000, &pbus); |
| 682 | if (err < 0) |
| 683 | goto out; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | memset(&ac97, 0, sizeof(ac97)); |
| 686 | ac97.private_data = au1000; |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 687 | err = snd_ac97_mixer(pbus, &ac97, &au1000->ac97); |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 688 | if (err < 0) |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 689 | goto out; |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 690 | |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 691 | err = snd_au1000_pcm_new(au1000); |
| 692 | if (err < 0) |
| 693 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
Takashi Iwai | 33ea25c | 2005-11-17 10:32:43 +0100 | [diff] [blame] | 695 | strcpy(card->driver, "Au1000-AC97"); |
| 696 | strcpy(card->shortname, "AMD Au1000-AC97"); |
| 697 | sprintf(card->longname, "AMD Au1000--AC97 ALSA Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 699 | err = snd_card_register(card); |
| 700 | if (err < 0) |
| 701 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Takashi Iwai | 2ebfb8e | 2009-02-05 16:11:58 +0100 | [diff] [blame] | 703 | printk(KERN_INFO "ALSA AC97: Driver Initialized\n"); |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 704 | |
| 705 | platform_set_drvdata(pdev, card); |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return 0; |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 708 | |
| 709 | out: |
| 710 | snd_card_free(card); |
| 711 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 714 | static int au1000_ac97_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 716 | return snd_card_free(platform_get_drvdata(pdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Manuel Lauss | 7d13211 | 2009-03-29 11:47:06 +0200 | [diff] [blame] | 719 | struct platform_driver au1000_ac97c_driver = { |
| 720 | .driver = { |
| 721 | .name = "au1000-ac97c", |
| 722 | .owner = THIS_MODULE, |
| 723 | }, |
| 724 | .probe = au1000_ac97_probe, |
| 725 | .remove = au1000_ac97_remove, |
| 726 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Christoph Jaeger | 34f98063 | 2014-04-09 09:42:32 +0200 | [diff] [blame] | 728 | module_platform_driver(au1000_ac97c_driver); |