Blame view

sound/arm/pxa2xx-ac97.c 6.32 KB
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip.
   *
   * Author:	Nicolas Pitre
   * Created:	Dec 02, 2004
   * Copyright:	MontaVista Software Inc.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
  
  #include <linux/init.h>
  #include <linux/module.h>
d052d1bef   Russell King   Create platform_d...
15
  #include <linux/platform_device.h>
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
16

2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
17
18
19
20
  #include <sound/core.h>
  #include <sound/pcm.h>
  #include <sound/ac97_codec.h>
  #include <sound/initval.h>
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
21
  #include <sound/pxa2xx-lib.h>
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
22

1f017a996   Eric Miao   [ARM] pxa: move A...
23
  #include <mach/regs-ac97.h>
a09e64fbc   Russell King   [ARM] Move includ...
24
  #include <mach/audio.h>
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
25
26
  
  #include "pxa2xx-pcm.h"
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
27
  static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
28
  {
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
29
30
  	if (!pxa2xx_ac97_try_cold_reset(ac97)) {
  		pxa2xx_ac97_try_warm_reset(ac97);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
31
  	}
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
32
  	pxa2xx_ac97_finish_reset(ac97);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
33
  }
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
34
  static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
35
36
37
38
  	.read	= pxa2xx_ac97_read,
  	.write	= pxa2xx_ac97_write,
  	.reset	= pxa2xx_ac97_reset,
  };
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
39
  static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_out = {
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
40
41
  	.name			= "AC97 PCM out",
  	.dev_addr		= __PREG(PCDR),
87f3dd779   Eric Miao   [ARM] pxa: simpli...
42
  	.drcmr			= &DRCMR(12),
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
43
44
45
  	.dcmd			= DCMD_INCSRCADDR | DCMD_FLOWTRG |
  				  DCMD_BURST32 | DCMD_WIDTH4,
  };
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
46
  static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_in = {
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
47
48
  	.name			= "AC97 PCM in",
  	.dev_addr		= __PREG(PCDR),
87f3dd779   Eric Miao   [ARM] pxa: simpli...
49
  	.drcmr			= &DRCMR(11),
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
50
51
52
  	.dcmd			= DCMD_INCTRGADDR | DCMD_FLOWSRC |
  				  DCMD_BURST32 | DCMD_WIDTH4,
  };
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
53
54
  static struct snd_pcm *pxa2xx_ac97_pcm;
  static struct snd_ac97 *pxa2xx_ac97_ac97;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
55

d18f83764   Takashi Iwai   [ALSA] Remove xxx...
56
  static int pxa2xx_ac97_pcm_startup(struct snd_pcm_substream *substream)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
57
  {
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
58
  	struct snd_pcm_runtime *runtime = substream->runtime;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  	pxa2xx_audio_ops_t *platform_ops;
  	int r;
  
  	runtime->hw.channels_min = 2;
  	runtime->hw.channels_max = 2;
  
  	r = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  	    AC97_RATES_FRONT_DAC : AC97_RATES_ADC;
  	runtime->hw.rates = pxa2xx_ac97_ac97->rates[r];
  	snd_pcm_limit_hw_rates(runtime);
  
         	platform_ops = substream->pcm->card->dev->platform_data;
  	if (platform_ops && platform_ops->startup)
  		return platform_ops->startup(substream, platform_ops->priv);
  	else
  		return 0;
  }
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
76
  static void pxa2xx_ac97_pcm_shutdown(struct snd_pcm_substream *substream)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
77
78
79
80
81
82
83
  {
  	pxa2xx_audio_ops_t *platform_ops;
  
         	platform_ops = substream->pcm->card->dev->platform_data;
  	if (platform_ops && platform_ops->shutdown)
  		platform_ops->shutdown(substream, platform_ops->priv);
  }
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
84
  static int pxa2xx_ac97_pcm_prepare(struct snd_pcm_substream *substream)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
