Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip. |
| 3 | * |
| 4 | * Author: Nicolas Pitre |
| 5 | * Created: Dec 02, 2004 |
| 6 | * Copyright: MontaVista Software Inc. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/wait.h> |
| 19 | #include <linux/delay.h> |
| 20 | |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/ac97_codec.h> |
| 24 | #include <sound/initval.h> |
| 25 | |
| 26 | #include <asm/irq.h> |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 28 | #include <asm/hardware.h> |
| 29 | #include <asm/arch/pxa-regs.h> |
| 30 | #include <asm/arch/audio.h> |
| 31 | |
| 32 | #include "pxa2xx-pcm.h" |
| 33 | |
| 34 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 35 | static DEFINE_MUTEX(car_mutex); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 36 | static DECLARE_WAIT_QUEUE_HEAD(gsr_wq); |
| 37 | static volatile long gsr_bits; |
| 38 | |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 39 | /* |
| 40 | * Beware PXA27x bugs: |
| 41 | * |
| 42 | * o Slot 12 read from modem space will hang controller. |
| 43 | * o CDONE, SDONE interrupt fails after any slot 12 IO. |
| 44 | * |
| 45 | * We therefore have an hybrid approach for waiting on SDONE (interrupt or |
| 46 | * 1 jiffy timeout if interrupt never comes). |
| 47 | */ |
| 48 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 49 | static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 50 | { |
| 51 | unsigned short val = -1; |
| 52 | volatile u32 *reg_addr; |
| 53 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 54 | mutex_lock(&car_mutex); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 55 | |
| 56 | /* set up primary or secondary codec space */ |
| 57 | reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE; |
| 58 | reg_addr += (reg >> 1); |
| 59 | |
| 60 | /* start read access across the ac97 link */ |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 61 | GSR = GSR_CDONE | GSR_SDONE; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 62 | gsr_bits = 0; |
| 63 | val = *reg_addr; |
| 64 | if (reg == AC97_GPIO_STATUS) |
| 65 | goto out; |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 66 | if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && |
| 67 | !((GSR | gsr_bits) & GSR_SDONE)) { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 68 | printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 69 | __FUNCTION__, reg, GSR | gsr_bits); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 70 | val = -1; |
| 71 | goto out; |
| 72 | } |
| 73 | |
| 74 | /* valid data now */ |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 75 | GSR = GSR_CDONE | GSR_SDONE; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 76 | gsr_bits = 0; |
| 77 | val = *reg_addr; |
| 78 | /* but we've just started another cycle... */ |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 79 | wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 80 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 81 | out: mutex_unlock(&car_mutex); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 82 | return val; |
| 83 | } |
| 84 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 85 | static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 86 | { |
| 87 | volatile u32 *reg_addr; |
| 88 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 89 | mutex_lock(&car_mutex); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 90 | |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 91 | /* set up primary or secondary codec space */ |
| 92 | reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE; |
| 93 | reg_addr += (reg >> 1); |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 94 | |
| 95 | GSR = GSR_CDONE | GSR_SDONE; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 96 | gsr_bits = 0; |
| 97 | *reg_addr = val; |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 98 | if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && |
| 99 | !((GSR | gsr_bits) & GSR_CDONE)) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 100 | printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", |
Nicolas Pitre | ea265c0 | 2005-12-12 15:41:47 +0100 | [diff] [blame] | 101 | __FUNCTION__, reg, GSR | gsr_bits); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 102 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 103 | mutex_unlock(&car_mutex); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 106 | static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 107 | { |
| 108 | /* First, try cold reset */ |
| 109 | GCR &= GCR_COLD_RST; /* clear everything but nCRST */ |
| 110 | GCR &= ~GCR_COLD_RST; /* then assert nCRST */ |
| 111 | |
| 112 | gsr_bits = 0; |
| 113 | #ifdef CONFIG_PXA27x |
| 114 | /* PXA27x Developers Manual section 13.5.2.2.1 */ |
Michael Brunner | 03d14a5 | 2007-12-04 21:39:20 +0100 | [diff] [blame] | 115 | pxa_set_cken(CKEN_AC97CONF, 1); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 116 | udelay(5); |
Michael Brunner | 03d14a5 | 2007-12-04 21:39:20 +0100 | [diff] [blame] | 117 | pxa_set_cken(CKEN_AC97CONF, 0); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 118 | GCR = GCR_COLD_RST; |
| 119 | udelay(50); |
| 120 | #else |
| 121 | GCR = GCR_COLD_RST; |
| 122 | GCR |= GCR_CDONE_IE|GCR_SDONE_IE; |
| 123 | wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); |
| 124 | #endif |
| 125 | |
| 126 | if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) { |
| 127 | printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", |
| 128 | __FUNCTION__, gsr_bits); |
| 129 | |
| 130 | /* let's try warm reset */ |
| 131 | gsr_bits = 0; |
| 132 | #ifdef CONFIG_PXA27x |
| 133 | /* warm reset broken on Bulverde, |
| 134 | so manually keep AC97 reset high */ |
| 135 | pxa_gpio_mode(113 | GPIO_OUT | GPIO_DFLT_HIGH); |
| 136 | udelay(10); |
| 137 | GCR |= GCR_WARM_RST; |
| 138 | pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); |
Liam Girdwood | 4a677ac5 | 2005-08-05 10:24:36 +0200 | [diff] [blame] | 139 | udelay(500); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 140 | #else |
Liam Girdwood | 4a677ac5 | 2005-08-05 10:24:36 +0200 | [diff] [blame] | 141 | GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 142 | wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); |
| 143 | #endif |
| 144 | |
| 145 | if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) |
| 146 | printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", |
| 147 | __FUNCTION__, gsr_bits); |
| 148 | } |
| 149 | |
| 150 | GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); |
| 151 | GCR |= GCR_SDONE_IE|GCR_CDONE_IE; |
| 152 | } |
| 153 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 154 | static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 155 | { |
| 156 | long status; |
| 157 | |
| 158 | status = GSR; |
| 159 | if (status) { |
| 160 | GSR = status; |
| 161 | gsr_bits |= status; |
| 162 | wake_up(&gsr_wq); |
| 163 | |
| 164 | #ifdef CONFIG_PXA27x |
| 165 | /* Although we don't use those we still need to clear them |
| 166 | since they tend to spuriously trigger when MMC is used |
| 167 | (hardware bug? go figure)... */ |
| 168 | MISR = MISR_EOC; |
| 169 | PISR = PISR_EOC; |
| 170 | MCSR = MCSR_EOC; |
| 171 | #endif |
| 172 | |
| 173 | return IRQ_HANDLED; |
| 174 | } |
| 175 | |
| 176 | return IRQ_NONE; |
| 177 | } |
| 178 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 179 | static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 180 | .read = pxa2xx_ac97_read, |
| 181 | .write = pxa2xx_ac97_write, |
| 182 | .reset = pxa2xx_ac97_reset, |
| 183 | }; |
| 184 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 185 | static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_out = { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 186 | .name = "AC97 PCM out", |
| 187 | .dev_addr = __PREG(PCDR), |
| 188 | .drcmr = &DRCMRTXPCDR, |
| 189 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | |
| 190 | DCMD_BURST32 | DCMD_WIDTH4, |
| 191 | }; |
| 192 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 193 | static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_in = { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 194 | .name = "AC97 PCM in", |
| 195 | .dev_addr = __PREG(PCDR), |
| 196 | .drcmr = &DRCMRRXPCDR, |
| 197 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | |
| 198 | DCMD_BURST32 | DCMD_WIDTH4, |
| 199 | }; |
| 200 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 201 | static struct snd_pcm *pxa2xx_ac97_pcm; |
| 202 | static struct snd_ac97 *pxa2xx_ac97_ac97; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 203 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 204 | static int pxa2xx_ac97_pcm_startup(struct snd_pcm_substream *substream) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 205 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 206 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 207 | pxa2xx_audio_ops_t *platform_ops; |
| 208 | int r; |
| 209 | |
| 210 | runtime->hw.channels_min = 2; |
| 211 | runtime->hw.channels_max = 2; |
| 212 | |
| 213 | r = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
| 214 | AC97_RATES_FRONT_DAC : AC97_RATES_ADC; |
| 215 | runtime->hw.rates = pxa2xx_ac97_ac97->rates[r]; |
| 216 | snd_pcm_limit_hw_rates(runtime); |
| 217 | |
| 218 | platform_ops = substream->pcm->card->dev->platform_data; |
| 219 | if (platform_ops && platform_ops->startup) |
| 220 | return platform_ops->startup(substream, platform_ops->priv); |
| 221 | else |
| 222 | return 0; |
| 223 | } |
| 224 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 225 | static void pxa2xx_ac97_pcm_shutdown(struct snd_pcm_substream *substream) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 226 | { |
| 227 | pxa2xx_audio_ops_t *platform_ops; |
| 228 | |
| 229 | platform_ops = substream->pcm->card->dev->platform_data; |
| 230 | if (platform_ops && platform_ops->shutdown) |
| 231 | platform_ops->shutdown(substream, platform_ops->priv); |
| 232 | } |
| 233 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 234 | static int pxa2xx_ac97_pcm_prepare(struct snd_pcm_substream *substream) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 235 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 236 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 237 | int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
| 238 | AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; |
| 239 | return snd_ac97_set_rate(pxa2xx_ac97_ac97, reg, runtime->rate); |
| 240 | } |
| 241 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 242 | static struct pxa2xx_pcm_client pxa2xx_ac97_pcm_client = { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 243 | .playback_params = &pxa2xx_ac97_pcm_out, |
| 244 | .capture_params = &pxa2xx_ac97_pcm_in, |
| 245 | .startup = pxa2xx_ac97_pcm_startup, |
| 246 | .shutdown = pxa2xx_ac97_pcm_shutdown, |
| 247 | .prepare = pxa2xx_ac97_pcm_prepare, |
| 248 | }; |
| 249 | |
| 250 | #ifdef CONFIG_PM |
| 251 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 252 | static int pxa2xx_ac97_do_suspend(struct snd_card *card, pm_message_t state) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 253 | { |
Takashi Iwai | 792a6c5 | 2005-11-17 17:19:25 +0100 | [diff] [blame] | 254 | pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; |
| 255 | |
| 256 | snd_power_change_state(card, SNDRV_CTL_POWER_D3cold); |
| 257 | snd_pcm_suspend_all(pxa2xx_ac97_pcm); |
| 258 | snd_ac97_suspend(pxa2xx_ac97_ac97); |
| 259 | if (platform_ops && platform_ops->suspend) |
| 260 | platform_ops->suspend(platform_ops->priv); |
| 261 | GCR |= GCR_ACLINK_OFF; |
Eric Miao | 7053acb | 2007-04-05 04:07:20 +0100 | [diff] [blame] | 262 | pxa_set_cken(CKEN_AC97, 0); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 267 | static int pxa2xx_ac97_do_resume(struct snd_card *card) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 268 | { |
Takashi Iwai | 792a6c5 | 2005-11-17 17:19:25 +0100 | [diff] [blame] | 269 | pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; |
| 270 | |
Eric Miao | 7053acb | 2007-04-05 04:07:20 +0100 | [diff] [blame] | 271 | pxa_set_cken(CKEN_AC97, 1); |
Takashi Iwai | 792a6c5 | 2005-11-17 17:19:25 +0100 | [diff] [blame] | 272 | if (platform_ops && platform_ops->resume) |
| 273 | platform_ops->resume(platform_ops->priv); |
| 274 | snd_ac97_resume(pxa2xx_ac97_ac97); |
| 275 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 280 | static int pxa2xx_ac97_suspend(struct platform_device *dev, pm_message_t state) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 281 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 282 | struct snd_card *card = platform_get_drvdata(dev); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 283 | int ret = 0; |
| 284 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 285 | if (card) |
Dirk Opfer | a55bfdc | 2005-08-08 16:29:43 +0200 | [diff] [blame] | 286 | ret = pxa2xx_ac97_do_suspend(card, PMSG_SUSPEND); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 287 | |
| 288 | return ret; |
| 289 | } |
| 290 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 291 | static int pxa2xx_ac97_resume(struct platform_device *dev) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 292 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 293 | struct snd_card *card = platform_get_drvdata(dev); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 294 | int ret = 0; |
| 295 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 296 | if (card) |
Dirk Opfer | a55bfdc | 2005-08-08 16:29:43 +0200 | [diff] [blame] | 297 | ret = pxa2xx_ac97_do_resume(card); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 298 | |
| 299 | return ret; |
| 300 | } |
| 301 | |
| 302 | #else |
| 303 | #define pxa2xx_ac97_suspend NULL |
| 304 | #define pxa2xx_ac97_resume NULL |
| 305 | #endif |
| 306 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 307 | static int __devinit pxa2xx_ac97_probe(struct platform_device *dev) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 308 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 309 | struct snd_card *card; |
| 310 | struct snd_ac97_bus *ac97_bus; |
| 311 | struct snd_ac97_template ac97_template; |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 312 | int ret; |
| 313 | |
| 314 | ret = -ENOMEM; |
| 315 | card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
| 316 | THIS_MODULE, 0); |
| 317 | if (!card) |
| 318 | goto err; |
| 319 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 320 | card->dev = &dev->dev; |
| 321 | strncpy(card->driver, dev->dev.driver->name, sizeof(card->driver)); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 322 | |
| 323 | ret = pxa2xx_pcm_new(card, &pxa2xx_ac97_pcm_client, &pxa2xx_ac97_pcm); |
| 324 | if (ret) |
| 325 | goto err; |
| 326 | |
| 327 | ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL); |
| 328 | if (ret < 0) |
| 329 | goto err; |
| 330 | |
| 331 | pxa_gpio_mode(GPIO31_SYNC_AC97_MD); |
| 332 | pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD); |
| 333 | pxa_gpio_mode(GPIO28_BITCLK_AC97_MD); |
| 334 | pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD); |
| 335 | #ifdef CONFIG_PXA27x |
| 336 | /* Use GPIO 113 as AC97 Reset on Bulverde */ |
| 337 | pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); |
| 338 | #endif |
Eric Miao | 7053acb | 2007-04-05 04:07:20 +0100 | [diff] [blame] | 339 | pxa_set_cken(CKEN_AC97, 1); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 340 | |
| 341 | ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus); |
| 342 | if (ret) |
| 343 | goto err; |
| 344 | memset(&ac97_template, 0, sizeof(ac97_template)); |
| 345 | ret = snd_ac97_mixer(ac97_bus, &ac97_template, &pxa2xx_ac97_ac97); |
| 346 | if (ret) |
| 347 | goto err; |
| 348 | |
| 349 | snprintf(card->shortname, sizeof(card->shortname), |
| 350 | "%s", snd_ac97_get_short_name(pxa2xx_ac97_ac97)); |
| 351 | snprintf(card->longname, sizeof(card->longname), |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 352 | "%s (%s)", dev->dev.driver->name, card->mixername); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 353 | |
Takashi Iwai | f78dfac | 2007-12-17 16:24:04 +0100 | [diff] [blame] | 354 | snd_card_set_dev(card, &dev->dev); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 355 | ret = snd_card_register(card); |
| 356 | if (ret == 0) { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 357 | platform_set_drvdata(dev, card); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | err: |
| 362 | if (card) |
| 363 | snd_card_free(card); |
Richard Purdie | 1f750a7 | 2007-07-02 10:19:07 +0100 | [diff] [blame] | 364 | if (CKEN & (1 << CKEN_AC97)) { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 365 | GCR |= GCR_ACLINK_OFF; |
| 366 | free_irq(IRQ_AC97, NULL); |
Eric Miao | 7053acb | 2007-04-05 04:07:20 +0100 | [diff] [blame] | 367 | pxa_set_cken(CKEN_AC97, 0); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 368 | } |
| 369 | return ret; |
| 370 | } |
| 371 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 372 | static int __devexit pxa2xx_ac97_remove(struct platform_device *dev) |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 373 | { |
Takashi Iwai | d18f837 | 2005-11-17 15:10:38 +0100 | [diff] [blame] | 374 | struct snd_card *card = platform_get_drvdata(dev); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 375 | |
| 376 | if (card) { |
| 377 | snd_card_free(card); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 378 | platform_set_drvdata(dev, NULL); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 379 | GCR |= GCR_ACLINK_OFF; |
| 380 | free_irq(IRQ_AC97, NULL); |
Eric Miao | 7053acb | 2007-04-05 04:07:20 +0100 | [diff] [blame] | 381 | pxa_set_cken(CKEN_AC97, 0); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 387 | static struct platform_driver pxa2xx_ac97_driver = { |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 388 | .probe = pxa2xx_ac97_probe, |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 389 | .remove = __devexit_p(pxa2xx_ac97_remove), |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 390 | .suspend = pxa2xx_ac97_suspend, |
| 391 | .resume = pxa2xx_ac97_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 392 | .driver = { |
| 393 | .name = "pxa2xx-ac97", |
| 394 | }, |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | static int __init pxa2xx_ac97_init(void) |
| 398 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 399 | return platform_driver_register(&pxa2xx_ac97_driver); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static void __exit pxa2xx_ac97_exit(void) |
| 403 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 404 | platform_driver_unregister(&pxa2xx_ac97_driver); |
Takashi Iwai | 2c484df | 2005-06-30 18:54:04 +0200 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | module_init(pxa2xx_ac97_init); |
| 408 | module_exit(pxa2xx_ac97_exit); |
| 409 | |
| 410 | MODULE_AUTHOR("Nicolas Pitre"); |
| 411 | MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); |
| 412 | MODULE_LICENSE("GPL"); |