Blame view

sound/arm/pxa2xx-ac97.c 6.37 KB
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
1
2
3
4
5
6
7
8
9
10
11
12
13
  /*
   * 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>
23019a733   Rob Herring   ARM: pxa: use com...
14
  #include <linux/io.h>
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
15
  #include <linux/module.h>
d052d1bef   Russell King   Create platform_d...
16
  #include <linux/platform_device.h>
d65a14587   Daniel Mack   ASoC: pxa: use sn...
17
  #include <linux/dmaengine.h>
58ceb57ec   Daniel Mack   ASoC: pxa: pxa-pc...
18
  #include <linux/dma/pxa-dma.h>
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
19

2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
20
21
22
23
  #include <sound/core.h>
  #include <sound/pcm.h>
  #include <sound/ac97_codec.h>
  #include <sound/initval.h>
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
24
  #include <sound/pxa2xx-lib.h>
d65a14587   Daniel Mack   ASoC: pxa: use sn...
25
  #include <sound/dmaengine_pcm.h>
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
26

1f017a996   Eric Miao   [ARM] pxa: move A...
27
  #include <mach/regs-ac97.h>
a09e64fbc   Russell King   [ARM] Move includ...
28
  #include <mach/audio.h>
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
29
30
  
  #include "pxa2xx-pcm.h"
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
31
  static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
32
  {
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
33
34
  	if (!pxa2xx_ac97_try_cold_reset(ac97)) {
  		pxa2xx_ac97_try_warm_reset(ac97);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
35
  	}
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
36
  	pxa2xx_ac97_finish_reset(ac97);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
37
  }
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
38
  static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
39
40
41
42
  	.read	= pxa2xx_ac97_read,
  	.write	= pxa2xx_ac97_write,
  	.reset	= pxa2xx_ac97_reset,
  };
58ceb57ec   Daniel Mack   ASoC: pxa: pxa-pc...
43
44
45
46
  static struct pxad_param pxa2xx_ac97_pcm_out_req = {
  	.prio = PXAD_PRIO_LOWEST,
  	.drcmr = 12,
  };
d65a14587   Daniel Mack   ASoC: pxa: use sn...
47
48
49
50
51
  static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_out = {
  	.addr		= __PREG(PCDR),
  	.addr_width	= DMA_SLAVE_BUSWIDTH_4_BYTES,
  	.maxburst	= 32,
  	.filter_data	= &pxa2xx_ac97_pcm_out_req,
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
52
  };
58ceb57ec   Daniel Mack   ASoC: pxa: pxa-pc...
53
54
55
56
  static struct pxad_param pxa2xx_ac97_pcm_in_req = {
  	.prio = PXAD_PRIO_LOWEST,
  	.drcmr = 11,
  };
d65a14587   Daniel Mack   ASoC: pxa: use sn...
57
58
59
60
61
  static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_in = {
  	.addr		= __PREG(PCDR),
  	.addr_width	= DMA_SLAVE_BUSWIDTH_4_BYTES,
  	.maxburst	= 32,
  	.filter_data	= &pxa2xx_ac97_pcm_in_req,
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
62
  };
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
63
64
  static struct snd_pcm *pxa2xx_ac97_pcm;
  static struct snd_ac97 *pxa2xx_ac97_ac97;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
65

d18f83764   Takashi Iwai   [ALSA] Remove xxx...
66
  static int pxa2xx_ac97_pcm_startup(struct snd_pcm_substream *substream)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
67
  {
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
68
  	struct snd_pcm_runtime *runtime = substream->runtime;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  	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...
86
  static void pxa2xx_ac97_pcm_shutdown(struct snd_pcm_substream *substream)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
87
88
89
90
91
92
93
  {
  	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...
94
  static int pxa2xx_ac97_pcm_prepare(struct snd_pcm_substream *substream)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
95
  {
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
96
  	struct snd_pcm_runtime *runtime = substream->runtime;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
97
98
99
100
  	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...
101
  static struct pxa2xx_pcm_client pxa2xx_ac97_pcm_client = {
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
102
103
104
105
106
107
  	.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,
  };
d34e4e00a   Takashi Iwai   ALSA: platform: C...
108
  #ifdef CONFIG_PM_SLEEP
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
109

284e7ca75   Takashi Iwai   ALSA: convert PM ...
110
  static int pxa2xx_ac97_do_suspend(struct snd_card *card)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
111
  {
792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
112
113
114
115
116
117
118
  	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...
119

9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
120
  	return pxa2xx_ac97_hw_suspend();
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
121
  }
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
122
  static int pxa2xx_ac97_do_resume(struct snd_card *card)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
123
  {
792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
124
  	pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
125
126
127
128
129
  	int rc;
  
  	rc = pxa2xx_ac97_hw_resume();
  	if (rc)
  		return rc;
792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
130

792a6c518   Takashi Iwai   [ALSA] Fix PM sup...
131
132
133
134
  	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...
135
136
137
  
  	return 0;
  }
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
138
  static int pxa2xx_ac97_suspend(struct device *dev)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
139
  {
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
140
  	struct snd_card *card = dev_get_drvdata(dev);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
141
  	int ret = 0;
9480e307c   Russell King   [PATCH] DRIVER MO...
142
  	if (card)
284e7ca75   Takashi Iwai   ALSA: convert PM ...
143
  		ret = pxa2xx_ac97_do_suspend(card);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
144
145
146
  
  	return ret;
  }
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
147
  static int pxa2xx_ac97_resume(struct device *dev)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
148
  {
2ba9fd0d1   Mike Rapoport   [ARM] pxa: update...
149
  	struct snd_card *card = dev_get_drvdata(dev);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
150
  	int ret = 0;
9480e307c   Russell King   [PATCH] DRIVER MO...
151
  	if (card)
a55bfdc58   Dirk Opfer   [ALSA] Fix compil...
152
  		ret = pxa2xx_ac97_do_resume(card);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
153
154
155
  
  	return ret;
  }
284e7ca75   Takashi Iwai   ALSA: convert PM ...
156
  static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, pxa2xx_ac97_suspend, pxa2xx_ac97_resume);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
157
  #endif
e21596bba   Bill Pemberton   ALSA: pxa2xx: rem...
158
  static int pxa2xx_ac97_probe(struct platform_device *dev)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
159
  {
d18f83764   Takashi Iwai   [ALSA] Remove xxx...
160
161
162
  	struct snd_card *card;
  	struct snd_ac97_bus *ac97_bus;
  	struct snd_ac97_template ac97_template;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
163
  	int ret;
4ac0478f2   Marek Vasut   ALSA: Allow passi...
164
165
166
167
168
169
170
171
  	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...
172

4a8755801   Takashi Iwai   ALSA: arm: Conver...
173
174
  	ret = snd_card_new(&dev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
  			   THIS_MODULE, 0, &card);
bd7dd77c2   Takashi Iwai   ALSA: Convert to ...
175
  	if (ret < 0)
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
176
  		goto err;
57a4451d2   Takashi Iwai   ALSA: Use strlcpy...
177
  	strlcpy(card->driver, dev->dev.driver->name, sizeof(card->driver));
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
178
179
180
181
  
  	ret = pxa2xx_pcm_new(card, &pxa2xx_ac97_pcm_client, &pxa2xx_ac97_pcm);
  	if (ret)
  		goto err;
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
182
183
  	ret = pxa2xx_ac97_hw_probe(dev);
  	if (ret)
93873fbfd   Mark Brown   [ARM] 4833/3: Con...
184
  		goto err;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
185
186
187
  
  	ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus);
  	if (ret)
9c6363422   Dmitry Eremin-Solenikov   ALSA: Separate co...
188
  		goto err_remove;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
189
190
191
  	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...
192
  		goto err_remove;
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
193
194
195
196
  
  	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...
197
  		 "%s (%s)", dev->dev.driver->name, card->mixername);
2c484df0d   Takashi Iwai   [ALSA] Add ARM PX...
198

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