85
  {
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
86
  	struct snd_pcm_runtime *runtime = substream->runtime;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
87
88
89
90
  	int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  		  AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
  	return snd_ac97_set_rate(pxa2xx_ac97_ac97, reg, runtime->rate);
  }
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
91
  static struct pxa2xx_pcm_client pxa2xx_ac97_pcm_client = {
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
92
93
94
95
96
97
98
99
  	.playback_params	= &pxa2xx_ac97_pcm_out,
  	.capture_params		= &pxa2xx_ac97_pcm_in,
  	.startup		= pxa2xx_ac97_pcm_startup,
  	.shutdown		= pxa2xx_ac97_pcm_shutdown,
  	.prepare		= pxa2xx_ac97_pcm_prepare,
  };
  
  #ifdef CONFIG_PM
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
100
  static int pxa2xx_ac97_do_suspend(struct snd_card *card, pm_message_t state)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
101
  {
792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
102
103
104
105
106
107
108
  	pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
  
  	snd_power_change_state(card, SNDRV_CTL_POWER_D3cold);
  	snd_pcm_suspend_all(pxa2xx_ac97_pcm);
  	snd_ac97_suspend(pxa2xx_ac97_ac97);
  	if (platform_ops && platform_ops->suspend)
  		platform_ops->suspend(platform_ops->priv);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
109

9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
110
  	return pxa2xx_ac97_hw_suspend();
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
111
  }
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
112
  static int pxa2xx_ac97_do_resume(struct snd_card *card)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
113
  {
792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
114
  	pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
115
116
117
118
119
  	int rc;
  
  	rc = pxa2xx_ac97_hw_resume();
  	if (rc)
  		return rc;
792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
120

792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
121
122
123
124
  	if (platform_ops && platform_ops->resume)
  		platform_ops->resume(platform_ops->priv);
  	snd_ac97_resume(pxa2xx_ac97_ac97);
  	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
125
126
127
  
  	return 0;
  }
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
128
  static int pxa2xx_ac97_suspend(struct device *dev)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
129
  {
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
130
  	struct snd_card *card = dev_get_drvdata(dev);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
131
  	int ret = 0;
9480e307c   Russell King   [PATCH] DRIVER MO...
132
  	if (card)
a55bfdc58   Dirk Opfer   [ALSA] Fix compil...
133
  		ret = pxa2xx_ac97_do_suspend(card, PMSG_SUSPEND);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
134
135
136
  
  	return ret;
  }
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
137
  static int pxa2xx_ac97_resume(struct device *dev)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
138
  {
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
139
  	struct snd_card *card = dev_get_drvdata(dev);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
140
  	int ret = 0;
9480e307c   Russell King   [PATCH] DRIVER MO...
141
  	if (card)
a55bfdc58   Dirk Opfer   [ALSA] Fix compil...
142
  		ret = pxa2xx_ac97_do_resume(card);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
143
144
145
  
  	return ret;
  }
471452104   Alexey Dobriyan   const: constify r...
146
  static const struct dev_pm_ops pxa2xx_ac97_pm_ops = {
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
147
148
149
  	.suspend	= pxa2xx_ac97_suspend,
  	.resume		= pxa2xx_ac97_resume,
  };
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
150
  #endif
788c60433   Prarit Bhargava   [ALSA] Fix __devi...
151
  static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
