blob: 7f13a35e9cc145342855c4286cf1059edfaa58a1 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Mark Brown1b340bd2008-07-30 19:12:04 +01002/*
3 * pxa-ssp.c -- ALSA Soc Audio Layer
4 *
5 * Copyright 2005,2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * Mark Brown <broonie@opensource.wolfsonmicro.com>
8 *
Mark Brown1b340bd2008-07-30 19:12:04 +01009 * TODO:
10 * o Test network mode for > 16bit sample size
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Mark Brown1b340bd2008-07-30 19:12:04 +010016#include <linux/platform_device.h>
17#include <linux/clk.h>
18#include <linux/io.h>
Sebastian Andrzej Siewior8348c252010-11-22 17:12:15 -080019#include <linux/pxa2xx_ssp.h>
Daniel Mack2023c902013-08-12 10:42:38 +020020#include <linux/of.h>
Daniel Mackd65a1452013-08-12 10:42:39 +020021#include <linux/dmaengine.h>
Mark Brown1b340bd2008-07-30 19:12:04 +010022
Philipp Zabel06646782009-02-03 21:18:26 +010023#include <asm/irq.h>
24
Mark Brown1b340bd2008-07-30 19:12:04 +010025#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/initval.h>
28#include <sound/pcm_params.h>
29#include <sound/soc.h>
30#include <sound/pxa2xx-lib.h>
Daniel Mackd65a1452013-08-12 10:42:39 +020031#include <sound/dmaengine_pcm.h>
Mark Brown1b340bd2008-07-30 19:12:04 +010032
Mark Brown1b340bd2008-07-30 19:12:04 +010033#include "pxa-ssp.h"
34
35/*
36 * SSP audio private data
37 */
38struct ssp_priv {
Eric Miaof9efc9d2010-02-09 19:46:01 +080039 struct ssp_device *ssp;
Daniel Mack90eb6b52018-07-02 17:11:00 +020040 struct clk *extclk;
Daniel Mack05739372018-06-29 14:59:40 +020041 unsigned long ssp_clk;
Mark Brown1b340bd2008-07-30 19:12:04 +010042 unsigned int sysclk;
Daniel Mack737e3702018-05-21 23:50:16 +020043 unsigned int dai_fmt;
44 unsigned int configured_dai_fmt;
Mark Brown1b340bd2008-07-30 19:12:04 +010045#ifdef CONFIG_PM
Eric Miaof9efc9d2010-02-09 19:46:01 +080046 uint32_t cr0;
47 uint32_t cr1;
48 uint32_t to;
49 uint32_t psp;
Mark Brown1b340bd2008-07-30 19:12:04 +010050#endif
51};
52
Mark Brown1b340bd2008-07-30 19:12:04 +010053static void dump_registers(struct ssp_device *ssp)
54{
Andy Shevchenko4f3d9572019-10-18 13:54:25 +030055 dev_dbg(ssp->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
Haojian Zhuangbaffe162010-05-05 10:11:15 -040056 pxa_ssp_read_reg(ssp, SSCR0), pxa_ssp_read_reg(ssp, SSCR1),
57 pxa_ssp_read_reg(ssp, SSTO));
Mark Brown1b340bd2008-07-30 19:12:04 +010058
Andy Shevchenko4f3d9572019-10-18 13:54:25 +030059 dev_dbg(ssp->dev, "SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n",
Haojian Zhuangbaffe162010-05-05 10:11:15 -040060 pxa_ssp_read_reg(ssp, SSPSP), pxa_ssp_read_reg(ssp, SSSR),
61 pxa_ssp_read_reg(ssp, SSACD));
Mark Brown1b340bd2008-07-30 19:12:04 +010062}
63
guoyhd93ca1a2012-05-07 15:34:24 +080064static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,
Daniel Mackd65a1452013-08-12 10:42:39 +020065 int out, struct snd_dmaengine_dai_dma_data *dma)
Eric Miao2d7e71f2009-04-23 17:05:38 +080066{
Daniel Mackd65a1452013-08-12 10:42:39 +020067 dma->addr_width = width4 ? DMA_SLAVE_BUSWIDTH_4_BYTES :
68 DMA_SLAVE_BUSWIDTH_2_BYTES;
69 dma->maxburst = 16;
70 dma->addr = ssp->phys_base + SSDR;
Eric Miao2d7e71f2009-04-23 17:05:38 +080071}
72
Mark Browndee89c42008-11-18 22:11:38 +000073static int pxa_ssp_startup(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000074 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +010075{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000076 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +080077 struct ssp_device *ssp = priv->ssp;
Daniel Mackd65a1452013-08-12 10:42:39 +020078 struct snd_dmaengine_dai_dma_data *dma;
Mark Brown1b340bd2008-07-30 19:12:04 +010079 int ret = 0;
80
Kuninori Morimotoaaeb5fb2020-05-15 09:47:41 +090081 if (!snd_soc_dai_active(cpu_dai)) {
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +030082 clk_prepare_enable(ssp->clk);
Haojian Zhuangbaffe162010-05-05 10:11:15 -040083 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +010084 }
Eric Miao2d7e71f2009-04-23 17:05:38 +080085
Xu Wangb8f94952020-10-29 09:01:04 +000086 clk_prepare_enable(priv->extclk);
Daniel Mackcfe9ee52018-10-03 21:36:27 +020087
Daniel Mackd65a1452013-08-12 10:42:39 +020088 dma = kzalloc(sizeof(struct snd_dmaengine_dai_dma_data), GFP_KERNEL);
guoyhd93ca1a2012-05-07 15:34:24 +080089 if (!dma)
90 return -ENOMEM;
Robert Jarzmikcd31b802018-06-17 19:02:17 +020091 dma->chan_name = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
92 "tx" : "rx";
Daniel Macka6714682013-08-12 10:42:40 +020093
Daniel Mackd65a1452013-08-12 10:42:39 +020094 snd_soc_dai_set_dma_data(cpu_dai, substream, dma);
Daniel Mack5f712b22010-03-22 10:11:15 +010095
Mark Brown1b340bd2008-07-30 19:12:04 +010096 return ret;
97}
98
Mark Browndee89c42008-11-18 22:11:38 +000099static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000100 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100101{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000102 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800103 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100104
Kuninori Morimotoaaeb5fb2020-05-15 09:47:41 +0900105 if (!snd_soc_dai_active(cpu_dai)) {
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400106 pxa_ssp_disable(ssp);
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300107 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100108 }
Eric Miao2d7e71f2009-04-23 17:05:38 +0800109
Xu Wangb8f94952020-10-29 09:01:04 +0000110 clk_disable_unprepare(priv->extclk);
Daniel Mackcfe9ee52018-10-03 21:36:27 +0200111
Daniel Mack5f712b22010-03-22 10:11:15 +0100112 kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
113 snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
Mark Brown1b340bd2008-07-30 19:12:04 +0100114}
115
116#ifdef CONFIG_PM
117
Kuninori Morimoto2c55f0b2020-01-20 10:04:52 +0900118static int pxa_ssp_suspend(struct snd_soc_component *component)
Mark Brown1b340bd2008-07-30 19:12:04 +0100119{
Kuninori Morimoto2c55f0b2020-01-20 10:04:52 +0900120 struct ssp_priv *priv = snd_soc_component_get_drvdata(component);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800121 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100122
Kuninori Morimotoaaeb5fb2020-05-15 09:47:41 +0900123 if (!snd_soc_component_active(component))
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300124 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100125
Eric Miaof9efc9d2010-02-09 19:46:01 +0800126 priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0);
127 priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1);
128 priv->to = __raw_readl(ssp->mmio_base + SSTO);
129 priv->psp = __raw_readl(ssp->mmio_base + SSPSP);
130
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400131 pxa_ssp_disable(ssp);
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300132 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100133 return 0;
134}
135
Kuninori Morimoto2c55f0b2020-01-20 10:04:52 +0900136static int pxa_ssp_resume(struct snd_soc_component *component)
Mark Brown1b340bd2008-07-30 19:12:04 +0100137{
Kuninori Morimoto2c55f0b2020-01-20 10:04:52 +0900138 struct ssp_priv *priv = snd_soc_component_get_drvdata(component);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800139 struct ssp_device *ssp = priv->ssp;
140 uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100141
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300142 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100143
Eric Miaof9efc9d2010-02-09 19:46:01 +0800144 __raw_writel(sssr, ssp->mmio_base + SSSR);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800145 __raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0);
146 __raw_writel(priv->cr1, ssp->mmio_base + SSCR1);
147 __raw_writel(priv->to, ssp->mmio_base + SSTO);
148 __raw_writel(priv->psp, ssp->mmio_base + SSPSP);
Daniel Mack026384d2010-02-02 18:45:27 +0800149
Kuninori Morimotoaaeb5fb2020-05-15 09:47:41 +0900150 if (snd_soc_component_active(component))
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400151 pxa_ssp_enable(ssp);
Daniel Mack026384d2010-02-02 18:45:27 +0800152 else
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300153 clk_disable_unprepare(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100154
155 return 0;
156}
157
158#else
159#define pxa_ssp_suspend NULL
160#define pxa_ssp_resume NULL
161#endif
162
Lee Jones701f4722020-07-09 11:23:22 -0500163/*
Mark Brown1b340bd2008-07-30 19:12:04 +0100164 * ssp_set_clkdiv - set SSP clock divider
165 * @div: serial clock rate divider
166 */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400167static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div)
Mark Brown1b340bd2008-07-30 19:12:04 +0100168{
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400169 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100170
Qiao Zhou972a55b2012-06-04 10:41:04 +0800171 if (ssp->type == PXA25x_SSP) {
Philipp Zabel1a297282009-04-17 11:39:38 +0200172 sscr0 &= ~0x0000ff00;
173 sscr0 |= ((div - 2)/2) << 8; /* 2..512 */
174 } else {
175 sscr0 &= ~0x000fff00;
176 sscr0 |= (div - 1) << 8; /* 1..4096 */
177 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400178 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Philipp Zabel1a297282009-04-17 11:39:38 +0200179}
180
Mark Brown1b340bd2008-07-30 19:12:04 +0100181/*
182 * Set the SSP ports SYSCLK.
183 */
184static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
185 int clk_id, unsigned int freq, int dir)
186{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000187 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800188 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100189
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400190 u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Daniel Mack05f38282018-05-21 23:50:17 +0200191 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100192
Daniel Mack90eb6b52018-07-02 17:11:00 +0200193 if (priv->extclk) {
194 int ret;
195
196 /*
197 * For DT based boards, if an extclk is given, use it
198 * here and configure PXA_SSP_CLK_EXT.
199 */
200
201 ret = clk_set_rate(priv->extclk, freq);
202 if (ret < 0)
203 return ret;
204
205 clk_id = PXA_SSP_CLK_EXT;
206 }
207
Andy Shevchenko4f3d9572019-10-18 13:54:25 +0300208 dev_dbg(ssp->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700209 "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %u\n",
Mark Brown1b340bd2008-07-30 19:12:04 +0100210 cpu_dai->id, clk_id, freq);
211
212 switch (clk_id) {
213 case PXA_SSP_CLK_NET_PLL:
214 sscr0 |= SSCR0_MOD;
215 break;
216 case PXA_SSP_CLK_PLL:
217 /* Internal PLL is fixed */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800218 if (ssp->type == PXA25x_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100219 priv->sysclk = 1843200;
220 else
221 priv->sysclk = 13000000;
222 break;
223 case PXA_SSP_CLK_EXT:
224 priv->sysclk = freq;
225 sscr0 |= SSCR0_ECS;
226 break;
227 case PXA_SSP_CLK_NET:
228 priv->sysclk = freq;
229 sscr0 |= SSCR0_NCS | SSCR0_MOD;
230 break;
231 case PXA_SSP_CLK_AUDIO:
232 priv->sysclk = 0;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400233 pxa_ssp_set_scr(ssp, 1);
Daniel Mack20a41ea2009-03-04 21:16:57 +0100234 sscr0 |= SSCR0_ACS;
Mark Brown1b340bd2008-07-30 19:12:04 +0100235 break;
236 default:
237 return -ENODEV;
238 }
239
240 /* The SSP clock must be disabled when changing SSP clock mode
241 * on PXA2xx. On PXA3xx it must be enabled when doing so. */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800242 if (ssp->type != PXA3xx_SSP)
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300243 clk_disable_unprepare(ssp->clk);
Daniel Mack05f38282018-05-21 23:50:17 +0200244 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Qiao Zhou972a55b2012-06-04 10:41:04 +0800245 if (ssp->type != PXA3xx_SSP)
Dmitry Eremin-Solenikov6d3efa42014-11-15 22:51:46 +0300246 clk_prepare_enable(ssp->clk);
Mark Brown1b340bd2008-07-30 19:12:04 +0100247
248 return 0;
249}
250
251/*
Mark Brown1b340bd2008-07-30 19:12:04 +0100252 * Configure the PLL frequency pxa27x and (afaik - pxa320 only)
253 */
Daniel Mack05739372018-06-29 14:59:40 +0200254static int pxa_ssp_set_pll(struct ssp_priv *priv, unsigned int freq)
Mark Brown1b340bd2008-07-30 19:12:04 +0100255{
Eric Miaof9efc9d2010-02-09 19:46:01 +0800256 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400257 u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70;
Mark Brown1b340bd2008-07-30 19:12:04 +0100258
Qiao Zhou972a55b2012-06-04 10:41:04 +0800259 if (ssp->type == PXA3xx_SSP)
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400260 pxa_ssp_write_reg(ssp, SSACDD, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100261
Daniel Mack05739372018-06-29 14:59:40 +0200262 switch (freq) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100263 case 5622000:
264 break;
265 case 11345000:
266 ssacd |= (0x1 << 4);
267 break;
268 case 12235000:
269 ssacd |= (0x2 << 4);
270 break;
271 case 14857000:
272 ssacd |= (0x3 << 4);
273 break;
274 case 32842000:
275 ssacd |= (0x4 << 4);
276 break;
277 case 48000000:
278 ssacd |= (0x5 << 4);
279 break;
280 case 0:
281 /* Disable */
282 break;
283
284 default:
Mark Brown1b340bd2008-07-30 19:12:04 +0100285 /* PXA3xx has a clock ditherer which can be used to generate
286 * a wider range of frequencies - calculate a value for it.
287 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800288 if (ssp->type == PXA3xx_SSP) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100289 u32 val;
290 u64 tmp = 19968;
Codrut Grosu1dbe6922017-02-25 23:33:50 +0200291
Mark Brown1b340bd2008-07-30 19:12:04 +0100292 tmp *= 1000000;
Daniel Mack05739372018-06-29 14:59:40 +0200293 do_div(tmp, freq);
Mark Brown1b340bd2008-07-30 19:12:04 +0100294 val = tmp;
295
Joe Perchesa419aef2009-08-18 11:18:35 -0700296 val = (val << 16) | 64;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400297 pxa_ssp_write_reg(ssp, SSACDD, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100298
299 ssacd |= (0x6 << 4);
300
Andy Shevchenko4f3d9572019-10-18 13:54:25 +0300301 dev_dbg(ssp->dev,
Roel Kluin449bd542009-05-27 17:08:39 -0700302 "Using SSACDD %x to supply %uHz\n",
Daniel Mack05739372018-06-29 14:59:40 +0200303 val, freq);
Mark Brown1b340bd2008-07-30 19:12:04 +0100304 break;
305 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100306
307 return -EINVAL;
308 }
309
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400310 pxa_ssp_write_reg(ssp, SSACD, ssacd);
Mark Brown1b340bd2008-07-30 19:12:04 +0100311
312 return 0;
313}
314
315/*
316 * Set the active slots in TDM/Network mode
317 */
318static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300319 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
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;
Mark Brown1b340bd2008-07-30 19:12:04 +0100323 u32 sscr0;
324
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400325 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300326 sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100327
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300328 /* set slot width */
329 if (slot_width > 16)
330 sscr0 |= SSCR0_EDSS | SSCR0_DataSize(slot_width - 16);
331 else
332 sscr0 |= SSCR0_DataSize(slot_width);
333
334 if (slots > 1) {
335 /* enable network mode */
336 sscr0 |= SSCR0_MOD;
337
338 /* set number of active slots */
339 sscr0 |= SSCR0_SlotsPerFrm(slots);
340
341 /* set active slot mask */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400342 pxa_ssp_write_reg(ssp, SSTSA, tx_mask);
343 pxa_ssp_write_reg(ssp, SSRSA, rx_mask);
Daniel Ribeiroa5479e32009-06-15 21:44:31 -0300344 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400345 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100346
Mark Brown1b340bd2008-07-30 19:12:04 +0100347 return 0;
348}
349
350/*
351 * Tristate the SSP DAI lines
352 */
353static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
354 int tristate)
355{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000356 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800357 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100358 u32 sscr1;
359
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400360 sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100361 if (tristate)
362 sscr1 &= ~SSCR1_TTE;
363 else
364 sscr1 |= SSCR1_TTE;
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400365 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100366
367 return 0;
368}
369
Daniel Mack737e3702018-05-21 23:50:16 +0200370static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
371 unsigned int fmt)
372{
373 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
374
375 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
376 case SND_SOC_DAIFMT_CBM_CFM:
377 case SND_SOC_DAIFMT_CBM_CFS:
378 case SND_SOC_DAIFMT_CBS_CFS:
379 break;
380 default:
381 return -EINVAL;
382 }
383
384 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
385 case SND_SOC_DAIFMT_NB_NF:
386 case SND_SOC_DAIFMT_NB_IF:
387 case SND_SOC_DAIFMT_IB_IF:
388 case SND_SOC_DAIFMT_IB_NF:
389 break;
390 default:
391 return -EINVAL;
392 }
393
394 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
395 case SND_SOC_DAIFMT_I2S:
396 case SND_SOC_DAIFMT_DSP_A:
397 case SND_SOC_DAIFMT_DSP_B:
398 break;
399
400 default:
401 return -EINVAL;
402 }
403
404 /* Settings will be applied in hw_params() */
405 priv->dai_fmt = fmt;
406
407 return 0;
408}
409
Mark Brown1b340bd2008-07-30 19:12:04 +0100410/*
411 * Set up the SSP DAI format.
412 * The SSP Port must be inactive before calling this function as the
413 * physical interface format is changed.
414 */
Daniel Mack737e3702018-05-21 23:50:16 +0200415static int pxa_ssp_configure_dai_fmt(struct ssp_priv *priv)
Mark Brown1b340bd2008-07-30 19:12:04 +0100416{
Eric Miaof9efc9d2010-02-09 19:46:01 +0800417 struct ssp_device *ssp = priv->ssp;
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800418 u32 sscr0, sscr1, sspsp, scfr;
Mark Brown1b340bd2008-07-30 19:12:04 +0100419
Daniel Mackcbf11462009-03-10 16:41:00 +0100420 /* check if we need to change anything at all */
Daniel Mack737e3702018-05-21 23:50:16 +0200421 if (priv->configured_dai_fmt == priv->dai_fmt)
Daniel Mackcbf11462009-03-10 16:41:00 +0100422 return 0;
423
Mark Brown1b340bd2008-07-30 19:12:04 +0100424 /* reset port settings */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400425 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
Daniel Mack737e3702018-05-21 23:50:16 +0200426 ~(SSCR0_PSP | SSCR0_MOD);
427 sscr1 = pxa_ssp_read_reg(ssp, SSCR1) &
428 ~(SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR |
429 SSCR1_RWOT | SSCR1_TRAIL | SSCR1_TFT | SSCR1_RFT);
430 sspsp = pxa_ssp_read_reg(ssp, SSPSP) &
431 ~(SSPSP_SFRMP | SSPSP_SCMODE(3));
Mark Brown1b340bd2008-07-30 19:12:04 +0100432
Daniel Mack737e3702018-05-21 23:50:16 +0200433 sscr1 |= SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
434
435 switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100436 case SND_SOC_DAIFMT_CBM_CFM:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800437 sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100438 break;
439 case SND_SOC_DAIFMT_CBM_CFS:
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800440 sscr1 |= SSCR1_SCLKDIR | SSCR1_SCFR;
Mark Brown1b340bd2008-07-30 19:12:04 +0100441 break;
442 case SND_SOC_DAIFMT_CBS_CFS:
443 break;
444 default:
445 return -EINVAL;
446 }
447
Daniel Mack737e3702018-05-21 23:50:16 +0200448 switch (priv->dai_fmt & SND_SOC_DAIFMT_INV_MASK) {
Daniel Ribeirofa44c072009-06-10 15:23:24 -0300449 case SND_SOC_DAIFMT_NB_NF:
450 sspsp |= SSPSP_SFRMP;
451 break;
452 case SND_SOC_DAIFMT_NB_IF:
453 break;
454 case SND_SOC_DAIFMT_IB_IF:
455 sspsp |= SSPSP_SCMODE(2);
456 break;
457 case SND_SOC_DAIFMT_IB_NF:
458 sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP;
459 break;
460 default:
461 return -EINVAL;
462 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100463
Daniel Mack737e3702018-05-21 23:50:16 +0200464 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
Mark Brown1b340bd2008-07-30 19:12:04 +0100465 case SND_SOC_DAIFMT_I2S:
Daniel Mack72d74662009-03-12 11:27:49 +0100466 sscr0 |= SSCR0_PSP;
Mark Brown1b340bd2008-07-30 19:12:04 +0100467 sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
Mark Brown0ce36c52009-03-13 14:26:08 +0000468 /* See hw_params() */
Mark Brown1b340bd2008-07-30 19:12:04 +0100469 break;
470
471 case SND_SOC_DAIFMT_DSP_A:
472 sspsp |= SSPSP_FSRT;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500473 fallthrough;
Mark Brown1b340bd2008-07-30 19:12:04 +0100474 case SND_SOC_DAIFMT_DSP_B:
475 sscr0 |= SSCR0_MOD | SSCR0_PSP;
476 sscr1 |= SSCR1_TRAIL | SSCR1_RWOT;
Mark Brown1b340bd2008-07-30 19:12:04 +0100477 break;
478
479 default:
480 return -EINVAL;
481 }
482
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400483 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
484 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
485 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100486
Daniel Mack737e3702018-05-21 23:50:16 +0200487 switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
Haojian Zhuangf5d1e5e2010-08-13 21:55:35 +0800488 case SND_SOC_DAIFMT_CBM_CFM:
489 case SND_SOC_DAIFMT_CBM_CFS:
490 scfr = pxa_ssp_read_reg(ssp, SSCR1) | SSCR1_SCFR;
491 pxa_ssp_write_reg(ssp, SSCR1, scfr);
492
493 while (pxa_ssp_read_reg(ssp, SSSR) & SSSR_BSY)
494 cpu_relax();
495 break;
496 }
497
Mark Brown1b340bd2008-07-30 19:12:04 +0100498 dump_registers(ssp);
499
500 /* Since we are configuring the timings for the format by hand
501 * we have to defer some things until hw_params() where we
502 * know parameters like the sample size.
503 */
Daniel Mack737e3702018-05-21 23:50:16 +0200504 priv->configured_dai_fmt = priv->dai_fmt;
Mark Brown1b340bd2008-07-30 19:12:04 +0100505
506 return 0;
507}
508
Daniel Mack05739372018-06-29 14:59:40 +0200509struct pxa_ssp_clock_mode {
510 int rate;
511 int pll;
512 u8 acds;
513 u8 scdb;
514};
515
516static const struct pxa_ssp_clock_mode pxa_ssp_clock_modes[] = {
517 { .rate = 8000, .pll = 32842000, .acds = SSACD_ACDS_32, .scdb = SSACD_SCDB_4X },
518 { .rate = 11025, .pll = 5622000, .acds = SSACD_ACDS_4, .scdb = SSACD_SCDB_4X },
519 { .rate = 16000, .pll = 32842000, .acds = SSACD_ACDS_16, .scdb = SSACD_SCDB_4X },
520 { .rate = 22050, .pll = 5622000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X },
521 { .rate = 44100, .pll = 11345000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X },
522 { .rate = 48000, .pll = 12235000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X },
523 { .rate = 96000, .pll = 12235000, .acds = SSACD_ACDS_4, .scdb = SSACD_SCDB_1X },
524 {}
525};
526
Mark Brown1b340bd2008-07-30 19:12:04 +0100527/*
528 * Set the SSP audio DMA parameters and sample size.
529 * Can be called multiple times by oss emulation.
530 */
531static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000532 struct snd_pcm_hw_params *params,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000533 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100534{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000535 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800536 struct ssp_device *ssp = priv->ssp;
Eric Miao2d7e71f2009-04-23 17:05:38 +0800537 int chn = params_channels(params);
Daniel Mack05739372018-06-29 14:59:40 +0200538 u32 sscr0, sspsp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100539 int width = snd_pcm_format_physical_width(params_format(params));
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400540 int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf;
Daniel Mackd65a1452013-08-12 10:42:39 +0200541 struct snd_dmaengine_dai_dma_data *dma_data;
Daniel Mack05739372018-06-29 14:59:40 +0200542 int rate = params_rate(params);
543 int bclk = rate * chn * (width / 8);
Daniel Mack737e3702018-05-21 23:50:16 +0200544 int ret;
Daniel Mack5f712b22010-03-22 10:11:15 +0100545
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000546 dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
Mark Brown1b340bd2008-07-30 19:12:04 +0100547
Philipp Zabel92429062009-03-19 09:32:01 +0100548 /* Network mode with one active slot (ttsa == 1) can be used
549 * to force 16-bit frame width on the wire (for S16_LE), even
550 * with two channels. Use 16-bit DMA transfers for this case.
551 */
guoyhd93ca1a2012-05-07 15:34:24 +0800552 pxa_ssp_set_dma_params(ssp,
553 ((chn == 2) && (ttsa != 1)) || (width == 32),
554 substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data);
Daniel Mack5f712b22010-03-22 10:11:15 +0100555
Mark Brown1b340bd2008-07-30 19:12:04 +0100556 /* we can only change the settings if the port is not in use */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400557 if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
Mark Brown1b340bd2008-07-30 19:12:04 +0100558 return 0;
559
Daniel Mack737e3702018-05-21 23:50:16 +0200560 ret = pxa_ssp_configure_dai_fmt(priv);
561 if (ret < 0)
562 return ret;
563
Mark Brown1b340bd2008-07-30 19:12:04 +0100564 /* clear selected SSP bits */
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400565 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
Mark Brown1b340bd2008-07-30 19:12:04 +0100566
567 /* bit size */
Mark Brown1b340bd2008-07-30 19:12:04 +0100568 switch (params_format(params)) {
569 case SNDRV_PCM_FORMAT_S16_LE:
Qiao Zhou972a55b2012-06-04 10:41:04 +0800570 if (ssp->type == PXA3xx_SSP)
Mark Brown1b340bd2008-07-30 19:12:04 +0100571 sscr0 |= SSCR0_FPCKE;
Mark Brown1b340bd2008-07-30 19:12:04 +0100572 sscr0 |= SSCR0_DataSize(16);
Mark Brown1b340bd2008-07-30 19:12:04 +0100573 break;
574 case SNDRV_PCM_FORMAT_S24_LE:
575 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
Mark Brown1b340bd2008-07-30 19:12:04 +0100576 break;
577 case SNDRV_PCM_FORMAT_S32_LE:
578 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
Mark Brown1b340bd2008-07-30 19:12:04 +0100579 break;
580 }
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400581 pxa_ssp_write_reg(ssp, SSCR0, sscr0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100582
Daniel Mack05739372018-06-29 14:59:40 +0200583 if (sscr0 & SSCR0_ACS) {
584 ret = pxa_ssp_set_pll(priv, bclk);
585
586 /*
587 * If we were able to generate the bclk directly,
588 * all is fine. Otherwise, look up the closest rate
589 * from the table and also set the dividers.
590 */
591
592 if (ret < 0) {
593 const struct pxa_ssp_clock_mode *m;
594 int ssacd, acds;
595
596 for (m = pxa_ssp_clock_modes; m->rate; m++) {
597 if (m->rate == rate)
598 break;
599 }
600
601 if (!m->rate)
602 return -EINVAL;
603
604 acds = m->acds;
605
606 /* The values in the table are for 16 bits */
607 if (width == 32)
608 acds--;
609
610 ret = pxa_ssp_set_pll(priv, bclk);
611 if (ret < 0)
612 return ret;
613
614 ssacd = pxa_ssp_read_reg(ssp, SSACD);
615 ssacd &= ~(SSACD_ACDS(7) | SSACD_SCDB_1X);
616 ssacd |= SSACD_ACDS(m->acds);
617 ssacd |= m->scdb;
618 pxa_ssp_write_reg(ssp, SSACD, ssacd);
619 }
620 } else if (sscr0 & SSCR0_ECS) {
621 /*
622 * For setups with external clocking, the PLL and its diviers
623 * are not active. Instead, the SCR bits in SSCR0 can be used
624 * to divide the clock.
625 */
626 pxa_ssp_set_scr(ssp, bclk / rate);
627 }
628
Mark Brown1b340bd2008-07-30 19:12:04 +0100629 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
630 case SND_SOC_DAIFMT_I2S:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400631 sspsp = pxa_ssp_read_reg(ssp, SSPSP);
Daniel Mack72d74662009-03-12 11:27:49 +0100632
Daniel Mack05739372018-06-29 14:59:40 +0200633 if (((priv->sysclk / bclk) == 64) && (width == 16)) {
Daniel Mack72d74662009-03-12 11:27:49 +0100634 /* This is a special case where the bitclk is 64fs
Codrut Grosu34e82432017-02-25 23:40:31 +0200635 * and we're not dealing with 2*32 bits of audio
636 * samples.
637 *
638 * The SSP values used for that are all found out by
639 * trying and failing a lot; some of the registers
640 * needed for that mode are only available on PXA3xx.
641 */
Qiao Zhou972a55b2012-06-04 10:41:04 +0800642 if (ssp->type != PXA3xx_SSP)
Daniel Mack72d74662009-03-12 11:27:49 +0100643 return -EINVAL;
644
645 sspsp |= SSPSP_SFRMWDTH(width * 2);
646 sspsp |= SSPSP_SFRMDLY(width * 4);
647 sspsp |= SSPSP_EDMYSTOP(3);
648 sspsp |= SSPSP_DMYSTOP(3);
649 sspsp |= SSPSP_DMYSTRT(1);
Mark Brown0ce36c52009-03-13 14:26:08 +0000650 } else {
651 /* The frame width is the width the LRCLK is
652 * asserted for; the delay is expressed in
653 * half cycle units. We need the extra cycle
654 * because the data starts clocking out one BCLK
655 * after LRCLK changes polarity.
656 */
657 sspsp |= SSPSP_SFRMWDTH(width + 1);
658 sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
659 sspsp |= SSPSP_DMYSTRT(1);
660 }
Daniel Mack72d74662009-03-12 11:27:49 +0100661
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400662 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100663 break;
664 default:
665 break;
666 }
667
Daniel Mack72d74662009-03-12 11:27:49 +0100668 /* When we use a network mode, we always require TDM slots
Mark Brown1b340bd2008-07-30 19:12:04 +0100669 * - complain loudly and fail if they've not been set up yet.
670 */
Philipp Zabel92429062009-03-19 09:32:01 +0100671 if ((sscr0 & SSCR0_MOD) && !ttsa) {
Andy Shevchenko4f3d9572019-10-18 13:54:25 +0300672 dev_err(ssp->dev, "No TDM timeslot configured\n");
Mark Brown1b340bd2008-07-30 19:12:04 +0100673 return -EINVAL;
674 }
675
676 dump_registers(ssp);
677
678 return 0;
679}
680
Daniel Mack273b72c2012-03-19 09:12:53 +0100681static void pxa_ssp_set_running_bit(struct snd_pcm_substream *substream,
682 struct ssp_device *ssp, int value)
683{
684 uint32_t sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
685 uint32_t sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
686 uint32_t sspsp = pxa_ssp_read_reg(ssp, SSPSP);
687 uint32_t sssr = pxa_ssp_read_reg(ssp, SSSR);
688
689 if (value && (sscr0 & SSCR0_SSE))
690 pxa_ssp_write_reg(ssp, SSCR0, sscr0 & ~SSCR0_SSE);
691
692 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
693 if (value)
694 sscr1 |= SSCR1_TSRE;
695 else
696 sscr1 &= ~SSCR1_TSRE;
697 } else {
698 if (value)
699 sscr1 |= SSCR1_RSRE;
700 else
701 sscr1 &= ~SSCR1_RSRE;
702 }
703
704 pxa_ssp_write_reg(ssp, SSCR1, sscr1);
705
706 if (value) {
707 pxa_ssp_write_reg(ssp, SSSR, sssr);
708 pxa_ssp_write_reg(ssp, SSPSP, sspsp);
709 pxa_ssp_write_reg(ssp, SSCR0, sscr0 | SSCR0_SSE);
710 }
711}
712
Mark Browndee89c42008-11-18 22:11:38 +0000713static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000714 struct snd_soc_dai *cpu_dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100715{
Mark Brown1b340bd2008-07-30 19:12:04 +0100716 int ret = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000717 struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
Eric Miaof9efc9d2010-02-09 19:46:01 +0800718 struct ssp_device *ssp = priv->ssp;
Mark Brown1b340bd2008-07-30 19:12:04 +0100719 int val;
720
721 switch (cmd) {
722 case SNDRV_PCM_TRIGGER_RESUME:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400723 pxa_ssp_enable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100724 break;
725 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Daniel Mack273b72c2012-03-19 09:12:53 +0100726 pxa_ssp_set_running_bit(substream, ssp, 1);
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400727 val = pxa_ssp_read_reg(ssp, SSSR);
728 pxa_ssp_write_reg(ssp, SSSR, val);
Mark Brown1b340bd2008-07-30 19:12:04 +0100729 break;
730 case SNDRV_PCM_TRIGGER_START:
Daniel Mack273b72c2012-03-19 09:12:53 +0100731 pxa_ssp_set_running_bit(substream, ssp, 1);
Mark Brown1b340bd2008-07-30 19:12:04 +0100732 break;
733 case SNDRV_PCM_TRIGGER_STOP:
Daniel Mack273b72c2012-03-19 09:12:53 +0100734 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100735 break;
736 case SNDRV_PCM_TRIGGER_SUSPEND:
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400737 pxa_ssp_disable(ssp);
Mark Brown1b340bd2008-07-30 19:12:04 +0100738 break;
739 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Daniel Mack273b72c2012-03-19 09:12:53 +0100740 pxa_ssp_set_running_bit(substream, ssp, 0);
Mark Brown1b340bd2008-07-30 19:12:04 +0100741 break;
742
743 default:
744 ret = -EINVAL;
745 }
746
747 dump_registers(ssp);
748
749 return ret;
750}
751
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000752static int pxa_ssp_probe(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100753{
Daniel Mack2023c902013-08-12 10:42:38 +0200754 struct device *dev = dai->dev;
Mark Brown1b340bd2008-07-30 19:12:04 +0100755 struct ssp_priv *priv;
756 int ret;
757
758 priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL);
759 if (!priv)
760 return -ENOMEM;
761
Daniel Mack2023c902013-08-12 10:42:38 +0200762 if (dev->of_node) {
763 struct device_node *ssp_handle;
764
765 ssp_handle = of_parse_phandle(dev->of_node, "port", 0);
766 if (!ssp_handle) {
767 dev_err(dev, "unable to get 'port' phandle\n");
Dan Carpenter45487282014-07-31 15:57:51 +0300768 ret = -ENODEV;
769 goto err_priv;
Daniel Mack2023c902013-08-12 10:42:38 +0200770 }
771
772 priv->ssp = pxa_ssp_request_of(ssp_handle, "SoC audio");
773 if (priv->ssp == NULL) {
774 ret = -ENODEV;
775 goto err_priv;
776 }
Daniel Mack90eb6b52018-07-02 17:11:00 +0200777
778 priv->extclk = devm_clk_get(dev, "extclk");
779 if (IS_ERR(priv->extclk)) {
780 ret = PTR_ERR(priv->extclk);
781 if (ret == -EPROBE_DEFER)
782 return ret;
783
784 priv->extclk = NULL;
785 }
Daniel Mack2023c902013-08-12 10:42:38 +0200786 } else {
787 priv->ssp = pxa_ssp_request(dai->id + 1, "SoC audio");
788 if (priv->ssp == NULL) {
789 ret = -ENODEV;
790 goto err_priv;
791 }
Mark Brown1b340bd2008-07-30 19:12:04 +0100792 }
793
Daniel Macka5735b72009-04-15 20:24:45 +0200794 priv->dai_fmt = (unsigned int) -1;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000795 snd_soc_dai_set_drvdata(dai, priv);
Mark Brown1b340bd2008-07-30 19:12:04 +0100796
797 return 0;
798
799err_priv:
800 kfree(priv);
801 return ret;
802}
803
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000804static int pxa_ssp_remove(struct snd_soc_dai *dai)
Mark Brown1b340bd2008-07-30 19:12:04 +0100805{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000806 struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai);
807
Haojian Zhuangbaffe162010-05-05 10:11:15 -0400808 pxa_ssp_free(priv->ssp);
Axel Lin014a2752010-08-25 16:59:11 +0800809 kfree(priv);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000810 return 0;
Mark Brown1b340bd2008-07-30 19:12:04 +0100811}
812
813#define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
814 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
Qiao Zhou8d8bf582012-03-08 10:02:36 +0800815 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
816 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
Mark Brown1b340bd2008-07-30 19:12:04 +0100817 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
818
Daniel Mack93015032014-08-13 21:51:06 +0200819#define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
Mark Brown1b340bd2008-07-30 19:12:04 +0100820
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100821static const struct snd_soc_dai_ops pxa_ssp_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800822 .startup = pxa_ssp_startup,
823 .shutdown = pxa_ssp_shutdown,
824 .trigger = pxa_ssp_trigger,
825 .hw_params = pxa_ssp_hw_params,
826 .set_sysclk = pxa_ssp_set_dai_sysclk,
Eric Miao6335d052009-03-03 09:41:00 +0800827 .set_fmt = pxa_ssp_set_dai_fmt,
828 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
829 .set_tristate = pxa_ssp_set_dai_tristate,
830};
831
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000832static struct snd_soc_dai_driver pxa_ssp_dai = {
Mark Brown1b340bd2008-07-30 19:12:04 +0100833 .probe = pxa_ssp_probe,
834 .remove = pxa_ssp_remove,
Mark Brown1b340bd2008-07-30 19:12:04 +0100835 .playback = {
836 .channels_min = 1,
Graeme Gregoryf34762b2009-09-25 13:30:26 +0100837 .channels_max = 8,
Mark Brown1b340bd2008-07-30 19:12:04 +0100838 .rates = PXA_SSP_RATES,
839 .formats = PXA_SSP_FORMATS,
840 },
841 .capture = {
842 .channels_min = 1,
Graeme Gregoryf34762b2009-09-25 13:30:26 +0100843 .channels_max = 8,
Mark Brown1b340bd2008-07-30 19:12:04 +0100844 .rates = PXA_SSP_RATES,
845 .formats = PXA_SSP_FORMATS,
846 },
Eric Miao6335d052009-03-03 09:41:00 +0800847 .ops = &pxa_ssp_dai_ops,
Mark Brown1b340bd2008-07-30 19:12:04 +0100848};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000849
Kuninori Morimotoe580f1c2013-03-21 03:34:12 -0700850static const struct snd_soc_component_driver pxa_ssp_component = {
851 .name = "pxa-ssp",
Kuninori Morimotof8772e12019-10-02 14:33:50 +0900852 .pcm_construct = pxa2xx_soc_pcm_new,
Kuninori Morimotof8772e12019-10-02 14:33:50 +0900853 .open = pxa2xx_soc_pcm_open,
854 .close = pxa2xx_soc_pcm_close,
Kuninori Morimotof8772e12019-10-02 14:33:50 +0900855 .hw_params = pxa2xx_soc_pcm_hw_params,
Kuninori Morimotof8772e12019-10-02 14:33:50 +0900856 .prepare = pxa2xx_soc_pcm_prepare,
857 .trigger = pxa2xx_soc_pcm_trigger,
858 .pointer = pxa2xx_soc_pcm_pointer,
Kuninori Morimoto2c55f0b2020-01-20 10:04:52 +0900859 .suspend = pxa_ssp_suspend,
860 .resume = pxa_ssp_resume,
Kuninori Morimotoe580f1c2013-03-21 03:34:12 -0700861};
862
Daniel Mack2023c902013-08-12 10:42:38 +0200863#ifdef CONFIG_OF
864static const struct of_device_id pxa_ssp_of_ids[] = {
865 { .compatible = "mrvl,pxa-ssp-dai" },
Stephen Boyd4c715c72014-05-23 17:16:49 -0700866 {}
Daniel Mack2023c902013-08-12 10:42:38 +0200867};
Luis de Bethencourtbaafd372015-09-03 13:00:03 +0200868MODULE_DEVICE_TABLE(of, pxa_ssp_of_ids);
Daniel Mack2023c902013-08-12 10:42:38 +0200869#endif
870
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500871static int asoc_ssp_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000872{
Axel Lin637ce532015-08-28 10:48:35 +0800873 return devm_snd_soc_register_component(&pdev->dev, &pxa_ssp_component,
874 &pxa_ssp_dai, 1);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000875}
876
877static struct platform_driver asoc_ssp_driver = {
878 .driver = {
Daniel Mack2023c902013-08-12 10:42:38 +0200879 .name = "pxa-ssp-dai",
Daniel Mack2023c902013-08-12 10:42:38 +0200880 .of_match_table = of_match_ptr(pxa_ssp_of_ids),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000881 },
882
883 .probe = asoc_ssp_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000884};
Mark Brown1b340bd2008-07-30 19:12:04 +0100885
Axel Lin2f702a12011-11-25 10:13:37 +0800886module_platform_driver(asoc_ssp_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000887
Mark Brown1b340bd2008-07-30 19:12:04 +0100888/* Module information */
889MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
890MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface");
891MODULE_LICENSE("GPL");
Andrea Adamie5b7d712016-05-06 17:27:34 +0200892MODULE_ALIAS("platform:pxa-ssp-dai");