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