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