blob: 69033e1a84e6ad52ef7c01b395af3a8f48a91c15 [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
Mark Brown1b340bd2008-07-30 19:12:04 +010037#include "pxa-ssp.h"
38
39/*
40 * SSP audio private data
41 */
42struct ssp_priv {
Eric Miaof9efc9d2010-02-09 19:46:01 +080043 struct ssp_device *ssp;
Daniel Mack90eb6b52018-07-02 17:11:00 +020044 struct clk *extclk;
Daniel Mack05739372018-06-29 14:59:40 +020045 unsigned long ssp_clk;
Mark Brown1b340bd2008-07-30 19:12:04 +010046 unsigned int sysclk;
Daniel Mack737e3702018-05-21 23:50:16 +020047 unsigned int dai_fmt;
48 unsigned int configured_dai_fmt;
Mark Brown1b340bd2008-07-30 19:12:04 +010049#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->addr_width = width4 ? DMA_SLAVE_BUSWIDTH_4_BYTES :
88 DMA_SLAVE_BUSWIDTH_2_BYTES;
89 dma->maxburst = 16;
90 dma->addr = ssp->phys_base + SSDR;
Eric Miao2d7e71f2009-04-23 17:05:38 +080091}
92
Mark Browndee89c42008-11-18 22:11:38 +000093static int pxa_ssp_startup(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000094 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +010095{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000096 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +080097 struct ssp_device *ssp = priv->ssp;
Daniel Mackd65a1452013-08-12 10:42:39 +020098 struct snd_dmaengine_dai_dma_data *dma;
Mark Brown1b340bd2008-07-30 19:12:04 +010099 int ret = 0;
100
101 if (!cpu_dai->active) {
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300102 clk_prepare_enable(ssp->clk);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400103 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100104 }
Eric Miao2d7e71f2009-04-23 17:05:38 +0800105
Daniel Mackd65a1452013-08-12 10:42:39 +0200106 dma = kzalloc(sizeof(struct snd_dmaengine_dai_dma_data), GFP_KERNEL);
guoyhd93ca1a2012-05-07 15:34:24 +0800107 if (!dma)
108 return -ENOMEM;
Robert Jarzmikcd31b802018-06-17 19:02:17 +0200109 dma->chan_name = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
110 "tx" : "rx";
Daniel Macka6714682013-08-12 10:42:40 +0200111
Daniel Mackd65a1452013-08-12 10:42:39 +0200112 snd_soc_dai_set_dma_data(cpu_dai, substream, dma);
Daniel Mack5f712b22010-03-22 10:11:15 +0100113
Mark Brown1b340bd2008-07-30 19:12:04 +0100114 return ret;
115}
116
Mark Browndee89c42008-11-18 22:11:38 +0000117static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000118 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100119{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000120 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800121 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100122
123 if (!cpu_dai->active) {
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400124 pxa_ssp_disable(ssp);
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300125 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100126 }
Eric Miao2d7e71f2009-04-23 17:05:38 +0800127
Daniel Mack5f712b22010-03-22 10:11:15 +0100128 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
129 snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
Mark Brown1b340bd2008-07-30 19:12:04 +0100130}
131
132#ifdef CONFIG_PM
133
Mark Browndc7d7b82008-12-03 18:21:52 +0000134static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100135{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000136 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800137 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100138
139 if (!cpu_dai->active)
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300140 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100141
Eric Miaof9efc9d2010-02-09 19:46:01 +0800142 priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0);
143 priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1);
144 priv->to = __raw_readl(ssp->mmio_base + SSTO);
145 priv->psp = __raw_readl(ssp->mmio_base + SSPSP);
146
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400147 pxa_ssp_disable(ssp);
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300148 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100149 return 0;
150}
151
Mark Browndc7d7b82008-12-03 18:21:52 +0000152static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100153{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000154 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800155 struct ssp_device *ssp = priv->ssp;
156 uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100157
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300158 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100159
Eric Miaof9efc9d2010-02-09 19:46:01 +0800160 __raw_writel(sssr, ssp->mmio_base + SSSR);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800161 __raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0);
162 __raw_writel(priv->cr1, ssp->mmio_base + SSCR1);
163 __raw_writel(priv->to, ssp->mmio_base + SSTO);
164 __raw_writel(priv->psp, ssp->mmio_base + SSPSP);
Daniel Mack026384d2010-02-02 18:45:27 +0800165
166 if (cpu_dai->active)
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400167 pxa_ssp_enable(ssp);
Daniel Mack026384d2010-02-02 18:45:27 +0800168 else
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300169 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100170
171 return 0;
172}
173
174#else
175#define pxa_ssp_suspend NULL
176#define pxa_ssp_resume NULL
177#endif
178
179/**
180 * ssp_set_clkdiv - set SSP clock divider
181 * @div: serial clock rate divider
182 */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400183static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div)
Mark Brown1b340bd2008-07-30 19:12:04 +0100184{
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400185 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100186
Qiao Zhou972a55b2012-06-04 10:41:04 +0800187 if (ssp->type == PXA25x_SSP) {
Philipp Zabel1a297282009-04-17 11:39:38 +0200188 sscr0 &= ~0x0000ff00;
189 sscr0 |= ((div - 2)/2) << 8; /* 2..512 */
190 } else {
191 sscr0 &= ~0x000fff00;
192 sscr0 |= (div - 1) << 8; /* 1..4096 */
193 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400194 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Philipp Zabel1a297282009-04-17 11:39:38 +0200195}
196
Mark Brown1b340bd2008-07-30 19:12:04 +0100197/*
198 * Set the SSP ports SYSCLK.
199 */
200static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
201 int clk_id, unsigned int freq, int dir)
202{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000203 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800204 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100205
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400206 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Daniel Mack05f38282018-05-21 23:50:17 +0200207 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100208
Daniel Mack90eb6b52018-07-02 17:11:00 +0200209 if (priv->extclk) {
210 int ret;
211
212 /*
213 * For DT based boards, if an extclk is given, use it
214 * here and configure PXA_SSP_CLK_EXT.
215 */
216
217 ret = clk_set_rate(priv->extclk, freq);
218 if (ret < 0)
219 return ret;
220
221 clk_id = PXA_SSP_CLK_EXT;
222 }
223
Mark Brown1b340bd2008-07-30 19:12:04 +0100224 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);
Daniel Mack05f38282018-05-21 23:50:17 +0200260 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Qiao Zhou972a55b2012-06-04 10:41:04 +0800261 if (ssp->type != PXA3xx_SSP)
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300262 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100263
264 return 0;
265}
266
267/*
Mark Brown1b340bd2008-07-30 19:12:04 +0100268 * Configure the PLL frequency pxa27x and (afaik - pxa320 only)
269 */
Daniel Mack05739372018-06-29 14:59:40 +0200270static int pxa_ssp_set_pll(struct ssp_priv *priv, unsigned int freq)
Mark Brown1b340bd2008-07-30 19:12:04 +0100271{
Eric Miaof9efc9d2010-02-09 19:46:01 +0800272 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400273 u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70;
Mark Brown1b340bd2008-07-30 19:12:04 +0100274
Qiao Zhou972a55b2012-06-04 10:41:04 +0800275 if (ssp->type == PXA3xx_SSP)
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400276 pxa_ssp_write_reg(ssp, SSACDD, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100277
Daniel Mack05739372018-06-29 14:59:40 +0200278 switch (freq) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100279 case 5622000:
280 break;
281 case 11345000:
282 ssacd |= (0x1 << 4);
283 break;
284 case 12235000:
285 ssacd |= (0x2 << 4);
286 break;
287 case 14857000:
288 ssacd |= (0x3 << 4);
289 break;
290 case 32842000:
291 ssacd |= (0x4 << 4);
292 break;
293 case 48000000:
294 ssacd |= (0x5 << 4);
295 break;
296 case 0:
297 /* Disable */
298 break;
299
300 default:
Mark Brown1b340bd2008-07-30 19:12:04 +0100301 /* PXA3xx has a clock ditherer which can be used to generate
302 * a wider range of frequencies - calculate a value for it.
303 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800304 if (ssp->type == PXA3xx_SSP) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100305 u32 val;
306 u64 tmp = 19968;
Codrut Grosu1dbe6922017-02-25 23:33:50 +0200307
Mark Brown1b340bd2008-07-30 19:12:04 +0100308 tmp *= 1000000;
Daniel Mack05739372018-06-29 14:59:40 +0200309 do_div(tmp, freq);
Mark Brown1b340bd2008-07-30 19:12:04 +0100310 val = tmp;
311
Joe Perchesa419aef2009-08-18 11:18:35 -0700312 val = (val << 16) | 64;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400313 pxa_ssp_write_reg(ssp, SSACDD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100314
315 ssacd |= (0x6 << 4);
316
317 dev_dbg(&ssp->pdev->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700318 "Using SSACDD %x to supply %uHz\n",
Daniel Mack05739372018-06-29 14:59:40 +0200319 val, freq);
Mark Brown1b340bd2008-07-30 19:12:04 +0100320 break;
321 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100322
323 return -EINVAL;
324 }
325
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400326 pxa_ssp_write_reg(ssp, SSACD, ssacd);
Mark Brown1b340bd2008-07-30 19:12:04 +0100327
328 return 0;
329}
330
331/*
332 * Set the active slots in TDM/Network mode
333 */
334static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300335 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
Mark Brown1b340bd2008-07-30 19:12:04 +0100336{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000337 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800338 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100339 u32 sscr0;
340
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400341 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300342 sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100343
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300344 /* set slot width */
345 if (slot_width > 16)
346 sscr0 |= SSCR0_EDSS | SSCR0_DataSize(slot_width - 16);
347 else
348 sscr0 |= SSCR0_DataSize(slot_width);
349
350 if (slots > 1) {
351 /* enable network mode */
352 sscr0 |= SSCR0_MOD;
353
354 /* set number of active slots */
355 sscr0 |= SSCR0_SlotsPerFrm(slots);
356
357 /* set active slot mask */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400358 pxa_ssp_write_reg(ssp, SSTSA, tx_mask);
359 pxa_ssp_write_reg(ssp, SSRSA, rx_mask);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300360 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400361 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100362
Mark Brown1b340bd2008-07-30 19:12:04 +0100363 return 0;
364}
365
366/*
367 * Tristate the SSP DAI lines
368 */
369static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
370 int tristate)
371{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000372 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800373 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100374 u32 sscr1;
375
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400376 sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100377 if (tristate)
378 sscr1 &= ~SSCR1_TTE;
379 else
380 sscr1 |= SSCR1_TTE;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400381 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100382
383 return 0;
384}
385
Daniel Mack737e3702018-05-21 23:50:16 +0200386static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
387 unsigned int fmt)
388{
389 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
390
391 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
392 case SND_SOC_DAIFMT_CBM_CFM:
393 case SND_SOC_DAIFMT_CBM_CFS:
394 case SND_SOC_DAIFMT_CBS_CFS:
395 break;
396 default:
397 return -EINVAL;
398 }
399
400 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
401 case SND_SOC_DAIFMT_NB_NF:
402 case SND_SOC_DAIFMT_NB_IF:
403 case SND_SOC_DAIFMT_IB_IF:
404 case SND_SOC_DAIFMT_IB_NF:
405 break;
406 default:
407 return -EINVAL;
408 }
409
410 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
411 case SND_SOC_DAIFMT_I2S:
412 case SND_SOC_DAIFMT_DSP_A:
413 case SND_SOC_DAIFMT_DSP_B:
414 break;
415
416 default:
417 return -EINVAL;
418 }
419
420 /* Settings will be applied in hw_params() */
421 priv->dai_fmt = fmt;
422
423 return 0;
424}
425
Mark Brown1b340bd2008-07-30 19:12:04 +0100426/*
427 * Set up the SSP DAI format.
428 * The SSP Port must be inactive before calling this function as the
429 * physical interface format is changed.
430 */
Daniel Mack737e3702018-05-21 23:50:16 +0200431static int pxa_ssp_configure_dai_fmt(struct ssp_priv *priv)
Mark Brown1b340bd2008-07-30 19:12:04 +0100432{
Eric Miaof9efc9d2010-02-09 19:46:01 +0800433 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800434 u32 sscr0, sscr1, sspsp, scfr;
Mark Brown1b340bd2008-07-30 19:12:04 +0100435
Daniel Mackcbf11462009-03-10 16:41:00 +0100436 /* check if we need to change anything at all */
Daniel Mack737e3702018-05-21 23:50:16 +0200437 if (priv->configured_dai_fmt == priv->dai_fmt)
Daniel Mackcbf11462009-03-10 16:41:00 +0100438 return 0;
439
Mark Brown1b340bd2008-07-30 19:12:04 +0100440 /* reset port settings */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400441 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Daniel Mack737e3702018-05-21 23:50:16 +0200442 ~(SSCR0_PSP | SSCR0_MOD);
443 sscr1 = pxa_ssp_read_reg(ssp, SSCR1) &
444 ~(SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR |
445 SSCR1_RWOT | SSCR1_TRAIL | SSCR1_TFT | SSCR1_RFT);
446 sspsp = pxa_ssp_read_reg(ssp, SSPSP) &
447 ~(SSPSP_SFRMP | SSPSP_SCMODE(3));
Mark Brown1b340bd2008-07-30 19:12:04 +0100448
Daniel Mack737e3702018-05-21 23:50:16 +0200449 sscr1 |= SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
450
451 switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100452 case SND_SOC_DAIFMT_CBM_CFM:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800453 sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100454 break;
455 case SND_SOC_DAIFMT_CBM_CFS:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800456 sscr1 |= SSCR1_SCLKDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100457 break;
458 case SND_SOC_DAIFMT_CBS_CFS:
459 break;
460 default:
461 return -EINVAL;
462 }
463
Daniel Mack737e3702018-05-21 23:50:16 +0200464 switch (priv->dai_fmt & SND_SOC_DAIFMT_INV_MASK) {
Daniel Ribeirofa44c072009-06-10 15:23:24 -0300465 case SND_SOC_DAIFMT_NB_NF:
466 sspsp |= SSPSP_SFRMP;
467 break;
468 case SND_SOC_DAIFMT_NB_IF:
469 break;
470 case SND_SOC_DAIFMT_IB_IF:
471 sspsp |= SSPSP_SCMODE(2);
472 break;
473 case SND_SOC_DAIFMT_IB_NF:
474 sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP;
475 break;
476 default:
477 return -EINVAL;
478 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100479
Daniel Mack737e3702018-05-21 23:50:16 +0200480 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100481 case SND_SOC_DAIFMT_I2S:
Daniel Mack72d74662009-03-12 11:27:49 +0100482 sscr0 |= SSCR0_PSP;
Mark Brown1b340bd2008-07-30 19:12:04 +0100483 sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
Mark Brown0ce36c52009-03-13 14:26:08 +0000484 /* See hw_params() */
Mark Brown1b340bd2008-07-30 19:12:04 +0100485 break;
486
487 case SND_SOC_DAIFMT_DSP_A:
488 sspsp |= SSPSP_FSRT;
Gustavo A. R. Silvae0431de2018-07-02 07:17:07 -0500489 /* fall through */
Mark Brown1b340bd2008-07-30 19:12:04 +0100490 case SND_SOC_DAIFMT_DSP_B:
491 sscr0 |= SSCR0_MOD | SSCR0_PSP;
492 sscr1 |= SSCR1_TRAIL | SSCR1_RWOT;
Mark Brown1b340bd2008-07-30 19:12:04 +0100493 break;
494
495 default:
496 return -EINVAL;
497 }
498
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400499 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
500 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
501 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100502
Daniel Mack737e3702018-05-21 23:50:16 +0200503 switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800504 case SND_SOC_DAIFMT_CBM_CFM:
505 case SND_SOC_DAIFMT_CBM_CFS:
506 scfr = pxa_ssp_read_reg(ssp, SSCR1) | SSCR1_SCFR;
507 pxa_ssp_write_reg(ssp, SSCR1, scfr);
508
509 while (pxa_ssp_read_reg(ssp, SSSR) & SSSR_BSY)
510 cpu_relax();
511 break;
512 }
513
Mark Brown1b340bd2008-07-30 19:12:04 +0100514 dump_registers(ssp);
515
516 /* Since we are configuring the timings for the format by hand
517 * we have to defer some things until hw_params() where we
518 * know parameters like the sample size.
519 */
Daniel Mack737e3702018-05-21 23:50:16 +0200520 priv->configured_dai_fmt = priv->dai_fmt;
Mark Brown1b340bd2008-07-30 19:12:04 +0100521
522 return 0;
523}
524
Daniel Mack05739372018-06-29 14:59:40 +0200525struct pxa_ssp_clock_mode {
526 int rate;
527 int pll;
528 u8 acds;
529 u8 scdb;
530};
531
532static const struct pxa_ssp_clock_mode pxa_ssp_clock_modes[] = {
533 { .rate = 8000, .pll = 32842000, .acds = SSACD_ACDS_32, .scdb = SSACD_SCDB_4X },
534 { .rate = 11025, .pll = 5622000, .acds = SSACD_ACDS_4, .scdb = SSACD_SCDB_4X },
535 { .rate = 16000, .pll = 32842000, .acds = SSACD_ACDS_16, .scdb = SSACD_SCDB_4X },
536 { .rate = 22050, .pll = 5622000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X },
537 { .rate = 44100, .pll = 11345000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X },
538 { .rate = 48000, .pll = 12235000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X },
539 { .rate = 96000, .pll = 12235000, .acds = SSACD_ACDS_4, .scdb = SSACD_SCDB_1X },
540 {}
541};
542
Mark Brown1b340bd2008-07-30 19:12:04 +0100543/*
544 * Set the SSP audio DMA parameters and sample size.
545 * Can be called multiple times by oss emulation.
546 */
547static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000548 struct snd_pcm_hw_params *params,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000549 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100550{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000551 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800552 struct ssp_device *ssp = priv->ssp;
Eric Miao2d7e71f2009-04-23 17:05:38 +0800553 int chn = params_channels(params);
Daniel Mack05739372018-06-29 14:59:40 +0200554 u32 sscr0, sspsp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100555 int width = snd_pcm_format_physical_width(params_format(params));
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400556 int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf;
Daniel Mackd65a1452013-08-12 10:42:39 +0200557 struct snd_dmaengine_dai_dma_data *dma_data;
Daniel Mack05739372018-06-29 14:59:40 +0200558 int rate = params_rate(params);
559 int bclk = rate * chn * (width / 8);
Daniel Mack737e3702018-05-21 23:50:16 +0200560 int ret;
Daniel Mack5f712b22010-03-22 10:11:15 +0100561
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000562 dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
Mark Brown1b340bd2008-07-30 19:12:04 +0100563
Philipp Zabel92429062009-03-19 09:32:01 +0100564 /* Network mode with one active slot (ttsa == 1) can be used
565 * to force 16-bit frame width on the wire (for S16_LE), even
566 * with two channels. Use 16-bit DMA transfers for this case.
567 */
guoyhd93ca1a2012-05-07 15:34:24 +0800568 pxa_ssp_set_dma_params(ssp,
569 ((chn == 2) && (ttsa != 1)) || (width == 32),
570 substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data);
Daniel Mack5f712b22010-03-22 10:11:15 +0100571
Mark Brown1b340bd2008-07-30 19:12:04 +0100572 /* we can only change the settings if the port is not in use */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400573 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
Mark Brown1b340bd2008-07-30 19:12:04 +0100574 return 0;
575
Daniel Mack737e3702018-05-21 23:50:16 +0200576 ret = pxa_ssp_configure_dai_fmt(priv);
577 if (ret < 0)
578 return ret;
579
Mark Brown1b340bd2008-07-30 19:12:04 +0100580 /* clear selected SSP bits */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400581 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100582
583 /* bit size */
Mark Brown1b340bd2008-07-30 19:12:04 +0100584 switch (params_format(params)) {
585 case SNDRV_PCM_FORMAT_S16_LE:
Qiao Zhou972a55b2012-06-04 10:41:04 +0800586 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100587 sscr0 |= SSCR0_FPCKE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100588 sscr0 |= SSCR0_DataSize(16);
Mark Brown1b340bd2008-07-30 19:12:04 +0100589 break;
590 case SNDRV_PCM_FORMAT_S24_LE:
591 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
Mark Brown1b340bd2008-07-30 19:12:04 +0100592 break;
593 case SNDRV_PCM_FORMAT_S32_LE:
594 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
Mark Brown1b340bd2008-07-30 19:12:04 +0100595 break;
596 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400597 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100598
Daniel Mack05739372018-06-29 14:59:40 +0200599 if (sscr0 & SSCR0_ACS) {
600 ret = pxa_ssp_set_pll(priv, bclk);
601
602 /*
603 * If we were able to generate the bclk directly,
604 * all is fine. Otherwise, look up the closest rate
605 * from the table and also set the dividers.
606 */
607
608 if (ret < 0) {
609 const struct pxa_ssp_clock_mode *m;
610 int ssacd, acds;
611
612 for (m = pxa_ssp_clock_modes; m->rate; m++) {
613 if (m->rate == rate)
614 break;
615 }
616
617 if (!m->rate)
618 return -EINVAL;
619
620 acds = m->acds;
621
622 /* The values in the table are for 16 bits */
623 if (width == 32)
624 acds--;
625
626 ret = pxa_ssp_set_pll(priv, bclk);
627 if (ret < 0)
628 return ret;
629
630 ssacd = pxa_ssp_read_reg(ssp, SSACD);
631 ssacd &= ~(SSACD_ACDS(7) | SSACD_SCDB_1X);
632 ssacd |= SSACD_ACDS(m->acds);
633 ssacd |= m->scdb;
634 pxa_ssp_write_reg(ssp, SSACD, ssacd);
635 }
636 } else if (sscr0 & SSCR0_ECS) {
637 /*
638 * For setups with external clocking, the PLL and its diviers
639 * are not active. Instead, the SCR bits in SSCR0 can be used
640 * to divide the clock.
641 */
642 pxa_ssp_set_scr(ssp, bclk / rate);
643 }
644
Mark Brown1b340bd2008-07-30 19:12:04 +0100645 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
646 case SND_SOC_DAIFMT_I2S:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400647 sspsp = pxa_ssp_read_reg(ssp, SSPSP);
Daniel Mack72d74662009-03-12 11:27:49 +0100648
Daniel Mack05739372018-06-29 14:59:40 +0200649 if (((priv->sysclk / bclk) == 64) && (width == 16)) {
Daniel Mack72d74662009-03-12 11:27:49 +0100650 /* This is a special case where the bitclk is 64fs
Codrut Grosu34e82432017-02-25 23:40:31 +0200651 * and we're not dealing with 2*32 bits of audio
652 * samples.
653 *
654 * The SSP values used for that are all found out by
655 * trying and failing a lot; some of the registers
656 * needed for that mode are only available on PXA3xx.
657 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800658 if (ssp->type != PXA3xx_SSP)
Daniel Mack72d74662009-03-12 11:27:49 +0100659 return -EINVAL;
660
661 sspsp |= SSPSP_SFRMWDTH(width * 2);
662 sspsp |= SSPSP_SFRMDLY(width * 4);
663 sspsp |= SSPSP_EDMYSTOP(3);
664 sspsp |= SSPSP_DMYSTOP(3);
665 sspsp |= SSPSP_DMYSTRT(1);
Mark Brown0ce36c52009-03-13 14:26:08 +0000666 } else {
667 /* The frame width is the width the LRCLK is
668 * asserted for; the delay is expressed in
669 * half cycle units. We need the extra cycle
670 * because the data starts clocking out one BCLK
671 * after LRCLK changes polarity.
672 */
673 sspsp |= SSPSP_SFRMWDTH(width + 1);
674 sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
675 sspsp |= SSPSP_DMYSTRT(1);
676 }
Daniel Mack72d74662009-03-12 11:27:49 +0100677
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400678 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100679 break;
680 default:
681 break;
682 }
683
Daniel Mack72d74662009-03-12 11:27:49 +0100684 /* When we use a network mode, we always require TDM slots
Mark Brown1b340bd2008-07-30 19:12:04 +0100685 * - complain loudly and fail if they've not been set up yet.
686 */
Philipp Zabel92429062009-03-19 09:32:01 +0100687 if ((sscr0 & SSCR0_MOD) && !ttsa) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100688 dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
689 return -EINVAL;
690 }
691
692 dump_registers(ssp);
693
694 return 0;
695}
696
Daniel Mack273b72c2012-03-19 09:12:53 +0100697static void pxa_ssp_set_running_bit(struct snd_pcm_substream *substream,
698 struct ssp_device *ssp, int value)
699{
700 uint32_t sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
701 uint32_t sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
702 uint32_t sspsp = pxa_ssp_read_reg(ssp, SSPSP);
703 uint32_t sssr = pxa_ssp_read_reg(ssp, SSSR);
704
705 if (value && (sscr0 & SSCR0_SSE))
706 pxa_ssp_write_reg(ssp, SSCR0, sscr0 & ~SSCR0_SSE);
707
708 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
709 if (value)
710 sscr1 |= SSCR1_TSRE;
711 else
712 sscr1 &= ~SSCR1_TSRE;
713 } else {
714 if (value)
715 sscr1 |= SSCR1_RSRE;
716 else
717 sscr1 &= ~SSCR1_RSRE;
718 }
719
720 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
721
722 if (value) {
723 pxa_ssp_write_reg(ssp, SSSR, sssr);
724 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
725 pxa_ssp_write_reg(ssp, SSCR0, sscr0 | SSCR0_SSE);
726 }
727}
728
Mark Browndee89c42008-11-18 22:11:38 +0000729static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000730 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100731{
Mark Brown1b340bd2008-07-30 19:12:04 +0100732 int ret = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000733 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800734 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100735 int val;
736
737 switch (cmd) {
738 case SNDRV_PCM_TRIGGER_RESUME:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400739 pxa_ssp_enable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100740 break;
741 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Daniel Mack273b72c2012-03-19 09:12:53 +0100742 pxa_ssp_set_running_bit(substream, ssp, 1);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400743 val = pxa_ssp_read_reg(ssp, SSSR);
744 pxa_ssp_write_reg(ssp, SSSR, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100745 break;
746 case SNDRV_PCM_TRIGGER_START:
Daniel Mack273b72c2012-03-19 09:12:53 +0100747 pxa_ssp_set_running_bit(substream, ssp, 1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100748 break;
749 case SNDRV_PCM_TRIGGER_STOP:
Daniel Mack273b72c2012-03-19 09:12:53 +0100750 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100751 break;
752 case SNDRV_PCM_TRIGGER_SUSPEND:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400753 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100754 break;
755 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Daniel Mack273b72c2012-03-19 09:12:53 +0100756 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100757 break;
758
759 default:
760 ret = -EINVAL;
761 }
762
763 dump_registers(ssp);
764
765 return ret;
766}
767
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000768static int pxa_ssp_probe(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100769{
Daniel Mack2023c902013-08-12 10:42:38 +0200770 struct device *dev = dai->dev;
Mark Brown1b340bd2008-07-30 19:12:04 +0100771 struct ssp_priv *priv;
772 int ret;
773
774 priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL);
775 if (!priv)
776 return -ENOMEM;
777
Daniel Mack2023c902013-08-12 10:42:38 +0200778 if (dev->of_node) {
779 struct device_node *ssp_handle;
780
781 ssp_handle = of_parse_phandle(dev->of_node, "port", 0);
782 if (!ssp_handle) {
783 dev_err(dev, "unable to get 'port' phandle\n");
Dan Carpenter45487282014-07-31 15:57:51 +0300784 ret = -ENODEV;
785 goto err_priv;
Daniel Mack2023c902013-08-12 10:42:38 +0200786 }
787
788 priv->ssp = pxa_ssp_request_of(ssp_handle, "SoC audio");
789 if (priv->ssp == NULL) {
790 ret = -ENODEV;
791 goto err_priv;
792 }
Daniel Mack90eb6b52018-07-02 17:11:00 +0200793
794 priv->extclk = devm_clk_get(dev, "extclk");
795 if (IS_ERR(priv->extclk)) {
796 ret = PTR_ERR(priv->extclk);
797 if (ret == -EPROBE_DEFER)
798 return ret;
799
800 priv->extclk = NULL;
801 }
Daniel Mack2023c902013-08-12 10:42:38 +0200802 } else {
803 priv->ssp = pxa_ssp_request(dai->id + 1, "SoC audio");
804 if (priv->ssp == NULL) {
805 ret = -ENODEV;
806 goto err_priv;
807 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100808 }
809
Daniel Macka5735b72009-04-15 20:24:45 +0200810 priv->dai_fmt = (unsigned int) -1;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000811 snd_soc_dai_set_drvdata(dai, priv);
Mark Brown1b340bd2008-07-30 19:12:04 +0100812
813 return 0;
814
815err_priv:
816 kfree(priv);
817 return ret;
818}
819
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000820static int pxa_ssp_remove(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100821{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000822 struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai);
823
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400824 pxa_ssp_free(priv->ssp);
Axel Lin014a2752010-08-25 16:59:11 +0800825 kfree(priv);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000826 return 0;
Mark Brown1b340bd2008-07-30 19:12:04 +0100827}
828
829#define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
830 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
Qiao Zhou8d8bf582012-03-08 10:02:36 +0800831 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
832 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
Mark Brown1b340bd2008-07-30 19:12:04 +0100833 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
834
Daniel Mack93015032014-08-13 21:51:06 +0200835#define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown1b340bd2008-07-30 19:12:04 +0100836
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100837static const struct snd_soc_dai_ops pxa_ssp_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800838 .startup = pxa_ssp_startup,
839 .shutdown = pxa_ssp_shutdown,
840 .trigger = pxa_ssp_trigger,
841 .hw_params = pxa_ssp_hw_params,
842 .set_sysclk = pxa_ssp_set_dai_sysclk,
Eric Miao6335d052009-03-03 09:41:00 +0800843 .set_fmt = pxa_ssp_set_dai_fmt,
844 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
845 .set_tristate = pxa_ssp_set_dai_tristate,
846};
847
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000848static struct snd_soc_dai_driver pxa_ssp_dai = {
Mark Brown1b340bd2008-07-30 19:12:04 +0100849 .probe = pxa_ssp_probe,
850 .remove = pxa_ssp_remove,
851 .suspend = pxa_ssp_suspend,
852 .resume = pxa_ssp_resume,
853 .playback = {
854 .channels_min = 1,
Graeme Gregoryf34762b2009-09-25 13:30:26 +0100855 .channels_max = 8,
Mark Brown1b340bd2008-07-30 19:12:04 +0100856 .rates = PXA_SSP_RATES,
857 .formats = PXA_SSP_FORMATS,
858 },
859 .capture = {
860 .channels_min = 1,
Graeme Gregoryf34762b2009-09-25 13:30:26 +0100861 .channels_max = 8,
Mark Brown1b340bd2008-07-30 19:12:04 +0100862 .rates = PXA_SSP_RATES,
863 .formats = PXA_SSP_FORMATS,
864 },
Eric Miao6335d052009-03-03 09:41:00 +0800865 .ops = &pxa_ssp_dai_ops,
Mark Brown1b340bd2008-07-30 19:12:04 +0100866};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000867
Kuninori Morimotoe580f1c2013-03-21 03:34:12 -0700868static const struct snd_soc_component_driver pxa_ssp_component = {
869 .name = "pxa-ssp",
Daniel Mackd767d3c2018-06-27 21:33:57 +0200870 .ops = &pxa2xx_pcm_ops,
871 .pcm_new = pxa2xx_soc_pcm_new,
872 .pcm_free = pxa2xx_pcm_free_dma_buffers,
Kuninori Morimotoe580f1c2013-03-21 03:34:12 -0700873};
874
Daniel Mack2023c902013-08-12 10:42:38 +0200875#ifdef CONFIG_OF
876static const struct of_device_id pxa_ssp_of_ids[] = {
877 { .compatible = "mrvl,pxa-ssp-dai" },
Stephen Boyd4c715c72014-05-23 17:16:49 -0700878 {}
Daniel Mack2023c902013-08-12 10:42:38 +0200879};
Luis de Bethencourtbaafd372015-09-03 13:00:03 +0200880MODULE_DEVICE_TABLE(of, pxa_ssp_of_ids);
Daniel Mack2023c902013-08-12 10:42:38 +0200881#endif
882
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500883static int asoc_ssp_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000884{
Axel Lin637ce532015-08-28 10:48:35 +0800885 return devm_snd_soc_register_component(&pdev->dev, &pxa_ssp_component,
886 &pxa_ssp_dai, 1);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000887}
888
889static struct platform_driver asoc_ssp_driver = {
890 .driver = {
Daniel Mack2023c902013-08-12 10:42:38 +0200891 .name = "pxa-ssp-dai",
Daniel Mack2023c902013-08-12 10:42:38 +0200892 .of_match_table = of_match_ptr(pxa_ssp_of_ids),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000893 },
894
895 .probe = asoc_ssp_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000896};
Mark Brown1b340bd2008-07-30 19:12:04 +0100897
Axel Lin2f702a12011-11-25 10:13:37 +0800898module_platform_driver(asoc_ssp_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000899
Mark Brown1b340bd2008-07-30 19:12:04 +0100900/* Module information */
901MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
902MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface");
903MODULE_LICENSE("GPL");
Andrea Adamie5b7d712016-05-06 17:27:34 +0200904MODULE_ALIAS("platform:pxa-ssp-dai");