Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/sound/arm/aaci.c - ARM PrimeCell AACI PL041 driver |
| 3 | * |
| 4 | * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * Documentation: ARM DDI 0173B |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/ioport.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/err.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 20 | #include <linux/amba/bus.h> |
Russell King | 88cdca9 | 2009-11-23 09:44:10 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 22 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 23 | #include <sound/core.h> |
| 24 | #include <sound/initval.h> |
| 25 | #include <sound/ac97_codec.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/pcm_params.h> |
| 28 | |
| 29 | #include "aaci.h" |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 30 | |
| 31 | #define DRIVER_NAME "aaci-pl041" |
| 32 | |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 33 | #define FRAME_PERIOD_US 21 |
| 34 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 35 | /* |
| 36 | * PM support is not complete. Turn it off. |
| 37 | */ |
| 38 | #undef CONFIG_PM |
| 39 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 40 | static void aaci_ac97_select_codec(struct aaci *aaci, struct snd_ac97 *ac97) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 41 | { |
| 42 | u32 v, maincr = aaci->maincr | MAINCR_SCRA(ac97->num); |
| 43 | |
| 44 | /* |
| 45 | * Ensure that the slot 1/2 RX registers are empty. |
| 46 | */ |
| 47 | v = readl(aaci->base + AACI_SLFR); |
| 48 | if (v & SLFR_2RXV) |
| 49 | readl(aaci->base + AACI_SL2RX); |
| 50 | if (v & SLFR_1RXV) |
| 51 | readl(aaci->base + AACI_SL1RX); |
| 52 | |
Russell King | 7c28938 | 2011-02-05 10:41:55 +0000 | [diff] [blame] | 53 | if (maincr != readl(aaci->base + AACI_MAINCR)) { |
| 54 | writel(maincr, aaci->base + AACI_MAINCR); |
| 55 | readl(aaci->base + AACI_MAINCR); |
| 56 | udelay(1); |
| 57 | } |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* |
| 61 | * P29: |
| 62 | * The recommended use of programming the external codec through slot 1 |
| 63 | * and slot 2 data is to use the channels during setup routines and the |
| 64 | * slot register at any other time. The data written into slot 1, slot 2 |
| 65 | * and slot 12 registers is transmitted only when their corresponding |
| 66 | * SI1TxEn, SI2TxEn and SI12TxEn bits are set in the AACI_MAINCR |
| 67 | * register. |
| 68 | */ |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 69 | static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg, |
| 70 | unsigned short val) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 71 | { |
| 72 | struct aaci *aaci = ac97->private_data; |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 73 | int timeout; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 74 | u32 v; |
| 75 | |
| 76 | if (ac97->num >= 4) |
| 77 | return; |
| 78 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 79 | mutex_lock(&aaci->ac97_sem); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 80 | |
| 81 | aaci_ac97_select_codec(aaci, ac97); |
| 82 | |
| 83 | /* |
| 84 | * P54: You must ensure that AACI_SL2TX is always written |
| 85 | * to, if required, before data is written to AACI_SL1TX. |
| 86 | */ |
| 87 | writel(val << 4, aaci->base + AACI_SL2TX); |
| 88 | writel(reg << 12, aaci->base + AACI_SL1TX); |
| 89 | |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 90 | /* Initially, wait one frame period */ |
| 91 | udelay(FRAME_PERIOD_US); |
| 92 | |
| 93 | /* And then wait an additional eight frame periods for it to be sent */ |
| 94 | timeout = FRAME_PERIOD_US * 8; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 95 | do { |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 96 | udelay(1); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 97 | v = readl(aaci->base + AACI_SLFR); |
Roel Kluin | f6f35bb | 2009-02-08 15:22:25 +0100 | [diff] [blame] | 98 | } while ((v & (SLFR_1TXB|SLFR_2TXB)) && --timeout); |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 99 | |
Russell King | 69058cd | 2011-01-12 23:17:24 +0000 | [diff] [blame] | 100 | if (v & (SLFR_1TXB|SLFR_2TXB)) |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 101 | dev_err(&aaci->dev->dev, |
| 102 | "timeout waiting for write to complete\n"); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 103 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 104 | mutex_unlock(&aaci->ac97_sem); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Read an AC'97 register. |
| 109 | */ |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 110 | static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 111 | { |
| 112 | struct aaci *aaci = ac97->private_data; |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 113 | int timeout, retries = 10; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 114 | u32 v; |
| 115 | |
| 116 | if (ac97->num >= 4) |
| 117 | return ~0; |
| 118 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 119 | mutex_lock(&aaci->ac97_sem); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 120 | |
| 121 | aaci_ac97_select_codec(aaci, ac97); |
| 122 | |
| 123 | /* |
| 124 | * Write the register address to slot 1. |
| 125 | */ |
| 126 | writel((reg << 12) | (1 << 19), aaci->base + AACI_SL1TX); |
| 127 | |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 128 | /* Initially, wait one frame period */ |
| 129 | udelay(FRAME_PERIOD_US); |
| 130 | |
| 131 | /* And then wait an additional eight frame periods for it to be sent */ |
| 132 | timeout = FRAME_PERIOD_US * 8; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 133 | do { |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 134 | udelay(1); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 135 | v = readl(aaci->base + AACI_SLFR); |
Roel Kluin | f6f35bb | 2009-02-08 15:22:25 +0100 | [diff] [blame] | 136 | } while ((v & SLFR_1TXB) && --timeout); |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 137 | |
Russell King | 69058cd | 2011-01-12 23:17:24 +0000 | [diff] [blame] | 138 | if (v & SLFR_1TXB) { |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 139 | dev_err(&aaci->dev->dev, "timeout on slot 1 TX busy\n"); |
| 140 | v = ~0; |
| 141 | goto out; |
| 142 | } |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 143 | |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 144 | /* Now wait for the response frame */ |
| 145 | udelay(FRAME_PERIOD_US); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 146 | |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 147 | /* And then wait an additional eight frame periods for data */ |
| 148 | timeout = FRAME_PERIOD_US * 8; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 149 | do { |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 150 | udelay(1); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 151 | cond_resched(); |
| 152 | v = readl(aaci->base + AACI_SLFR) & (SLFR_1RXV|SLFR_2RXV); |
Roel Kluin | f6f35bb | 2009-02-08 15:22:25 +0100 | [diff] [blame] | 153 | } while ((v != (SLFR_1RXV|SLFR_2RXV)) && --timeout); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 154 | |
Russell King | 69058cd | 2011-01-12 23:17:24 +0000 | [diff] [blame] | 155 | if (v != (SLFR_1RXV|SLFR_2RXV)) { |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 156 | dev_err(&aaci->dev->dev, "timeout on RX valid\n"); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 157 | v = ~0; |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 158 | goto out; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Kevin Hilman | 14d178a | 2007-02-07 05:46:47 +0100 | [diff] [blame] | 161 | do { |
| 162 | v = readl(aaci->base + AACI_SL1RX) >> 12; |
| 163 | if (v == reg) { |
| 164 | v = readl(aaci->base + AACI_SL2RX) >> 4; |
| 165 | break; |
| 166 | } else if (--retries) { |
| 167 | dev_warn(&aaci->dev->dev, |
| 168 | "ac97 read back fail. retry\n"); |
| 169 | continue; |
| 170 | } else { |
| 171 | dev_warn(&aaci->dev->dev, |
| 172 | "wrong ac97 register read back (%x != %x)\n", |
| 173 | v, reg); |
| 174 | v = ~0; |
| 175 | } |
| 176 | } while (retries); |
| 177 | out: |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 178 | mutex_unlock(&aaci->ac97_sem); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 179 | return v; |
| 180 | } |
| 181 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 182 | static inline void |
| 183 | aaci_chan_wait_ready(struct aaci_runtime *aacirun, unsigned long mask) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 184 | { |
| 185 | u32 val; |
| 186 | int timeout = 5000; |
| 187 | |
| 188 | do { |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 189 | udelay(1); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 190 | val = readl(aacirun->base + AACI_SR); |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 191 | } while (val & mask && timeout--); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | |
| 195 | |
| 196 | /* |
| 197 | * Interrupt support. |
| 198 | */ |
Kevin Hilman | 62578cb | 2007-02-07 05:41:37 +0100 | [diff] [blame] | 199 | static void aaci_fifo_irq(struct aaci *aaci, int channel, u32 mask) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 200 | { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 201 | if (mask & ISR_ORINTR) { |
| 202 | dev_warn(&aaci->dev->dev, "RX overrun on chan %d\n", channel); |
| 203 | writel(ICLR_RXOEC1 << channel, aaci->base + AACI_INTCLR); |
| 204 | } |
| 205 | |
| 206 | if (mask & ISR_RXTOINTR) { |
| 207 | dev_warn(&aaci->dev->dev, "RX timeout on chan %d\n", channel); |
| 208 | writel(ICLR_RXTOFEC1 << channel, aaci->base + AACI_INTCLR); |
| 209 | } |
| 210 | |
| 211 | if (mask & ISR_RXINTR) { |
| 212 | struct aaci_runtime *aacirun = &aaci->capture; |
| 213 | void *ptr; |
| 214 | |
| 215 | if (!aacirun->substream || !aacirun->start) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 216 | dev_warn(&aaci->dev->dev, "RX interrupt???\n"); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 217 | writel(0, aacirun->base + AACI_IE); |
| 218 | return; |
| 219 | } |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 220 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 221 | spin_lock(&aacirun->lock); |
| 222 | |
| 223 | ptr = aacirun->ptr; |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 224 | do { |
| 225 | unsigned int len = aacirun->fifosz; |
| 226 | u32 val; |
| 227 | |
| 228 | if (aacirun->bytes <= 0) { |
| 229 | aacirun->bytes += aacirun->period; |
| 230 | aacirun->ptr = ptr; |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 231 | spin_unlock(&aacirun->lock); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 232 | snd_pcm_period_elapsed(aacirun->substream); |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 233 | spin_lock(&aacirun->lock); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 234 | } |
| 235 | if (!(aacirun->cr & CR_EN)) |
| 236 | break; |
| 237 | |
| 238 | val = readl(aacirun->base + AACI_SR); |
| 239 | if (!(val & SR_RXHF)) |
| 240 | break; |
| 241 | if (!(val & SR_RXFF)) |
| 242 | len >>= 1; |
| 243 | |
| 244 | aacirun->bytes -= len; |
| 245 | |
| 246 | /* reading 16 bytes at a time */ |
| 247 | for( ; len > 0; len -= 16) { |
| 248 | asm( |
| 249 | "ldmia %1, {r0, r1, r2, r3}\n\t" |
| 250 | "stmia %0!, {r0, r1, r2, r3}" |
| 251 | : "+r" (ptr) |
| 252 | : "r" (aacirun->fifo) |
| 253 | : "r0", "r1", "r2", "r3", "cc"); |
| 254 | |
| 255 | if (ptr >= aacirun->end) |
| 256 | ptr = aacirun->start; |
| 257 | } |
| 258 | } while(1); |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 259 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 260 | aacirun->ptr = ptr; |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 261 | |
| 262 | spin_unlock(&aacirun->lock); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 265 | if (mask & ISR_URINTR) { |
Kevin Hilman | 62578cb | 2007-02-07 05:41:37 +0100 | [diff] [blame] | 266 | dev_dbg(&aaci->dev->dev, "TX underrun on chan %d\n", channel); |
| 267 | writel(ICLR_TXUEC1 << channel, aaci->base + AACI_INTCLR); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | if (mask & ISR_TXINTR) { |
| 271 | struct aaci_runtime *aacirun = &aaci->playback; |
| 272 | void *ptr; |
| 273 | |
| 274 | if (!aacirun->substream || !aacirun->start) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 275 | dev_warn(&aaci->dev->dev, "TX interrupt???\n"); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 276 | writel(0, aacirun->base + AACI_IE); |
| 277 | return; |
| 278 | } |
| 279 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 280 | spin_lock(&aacirun->lock); |
| 281 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 282 | ptr = aacirun->ptr; |
| 283 | do { |
| 284 | unsigned int len = aacirun->fifosz; |
| 285 | u32 val; |
| 286 | |
| 287 | if (aacirun->bytes <= 0) { |
| 288 | aacirun->bytes += aacirun->period; |
| 289 | aacirun->ptr = ptr; |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 290 | spin_unlock(&aacirun->lock); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 291 | snd_pcm_period_elapsed(aacirun->substream); |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 292 | spin_lock(&aacirun->lock); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 293 | } |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 294 | if (!(aacirun->cr & CR_EN)) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 295 | break; |
| 296 | |
| 297 | val = readl(aacirun->base + AACI_SR); |
| 298 | if (!(val & SR_TXHE)) |
| 299 | break; |
| 300 | if (!(val & SR_TXFE)) |
| 301 | len >>= 1; |
| 302 | |
| 303 | aacirun->bytes -= len; |
| 304 | |
| 305 | /* writing 16 bytes at a time */ |
| 306 | for ( ; len > 0; len -= 16) { |
| 307 | asm( |
| 308 | "ldmia %0!, {r0, r1, r2, r3}\n\t" |
| 309 | "stmia %1, {r0, r1, r2, r3}" |
| 310 | : "+r" (ptr) |
| 311 | : "r" (aacirun->fifo) |
| 312 | : "r0", "r1", "r2", "r3", "cc"); |
| 313 | |
| 314 | if (ptr >= aacirun->end) |
| 315 | ptr = aacirun->start; |
| 316 | } |
| 317 | } while (1); |
| 318 | |
| 319 | aacirun->ptr = ptr; |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 320 | |
| 321 | spin_unlock(&aacirun->lock); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 325 | static irqreturn_t aaci_irq(int irq, void *devid) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 326 | { |
| 327 | struct aaci *aaci = devid; |
| 328 | u32 mask; |
| 329 | int i; |
| 330 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 331 | mask = readl(aaci->base + AACI_ALLINTS); |
| 332 | if (mask) { |
| 333 | u32 m = mask; |
| 334 | for (i = 0; i < 4; i++, m >>= 7) { |
| 335 | if (m & 0x7f) { |
Kevin Hilman | 62578cb | 2007-02-07 05:41:37 +0100 | [diff] [blame] | 336 | aaci_fifo_irq(aaci, i, m); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | } |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 340 | |
| 341 | return mask ? IRQ_HANDLED : IRQ_NONE; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | |
| 346 | /* |
| 347 | * ALSA support. |
| 348 | */ |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 349 | static struct snd_pcm_hardware aaci_hw_info = { |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 350 | .info = SNDRV_PCM_INFO_MMAP | |
| 351 | SNDRV_PCM_INFO_MMAP_VALID | |
| 352 | SNDRV_PCM_INFO_INTERLEAVED | |
| 353 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 354 | SNDRV_PCM_INFO_RESUME, |
| 355 | |
| 356 | /* |
| 357 | * ALSA doesn't support 18-bit or 20-bit packed into 32-bit |
| 358 | * words. It also doesn't support 12-bit at all. |
| 359 | */ |
| 360 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 361 | |
Russell King | 6ca867c | 2009-12-18 17:48:35 +0000 | [diff] [blame] | 362 | /* rates are setup from the AC'97 codec */ |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 363 | .channels_min = 2, |
| 364 | .channels_max = 6, |
| 365 | .buffer_bytes_max = 64 * 1024, |
| 366 | .period_bytes_min = 256, |
| 367 | .period_bytes_max = PAGE_SIZE, |
| 368 | .periods_min = 4, |
| 369 | .periods_max = PAGE_SIZE / 16, |
| 370 | }; |
| 371 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 372 | static int __aaci_pcm_open(struct aaci *aaci, |
| 373 | struct snd_pcm_substream *substream, |
| 374 | struct aaci_runtime *aacirun) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 375 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 376 | struct snd_pcm_runtime *runtime = substream->runtime; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 377 | int ret; |
| 378 | |
| 379 | aacirun->substream = substream; |
| 380 | runtime->private_data = aacirun; |
| 381 | runtime->hw = aaci_hw_info; |
Russell King | 6ca867c | 2009-12-18 17:48:35 +0000 | [diff] [blame] | 382 | runtime->hw.rates = aacirun->pcm->rates; |
| 383 | snd_pcm_limit_hw_rates(runtime); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 384 | |
Russell King | a08d565 | 2009-12-18 17:48:45 +0000 | [diff] [blame] | 385 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 386 | aacirun->pcm->r[1].slots) |
| 387 | snd_ac97_pcm_double_rate_rules(runtime); |
| 388 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 389 | /* |
| 390 | * FIXME: ALSA specifies fifo_size in bytes. If we're in normal |
| 391 | * mode, each 32-bit word contains one sample. If we're in |
| 392 | * compact mode, each 32-bit word contains two samples, effectively |
| 393 | * halving the FIFO size. However, we don't know for sure which |
| 394 | * we'll be using at this point. We set this to the lower limit. |
| 395 | */ |
| 396 | runtime->hw.fifo_size = aaci->fifosize * 2; |
| 397 | |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 398 | ret = request_irq(aaci->dev->irq[0], aaci_irq, IRQF_SHARED|IRQF_DISABLED, |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 399 | DRIVER_NAME, aaci); |
| 400 | if (ret) |
| 401 | goto out; |
| 402 | |
| 403 | return 0; |
| 404 | |
| 405 | out: |
| 406 | return ret; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | /* |
| 411 | * Common ALSA stuff |
| 412 | */ |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 413 | static int aaci_pcm_close(struct snd_pcm_substream *substream) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 414 | { |
| 415 | struct aaci *aaci = substream->private_data; |
| 416 | struct aaci_runtime *aacirun = substream->runtime->private_data; |
| 417 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 418 | WARN_ON(aacirun->cr & CR_EN); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 419 | |
| 420 | aacirun->substream = NULL; |
| 421 | free_irq(aaci->dev->irq[0], aaci); |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 426 | static int aaci_pcm_hw_free(struct snd_pcm_substream *substream) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 427 | { |
| 428 | struct aaci_runtime *aacirun = substream->runtime->private_data; |
| 429 | |
| 430 | /* |
| 431 | * This must not be called with the device enabled. |
| 432 | */ |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 433 | WARN_ON(aacirun->cr & CR_EN); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 434 | |
| 435 | if (aacirun->pcm_open) |
| 436 | snd_ac97_pcm_close(aacirun->pcm); |
| 437 | aacirun->pcm_open = 0; |
| 438 | |
| 439 | /* |
| 440 | * Clear out the DMA and any allocated buffers. |
| 441 | */ |
Takashi Iwai | d679732 | 2009-11-26 15:08:54 +0100 | [diff] [blame] | 442 | snd_pcm_lib_free_pages(substream); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 447 | static int aaci_pcm_hw_params(struct snd_pcm_substream *substream, |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 448 | struct aaci_runtime *aacirun, |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 449 | struct snd_pcm_hw_params *params) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 450 | { |
| 451 | int err; |
Peter Huewe | 903b0eb | 2009-12-26 03:27:45 +0100 | [diff] [blame] | 452 | struct aaci *aaci = substream->private_data; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 453 | |
| 454 | aaci_pcm_hw_free(substream); |
Russell King | 4acd57c | 2009-11-29 16:39:52 +0000 | [diff] [blame] | 455 | if (aacirun->pcm_open) { |
| 456 | snd_ac97_pcm_close(aacirun->pcm); |
| 457 | aacirun->pcm_open = 0; |
| 458 | } |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 459 | |
Takashi Iwai | d679732 | 2009-11-26 15:08:54 +0100 | [diff] [blame] | 460 | err = snd_pcm_lib_malloc_pages(substream, |
| 461 | params_buffer_bytes(params)); |
Russell King | 4e30b69 | 2009-12-18 17:48:37 +0000 | [diff] [blame] | 462 | if (err >= 0) { |
Russell King | a08d565 | 2009-12-18 17:48:45 +0000 | [diff] [blame] | 463 | unsigned int rate = params_rate(params); |
| 464 | int dbl = rate > 48000; |
| 465 | |
| 466 | err = snd_ac97_pcm_open(aacirun->pcm, rate, |
Russell King | 4e30b69 | 2009-12-18 17:48:37 +0000 | [diff] [blame] | 467 | params_channels(params), |
Russell King | a08d565 | 2009-12-18 17:48:45 +0000 | [diff] [blame] | 468 | aacirun->pcm->r[dbl].slots); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 469 | |
Russell King | 4e30b69 | 2009-12-18 17:48:37 +0000 | [diff] [blame] | 470 | aacirun->pcm_open = err == 0; |
Russell King | d3aee79 | 2009-12-18 17:48:40 +0000 | [diff] [blame] | 471 | aacirun->cr = CR_FEN | CR_COMPACT | CR_SZ16; |
| 472 | aacirun->fifosz = aaci->fifosize * 4; |
| 473 | |
| 474 | if (aacirun->cr & CR_COMPACT) |
| 475 | aacirun->fifosz >>= 1; |
Russell King | 4e30b69 | 2009-12-18 17:48:37 +0000 | [diff] [blame] | 476 | } |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 477 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 478 | return err; |
| 479 | } |
| 480 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 481 | static int aaci_pcm_prepare(struct snd_pcm_substream *substream) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 482 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 483 | struct snd_pcm_runtime *runtime = substream->runtime; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 484 | struct aaci_runtime *aacirun = runtime->private_data; |
| 485 | |
Russell King | 4e30b69 | 2009-12-18 17:48:37 +0000 | [diff] [blame] | 486 | aacirun->start = runtime->dma_area; |
Russell King | 88cdca9 | 2009-11-23 09:44:10 +0100 | [diff] [blame] | 487 | aacirun->end = aacirun->start + snd_pcm_lib_buffer_bytes(substream); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 488 | aacirun->ptr = aacirun->start; |
| 489 | aacirun->period = |
| 490 | aacirun->bytes = frames_to_bytes(runtime, runtime->period_size); |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 495 | static snd_pcm_uframes_t aaci_pcm_pointer(struct snd_pcm_substream *substream) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 496 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 497 | struct snd_pcm_runtime *runtime = substream->runtime; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 498 | struct aaci_runtime *aacirun = runtime->private_data; |
| 499 | ssize_t bytes = aacirun->ptr - aacirun->start; |
| 500 | |
| 501 | return bytes_to_frames(runtime, bytes); |
| 502 | } |
| 503 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 504 | |
| 505 | /* |
| 506 | * Playback specific ALSA stuff |
| 507 | */ |
| 508 | static const u32 channels_to_txmask[] = { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 509 | [2] = CR_SL3 | CR_SL4, |
| 510 | [4] = CR_SL3 | CR_SL4 | CR_SL7 | CR_SL8, |
| 511 | [6] = CR_SL3 | CR_SL4 | CR_SL7 | CR_SL8 | CR_SL6 | CR_SL9, |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 512 | }; |
| 513 | |
| 514 | /* |
| 515 | * We can support two and four channel audio. Unfortunately |
| 516 | * six channel audio requires a non-standard channel ordering: |
| 517 | * 2 -> FL(3), FR(4) |
| 518 | * 4 -> FL(3), FR(4), SL(7), SR(8) |
| 519 | * 6 -> FL(3), FR(4), SL(7), SR(8), C(6), LFE(9) (required) |
| 520 | * FL(3), FR(4), C(6), SL(7), SR(8), LFE(9) (actual) |
| 521 | * This requires an ALSA configuration file to correct. |
| 522 | */ |
| 523 | static unsigned int channel_list[] = { 2, 4, 6 }; |
| 524 | |
| 525 | static int |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 526 | aaci_rule_channels(struct snd_pcm_hw_params *p, struct snd_pcm_hw_rule *rule) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 527 | { |
| 528 | struct aaci *aaci = rule->private; |
| 529 | unsigned int chan_mask = 1 << 0, slots; |
| 530 | |
| 531 | /* |
| 532 | * pcms[0] is the our 5.1 PCM instance. |
| 533 | */ |
| 534 | slots = aaci->ac97_bus->pcms[0].r[0].slots; |
| 535 | if (slots & (1 << AC97_SLOT_PCM_SLEFT)) { |
| 536 | chan_mask |= 1 << 1; |
| 537 | if (slots & (1 << AC97_SLOT_LFE)) |
| 538 | chan_mask |= 1 << 2; |
| 539 | } |
| 540 | |
| 541 | return snd_interval_list(hw_param_interval(p, rule->var), |
| 542 | ARRAY_SIZE(channel_list), channel_list, |
| 543 | chan_mask); |
| 544 | } |
| 545 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 546 | static int aaci_pcm_open(struct snd_pcm_substream *substream) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 547 | { |
| 548 | struct aaci *aaci = substream->private_data; |
| 549 | int ret; |
| 550 | |
| 551 | /* |
| 552 | * Add rule describing channel dependency. |
| 553 | */ |
| 554 | ret = snd_pcm_hw_rule_add(substream->runtime, 0, |
| 555 | SNDRV_PCM_HW_PARAM_CHANNELS, |
| 556 | aaci_rule_channels, aaci, |
| 557 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 558 | if (ret) |
| 559 | return ret; |
| 560 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 561 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 562 | ret = __aaci_pcm_open(aaci, substream, &aaci->playback); |
| 563 | } else { |
| 564 | ret = __aaci_pcm_open(aaci, substream, &aaci->capture); |
| 565 | } |
| 566 | return ret; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 567 | } |
| 568 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 569 | static int aaci_pcm_playback_hw_params(struct snd_pcm_substream *substream, |
| 570 | struct snd_pcm_hw_params *params) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 571 | { |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 572 | struct aaci_runtime *aacirun = substream->runtime->private_data; |
| 573 | unsigned int channels = params_channels(params); |
| 574 | int ret; |
| 575 | |
| 576 | WARN_ON(channels >= ARRAY_SIZE(channels_to_txmask) || |
| 577 | !channels_to_txmask[channels]); |
| 578 | |
| 579 | ret = aaci_pcm_hw_params(substream, aacirun, params); |
| 580 | |
| 581 | /* |
| 582 | * Enable FIFO, compact mode, 16 bits per sample. |
| 583 | * FIXME: double rate slots? |
| 584 | */ |
Russell King | d3aee79 | 2009-12-18 17:48:40 +0000 | [diff] [blame] | 585 | if (ret >= 0) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 586 | aacirun->cr |= channels_to_txmask[channels]; |
| 587 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | static void aaci_pcm_playback_stop(struct aaci_runtime *aacirun) |
| 592 | { |
| 593 | u32 ie; |
| 594 | |
| 595 | ie = readl(aacirun->base + AACI_IE); |
| 596 | ie &= ~(IE_URIE|IE_TXIE); |
| 597 | writel(ie, aacirun->base + AACI_IE); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 598 | aacirun->cr &= ~CR_EN; |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 599 | aaci_chan_wait_ready(aacirun, SR_TXB); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 600 | writel(aacirun->cr, aacirun->base + AACI_TXCR); |
| 601 | } |
| 602 | |
| 603 | static void aaci_pcm_playback_start(struct aaci_runtime *aacirun) |
| 604 | { |
| 605 | u32 ie; |
| 606 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 607 | aaci_chan_wait_ready(aacirun, SR_TXB); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 608 | aacirun->cr |= CR_EN; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 609 | |
| 610 | ie = readl(aacirun->base + AACI_IE); |
| 611 | ie |= IE_URIE | IE_TXIE; |
| 612 | writel(ie, aacirun->base + AACI_IE); |
| 613 | writel(aacirun->cr, aacirun->base + AACI_TXCR); |
| 614 | } |
| 615 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 616 | static int aaci_pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 617 | { |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 618 | struct aaci_runtime *aacirun = substream->runtime->private_data; |
| 619 | unsigned long flags; |
| 620 | int ret = 0; |
| 621 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 622 | spin_lock_irqsave(&aacirun->lock, flags); |
| 623 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 624 | switch (cmd) { |
| 625 | case SNDRV_PCM_TRIGGER_START: |
| 626 | aaci_pcm_playback_start(aacirun); |
| 627 | break; |
| 628 | |
| 629 | case SNDRV_PCM_TRIGGER_RESUME: |
| 630 | aaci_pcm_playback_start(aacirun); |
| 631 | break; |
| 632 | |
| 633 | case SNDRV_PCM_TRIGGER_STOP: |
| 634 | aaci_pcm_playback_stop(aacirun); |
| 635 | break; |
| 636 | |
| 637 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 638 | aaci_pcm_playback_stop(aacirun); |
| 639 | break; |
| 640 | |
| 641 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 642 | break; |
| 643 | |
| 644 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 645 | break; |
| 646 | |
| 647 | default: |
| 648 | ret = -EINVAL; |
| 649 | } |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 650 | |
| 651 | spin_unlock_irqrestore(&aacirun->lock, flags); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 652 | |
| 653 | return ret; |
| 654 | } |
| 655 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 656 | static struct snd_pcm_ops aaci_playback_ops = { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 657 | .open = aaci_pcm_open, |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 658 | .close = aaci_pcm_close, |
| 659 | .ioctl = snd_pcm_lib_ioctl, |
| 660 | .hw_params = aaci_pcm_playback_hw_params, |
| 661 | .hw_free = aaci_pcm_hw_free, |
| 662 | .prepare = aaci_pcm_prepare, |
| 663 | .trigger = aaci_pcm_playback_trigger, |
| 664 | .pointer = aaci_pcm_pointer, |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 665 | }; |
| 666 | |
Russell King | 8a37184 | 2007-02-20 15:44:23 +0000 | [diff] [blame] | 667 | static int aaci_pcm_capture_hw_params(struct snd_pcm_substream *substream, |
| 668 | struct snd_pcm_hw_params *params) |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 669 | { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 670 | struct aaci_runtime *aacirun = substream->runtime->private_data; |
| 671 | int ret; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 672 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 673 | ret = aaci_pcm_hw_params(substream, aacirun, params); |
Russell King | d3aee79 | 2009-12-18 17:48:40 +0000 | [diff] [blame] | 674 | if (ret >= 0) |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 675 | /* Line in record: slot 3 and 4 */ |
| 676 | aacirun->cr |= CR_SL3 | CR_SL4; |
| 677 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 678 | return ret; |
| 679 | } |
| 680 | |
| 681 | static void aaci_pcm_capture_stop(struct aaci_runtime *aacirun) |
| 682 | { |
| 683 | u32 ie; |
| 684 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 685 | aaci_chan_wait_ready(aacirun, SR_RXB); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 686 | |
| 687 | ie = readl(aacirun->base + AACI_IE); |
| 688 | ie &= ~(IE_ORIE | IE_RXIE); |
| 689 | writel(ie, aacirun->base+AACI_IE); |
| 690 | |
| 691 | aacirun->cr &= ~CR_EN; |
| 692 | |
| 693 | writel(aacirun->cr, aacirun->base + AACI_RXCR); |
| 694 | } |
| 695 | |
| 696 | static void aaci_pcm_capture_start(struct aaci_runtime *aacirun) |
| 697 | { |
| 698 | u32 ie; |
| 699 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 700 | aaci_chan_wait_ready(aacirun, SR_RXB); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 701 | |
| 702 | #ifdef DEBUG |
| 703 | /* RX Timeout value: bits 28:17 in RXCR */ |
| 704 | aacirun->cr |= 0xf << 17; |
| 705 | #endif |
| 706 | |
| 707 | aacirun->cr |= CR_EN; |
| 708 | writel(aacirun->cr, aacirun->base + AACI_RXCR); |
| 709 | |
| 710 | ie = readl(aacirun->base + AACI_IE); |
| 711 | ie |= IE_ORIE |IE_RXIE; // overrun and rx interrupt -- half full |
| 712 | writel(ie, aacirun->base + AACI_IE); |
| 713 | } |
| 714 | |
Russell King | 8a37184 | 2007-02-20 15:44:23 +0000 | [diff] [blame] | 715 | static int aaci_pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd) |
| 716 | { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 717 | struct aaci_runtime *aacirun = substream->runtime->private_data; |
| 718 | unsigned long flags; |
| 719 | int ret = 0; |
| 720 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 721 | spin_lock_irqsave(&aacirun->lock, flags); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 722 | |
| 723 | switch (cmd) { |
| 724 | case SNDRV_PCM_TRIGGER_START: |
| 725 | aaci_pcm_capture_start(aacirun); |
| 726 | break; |
| 727 | |
| 728 | case SNDRV_PCM_TRIGGER_RESUME: |
| 729 | aaci_pcm_capture_start(aacirun); |
| 730 | break; |
| 731 | |
| 732 | case SNDRV_PCM_TRIGGER_STOP: |
| 733 | aaci_pcm_capture_stop(aacirun); |
| 734 | break; |
| 735 | |
| 736 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 737 | aaci_pcm_capture_stop(aacirun); |
| 738 | break; |
| 739 | |
| 740 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 741 | break; |
| 742 | |
| 743 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 744 | break; |
| 745 | |
| 746 | default: |
| 747 | ret = -EINVAL; |
| 748 | } |
| 749 | |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 750 | spin_unlock_irqrestore(&aacirun->lock, flags); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 751 | |
| 752 | return ret; |
| 753 | } |
| 754 | |
Russell King | 8a37184 | 2007-02-20 15:44:23 +0000 | [diff] [blame] | 755 | static int aaci_pcm_capture_prepare(struct snd_pcm_substream *substream) |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 756 | { |
| 757 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 758 | struct aaci *aaci = substream->private_data; |
| 759 | |
| 760 | aaci_pcm_prepare(substream); |
| 761 | |
| 762 | /* allow changing of sample rate */ |
| 763 | aaci_ac97_write(aaci->ac97, AC97_EXTENDED_STATUS, 0x0001); /* VRA */ |
| 764 | aaci_ac97_write(aaci->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); |
| 765 | aaci_ac97_write(aaci->ac97, AC97_PCM_MIC_ADC_RATE, runtime->rate); |
| 766 | |
| 767 | /* Record select: Mic: 0, Aux: 3, Line: 4 */ |
| 768 | aaci_ac97_write(aaci->ac97, AC97_REC_SEL, 0x0404); |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
Russell King | 8a37184 | 2007-02-20 15:44:23 +0000 | [diff] [blame] | 773 | static struct snd_pcm_ops aaci_capture_ops = { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 774 | .open = aaci_pcm_open, |
| 775 | .close = aaci_pcm_close, |
| 776 | .ioctl = snd_pcm_lib_ioctl, |
| 777 | .hw_params = aaci_pcm_capture_hw_params, |
| 778 | .hw_free = aaci_pcm_hw_free, |
| 779 | .prepare = aaci_pcm_capture_prepare, |
| 780 | .trigger = aaci_pcm_capture_trigger, |
| 781 | .pointer = aaci_pcm_pointer, |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 782 | }; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 783 | |
| 784 | /* |
| 785 | * Power Management. |
| 786 | */ |
| 787 | #ifdef CONFIG_PM |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 788 | static int aaci_do_suspend(struct snd_card *card, unsigned int state) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 789 | { |
| 790 | struct aaci *aaci = card->private_data; |
Takashi Iwai | 792a6c5 | 2005-11-17 17:19:25 +0100 | [diff] [blame] | 791 | snd_power_change_state(card, SNDRV_CTL_POWER_D3cold); |
| 792 | snd_pcm_suspend_all(aaci->pcm); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 793 | return 0; |
| 794 | } |
| 795 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 796 | static int aaci_do_resume(struct snd_card *card, unsigned int state) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 797 | { |
Takashi Iwai | 792a6c5 | 2005-11-17 17:19:25 +0100 | [diff] [blame] | 798 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 799 | return 0; |
| 800 | } |
| 801 | |
Richard Purdie | e36d394 | 2005-09-16 19:27:53 -0700 | [diff] [blame] | 802 | static int aaci_suspend(struct amba_device *dev, pm_message_t state) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 803 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 804 | struct snd_card *card = amba_get_drvdata(dev); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 805 | return card ? aaci_do_suspend(card) : 0; |
| 806 | } |
| 807 | |
| 808 | static int aaci_resume(struct amba_device *dev) |
| 809 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 810 | struct snd_card *card = amba_get_drvdata(dev); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 811 | return card ? aaci_do_resume(card) : 0; |
| 812 | } |
| 813 | #else |
| 814 | #define aaci_do_suspend NULL |
| 815 | #define aaci_do_resume NULL |
| 816 | #define aaci_suspend NULL |
| 817 | #define aaci_resume NULL |
| 818 | #endif |
| 819 | |
| 820 | |
| 821 | static struct ac97_pcm ac97_defs[] __devinitdata = { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 822 | [0] = { /* Front PCM */ |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 823 | .exclusive = 1, |
| 824 | .r = { |
| 825 | [0] = { |
| 826 | .slots = (1 << AC97_SLOT_PCM_LEFT) | |
| 827 | (1 << AC97_SLOT_PCM_RIGHT) | |
| 828 | (1 << AC97_SLOT_PCM_CENTER) | |
| 829 | (1 << AC97_SLOT_PCM_SLEFT) | |
| 830 | (1 << AC97_SLOT_PCM_SRIGHT) | |
| 831 | (1 << AC97_SLOT_LFE), |
| 832 | }, |
Russell King | a08d565 | 2009-12-18 17:48:45 +0000 | [diff] [blame] | 833 | [1] = { |
| 834 | .slots = (1 << AC97_SLOT_PCM_LEFT) | |
| 835 | (1 << AC97_SLOT_PCM_RIGHT) | |
| 836 | (1 << AC97_SLOT_PCM_LEFT_0) | |
| 837 | (1 << AC97_SLOT_PCM_RIGHT_0), |
| 838 | }, |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 839 | }, |
| 840 | }, |
| 841 | [1] = { /* PCM in */ |
| 842 | .stream = 1, |
| 843 | .exclusive = 1, |
| 844 | .r = { |
| 845 | [0] = { |
| 846 | .slots = (1 << AC97_SLOT_PCM_LEFT) | |
| 847 | (1 << AC97_SLOT_PCM_RIGHT), |
| 848 | }, |
| 849 | }, |
| 850 | }, |
| 851 | [2] = { /* Mic in */ |
| 852 | .stream = 1, |
| 853 | .exclusive = 1, |
| 854 | .r = { |
| 855 | [0] = { |
| 856 | .slots = (1 << AC97_SLOT_MIC), |
| 857 | }, |
| 858 | }, |
| 859 | } |
| 860 | }; |
| 861 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 862 | static struct snd_ac97_bus_ops aaci_bus_ops = { |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 863 | .write = aaci_ac97_write, |
| 864 | .read = aaci_ac97_read, |
| 865 | }; |
| 866 | |
| 867 | static int __devinit aaci_probe_ac97(struct aaci *aaci) |
| 868 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 869 | struct snd_ac97_template ac97_template; |
| 870 | struct snd_ac97_bus *ac97_bus; |
| 871 | struct snd_ac97 *ac97; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 872 | int ret; |
| 873 | |
| 874 | /* |
| 875 | * Assert AACIRESET for 2us |
| 876 | */ |
| 877 | writel(0, aaci->base + AACI_RESET); |
| 878 | udelay(2); |
| 879 | writel(RESET_NRST, aaci->base + AACI_RESET); |
| 880 | |
| 881 | /* |
| 882 | * Give the AC'97 codec more than enough time |
| 883 | * to wake up. (42us = ~2 frames at 48kHz.) |
| 884 | */ |
Russell King | 250c7a6 | 2011-01-12 23:42:57 +0000 | [diff] [blame] | 885 | udelay(FRAME_PERIOD_US * 2); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 886 | |
| 887 | ret = snd_ac97_bus(aaci->card, 0, &aaci_bus_ops, aaci, &ac97_bus); |
| 888 | if (ret) |
| 889 | goto out; |
| 890 | |
| 891 | ac97_bus->clock = 48000; |
| 892 | aaci->ac97_bus = ac97_bus; |
| 893 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 894 | memset(&ac97_template, 0, sizeof(struct snd_ac97_template)); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 895 | ac97_template.private_data = aaci; |
| 896 | ac97_template.num = 0; |
| 897 | ac97_template.scaps = AC97_SCAP_SKIP_MODEM; |
| 898 | |
| 899 | ret = snd_ac97_mixer(ac97_bus, &ac97_template, &ac97); |
| 900 | if (ret) |
| 901 | goto out; |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 902 | aaci->ac97 = ac97; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 903 | |
| 904 | /* |
| 905 | * Disable AC97 PC Beep input on audio codecs. |
| 906 | */ |
| 907 | if (ac97_is_audio(ac97)) |
| 908 | snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x801e); |
| 909 | |
| 910 | ret = snd_ac97_pcm_assign(ac97_bus, ARRAY_SIZE(ac97_defs), ac97_defs); |
| 911 | if (ret) |
| 912 | goto out; |
| 913 | |
| 914 | aaci->playback.pcm = &ac97_bus->pcms[0]; |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 915 | aaci->capture.pcm = &ac97_bus->pcms[1]; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 916 | |
| 917 | out: |
| 918 | return ret; |
| 919 | } |
| 920 | |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 921 | static void aaci_free_card(struct snd_card *card) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 922 | { |
| 923 | struct aaci *aaci = card->private_data; |
| 924 | if (aaci->base) |
| 925 | iounmap(aaci->base); |
| 926 | } |
| 927 | |
| 928 | static struct aaci * __devinit aaci_init_card(struct amba_device *dev) |
| 929 | { |
| 930 | struct aaci *aaci; |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 931 | struct snd_card *card; |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 932 | int err; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 933 | |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 934 | err = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
| 935 | THIS_MODULE, sizeof(struct aaci), &card); |
| 936 | if (err < 0) |
Takashi Iwai | 631e8ad | 2008-09-01 15:31:50 +0200 | [diff] [blame] | 937 | return NULL; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 938 | |
| 939 | card->private_free = aaci_free_card; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 940 | |
| 941 | strlcpy(card->driver, DRIVER_NAME, sizeof(card->driver)); |
| 942 | strlcpy(card->shortname, "ARM AC'97 Interface", sizeof(card->shortname)); |
| 943 | snprintf(card->longname, sizeof(card->longname), |
Greg Kroah-Hartman | aa0a2dd | 2006-06-12 14:50:27 -0700 | [diff] [blame] | 944 | "%s at 0x%016llx, irq %d", |
| 945 | card->shortname, (unsigned long long)dev->res.start, |
| 946 | dev->irq[0]); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 947 | |
| 948 | aaci = card->private_data; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 949 | mutex_init(&aaci->ac97_sem); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 950 | aaci->card = card; |
| 951 | aaci->dev = dev; |
| 952 | |
| 953 | /* Set MAINCR to allow slot 1 and 2 data IO */ |
| 954 | aaci->maincr = MAINCR_IE | MAINCR_SL1RXEN | MAINCR_SL1TXEN | |
| 955 | MAINCR_SL2RXEN | MAINCR_SL2TXEN; |
| 956 | |
| 957 | return aaci; |
| 958 | } |
| 959 | |
| 960 | static int __devinit aaci_init_pcm(struct aaci *aaci) |
| 961 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 962 | struct snd_pcm *pcm; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 963 | int ret; |
| 964 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 965 | ret = snd_pcm_new(aaci->card, "AACI AC'97", 0, 1, 1, &pcm); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 966 | if (ret == 0) { |
| 967 | aaci->pcm = pcm; |
| 968 | pcm->private_data = aaci; |
| 969 | pcm->info_flags = 0; |
| 970 | |
| 971 | strlcpy(pcm->name, DRIVER_NAME, sizeof(pcm->name)); |
| 972 | |
| 973 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &aaci_playback_ops); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 974 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &aaci_capture_ops); |
Takashi Iwai | d679732 | 2009-11-26 15:08:54 +0100 | [diff] [blame] | 975 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
Takashi Iwai | d494643 | 2009-12-18 20:25:30 +0100 | [diff] [blame] | 976 | NULL, 0, 64 * 1024); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | return ret; |
| 980 | } |
| 981 | |
| 982 | static unsigned int __devinit aaci_size_fifo(struct aaci *aaci) |
| 983 | { |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 984 | struct aaci_runtime *aacirun = &aaci->playback; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 985 | int i; |
| 986 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 987 | writel(CR_FEN | CR_SZ16 | CR_EN, aacirun->base + AACI_TXCR); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 988 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 989 | for (i = 0; !(readl(aacirun->base + AACI_SR) & SR_TXFF) && i < 4096; i++) |
| 990 | writel(0, aacirun->fifo); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 991 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 992 | writel(0, aacirun->base + AACI_TXCR); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 993 | |
| 994 | /* |
| 995 | * Re-initialise the AACI after the FIFO depth test, to |
| 996 | * ensure that the FIFOs are empty. Unfortunately, merely |
| 997 | * disabling the channel doesn't clear the FIFO. |
| 998 | */ |
| 999 | writel(aaci->maincr & ~MAINCR_IE, aaci->base + AACI_MAINCR); |
Russell King | 7c28938 | 2011-02-05 10:41:55 +0000 | [diff] [blame] | 1000 | readl(aaci->base + AACI_MAINCR); |
| 1001 | udelay(1); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1002 | writel(aaci->maincr, aaci->base + AACI_MAINCR); |
| 1003 | |
| 1004 | /* |
| 1005 | * If we hit 4096, we failed. Go back to the specified |
| 1006 | * fifo depth. |
| 1007 | */ |
| 1008 | if (i == 4096) |
| 1009 | i = 8; |
| 1010 | |
| 1011 | return i; |
| 1012 | } |
| 1013 | |
Russell King | aa25afa | 2011-02-19 15:55:00 +0000 | [diff] [blame^] | 1014 | static int __devinit aaci_probe(struct amba_device *dev, |
| 1015 | const struct amba_id *id) |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1016 | { |
| 1017 | struct aaci *aaci; |
| 1018 | int ret, i; |
| 1019 | |
| 1020 | ret = amba_request_regions(dev, NULL); |
| 1021 | if (ret) |
| 1022 | return ret; |
| 1023 | |
| 1024 | aaci = aaci_init_card(dev); |
Takashi Iwai | 631e8ad | 2008-09-01 15:31:50 +0200 | [diff] [blame] | 1025 | if (!aaci) { |
| 1026 | ret = -ENOMEM; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1027 | goto out; |
| 1028 | } |
| 1029 | |
Linus Walleij | dc890c2 | 2009-06-07 23:27:31 +0100 | [diff] [blame] | 1030 | aaci->base = ioremap(dev->res.start, resource_size(&dev->res)); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1031 | if (!aaci->base) { |
| 1032 | ret = -ENOMEM; |
| 1033 | goto out; |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Playback uses AACI channel 0 |
| 1038 | */ |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 1039 | spin_lock_init(&aaci->playback.lock); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1040 | aaci->playback.base = aaci->base + AACI_CSCH1; |
| 1041 | aaci->playback.fifo = aaci->base + AACI_DR1; |
| 1042 | |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 1043 | /* |
| 1044 | * Capture uses AACI channel 0 |
| 1045 | */ |
Russell King | d6a89fe | 2009-12-18 17:48:50 +0000 | [diff] [blame] | 1046 | spin_lock_init(&aaci->capture.lock); |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 1047 | aaci->capture.base = aaci->base + AACI_CSCH1; |
| 1048 | aaci->capture.fifo = aaci->base + AACI_DR1; |
| 1049 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1050 | for (i = 0; i < 4; i++) { |
viro@ZenIV.linux.org.uk | e12ba64 | 2005-09-06 02:06:57 +0100 | [diff] [blame] | 1051 | void __iomem *base = aaci->base + i * 0x14; |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1052 | |
| 1053 | writel(0, base + AACI_IE); |
| 1054 | writel(0, base + AACI_TXCR); |
| 1055 | writel(0, base + AACI_RXCR); |
| 1056 | } |
| 1057 | |
| 1058 | writel(0x1fff, aaci->base + AACI_INTCLR); |
| 1059 | writel(aaci->maincr, aaci->base + AACI_MAINCR); |
Philby John | b68b58f | 2010-03-26 21:37:51 +0530 | [diff] [blame] | 1060 | /* |
| 1061 | * Fix: ac97 read back fail errors by reading |
| 1062 | * from any arbitrary aaci register. |
| 1063 | */ |
| 1064 | readl(aaci->base + AACI_CSCH1); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1065 | ret = aaci_probe_ac97(aaci); |
| 1066 | if (ret) |
| 1067 | goto out; |
| 1068 | |
Catalin Marinas | f27f218 | 2006-02-01 19:25:58 +0000 | [diff] [blame] | 1069 | /* |
| 1070 | * Size the FIFOs (must be multiple of 16). |
| 1071 | */ |
| 1072 | aaci->fifosize = aaci_size_fifo(aaci); |
| 1073 | if (aaci->fifosize & 15) { |
| 1074 | printk(KERN_WARNING "AACI: fifosize = %d not supported\n", |
| 1075 | aaci->fifosize); |
| 1076 | ret = -ENODEV; |
| 1077 | goto out; |
| 1078 | } |
| 1079 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1080 | ret = aaci_init_pcm(aaci); |
| 1081 | if (ret) |
| 1082 | goto out; |
| 1083 | |
Takashi Iwai | a76af19 | 2005-09-05 16:56:40 +0200 | [diff] [blame] | 1084 | snd_card_set_dev(aaci->card, &dev->dev); |
| 1085 | |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1086 | ret = snd_card_register(aaci->card); |
| 1087 | if (ret == 0) { |
| 1088 | dev_info(&dev->dev, "%s, fifo %d\n", aaci->card->longname, |
Kevin Hilman | 41762b8 | 2007-02-07 05:45:32 +0100 | [diff] [blame] | 1089 | aaci->fifosize); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1090 | amba_set_drvdata(dev, aaci->card); |
| 1091 | return ret; |
| 1092 | } |
| 1093 | |
| 1094 | out: |
| 1095 | if (aaci) |
| 1096 | snd_card_free(aaci->card); |
| 1097 | amba_release_regions(dev); |
| 1098 | return ret; |
| 1099 | } |
| 1100 | |
| 1101 | static int __devexit aaci_remove(struct amba_device *dev) |
| 1102 | { |
Takashi Iwai | ceb9e47 | 2005-11-17 15:10:16 +0100 | [diff] [blame] | 1103 | struct snd_card *card = amba_get_drvdata(dev); |
Russell King | cb5a6ff | 2005-05-12 14:04:59 +0200 | [diff] [blame] | 1104 | |
| 1105 | amba_set_drvdata(dev, NULL); |
| 1106 | |
| 1107 | if (card) { |
| 1108 | struct aaci *aaci = card->private_data; |
| 1109 | writel(0, aaci->base + AACI_MAINCR); |
| 1110 | |
| 1111 | snd_card_free(card); |
| 1112 | amba_release_regions(dev); |
| 1113 | } |
| 1114 | |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static struct amba_id aaci_ids[] = { |
| 1119 | { |
| 1120 | .id = 0x00041041, |
| 1121 | .mask = 0x000fffff, |
| 1122 | }, |
| 1123 | { 0, 0 }, |
| 1124 | }; |
| 1125 | |
| 1126 | static struct amba_driver aaci_driver = { |
| 1127 | .drv = { |
| 1128 | .name = DRIVER_NAME, |
| 1129 | }, |
| 1130 | .probe = aaci_probe, |
| 1131 | .remove = __devexit_p(aaci_remove), |
| 1132 | .suspend = aaci_suspend, |
| 1133 | .resume = aaci_resume, |
| 1134 | .id_table = aaci_ids, |
| 1135 | }; |
| 1136 | |
| 1137 | static int __init aaci_init(void) |
| 1138 | { |
| 1139 | return amba_driver_register(&aaci_driver); |
| 1140 | } |
| 1141 | |
| 1142 | static void __exit aaci_exit(void) |
| 1143 | { |
| 1144 | amba_driver_unregister(&aaci_driver); |
| 1145 | } |
| 1146 | |
| 1147 | module_init(aaci_init); |
| 1148 | module_exit(aaci_exit); |
| 1149 | |
| 1150 | MODULE_LICENSE("GPL"); |
| 1151 | MODULE_DESCRIPTION("ARM PrimeCell PL041 Advanced Audio CODEC Interface driver"); |