Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 2 | /* |
| 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 9 | * TODO: |
| 10 | * o Test network mode for > 16bit sample size |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/io.h> |
Sebastian Andrzej Siewior | 8348c25 | 2010-11-22 17:12:15 -0800 | [diff] [blame] | 19 | #include <linux/pxa2xx_ssp.h> |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 20 | #include <linux/of.h> |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 21 | #include <linux/dmaengine.h> |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 22 | |
Philipp Zabel | 0664678 | 2009-02-03 21:18:26 +0100 | [diff] [blame] | 23 | #include <asm/irq.h> |
| 24 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 25 | #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 Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 31 | #include <sound/dmaengine_pcm.h> |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 32 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 33 | #include "pxa-ssp.h" |
| 34 | |
| 35 | /* |
| 36 | * SSP audio private data |
| 37 | */ |
| 38 | struct ssp_priv { |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 39 | struct ssp_device *ssp; |
Daniel Mack | 90eb6b5 | 2018-07-02 17:11:00 +0200 | [diff] [blame] | 40 | struct clk *extclk; |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 41 | unsigned long ssp_clk; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 42 | unsigned int sysclk; |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 43 | unsigned int dai_fmt; |
| 44 | unsigned int configured_dai_fmt; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 45 | #ifdef CONFIG_PM |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 46 | uint32_t cr0; |
| 47 | uint32_t cr1; |
| 48 | uint32_t to; |
| 49 | uint32_t psp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 50 | #endif |
| 51 | }; |
| 52 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 53 | static void dump_registers(struct ssp_device *ssp) |
| 54 | { |
Andy Shevchenko | 4f3d957 | 2019-10-18 13:54:25 +0300 | [diff] [blame] | 55 | dev_dbg(ssp->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n", |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 56 | pxa_ssp_read_reg(ssp, SSCR0), pxa_ssp_read_reg(ssp, SSCR1), |
| 57 | pxa_ssp_read_reg(ssp, SSTO)); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 58 | |
Andy Shevchenko | 4f3d957 | 2019-10-18 13:54:25 +0300 | [diff] [blame] | 59 | dev_dbg(ssp->dev, "SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n", |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 60 | pxa_ssp_read_reg(ssp, SSPSP), pxa_ssp_read_reg(ssp, SSSR), |
| 61 | pxa_ssp_read_reg(ssp, SSACD)); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 62 | } |
| 63 | |
guoyh | d93ca1a | 2012-05-07 15:34:24 +0800 | [diff] [blame] | 64 | static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4, |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 65 | int out, struct snd_dmaengine_dai_dma_data *dma) |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 66 | { |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 67 | 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 Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 71 | } |
| 72 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 73 | static int pxa_ssp_startup(struct snd_pcm_substream *substream, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 74 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 75 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 76 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 77 | struct ssp_device *ssp = priv->ssp; |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 78 | struct snd_dmaengine_dai_dma_data *dma; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 79 | int ret = 0; |
| 80 | |
Kuninori Morimoto | aaeb5fb | 2020-05-15 09:47:41 +0900 | [diff] [blame] | 81 | if (!snd_soc_dai_active(cpu_dai)) { |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 82 | clk_prepare_enable(ssp->clk); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 83 | pxa_ssp_disable(ssp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 84 | } |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 85 | |
Xu Wang | b8f9495 | 2020-10-29 09:01:04 +0000 | [diff] [blame] | 86 | clk_prepare_enable(priv->extclk); |
Daniel Mack | cfe9ee5 | 2018-10-03 21:36:27 +0200 | [diff] [blame] | 87 | |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 88 | dma = kzalloc(sizeof(struct snd_dmaengine_dai_dma_data), GFP_KERNEL); |
guoyh | d93ca1a | 2012-05-07 15:34:24 +0800 | [diff] [blame] | 89 | if (!dma) |
| 90 | return -ENOMEM; |
Robert Jarzmik | cd31b80 | 2018-06-17 19:02:17 +0200 | [diff] [blame] | 91 | dma->chan_name = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 92 | "tx" : "rx"; |
Daniel Mack | a671468 | 2013-08-12 10:42:40 +0200 | [diff] [blame] | 93 | |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 94 | snd_soc_dai_set_dma_data(cpu_dai, substream, dma); |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 95 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 96 | return ret; |
| 97 | } |
| 98 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 99 | static void pxa_ssp_shutdown(struct snd_pcm_substream *substream, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 100 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 101 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 102 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 103 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 104 | |
Kuninori Morimoto | aaeb5fb | 2020-05-15 09:47:41 +0900 | [diff] [blame] | 105 | if (!snd_soc_dai_active(cpu_dai)) { |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 106 | pxa_ssp_disable(ssp); |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 107 | clk_disable_unprepare(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 108 | } |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 109 | |
Xu Wang | b8f9495 | 2020-10-29 09:01:04 +0000 | [diff] [blame] | 110 | clk_disable_unprepare(priv->extclk); |
Daniel Mack | cfe9ee5 | 2018-10-03 21:36:27 +0200 | [diff] [blame] | 111 | |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 112 | kfree(snd_soc_dai_get_dma_data(cpu_dai, substream)); |
| 113 | snd_soc_dai_set_dma_data(cpu_dai, substream, NULL); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | #ifdef CONFIG_PM |
| 117 | |
Kuninori Morimoto | 2c55f0b | 2020-01-20 10:04:52 +0900 | [diff] [blame] | 118 | static int pxa_ssp_suspend(struct snd_soc_component *component) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 119 | { |
Kuninori Morimoto | 2c55f0b | 2020-01-20 10:04:52 +0900 | [diff] [blame] | 120 | struct ssp_priv *priv = snd_soc_component_get_drvdata(component); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 121 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 122 | |
Kuninori Morimoto | aaeb5fb | 2020-05-15 09:47:41 +0900 | [diff] [blame] | 123 | if (!snd_soc_component_active(component)) |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 124 | clk_prepare_enable(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 125 | |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 126 | 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 Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 131 | pxa_ssp_disable(ssp); |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 132 | clk_disable_unprepare(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
Kuninori Morimoto | 2c55f0b | 2020-01-20 10:04:52 +0900 | [diff] [blame] | 136 | static int pxa_ssp_resume(struct snd_soc_component *component) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 137 | { |
Kuninori Morimoto | 2c55f0b | 2020-01-20 10:04:52 +0900 | [diff] [blame] | 138 | struct ssp_priv *priv = snd_soc_component_get_drvdata(component); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 139 | struct ssp_device *ssp = priv->ssp; |
| 140 | uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 141 | |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 142 | clk_prepare_enable(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 143 | |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 144 | __raw_writel(sssr, ssp->mmio_base + SSSR); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 145 | __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 Mack | 026384d | 2010-02-02 18:45:27 +0800 | [diff] [blame] | 149 | |
Kuninori Morimoto | aaeb5fb | 2020-05-15 09:47:41 +0900 | [diff] [blame] | 150 | if (snd_soc_component_active(component)) |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 151 | pxa_ssp_enable(ssp); |
Daniel Mack | 026384d | 2010-02-02 18:45:27 +0800 | [diff] [blame] | 152 | else |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 153 | clk_disable_unprepare(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | #else |
| 159 | #define pxa_ssp_suspend NULL |
| 160 | #define pxa_ssp_resume NULL |
| 161 | #endif |
| 162 | |
Lee Jones | 701f472 | 2020-07-09 11:23:22 -0500 | [diff] [blame] | 163 | /* |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 164 | * ssp_set_clkdiv - set SSP clock divider |
| 165 | * @div: serial clock rate divider |
| 166 | */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 167 | static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 168 | { |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 169 | u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 170 | |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 171 | if (ssp->type == PXA25x_SSP) { |
Philipp Zabel | 1a29728 | 2009-04-17 11:39:38 +0200 | [diff] [blame] | 172 | sscr0 &= ~0x0000ff00; |
| 173 | sscr0 |= ((div - 2)/2) << 8; /* 2..512 */ |
| 174 | } else { |
| 175 | sscr0 &= ~0x000fff00; |
| 176 | sscr0 |= (div - 1) << 8; /* 1..4096 */ |
| 177 | } |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 178 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Philipp Zabel | 1a29728 | 2009-04-17 11:39:38 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 181 | /* |
| 182 | * Set the SSP ports SYSCLK. |
| 183 | */ |
| 184 | static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai, |
| 185 | int clk_id, unsigned int freq, int dir) |
| 186 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 187 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 188 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 189 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 190 | u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & |
Daniel Mack | 05f3828 | 2018-05-21 23:50:17 +0200 | [diff] [blame] | 191 | ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 192 | |
Daniel Mack | 90eb6b5 | 2018-07-02 17:11:00 +0200 | [diff] [blame] | 193 | 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 Shevchenko | 4f3d957 | 2019-10-18 13:54:25 +0300 | [diff] [blame] | 208 | dev_dbg(ssp->dev, |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 209 | "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %u\n", |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 210 | 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 Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 218 | if (ssp->type == PXA25x_SSP) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 219 | 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 Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 233 | pxa_ssp_set_scr(ssp, 1); |
Daniel Mack | 20a41ea | 2009-03-04 21:16:57 +0100 | [diff] [blame] | 234 | sscr0 |= SSCR0_ACS; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 235 | 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 Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 242 | if (ssp->type != PXA3xx_SSP) |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 243 | clk_disable_unprepare(ssp->clk); |
Daniel Mack | 05f3828 | 2018-05-21 23:50:17 +0200 | [diff] [blame] | 244 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 245 | if (ssp->type != PXA3xx_SSP) |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 246 | clk_prepare_enable(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /* |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 252 | * Configure the PLL frequency pxa27x and (afaik - pxa320 only) |
| 253 | */ |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 254 | static int pxa_ssp_set_pll(struct ssp_priv *priv, unsigned int freq) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 255 | { |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 256 | struct ssp_device *ssp = priv->ssp; |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 257 | u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 258 | |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 259 | if (ssp->type == PXA3xx_SSP) |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 260 | pxa_ssp_write_reg(ssp, SSACDD, 0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 261 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 262 | switch (freq) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 263 | 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 285 | /* PXA3xx has a clock ditherer which can be used to generate |
| 286 | * a wider range of frequencies - calculate a value for it. |
| 287 | */ |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 288 | if (ssp->type == PXA3xx_SSP) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 289 | u32 val; |
| 290 | u64 tmp = 19968; |
Codrut Grosu | 1dbe692 | 2017-02-25 23:33:50 +0200 | [diff] [blame] | 291 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 292 | tmp *= 1000000; |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 293 | do_div(tmp, freq); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 294 | val = tmp; |
| 295 | |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 296 | val = (val << 16) | 64; |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 297 | pxa_ssp_write_reg(ssp, SSACDD, val); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 298 | |
| 299 | ssacd |= (0x6 << 4); |
| 300 | |
Andy Shevchenko | 4f3d957 | 2019-10-18 13:54:25 +0300 | [diff] [blame] | 301 | dev_dbg(ssp->dev, |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 302 | "Using SSACDD %x to supply %uHz\n", |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 303 | val, freq); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 304 | break; |
| 305 | } |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 306 | |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 310 | pxa_ssp_write_reg(ssp, SSACD, ssacd); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | * Set the active slots in TDM/Network mode |
| 317 | */ |
| 318 | static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 319 | unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 320 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 321 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 322 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 323 | u32 sscr0; |
| 324 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 325 | sscr0 = pxa_ssp_read_reg(ssp, SSCR0); |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 326 | sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 327 | |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 328 | /* 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 Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 342 | pxa_ssp_write_reg(ssp, SSTSA, tx_mask); |
| 343 | pxa_ssp_write_reg(ssp, SSRSA, rx_mask); |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 344 | } |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 345 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 346 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Tristate the SSP DAI lines |
| 352 | */ |
| 353 | static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai, |
| 354 | int tristate) |
| 355 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 356 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 357 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 358 | u32 sscr1; |
| 359 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 360 | sscr1 = pxa_ssp_read_reg(ssp, SSCR1); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 361 | if (tristate) |
| 362 | sscr1 &= ~SSCR1_TTE; |
| 363 | else |
| 364 | sscr1 |= SSCR1_TTE; |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 365 | pxa_ssp_write_reg(ssp, SSCR1, sscr1); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 370 | static 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 410 | /* |
| 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 Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 415 | static int pxa_ssp_configure_dai_fmt(struct ssp_priv *priv) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 416 | { |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 417 | struct ssp_device *ssp = priv->ssp; |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 418 | u32 sscr0, sscr1, sspsp, scfr; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 419 | |
Daniel Mack | cbf1146 | 2009-03-10 16:41:00 +0100 | [diff] [blame] | 420 | /* check if we need to change anything at all */ |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 421 | if (priv->configured_dai_fmt == priv->dai_fmt) |
Daniel Mack | cbf1146 | 2009-03-10 16:41:00 +0100 | [diff] [blame] | 422 | return 0; |
| 423 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 424 | /* reset port settings */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 425 | sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 426 | ~(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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 432 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 433 | sscr1 |= SSCR1_RxTresh(8) | SSCR1_TxTresh(7); |
| 434 | |
| 435 | switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 436 | case SND_SOC_DAIFMT_CBM_CFM: |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 437 | sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 438 | break; |
| 439 | case SND_SOC_DAIFMT_CBM_CFS: |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 440 | sscr1 |= SSCR1_SCLKDIR | SSCR1_SCFR; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 441 | break; |
| 442 | case SND_SOC_DAIFMT_CBS_CFS: |
| 443 | break; |
| 444 | default: |
| 445 | return -EINVAL; |
| 446 | } |
| 447 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 448 | switch (priv->dai_fmt & SND_SOC_DAIFMT_INV_MASK) { |
Daniel Ribeiro | fa44c07 | 2009-06-10 15:23:24 -0300 | [diff] [blame] | 449 | 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 463 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 464 | switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 465 | case SND_SOC_DAIFMT_I2S: |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 466 | sscr0 |= SSCR0_PSP; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 467 | sscr1 |= SSCR1_RWOT | SSCR1_TRAIL; |
Mark Brown | 0ce36c5 | 2009-03-13 14:26:08 +0000 | [diff] [blame] | 468 | /* See hw_params() */ |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 469 | break; |
| 470 | |
| 471 | case SND_SOC_DAIFMT_DSP_A: |
| 472 | sspsp |= SSPSP_FSRT; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 473 | fallthrough; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 474 | case SND_SOC_DAIFMT_DSP_B: |
| 475 | sscr0 |= SSCR0_MOD | SSCR0_PSP; |
| 476 | sscr1 |= SSCR1_TRAIL | SSCR1_RWOT; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 477 | break; |
| 478 | |
| 479 | default: |
| 480 | return -EINVAL; |
| 481 | } |
| 482 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 483 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
| 484 | pxa_ssp_write_reg(ssp, SSCR1, sscr1); |
| 485 | pxa_ssp_write_reg(ssp, SSPSP, sspsp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 486 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 487 | switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 488 | 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 498 | 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 Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 504 | priv->configured_dai_fmt = priv->dai_fmt; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 509 | struct pxa_ssp_clock_mode { |
| 510 | int rate; |
| 511 | int pll; |
| 512 | u8 acds; |
| 513 | u8 scdb; |
| 514 | }; |
| 515 | |
| 516 | static 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 527 | /* |
| 528 | * Set the SSP audio DMA parameters and sample size. |
| 529 | * Can be called multiple times by oss emulation. |
| 530 | */ |
| 531 | static int pxa_ssp_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 532 | struct snd_pcm_hw_params *params, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 533 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 534 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 535 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 536 | struct ssp_device *ssp = priv->ssp; |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 537 | int chn = params_channels(params); |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 538 | u32 sscr0, sspsp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 539 | int width = snd_pcm_format_physical_width(params_format(params)); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 540 | int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf; |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 541 | struct snd_dmaengine_dai_dma_data *dma_data; |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 542 | int rate = params_rate(params); |
| 543 | int bclk = rate * chn * (width / 8); |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 544 | int ret; |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 545 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 546 | dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 547 | |
Philipp Zabel | 9242906 | 2009-03-19 09:32:01 +0100 | [diff] [blame] | 548 | /* 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 | */ |
guoyh | d93ca1a | 2012-05-07 15:34:24 +0800 | [diff] [blame] | 552 | pxa_ssp_set_dma_params(ssp, |
| 553 | ((chn == 2) && (ttsa != 1)) || (width == 32), |
| 554 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data); |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 555 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 556 | /* we can only change the settings if the port is not in use */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 557 | if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 558 | return 0; |
| 559 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 560 | ret = pxa_ssp_configure_dai_fmt(priv); |
| 561 | if (ret < 0) |
| 562 | return ret; |
| 563 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 564 | /* clear selected SSP bits */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 565 | sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 566 | |
| 567 | /* bit size */ |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 568 | switch (params_format(params)) { |
| 569 | case SNDRV_PCM_FORMAT_S16_LE: |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 570 | if (ssp->type == PXA3xx_SSP) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 571 | sscr0 |= SSCR0_FPCKE; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 572 | sscr0 |= SSCR0_DataSize(16); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 573 | break; |
| 574 | case SNDRV_PCM_FORMAT_S24_LE: |
| 575 | sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8)); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 576 | break; |
| 577 | case SNDRV_PCM_FORMAT_S32_LE: |
| 578 | sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16)); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 579 | break; |
| 580 | } |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 581 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 582 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 583 | 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 629 | switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 630 | case SND_SOC_DAIFMT_I2S: |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 631 | sspsp = pxa_ssp_read_reg(ssp, SSPSP); |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 632 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 633 | if (((priv->sysclk / bclk) == 64) && (width == 16)) { |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 634 | /* This is a special case where the bitclk is 64fs |
Codrut Grosu | 34e8243 | 2017-02-25 23:40:31 +0200 | [diff] [blame] | 635 | * 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 Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 642 | if (ssp->type != PXA3xx_SSP) |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 643 | 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 Brown | 0ce36c5 | 2009-03-13 14:26:08 +0000 | [diff] [blame] | 650 | } 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 Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 661 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 662 | pxa_ssp_write_reg(ssp, SSPSP, sspsp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 663 | break; |
| 664 | default: |
| 665 | break; |
| 666 | } |
| 667 | |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 668 | /* When we use a network mode, we always require TDM slots |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 669 | * - complain loudly and fail if they've not been set up yet. |
| 670 | */ |
Philipp Zabel | 9242906 | 2009-03-19 09:32:01 +0100 | [diff] [blame] | 671 | if ((sscr0 & SSCR0_MOD) && !ttsa) { |
Andy Shevchenko | 4f3d957 | 2019-10-18 13:54:25 +0300 | [diff] [blame] | 672 | dev_err(ssp->dev, "No TDM timeslot configured\n"); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 673 | return -EINVAL; |
| 674 | } |
| 675 | |
| 676 | dump_registers(ssp); |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 681 | static 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 Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 713 | static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 714 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 715 | { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 716 | int ret = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 717 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 718 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 719 | int val; |
| 720 | |
| 721 | switch (cmd) { |
| 722 | case SNDRV_PCM_TRIGGER_RESUME: |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 723 | pxa_ssp_enable(ssp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 724 | break; |
| 725 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 726 | pxa_ssp_set_running_bit(substream, ssp, 1); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 727 | val = pxa_ssp_read_reg(ssp, SSSR); |
| 728 | pxa_ssp_write_reg(ssp, SSSR, val); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 729 | break; |
| 730 | case SNDRV_PCM_TRIGGER_START: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 731 | pxa_ssp_set_running_bit(substream, ssp, 1); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 732 | break; |
| 733 | case SNDRV_PCM_TRIGGER_STOP: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 734 | pxa_ssp_set_running_bit(substream, ssp, 0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 735 | break; |
| 736 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 737 | pxa_ssp_disable(ssp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 738 | break; |
| 739 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 740 | pxa_ssp_set_running_bit(substream, ssp, 0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | default: |
| 744 | ret = -EINVAL; |
| 745 | } |
| 746 | |
| 747 | dump_registers(ssp); |
| 748 | |
| 749 | return ret; |
| 750 | } |
| 751 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 752 | static int pxa_ssp_probe(struct snd_soc_dai *dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 753 | { |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 754 | struct device *dev = dai->dev; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 755 | 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 Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 762 | 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 Carpenter | 4548728 | 2014-07-31 15:57:51 +0300 | [diff] [blame] | 768 | ret = -ENODEV; |
| 769 | goto err_priv; |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 770 | } |
| 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 Mack | 90eb6b5 | 2018-07-02 17:11:00 +0200 | [diff] [blame] | 777 | |
| 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 Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 786 | } 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 Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 792 | } |
| 793 | |
Daniel Mack | a5735b7 | 2009-04-15 20:24:45 +0200 | [diff] [blame] | 794 | priv->dai_fmt = (unsigned int) -1; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 795 | snd_soc_dai_set_drvdata(dai, priv); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 796 | |
| 797 | return 0; |
| 798 | |
| 799 | err_priv: |
| 800 | kfree(priv); |
| 801 | return ret; |
| 802 | } |
| 803 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 804 | static int pxa_ssp_remove(struct snd_soc_dai *dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 805 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 806 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai); |
| 807 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 808 | pxa_ssp_free(priv->ssp); |
Axel Lin | 014a275 | 2010-08-25 16:59:11 +0800 | [diff] [blame] | 809 | kfree(priv); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 810 | return 0; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | #define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
| 814 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ |
Qiao Zhou | 8d8bf58 | 2012-03-08 10:02:36 +0800 | [diff] [blame] | 815 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 816 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \ |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 817 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
| 818 | |
Daniel Mack | 9301503 | 2014-08-13 21:51:06 +0200 | [diff] [blame] | 819 | #define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 820 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 821 | static const struct snd_soc_dai_ops pxa_ssp_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 822 | .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 Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 827 | .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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 832 | static struct snd_soc_dai_driver pxa_ssp_dai = { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 833 | .probe = pxa_ssp_probe, |
| 834 | .remove = pxa_ssp_remove, |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 835 | .playback = { |
| 836 | .channels_min = 1, |
Graeme Gregory | f34762b | 2009-09-25 13:30:26 +0100 | [diff] [blame] | 837 | .channels_max = 8, |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 838 | .rates = PXA_SSP_RATES, |
| 839 | .formats = PXA_SSP_FORMATS, |
| 840 | }, |
| 841 | .capture = { |
| 842 | .channels_min = 1, |
Graeme Gregory | f34762b | 2009-09-25 13:30:26 +0100 | [diff] [blame] | 843 | .channels_max = 8, |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 844 | .rates = PXA_SSP_RATES, |
| 845 | .formats = PXA_SSP_FORMATS, |
| 846 | }, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 847 | .ops = &pxa_ssp_dai_ops, |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 848 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 849 | |
Kuninori Morimoto | e580f1c | 2013-03-21 03:34:12 -0700 | [diff] [blame] | 850 | static const struct snd_soc_component_driver pxa_ssp_component = { |
| 851 | .name = "pxa-ssp", |
Kuninori Morimoto | f8772e1 | 2019-10-02 14:33:50 +0900 | [diff] [blame] | 852 | .pcm_construct = pxa2xx_soc_pcm_new, |
Kuninori Morimoto | f8772e1 | 2019-10-02 14:33:50 +0900 | [diff] [blame] | 853 | .open = pxa2xx_soc_pcm_open, |
| 854 | .close = pxa2xx_soc_pcm_close, |
Kuninori Morimoto | f8772e1 | 2019-10-02 14:33:50 +0900 | [diff] [blame] | 855 | .hw_params = pxa2xx_soc_pcm_hw_params, |
Kuninori Morimoto | f8772e1 | 2019-10-02 14:33:50 +0900 | [diff] [blame] | 856 | .prepare = pxa2xx_soc_pcm_prepare, |
| 857 | .trigger = pxa2xx_soc_pcm_trigger, |
| 858 | .pointer = pxa2xx_soc_pcm_pointer, |
Kuninori Morimoto | 2c55f0b | 2020-01-20 10:04:52 +0900 | [diff] [blame] | 859 | .suspend = pxa_ssp_suspend, |
| 860 | .resume = pxa_ssp_resume, |
Kuninori Morimoto | e580f1c | 2013-03-21 03:34:12 -0700 | [diff] [blame] | 861 | }; |
| 862 | |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 863 | #ifdef CONFIG_OF |
| 864 | static const struct of_device_id pxa_ssp_of_ids[] = { |
| 865 | { .compatible = "mrvl,pxa-ssp-dai" }, |
Stephen Boyd | 4c715c7 | 2014-05-23 17:16:49 -0700 | [diff] [blame] | 866 | {} |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 867 | }; |
Luis de Bethencourt | baafd37 | 2015-09-03 13:00:03 +0200 | [diff] [blame] | 868 | MODULE_DEVICE_TABLE(of, pxa_ssp_of_ids); |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 869 | #endif |
| 870 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 871 | static int asoc_ssp_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 872 | { |
Axel Lin | 637ce53 | 2015-08-28 10:48:35 +0800 | [diff] [blame] | 873 | return devm_snd_soc_register_component(&pdev->dev, &pxa_ssp_component, |
| 874 | &pxa_ssp_dai, 1); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static struct platform_driver asoc_ssp_driver = { |
| 878 | .driver = { |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 879 | .name = "pxa-ssp-dai", |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 880 | .of_match_table = of_match_ptr(pxa_ssp_of_ids), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 881 | }, |
| 882 | |
| 883 | .probe = asoc_ssp_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 884 | }; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 885 | |
Axel Lin | 2f702a1 | 2011-11-25 10:13:37 +0800 | [diff] [blame] | 886 | module_platform_driver(asoc_ssp_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 887 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 888 | /* Module information */ |
| 889 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 890 | MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface"); |
| 891 | MODULE_LICENSE("GPL"); |
Andrea Adami | e5b7d71 | 2016-05-06 17:27:34 +0200 | [diff] [blame] | 892 | MODULE_ALIAS("platform:pxa-ssp-dai"); |