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 | { |
| 55 | dev_dbg(&ssp->pdev->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 | |
| 59 | dev_dbg(&ssp->pdev->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 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 64 | static void pxa_ssp_enable(struct ssp_device *ssp) |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 65 | { |
| 66 | uint32_t sscr0; |
| 67 | |
| 68 | sscr0 = __raw_readl(ssp->mmio_base + SSCR0) | SSCR0_SSE; |
| 69 | __raw_writel(sscr0, ssp->mmio_base + SSCR0); |
| 70 | } |
| 71 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 72 | static void pxa_ssp_disable(struct ssp_device *ssp) |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 73 | { |
| 74 | uint32_t sscr0; |
| 75 | |
| 76 | sscr0 = __raw_readl(ssp->mmio_base + SSCR0) & ~SSCR0_SSE; |
| 77 | __raw_writel(sscr0, ssp->mmio_base + SSCR0); |
| 78 | } |
| 79 | |
guoyh | d93ca1a | 2012-05-07 15:34:24 +0800 | [diff] [blame] | 80 | 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] | 81 | int out, struct snd_dmaengine_dai_dma_data *dma) |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 82 | { |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 83 | dma->addr_width = width4 ? DMA_SLAVE_BUSWIDTH_4_BYTES : |
| 84 | DMA_SLAVE_BUSWIDTH_2_BYTES; |
| 85 | dma->maxburst = 16; |
| 86 | dma->addr = ssp->phys_base + SSDR; |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 87 | } |
| 88 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 89 | static int pxa_ssp_startup(struct snd_pcm_substream *substream, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 90 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 91 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 92 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 93 | struct ssp_device *ssp = priv->ssp; |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 94 | struct snd_dmaengine_dai_dma_data *dma; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 95 | int ret = 0; |
| 96 | |
| 97 | if (!cpu_dai->active) { |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 98 | clk_prepare_enable(ssp->clk); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 99 | pxa_ssp_disable(ssp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 100 | } |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 101 | |
Daniel Mack | cfe9ee5 | 2018-10-03 21:36:27 +0200 | [diff] [blame] | 102 | if (priv->extclk) |
| 103 | clk_prepare_enable(priv->extclk); |
| 104 | |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 105 | dma = kzalloc(sizeof(struct snd_dmaengine_dai_dma_data), GFP_KERNEL); |
guoyh | d93ca1a | 2012-05-07 15:34:24 +0800 | [diff] [blame] | 106 | if (!dma) |
| 107 | return -ENOMEM; |
Robert Jarzmik | cd31b80 | 2018-06-17 19:02:17 +0200 | [diff] [blame] | 108 | dma->chan_name = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 109 | "tx" : "rx"; |
Daniel Mack | a671468 | 2013-08-12 10:42:40 +0200 | [diff] [blame] | 110 | |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 111 | snd_soc_dai_set_dma_data(cpu_dai, substream, dma); |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 112 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 113 | return ret; |
| 114 | } |
| 115 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 116 | static void pxa_ssp_shutdown(struct snd_pcm_substream *substream, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 117 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 118 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 119 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 120 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 121 | |
| 122 | if (!cpu_dai->active) { |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 123 | pxa_ssp_disable(ssp); |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 124 | clk_disable_unprepare(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 125 | } |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 126 | |
Daniel Mack | cfe9ee5 | 2018-10-03 21:36:27 +0200 | [diff] [blame] | 127 | if (priv->extclk) |
| 128 | clk_disable_unprepare(priv->extclk); |
| 129 | |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 130 | kfree(snd_soc_dai_get_dma_data(cpu_dai, substream)); |
| 131 | snd_soc_dai_set_dma_data(cpu_dai, substream, NULL); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | #ifdef CONFIG_PM |
| 135 | |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 136 | static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 137 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 138 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 139 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 140 | |
| 141 | if (!cpu_dai->active) |
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 | priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0); |
| 145 | priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1); |
| 146 | priv->to = __raw_readl(ssp->mmio_base + SSTO); |
| 147 | priv->psp = __raw_readl(ssp->mmio_base + SSPSP); |
| 148 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 149 | pxa_ssp_disable(ssp); |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 150 | clk_disable_unprepare(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 154 | static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 155 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 156 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 157 | struct ssp_device *ssp = priv->ssp; |
| 158 | uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 159 | |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 160 | clk_prepare_enable(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 161 | |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 162 | __raw_writel(sssr, ssp->mmio_base + SSSR); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 163 | __raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0); |
| 164 | __raw_writel(priv->cr1, ssp->mmio_base + SSCR1); |
| 165 | __raw_writel(priv->to, ssp->mmio_base + SSTO); |
| 166 | __raw_writel(priv->psp, ssp->mmio_base + SSPSP); |
Daniel Mack | 026384d | 2010-02-02 18:45:27 +0800 | [diff] [blame] | 167 | |
| 168 | if (cpu_dai->active) |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 169 | pxa_ssp_enable(ssp); |
Daniel Mack | 026384d | 2010-02-02 18:45:27 +0800 | [diff] [blame] | 170 | else |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 171 | clk_disable_unprepare(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | #else |
| 177 | #define pxa_ssp_suspend NULL |
| 178 | #define pxa_ssp_resume NULL |
| 179 | #endif |
| 180 | |
| 181 | /** |
| 182 | * ssp_set_clkdiv - set SSP clock divider |
| 183 | * @div: serial clock rate divider |
| 184 | */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 185 | static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 186 | { |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 187 | u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 188 | |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 189 | if (ssp->type == PXA25x_SSP) { |
Philipp Zabel | 1a29728 | 2009-04-17 11:39:38 +0200 | [diff] [blame] | 190 | sscr0 &= ~0x0000ff00; |
| 191 | sscr0 |= ((div - 2)/2) << 8; /* 2..512 */ |
| 192 | } else { |
| 193 | sscr0 &= ~0x000fff00; |
| 194 | sscr0 |= (div - 1) << 8; /* 1..4096 */ |
| 195 | } |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 196 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Philipp Zabel | 1a29728 | 2009-04-17 11:39:38 +0200 | [diff] [blame] | 197 | } |
| 198 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 199 | /* |
| 200 | * Set the SSP ports SYSCLK. |
| 201 | */ |
| 202 | static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai, |
| 203 | int clk_id, unsigned int freq, int dir) |
| 204 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 205 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 206 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 207 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 208 | u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & |
Daniel Mack | 05f3828 | 2018-05-21 23:50:17 +0200 | [diff] [blame] | 209 | ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 210 | |
Daniel Mack | 90eb6b5 | 2018-07-02 17:11:00 +0200 | [diff] [blame] | 211 | if (priv->extclk) { |
| 212 | int ret; |
| 213 | |
| 214 | /* |
| 215 | * For DT based boards, if an extclk is given, use it |
| 216 | * here and configure PXA_SSP_CLK_EXT. |
| 217 | */ |
| 218 | |
| 219 | ret = clk_set_rate(priv->extclk, freq); |
| 220 | if (ret < 0) |
| 221 | return ret; |
| 222 | |
| 223 | clk_id = PXA_SSP_CLK_EXT; |
| 224 | } |
| 225 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 226 | dev_dbg(&ssp->pdev->dev, |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 227 | "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] | 228 | cpu_dai->id, clk_id, freq); |
| 229 | |
| 230 | switch (clk_id) { |
| 231 | case PXA_SSP_CLK_NET_PLL: |
| 232 | sscr0 |= SSCR0_MOD; |
| 233 | break; |
| 234 | case PXA_SSP_CLK_PLL: |
| 235 | /* Internal PLL is fixed */ |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 236 | if (ssp->type == PXA25x_SSP) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 237 | priv->sysclk = 1843200; |
| 238 | else |
| 239 | priv->sysclk = 13000000; |
| 240 | break; |
| 241 | case PXA_SSP_CLK_EXT: |
| 242 | priv->sysclk = freq; |
| 243 | sscr0 |= SSCR0_ECS; |
| 244 | break; |
| 245 | case PXA_SSP_CLK_NET: |
| 246 | priv->sysclk = freq; |
| 247 | sscr0 |= SSCR0_NCS | SSCR0_MOD; |
| 248 | break; |
| 249 | case PXA_SSP_CLK_AUDIO: |
| 250 | priv->sysclk = 0; |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 251 | pxa_ssp_set_scr(ssp, 1); |
Daniel Mack | 20a41ea | 2009-03-04 21:16:57 +0100 | [diff] [blame] | 252 | sscr0 |= SSCR0_ACS; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 253 | break; |
| 254 | default: |
| 255 | return -ENODEV; |
| 256 | } |
| 257 | |
| 258 | /* The SSP clock must be disabled when changing SSP clock mode |
| 259 | * on PXA2xx. On PXA3xx it must be enabled when doing so. */ |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 260 | if (ssp->type != PXA3xx_SSP) |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 261 | clk_disable_unprepare(ssp->clk); |
Daniel Mack | 05f3828 | 2018-05-21 23:50:17 +0200 | [diff] [blame] | 262 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 263 | if (ssp->type != PXA3xx_SSP) |
Dmitry Eremin-Solenikov | 6d3efa4 | 2014-11-15 22:51:46 +0300 | [diff] [blame] | 264 | clk_prepare_enable(ssp->clk); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | /* |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 270 | * Configure the PLL frequency pxa27x and (afaik - pxa320 only) |
| 271 | */ |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 272 | 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] | 273 | { |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 274 | struct ssp_device *ssp = priv->ssp; |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 275 | u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 276 | |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 277 | if (ssp->type == PXA3xx_SSP) |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 278 | pxa_ssp_write_reg(ssp, SSACDD, 0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 279 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 280 | switch (freq) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 281 | case 5622000: |
| 282 | break; |
| 283 | case 11345000: |
| 284 | ssacd |= (0x1 << 4); |
| 285 | break; |
| 286 | case 12235000: |
| 287 | ssacd |= (0x2 << 4); |
| 288 | break; |
| 289 | case 14857000: |
| 290 | ssacd |= (0x3 << 4); |
| 291 | break; |
| 292 | case 32842000: |
| 293 | ssacd |= (0x4 << 4); |
| 294 | break; |
| 295 | case 48000000: |
| 296 | ssacd |= (0x5 << 4); |
| 297 | break; |
| 298 | case 0: |
| 299 | /* Disable */ |
| 300 | break; |
| 301 | |
| 302 | default: |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 303 | /* PXA3xx has a clock ditherer which can be used to generate |
| 304 | * a wider range of frequencies - calculate a value for it. |
| 305 | */ |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 306 | if (ssp->type == PXA3xx_SSP) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 307 | u32 val; |
| 308 | u64 tmp = 19968; |
Codrut Grosu | 1dbe692 | 2017-02-25 23:33:50 +0200 | [diff] [blame] | 309 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 310 | tmp *= 1000000; |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 311 | do_div(tmp, freq); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 312 | val = tmp; |
| 313 | |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 314 | val = (val << 16) | 64; |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 315 | pxa_ssp_write_reg(ssp, SSACDD, val); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 316 | |
| 317 | ssacd |= (0x6 << 4); |
| 318 | |
| 319 | dev_dbg(&ssp->pdev->dev, |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 320 | "Using SSACDD %x to supply %uHz\n", |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 321 | val, freq); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 322 | break; |
| 323 | } |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 324 | |
| 325 | return -EINVAL; |
| 326 | } |
| 327 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 328 | pxa_ssp_write_reg(ssp, SSACD, ssacd); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Set the active slots in TDM/Network mode |
| 335 | */ |
| 336 | 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] | 337 | 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] | 338 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 339 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 340 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 341 | u32 sscr0; |
| 342 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 343 | sscr0 = pxa_ssp_read_reg(ssp, SSCR0); |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 344 | sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 345 | |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 346 | /* set slot width */ |
| 347 | if (slot_width > 16) |
| 348 | sscr0 |= SSCR0_EDSS | SSCR0_DataSize(slot_width - 16); |
| 349 | else |
| 350 | sscr0 |= SSCR0_DataSize(slot_width); |
| 351 | |
| 352 | if (slots > 1) { |
| 353 | /* enable network mode */ |
| 354 | sscr0 |= SSCR0_MOD; |
| 355 | |
| 356 | /* set number of active slots */ |
| 357 | sscr0 |= SSCR0_SlotsPerFrm(slots); |
| 358 | |
| 359 | /* set active slot mask */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 360 | pxa_ssp_write_reg(ssp, SSTSA, tx_mask); |
| 361 | pxa_ssp_write_reg(ssp, SSRSA, rx_mask); |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 362 | } |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 363 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 364 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Tristate the SSP DAI lines |
| 370 | */ |
| 371 | static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai, |
| 372 | int tristate) |
| 373 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 374 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 375 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 376 | u32 sscr1; |
| 377 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 378 | sscr1 = pxa_ssp_read_reg(ssp, SSCR1); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 379 | if (tristate) |
| 380 | sscr1 &= ~SSCR1_TTE; |
| 381 | else |
| 382 | sscr1 |= SSCR1_TTE; |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 383 | pxa_ssp_write_reg(ssp, SSCR1, sscr1); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 388 | static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
| 389 | unsigned int fmt) |
| 390 | { |
| 391 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
| 392 | |
| 393 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 394 | case SND_SOC_DAIFMT_CBM_CFM: |
| 395 | case SND_SOC_DAIFMT_CBM_CFS: |
| 396 | case SND_SOC_DAIFMT_CBS_CFS: |
| 397 | break; |
| 398 | default: |
| 399 | return -EINVAL; |
| 400 | } |
| 401 | |
| 402 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 403 | case SND_SOC_DAIFMT_NB_NF: |
| 404 | case SND_SOC_DAIFMT_NB_IF: |
| 405 | case SND_SOC_DAIFMT_IB_IF: |
| 406 | case SND_SOC_DAIFMT_IB_NF: |
| 407 | break; |
| 408 | default: |
| 409 | return -EINVAL; |
| 410 | } |
| 411 | |
| 412 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 413 | case SND_SOC_DAIFMT_I2S: |
| 414 | case SND_SOC_DAIFMT_DSP_A: |
| 415 | case SND_SOC_DAIFMT_DSP_B: |
| 416 | break; |
| 417 | |
| 418 | default: |
| 419 | return -EINVAL; |
| 420 | } |
| 421 | |
| 422 | /* Settings will be applied in hw_params() */ |
| 423 | priv->dai_fmt = fmt; |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 428 | /* |
| 429 | * Set up the SSP DAI format. |
| 430 | * The SSP Port must be inactive before calling this function as the |
| 431 | * physical interface format is changed. |
| 432 | */ |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 433 | static int pxa_ssp_configure_dai_fmt(struct ssp_priv *priv) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 434 | { |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 435 | struct ssp_device *ssp = priv->ssp; |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 436 | u32 sscr0, sscr1, sspsp, scfr; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 437 | |
Daniel Mack | cbf1146 | 2009-03-10 16:41:00 +0100 | [diff] [blame] | 438 | /* check if we need to change anything at all */ |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 439 | if (priv->configured_dai_fmt == priv->dai_fmt) |
Daniel Mack | cbf1146 | 2009-03-10 16:41:00 +0100 | [diff] [blame] | 440 | return 0; |
| 441 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 442 | /* reset port settings */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 443 | sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 444 | ~(SSCR0_PSP | SSCR0_MOD); |
| 445 | sscr1 = pxa_ssp_read_reg(ssp, SSCR1) & |
| 446 | ~(SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR | |
| 447 | SSCR1_RWOT | SSCR1_TRAIL | SSCR1_TFT | SSCR1_RFT); |
| 448 | sspsp = pxa_ssp_read_reg(ssp, SSPSP) & |
| 449 | ~(SSPSP_SFRMP | SSPSP_SCMODE(3)); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 450 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 451 | sscr1 |= SSCR1_RxTresh(8) | SSCR1_TxTresh(7); |
| 452 | |
| 453 | switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 454 | case SND_SOC_DAIFMT_CBM_CFM: |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 455 | sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 456 | break; |
| 457 | case SND_SOC_DAIFMT_CBM_CFS: |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 458 | sscr1 |= SSCR1_SCLKDIR | SSCR1_SCFR; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 459 | break; |
| 460 | case SND_SOC_DAIFMT_CBS_CFS: |
| 461 | break; |
| 462 | default: |
| 463 | return -EINVAL; |
| 464 | } |
| 465 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 466 | switch (priv->dai_fmt & SND_SOC_DAIFMT_INV_MASK) { |
Daniel Ribeiro | fa44c07 | 2009-06-10 15:23:24 -0300 | [diff] [blame] | 467 | case SND_SOC_DAIFMT_NB_NF: |
| 468 | sspsp |= SSPSP_SFRMP; |
| 469 | break; |
| 470 | case SND_SOC_DAIFMT_NB_IF: |
| 471 | break; |
| 472 | case SND_SOC_DAIFMT_IB_IF: |
| 473 | sspsp |= SSPSP_SCMODE(2); |
| 474 | break; |
| 475 | case SND_SOC_DAIFMT_IB_NF: |
| 476 | sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP; |
| 477 | break; |
| 478 | default: |
| 479 | return -EINVAL; |
| 480 | } |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 481 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 482 | switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 483 | case SND_SOC_DAIFMT_I2S: |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 484 | sscr0 |= SSCR0_PSP; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 485 | sscr1 |= SSCR1_RWOT | SSCR1_TRAIL; |
Mark Brown | 0ce36c5 | 2009-03-13 14:26:08 +0000 | [diff] [blame] | 486 | /* See hw_params() */ |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 487 | break; |
| 488 | |
| 489 | case SND_SOC_DAIFMT_DSP_A: |
| 490 | sspsp |= SSPSP_FSRT; |
Gustavo A. R. Silva | e0431de | 2018-07-02 07:17:07 -0500 | [diff] [blame] | 491 | /* fall through */ |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 492 | case SND_SOC_DAIFMT_DSP_B: |
| 493 | sscr0 |= SSCR0_MOD | SSCR0_PSP; |
| 494 | sscr1 |= SSCR1_TRAIL | SSCR1_RWOT; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 495 | break; |
| 496 | |
| 497 | default: |
| 498 | return -EINVAL; |
| 499 | } |
| 500 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 501 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
| 502 | pxa_ssp_write_reg(ssp, SSCR1, sscr1); |
| 503 | pxa_ssp_write_reg(ssp, SSPSP, sspsp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 504 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 505 | switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
Haojian Zhuang | f5d1e5e | 2010-08-13 21:55:35 +0800 | [diff] [blame] | 506 | case SND_SOC_DAIFMT_CBM_CFM: |
| 507 | case SND_SOC_DAIFMT_CBM_CFS: |
| 508 | scfr = pxa_ssp_read_reg(ssp, SSCR1) | SSCR1_SCFR; |
| 509 | pxa_ssp_write_reg(ssp, SSCR1, scfr); |
| 510 | |
| 511 | while (pxa_ssp_read_reg(ssp, SSSR) & SSSR_BSY) |
| 512 | cpu_relax(); |
| 513 | break; |
| 514 | } |
| 515 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 516 | dump_registers(ssp); |
| 517 | |
| 518 | /* Since we are configuring the timings for the format by hand |
| 519 | * we have to defer some things until hw_params() where we |
| 520 | * know parameters like the sample size. |
| 521 | */ |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 522 | priv->configured_dai_fmt = priv->dai_fmt; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 527 | struct pxa_ssp_clock_mode { |
| 528 | int rate; |
| 529 | int pll; |
| 530 | u8 acds; |
| 531 | u8 scdb; |
| 532 | }; |
| 533 | |
| 534 | static const struct pxa_ssp_clock_mode pxa_ssp_clock_modes[] = { |
| 535 | { .rate = 8000, .pll = 32842000, .acds = SSACD_ACDS_32, .scdb = SSACD_SCDB_4X }, |
| 536 | { .rate = 11025, .pll = 5622000, .acds = SSACD_ACDS_4, .scdb = SSACD_SCDB_4X }, |
| 537 | { .rate = 16000, .pll = 32842000, .acds = SSACD_ACDS_16, .scdb = SSACD_SCDB_4X }, |
| 538 | { .rate = 22050, .pll = 5622000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X }, |
| 539 | { .rate = 44100, .pll = 11345000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X }, |
| 540 | { .rate = 48000, .pll = 12235000, .acds = SSACD_ACDS_2, .scdb = SSACD_SCDB_4X }, |
| 541 | { .rate = 96000, .pll = 12235000, .acds = SSACD_ACDS_4, .scdb = SSACD_SCDB_1X }, |
| 542 | {} |
| 543 | }; |
| 544 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 545 | /* |
| 546 | * Set the SSP audio DMA parameters and sample size. |
| 547 | * Can be called multiple times by oss emulation. |
| 548 | */ |
| 549 | static int pxa_ssp_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 550 | struct snd_pcm_hw_params *params, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 551 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 552 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 553 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 554 | struct ssp_device *ssp = priv->ssp; |
Eric Miao | 2d7e71f | 2009-04-23 17:05:38 +0800 | [diff] [blame] | 555 | int chn = params_channels(params); |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 556 | u32 sscr0, sspsp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 557 | int width = snd_pcm_format_physical_width(params_format(params)); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 558 | int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf; |
Daniel Mack | d65a145 | 2013-08-12 10:42:39 +0200 | [diff] [blame] | 559 | struct snd_dmaengine_dai_dma_data *dma_data; |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 560 | int rate = params_rate(params); |
| 561 | int bclk = rate * chn * (width / 8); |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 562 | int ret; |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 563 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 564 | dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 565 | |
Philipp Zabel | 9242906 | 2009-03-19 09:32:01 +0100 | [diff] [blame] | 566 | /* Network mode with one active slot (ttsa == 1) can be used |
| 567 | * to force 16-bit frame width on the wire (for S16_LE), even |
| 568 | * with two channels. Use 16-bit DMA transfers for this case. |
| 569 | */ |
guoyh | d93ca1a | 2012-05-07 15:34:24 +0800 | [diff] [blame] | 570 | pxa_ssp_set_dma_params(ssp, |
| 571 | ((chn == 2) && (ttsa != 1)) || (width == 32), |
| 572 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data); |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 573 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 574 | /* 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] | 575 | if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 576 | return 0; |
| 577 | |
Daniel Mack | 737e370 | 2018-05-21 23:50:16 +0200 | [diff] [blame] | 578 | ret = pxa_ssp_configure_dai_fmt(priv); |
| 579 | if (ret < 0) |
| 580 | return ret; |
| 581 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 582 | /* clear selected SSP bits */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 583 | sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 584 | |
| 585 | /* bit size */ |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 586 | switch (params_format(params)) { |
| 587 | case SNDRV_PCM_FORMAT_S16_LE: |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 588 | if (ssp->type == PXA3xx_SSP) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 589 | sscr0 |= SSCR0_FPCKE; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 590 | sscr0 |= SSCR0_DataSize(16); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 591 | break; |
| 592 | case SNDRV_PCM_FORMAT_S24_LE: |
| 593 | sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8)); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 594 | break; |
| 595 | case SNDRV_PCM_FORMAT_S32_LE: |
| 596 | sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16)); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 597 | break; |
| 598 | } |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 599 | pxa_ssp_write_reg(ssp, SSCR0, sscr0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 600 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 601 | if (sscr0 & SSCR0_ACS) { |
| 602 | ret = pxa_ssp_set_pll(priv, bclk); |
| 603 | |
| 604 | /* |
| 605 | * If we were able to generate the bclk directly, |
| 606 | * all is fine. Otherwise, look up the closest rate |
| 607 | * from the table and also set the dividers. |
| 608 | */ |
| 609 | |
| 610 | if (ret < 0) { |
| 611 | const struct pxa_ssp_clock_mode *m; |
| 612 | int ssacd, acds; |
| 613 | |
| 614 | for (m = pxa_ssp_clock_modes; m->rate; m++) { |
| 615 | if (m->rate == rate) |
| 616 | break; |
| 617 | } |
| 618 | |
| 619 | if (!m->rate) |
| 620 | return -EINVAL; |
| 621 | |
| 622 | acds = m->acds; |
| 623 | |
| 624 | /* The values in the table are for 16 bits */ |
| 625 | if (width == 32) |
| 626 | acds--; |
| 627 | |
| 628 | ret = pxa_ssp_set_pll(priv, bclk); |
| 629 | if (ret < 0) |
| 630 | return ret; |
| 631 | |
| 632 | ssacd = pxa_ssp_read_reg(ssp, SSACD); |
| 633 | ssacd &= ~(SSACD_ACDS(7) | SSACD_SCDB_1X); |
| 634 | ssacd |= SSACD_ACDS(m->acds); |
| 635 | ssacd |= m->scdb; |
| 636 | pxa_ssp_write_reg(ssp, SSACD, ssacd); |
| 637 | } |
| 638 | } else if (sscr0 & SSCR0_ECS) { |
| 639 | /* |
| 640 | * For setups with external clocking, the PLL and its diviers |
| 641 | * are not active. Instead, the SCR bits in SSCR0 can be used |
| 642 | * to divide the clock. |
| 643 | */ |
| 644 | pxa_ssp_set_scr(ssp, bclk / rate); |
| 645 | } |
| 646 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 647 | switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 648 | case SND_SOC_DAIFMT_I2S: |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 649 | sspsp = pxa_ssp_read_reg(ssp, SSPSP); |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 650 | |
Daniel Mack | 0573937 | 2018-06-29 14:59:40 +0200 | [diff] [blame] | 651 | if (((priv->sysclk / bclk) == 64) && (width == 16)) { |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 652 | /* This is a special case where the bitclk is 64fs |
Codrut Grosu | 34e8243 | 2017-02-25 23:40:31 +0200 | [diff] [blame] | 653 | * and we're not dealing with 2*32 bits of audio |
| 654 | * samples. |
| 655 | * |
| 656 | * The SSP values used for that are all found out by |
| 657 | * trying and failing a lot; some of the registers |
| 658 | * needed for that mode are only available on PXA3xx. |
| 659 | */ |
Qiao Zhou | 972a55b | 2012-06-04 10:41:04 +0800 | [diff] [blame] | 660 | if (ssp->type != PXA3xx_SSP) |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 661 | return -EINVAL; |
| 662 | |
| 663 | sspsp |= SSPSP_SFRMWDTH(width * 2); |
| 664 | sspsp |= SSPSP_SFRMDLY(width * 4); |
| 665 | sspsp |= SSPSP_EDMYSTOP(3); |
| 666 | sspsp |= SSPSP_DMYSTOP(3); |
| 667 | sspsp |= SSPSP_DMYSTRT(1); |
Mark Brown | 0ce36c5 | 2009-03-13 14:26:08 +0000 | [diff] [blame] | 668 | } else { |
| 669 | /* The frame width is the width the LRCLK is |
| 670 | * asserted for; the delay is expressed in |
| 671 | * half cycle units. We need the extra cycle |
| 672 | * because the data starts clocking out one BCLK |
| 673 | * after LRCLK changes polarity. |
| 674 | */ |
| 675 | sspsp |= SSPSP_SFRMWDTH(width + 1); |
| 676 | sspsp |= SSPSP_SFRMDLY((width + 1) * 2); |
| 677 | sspsp |= SSPSP_DMYSTRT(1); |
| 678 | } |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 679 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 680 | pxa_ssp_write_reg(ssp, SSPSP, sspsp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 681 | break; |
| 682 | default: |
| 683 | break; |
| 684 | } |
| 685 | |
Daniel Mack | 72d7466 | 2009-03-12 11:27:49 +0100 | [diff] [blame] | 686 | /* When we use a network mode, we always require TDM slots |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 687 | * - complain loudly and fail if they've not been set up yet. |
| 688 | */ |
Philipp Zabel | 9242906 | 2009-03-19 09:32:01 +0100 | [diff] [blame] | 689 | if ((sscr0 & SSCR0_MOD) && !ttsa) { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 690 | dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n"); |
| 691 | return -EINVAL; |
| 692 | } |
| 693 | |
| 694 | dump_registers(ssp); |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 699 | static void pxa_ssp_set_running_bit(struct snd_pcm_substream *substream, |
| 700 | struct ssp_device *ssp, int value) |
| 701 | { |
| 702 | uint32_t sscr0 = pxa_ssp_read_reg(ssp, SSCR0); |
| 703 | uint32_t sscr1 = pxa_ssp_read_reg(ssp, SSCR1); |
| 704 | uint32_t sspsp = pxa_ssp_read_reg(ssp, SSPSP); |
| 705 | uint32_t sssr = pxa_ssp_read_reg(ssp, SSSR); |
| 706 | |
| 707 | if (value && (sscr0 & SSCR0_SSE)) |
| 708 | pxa_ssp_write_reg(ssp, SSCR0, sscr0 & ~SSCR0_SSE); |
| 709 | |
| 710 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 711 | if (value) |
| 712 | sscr1 |= SSCR1_TSRE; |
| 713 | else |
| 714 | sscr1 &= ~SSCR1_TSRE; |
| 715 | } else { |
| 716 | if (value) |
| 717 | sscr1 |= SSCR1_RSRE; |
| 718 | else |
| 719 | sscr1 &= ~SSCR1_RSRE; |
| 720 | } |
| 721 | |
| 722 | pxa_ssp_write_reg(ssp, SSCR1, sscr1); |
| 723 | |
| 724 | if (value) { |
| 725 | pxa_ssp_write_reg(ssp, SSSR, sssr); |
| 726 | pxa_ssp_write_reg(ssp, SSPSP, sspsp); |
| 727 | pxa_ssp_write_reg(ssp, SSCR0, sscr0 | SSCR0_SSE); |
| 728 | } |
| 729 | } |
| 730 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 731 | static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 732 | struct snd_soc_dai *cpu_dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 733 | { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 734 | int ret = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 735 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai); |
Eric Miao | f9efc9d | 2010-02-09 19:46:01 +0800 | [diff] [blame] | 736 | struct ssp_device *ssp = priv->ssp; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 737 | int val; |
| 738 | |
| 739 | switch (cmd) { |
| 740 | case SNDRV_PCM_TRIGGER_RESUME: |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 741 | pxa_ssp_enable(ssp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 742 | break; |
| 743 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 744 | pxa_ssp_set_running_bit(substream, ssp, 1); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 745 | val = pxa_ssp_read_reg(ssp, SSSR); |
| 746 | pxa_ssp_write_reg(ssp, SSSR, val); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 747 | break; |
| 748 | case SNDRV_PCM_TRIGGER_START: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 749 | pxa_ssp_set_running_bit(substream, ssp, 1); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 750 | break; |
| 751 | case SNDRV_PCM_TRIGGER_STOP: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 752 | pxa_ssp_set_running_bit(substream, ssp, 0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 753 | break; |
| 754 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 755 | pxa_ssp_disable(ssp); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 756 | break; |
| 757 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Daniel Mack | 273b72c | 2012-03-19 09:12:53 +0100 | [diff] [blame] | 758 | pxa_ssp_set_running_bit(substream, ssp, 0); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 759 | break; |
| 760 | |
| 761 | default: |
| 762 | ret = -EINVAL; |
| 763 | } |
| 764 | |
| 765 | dump_registers(ssp); |
| 766 | |
| 767 | return ret; |
| 768 | } |
| 769 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 770 | static int pxa_ssp_probe(struct snd_soc_dai *dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 771 | { |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 772 | struct device *dev = dai->dev; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 773 | struct ssp_priv *priv; |
| 774 | int ret; |
| 775 | |
| 776 | priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL); |
| 777 | if (!priv) |
| 778 | return -ENOMEM; |
| 779 | |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 780 | if (dev->of_node) { |
| 781 | struct device_node *ssp_handle; |
| 782 | |
| 783 | ssp_handle = of_parse_phandle(dev->of_node, "port", 0); |
| 784 | if (!ssp_handle) { |
| 785 | dev_err(dev, "unable to get 'port' phandle\n"); |
Dan Carpenter | 4548728 | 2014-07-31 15:57:51 +0300 | [diff] [blame] | 786 | ret = -ENODEV; |
| 787 | goto err_priv; |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | priv->ssp = pxa_ssp_request_of(ssp_handle, "SoC audio"); |
| 791 | if (priv->ssp == NULL) { |
| 792 | ret = -ENODEV; |
| 793 | goto err_priv; |
| 794 | } |
Daniel Mack | 90eb6b5 | 2018-07-02 17:11:00 +0200 | [diff] [blame] | 795 | |
| 796 | priv->extclk = devm_clk_get(dev, "extclk"); |
| 797 | if (IS_ERR(priv->extclk)) { |
| 798 | ret = PTR_ERR(priv->extclk); |
| 799 | if (ret == -EPROBE_DEFER) |
| 800 | return ret; |
| 801 | |
| 802 | priv->extclk = NULL; |
| 803 | } |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 804 | } else { |
| 805 | priv->ssp = pxa_ssp_request(dai->id + 1, "SoC audio"); |
| 806 | if (priv->ssp == NULL) { |
| 807 | ret = -ENODEV; |
| 808 | goto err_priv; |
| 809 | } |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 810 | } |
| 811 | |
Daniel Mack | a5735b7 | 2009-04-15 20:24:45 +0200 | [diff] [blame] | 812 | priv->dai_fmt = (unsigned int) -1; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 813 | snd_soc_dai_set_drvdata(dai, priv); |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 814 | |
| 815 | return 0; |
| 816 | |
| 817 | err_priv: |
| 818 | kfree(priv); |
| 819 | return ret; |
| 820 | } |
| 821 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 822 | static int pxa_ssp_remove(struct snd_soc_dai *dai) |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 823 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 824 | struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai); |
| 825 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 826 | pxa_ssp_free(priv->ssp); |
Axel Lin | 014a275 | 2010-08-25 16:59:11 +0800 | [diff] [blame] | 827 | kfree(priv); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 828 | return 0; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | #define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
| 832 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ |
Qiao Zhou | 8d8bf58 | 2012-03-08 10:02:36 +0800 | [diff] [blame] | 833 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 834 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \ |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 835 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
| 836 | |
Daniel Mack | 9301503 | 2014-08-13 21:51:06 +0200 | [diff] [blame] | 837 | #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] | 838 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 839 | static const struct snd_soc_dai_ops pxa_ssp_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 840 | .startup = pxa_ssp_startup, |
| 841 | .shutdown = pxa_ssp_shutdown, |
| 842 | .trigger = pxa_ssp_trigger, |
| 843 | .hw_params = pxa_ssp_hw_params, |
| 844 | .set_sysclk = pxa_ssp_set_dai_sysclk, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 845 | .set_fmt = pxa_ssp_set_dai_fmt, |
| 846 | .set_tdm_slot = pxa_ssp_set_dai_tdm_slot, |
| 847 | .set_tristate = pxa_ssp_set_dai_tristate, |
| 848 | }; |
| 849 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 850 | static struct snd_soc_dai_driver pxa_ssp_dai = { |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 851 | .probe = pxa_ssp_probe, |
| 852 | .remove = pxa_ssp_remove, |
| 853 | .suspend = pxa_ssp_suspend, |
| 854 | .resume = pxa_ssp_resume, |
| 855 | .playback = { |
| 856 | .channels_min = 1, |
Graeme Gregory | f34762b | 2009-09-25 13:30:26 +0100 | [diff] [blame] | 857 | .channels_max = 8, |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 858 | .rates = PXA_SSP_RATES, |
| 859 | .formats = PXA_SSP_FORMATS, |
| 860 | }, |
| 861 | .capture = { |
| 862 | .channels_min = 1, |
Graeme Gregory | f34762b | 2009-09-25 13:30:26 +0100 | [diff] [blame] | 863 | .channels_max = 8, |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 864 | .rates = PXA_SSP_RATES, |
| 865 | .formats = PXA_SSP_FORMATS, |
| 866 | }, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 867 | .ops = &pxa_ssp_dai_ops, |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 868 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 869 | |
Kuninori Morimoto | e580f1c | 2013-03-21 03:34:12 -0700 | [diff] [blame] | 870 | static const struct snd_soc_component_driver pxa_ssp_component = { |
| 871 | .name = "pxa-ssp", |
Kuninori Morimoto | f8772e1 | 2019-10-02 14:33:50 +0900 | [diff] [blame^] | 872 | .pcm_construct = pxa2xx_soc_pcm_new, |
| 873 | .pcm_destruct = pxa2xx_soc_pcm_free, |
| 874 | .open = pxa2xx_soc_pcm_open, |
| 875 | .close = pxa2xx_soc_pcm_close, |
| 876 | .ioctl = snd_soc_pcm_lib_ioctl, |
| 877 | .hw_params = pxa2xx_soc_pcm_hw_params, |
| 878 | .hw_free = pxa2xx_soc_pcm_hw_free, |
| 879 | .prepare = pxa2xx_soc_pcm_prepare, |
| 880 | .trigger = pxa2xx_soc_pcm_trigger, |
| 881 | .pointer = pxa2xx_soc_pcm_pointer, |
| 882 | .mmap = pxa2xx_soc_pcm_mmap, |
Kuninori Morimoto | e580f1c | 2013-03-21 03:34:12 -0700 | [diff] [blame] | 883 | }; |
| 884 | |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 885 | #ifdef CONFIG_OF |
| 886 | static const struct of_device_id pxa_ssp_of_ids[] = { |
| 887 | { .compatible = "mrvl,pxa-ssp-dai" }, |
Stephen Boyd | 4c715c7 | 2014-05-23 17:16:49 -0700 | [diff] [blame] | 888 | {} |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 889 | }; |
Luis de Bethencourt | baafd37 | 2015-09-03 13:00:03 +0200 | [diff] [blame] | 890 | MODULE_DEVICE_TABLE(of, pxa_ssp_of_ids); |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 891 | #endif |
| 892 | |
Bill Pemberton | 570f6fe | 2012-12-07 09:26:17 -0500 | [diff] [blame] | 893 | static int asoc_ssp_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 894 | { |
Axel Lin | 637ce53 | 2015-08-28 10:48:35 +0800 | [diff] [blame] | 895 | return devm_snd_soc_register_component(&pdev->dev, &pxa_ssp_component, |
| 896 | &pxa_ssp_dai, 1); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static struct platform_driver asoc_ssp_driver = { |
| 900 | .driver = { |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 901 | .name = "pxa-ssp-dai", |
Daniel Mack | 2023c90 | 2013-08-12 10:42:38 +0200 | [diff] [blame] | 902 | .of_match_table = of_match_ptr(pxa_ssp_of_ids), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 903 | }, |
| 904 | |
| 905 | .probe = asoc_ssp_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 906 | }; |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 907 | |
Axel Lin | 2f702a1 | 2011-11-25 10:13:37 +0800 | [diff] [blame] | 908 | module_platform_driver(asoc_ssp_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 909 | |
Mark Brown | 1b340bd | 2008-07-30 19:12:04 +0100 | [diff] [blame] | 910 | /* Module information */ |
| 911 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 912 | MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface"); |
| 913 | MODULE_LICENSE("GPL"); |
Andrea Adami | e5b7d71 | 2016-05-06 17:27:34 +0200 | [diff] [blame] | 914 | MODULE_ALIAS("platform:pxa-ssp-dai"); |