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