Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * omap-mcbsp.c -- OMAP ALSA SoC DAI driver using McBSP port |
| 3 | * |
| 4 | * Copyright (C) 2008 Nokia Corporation |
| 5 | * |
Jarkko Nikula | 7ec41ee | 2011-08-11 15:44:57 +0300 | [diff] [blame] | 6 | * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com> |
Peter Ujfalusi | 56a8742 | 2011-05-03 18:14:06 +0300 | [diff] [blame] | 7 | * Peter Ujfalusi <peter.ujfalusi@ti.com> |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * version 2 as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/device.h> |
| 28 | #include <sound/core.h> |
| 29 | #include <sound/pcm.h> |
| 30 | #include <sound/pcm_params.h> |
| 31 | #include <sound/initval.h> |
| 32 | #include <sound/soc.h> |
| 33 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 34 | #include <plat/dma.h> |
| 35 | #include <plat/mcbsp.h> |
Peter Ujfalusi | 219f431 | 2012-02-03 13:11:47 +0200 | [diff] [blame^] | 36 | #include "mcbsp.h" |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 37 | #include "omap-mcbsp.h" |
| 38 | #include "omap-pcm.h" |
| 39 | |
Jarkko Nikula | 0b60485 | 2008-11-12 17:05:51 +0200 | [diff] [blame] | 40 | #define OMAP_MCBSP_RATES (SNDRV_PCM_RATE_8000_96000) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 41 | |
Ilkka Koskinen | 83905c1 | 2010-02-22 12:21:12 +0000 | [diff] [blame] | 42 | #define OMAP_MCBSP_SOC_SINGLE_S16_EXT(xname, xmin, xmax, \ |
| 43 | xhandler_get, xhandler_put) \ |
| 44 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 45 | .info = omap_mcbsp_st_info_volsw, \ |
| 46 | .get = xhandler_get, .put = xhandler_put, \ |
| 47 | .private_value = (unsigned long) &(struct soc_mixer_control) \ |
| 48 | {.min = xmin, .max = xmax} } |
| 49 | |
Peter Ujfalusi | 219f431 | 2012-02-03 13:11:47 +0200 | [diff] [blame^] | 50 | enum { |
| 51 | OMAP_MCBSP_WORD_8 = 0, |
| 52 | OMAP_MCBSP_WORD_12, |
| 53 | OMAP_MCBSP_WORD_16, |
| 54 | OMAP_MCBSP_WORD_20, |
| 55 | OMAP_MCBSP_WORD_24, |
| 56 | OMAP_MCBSP_WORD_32, |
| 57 | }; |
| 58 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 59 | struct omap_mcbsp_data { |
| 60 | unsigned int bus_id; |
| 61 | struct omap_mcbsp_reg_cfg regs; |
Jarkko Nikula | ba9d0fd | 2008-10-20 15:29:59 +0300 | [diff] [blame] | 62 | unsigned int fmt; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 63 | /* |
| 64 | * Flags indicating is the bus already activated and configured by |
| 65 | * another substream |
| 66 | */ |
| 67 | int active; |
| 68 | int configured; |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 69 | unsigned int in_freq; |
| 70 | int clk_div; |
Peter Ujfalusi | 3f02403 | 2010-06-03 07:39:35 +0300 | [diff] [blame] | 71 | int wlen; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 74 | static struct omap_mcbsp_data mcbsp_data[NUM_LINKS]; |
| 75 | |
| 76 | /* |
| 77 | * Stream DMA parameters. DMA request line and port address are set runtime |
| 78 | * since they are different between OMAP1 and later OMAPs |
| 79 | */ |
Jarkko Nikula | 2e89713 | 2008-10-09 15:57:21 +0300 | [diff] [blame] | 80 | static struct omap_pcm_dma_data omap_mcbsp_dai_dma_params[NUM_LINKS][2]; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 81 | |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 82 | static void omap_mcbsp_set_threshold(struct snd_pcm_substream *substream) |
| 83 | { |
| 84 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 85 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 86 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 87 | struct omap_pcm_dma_data *dma_data; |
Eduardo Valentin | a0a499c | 2009-08-20 16:18:26 +0300 | [diff] [blame] | 88 | int dma_op_mode = omap_mcbsp_get_dma_op_mode(mcbsp_data->bus_id); |
Peter Ujfalusi | 3f02403 | 2010-06-03 07:39:35 +0300 | [diff] [blame] | 89 | int words; |
Eduardo Valentin | a0a499c | 2009-08-20 16:18:26 +0300 | [diff] [blame] | 90 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 91 | dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 92 | |
Eduardo Valentin | a0a499c | 2009-08-20 16:18:26 +0300 | [diff] [blame] | 93 | /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */ |
| 94 | if (dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 95 | /* |
| 96 | * Configure McBSP threshold based on either: |
| 97 | * packet_size, when the sDMA is in packet mode, or |
| 98 | * based on the period size. |
| 99 | */ |
| 100 | if (dma_data->packet_size) |
| 101 | words = dma_data->packet_size; |
| 102 | else |
| 103 | words = snd_pcm_lib_period_bytes(substream) / |
Peter Ujfalusi | 3f02403 | 2010-06-03 07:39:35 +0300 | [diff] [blame] | 104 | (mcbsp_data->wlen / 8); |
Eduardo Valentin | a0a499c | 2009-08-20 16:18:26 +0300 | [diff] [blame] | 105 | else |
Peter Ujfalusi | 3f02403 | 2010-06-03 07:39:35 +0300 | [diff] [blame] | 106 | words = 1; |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 107 | |
| 108 | /* Configure McBSP internal buffer usage */ |
| 109 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Peter Ujfalusi | 3f02403 | 2010-06-03 07:39:35 +0300 | [diff] [blame] | 110 | omap_mcbsp_set_tx_threshold(mcbsp_data->bus_id, words); |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 111 | else |
Peter Ujfalusi | 3f02403 | 2010-06-03 07:39:35 +0300 | [diff] [blame] | 112 | omap_mcbsp_set_rx_threshold(mcbsp_data->bus_id, words); |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 113 | } |
| 114 | |
Peter Ujfalusi | ddc29b0 | 2010-06-03 07:39:36 +0300 | [diff] [blame] | 115 | static int omap_mcbsp_hwrule_min_buffersize(struct snd_pcm_hw_params *params, |
| 116 | struct snd_pcm_hw_rule *rule) |
| 117 | { |
| 118 | struct snd_interval *buffer_size = hw_param_interval(params, |
| 119 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE); |
| 120 | struct snd_interval *channels = hw_param_interval(params, |
| 121 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 122 | struct omap_mcbsp_data *mcbsp_data = rule->private; |
| 123 | struct snd_interval frames; |
| 124 | int size; |
| 125 | |
| 126 | snd_interval_any(&frames); |
| 127 | size = omap_mcbsp_get_fifo_size(mcbsp_data->bus_id); |
| 128 | |
| 129 | frames.min = size / channels->min; |
| 130 | frames.integer = 1; |
| 131 | return snd_interval_refine(buffer_size, &frames); |
| 132 | } |
| 133 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 134 | static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 135 | struct snd_soc_dai *cpu_dai) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 136 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 137 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 138 | int bus_id = mcbsp_data->bus_id; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 139 | int err = 0; |
| 140 | |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 141 | if (!cpu_dai->active) |
| 142 | err = omap_mcbsp_request(bus_id); |
| 143 | |
Peter Ujfalusi | ddc29b0 | 2010-06-03 07:39:36 +0300 | [diff] [blame] | 144 | /* |
| 145 | * OMAP3 McBSP FIFO is word structured. |
| 146 | * McBSP2 has 1024 + 256 = 1280 word long buffer, |
| 147 | * McBSP1,3,4,5 has 128 word long buffer |
| 148 | * This means that the size of the FIFO depends on the sample format. |
| 149 | * For example on McBSP3: |
| 150 | * 16bit samples: size is 128 * 2 = 256 bytes |
| 151 | * 32bit samples: size is 128 * 4 = 512 bytes |
| 152 | * It is simpler to place constraint for buffer and period based on |
| 153 | * channels. |
| 154 | * McBSP3 as example again (16 or 32 bit samples): |
| 155 | * 1 channel (mono): size is 128 frames (128 words) |
| 156 | * 2 channels (stereo): size is 128 / 2 = 64 frames (2 * 64 words) |
| 157 | * 4 channels: size is 128 / 4 = 32 frames (4 * 32 words) |
| 158 | */ |
Sanjeev Premi | d491297 | 2011-05-11 19:25:35 +0530 | [diff] [blame] | 159 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Jarkko Nikula | 6984992 | 2009-03-27 15:32:01 +0200 | [diff] [blame] | 160 | /* |
Peter Ujfalusi | 998a8a6 | 2010-07-29 09:51:28 +0300 | [diff] [blame] | 161 | * Rule for the buffer size. We should not allow |
Peter Ujfalusi | ddc29b0 | 2010-06-03 07:39:36 +0300 | [diff] [blame] | 162 | * smaller buffer than the FIFO size to avoid underruns |
| 163 | */ |
| 164 | snd_pcm_hw_rule_add(substream->runtime, 0, |
| 165 | SNDRV_PCM_HW_PARAM_CHANNELS, |
| 166 | omap_mcbsp_hwrule_min_buffersize, |
| 167 | mcbsp_data, |
| 168 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, -1); |
| 169 | |
Peter Ujfalusi | 998a8a6 | 2010-07-29 09:51:28 +0300 | [diff] [blame] | 170 | /* Make sure, that the period size is always even */ |
| 171 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 172 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 2); |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 173 | } |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 174 | |
| 175 | return err; |
| 176 | } |
| 177 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 178 | static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 179 | struct snd_soc_dai *cpu_dai) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 180 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 181 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 182 | |
| 183 | if (!cpu_dai->active) { |
| 184 | omap_mcbsp_free(mcbsp_data->bus_id); |
| 185 | mcbsp_data->configured = 0; |
| 186 | } |
| 187 | } |
| 188 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 189 | static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 190 | struct snd_soc_dai *cpu_dai) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 191 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 192 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 193 | int err = 0, play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 194 | |
| 195 | switch (cmd) { |
| 196 | case SNDRV_PCM_TRIGGER_START: |
| 197 | case SNDRV_PCM_TRIGGER_RESUME: |
| 198 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 199 | mcbsp_data->active++; |
| 200 | omap_mcbsp_start(mcbsp_data->bus_id, play, !play); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 201 | break; |
| 202 | |
| 203 | case SNDRV_PCM_TRIGGER_STOP: |
| 204 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 205 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 206 | omap_mcbsp_stop(mcbsp_data->bus_id, play, !play); |
| 207 | mcbsp_data->active--; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 208 | break; |
| 209 | default: |
| 210 | err = -EINVAL; |
| 211 | } |
| 212 | |
| 213 | return err; |
| 214 | } |
| 215 | |
Peter Ujfalusi | 75581d2 | 2010-03-03 15:08:09 +0200 | [diff] [blame] | 216 | static snd_pcm_sframes_t omap_mcbsp_dai_delay( |
| 217 | struct snd_pcm_substream *substream, |
| 218 | struct snd_soc_dai *dai) |
| 219 | { |
| 220 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 221 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 222 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Peter Ujfalusi | 75581d2 | 2010-03-03 15:08:09 +0200 | [diff] [blame] | 223 | u16 fifo_use; |
| 224 | snd_pcm_sframes_t delay; |
| 225 | |
| 226 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 227 | fifo_use = omap_mcbsp_get_tx_delay(mcbsp_data->bus_id); |
| 228 | else |
| 229 | fifo_use = omap_mcbsp_get_rx_delay(mcbsp_data->bus_id); |
| 230 | |
| 231 | /* |
| 232 | * Divide the used locations with the channel count to get the |
| 233 | * FIFO usage in samples (don't care about partial samples in the |
| 234 | * buffer). |
| 235 | */ |
| 236 | delay = fifo_use / substream->runtime->channels; |
| 237 | |
| 238 | return delay; |
| 239 | } |
| 240 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 241 | static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 242 | struct snd_pcm_hw_params *params, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 243 | struct snd_soc_dai *cpu_dai) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 244 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 245 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 246 | struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; |
Peter Ujfalusi | 81ec027 | 2010-07-29 09:51:26 +0300 | [diff] [blame] | 247 | struct omap_pcm_dma_data *dma_data; |
| 248 | int dma, bus_id = mcbsp_data->bus_id; |
Eduardo Valentin | caebc0c | 2009-08-20 16:18:25 +0300 | [diff] [blame] | 249 | int wlen, channels, wpf, sync_mode = OMAP_DMA_SYNC_ELEMENT; |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 250 | int pkt_size = 0; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 251 | unsigned long port; |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 252 | unsigned int format, div, framesize, master; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 253 | |
Peter Ujfalusi | 81ec027 | 2010-07-29 09:51:26 +0300 | [diff] [blame] | 254 | dma_data = &omap_mcbsp_dai_dma_params[cpu_dai->id][substream->stream]; |
Kishon Vijay Abraham I | 2686e07 | 2011-02-24 15:16:56 +0530 | [diff] [blame] | 255 | |
| 256 | dma = omap_mcbsp_dma_ch_params(bus_id, substream->stream); |
| 257 | port = omap_mcbsp_dma_reg_params(bus_id, substream->stream); |
| 258 | |
Sergey Lapin | d98508a | 2010-05-13 19:48:16 +0400 | [diff] [blame] | 259 | switch (params_format(params)) { |
| 260 | case SNDRV_PCM_FORMAT_S16_LE: |
Peter Ujfalusi | 81ec027 | 2010-07-29 09:51:26 +0300 | [diff] [blame] | 261 | dma_data->data_type = OMAP_DMA_DATA_TYPE_S16; |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 262 | wlen = 16; |
Sergey Lapin | d98508a | 2010-05-13 19:48:16 +0400 | [diff] [blame] | 263 | break; |
| 264 | case SNDRV_PCM_FORMAT_S32_LE: |
Peter Ujfalusi | 81ec027 | 2010-07-29 09:51:26 +0300 | [diff] [blame] | 265 | dma_data->data_type = OMAP_DMA_DATA_TYPE_S32; |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 266 | wlen = 32; |
Sergey Lapin | d98508a | 2010-05-13 19:48:16 +0400 | [diff] [blame] | 267 | break; |
| 268 | default: |
| 269 | return -EINVAL; |
| 270 | } |
Peter Ujfalusi | 7243a4b | 2011-12-15 11:32:27 +0200 | [diff] [blame] | 271 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Peter Ujfalusi | 15d0143 | 2010-07-29 09:51:25 +0300 | [diff] [blame] | 272 | dma_data->set_threshold = omap_mcbsp_set_threshold; |
| 273 | /* TODO: Currently, MODE_ELEMENT == MODE_FRAME */ |
| 274 | if (omap_mcbsp_get_dma_op_mode(bus_id) == |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 275 | MCBSP_DMA_MODE_THRESHOLD) { |
| 276 | int period_words, max_thrsh; |
| 277 | |
| 278 | period_words = params_period_bytes(params) / (wlen / 8); |
| 279 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 280 | max_thrsh = omap_mcbsp_get_max_tx_threshold( |
| 281 | mcbsp_data->bus_id); |
| 282 | else |
| 283 | max_thrsh = omap_mcbsp_get_max_rx_threshold( |
| 284 | mcbsp_data->bus_id); |
| 285 | /* |
| 286 | * If the period contains less or equal number of words, |
| 287 | * we are using the original threshold mode setup: |
| 288 | * McBSP threshold = sDMA frame size = period_size |
| 289 | * Otherwise we switch to sDMA packet mode: |
| 290 | * McBSP threshold = sDMA packet size |
| 291 | * sDMA frame size = period size |
| 292 | */ |
| 293 | if (period_words > max_thrsh) { |
| 294 | int divider = 0; |
| 295 | |
| 296 | /* |
| 297 | * Look for the biggest threshold value, which |
| 298 | * divides the period size evenly. |
| 299 | */ |
| 300 | divider = period_words / max_thrsh; |
| 301 | if (period_words % max_thrsh) |
| 302 | divider++; |
| 303 | while (period_words % divider && |
| 304 | divider < period_words) |
| 305 | divider++; |
| 306 | if (divider == period_words) |
| 307 | return -EINVAL; |
| 308 | |
| 309 | pkt_size = period_words / divider; |
| 310 | sync_mode = OMAP_DMA_SYNC_PACKET; |
| 311 | } else { |
| 312 | sync_mode = OMAP_DMA_SYNC_FRAME; |
| 313 | } |
| 314 | } |
Peter Ujfalusi | 15d0143 | 2010-07-29 09:51:25 +0300 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | dma_data->name = substream->stream ? "Audio Capture" : "Audio Playback"; |
| 318 | dma_data->dma_req = dma; |
| 319 | dma_data->port_addr = port; |
| 320 | dma_data->sync_mode = sync_mode; |
Peter Ujfalusi | cf80e15 | 2010-07-29 09:51:27 +0300 | [diff] [blame] | 321 | dma_data->packet_size = pkt_size; |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 322 | |
Peter Ujfalusi | 81ec027 | 2010-07-29 09:51:26 +0300 | [diff] [blame] | 323 | snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 324 | |
| 325 | if (mcbsp_data->configured) { |
| 326 | /* McBSP already configured by another stream */ |
| 327 | return 0; |
| 328 | } |
| 329 | |
Jarkko Nikula | 4dd0417 | 2011-09-30 16:07:44 +0300 | [diff] [blame] | 330 | regs->rcr2 &= ~(RPHASE | RFRLEN2(0x7f) | RWDLEN2(7)); |
| 331 | regs->xcr2 &= ~(RPHASE | XFRLEN2(0x7f) | XWDLEN2(7)); |
| 332 | regs->rcr1 &= ~(RFRLEN1(0x7f) | RWDLEN1(7)); |
| 333 | regs->xcr1 &= ~(XFRLEN1(0x7f) | XWDLEN1(7)); |
Peter Ujfalusi | c29b206 | 2009-04-15 15:38:55 +0300 | [diff] [blame] | 334 | format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK; |
| 335 | wpf = channels = params_channels(params); |
Peter Ujfalusi | 299a151 | 2010-03-19 12:27:31 +0200 | [diff] [blame] | 336 | if (channels == 2 && (format == SND_SOC_DAIFMT_I2S || |
| 337 | format == SND_SOC_DAIFMT_LEFT_J)) { |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 338 | /* Use dual-phase frames */ |
| 339 | regs->rcr2 |= RPHASE; |
| 340 | regs->xcr2 |= XPHASE; |
| 341 | /* Set 1 word per (McBSP) frame for phase1 and phase2 */ |
| 342 | wpf--; |
| 343 | regs->rcr2 |= RFRLEN2(wpf - 1); |
| 344 | regs->xcr2 |= XFRLEN2(wpf - 1); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 347 | regs->rcr1 |= RFRLEN1(wpf - 1); |
| 348 | regs->xcr1 |= XFRLEN1(wpf - 1); |
| 349 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 350 | switch (params_format(params)) { |
| 351 | case SNDRV_PCM_FORMAT_S16_LE: |
| 352 | /* Set word lengths */ |
| 353 | regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_16); |
| 354 | regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_16); |
| 355 | regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_16); |
| 356 | regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_16); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 357 | break; |
Sergey Lapin | d98508a | 2010-05-13 19:48:16 +0400 | [diff] [blame] | 358 | case SNDRV_PCM_FORMAT_S32_LE: |
| 359 | /* Set word lengths */ |
Sergey Lapin | d98508a | 2010-05-13 19:48:16 +0400 | [diff] [blame] | 360 | regs->rcr2 |= RWDLEN2(OMAP_MCBSP_WORD_32); |
| 361 | regs->rcr1 |= RWDLEN1(OMAP_MCBSP_WORD_32); |
| 362 | regs->xcr2 |= XWDLEN2(OMAP_MCBSP_WORD_32); |
| 363 | regs->xcr1 |= XWDLEN1(OMAP_MCBSP_WORD_32); |
| 364 | break; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 365 | default: |
| 366 | /* Unsupported PCM format */ |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 370 | /* In McBSP master modes, FRAME (i.e. sample rate) is generated |
| 371 | * by _counting_ BCLKs. Calculate frame size in BCLKs */ |
| 372 | master = mcbsp_data->fmt & SND_SOC_DAIFMT_MASTER_MASK; |
| 373 | if (master == SND_SOC_DAIFMT_CBS_CFS) { |
| 374 | div = mcbsp_data->clk_div ? mcbsp_data->clk_div : 1; |
| 375 | framesize = (mcbsp_data->in_freq / div) / params_rate(params); |
| 376 | |
| 377 | if (framesize < wlen * channels) { |
| 378 | printk(KERN_ERR "%s: not enough bandwidth for desired rate and " |
| 379 | "channels\n", __func__); |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | } else |
| 383 | framesize = wlen * channels; |
| 384 | |
Jarkko Nikula | ba9d0fd | 2008-10-20 15:29:59 +0300 | [diff] [blame] | 385 | /* Set FS period and length in terms of bit clock periods */ |
Jarkko Nikula | 4dd0417 | 2011-09-30 16:07:44 +0300 | [diff] [blame] | 386 | regs->srgr2 &= ~FPER(0xfff); |
| 387 | regs->srgr1 &= ~FWID(0xff); |
Peter Ujfalusi | c29b206 | 2009-04-15 15:38:55 +0300 | [diff] [blame] | 388 | switch (format) { |
Jarkko Nikula | ba9d0fd | 2008-10-20 15:29:59 +0300 | [diff] [blame] | 389 | case SND_SOC_DAIFMT_I2S: |
Peter Ujfalusi | 299a151 | 2010-03-19 12:27:31 +0200 | [diff] [blame] | 390 | case SND_SOC_DAIFMT_LEFT_J: |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 391 | regs->srgr2 |= FPER(framesize - 1); |
| 392 | regs->srgr1 |= FWID((framesize >> 1) - 1); |
Jarkko Nikula | ba9d0fd | 2008-10-20 15:29:59 +0300 | [diff] [blame] | 393 | break; |
Peter Ujfalusi | 3ba191c | 2009-04-15 15:38:56 +0300 | [diff] [blame] | 394 | case SND_SOC_DAIFMT_DSP_A: |
Jarkko Nikula | bd25867 | 2008-12-22 10:21:36 +0200 | [diff] [blame] | 395 | case SND_SOC_DAIFMT_DSP_B: |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 396 | regs->srgr2 |= FPER(framesize - 1); |
Jarkko Nikula | 36ce858 | 2009-04-15 13:48:16 +0300 | [diff] [blame] | 397 | regs->srgr1 |= FWID(0); |
Jarkko Nikula | ba9d0fd | 2008-10-20 15:29:59 +0300 | [diff] [blame] | 398 | break; |
| 399 | } |
| 400 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 401 | omap_mcbsp_config(bus_id, &mcbsp_data->regs); |
Peter Ujfalusi | 3f02403 | 2010-06-03 07:39:35 +0300 | [diff] [blame] | 402 | mcbsp_data->wlen = wlen; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 403 | mcbsp_data->configured = 1; |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * This must be called before _set_clkdiv and _set_sysclk since McBSP register |
| 410 | * cache is initialized here |
| 411 | */ |
Liam Girdwood | 8687eb8 | 2008-07-07 16:08:07 +0100 | [diff] [blame] | 412 | static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 413 | unsigned int fmt) |
| 414 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 415 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 416 | struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; |
Jarkko Nikula | 91a18ae | 2011-09-30 10:55:32 +0300 | [diff] [blame] | 417 | bool inv_fs = false; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 418 | |
| 419 | if (mcbsp_data->configured) |
| 420 | return 0; |
| 421 | |
Jarkko Nikula | ba9d0fd | 2008-10-20 15:29:59 +0300 | [diff] [blame] | 422 | mcbsp_data->fmt = fmt; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 423 | memset(regs, 0, sizeof(*regs)); |
| 424 | /* Generic McBSP register settings */ |
| 425 | regs->spcr2 |= XINTM(3) | FREE; |
| 426 | regs->spcr1 |= RINTM(3); |
Eero Nurkkala | c721bbd | 2009-08-20 16:18:23 +0300 | [diff] [blame] | 427 | /* RFIG and XFIG are not defined in 34xx */ |
Jorge Eduardo Candelaria | d4686c6 | 2010-12-20 11:32:47 -0600 | [diff] [blame] | 428 | if (!cpu_is_omap34xx() && !cpu_is_omap44xx()) { |
Eero Nurkkala | c721bbd | 2009-08-20 16:18:23 +0300 | [diff] [blame] | 429 | regs->rcr2 |= RFIG; |
| 430 | regs->xcr2 |= XFIG; |
| 431 | } |
Jorge Eduardo Candelaria | d4686c6 | 2010-12-20 11:32:47 -0600 | [diff] [blame] | 432 | if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Jarkko Nikula | 32080af | 2009-08-23 12:24:26 +0300 | [diff] [blame] | 433 | regs->xccr = DXENDLY(1) | XDMAEN | XDISABLE; |
| 434 | regs->rccr = RFULL_CYCLE | RDMAEN | RDISABLE; |
Misael Lopez Cruz | ef390c0 | 2009-01-29 13:29:46 +0200 | [diff] [blame] | 435 | } |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 436 | |
| 437 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 438 | case SND_SOC_DAIFMT_I2S: |
| 439 | /* 1-bit data delay */ |
| 440 | regs->rcr2 |= RDATDLY(1); |
| 441 | regs->xcr2 |= XDATDLY(1); |
| 442 | break; |
Peter Ujfalusi | 299a151 | 2010-03-19 12:27:31 +0200 | [diff] [blame] | 443 | case SND_SOC_DAIFMT_LEFT_J: |
| 444 | /* 0-bit data delay */ |
| 445 | regs->rcr2 |= RDATDLY(0); |
| 446 | regs->xcr2 |= XDATDLY(0); |
| 447 | regs->spcr1 |= RJUST(2); |
| 448 | /* Invert FS polarity configuration */ |
Jarkko Nikula | 91a18ae | 2011-09-30 10:55:32 +0300 | [diff] [blame] | 449 | inv_fs = true; |
Peter Ujfalusi | 299a151 | 2010-03-19 12:27:31 +0200 | [diff] [blame] | 450 | break; |
Peter Ujfalusi | 3ba191c | 2009-04-15 15:38:56 +0300 | [diff] [blame] | 451 | case SND_SOC_DAIFMT_DSP_A: |
| 452 | /* 1-bit data delay */ |
| 453 | regs->rcr2 |= RDATDLY(1); |
| 454 | regs->xcr2 |= XDATDLY(1); |
| 455 | /* Invert FS polarity configuration */ |
Jarkko Nikula | 91a18ae | 2011-09-30 10:55:32 +0300 | [diff] [blame] | 456 | inv_fs = true; |
Peter Ujfalusi | 3ba191c | 2009-04-15 15:38:56 +0300 | [diff] [blame] | 457 | break; |
Jarkko Nikula | bd25867 | 2008-12-22 10:21:36 +0200 | [diff] [blame] | 458 | case SND_SOC_DAIFMT_DSP_B: |
Arun KS | 3336c5b | 2008-10-02 15:07:06 +0530 | [diff] [blame] | 459 | /* 0-bit data delay */ |
| 460 | regs->rcr2 |= RDATDLY(0); |
| 461 | regs->xcr2 |= XDATDLY(0); |
Jarkko Nikula | 36ce858 | 2009-04-15 13:48:16 +0300 | [diff] [blame] | 462 | /* Invert FS polarity configuration */ |
Jarkko Nikula | 91a18ae | 2011-09-30 10:55:32 +0300 | [diff] [blame] | 463 | inv_fs = true; |
Arun KS | 3336c5b | 2008-10-02 15:07:06 +0530 | [diff] [blame] | 464 | break; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 465 | default: |
| 466 | /* Unsupported data format */ |
| 467 | return -EINVAL; |
| 468 | } |
| 469 | |
| 470 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 471 | case SND_SOC_DAIFMT_CBS_CFS: |
| 472 | /* McBSP master. Set FS and bit clocks as outputs */ |
| 473 | regs->pcr0 |= FSXM | FSRM | |
| 474 | CLKXM | CLKRM; |
| 475 | /* Sample rate generator drives the FS */ |
| 476 | regs->srgr2 |= FSGM; |
| 477 | break; |
| 478 | case SND_SOC_DAIFMT_CBM_CFM: |
| 479 | /* McBSP slave */ |
| 480 | break; |
| 481 | default: |
| 482 | /* Unsupported master/slave configuration */ |
| 483 | return -EINVAL; |
| 484 | } |
| 485 | |
| 486 | /* Set bit clock (CLKX/CLKR) and FS polarities */ |
Jarkko Nikula | 91a18ae | 2011-09-30 10:55:32 +0300 | [diff] [blame] | 487 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 488 | case SND_SOC_DAIFMT_NB_NF: |
| 489 | /* |
| 490 | * Normal BCLK + FS. |
| 491 | * FS active low. TX data driven on falling edge of bit clock |
| 492 | * and RX data sampled on rising edge of bit clock. |
| 493 | */ |
| 494 | regs->pcr0 |= FSXP | FSRP | |
| 495 | CLKXP | CLKRP; |
| 496 | break; |
| 497 | case SND_SOC_DAIFMT_NB_IF: |
| 498 | regs->pcr0 |= CLKXP | CLKRP; |
| 499 | break; |
| 500 | case SND_SOC_DAIFMT_IB_NF: |
| 501 | regs->pcr0 |= FSXP | FSRP; |
| 502 | break; |
| 503 | case SND_SOC_DAIFMT_IB_IF: |
| 504 | break; |
| 505 | default: |
| 506 | return -EINVAL; |
| 507 | } |
Jarkko Nikula | 91a18ae | 2011-09-30 10:55:32 +0300 | [diff] [blame] | 508 | if (inv_fs == true) |
| 509 | regs->pcr0 ^= FSXP | FSRP; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
Liam Girdwood | 8687eb8 | 2008-07-07 16:08:07 +0100 | [diff] [blame] | 514 | static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 515 | int div_id, int div) |
| 516 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 517 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 518 | struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; |
| 519 | |
| 520 | if (div_id != OMAP_MCBSP_CLKGDV) |
| 521 | return -ENODEV; |
| 522 | |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 523 | mcbsp_data->clk_div = div; |
Jarkko Nikula | 4dd0417 | 2011-09-30 16:07:44 +0300 | [diff] [blame] | 524 | regs->srgr1 &= ~CLKGDV(0xff); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 525 | regs->srgr1 |= CLKGDV(div - 1); |
| 526 | |
| 527 | return 0; |
| 528 | } |
| 529 | |
Liam Girdwood | 8687eb8 | 2008-07-07 16:08:07 +0100 | [diff] [blame] | 530 | static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 531 | int clk_id, unsigned int freq, |
| 532 | int dir) |
| 533 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 534 | struct omap_mcbsp_data *mcbsp_data = snd_soc_dai_get_drvdata(cpu_dai); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 535 | struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; |
| 536 | int err = 0; |
| 537 | |
Peter Ujfalusi | 141947e | 2011-09-26 10:56:42 +0300 | [diff] [blame] | 538 | if (mcbsp_data->active) { |
Jarkko Nikula | 34c8698 | 2011-09-23 11:19:13 +0300 | [diff] [blame] | 539 | if (freq == mcbsp_data->in_freq) |
| 540 | return 0; |
| 541 | else |
| 542 | return -EBUSY; |
Peter Ujfalusi | 141947e | 2011-09-26 10:56:42 +0300 | [diff] [blame] | 543 | } |
Jarkko Nikula | 34c8698 | 2011-09-23 11:19:13 +0300 | [diff] [blame] | 544 | |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 545 | /* The McBSP signal muxing functions are only available on McBSP1 */ |
| 546 | if (clk_id == OMAP_MCBSP_CLKR_SRC_CLKR || |
| 547 | clk_id == OMAP_MCBSP_CLKR_SRC_CLKX || |
| 548 | clk_id == OMAP_MCBSP_FSR_SRC_FSR || |
| 549 | clk_id == OMAP_MCBSP_FSR_SRC_FSX) |
| 550 | if (cpu_class_is_omap1() || mcbsp_data->bus_id != 0) |
| 551 | return -EINVAL; |
| 552 | |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 553 | mcbsp_data->in_freq = freq; |
Jarkko Nikula | 4dd0417 | 2011-09-30 16:07:44 +0300 | [diff] [blame] | 554 | regs->srgr2 &= ~CLKSM; |
| 555 | regs->pcr0 &= ~SCLKME; |
Graeme Gregory | 5f63ef9 | 2009-11-09 19:02:15 +0000 | [diff] [blame] | 556 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 557 | switch (clk_id) { |
| 558 | case OMAP_MCBSP_SYSCLK_CLK: |
| 559 | regs->srgr2 |= CLKSM; |
| 560 | break; |
| 561 | case OMAP_MCBSP_SYSCLK_CLKS_FCLK: |
Paul Walmsley | d1358657 | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 562 | if (cpu_class_is_omap1()) { |
| 563 | err = -EINVAL; |
| 564 | break; |
| 565 | } |
| 566 | err = omap2_mcbsp_set_clks_src(mcbsp_data->bus_id, |
| 567 | MCBSP_CLKS_PRCM_SRC); |
| 568 | break; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 569 | case OMAP_MCBSP_SYSCLK_CLKS_EXT: |
Paul Walmsley | d1358657 | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 570 | if (cpu_class_is_omap1()) { |
| 571 | err = 0; |
| 572 | break; |
| 573 | } |
| 574 | err = omap2_mcbsp_set_clks_src(mcbsp_data->bus_id, |
| 575 | MCBSP_CLKS_PAD_SRC); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 576 | break; |
| 577 | |
| 578 | case OMAP_MCBSP_SYSCLK_CLKX_EXT: |
| 579 | regs->srgr2 |= CLKSM; |
| 580 | case OMAP_MCBSP_SYSCLK_CLKR_EXT: |
| 581 | regs->pcr0 |= SCLKME; |
| 582 | break; |
Jarkko Nikula | d2c0bda | 2009-08-28 15:35:35 +0300 | [diff] [blame] | 583 | |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 584 | |
Jarkko Nikula | d2c0bda | 2009-08-28 15:35:35 +0300 | [diff] [blame] | 585 | case OMAP_MCBSP_CLKR_SRC_CLKR: |
Janusz Krzysztofik | 2335385 | 2010-11-02 15:50:32 +0100 | [diff] [blame] | 586 | if (cpu_class_is_omap1()) |
| 587 | break; |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 588 | omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKR); |
| 589 | break; |
Jarkko Nikula | d2c0bda | 2009-08-28 15:35:35 +0300 | [diff] [blame] | 590 | case OMAP_MCBSP_CLKR_SRC_CLKX: |
Janusz Krzysztofik | 2335385 | 2010-11-02 15:50:32 +0100 | [diff] [blame] | 591 | if (cpu_class_is_omap1()) |
| 592 | break; |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 593 | omap2_mcbsp1_mux_clkr_src(CLKR_SRC_CLKX); |
| 594 | break; |
Jarkko Nikula | d2c0bda | 2009-08-28 15:35:35 +0300 | [diff] [blame] | 595 | case OMAP_MCBSP_FSR_SRC_FSR: |
Janusz Krzysztofik | 2335385 | 2010-11-02 15:50:32 +0100 | [diff] [blame] | 596 | if (cpu_class_is_omap1()) |
| 597 | break; |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 598 | omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSR); |
| 599 | break; |
Jarkko Nikula | d2c0bda | 2009-08-28 15:35:35 +0300 | [diff] [blame] | 600 | case OMAP_MCBSP_FSR_SRC_FSX: |
Janusz Krzysztofik | 2335385 | 2010-11-02 15:50:32 +0100 | [diff] [blame] | 601 | if (cpu_class_is_omap1()) |
| 602 | break; |
Paul Walmsley | cf4c87a | 2010-10-08 11:40:19 -0600 | [diff] [blame] | 603 | omap2_mcbsp1_mux_fsr_src(FSR_SRC_FSX); |
Jarkko Nikula | d2c0bda | 2009-08-28 15:35:35 +0300 | [diff] [blame] | 604 | break; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 605 | default: |
| 606 | err = -ENODEV; |
| 607 | } |
| 608 | |
| 609 | return err; |
| 610 | } |
| 611 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 612 | static const struct snd_soc_dai_ops mcbsp_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 613 | .startup = omap_mcbsp_dai_startup, |
| 614 | .shutdown = omap_mcbsp_dai_shutdown, |
| 615 | .trigger = omap_mcbsp_dai_trigger, |
Peter Ujfalusi | 75581d2 | 2010-03-03 15:08:09 +0200 | [diff] [blame] | 616 | .delay = omap_mcbsp_dai_delay, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 617 | .hw_params = omap_mcbsp_dai_hw_params, |
| 618 | .set_fmt = omap_mcbsp_dai_set_dai_fmt, |
| 619 | .set_clkdiv = omap_mcbsp_dai_set_clkdiv, |
| 620 | .set_sysclk = omap_mcbsp_dai_set_dai_sysclk, |
| 621 | }; |
| 622 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 623 | static int mcbsp_dai_probe(struct snd_soc_dai *dai) |
| 624 | { |
| 625 | mcbsp_data[dai->id].bus_id = dai->id; |
| 626 | snd_soc_dai_set_drvdata(dai, &mcbsp_data[dai->id].bus_id); |
| 627 | return 0; |
Jarkko Nikula | 8def464 | 2008-10-09 15:57:22 +0300 | [diff] [blame] | 628 | } |
| 629 | |
Michael Opdenacker | 6179b77 | 2011-10-10 07:07:08 +0200 | [diff] [blame] | 630 | static struct snd_soc_dai_driver omap_mcbsp_dai = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 631 | .probe = mcbsp_dai_probe, |
| 632 | .playback = { |
| 633 | .channels_min = 1, |
| 634 | .channels_max = 16, |
| 635 | .rates = OMAP_MCBSP_RATES, |
| 636 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 637 | }, |
| 638 | .capture = { |
| 639 | .channels_min = 1, |
| 640 | .channels_max = 16, |
| 641 | .rates = OMAP_MCBSP_RATES, |
| 642 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 643 | }, |
| 644 | .ops = &mcbsp_dai_ops, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 645 | }; |
Jarkko Nikula | 8def464 | 2008-10-09 15:57:22 +0300 | [diff] [blame] | 646 | |
G, Manjunath Kondaiah | 3484457 | 2010-09-08 08:53:43 +0530 | [diff] [blame] | 647 | static int omap_mcbsp_st_info_volsw(struct snd_kcontrol *kcontrol, |
Ilkka Koskinen | 83905c1 | 2010-02-22 12:21:12 +0000 | [diff] [blame] | 648 | struct snd_ctl_elem_info *uinfo) |
| 649 | { |
| 650 | struct soc_mixer_control *mc = |
| 651 | (struct soc_mixer_control *)kcontrol->private_value; |
| 652 | int max = mc->max; |
| 653 | int min = mc->min; |
| 654 | |
| 655 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 656 | uinfo->count = 1; |
| 657 | uinfo->value.integer.min = min; |
| 658 | uinfo->value.integer.max = max; |
| 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | #define OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(id, channel) \ |
| 663 | static int \ |
| 664 | omap_mcbsp##id##_set_st_ch##channel##_volume(struct snd_kcontrol *kc, \ |
| 665 | struct snd_ctl_elem_value *uc) \ |
| 666 | { \ |
| 667 | struct soc_mixer_control *mc = \ |
| 668 | (struct soc_mixer_control *)kc->private_value; \ |
| 669 | int max = mc->max; \ |
| 670 | int min = mc->min; \ |
| 671 | int val = uc->value.integer.value[0]; \ |
| 672 | \ |
| 673 | if (val < min || val > max) \ |
| 674 | return -EINVAL; \ |
| 675 | \ |
| 676 | /* OMAP McBSP implementation uses index values 0..4 */ \ |
| 677 | return omap_st_set_chgain((id)-1, channel, val); \ |
| 678 | } |
| 679 | |
| 680 | #define OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(id, channel) \ |
| 681 | static int \ |
| 682 | omap_mcbsp##id##_get_st_ch##channel##_volume(struct snd_kcontrol *kc, \ |
| 683 | struct snd_ctl_elem_value *uc) \ |
| 684 | { \ |
| 685 | s16 chgain; \ |
| 686 | \ |
| 687 | if (omap_st_get_chgain((id)-1, channel, &chgain)) \ |
| 688 | return -EAGAIN; \ |
| 689 | \ |
| 690 | uc->value.integer.value[0] = chgain; \ |
| 691 | return 0; \ |
| 692 | } |
| 693 | |
| 694 | OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 0) |
| 695 | OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(2, 1) |
| 696 | OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 0) |
| 697 | OMAP_MCBSP_ST_SET_CHANNEL_VOLUME(3, 1) |
| 698 | OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 0) |
| 699 | OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(2, 1) |
| 700 | OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 0) |
| 701 | OMAP_MCBSP_ST_GET_CHANNEL_VOLUME(3, 1) |
| 702 | |
| 703 | static int omap_mcbsp_st_put_mode(struct snd_kcontrol *kcontrol, |
| 704 | struct snd_ctl_elem_value *ucontrol) |
| 705 | { |
| 706 | struct soc_mixer_control *mc = |
| 707 | (struct soc_mixer_control *)kcontrol->private_value; |
| 708 | u8 value = ucontrol->value.integer.value[0]; |
| 709 | |
| 710 | if (value == omap_st_is_enabled(mc->reg)) |
| 711 | return 0; |
| 712 | |
| 713 | if (value) |
| 714 | omap_st_enable(mc->reg); |
| 715 | else |
| 716 | omap_st_disable(mc->reg); |
| 717 | |
| 718 | return 1; |
| 719 | } |
| 720 | |
| 721 | static int omap_mcbsp_st_get_mode(struct snd_kcontrol *kcontrol, |
| 722 | struct snd_ctl_elem_value *ucontrol) |
| 723 | { |
| 724 | struct soc_mixer_control *mc = |
| 725 | (struct soc_mixer_control *)kcontrol->private_value; |
| 726 | |
| 727 | ucontrol->value.integer.value[0] = omap_st_is_enabled(mc->reg); |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static const struct snd_kcontrol_new omap_mcbsp2_st_controls[] = { |
| 732 | SOC_SINGLE_EXT("McBSP2 Sidetone Switch", 1, 0, 1, 0, |
| 733 | omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode), |
| 734 | OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 0 Volume", |
| 735 | -32768, 32767, |
| 736 | omap_mcbsp2_get_st_ch0_volume, |
| 737 | omap_mcbsp2_set_st_ch0_volume), |
| 738 | OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP2 Sidetone Channel 1 Volume", |
| 739 | -32768, 32767, |
| 740 | omap_mcbsp2_get_st_ch1_volume, |
| 741 | omap_mcbsp2_set_st_ch1_volume), |
| 742 | }; |
| 743 | |
| 744 | static const struct snd_kcontrol_new omap_mcbsp3_st_controls[] = { |
| 745 | SOC_SINGLE_EXT("McBSP3 Sidetone Switch", 2, 0, 1, 0, |
| 746 | omap_mcbsp_st_get_mode, omap_mcbsp_st_put_mode), |
| 747 | OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 0 Volume", |
| 748 | -32768, 32767, |
| 749 | omap_mcbsp3_get_st_ch0_volume, |
| 750 | omap_mcbsp3_set_st_ch0_volume), |
| 751 | OMAP_MCBSP_SOC_SINGLE_S16_EXT("McBSP3 Sidetone Channel 1 Volume", |
| 752 | -32768, 32767, |
| 753 | omap_mcbsp3_get_st_ch1_volume, |
| 754 | omap_mcbsp3_set_st_ch1_volume), |
| 755 | }; |
| 756 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 757 | int omap_mcbsp_st_add_controls(struct snd_soc_dai *dai) |
Ilkka Koskinen | 83905c1 | 2010-02-22 12:21:12 +0000 | [diff] [blame] | 758 | { |
| 759 | if (!cpu_is_omap34xx()) |
| 760 | return -ENODEV; |
| 761 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 762 | switch (dai->id) { |
Ilkka Koskinen | 83905c1 | 2010-02-22 12:21:12 +0000 | [diff] [blame] | 763 | case 1: /* McBSP 2 */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 764 | return snd_soc_add_dai_controls(dai, omap_mcbsp2_st_controls, |
Ilkka Koskinen | 83905c1 | 2010-02-22 12:21:12 +0000 | [diff] [blame] | 765 | ARRAY_SIZE(omap_mcbsp2_st_controls)); |
| 766 | case 2: /* McBSP 3 */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 767 | return snd_soc_add_dai_controls(dai, omap_mcbsp3_st_controls, |
Ilkka Koskinen | 83905c1 | 2010-02-22 12:21:12 +0000 | [diff] [blame] | 768 | ARRAY_SIZE(omap_mcbsp3_st_controls)); |
| 769 | default: |
| 770 | break; |
| 771 | } |
| 772 | |
| 773 | return -EINVAL; |
| 774 | } |
| 775 | EXPORT_SYMBOL_GPL(omap_mcbsp_st_add_controls); |
| 776 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 777 | static __devinit int asoc_mcbsp_probe(struct platform_device *pdev) |
| 778 | { |
| 779 | return snd_soc_register_dai(&pdev->dev, &omap_mcbsp_dai); |
| 780 | } |
| 781 | |
| 782 | static int __devexit asoc_mcbsp_remove(struct platform_device *pdev) |
| 783 | { |
| 784 | snd_soc_unregister_dai(&pdev->dev); |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | static struct platform_driver asoc_mcbsp_driver = { |
| 789 | .driver = { |
| 790 | .name = "omap-mcbsp-dai", |
| 791 | .owner = THIS_MODULE, |
| 792 | }, |
| 793 | |
| 794 | .probe = asoc_mcbsp_probe, |
| 795 | .remove = __devexit_p(asoc_mcbsp_remove), |
| 796 | }; |
| 797 | |
Axel Lin | beda5bf5 | 2011-11-25 10:12:16 +0800 | [diff] [blame] | 798 | module_platform_driver(asoc_mcbsp_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 799 | |
Jarkko Nikula | 7ec41ee | 2011-08-11 15:44:57 +0300 | [diff] [blame] | 800 | MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@bitmer.com>"); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 801 | MODULE_DESCRIPTION("OMAP I2S SoC Interface"); |
| 802 | MODULE_LICENSE("GPL"); |