blob: c0dcc3538e35d8e44cc549b6a157bf224ee589f9 [file] [log] [blame]
Mark Brown1b340bd2008-07-30 19:12:04 +01001/*
2 * pxa-ssp.c -- ALSA Soc Audio Layer
3 *
4 * Copyright 2005,2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * TODO:
14 * o Test network mode for > 16bit sample size
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Mark Brown1b340bd2008-07-30 19:12:04 +010020#include <linux/platform_device.h>
21#include <linux/clk.h>
22#include <linux/io.h>
Sebastian Andrzej Siewior8348c252010-11-22 17:12:15 -080023#include <linux/pxa2xx_ssp.h>
Daniel Mack2023c902013-08-12 10:42:38 +020024#include <linux/of.h>
Daniel Mackd65a1452013-08-12 10:42:39 +020025#include <linux/dmaengine.h>
Mark Brown1b340bd2008-07-30 19:12:04 +010026
Philipp Zabel06646782009-02-03 21:18:26 +010027#include <asm/irq.h>
28
Mark Brown1b340bd2008-07-30 19:12:04 +010029#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/initval.h>
32#include <sound/pcm_params.h>
33#include <sound/soc.h>
34#include <sound/pxa2xx-lib.h>
Daniel Mackd65a1452013-08-12 10:42:39 +020035#include <sound/dmaengine_pcm.h>
Mark Brown1b340bd2008-07-30 19:12:04 +010036
37#include <mach/hardware.h>
Mark Brown1b340bd2008-07-30 19:12:04 +010038
Haojian Zhuangdd99a452010-08-13 21:55:27 +080039#include "../../arm/pxa2xx-pcm.h"
Mark Brown1b340bd2008-07-30 19:12:04 +010040#include "pxa-ssp.h"
41
42/*
43 * SSP audio private data
44 */
45struct ssp_priv {
Eric Miaof9efc9d2010-02-09 19:46:01 +080046 struct ssp_device *ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +010047 unsigned int sysclk;
48 int dai_fmt;
49#ifdef CONFIG_PM
Eric Miaof9efc9d2010-02-09 19:46:01 +080050 uint32_t cr0;
51 uint32_t cr1;
52 uint32_t to;
53 uint32_t psp;
Mark Brown1b340bd2008-07-30 19:12:04 +010054#endif
55};
56
Mark Brown1b340bd2008-07-30 19:12:04 +010057static void dump_registers(struct ssp_device *ssp)
58{
59 dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
Haojian Zhuangbaffe162010-05-05 10:11:15 -040060 pxa_ssp_read_reg(ssp, SSCR0), pxa_ssp_read_reg(ssp, SSCR1),
61 pxa_ssp_read_reg(ssp, SSTO));
Mark Brown1b340bd2008-07-30 19:12:04 +010062
63 dev_dbg(&ssp->pdev->dev, "SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n",
Haojian Zhuangbaffe162010-05-05 10:11:15 -040064 pxa_ssp_read_reg(ssp, SSPSP), pxa_ssp_read_reg(ssp, SSSR),
65 pxa_ssp_read_reg(ssp, SSACD));
Mark Brown1b340bd2008-07-30 19:12:04 +010066}
67
Haojian Zhuangbaffe162010-05-05 10:11:15 -040068static void pxa_ssp_enable(struct ssp_device *ssp)
Eric Miaof9efc9d2010-02-09 19:46:01 +080069{
70 uint32_t sscr0;
71
72 sscr0 = __raw_readl(ssp->mmio_base + SSCR0) | SSCR0_SSE;
73 __raw_writel(sscr0, ssp->mmio_base + SSCR0);
74}
75
Haojian Zhuangbaffe162010-05-05 10:11:15 -040076static void pxa_ssp_disable(struct ssp_device *ssp)
Eric Miaof9efc9d2010-02-09 19:46:01 +080077{
78 uint32_t sscr0;
79
80 sscr0 = __raw_readl(ssp->mmio_base + SSCR0) & ~SSCR0_SSE;
81 __raw_writel(sscr0, ssp->mmio_base + SSCR0);
82}
83
guoyhd93ca1a2012-05-07 15:34:24 +080084static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,
Daniel Mackd65a1452013-08-12 10:42:39 +020085 int out, struct snd_dmaengine_dai_dma_data *dma)
Eric Miao2d7e71f2009-04-23 17:05:38 +080086{
Daniel Mackd65a1452013-08-12 10:42:39 +020087 dma->filter_data = out ? &ssp->drcmr_tx : &ssp->drcmr_rx;
88 dma->addr_width = width4 ? DMA_SLAVE_BUSWIDTH_4_BYTES :
89 DMA_SLAVE_BUSWIDTH_2_BYTES;
90 dma->maxburst = 16;
91 dma->addr = ssp->phys_base + SSDR;
Eric Miao2d7e71f2009-04-23 17:05:38 +080092}
93
Mark Browndee89c42008-11-18 22:11:38 +000094static int pxa_ssp_startup(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +010096{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000097 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +080098 struct ssp_device *ssp = priv->ssp;
Daniel Mackd65a1452013-08-12 10:42:39 +020099 struct snd_dmaengine_dai_dma_data *dma;
Mark Brown1b340bd2008-07-30 19:12:04 +0100100 int ret = 0;
101
102 if (!cpu_dai->active) {
Eric Miaof9efc9d2010-02-09 19:46:01 +0800103 clk_enable(ssp->clk);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400104 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100105 }
Eric Miao2d7e71f2009-04-23 17:05:38 +0800106
Daniel Mackd65a1452013-08-12 10:42:39 +0200107 dma = kzalloc(sizeof(struct snd_dmaengine_dai_dma_data), GFP_KERNEL);
guoyhd93ca1a2012-05-07 15:34:24 +0800108 if (!dma)
109 return -ENOMEM;
Daniel Mackd65a1452013-08-12 10:42:39 +0200110 snd_soc_dai_set_dma_data(cpu_dai, substream, dma);
Daniel Mack5f712b22010-03-22 10:11:15 +0100111
Mark Brown1b340bd2008-07-30 19:12:04 +0100112 return ret;
113}
114
Mark Browndee89c42008-11-18 22:11:38 +0000115static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000116 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100117{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000118 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800119 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100120
121 if (!cpu_dai->active) {
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400122 pxa_ssp_disable(ssp);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800123 clk_disable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100124 }
Eric Miao2d7e71f2009-04-23 17:05:38 +0800125
Daniel Mack5f712b22010-03-22 10:11:15 +0100126 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
127 snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
Mark Brown1b340bd2008-07-30 19:12:04 +0100128}
129
130#ifdef CONFIG_PM
131
Mark Browndc7d7b82008-12-03 18:21:52 +0000132static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100133{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000134 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800135 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100136
137 if (!cpu_dai->active)
Russell King988addf2010-03-08 20:21:04 +0000138 clk_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100139
Eric Miaof9efc9d2010-02-09 19:46:01 +0800140 priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0);
141 priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1);
142 priv->to = __raw_readl(ssp->mmio_base + SSTO);
143 priv->psp = __raw_readl(ssp->mmio_base + SSPSP);
144
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400145 pxa_ssp_disable(ssp);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800146 clk_disable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100147 return 0;
148}
149
Mark Browndc7d7b82008-12-03 18:21:52 +0000150static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100151{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000152 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800153 struct ssp_device *ssp = priv->ssp;
154 uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100155
Eric Miaof9efc9d2010-02-09 19:46:01 +0800156 clk_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100157
Eric Miaof9efc9d2010-02-09 19:46:01 +0800158 __raw_writel(sssr, ssp->mmio_base + SSSR);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800159 __raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0);
160 __raw_writel(priv->cr1, ssp->mmio_base + SSCR1);
161 __raw_writel(priv->to, ssp->mmio_base + SSTO);
162 __raw_writel(priv->psp, ssp->mmio_base + SSPSP);
Daniel Mack026384d2010-02-02 18:45:27 +0800163
164 if (cpu_dai->active)
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400165 pxa_ssp_enable(ssp);
Daniel Mack026384d2010-02-02 18:45:27 +0800166 else
Russell King988addf2010-03-08 20:21:04 +0000167 clk_disable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100168
169 return 0;
170}
171
172#else
173#define pxa_ssp_suspend NULL
174#define pxa_ssp_resume NULL
175#endif
176
177/**
178 * ssp_set_clkdiv - set SSP clock divider
179 * @div: serial clock rate divider
180 */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400181static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div)
Mark Brown1b340bd2008-07-30 19:12:04 +0100182{
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400183 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100184
Qiao Zhou972a55b2012-06-04 10:41:04 +0800185 if (ssp->type == PXA25x_SSP) {
Philipp Zabel1a297282009-04-17 11:39:38 +0200186 sscr0 &= ~0x0000ff00;
187 sscr0 |= ((div - 2)/2) << 8; /* 2..512 */
188 } else {
189 sscr0 &= ~0x000fff00;
190 sscr0 |= (div - 1) << 8; /* 1..4096 */
191 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400192 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Philipp Zabel1a297282009-04-17 11:39:38 +0200193}
194
195/**
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400196 * pxa_ssp_get_clkdiv - get SSP clock divider
Philipp Zabel1a297282009-04-17 11:39:38 +0200197 */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400198static u32 pxa_ssp_get_scr(struct ssp_device *ssp)
Philipp Zabel1a297282009-04-17 11:39:38 +0200199{
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400200 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Philipp Zabel1a297282009-04-17 11:39:38 +0200201 u32 div;
202
Qiao Zhou972a55b2012-06-04 10:41:04 +0800203 if (ssp->type == PXA25x_SSP)
Philipp Zabel1a297282009-04-17 11:39:38 +0200204 div = ((sscr0 >> 8) & 0xff) * 2 + 2;
205 else
206 div = ((sscr0 >> 8) & 0xfff) + 1;
207 return div;
Mark Brown1b340bd2008-07-30 19:12:04 +0100208}
209
210/*
211 * Set the SSP ports SYSCLK.
212 */
213static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
214 int clk_id, unsigned int freq, int dir)
215{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000216 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800217 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100218 int val;
219
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400220 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Daniel Mack20a41ea2009-03-04 21:16:57 +0100221 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100222
223 dev_dbg(&ssp->pdev->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700224 "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %u\n",
Mark Brown1b340bd2008-07-30 19:12:04 +0100225 cpu_dai->id, clk_id, freq);
226
227 switch (clk_id) {
228 case PXA_SSP_CLK_NET_PLL:
229 sscr0 |= SSCR0_MOD;
230 break;
231 case PXA_SSP_CLK_PLL:
232 /* Internal PLL is fixed */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800233 if (ssp->type == PXA25x_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100234 priv->sysclk = 1843200;
235 else
236 priv->sysclk = 13000000;
237 break;
238 case PXA_SSP_CLK_EXT:
239 priv->sysclk = freq;
240 sscr0 |= SSCR0_ECS;
241 break;
242 case PXA_SSP_CLK_NET:
243 priv->sysclk = freq;
244 sscr0 |= SSCR0_NCS | SSCR0_MOD;
245 break;
246 case PXA_SSP_CLK_AUDIO:
247 priv->sysclk = 0;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400248 pxa_ssp_set_scr(ssp, 1);
Daniel Mack20a41ea2009-03-04 21:16:57 +0100249 sscr0 |= SSCR0_ACS;
Mark Brown1b340bd2008-07-30 19:12:04 +0100250 break;
251 default:
252 return -ENODEV;
253 }
254
255 /* The SSP clock must be disabled when changing SSP clock mode
256 * on PXA2xx. On PXA3xx it must be enabled when doing so. */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800257 if (ssp->type != PXA3xx_SSP)
Eric Miaof9efc9d2010-02-09 19:46:01 +0800258 clk_disable(ssp->clk);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400259 val = pxa_ssp_read_reg(ssp, SSCR0) | sscr0;
260 pxa_ssp_write_reg(ssp, SSCR0, val);
Qiao Zhou972a55b2012-06-04 10:41:04 +0800261 if (ssp->type != PXA3xx_SSP)
Eric Miaof9efc9d2010-02-09 19:46:01 +0800262 clk_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100263
264 return 0;
265}
266
267/*
268 * Set the SSP clock dividers.
269 */
270static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
271 int div_id, int div)
272{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000273 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800274 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100275 int val;
276
277 switch (div_id) {
278 case PXA_SSP_AUDIO_DIV_ACDS:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400279 val = (pxa_ssp_read_reg(ssp, SSACD) & ~0x7) | SSACD_ACDS(div);
280 pxa_ssp_write_reg(ssp, SSACD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100281 break;
282 case PXA_SSP_AUDIO_DIV_SCDB:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400283 val = pxa_ssp_read_reg(ssp, SSACD);
Mark Brown1b340bd2008-07-30 19:12:04 +0100284 val &= ~SSACD_SCDB;
Qiao Zhou972a55b2012-06-04 10:41:04 +0800285 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100286 val &= ~SSACD_SCDX8;
Mark Brown1b340bd2008-07-30 19:12:04 +0100287 switch (div) {
288 case PXA_SSP_CLK_SCDB_1:
289 val |= SSACD_SCDB;
290 break;
291 case PXA_SSP_CLK_SCDB_4:
292 break;
Mark Brown1b340bd2008-07-30 19:12:04 +0100293 case PXA_SSP_CLK_SCDB_8:
Qiao Zhou972a55b2012-06-04 10:41:04 +0800294 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100295 val |= SSACD_SCDX8;
296 else
297 return -EINVAL;
298 break;
Mark Brown1b340bd2008-07-30 19:12:04 +0100299 default:
300 return -EINVAL;
301 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400302 pxa_ssp_write_reg(ssp, SSACD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100303 break;
304 case PXA_SSP_DIV_SCR:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400305 pxa_ssp_set_scr(ssp, div);
Mark Brown1b340bd2008-07-30 19:12:04 +0100306 break;
307 default:
308 return -ENODEV;
309 }
310
311 return 0;
312}
313
314/*
315 * Configure the PLL frequency pxa27x and (afaik - pxa320 only)
316 */
Mark Brown85488032009-09-05 18:52:16 +0100317static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
318 int source, unsigned int freq_in, unsigned int freq_out)
Mark Brown1b340bd2008-07-30 19:12:04 +0100319{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000320 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800321 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400322 u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70;
Mark Brown1b340bd2008-07-30 19:12:04 +0100323
Qiao Zhou972a55b2012-06-04 10:41:04 +0800324 if (ssp->type == PXA3xx_SSP)
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400325 pxa_ssp_write_reg(ssp, SSACDD, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100326
327 switch (freq_out) {
328 case 5622000:
329 break;
330 case 11345000:
331 ssacd |= (0x1 << 4);
332 break;
333 case 12235000:
334 ssacd |= (0x2 << 4);
335 break;
336 case 14857000:
337 ssacd |= (0x3 << 4);
338 break;
339 case 32842000:
340 ssacd |= (0x4 << 4);
341 break;
342 case 48000000:
343 ssacd |= (0x5 << 4);
344 break;
345 case 0:
346 /* Disable */
347 break;
348
349 default:
Mark Brown1b340bd2008-07-30 19:12:04 +0100350 /* PXA3xx has a clock ditherer which can be used to generate
351 * a wider range of frequencies - calculate a value for it.
352 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800353 if (ssp->type == PXA3xx_SSP) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100354 u32 val;
355 u64 tmp = 19968;
356 tmp *= 1000000;
357 do_div(tmp, freq_out);
358 val = tmp;
359
Joe Perchesa419aef2009-08-18 11:18:35 -0700360 val = (val << 16) | 64;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400361 pxa_ssp_write_reg(ssp, SSACDD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100362
363 ssacd |= (0x6 << 4);
364
365 dev_dbg(&ssp->pdev->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700366 "Using SSACDD %x to supply %uHz\n",
Mark Brown1b340bd2008-07-30 19:12:04 +0100367 val, freq_out);
368 break;
369 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100370
371 return -EINVAL;
372 }
373
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400374 pxa_ssp_write_reg(ssp, SSACD, ssacd);
Mark Brown1b340bd2008-07-30 19:12:04 +0100375
376 return 0;
377}
378
379/*
380 * Set the active slots in TDM/Network mode
381 */
382static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300383 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
Mark Brown1b340bd2008-07-30 19:12:04 +0100384{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000385 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800386 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100387 u32 sscr0;
388
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400389 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300390 sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100391
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300392 /* set slot width */
393 if (slot_width > 16)
394 sscr0 |= SSCR0_EDSS | SSCR0_DataSize(slot_width - 16);
395 else
396 sscr0 |= SSCR0_DataSize(slot_width);
397
398 if (slots > 1) {
399 /* enable network mode */
400 sscr0 |= SSCR0_MOD;
401
402 /* set number of active slots */
403 sscr0 |= SSCR0_SlotsPerFrm(slots);
404
405 /* set active slot mask */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400406 pxa_ssp_write_reg(ssp, SSTSA, tx_mask);
407 pxa_ssp_write_reg(ssp, SSRSA, rx_mask);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300408 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400409 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100410
Mark Brown1b340bd2008-07-30 19:12:04 +0100411 return 0;
412}
413
414/*
415 * Tristate the SSP DAI lines
416 */
417static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
418 int tristate)
419{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000420 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800421 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100422 u32 sscr1;
423
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400424 sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100425 if (tristate)
426 sscr1 &= ~SSCR1_TTE;
427 else
428 sscr1 |= SSCR1_TTE;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400429 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100430
431 return 0;
432}
433
434/*
435 * Set up the SSP DAI format.
436 * The SSP Port must be inactive before calling this function as the
437 * physical interface format is changed.
438 */
439static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
440 unsigned int fmt)
441{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000442 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800443 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800444 u32 sscr0, sscr1, sspsp, scfr;
Mark Brown1b340bd2008-07-30 19:12:04 +0100445
Daniel Mackcbf11462009-03-10 16:41:00 +0100446 /* check if we need to change anything at all */
447 if (priv->dai_fmt == fmt)
448 return 0;
449
450 /* we can only change the settings if the port is not in use */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400451 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
Daniel Mackcbf11462009-03-10 16:41:00 +0100452 dev_err(&ssp->pdev->dev,
453 "can't change hardware dai format: stream is in use");
454 return -EINVAL;
455 }
456
Mark Brown1b340bd2008-07-30 19:12:04 +0100457 /* reset port settings */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400458 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800459 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100460 sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
461 sspsp = 0;
462
463 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
464 case SND_SOC_DAIFMT_CBM_CFM:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800465 sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100466 break;
467 case SND_SOC_DAIFMT_CBM_CFS:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800468 sscr1 |= SSCR1_SCLKDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100469 break;
470 case SND_SOC_DAIFMT_CBS_CFS:
471 break;
472 default:
473 return -EINVAL;
474 }
475
Daniel Ribeirofa44c072009-06-10 15:23:24 -0300476 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
477 case SND_SOC_DAIFMT_NB_NF:
478 sspsp |= SSPSP_SFRMP;
479 break;
480 case SND_SOC_DAIFMT_NB_IF:
481 break;
482 case SND_SOC_DAIFMT_IB_IF:
483 sspsp |= SSPSP_SCMODE(2);
484 break;
485 case SND_SOC_DAIFMT_IB_NF:
486 sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP;
487 break;
488 default:
489 return -EINVAL;
490 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100491
492 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
493 case SND_SOC_DAIFMT_I2S:
Daniel Mack72d74662009-03-12 11:27:49 +0100494 sscr0 |= SSCR0_PSP;
Mark Brown1b340bd2008-07-30 19:12:04 +0100495 sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
Mark Brown0ce36c52009-03-13 14:26:08 +0000496 /* See hw_params() */
Mark Brown1b340bd2008-07-30 19:12:04 +0100497 break;
498
499 case SND_SOC_DAIFMT_DSP_A:
500 sspsp |= SSPSP_FSRT;
501 case SND_SOC_DAIFMT_DSP_B:
502 sscr0 |= SSCR0_MOD | SSCR0_PSP;
503 sscr1 |= SSCR1_TRAIL | SSCR1_RWOT;
Mark Brown1b340bd2008-07-30 19:12:04 +0100504 break;
505
506 default:
507 return -EINVAL;
508 }
509
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400510 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
511 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
512 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100513
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800514 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
515 case SND_SOC_DAIFMT_CBM_CFM:
516 case SND_SOC_DAIFMT_CBM_CFS:
517 scfr = pxa_ssp_read_reg(ssp, SSCR1) | SSCR1_SCFR;
518 pxa_ssp_write_reg(ssp, SSCR1, scfr);
519
520 while (pxa_ssp_read_reg(ssp, SSSR) & SSSR_BSY)
521 cpu_relax();
522 break;
523 }
524
Mark Brown1b340bd2008-07-30 19:12:04 +0100525 dump_registers(ssp);
526
527 /* Since we are configuring the timings for the format by hand
528 * we have to defer some things until hw_params() where we
529 * know parameters like the sample size.
530 */
531 priv->dai_fmt = fmt;
532
533 return 0;
534}
535
536/*
537 * Set the SSP audio DMA parameters and sample size.
538 * Can be called multiple times by oss emulation.
539 */
540static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000541 struct snd_pcm_hw_params *params,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000542 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100543{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000544 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800545 struct ssp_device *ssp = priv->ssp;
Eric Miao2d7e71f2009-04-23 17:05:38 +0800546 int chn = params_channels(params);
Mark Brown1b340bd2008-07-30 19:12:04 +0100547 u32 sscr0;
548 u32 sspsp;
549 int width = snd_pcm_format_physical_width(params_format(params));
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400550 int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf;
Daniel Mackd65a1452013-08-12 10:42:39 +0200551 struct snd_dmaengine_dai_dma_data *dma_data;
Daniel Mack5f712b22010-03-22 10:11:15 +0100552
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000553 dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
Mark Brown1b340bd2008-07-30 19:12:04 +0100554
Philipp Zabel92429062009-03-19 09:32:01 +0100555 /* Network mode with one active slot (ttsa == 1) can be used
556 * to force 16-bit frame width on the wire (for S16_LE), even
557 * with two channels. Use 16-bit DMA transfers for this case.
558 */
guoyhd93ca1a2012-05-07 15:34:24 +0800559 pxa_ssp_set_dma_params(ssp,
560 ((chn == 2) && (ttsa != 1)) || (width == 32),
561 substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data);
Daniel Mack5f712b22010-03-22 10:11:15 +0100562
Mark Brown1b340bd2008-07-30 19:12:04 +0100563 /* we can only change the settings if the port is not in use */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400564 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
Mark Brown1b340bd2008-07-30 19:12:04 +0100565 return 0;
566
567 /* clear selected SSP bits */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400568 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100569
570 /* bit size */
Mark Brown1b340bd2008-07-30 19:12:04 +0100571 switch (params_format(params)) {
572 case SNDRV_PCM_FORMAT_S16_LE:
Qiao Zhou972a55b2012-06-04 10:41:04 +0800573 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100574 sscr0 |= SSCR0_FPCKE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100575 sscr0 |= SSCR0_DataSize(16);
Mark Brown1b340bd2008-07-30 19:12:04 +0100576 break;
577 case SNDRV_PCM_FORMAT_S24_LE:
578 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
Mark Brown1b340bd2008-07-30 19:12:04 +0100579 break;
580 case SNDRV_PCM_FORMAT_S32_LE:
581 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
Mark Brown1b340bd2008-07-30 19:12:04 +0100582 break;
583 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400584 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100585
586 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
587 case SND_SOC_DAIFMT_I2S:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400588 sspsp = pxa_ssp_read_reg(ssp, SSPSP);
Daniel Mack72d74662009-03-12 11:27:49 +0100589
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400590 if ((pxa_ssp_get_scr(ssp) == 4) && (width == 16)) {
Daniel Mack72d74662009-03-12 11:27:49 +0100591 /* This is a special case where the bitclk is 64fs
592 * and we're not dealing with 2*32 bits of audio
593 * samples.
594 *
595 * The SSP values used for that are all found out by
596 * trying and failing a lot; some of the registers
597 * needed for that mode are only available on PXA3xx.
598 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800599 if (ssp->type != PXA3xx_SSP)
Daniel Mack72d74662009-03-12 11:27:49 +0100600 return -EINVAL;
601
602 sspsp |= SSPSP_SFRMWDTH(width * 2);
603 sspsp |= SSPSP_SFRMDLY(width * 4);
604 sspsp |= SSPSP_EDMYSTOP(3);
605 sspsp |= SSPSP_DMYSTOP(3);
606 sspsp |= SSPSP_DMYSTRT(1);
Mark Brown0ce36c52009-03-13 14:26:08 +0000607 } else {
608 /* The frame width is the width the LRCLK is
609 * asserted for; the delay is expressed in
610 * half cycle units. We need the extra cycle
611 * because the data starts clocking out one BCLK
612 * after LRCLK changes polarity.
613 */
614 sspsp |= SSPSP_SFRMWDTH(width + 1);
615 sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
616 sspsp |= SSPSP_DMYSTRT(1);
617 }
Daniel Mack72d74662009-03-12 11:27:49 +0100618
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400619 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100620 break;
621 default:
622 break;
623 }
624
Daniel Mack72d74662009-03-12 11:27:49 +0100625 /* When we use a network mode, we always require TDM slots
Mark Brown1b340bd2008-07-30 19:12:04 +0100626 * - complain loudly and fail if they've not been set up yet.
627 */
Philipp Zabel92429062009-03-19 09:32:01 +0100628 if ((sscr0 & SSCR0_MOD) && !ttsa) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100629 dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
630 return -EINVAL;
631 }
632
633 dump_registers(ssp);
634
635 return 0;
636}
637
Daniel Mack273b72c2012-03-19 09:12:53 +0100638static void pxa_ssp_set_running_bit(struct snd_pcm_substream *substream,
639 struct ssp_device *ssp, int value)
640{
641 uint32_t sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
642 uint32_t sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
643 uint32_t sspsp = pxa_ssp_read_reg(ssp, SSPSP);
644 uint32_t sssr = pxa_ssp_read_reg(ssp, SSSR);
645
646 if (value && (sscr0 & SSCR0_SSE))
647 pxa_ssp_write_reg(ssp, SSCR0, sscr0 & ~SSCR0_SSE);
648
649 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
650 if (value)
651 sscr1 |= SSCR1_TSRE;
652 else
653 sscr1 &= ~SSCR1_TSRE;
654 } else {
655 if (value)
656 sscr1 |= SSCR1_RSRE;
657 else
658 sscr1 &= ~SSCR1_RSRE;
659 }
660
661 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
662
663 if (value) {
664 pxa_ssp_write_reg(ssp, SSSR, sssr);
665 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
666 pxa_ssp_write_reg(ssp, SSCR0, sscr0 | SSCR0_SSE);
667 }
668}
669
Mark Browndee89c42008-11-18 22:11:38 +0000670static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000671 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100672{
Mark Brown1b340bd2008-07-30 19:12:04 +0100673 int ret = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000674 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800675 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100676 int val;
677
678 switch (cmd) {
679 case SNDRV_PCM_TRIGGER_RESUME:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400680 pxa_ssp_enable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100681 break;
682 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Daniel Mack273b72c2012-03-19 09:12:53 +0100683 pxa_ssp_set_running_bit(substream, ssp, 1);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400684 val = pxa_ssp_read_reg(ssp, SSSR);
685 pxa_ssp_write_reg(ssp, SSSR, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100686 break;
687 case SNDRV_PCM_TRIGGER_START:
Daniel Mack273b72c2012-03-19 09:12:53 +0100688 pxa_ssp_set_running_bit(substream, ssp, 1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100689 break;
690 case SNDRV_PCM_TRIGGER_STOP:
Daniel Mack273b72c2012-03-19 09:12:53 +0100691 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100692 break;
693 case SNDRV_PCM_TRIGGER_SUSPEND:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400694 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100695 break;
696 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Daniel Mack273b72c2012-03-19 09:12:53 +0100697 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100698 break;
699
700 default:
701 ret = -EINVAL;
702 }
703
704 dump_registers(ssp);
705
706 return ret;
707}
708
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000709static int pxa_ssp_probe(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100710{
Daniel Mack2023c902013-08-12 10:42:38 +0200711 struct device *dev = dai->dev;
Mark Brown1b340bd2008-07-30 19:12:04 +0100712 struct ssp_priv *priv;
713 int ret;
714
715 priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL);
716 if (!priv)
717 return -ENOMEM;
718
Daniel Mack2023c902013-08-12 10:42:38 +0200719 if (dev->of_node) {
720 struct device_node *ssp_handle;
721
722 ssp_handle = of_parse_phandle(dev->of_node, "port", 0);
723 if (!ssp_handle) {
724 dev_err(dev, "unable to get 'port' phandle\n");
725 return -ENODEV;
726 }
727
728 priv->ssp = pxa_ssp_request_of(ssp_handle, "SoC audio");
729 if (priv->ssp == NULL) {
730 ret = -ENODEV;
731 goto err_priv;
732 }
733 } else {
734 priv->ssp = pxa_ssp_request(dai->id + 1, "SoC audio");
735 if (priv->ssp == NULL) {
736 ret = -ENODEV;
737 goto err_priv;
738 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100739 }
740
Daniel Macka5735b72009-04-15 20:24:45 +0200741 priv->dai_fmt = (unsigned int) -1;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000742 snd_soc_dai_set_drvdata(dai, priv);
Mark Brown1b340bd2008-07-30 19:12:04 +0100743
744 return 0;
745
746err_priv:
747 kfree(priv);
748 return ret;
749}
750
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000751static int pxa_ssp_remove(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100752{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000753 struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai);
754
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400755 pxa_ssp_free(priv->ssp);
Axel Lin014a2752010-08-25 16:59:11 +0800756 kfree(priv);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000757 return 0;
Mark Brown1b340bd2008-07-30 19:12:04 +0100758}
759
760#define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
761 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
Qiao Zhou8d8bf582012-03-08 10:02:36 +0800762 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
763 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
Mark Brown1b340bd2008-07-30 19:12:04 +0100764 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
765
766#define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
767 SNDRV_PCM_FMTBIT_S24_LE | \
768 SNDRV_PCM_FMTBIT_S32_LE)
769
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100770static const struct snd_soc_dai_ops pxa_ssp_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800771 .startup = pxa_ssp_startup,
772 .shutdown = pxa_ssp_shutdown,
773 .trigger = pxa_ssp_trigger,
774 .hw_params = pxa_ssp_hw_params,
775 .set_sysclk = pxa_ssp_set_dai_sysclk,
776 .set_clkdiv = pxa_ssp_set_dai_clkdiv,
777 .set_pll = pxa_ssp_set_dai_pll,
778 .set_fmt = pxa_ssp_set_dai_fmt,
779 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
780 .set_tristate = pxa_ssp_set_dai_tristate,
781};
782
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000783static struct snd_soc_dai_driver pxa_ssp_dai = {
Mark Brown1b340bd2008-07-30 19:12:04 +0100784 .probe = pxa_ssp_probe,
785 .remove = pxa_ssp_remove,
786 .suspend = pxa_ssp_suspend,
787 .resume = pxa_ssp_resume,
788 .playback = {
789 .channels_min = 1,
Graeme Gregoryf34762b2009-09-25 13:30:26 +0100790 .channels_max = 8,
Mark Brown1b340bd2008-07-30 19:12:04 +0100791 .rates = PXA_SSP_RATES,
792 .formats = PXA_SSP_FORMATS,
793 },
794 .capture = {
795 .channels_min = 1,
Graeme Gregoryf34762b2009-09-25 13:30:26 +0100796 .channels_max = 8,
Mark Brown1b340bd2008-07-30 19:12:04 +0100797 .rates = PXA_SSP_RATES,
798 .formats = PXA_SSP_FORMATS,
799 },
Eric Miao6335d052009-03-03 09:41:00 +0800800 .ops = &pxa_ssp_dai_ops,
Mark Brown1b340bd2008-07-30 19:12:04 +0100801};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000802
Kuninori Morimotoe580f1c2013-03-21 03:34:12 -0700803static const struct snd_soc_component_driver pxa_ssp_component = {
804 .name = "pxa-ssp",
805};
806
Daniel Mack2023c902013-08-12 10:42:38 +0200807#ifdef CONFIG_OF
808static const struct of_device_id pxa_ssp_of_ids[] = {
809 { .compatible = "mrvl,pxa-ssp-dai" },
810};
811#endif
812
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500813static int asoc_ssp_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000814{
Kuninori Morimotoe580f1c2013-03-21 03:34:12 -0700815 return snd_soc_register_component(&pdev->dev, &pxa_ssp_component,
816 &pxa_ssp_dai, 1);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000817}
818
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500819static int asoc_ssp_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000820{
Kuninori Morimotoe580f1c2013-03-21 03:34:12 -0700821 snd_soc_unregister_component(&pdev->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000822 return 0;
823}
824
825static struct platform_driver asoc_ssp_driver = {
826 .driver = {
Daniel Mack2023c902013-08-12 10:42:38 +0200827 .name = "pxa-ssp-dai",
828 .owner = THIS_MODULE,
829 .of_match_table = of_match_ptr(pxa_ssp_of_ids),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000830 },
831
832 .probe = asoc_ssp_probe,
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500833 .remove = asoc_ssp_remove,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000834};
Mark Brown1b340bd2008-07-30 19:12:04 +0100835
Axel Lin2f702a12011-11-25 10:13:37 +0800836module_platform_driver(asoc_ssp_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000837
Mark Brown1b340bd2008-07-30 19:12:04 +0100838/* Module information */
839MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
840MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface");
841MODULE_LICENSE("GPL");