Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 1 | /* |
| 2 | * File: sound/soc/blackfin/bf5xx-i2s.c |
| 3 | * Author: Cliff Cai <Cliff.Cai@analog.com> |
| 4 | * |
| 5 | * Created: Tue June 06 2008 |
| 6 | * Description: Blackfin I2S CPU DAI driver |
| 7 | * |
| 8 | * Modified: |
| 9 | * Copyright 2008 Analog Devices Inc. |
| 10 | * |
| 11 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, see the file COPYING, or write |
| 25 | * to the Free Software Foundation, Inc., |
| 26 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | */ |
| 28 | |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/device.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <sound/core.h> |
| 34 | #include <sound/pcm.h> |
| 35 | #include <sound/pcm_params.h> |
| 36 | #include <sound/initval.h> |
| 37 | #include <sound/soc.h> |
| 38 | |
| 39 | #include <asm/irq.h> |
| 40 | #include <asm/portmux.h> |
| 41 | #include <linux/mutex.h> |
| 42 | #include <linux/gpio.h> |
| 43 | |
| 44 | #include "bf5xx-sport.h" |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 45 | #include "bf5xx-i2s-pcm.h" |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 46 | |
| 47 | struct bf5xx_i2s_port { |
| 48 | u16 tcr1; |
| 49 | u16 rcr1; |
| 50 | u16 tcr2; |
| 51 | u16 rcr2; |
Cliff Cai | 895c9c0 | 2009-06-20 11:29:05 -0400 | [diff] [blame] | 52 | int configured; |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 53 | |
| 54 | unsigned int slots; |
| 55 | unsigned int tx_mask; |
| 56 | unsigned int rx_mask; |
| 57 | |
| 58 | struct bf5xx_i2s_pcm_data tx_dma_data; |
| 59 | struct bf5xx_i2s_pcm_data rx_dma_data; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 60 | }; |
| 61 | |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 62 | static int bf5xx_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
| 63 | unsigned int fmt) |
| 64 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 65 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(cpu_dai); |
| 66 | struct bf5xx_i2s_port *bf5xx_i2s = sport_handle->private_data; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 67 | int ret = 0; |
| 68 | |
| 69 | /* interface format:support I2S,slave mode */ |
| 70 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 71 | case SND_SOC_DAIFMT_I2S: |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 72 | bf5xx_i2s->tcr1 |= TFSR | TCKFE; |
| 73 | bf5xx_i2s->rcr1 |= RFSR | RCKFE; |
| 74 | bf5xx_i2s->tcr2 |= TSFSE; |
| 75 | bf5xx_i2s->rcr2 |= RSFSE; |
Cliff Cai | 3339268 | 2008-09-27 22:30:15 +0800 | [diff] [blame] | 76 | break; |
| 77 | case SND_SOC_DAIFMT_DSP_A: |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 78 | bf5xx_i2s->tcr1 |= TFSR; |
| 79 | bf5xx_i2s->rcr1 |= RFSR; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 80 | break; |
| 81 | case SND_SOC_DAIFMT_LEFT_J: |
| 82 | ret = -EINVAL; |
| 83 | break; |
| 84 | default: |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 85 | dev_err(cpu_dai->dev, "%s: Unknown DAI format type\n", |
| 86 | __func__); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 87 | ret = -EINVAL; |
| 88 | break; |
| 89 | } |
| 90 | |
| 91 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 92 | case SND_SOC_DAIFMT_CBM_CFM: |
| 93 | break; |
Cliff Cai | c3e5203 | 2008-10-27 17:09:25 +0800 | [diff] [blame] | 94 | case SND_SOC_DAIFMT_CBS_CFS: |
| 95 | case SND_SOC_DAIFMT_CBM_CFS: |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 96 | case SND_SOC_DAIFMT_CBS_CFM: |
| 97 | ret = -EINVAL; |
| 98 | break; |
| 99 | default: |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 100 | dev_err(cpu_dai->dev, "%s: Unknown DAI master type\n", |
| 101 | __func__); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 102 | ret = -EINVAL; |
| 103 | break; |
| 104 | } |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 109 | static int bf5xx_i2s_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 110 | struct snd_pcm_hw_params *params, |
| 111 | struct snd_soc_dai *dai) |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 112 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 113 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(dai); |
| 114 | struct bf5xx_i2s_port *bf5xx_i2s = sport_handle->private_data; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 115 | int ret = 0; |
| 116 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 117 | bf5xx_i2s->tcr2 &= ~0x1f; |
| 118 | bf5xx_i2s->rcr2 &= ~0x1f; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 119 | switch (params_format(params)) { |
Cliff Cai | 4b2ffc2 | 2011-03-26 03:05:08 -0400 | [diff] [blame] | 120 | case SNDRV_PCM_FORMAT_S8: |
| 121 | bf5xx_i2s->tcr2 |= 7; |
| 122 | bf5xx_i2s->rcr2 |= 7; |
| 123 | sport_handle->wdsize = 1; |
Takashi Iwai | afed4db | 2013-11-13 17:15:00 +0100 | [diff] [blame] | 124 | break; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 125 | case SNDRV_PCM_FORMAT_S16_LE: |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 126 | bf5xx_i2s->tcr2 |= 15; |
| 127 | bf5xx_i2s->rcr2 |= 15; |
Cliff Cai | 3339268 | 2008-09-27 22:30:15 +0800 | [diff] [blame] | 128 | sport_handle->wdsize = 2; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 129 | break; |
| 130 | case SNDRV_PCM_FORMAT_S24_LE: |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 131 | bf5xx_i2s->tcr2 |= 23; |
| 132 | bf5xx_i2s->rcr2 |= 23; |
Cliff Cai | 3339268 | 2008-09-27 22:30:15 +0800 | [diff] [blame] | 133 | sport_handle->wdsize = 3; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 134 | break; |
| 135 | case SNDRV_PCM_FORMAT_S32_LE: |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 136 | bf5xx_i2s->tcr2 |= 31; |
| 137 | bf5xx_i2s->rcr2 |= 31; |
Cliff Cai | 3339268 | 2008-09-27 22:30:15 +0800 | [diff] [blame] | 138 | sport_handle->wdsize = 4; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 139 | break; |
| 140 | } |
| 141 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 142 | if (!bf5xx_i2s->configured) { |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 143 | /* |
| 144 | * TX and RX are not independent,they are enabled at the |
| 145 | * same time, even if only one side is running. So, we |
| 146 | * need to configure both of them at the time when the first |
| 147 | * stream is opened. |
| 148 | * |
Cliff Cai | 3339268 | 2008-09-27 22:30:15 +0800 | [diff] [blame] | 149 | * CPU DAI:slave mode. |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 150 | */ |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 151 | bf5xx_i2s->configured = 1; |
| 152 | ret = sport_config_rx(sport_handle, bf5xx_i2s->rcr1, |
| 153 | bf5xx_i2s->rcr2, 0, 0); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 154 | if (ret) { |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 155 | dev_err(dai->dev, "SPORT is busy!\n"); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 156 | return -EBUSY; |
| 157 | } |
| 158 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 159 | ret = sport_config_tx(sport_handle, bf5xx_i2s->tcr1, |
| 160 | bf5xx_i2s->tcr2, 0, 0); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 161 | if (ret) { |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 162 | dev_err(dai->dev, "SPORT is busy!\n"); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 163 | return -EBUSY; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 170 | static void bf5xx_i2s_shutdown(struct snd_pcm_substream *substream, |
| 171 | struct snd_soc_dai *dai) |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 172 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 173 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(dai); |
| 174 | struct bf5xx_i2s_port *bf5xx_i2s = sport_handle->private_data; |
| 175 | |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 176 | dev_dbg(dai->dev, "%s enter\n", __func__); |
Cliff Cai | 895c9c0 | 2009-06-20 11:29:05 -0400 | [diff] [blame] | 177 | /* No active stream, SPORT is allowed to be configured again. */ |
Barry Song | 766df6d | 2009-09-23 11:51:04 -0400 | [diff] [blame] | 178 | if (!dai->active) |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 179 | bf5xx_i2s->configured = 0; |
Cliff Cai | 3339268 | 2008-09-27 22:30:15 +0800 | [diff] [blame] | 180 | } |
| 181 | |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 182 | static int bf5xx_i2s_set_channel_map(struct snd_soc_dai *dai, |
| 183 | unsigned int tx_num, unsigned int *tx_slot, |
| 184 | unsigned int rx_num, unsigned int *rx_slot) |
| 185 | { |
| 186 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(dai); |
| 187 | struct bf5xx_i2s_port *bf5xx_i2s = sport_handle->private_data; |
| 188 | unsigned int tx_mapped = 0, rx_mapped = 0; |
| 189 | unsigned int slot; |
| 190 | int i; |
| 191 | |
| 192 | if ((tx_num > BFIN_TDM_DAI_MAX_SLOTS) || |
| 193 | (rx_num > BFIN_TDM_DAI_MAX_SLOTS)) |
| 194 | return -EINVAL; |
| 195 | |
| 196 | for (i = 0; i < tx_num; i++) { |
| 197 | slot = tx_slot[i]; |
| 198 | if ((slot < BFIN_TDM_DAI_MAX_SLOTS) && |
| 199 | (!(tx_mapped & (1 << slot)))) { |
| 200 | bf5xx_i2s->tx_dma_data.map[i] = slot; |
| 201 | tx_mapped |= 1 << slot; |
| 202 | } else |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | for (i = 0; i < rx_num; i++) { |
| 206 | slot = rx_slot[i]; |
| 207 | if ((slot < BFIN_TDM_DAI_MAX_SLOTS) && |
| 208 | (!(rx_mapped & (1 << slot)))) { |
| 209 | bf5xx_i2s->rx_dma_data.map[i] = slot; |
| 210 | rx_mapped |= 1 << slot; |
| 211 | } else |
| 212 | return -EINVAL; |
| 213 | } |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static int bf5xx_i2s_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, |
| 219 | unsigned int rx_mask, int slots, int width) |
| 220 | { |
| 221 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(dai); |
| 222 | struct bf5xx_i2s_port *bf5xx_i2s = sport_handle->private_data; |
| 223 | |
| 224 | if (slots % 8 != 0 || slots > 8) |
| 225 | return -EINVAL; |
| 226 | |
| 227 | if (width != 32) |
| 228 | return -EINVAL; |
| 229 | |
| 230 | bf5xx_i2s->slots = slots; |
| 231 | bf5xx_i2s->tx_mask = tx_mask; |
| 232 | bf5xx_i2s->rx_mask = rx_mask; |
| 233 | |
| 234 | bf5xx_i2s->tx_dma_data.tdm_mode = slots != 0; |
| 235 | bf5xx_i2s->rx_dma_data.tdm_mode = slots != 0; |
| 236 | |
| 237 | return sport_set_multichannel(sport_handle, slots, tx_mask, rx_mask, 0); |
| 238 | } |
| 239 | |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 240 | #ifdef CONFIG_PM |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 241 | static int bf5xx_i2s_suspend(struct snd_soc_dai *dai) |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 242 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 243 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(dai); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 244 | |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 245 | dev_dbg(dai->dev, "%s : sport %d\n", __func__, dai->id); |
Cliff Cai | ad80efc | 2009-09-16 20:25:12 -0400 | [diff] [blame] | 246 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 247 | if (dai->capture_active) |
Cliff Cai | ad80efc | 2009-09-16 20:25:12 -0400 | [diff] [blame] | 248 | sport_rx_stop(sport_handle); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 249 | if (dai->playback_active) |
Cliff Cai | ad80efc | 2009-09-16 20:25:12 -0400 | [diff] [blame] | 250 | sport_tx_stop(sport_handle); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Barry Song | 92a6ad3 | 2009-06-20 11:29:57 -0400 | [diff] [blame] | 254 | static int bf5xx_i2s_resume(struct snd_soc_dai *dai) |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 255 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 256 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(dai); |
| 257 | struct bf5xx_i2s_port *bf5xx_i2s = sport_handle->private_data; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 258 | int ret; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 259 | |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 260 | dev_dbg(dai->dev, "%s : sport %d\n", __func__, dai->id); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 261 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 262 | ret = sport_config_rx(sport_handle, bf5xx_i2s->rcr1, |
| 263 | bf5xx_i2s->rcr2, 0, 0); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 264 | if (ret) { |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 265 | dev_err(dai->dev, "SPORT is busy!\n"); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 266 | return -EBUSY; |
| 267 | } |
| 268 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 269 | ret = sport_config_tx(sport_handle, bf5xx_i2s->tcr1, |
| 270 | bf5xx_i2s->tcr2, 0, 0); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 271 | if (ret) { |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 272 | dev_err(dai->dev, "SPORT is busy!\n"); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 273 | return -EBUSY; |
| 274 | } |
| 275 | |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 276 | return sport_set_multichannel(sport_handle, bf5xx_i2s->slots, |
| 277 | bf5xx_i2s->tx_mask, bf5xx_i2s->rx_mask, 0); |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | #else |
| 281 | #define bf5xx_i2s_suspend NULL |
| 282 | #define bf5xx_i2s_resume NULL |
| 283 | #endif |
| 284 | |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 285 | static int bf5xx_i2s_dai_probe(struct snd_soc_dai *dai) |
| 286 | { |
| 287 | struct sport_device *sport_handle = snd_soc_dai_get_drvdata(dai); |
| 288 | struct bf5xx_i2s_port *bf5xx_i2s = sport_handle->private_data; |
| 289 | unsigned int i; |
| 290 | |
| 291 | for (i = 0; i < BFIN_TDM_DAI_MAX_SLOTS; i++) { |
| 292 | bf5xx_i2s->tx_dma_data.map[i] = i; |
| 293 | bf5xx_i2s->rx_dma_data.map[i] = i; |
| 294 | } |
| 295 | |
| 296 | dai->playback_dma_data = &bf5xx_i2s->tx_dma_data; |
| 297 | dai->capture_dma_data = &bf5xx_i2s->rx_dma_data; |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 302 | #define BF5XX_I2S_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
| 303 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ |
| 304 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | \ |
| 305 | SNDRV_PCM_RATE_96000) |
| 306 | |
Cliff Cai | 4b2ffc2 | 2011-03-26 03:05:08 -0400 | [diff] [blame] | 307 | #define BF5XX_I2S_FORMATS \ |
| 308 | (SNDRV_PCM_FMTBIT_S8 | \ |
| 309 | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 310 | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 311 | SNDRV_PCM_FMTBIT_S32_LE) |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 312 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 313 | static const struct snd_soc_dai_ops bf5xx_i2s_dai_ops = { |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 314 | .shutdown = bf5xx_i2s_shutdown, |
| 315 | .hw_params = bf5xx_i2s_hw_params, |
| 316 | .set_fmt = bf5xx_i2s_set_dai_fmt, |
| 317 | .set_tdm_slot = bf5xx_i2s_set_tdm_slot, |
| 318 | .set_channel_map = bf5xx_i2s_set_channel_map, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 319 | }; |
| 320 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 321 | static struct snd_soc_dai_driver bf5xx_i2s_dai = { |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 322 | .probe = bf5xx_i2s_dai_probe, |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 323 | .suspend = bf5xx_i2s_suspend, |
| 324 | .resume = bf5xx_i2s_resume, |
| 325 | .playback = { |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 326 | .channels_min = 2, |
| 327 | .channels_max = 8, |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 328 | .rates = BF5XX_I2S_RATES, |
| 329 | .formats = BF5XX_I2S_FORMATS,}, |
| 330 | .capture = { |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 331 | .channels_min = 2, |
| 332 | .channels_max = 8, |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 333 | .rates = BF5XX_I2S_RATES, |
| 334 | .formats = BF5XX_I2S_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 335 | .ops = &bf5xx_i2s_dai_ops, |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 336 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 337 | |
Kuninori Morimoto | b56733b | 2013-03-21 03:30:08 -0700 | [diff] [blame] | 338 | static const struct snd_soc_component_driver bf5xx_i2s_component = { |
| 339 | .name = "bf5xx-i2s", |
| 340 | }; |
| 341 | |
Bill Pemberton | dca66da | 2012-12-07 09:26:13 -0500 | [diff] [blame] | 342 | static int bf5xx_i2s_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 343 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 344 | struct sport_device *sport_handle; |
| 345 | int ret; |
| 346 | |
| 347 | /* configure SPORT for I2S */ |
Lars-Peter Clausen | 8b5e2e3 | 2013-05-28 19:22:14 +0200 | [diff] [blame] | 348 | sport_handle = sport_init(pdev, 4, 8 * sizeof(u32), |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 349 | sizeof(struct bf5xx_i2s_port)); |
| 350 | if (!sport_handle) |
| 351 | return -ENODEV; |
| 352 | |
| 353 | /* register with the ASoC layers */ |
Kuninori Morimoto | b56733b | 2013-03-21 03:30:08 -0700 | [diff] [blame] | 354 | ret = snd_soc_register_component(&pdev->dev, &bf5xx_i2s_component, |
| 355 | &bf5xx_i2s_dai, 1); |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 356 | if (ret) { |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 357 | dev_err(&pdev->dev, "Failed to register DAI: %d\n", ret); |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 358 | sport_done(sport_handle); |
| 359 | return ret; |
| 360 | } |
| 361 | |
| 362 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Bill Pemberton | dca66da | 2012-12-07 09:26:13 -0500 | [diff] [blame] | 365 | static int bf5xx_i2s_remove(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 366 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 367 | struct sport_device *sport_handle = platform_get_drvdata(pdev); |
| 368 | |
Lars-Peter Clausen | b7ede5d | 2013-05-28 19:22:10 +0200 | [diff] [blame] | 369 | dev_dbg(&pdev->dev, "%s enter\n", __func__); |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 370 | |
Kuninori Morimoto | b56733b | 2013-03-21 03:30:08 -0700 | [diff] [blame] | 371 | snd_soc_unregister_component(&pdev->dev); |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 372 | sport_done(sport_handle); |
| 373 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static struct platform_driver bfin_i2s_driver = { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 378 | .probe = bf5xx_i2s_probe, |
Bill Pemberton | dca66da | 2012-12-07 09:26:13 -0500 | [diff] [blame] | 379 | .remove = bf5xx_i2s_remove, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 380 | .driver = { |
Mike Frysinger | bfe4ee0 | 2011-03-28 01:45:09 -0400 | [diff] [blame] | 381 | .name = "bfin-i2s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 382 | }, |
| 383 | }; |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 384 | |
Axel Lin | fb80297 | 2011-11-24 14:44:52 +0800 | [diff] [blame] | 385 | module_platform_driver(bfin_i2s_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 386 | |
Cliff Cai | 912c2ac | 2008-09-05 18:21:39 +0800 | [diff] [blame] | 387 | /* Module information */ |
| 388 | MODULE_AUTHOR("Cliff Cai"); |
| 389 | MODULE_DESCRIPTION("I2S driver for ADI Blackfin"); |
| 390 | MODULE_LICENSE("GPL"); |
| 391 | |