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