152
  {
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
153
154
155
  	struct snd_card *card;
  	struct snd_ac97_bus *ac97_bus;
  	struct snd_ac97_template ac97_template;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
156
  	int ret;
4ac0478f2   Marek Vasut   ALSA: Allow passi...
157
158
159
160
161
162
163
164
  	pxa2xx_audio_ops_t *pdata = dev->dev.platform_data;
  
  	if (dev->id >= 0) {
  		dev_err(&dev->dev, "PXA2xx has only one AC97 port.
  ");
  		ret = -ENXIO;
  		goto err_dev;
  	}
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
165

bd7dd77c2   Takashi Iwai   ALSA: Convert to ...
166
167
168
  	ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
  			      THIS_MODULE, 0, &card);
  	if (ret < 0)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
169
  		goto err;
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
170
171
  	card->dev = &dev->dev;
  	strncpy(card->driver, dev->dev.driver->name, sizeof(card->driver));
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
172
173
174
175
  
  	ret = pxa2xx_pcm_new(card, &pxa2xx_ac97_pcm_client, &pxa2xx_ac97_pcm);
  	if (ret)
  		goto err;
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
176
177
  	ret = pxa2xx_ac97_hw_probe(dev);
  	if (ret)
93873fbfd   Mark Brown   [ARM] 4833/3: Con...
178
  		goto err;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
179
180
181
  
  	ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus);
  	if (ret)
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
182
  		goto err_remove;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
183
184
185
  	memset(&ac97_template, 0, sizeof(ac97_template));
  	ret = snd_ac97_mixer(ac97_bus, &ac97_template, &pxa2xx_ac97_ac97);
  	if (ret)
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
186
  		goto err_remove;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
187
188
189
190
  
  	snprintf(card->shortname, sizeof(card->shortname),
  		 "%s", snd_ac97_get_short_name(pxa2xx_ac97_ac97));
  	snprintf(card->longname, sizeof(card->longname),
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
191
  		 "%s (%s)", dev->dev.driver->name, card->mixername);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
192

367da1527   Robert Schwebel   ASoC: fix pxa2xx-...
193
  	if (pdata && pdata->codec_pdata[0])
e2365bf31   Marek Vasut   ASoC: Pass correc...
194
  		snd_ac97_dev_add_pdata(ac97_bus->codec[0], pdata->codec_pdata[0]);
f78dfac90   Takashi Iwai   [ALSA] Add missin...
195
  	snd_card_set_dev(card, &dev->dev);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
196
197
  	ret = snd_card_register(card);
  	if (ret == 0) {
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
198
  		platform_set_drvdata(dev, card);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
199
200
  		return 0;
  	}
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
201
202
203
  err_remove:
  	pxa2xx_ac97_hw_remove(dev);
  err:
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
204
205
  	if (card)
  		snd_card_free(card);
4ac0478f2   Marek Vasut   ALSA: Allow passi...
206
  err_dev:
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
207
208
  	return ret;
  }
788c60433   Prarit Bhargava   [ALSA] Fix __devi...
209
  static int __devexit pxa2xx_ac97_remove(struct platform_device *dev)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
210
  {
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
211
  	struct snd_card *card = platform_get_drvdata(dev);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
212
213
214
  
  	if (card) {
  		snd_card_free(card);
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
215
  		platform_set_drvdata(dev, NULL);
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
216
  		pxa2xx_ac97_hw_remove(dev);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
217
218
219
220
  	}
  
  	return 0;
  }
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
221
  static struct platform_driver pxa2xx_ac97_driver = {
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
222
  	.probe		= pxa2xx_ac97_probe,
788c60433   Prarit Bhargava   [ALSA] Fix __devi...
223
  	.remove		= __devexit_p(pxa2xx_ac97_remove),
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
224
225
  	.driver		= {
  		.name	= "pxa2xx-ac97",
8b45a2099   Kay Sievers   [ALSA] sound: fix...
226
  		.owner	= THIS_MODULE,
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
227
228
229
  #ifdef CONFIG_PM
  		.pm	= &pxa2xx_ac97_pm_ops,
  #endif
3ae5eaec1   Russell King   [DRIVER MODEL] Co...
230
  	},
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
231
  };
a09452eeb   Axel Lin   ALSA: convert sou...
232
  module_platform_driver(pxa2xx_ac97_driver);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
233
234
235
236
  
  MODULE_AUTHOR("Nicolas Pitre");
  MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
  MODULE_LICENSE("GPL");
8b45a2099   Kay Sievers   [ALSA] sound: fix...
237
  MODULE_ALIAS("platform:pxa2xx-ac97");