blob: 3cad990dad2cd35e8334ff54ea14632c0319dd8c [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
Haojian Zhuangdd99a452010-08-13 21:55:27 +080037#include "../../arm/pxa2xx-pcm.h"
Mark Brown1b340bd2008-07-30 19:12:04 +010038#include "pxa-ssp.h"
39
40/*
41 * SSP audio private data
42 */
43struct ssp_priv {
Eric Miaof9efc9d2010-02-09 19:46:01 +080044 struct ssp_device *ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +010045 unsigned int sysclk;
46 int dai_fmt;
47#ifdef CONFIG_PM
Eric Miaof9efc9d2010-02-09 19:46:01 +080048 uint32_t cr0;
49 uint32_t cr1;
50 uint32_t to;
51 uint32_t psp;
Mark Brown1b340bd2008-07-30 19:12:04 +010052#endif
53};
54
Mark Brown1b340bd2008-07-30 19:12:04 +010055static void dump_registers(struct ssp_device *ssp)
56{
57 dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
Haojian Zhuangbaffe162010-05-05 10:11:15 -040058 pxa_ssp_read_reg(ssp, SSCR0), pxa_ssp_read_reg(ssp, SSCR1),
59 pxa_ssp_read_reg(ssp, SSTO));
Mark Brown1b340bd2008-07-30 19:12:04 +010060
61 dev_dbg(&ssp->pdev->dev, "SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n",
Haojian Zhuangbaffe162010-05-05 10:11:15 -040062 pxa_ssp_read_reg(ssp, SSPSP), pxa_ssp_read_reg(ssp, SSSR),
63 pxa_ssp_read_reg(ssp, SSACD));
Mark Brown1b340bd2008-07-30 19:12:04 +010064}
65
Haojian Zhuangbaffe162010-05-05 10:11:15 -040066static void pxa_ssp_enable(struct ssp_device *ssp)
Eric Miaof9efc9d2010-02-09 19:46:01 +080067{
68 uint32_t sscr0;
69
70 sscr0 = __raw_readl(ssp->mmio_base + SSCR0) | SSCR0_SSE;
71 __raw_writel(sscr0, ssp->mmio_base + SSCR0);
72}
73
Haojian Zhuangbaffe162010-05-05 10:11:15 -040074static void pxa_ssp_disable(struct ssp_device *ssp)
Eric Miaof9efc9d2010-02-09 19:46:01 +080075{
76 uint32_t sscr0;
77
78 sscr0 = __raw_readl(ssp->mmio_base + SSCR0) & ~SSCR0_SSE;
79 __raw_writel(sscr0, ssp->mmio_base + SSCR0);
80}
81
guoyhd93ca1a2012-05-07 15:34:24 +080082static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,
Daniel Mackd65a1452013-08-12 10:42:39 +020083 int out, struct snd_dmaengine_dai_dma_data *dma)
Eric Miao2d7e71f2009-04-23 17:05:38 +080084{
Daniel Mackd65a1452013-08-12 10:42:39 +020085 dma->addr_width = width4 ? DMA_SLAVE_BUSWIDTH_4_BYTES :
86 DMA_SLAVE_BUSWIDTH_2_BYTES;
87 dma->maxburst = 16;
88 dma->addr = ssp->phys_base + SSDR;
Eric Miao2d7e71f2009-04-23 17:05:38 +080089}
90
Mark Browndee89c42008-11-18 22:11:38 +000091static int pxa_ssp_startup(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000092 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +010093{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000094 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +080095 struct ssp_device *ssp = priv->ssp;
Daniel Mackd65a1452013-08-12 10:42:39 +020096 struct snd_dmaengine_dai_dma_data *dma;
Mark Brown1b340bd2008-07-30 19:12:04 +010097 int ret = 0;
98
99 if (!cpu_dai->active) {
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300100 clk_prepare_enable(ssp->clk);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400101 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100102 }
Eric Miao2d7e71f2009-04-23 17:05:38 +0800103
Daniel Mackd65a1452013-08-12 10:42:39 +0200104 dma = kzalloc(sizeof(struct snd_dmaengine_dai_dma_data), GFP_KERNEL);
guoyhd93ca1a2012-05-07 15:34:24 +0800105 if (!dma)
106 return -ENOMEM;
Daniel Macka6714682013-08-12 10:42:40 +0200107
108 dma->filter_data = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
109 &ssp->drcmr_tx : &ssp->drcmr_rx;
110
Daniel Mackd65a1452013-08-12 10:42:39 +0200111 snd_soc_dai_set_dma_data(cpu_dai, substream, dma);
Daniel Mack5f712b22010-03-22 10:11:15 +0100112
Mark Brown1b340bd2008-07-30 19:12:04 +0100113 return ret;
114}
115
Mark Browndee89c42008-11-18 22:11:38 +0000116static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000117 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100118{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000119 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800120 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100121
122 if (!cpu_dai->active) {
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400123 pxa_ssp_disable(ssp);
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300124 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100125 }
Eric Miao2d7e71f2009-04-23 17:05:38 +0800126
Daniel Mack5f712b22010-03-22 10:11:15 +0100127 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
128 snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
Mark Brown1b340bd2008-07-30 19:12:04 +0100129}
130
131#ifdef CONFIG_PM
132
Mark Browndc7d7b82008-12-03 18:21:52 +0000133static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100134{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000135 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800136 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100137
138 if (!cpu_dai->active)
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300139 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100140
Eric Miaof9efc9d2010-02-09 19:46:01 +0800141 priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0);
142 priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1);
143 priv->to = __raw_readl(ssp->mmio_base + SSTO);
144 priv->psp = __raw_readl(ssp->mmio_base + SSPSP);
145
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400146 pxa_ssp_disable(ssp);
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300147 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100148 return 0;
149}
150
Mark Browndc7d7b82008-12-03 18:21:52 +0000151static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100152{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000153 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800154 struct ssp_device *ssp = priv->ssp;
155 uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100156
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300157 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100158
Eric Miaof9efc9d2010-02-09 19:46:01 +0800159 __raw_writel(sssr, ssp->mmio_base + SSSR);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800160 __raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0);
161 __raw_writel(priv->cr1, ssp->mmio_base + SSCR1);
162 __raw_writel(priv->to, ssp->mmio_base + SSTO);
163 __raw_writel(priv->psp, ssp->mmio_base + SSPSP);
Daniel Mack026384d2010-02-02 18:45:27 +0800164
165 if (cpu_dai->active)
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400166 pxa_ssp_enable(ssp);
Daniel Mack026384d2010-02-02 18:45:27 +0800167 else
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300168 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100169
170 return 0;
171}
172
173#else
174#define pxa_ssp_suspend NULL
175#define pxa_ssp_resume NULL
176#endif
177
178/**
179 * ssp_set_clkdiv - set SSP clock divider
180 * @div: serial clock rate divider
181 */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400182static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div)
Mark Brown1b340bd2008-07-30 19:12:04 +0100183{
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400184 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100185
Qiao Zhou972a55b2012-06-04 10:41:04 +0800186 if (ssp->type == PXA25x_SSP) {
Philipp Zabel1a297282009-04-17 11:39:38 +0200187 sscr0 &= ~0x0000ff00;
188 sscr0 |= ((div - 2)/2) << 8; /* 2..512 */
189 } else {
190 sscr0 &= ~0x000fff00;
191 sscr0 |= (div - 1) << 8; /* 1..4096 */
192 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400193 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Philipp Zabel1a297282009-04-17 11:39:38 +0200194}
195
196/**
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400197 * pxa_ssp_get_clkdiv - get SSP clock divider
Philipp Zabel1a297282009-04-17 11:39:38 +0200198 */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400199static u32 pxa_ssp_get_scr(struct ssp_device *ssp)
Philipp Zabel1a297282009-04-17 11:39:38 +0200200{
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400201 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Philipp Zabel1a297282009-04-17 11:39:38 +0200202 u32 div;
203
Qiao Zhou972a55b2012-06-04 10:41:04 +0800204 if (ssp->type == PXA25x_SSP)
Philipp Zabel1a297282009-04-17 11:39:38 +0200205 div = ((sscr0 >> 8) & 0xff) * 2 + 2;
206 else
207 div = ((sscr0 >> 8) & 0xfff) + 1;
208 return div;
Mark Brown1b340bd2008-07-30 19:12:04 +0100209}
210
211/*
212 * Set the SSP ports SYSCLK.
213 */
214static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
215 int clk_id, unsigned int freq, int dir)
216{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000217 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800218 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100219 int val;
220
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400221 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Daniel Mack20a41ea2009-03-04 21:16:57 +0100222 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100223
224 dev_dbg(&ssp->pdev->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700225 "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %u\n",
Mark Brown1b340bd2008-07-30 19:12:04 +0100226 cpu_dai->id, clk_id, freq);
227
228 switch (clk_id) {
229 case PXA_SSP_CLK_NET_PLL:
230 sscr0 |= SSCR0_MOD;
231 break;
232 case PXA_SSP_CLK_PLL:
233 /* Internal PLL is fixed */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800234 if (ssp->type == PXA25x_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100235 priv->sysclk = 1843200;
236 else
237 priv->sysclk = 13000000;
238 break;
239 case PXA_SSP_CLK_EXT:
240 priv->sysclk = freq;
241 sscr0 |= SSCR0_ECS;
242 break;
243 case PXA_SSP_CLK_NET:
244 priv->sysclk = freq;
245 sscr0 |= SSCR0_NCS | SSCR0_MOD;
246 break;
247 case PXA_SSP_CLK_AUDIO:
248 priv->sysclk = 0;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400249 pxa_ssp_set_scr(ssp, 1);
Daniel Mack20a41ea2009-03-04 21:16:57 +0100250 sscr0 |= SSCR0_ACS;
Mark Brown1b340bd2008-07-30 19:12:04 +0100251 break;
252 default:
253 return -ENODEV;
254 }
255
256 /* The SSP clock must be disabled when changing SSP clock mode
257 * on PXA2xx. On PXA3xx it must be enabled when doing so. */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800258 if (ssp->type != PXA3xx_SSP)
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300259 clk_disable_unprepare(ssp->clk);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400260 val = pxa_ssp_read_reg(ssp, SSCR0) | sscr0;
261 pxa_ssp_write_reg(ssp, SSCR0, val);
Qiao Zhou972a55b2012-06-04 10:41:04 +0800262 if (ssp->type != PXA3xx_SSP)
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300263 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100264
265 return 0;
266}
267
268/*
269 * Set the SSP clock dividers.
270 */
271static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
272 int div_id, int div)
273{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000274 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800275 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100276 int val;
277
278 switch (div_id) {
279 case PXA_SSP_AUDIO_DIV_ACDS:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400280 val = (pxa_ssp_read_reg(ssp, SSACD) & ~0x7) | SSACD_ACDS(div);
281 pxa_ssp_write_reg(ssp, SSACD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100282 break;
283 case PXA_SSP_AUDIO_DIV_SCDB:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400284 val = pxa_ssp_read_reg(ssp, SSACD);
Mark Brown1b340bd2008-07-30 19:12:04 +0100285 val &= ~SSACD_SCDB;
Qiao Zhou972a55b2012-06-04 10:41:04 +0800286 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100287 val &= ~SSACD_SCDX8;
Mark Brown1b340bd2008-07-30 19:12:04 +0100288 switch (div) {
289 case PXA_SSP_CLK_SCDB_1:
290 val |= SSACD_SCDB;
291 break;
292 case PXA_SSP_CLK_SCDB_4:
293 break;
Mark Brown1b340bd2008-07-30 19:12:04 +0100294 case PXA_SSP_CLK_SCDB_8:
Qiao Zhou972a55b2012-06-04 10:41:04 +0800295 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100296 val |= SSACD_SCDX8;
297 else
298 return -EINVAL;
299 break;
Mark Brown1b340bd2008-07-30 19:12:04 +0100300 default:
301 return -EINVAL;
302 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400303 pxa_ssp_write_reg(ssp, SSACD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100304 break;
305 case PXA_SSP_DIV_SCR:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400306 pxa_ssp_set_scr(ssp, div);
Mark Brown1b340bd2008-07-30 19:12:04 +0100307 break;
308 default:
309 return -ENODEV;
310 }
311
312 return 0;
313}
314
315/*
316 * Configure the PLL frequency pxa27x and (afaik - pxa320 only)
317 */
Mark Brown85488032009-09-05 18:52:16 +0100318static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
319 int source, unsigned int freq_in, unsigned int freq_out)
Mark Brown1b340bd2008-07-30 19:12:04 +0100320{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000321 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800322 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400323 u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70;
Mark Brown1b340bd2008-07-30 19:12:04 +0100324
Qiao Zhou972a55b2012-06-04 10:41:04 +0800325 if (ssp->type == PXA3xx_SSP)
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400326 pxa_ssp_write_reg(ssp, SSACDD, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100327
328 switch (freq_out) {
329 case 5622000:
330 break;
331 case 11345000:
332 ssacd |= (0x1 << 4);
333 break;
334 case 12235000:
335 ssacd |= (0x2 << 4);
336 break;
337 case 14857000:
338 ssacd |= (0x3 << 4);
339 break;
340 case 32842000:
341 ssacd |= (0x4 << 4);
342 break;
343 case 48000000:
344 ssacd |= (0x5 << 4);
345 break;
346 case 0:
347 /* Disable */
348 break;
349
350 default:
Mark Brown1b340bd2008-07-30 19:12:04 +0100351 /* PXA3xx has a clock ditherer which can be used to generate
352 * a wider range of frequencies - calculate a value for it.
353 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800354 if (ssp->type == PXA3xx_SSP) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100355 u32 val;
356 u64 tmp = 19968;
357 tmp *= 1000000;
358 do_div(tmp, freq_out);
359 val = tmp;
360
Joe Perchesa419aef2009-08-18 11:18:35 -0700361 val = (val << 16) | 64;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400362 pxa_ssp_write_reg(ssp, SSACDD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100363
364 ssacd |= (0x6 << 4);
365
366 dev_dbg(&ssp->pdev->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700367 "Using SSACDD %x to supply %uHz\n",
Mark Brown1b340bd2008-07-30 19:12:04 +0100368 val, freq_out);
369 break;
370 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100371
372 return -EINVAL;
373 }
374
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400375 pxa_ssp_write_reg(ssp, SSACD, ssacd);
Mark Brown1b340bd2008-07-30 19:12:04 +0100376
377 return 0;
378}
379
380/*
381 * Set the active slots in TDM/Network mode
382 */
383static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300384 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
Mark Brown1b340bd2008-07-30 19:12:04 +0100385{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000386 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800387 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100388 u32 sscr0;
389
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400390 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300391 sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100392
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300393 /* set slot width */
394 if (slot_width > 16)
395 sscr0 |= SSCR0_EDSS | SSCR0_DataSize(slot_width - 16);
396 else
397 sscr0 |= SSCR0_DataSize(slot_width);
398
399 if (slots > 1) {
400 /* enable network mode */
401 sscr0 |= SSCR0_MOD;
402
403 /* set number of active slots */
404 sscr0 |= SSCR0_SlotsPerFrm(slots);
405
406 /* set active slot mask */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400407 pxa_ssp_write_reg(ssp, SSTSA, tx_mask);
408 pxa_ssp_write_reg(ssp, SSRSA, rx_mask);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300409 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400410 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100411
Mark Brown1b340bd2008-07-30 19:12:04 +0100412 return 0;
413}
414
415/*
416 * Tristate the SSP DAI lines
417 */
418static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
419 int tristate)
420{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000421 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800422 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100423 u32 sscr1;
424
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400425 sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100426 if (tristate)
427 sscr1 &= ~SSCR1_TTE;
428 else
429 sscr1 |= SSCR1_TTE;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400430 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100431
432 return 0;
433}
434
435/*
436 * Set up the SSP DAI format.
437 * The SSP Port must be inactive before calling this function as the
438 * physical interface format is changed.
439 */
440static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
441 unsigned int fmt)
442{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000443 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800444 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800445 u32 sscr0, sscr1, sspsp, scfr;
Mark Brown1b340bd2008-07-30 19:12:04 +0100446
Daniel Mackcbf11462009-03-10 16:41:00 +0100447 /* check if we need to change anything at all */
448 if (priv->dai_fmt == fmt)
449 return 0;
450
451 /* we can only change the settings if the port is not in use */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400452 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
Daniel Mackcbf11462009-03-10 16:41:00 +0100453 dev_err(&ssp->pdev->dev,
454 "can't change hardware dai format: stream is in use");
455 return -EINVAL;
456 }
457
Mark Brown1b340bd2008-07-30 19:12:04 +0100458 /* reset port settings */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400459 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800460 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100461 sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
462 sspsp = 0;
463
464 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
465 case SND_SOC_DAIFMT_CBM_CFM:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800466 sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100467 break;
468 case SND_SOC_DAIFMT_CBM_CFS:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800469 sscr1 |= SSCR1_SCLKDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100470 break;
471 case SND_SOC_DAIFMT_CBS_CFS:
472 break;
473 default:
474 return -EINVAL;
475 }
476
Daniel Ribeirofa44c072009-06-10 15:23:24 -0300477 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
478 case SND_SOC_DAIFMT_NB_NF:
479 sspsp |= SSPSP_SFRMP;
480 break;
481 case SND_SOC_DAIFMT_NB_IF:
482 break;
483 case SND_SOC_DAIFMT_IB_IF:
484 sspsp |= SSPSP_SCMODE(2);
485 break;
486 case SND_SOC_DAIFMT_IB_NF:
487 sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP;
488 break;
489 default:
490 return -EINVAL;
491 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100492
493 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
494 case SND_SOC_DAIFMT_I2S:
Daniel Mack72d74662009-03-12 11:27:49 +0100495 sscr0 |= SSCR0_PSP;
Mark Brown1b340bd2008-07-30 19:12:04 +0100496 sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
Mark Brown0ce36c52009-03-13 14:26:08 +0000497 /* See hw_params() */
Mark Brown1b340bd2008-07-30 19:12:04 +0100498 break;
499
500 case SND_SOC_DAIFMT_DSP_A:
501 sspsp |= SSPSP_FSRT;
502 case SND_SOC_DAIFMT_DSP_B:
503 sscr0 |= SSCR0_MOD | SSCR0_PSP;
504 sscr1 |= SSCR1_TRAIL | SSCR1_RWOT;
Mark Brown1b340bd2008-07-30 19:12:04 +0100505 break;
506
507 default:
508 return -EINVAL;
509 }
510
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400511 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
512 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
513 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100514
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800515 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
516 case SND_SOC_DAIFMT_CBM_CFM:
517 case SND_SOC_DAIFMT_CBM_CFS:
518 scfr = pxa_ssp_read_reg(ssp, SSCR1) | SSCR1_SCFR;
519 pxa_ssp_write_reg(ssp, SSCR1, scfr);
520
521 while (pxa_ssp_read_reg(ssp, SSSR) & SSSR_BSY)
522 cpu_relax();
523 break;
524 }
525
Mark Brown1b340bd2008-07-30 19:12:04 +0100526 dump_registers(ssp);
527
528 /* Since we are configuring the timings for the format by hand
529 * we have to defer some things until hw_params() where we
530 * know parameters like the sample size.
531 */
532 priv->dai_fmt = fmt;
533
534 return 0;
535}
536
537/*
538 * Set the SSP audio DMA parameters and sample size.
539 * Can be called multiple times by oss emulation.
540 */
541static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000542 struct snd_pcm_hw_params *params,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000543 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100544{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000545 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800546 struct ssp_device *ssp = priv->ssp;
Eric Miao2d7e71f2009-04-23 17:05:38 +0800547 int chn = params_channels(params);
Mark Brown1b340bd2008-07-30 19:12:04 +0100548 u32 sscr0;
549 u32 sspsp;
550 int width = snd_pcm_format_physical_width(params_format(params));
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400551 int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf;
Daniel Mackd65a1452013-08-12 10:42:39 +0200552 struct snd_dmaengine_dai_dma_data *dma_data;
Daniel Mack5f712b22010-03-22 10:11:15 +0100553
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000554 dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
Mark Brown1b340bd2008-07-30 19:12:04 +0100555
Philipp Zabel92429062009-03-19 09:32:01 +0100556 /* Network mode with one active slot (ttsa == 1) can be used
557 * to force 16-bit frame width on the wire (for S16_LE), even
558 * with two channels. Use 16-bit DMA transfers for this case.
559 */
guoyhd93ca1a2012-05-07 15:34:24 +0800560 pxa_ssp_set_dma_params(ssp,
561 ((chn == 2) && (ttsa != 1)) || (width == 32),
562 substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data);
Daniel Mack5f712b22010-03-22 10:11:15 +0100563
Mark Brown1b340bd2008-07-30 19:12:04 +0100564 /* we can only change the settings if the port is not in use */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400565 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
Mark Brown1b340bd2008-07-30 19:12:04 +0100566 return 0;
567
568 /* clear selected SSP bits */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400569 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100570
571 /* bit size */
Mark Brown1b340bd2008-07-30 19:12:04 +0100572 switch (params_format(params)) {
573 case SNDRV_PCM_FORMAT_S16_LE:
Qiao Zhou972a55b2012-06-04 10:41:04 +0800574 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100575 sscr0 |= SSCR0_FPCKE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100576 sscr0 |= SSCR0_DataSize(16);
Mark Brown1b340bd2008-07-30 19:12:04 +0100577 break;
578 case SNDRV_PCM_FORMAT_S24_LE:
579 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
Mark Brown1b340bd2008-07-30 19:12:04 +0100580 break;
581 case SNDRV_PCM_FORMAT_S32_LE:
582 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
Mark Brown1b340bd2008-07-30 19:12:04 +0100583 break;
584 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400585 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100586
587 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
588 case SND_SOC_DAIFMT_I2S:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400589 sspsp = pxa_ssp_read_reg(ssp, SSPSP);
Daniel Mack72d74662009-03-12 11:27:49 +0100590
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400591 if ((pxa_ssp_get_scr(ssp) == 4) && (width == 16)) {
Daniel Mack72d74662009-03-12 11:27:49 +0100592 /* This is a special case where the bitclk is 64fs
593 * and we're not dealing with 2*32 bits of audio
594 * samples.
595 *
596 * The SSP values used for that are all found out by
597 * trying and failing a lot; some of the registers
598 * needed for that mode are only available on PXA3xx.
599 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800600 if (ssp->type != PXA3xx_SSP)
Daniel Mack72d74662009-03-12 11:27:49 +0100601 return -EINVAL;
602
603 sspsp |= SSPSP_SFRMWDTH(width * 2);
604 sspsp |= SSPSP_SFRMDLY(width * 4);
605 sspsp |= SSPSP_EDMYSTOP(3);
606 sspsp |= SSPSP_DMYSTOP(3);
607 sspsp |= SSPSP_DMYSTRT(1);
Mark Brown0ce36c52009-03-13 14:26:08 +0000608 } else {
609 /* The frame width is the width the LRCLK is
610 * asserted for; the delay is expressed in
611 * half cycle units. We need the extra cycle
612 * because the data starts clocking out one BCLK
613 * after LRCLK changes polarity.
614 */
615 sspsp |= SSPSP_SFRMWDTH(width + 1);
616 sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
617 sspsp |= SSPSP_DMYSTRT(1);
618 }
Daniel Mack72d74662009-03-12 11:27:49 +0100619
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400620 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100621 break;
622 default:
623 break;
624 }
625
Daniel Mack72d74662009-03-12 11:27:49 +0100626 /* When we use a network mode, we always require TDM slots
Mark Brown1b340bd2008-07-30 19:12:04 +0100627 * - complain loudly and fail if they've not been set up yet.
628 */
Philipp Zabel92429062009-03-19 09:32:01 +0100629 if ((sscr0 & SSCR0_MOD) && !ttsa) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100630 dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
631 return -EINVAL;
632 }
633
634 dump_registers(ssp);
635
636 return 0;
637}
638
Daniel Mack273b72c2012-03-19 09:12:53 +0100639static void pxa_ssp_set_running_bit(struct snd_pcm_substream *substream,
640 struct ssp_device *ssp, int value)
641{
642 uint32_t sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
643 uint32_t sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
644 uint32_t sspsp = pxa_ssp_read_reg(ssp, SSPSP);
645 uint32_t sssr = pxa_ssp_read_reg(ssp, SSSR);
646
647 if (value && (sscr0 & SSCR0_SSE))
648 pxa_ssp_write_reg(ssp, SSCR0, sscr0 & ~SSCR0_SSE);
649
650 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
651 if (value)
652 sscr1 |= SSCR1_TSRE;
653 else
654 sscr1 &= ~SSCR1_TSRE;
655 } else {
656 if (value)
657 sscr1 |= SSCR1_RSRE;
658 else
659 sscr1 &= ~SSCR1_RSRE;
660 }
661
662 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
663
664 if (value) {
665 pxa_ssp_write_reg(ssp, SSSR, sssr);
666 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
667 pxa_ssp_write_reg(ssp, SSCR0, sscr0 | SSCR0_SSE);
668 }
669}
670
Mark Browndee89c42008-11-18 22:11:38 +0000671static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000672 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100673{
Mark Brown1b340bd2008-07-30 19:12:04 +0100674 int ret = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000675 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800676 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100677 int val;
678
679 switch (cmd) {
680 case SNDRV_PCM_TRIGGER_RESUME:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400681 pxa_ssp_enable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100682 break;
683 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Daniel Mack273b72c2012-03-19 09:12:53 +0100684 pxa_ssp_set_running_bit(substream, ssp, 1);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400685 val = pxa_ssp_read_reg(ssp, SSSR);
686 pxa_ssp_write_reg(ssp, SSSR, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100687 break;
688 case SNDRV_PCM_TRIGGER_START:
Daniel Mack273b72c2012-03-19 09:12:53 +0100689 pxa_ssp_set_running_bit(substream, ssp, 1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100690 break;
691 case SNDRV_PCM_TRIGGER_STOP:
Daniel Mack273b72c2012-03-19 09:12:53 +0100692 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100693 break;
694 case SNDRV_PCM_TRIGGER_SUSPEND:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400695 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100696 break;
697 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Daniel Mack273b72c2012-03-19 09:12:53 +0100698 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100699 break;
700
701 default:
702 ret = -EINVAL;
703 }
704
705 dump_registers(ssp);
706
707 return ret;
708}
709
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000710static int pxa_ssp_probe(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100711{
Daniel Mack2023c902013-08-12 10:42:38 +0200712 struct device *dev = dai->dev;
Mark Brown1b340bd2008-07-30 19:12:04 +0100713 struct ssp_priv *priv;
714 int ret;
715
716 priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL);
717 if (!priv)
718 return -ENOMEM;
719
Daniel Mack2023c902013-08-12 10:42:38 +0200720 if (dev->of_node) {
721 struct device_node *ssp_handle;
722
723 ssp_handle = of_parse_phandle(dev->of_node, "port", 0);
724 if (!ssp_handle) {
725 dev_err(dev, "unable to get 'port' phandle\n");
Dan Carpenter45487282014-07-31 15:57:51 +0300726 ret = -ENODEV;
727 goto err_priv;
Daniel Mack2023c902013-08-12 10:42:38 +0200728 }
729
730 priv->ssp = pxa_ssp_request_of(ssp_handle, "SoC audio");
731 if (priv->ssp == NULL) {
732 ret = -ENODEV;
733 goto err_priv;
734 }
735 } else {
736 priv->ssp = pxa_ssp_request(dai->id + 1, "SoC audio");
737 if (priv->ssp == NULL) {
738 ret = -ENODEV;
739 goto err_priv;
740 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100741 }
742
Daniel Macka5735b72009-04-15 20:24:45 +0200743 priv->dai_fmt = (unsigned int) -1;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000744 snd_soc_dai_set_drvdata(dai, priv);
Mark Brown1b340bd2008-07-30 19:12:04 +0100745
746 return 0;
747
748err_priv:
749 kfree(priv);
750 return ret;
751}
752
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000753static int pxa_ssp_remove(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100754{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000755 struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai);
756
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400757 pxa_ssp_free(priv->ssp);
Axel Lin014a2752010-08-25 16:59:11 +0800758 kfree(priv);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000759 return 0;
Mark Brown1b340bd2008-07-30 19:12:04 +0100760}
761
762#define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
763 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
Qiao Zhou8d8bf582012-03-08 10:02:36 +0800764 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
765 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
Mark Brown1b340bd2008-07-30 19:12:04 +0100766 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
767
Daniel Mack93015032014-08-13 21:51:06 +0200768#define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown1b340bd2008-07-30 19:12:04 +0100769
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" },
Stephen Boyd4c715c72014-05-23 17:16:49 -0700810 {}
Daniel Mack2023c902013-08-12 10:42:38 +0200811};
Luis de Bethencourtbaafd372015-09-03 13:00:03 +0200812MODULE_DEVICE_TABLE(of, pxa_ssp_of_ids);
Daniel Mack2023c902013-08-12 10:42:38 +0200813#endif
814
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500815static int asoc_ssp_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000816{
Axel Lin637ce532015-08-28 10:48:35 +0800817 return devm_snd_soc_register_component(&pdev->dev, &pxa_ssp_component,
818 &pxa_ssp_dai, 1);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000819}
820
821static struct platform_driver asoc_ssp_driver = {
822 .driver = {
Daniel Mack2023c902013-08-12 10:42:38 +0200823 .name = "pxa-ssp-dai",
Daniel Mack2023c902013-08-12 10:42:38 +0200824 .of_match_table = of_match_ptr(pxa_ssp_of_ids),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000825 },
826
827 .probe = asoc_ssp_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000828};
Mark Brown1b340bd2008-07-30 19:12:04 +0100829
Axel Lin2f702a12011-11-25 10:13:37 +0800830module_platform_driver(asoc_ssp_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000831
Mark Brown1b340bd2008-07-30 19:12:04 +0100832/* Module information */
833MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
834MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface");
835MODULE_LICENSE("GPL");
Andrea Adamie5b7d712016-05-06 17:27:34 +0200836MODULE_ALIAS("platform:pxa-ssp-dai");