blob: a822ab822bb7ba40f5f1ead77a04a7caa7069233 [file] [log] [blame]
Manuel Lauss4a161d22008-07-09 16:27:56 +02001/*
2 * Au12x0/Au1550 PSC ALSA ASoC audio support.
3 *
Manuel Lausscdc65fb2009-09-08 19:45:17 +02004 * (c) 2007-2009 MSC Vertriebsges.m.b.H.,
5 * Manuel Lauss <manuel.lauss@gmail.com>
Manuel Lauss4a161d22008-07-09 16:27:56 +02006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Au1xxx-PSC AC97 glue.
12 *
Manuel Lauss4a161d22008-07-09 16:27:56 +020013 */
14
15#include <linux/init.h>
16#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Manuel Lauss4a161d22008-07-09 16:27:56 +020018#include <linux/device.h>
19#include <linux/delay.h>
Manuel Lausscdc65fb2009-09-08 19:45:17 +020020#include <linux/mutex.h>
Manuel Lauss4a161d22008-07-09 16:27:56 +020021#include <linux/suspend.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/initval.h>
25#include <sound/soc.h>
26#include <asm/mach-au1x00/au1000.h>
27#include <asm/mach-au1x00/au1xxx_psc.h>
28
29#include "psc.h"
30
Manuel Lausscdc65fb2009-09-08 19:45:17 +020031/* how often to retry failed codec register reads/writes */
32#define AC97_RW_RETRIES 5
33
Manuel Lauss4a161d22008-07-09 16:27:56 +020034#define AC97_DIR \
35 (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
36
37#define AC97_RATES \
38 SNDRV_PCM_RATE_8000_48000
39
40#define AC97_FMTS \
41 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3BE)
42
43#define AC97PCR_START(stype) \
Manuel Lauss25942fd2011-07-25 13:45:04 +020044 ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97PCR_TS : PSC_AC97PCR_RS)
Manuel Lauss4a161d22008-07-09 16:27:56 +020045#define AC97PCR_STOP(stype) \
Manuel Lauss25942fd2011-07-25 13:45:04 +020046 ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97PCR_TP : PSC_AC97PCR_RP)
Manuel Lauss4a161d22008-07-09 16:27:56 +020047#define AC97PCR_CLRFIFO(stype) \
Manuel Lauss25942fd2011-07-25 13:45:04 +020048 ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97PCR_TC : PSC_AC97PCR_RC)
Manuel Lauss4a161d22008-07-09 16:27:56 +020049
Manuel Lausscdc65fb2009-09-08 19:45:17 +020050#define AC97STAT_BUSY(stype) \
Manuel Lauss25942fd2011-07-25 13:45:04 +020051 ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_AC97STAT_TB : PSC_AC97STAT_RB)
Manuel Lausscdc65fb2009-09-08 19:45:17 +020052
Manuel Lauss4a161d22008-07-09 16:27:56 +020053/* instance data. There can be only one, MacLeod!!!! */
54static struct au1xpsc_audio_data *au1xpsc_ac97_workdata;
55
Manuel Laussffc4fdb2010-08-26 14:53:51 +020056#if 0
57
58/* this could theoretically work, but ac97->bus->card->private_data can be NULL
59 * when snd_ac97_mixer() is called; I don't know if the rest further down the
60 * chain are always valid either.
61 */
62static inline struct au1xpsc_audio_data *ac97_to_pscdata(struct snd_ac97 *x)
63{
64 struct snd_soc_card *c = x->bus->card->private_data;
65 return snd_soc_dai_get_drvdata(c->rtd->cpu_dai);
66}
67
68#else
69
70#define ac97_to_pscdata(x) au1xpsc_ac97_workdata
71
72#endif
73
Manuel Lauss4a161d22008-07-09 16:27:56 +020074/* AC97 controller reads codec register */
75static unsigned short au1xpsc_ac97_read(struct snd_ac97 *ac97,
76 unsigned short reg)
77{
Manuel Laussffc4fdb2010-08-26 14:53:51 +020078 struct au1xpsc_audio_data *pscdata = ac97_to_pscdata(ac97);
Manuel Lausse697cd42009-10-19 16:10:58 +020079 unsigned short retry, tmo;
80 unsigned long data;
Manuel Lauss4a161d22008-07-09 16:27:56 +020081
82 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
83 au_sync();
84
Manuel Lausscdc65fb2009-09-08 19:45:17 +020085 retry = AC97_RW_RETRIES;
86 do {
87 mutex_lock(&pscdata->lock);
88
89 au_writel(PSC_AC97CDC_RD | PSC_AC97CDC_INDX(reg),
90 AC97_CDC(pscdata));
91 au_sync();
92
Manuel Lauss8d567b62009-10-19 16:10:59 +020093 tmo = 20;
94 do {
95 udelay(21);
96 if (au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)
97 break;
98 } while (--tmo);
Manuel Lausscdc65fb2009-09-08 19:45:17 +020099
Manuel Lausse697cd42009-10-19 16:10:58 +0200100 data = au_readl(AC97_CDC(pscdata));
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200101
102 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
103 au_sync();
104
105 mutex_unlock(&pscdata->lock);
Manuel Lausse697cd42009-10-19 16:10:58 +0200106
107 if (reg != ((data >> 16) & 0x7f))
108 tmo = 1; /* wrong register, try again */
109
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200110 } while (--retry && !tmo);
111
Manuel Lausse697cd42009-10-19 16:10:58 +0200112 return retry ? data & 0xffff : 0xffff;
Manuel Lauss4a161d22008-07-09 16:27:56 +0200113}
114
115/* AC97 controller writes to codec register */
116static void au1xpsc_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
117 unsigned short val)
118{
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200119 struct au1xpsc_audio_data *pscdata = ac97_to_pscdata(ac97);
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200120 unsigned int tmo, retry;
Manuel Lauss4a161d22008-07-09 16:27:56 +0200121
122 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
123 au_sync();
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200124
125 retry = AC97_RW_RETRIES;
126 do {
127 mutex_lock(&pscdata->lock);
128
129 au_writel(PSC_AC97CDC_INDX(reg) | (val & 0xffff),
130 AC97_CDC(pscdata));
131 au_sync();
132
Manuel Lauss8d567b62009-10-19 16:10:59 +0200133 tmo = 20;
134 do {
135 udelay(21);
136 if (au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)
137 break;
138 } while (--tmo);
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200139
140 au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
141 au_sync();
142
143 mutex_unlock(&pscdata->lock);
144 } while (--retry && !tmo);
Manuel Lauss4a161d22008-07-09 16:27:56 +0200145}
146
147/* AC97 controller asserts a warm reset */
148static void au1xpsc_ac97_warm_reset(struct snd_ac97 *ac97)
149{
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200150 struct au1xpsc_audio_data *pscdata = ac97_to_pscdata(ac97);
Manuel Lauss4a161d22008-07-09 16:27:56 +0200151
152 au_writel(PSC_AC97RST_SNC, AC97_RST(pscdata));
153 au_sync();
154 msleep(10);
155 au_writel(0, AC97_RST(pscdata));
156 au_sync();
157}
158
159static void au1xpsc_ac97_cold_reset(struct snd_ac97 *ac97)
160{
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200161 struct au1xpsc_audio_data *pscdata = ac97_to_pscdata(ac97);
Manuel Lauss4a161d22008-07-09 16:27:56 +0200162 int i;
163
164 /* disable PSC during cold reset */
165 au_writel(0, AC97_CFG(au1xpsc_ac97_workdata));
166 au_sync();
167 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(pscdata));
168 au_sync();
169
170 /* issue cold reset */
171 au_writel(PSC_AC97RST_RST, AC97_RST(pscdata));
172 au_sync();
173 msleep(500);
174 au_writel(0, AC97_RST(pscdata));
175 au_sync();
176
177 /* enable PSC */
178 au_writel(PSC_CTRL_ENABLE, PSC_CTRL(pscdata));
179 au_sync();
180
181 /* wait for PSC to indicate it's ready */
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200182 i = 1000;
Manuel Lauss4a161d22008-07-09 16:27:56 +0200183 while (!((au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_SR)) && (--i))
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200184 msleep(1);
Manuel Lauss4a161d22008-07-09 16:27:56 +0200185
186 if (i == 0) {
187 printk(KERN_ERR "au1xpsc-ac97: PSC not ready!\n");
188 return;
189 }
190
191 /* enable the ac97 function */
192 au_writel(pscdata->cfg | PSC_AC97CFG_DE_ENABLE, AC97_CFG(pscdata));
193 au_sync();
194
195 /* wait for AC97 core to become ready */
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200196 i = 1000;
Manuel Lauss4a161d22008-07-09 16:27:56 +0200197 while (!((au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR)) && (--i))
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200198 msleep(1);
Manuel Lauss4a161d22008-07-09 16:27:56 +0200199 if (i == 0)
200 printk(KERN_ERR "au1xpsc-ac97: AC97 ctrl not ready\n");
201}
202
203/* AC97 controller operations */
Mark Brownb047e1c2013-06-26 12:45:59 +0100204static struct snd_ac97_bus_ops psc_ac97_ops = {
Manuel Lauss4a161d22008-07-09 16:27:56 +0200205 .read = au1xpsc_ac97_read,
206 .write = au1xpsc_ac97_write,
207 .reset = au1xpsc_ac97_cold_reset,
208 .warm_reset = au1xpsc_ac97_warm_reset,
209};
Manuel Lauss4a161d22008-07-09 16:27:56 +0200210
211static int au1xpsc_ac97_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000212 struct snd_pcm_hw_params *params,
213 struct snd_soc_dai *dai)
Manuel Lauss4a161d22008-07-09 16:27:56 +0200214{
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200215 struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200216 unsigned long r, ro, stat;
Manuel Lauss25942fd2011-07-25 13:45:04 +0200217 int chans, t, stype = substream->stream;
Manuel Lauss4a161d22008-07-09 16:27:56 +0200218
219 chans = params_channels(params);
220
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200221 r = ro = au_readl(AC97_CFG(pscdata));
Manuel Lauss4a161d22008-07-09 16:27:56 +0200222 stat = au_readl(AC97_STAT(pscdata));
223
224 /* already active? */
225 if (stat & (PSC_AC97STAT_TB | PSC_AC97STAT_RB)) {
226 /* reject parameters not currently set up */
227 if ((PSC_AC97CFG_GET_LEN(r) != params->msbits) ||
228 (pscdata->rate != params_rate(params)))
229 return -EINVAL;
230 } else {
Manuel Lauss4a161d22008-07-09 16:27:56 +0200231
232 /* set sample bitdepth: REG[24:21]=(BITS-2)/2 */
233 r &= ~PSC_AC97CFG_LEN_MASK;
234 r |= PSC_AC97CFG_SET_LEN(params->msbits);
235
236 /* channels: enable slots for front L/R channel */
Manuel Lauss25942fd2011-07-25 13:45:04 +0200237 if (stype == SNDRV_PCM_STREAM_PLAYBACK) {
Manuel Lauss4a161d22008-07-09 16:27:56 +0200238 r &= ~PSC_AC97CFG_TXSLOT_MASK;
239 r |= PSC_AC97CFG_TXSLOT_ENA(3);
240 r |= PSC_AC97CFG_TXSLOT_ENA(4);
241 } else {
242 r &= ~PSC_AC97CFG_RXSLOT_MASK;
243 r |= PSC_AC97CFG_RXSLOT_ENA(3);
244 r |= PSC_AC97CFG_RXSLOT_ENA(4);
245 }
246
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200247 /* do we need to poke the hardware? */
248 if (!(r ^ ro))
249 goto out;
250
251 /* ac97 engine is about to be disabled */
252 mutex_lock(&pscdata->lock);
253
254 /* disable AC97 device controller first... */
255 au_writel(r & ~PSC_AC97CFG_DE_ENABLE, AC97_CFG(pscdata));
256 au_sync();
257
258 /* ...wait for it... */
Manuel Lauss8d567b62009-10-19 16:10:59 +0200259 t = 100;
260 while ((au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR) && --t)
261 msleep(1);
262
263 if (!t)
264 printk(KERN_ERR "PSC-AC97: can't disable!\n");
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200265
266 /* ...write config... */
267 au_writel(r, AC97_CFG(pscdata));
268 au_sync();
269
270 /* ...enable the AC97 controller again... */
Manuel Lauss4a161d22008-07-09 16:27:56 +0200271 au_writel(r | PSC_AC97CFG_DE_ENABLE, AC97_CFG(pscdata));
272 au_sync();
273
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200274 /* ...and wait for ready bit */
Manuel Lauss8d567b62009-10-19 16:10:59 +0200275 t = 100;
276 while ((!(au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR)) && --t)
277 msleep(1);
278
279 if (!t)
280 printk(KERN_ERR "PSC-AC97: can't enable!\n");
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200281
282 mutex_unlock(&pscdata->lock);
283
Manuel Lauss4a161d22008-07-09 16:27:56 +0200284 pscdata->cfg = r;
285 pscdata->rate = params_rate(params);
286 }
287
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200288out:
Manuel Lauss4a161d22008-07-09 16:27:56 +0200289 return 0;
290}
291
292static int au1xpsc_ac97_trigger(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000293 int cmd, struct snd_soc_dai *dai)
Manuel Lauss4a161d22008-07-09 16:27:56 +0200294{
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200295 struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
Manuel Lauss25942fd2011-07-25 13:45:04 +0200296 int ret, stype = substream->stream;
Manuel Lauss4a161d22008-07-09 16:27:56 +0200297
298 ret = 0;
299
300 switch (cmd) {
301 case SNDRV_PCM_TRIGGER_START:
302 case SNDRV_PCM_TRIGGER_RESUME:
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200303 au_writel(AC97PCR_CLRFIFO(stype), AC97_PCR(pscdata));
304 au_sync();
Manuel Lauss4a161d22008-07-09 16:27:56 +0200305 au_writel(AC97PCR_START(stype), AC97_PCR(pscdata));
306 au_sync();
307 break;
308 case SNDRV_PCM_TRIGGER_STOP:
309 case SNDRV_PCM_TRIGGER_SUSPEND:
310 au_writel(AC97PCR_STOP(stype), AC97_PCR(pscdata));
311 au_sync();
Manuel Lausscdc65fb2009-09-08 19:45:17 +0200312
313 while (au_readl(AC97_STAT(pscdata)) & AC97STAT_BUSY(stype))
314 asm volatile ("nop");
315
316 au_writel(AC97PCR_CLRFIFO(stype), AC97_PCR(pscdata));
317 au_sync();
318
Manuel Lauss4a161d22008-07-09 16:27:56 +0200319 break;
320 default:
321 ret = -EINVAL;
322 }
323 return ret;
324}
325
Manuel Lauss5b0912b2011-07-25 13:45:02 +0200326static int au1xpsc_ac97_startup(struct snd_pcm_substream *substream,
327 struct snd_soc_dai *dai)
328{
329 struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai);
330 snd_soc_dai_set_dma_data(dai, substream, &pscdata->dmaids[0]);
331 return 0;
332}
333
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000334static int au1xpsc_ac97_probe(struct snd_soc_dai *dai)
Manuel Lauss4a161d22008-07-09 16:27:56 +0200335{
Manuel Lauss0f83d632009-10-31 20:15:08 +0100336 return au1xpsc_ac97_workdata ? 0 : -ENODEV;
Manuel Lauss4a161d22008-07-09 16:27:56 +0200337}
338
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100339static const struct snd_soc_dai_ops au1xpsc_ac97_dai_ops = {
Manuel Lauss5b0912b2011-07-25 13:45:02 +0200340 .startup = au1xpsc_ac97_startup,
Eric Miao6335d052009-03-03 09:41:00 +0800341 .trigger = au1xpsc_ac97_trigger,
342 .hw_params = au1xpsc_ac97_hw_params,
343};
344
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200345static const struct snd_soc_dai_driver au1xpsc_ac97_dai_template = {
Mark Brown3ba9e10a2008-11-24 18:01:05 +0000346 .ac97_control = 1,
Manuel Lauss4a161d22008-07-09 16:27:56 +0200347 .probe = au1xpsc_ac97_probe,
Manuel Lauss4a161d22008-07-09 16:27:56 +0200348 .playback = {
349 .rates = AC97_RATES,
350 .formats = AC97_FMTS,
351 .channels_min = 2,
352 .channels_max = 2,
353 },
354 .capture = {
355 .rates = AC97_RATES,
356 .formats = AC97_FMTS,
357 .channels_min = 2,
358 .channels_max = 2,
359 },
Eric Miao6335d052009-03-03 09:41:00 +0800360 .ops = &au1xpsc_ac97_dai_ops,
Manuel Lauss4a161d22008-07-09 16:27:56 +0200361};
Manuel Lauss4a161d22008-07-09 16:27:56 +0200362
Kuninori Morimotoa4ff2002013-03-21 03:28:50 -0700363static const struct snd_soc_component_driver au1xpsc_ac97_component = {
364 .name = "au1xpsc-ac97",
365};
366
Bill Pemberton5c658be2012-12-07 09:26:22 -0500367static int au1xpsc_ac97_drvprobe(struct platform_device *pdev)
Manuel Lauss0f83d632009-10-31 20:15:08 +0100368{
369 int ret;
Julia Lawall226d0f22011-10-18 17:06:39 +0200370 struct resource *iores, *dmares;
Manuel Lauss0f83d632009-10-31 20:15:08 +0100371 unsigned long sel;
372 struct au1xpsc_audio_data *wd;
373
Julia Lawall8d9626d2011-12-29 17:51:25 +0100374 wd = devm_kzalloc(&pdev->dev, sizeof(struct au1xpsc_audio_data),
375 GFP_KERNEL);
Manuel Lauss0f83d632009-10-31 20:15:08 +0100376 if (!wd)
377 return -ENOMEM;
378
379 mutex_init(&wd->lock);
380
Julia Lawall226d0f22011-10-18 17:06:39 +0200381 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Julia Lawall8d9626d2011-12-29 17:51:25 +0100382 if (!iores)
383 return -ENODEV;
Manuel Lauss0f83d632009-10-31 20:15:08 +0100384
Mark Browna16a6c62013-06-26 11:09:55 +0100385 wd->mmio = devm_ioremap_resource(&pdev->dev, iores);
386 if (IS_ERR(wd->mmio))
387 return PTR_ERR(wd->mmio);
Manuel Lauss0f83d632009-10-31 20:15:08 +0100388
Julia Lawall226d0f22011-10-18 17:06:39 +0200389 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
390 if (!dmares)
Julia Lawall8d9626d2011-12-29 17:51:25 +0100391 return -EBUSY;
Julia Lawall226d0f22011-10-18 17:06:39 +0200392 wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start;
Manuel Lauss5b0912b2011-07-25 13:45:02 +0200393
Julia Lawall226d0f22011-10-18 17:06:39 +0200394 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1);
395 if (!dmares)
Julia Lawall8d9626d2011-12-29 17:51:25 +0100396 return -EBUSY;
Julia Lawall226d0f22011-10-18 17:06:39 +0200397 wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start;
Manuel Lauss5b0912b2011-07-25 13:45:02 +0200398
Manuel Lauss0f83d632009-10-31 20:15:08 +0100399 /* configuration: max dma trigger threshold, enable ac97 */
400 wd->cfg = PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8 |
401 PSC_AC97CFG_DE_ENABLE;
402
403 /* preserve PSC clock source set up by platform */
404 sel = au_readl(PSC_SEL(wd)) & PSC_SEL_CLK_MASK;
405 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
406 au_sync();
407 au_writel(0, PSC_SEL(wd));
408 au_sync();
409 au_writel(PSC_SEL_PS_AC97MODE | sel, PSC_SEL(wd));
410 au_sync();
411
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200412 /* name the DAI like this device instance ("au1xpsc-ac97.PSCINDEX") */
413 memcpy(&wd->dai_drv, &au1xpsc_ac97_dai_template,
414 sizeof(struct snd_soc_dai_driver));
415 wd->dai_drv.name = dev_name(&pdev->dev);
416
417 platform_set_drvdata(pdev, wd);
418
Mark Brownb047e1c2013-06-26 12:45:59 +0100419 ret = snd_soc_set_ac97_ops(&psc_ac97_ops);
420 if (ret)
421 return ret;
422
Kuninori Morimotoa4ff2002013-03-21 03:28:50 -0700423 ret = snd_soc_register_component(&pdev->dev, &au1xpsc_ac97_component,
424 &wd->dai_drv, 1);
Manuel Lauss0f83d632009-10-31 20:15:08 +0100425 if (ret)
Julia Lawall8d9626d2011-12-29 17:51:25 +0100426 return ret;
Manuel Lauss0f83d632009-10-31 20:15:08 +0100427
Manuel Lauss5b0912b2011-07-25 13:45:02 +0200428 au1xpsc_ac97_workdata = wd;
429 return 0;
Manuel Lauss0f83d632009-10-31 20:15:08 +0100430}
431
Bill Pemberton5c658be2012-12-07 09:26:22 -0500432static int au1xpsc_ac97_drvremove(struct platform_device *pdev)
Manuel Lauss0f83d632009-10-31 20:15:08 +0100433{
434 struct au1xpsc_audio_data *wd = platform_get_drvdata(pdev);
435
Kuninori Morimotoa4ff2002013-03-21 03:28:50 -0700436 snd_soc_unregister_component(&pdev->dev);
Manuel Lauss0f83d632009-10-31 20:15:08 +0100437
438 /* disable PSC completely */
439 au_writel(0, AC97_CFG(wd));
440 au_sync();
441 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
442 au_sync();
443
Manuel Lauss0f83d632009-10-31 20:15:08 +0100444 au1xpsc_ac97_workdata = NULL; /* MDEV */
445
446 return 0;
447}
448
449#ifdef CONFIG_PM
450static int au1xpsc_ac97_drvsuspend(struct device *dev)
451{
452 struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
453
454 /* save interesting registers and disable PSC */
455 wd->pm[0] = au_readl(PSC_SEL(wd));
456
457 au_writel(0, AC97_CFG(wd));
458 au_sync();
459 au_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd));
460 au_sync();
461
462 return 0;
463}
464
465static int au1xpsc_ac97_drvresume(struct device *dev)
466{
467 struct au1xpsc_audio_data *wd = dev_get_drvdata(dev);
468
469 /* restore PSC clock config */
470 au_writel(wd->pm[0] | PSC_SEL_PS_AC97MODE, PSC_SEL(wd));
471 au_sync();
472
473 /* after this point the ac97 core will cold-reset the codec.
474 * During cold-reset the PSC is reinitialized and the last
475 * configuration set up in hw_params() is restored.
476 */
477 return 0;
478}
479
480static struct dev_pm_ops au1xpscac97_pmops = {
481 .suspend = au1xpsc_ac97_drvsuspend,
482 .resume = au1xpsc_ac97_drvresume,
483};
484
485#define AU1XPSCAC97_PMOPS &au1xpscac97_pmops
486
487#else
488
489#define AU1XPSCAC97_PMOPS NULL
490
491#endif
492
493static struct platform_driver au1xpsc_ac97_driver = {
494 .driver = {
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200495 .name = "au1xpsc_ac97",
Manuel Lauss0f83d632009-10-31 20:15:08 +0100496 .owner = THIS_MODULE,
497 .pm = AU1XPSCAC97_PMOPS,
498 },
499 .probe = au1xpsc_ac97_drvprobe,
Bill Pemberton5c658be2012-12-07 09:26:22 -0500500 .remove = au1xpsc_ac97_drvremove,
Manuel Lauss0f83d632009-10-31 20:15:08 +0100501};
502
Mark Brown2105d632013-06-26 11:28:59 +0100503module_platform_driver(au1xpsc_ac97_driver);
Manuel Lauss4a161d22008-07-09 16:27:56 +0200504
505MODULE_LICENSE("GPL");
506MODULE_DESCRIPTION("Au12x0/Au1550 PSC AC97 ALSA ASoC audio driver");
Manuel Lauss0f83d632009-10-31 20:15:08 +0100507MODULE_AUTHOR("Manuel Lauss");
508