Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 1 | /* |
Stephen Warren | ef280d3 | 2012-04-05 15:54:53 -0600 | [diff] [blame] | 2 | * tegra20_spdif.c - Tegra20 SPDIF driver |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 3 | * |
| 4 | * Author: Stephen Warren <swarren@nvidia.com> |
Stephen Warren | 518de86 | 2012-03-20 14:55:49 -0600 | [diff] [blame] | 5 | * Copyright (C) 2011-2012 - NVIDIA, Inc. |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <linux/clk.h> |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 24 | #include <linux/debugfs.h> |
| 25 | #include <linux/device.h> |
Stephen Warren | 7613c50 | 2012-04-06 11:12:25 -0600 | [diff] [blame] | 26 | #include <linux/io.h> |
| 27 | #include <linux/module.h> |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 29 | #include <linux/pm_runtime.h> |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 30 | #include <linux/seq_file.h> |
| 31 | #include <linux/slab.h> |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 32 | #include <sound/core.h> |
| 33 | #include <sound/pcm.h> |
| 34 | #include <sound/pcm_params.h> |
| 35 | #include <sound/soc.h> |
| 36 | |
Stephen Warren | ef280d3 | 2012-04-05 15:54:53 -0600 | [diff] [blame] | 37 | #include "tegra20_spdif.h" |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 38 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 39 | #define DRV_NAME "tegra20-spdif" |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 40 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 41 | static inline void tegra20_spdif_write(struct tegra20_spdif *spdif, u32 reg, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 42 | u32 val) |
| 43 | { |
| 44 | __raw_writel(val, spdif->regs + reg); |
| 45 | } |
| 46 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 47 | static inline u32 tegra20_spdif_read(struct tegra20_spdif *spdif, u32 reg) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 48 | { |
| 49 | return __raw_readl(spdif->regs + reg); |
| 50 | } |
| 51 | |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 52 | static int tegra20_spdif_runtime_suspend(struct device *dev) |
| 53 | { |
| 54 | struct tegra20_spdif *spdif = dev_get_drvdata(dev); |
| 55 | |
| 56 | clk_disable(spdif->clk_spdif_out); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static int tegra20_spdif_runtime_resume(struct device *dev) |
| 62 | { |
| 63 | struct tegra20_spdif *spdif = dev_get_drvdata(dev); |
| 64 | int ret; |
| 65 | |
| 66 | ret = clk_enable(spdif->clk_spdif_out); |
| 67 | if (ret) { |
| 68 | dev_err(dev, "clk_enable failed: %d\n", ret); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 75 | #ifdef CONFIG_DEBUG_FS |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 76 | static int tegra20_spdif_show(struct seq_file *s, void *unused) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 77 | { |
| 78 | #define REG(r) { r, #r } |
| 79 | static const struct { |
| 80 | int offset; |
| 81 | const char *name; |
| 82 | } regs[] = { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 83 | REG(TEGRA20_SPDIF_CTRL), |
| 84 | REG(TEGRA20_SPDIF_STATUS), |
| 85 | REG(TEGRA20_SPDIF_STROBE_CTRL), |
| 86 | REG(TEGRA20_SPDIF_DATA_FIFO_CSR), |
| 87 | REG(TEGRA20_SPDIF_CH_STA_RX_A), |
| 88 | REG(TEGRA20_SPDIF_CH_STA_RX_B), |
| 89 | REG(TEGRA20_SPDIF_CH_STA_RX_C), |
| 90 | REG(TEGRA20_SPDIF_CH_STA_RX_D), |
| 91 | REG(TEGRA20_SPDIF_CH_STA_RX_E), |
| 92 | REG(TEGRA20_SPDIF_CH_STA_RX_F), |
| 93 | REG(TEGRA20_SPDIF_CH_STA_TX_A), |
| 94 | REG(TEGRA20_SPDIF_CH_STA_TX_B), |
| 95 | REG(TEGRA20_SPDIF_CH_STA_TX_C), |
| 96 | REG(TEGRA20_SPDIF_CH_STA_TX_D), |
| 97 | REG(TEGRA20_SPDIF_CH_STA_TX_E), |
| 98 | REG(TEGRA20_SPDIF_CH_STA_TX_F), |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 99 | }; |
| 100 | #undef REG |
| 101 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 102 | struct tegra20_spdif *spdif = s->private; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 103 | int i; |
| 104 | |
| 105 | for (i = 0; i < ARRAY_SIZE(regs); i++) { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 106 | u32 val = tegra20_spdif_read(spdif, regs[i].offset); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 107 | seq_printf(s, "%s = %08x\n", regs[i].name, val); |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 113 | static int tegra20_spdif_debug_open(struct inode *inode, struct file *file) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 114 | { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 115 | return single_open(file, tegra20_spdif_show, inode->i_private); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 116 | } |
| 117 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 118 | static const struct file_operations tegra20_spdif_debug_fops = { |
| 119 | .open = tegra20_spdif_debug_open, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 120 | .read = seq_read, |
| 121 | .llseek = seq_lseek, |
| 122 | .release = single_release, |
| 123 | }; |
| 124 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 125 | static void tegra20_spdif_debug_add(struct tegra20_spdif *spdif) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 126 | { |
| 127 | spdif->debug = debugfs_create_file(DRV_NAME, S_IRUGO, |
| 128 | snd_soc_debugfs_root, spdif, |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 129 | &tegra20_spdif_debug_fops); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 130 | } |
| 131 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 132 | static void tegra20_spdif_debug_remove(struct tegra20_spdif *spdif) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 133 | { |
| 134 | if (spdif->debug) |
| 135 | debugfs_remove(spdif->debug); |
| 136 | } |
| 137 | #else |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 138 | static inline void tegra20_spdif_debug_add(struct tegra20_spdif *spdif) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 139 | { |
| 140 | } |
| 141 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 142 | static inline void tegra20_spdif_debug_remove(struct tegra20_spdif *spdif) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 143 | { |
| 144 | } |
| 145 | #endif |
| 146 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 147 | static int tegra20_spdif_hw_params(struct snd_pcm_substream *substream, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 148 | struct snd_pcm_hw_params *params, |
| 149 | struct snd_soc_dai *dai) |
| 150 | { |
| 151 | struct device *dev = substream->pcm->card->dev; |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 152 | struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai); |
Axel Lin | 4b8713f | 2011-10-02 21:07:02 +0800 | [diff] [blame] | 153 | int ret, spdifclock; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 154 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 155 | spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_PACK; |
| 156 | spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_BIT_MODE_MASK; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 157 | switch (params_format(params)) { |
| 158 | case SNDRV_PCM_FORMAT_S16_LE: |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 159 | spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_PACK; |
| 160 | spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_BIT_MODE_16BIT; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 161 | break; |
| 162 | default: |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 166 | switch (params_rate(params)) { |
| 167 | case 32000: |
| 168 | spdifclock = 4096000; |
| 169 | break; |
| 170 | case 44100: |
| 171 | spdifclock = 5644800; |
| 172 | break; |
| 173 | case 48000: |
| 174 | spdifclock = 6144000; |
| 175 | break; |
| 176 | case 88200: |
| 177 | spdifclock = 11289600; |
| 178 | break; |
| 179 | case 96000: |
| 180 | spdifclock = 12288000; |
| 181 | break; |
| 182 | case 176400: |
| 183 | spdifclock = 22579200; |
| 184 | break; |
| 185 | case 192000: |
| 186 | spdifclock = 24576000; |
| 187 | break; |
| 188 | default: |
| 189 | return -EINVAL; |
| 190 | } |
| 191 | |
| 192 | ret = clk_set_rate(spdif->clk_spdif_out, spdifclock); |
| 193 | if (ret) { |
| 194 | dev_err(dev, "Can't set SPDIF clock rate: %d\n", ret); |
| 195 | return ret; |
| 196 | } |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 201 | static void tegra20_spdif_start_playback(struct tegra20_spdif *spdif) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 202 | { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 203 | spdif->reg_ctrl |= TEGRA20_SPDIF_CTRL_TX_EN; |
| 204 | tegra20_spdif_write(spdif, TEGRA20_SPDIF_CTRL, spdif->reg_ctrl); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 205 | } |
| 206 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 207 | static void tegra20_spdif_stop_playback(struct tegra20_spdif *spdif) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 208 | { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 209 | spdif->reg_ctrl &= ~TEGRA20_SPDIF_CTRL_TX_EN; |
| 210 | tegra20_spdif_write(spdif, TEGRA20_SPDIF_CTRL, spdif->reg_ctrl); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 211 | } |
| 212 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 213 | static int tegra20_spdif_trigger(struct snd_pcm_substream *substream, int cmd, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 214 | struct snd_soc_dai *dai) |
| 215 | { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 216 | struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 217 | |
| 218 | switch (cmd) { |
| 219 | case SNDRV_PCM_TRIGGER_START: |
| 220 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 221 | case SNDRV_PCM_TRIGGER_RESUME: |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 222 | tegra20_spdif_start_playback(spdif); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 223 | break; |
| 224 | case SNDRV_PCM_TRIGGER_STOP: |
| 225 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 226 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 227 | tegra20_spdif_stop_playback(spdif); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 228 | break; |
| 229 | default: |
| 230 | return -EINVAL; |
| 231 | } |
| 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 236 | static int tegra20_spdif_probe(struct snd_soc_dai *dai) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 237 | { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 238 | struct tegra20_spdif *spdif = snd_soc_dai_get_drvdata(dai); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 239 | |
| 240 | dai->capture_dma_data = NULL; |
| 241 | dai->playback_dma_data = &spdif->playback_dma_data; |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 246 | static const struct snd_soc_dai_ops tegra20_spdif_dai_ops = { |
| 247 | .hw_params = tegra20_spdif_hw_params, |
| 248 | .trigger = tegra20_spdif_trigger, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 249 | }; |
| 250 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 251 | static struct snd_soc_dai_driver tegra20_spdif_dai = { |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 252 | .name = DRV_NAME, |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 253 | .probe = tegra20_spdif_probe, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 254 | .playback = { |
| 255 | .channels_min = 2, |
| 256 | .channels_max = 2, |
| 257 | .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | |
| 258 | SNDRV_PCM_RATE_48000, |
| 259 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 260 | }, |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 261 | .ops = &tegra20_spdif_dai_ops, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 262 | }; |
| 263 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 264 | static __devinit int tegra20_spdif_platform_probe(struct platform_device *pdev) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 265 | { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 266 | struct tegra20_spdif *spdif; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 267 | struct resource *mem, *memregion, *dmareq; |
| 268 | int ret; |
| 269 | |
Stephen Warren | 17933db | 2012-04-06 11:14:04 -0600 | [diff] [blame] | 270 | spdif = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_spdif), |
| 271 | GFP_KERNEL); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 272 | if (!spdif) { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 273 | dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n"); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 274 | ret = -ENOMEM; |
Stephen Warren | 17933db | 2012-04-06 11:14:04 -0600 | [diff] [blame] | 275 | goto err; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 276 | } |
| 277 | dev_set_drvdata(&pdev->dev, spdif); |
| 278 | |
| 279 | spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out"); |
| 280 | if (IS_ERR(spdif->clk_spdif_out)) { |
| 281 | pr_err("Can't retrieve spdif clock\n"); |
| 282 | ret = PTR_ERR(spdif->clk_spdif_out); |
Stephen Warren | 17933db | 2012-04-06 11:14:04 -0600 | [diff] [blame] | 283 | goto err; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 287 | if (!mem) { |
| 288 | dev_err(&pdev->dev, "No memory resource\n"); |
| 289 | ret = -ENODEV; |
| 290 | goto err_clk_put; |
| 291 | } |
| 292 | |
| 293 | dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 294 | if (!dmareq) { |
| 295 | dev_err(&pdev->dev, "No DMA resource\n"); |
| 296 | ret = -ENODEV; |
| 297 | goto err_clk_put; |
| 298 | } |
| 299 | |
Stephen Warren | 17933db | 2012-04-06 11:14:04 -0600 | [diff] [blame] | 300 | memregion = devm_request_mem_region(&pdev->dev, mem->start, |
| 301 | resource_size(mem), DRV_NAME); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 302 | if (!memregion) { |
| 303 | dev_err(&pdev->dev, "Memory region already claimed\n"); |
| 304 | ret = -EBUSY; |
| 305 | goto err_clk_put; |
| 306 | } |
| 307 | |
Stephen Warren | 17933db | 2012-04-06 11:14:04 -0600 | [diff] [blame] | 308 | spdif->regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 309 | if (!spdif->regs) { |
| 310 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 311 | ret = -ENOMEM; |
Stephen Warren | 17933db | 2012-04-06 11:14:04 -0600 | [diff] [blame] | 312 | goto err_clk_put; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 313 | } |
| 314 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 315 | spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 316 | spdif->playback_dma_data.wrap = 4; |
| 317 | spdif->playback_dma_data.width = 32; |
| 318 | spdif->playback_dma_data.req_sel = dmareq->start; |
| 319 | |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 320 | pm_runtime_enable(&pdev->dev); |
| 321 | if (!pm_runtime_enabled(&pdev->dev)) { |
| 322 | ret = tegra20_spdif_runtime_resume(&pdev->dev); |
| 323 | if (ret) |
| 324 | goto err_pm_disable; |
| 325 | } |
| 326 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 327 | ret = snd_soc_register_dai(&pdev->dev, &tegra20_spdif_dai); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 328 | if (ret) { |
| 329 | dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); |
| 330 | ret = -ENOMEM; |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 331 | goto err_suspend; |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 332 | } |
| 333 | |
Stephen Warren | 518de86 | 2012-03-20 14:55:49 -0600 | [diff] [blame] | 334 | ret = tegra_pcm_platform_register(&pdev->dev); |
| 335 | if (ret) { |
| 336 | dev_err(&pdev->dev, "Could not register PCM: %d\n", ret); |
| 337 | goto err_unregister_dai; |
| 338 | } |
| 339 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 340 | tegra20_spdif_debug_add(spdif); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | |
Stephen Warren | 518de86 | 2012-03-20 14:55:49 -0600 | [diff] [blame] | 344 | err_unregister_dai: |
| 345 | snd_soc_unregister_dai(&pdev->dev); |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 346 | err_suspend: |
| 347 | if (!pm_runtime_status_suspended(&pdev->dev)) |
| 348 | tegra20_spdif_runtime_suspend(&pdev->dev); |
| 349 | err_pm_disable: |
| 350 | pm_runtime_disable(&pdev->dev); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 351 | err_clk_put: |
| 352 | clk_put(spdif->clk_spdif_out); |
Stephen Warren | 17933db | 2012-04-06 11:14:04 -0600 | [diff] [blame] | 353 | err: |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 354 | return ret; |
| 355 | } |
| 356 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 357 | static int __devexit tegra20_spdif_platform_remove(struct platform_device *pdev) |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 358 | { |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 359 | struct tegra20_spdif *spdif = dev_get_drvdata(&pdev->dev); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 360 | |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 361 | pm_runtime_disable(&pdev->dev); |
| 362 | if (!pm_runtime_status_suspended(&pdev->dev)) |
| 363 | tegra20_spdif_runtime_suspend(&pdev->dev); |
| 364 | |
Stephen Warren | 518de86 | 2012-03-20 14:55:49 -0600 | [diff] [blame] | 365 | tegra_pcm_platform_unregister(&pdev->dev); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 366 | snd_soc_unregister_dai(&pdev->dev); |
| 367 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 368 | tegra20_spdif_debug_remove(spdif); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 369 | |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 370 | clk_put(spdif->clk_spdif_out); |
| 371 | |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 375 | static const struct dev_pm_ops tegra20_spdif_pm_ops __devinitconst = { |
| 376 | SET_RUNTIME_PM_OPS(tegra20_spdif_runtime_suspend, |
| 377 | tegra20_spdif_runtime_resume, NULL) |
| 378 | }; |
| 379 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 380 | static struct platform_driver tegra20_spdif_driver = { |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 381 | .driver = { |
| 382 | .name = DRV_NAME, |
| 383 | .owner = THIS_MODULE, |
Stephen Warren | 82ef0ae | 2012-04-09 09:52:22 -0600 | [diff] [blame^] | 384 | .pm = &tegra20_spdif_pm_ops, |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 385 | }, |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 386 | .probe = tegra20_spdif_platform_probe, |
| 387 | .remove = __devexit_p(tegra20_spdif_platform_remove), |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 388 | }; |
| 389 | |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 390 | module_platform_driver(tegra20_spdif_driver); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 391 | |
| 392 | MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>"); |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 393 | MODULE_DESCRIPTION("Tegra20 SPDIF ASoC driver"); |
Stephen Warren | 774fec3 | 2011-07-05 10:55:27 -0600 | [diff] [blame] | 394 | MODULE_LICENSE("GPL"); |
| 395 | MODULE_ALIAS("platform:" DRV_NAME); |