blob: b26779d780ccfba528a9ee92ab3651fe39e5f3cc [file] [log] [blame]
/*
* tonka.c -- SoC audio for Tonka
*
* Author: Misael Lopez Cruz <misael.lopez@ti.com>
* Liam Girdwood <lrg@ti.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#include <sound/jack.h>
#include <sound/pcm_params.h>
#include <sound/soc-dapm.h>
#include <sound/soc-dsp.h>
#include <asm/mach-types.h>
#include <plat/hardware.h>
#include <plat/mux.h>
#include <plat/mcbsp.h>
#include "omap-pcm.h"
#include "omap-abe.h"
#include "omap-abe-dsp.h"
#include "omap-mcbsp.h"
static int tonka_mcbsp_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
int ret = 0;
unsigned int channels, div;
/* Codec reference clock. */
ret = snd_soc_dai_set_sysclk(codec_dai, 0, 12000000, SND_SOC_CLOCK_IN);
if (unlikely(ret < 0)) {
dev_err(codec_dai->dev, "can't set reference clock\n");
return ret;
}
if (params != NULL) {
/* Configure McBSP internal buffer usage */
/* this need to be done for playback and/or record */
channels = params_channels(params);
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
omap_mcbsp_set_tx_threshold(cpu_dai->id, channels);
else
omap_mcbsp_set_rx_threshold(cpu_dai->id, channels);
}
/* Clock master mode; derive bit clock from FCLK. */
ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKS_FCLK,
24576000, SND_SOC_CLOCK_IN);
if (unlikely(ret < 0)) {
dev_err(cpu_dai->dev, "can't set reference clock\n");
return ret;
}
switch (params_rate(params)) {
case 44100: /* XXX 45176 */
div = 17;
break;
case 48000:
div = 16;
break;
default:
dev_err(cpu_dai->dev, "unknown rate %d\n", params_rate(params));
return -EINVAL;
}
ret = snd_soc_dai_set_clkdiv(cpu_dai, OMAP_MCBSP_CLKGDV, div);
if (unlikely(ret < 0)) {
dev_err(cpu_dai->dev, "can't set clock divider\n");
return ret;
}
return 0;
}
static struct snd_soc_ops tonka_mcbsp_ops = {
.hw_params = tonka_mcbsp_hw_params,
};
static int tonka_mcbsp_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params)
{
struct snd_interval *channels = hw_param_interval(params,
SNDRV_PCM_HW_PARAM_CHANNELS);
channels->min = 2;
channels->max = 2;
snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
SNDRV_PCM_HW_PARAM_FIRST_MASK],
SNDRV_PCM_FORMAT_S16_LE);
return 0;
}
static int sdp4430_stream_event(struct snd_soc_dapm_context *dapm, int event)
{
#if 0
/*
* set DL1 gains dynamically according to the active output
* (Headset, Earpiece) and HSDAC power mode
*/
return sdp4430_set_pdm_dl1_gains(dapm);
#else
return 0;
#endif
}
static const struct snd_kcontrol_new tonka_controls_display[] = {
};
static const struct snd_soc_dapm_widget tonka_dapm_widgets_display[] = {
};
static const struct snd_soc_dapm_route tonka_dapm_routes_display[] = {
};
static int tonka_display_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_codec *codec = rtd->codec;
struct snd_soc_dapm_context *dapm = &codec->dapm;
int ret;
//snd_soc_dapm_nc_pin(dapm, "MIC3L");
//…
ret = snd_soc_add_controls(codec, tonka_controls_display,
ARRAY_SIZE(tonka_controls_display));
if (unlikely(ret < 0))
return ret;
ret = snd_soc_dapm_new_controls(dapm, tonka_dapm_widgets_display,
ARRAY_SIZE(tonka_dapm_widgets_display));
if (unlikely(ret < 0))
return ret;
ret = snd_soc_dapm_add_routes(dapm, tonka_dapm_routes_display,
ARRAY_SIZE(tonka_dapm_routes_display));
if (unlikely(ret < 0))
return ret;
return 0;
}
static const struct snd_kcontrol_new tonka_controls_speaker[] = {
};
static const struct snd_soc_dapm_widget tonka_dapm_widgets_speaker[] = {
SND_SOC_DAPM_LINE("Line Out", NULL),
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_LINE("Line In", NULL),
SND_SOC_DAPM_MIC("Mic In", NULL),
};
static const struct snd_soc_dapm_route tonka_dapm_routes_speaker[] = {
{"Line Out", NULL, "Speaker LOUT"},
{"Line Out", NULL, "Speaker ROUT"},
{"Headphone Jack", NULL, "Speaker LHPOUT"},
{"Headphone Jack", NULL, "Speaker RHPOUT"},
{"Speaker LLINEIN", NULL, "Line In"},
{"Speaker RLINEIN", NULL, "Line In"},
{"Speaker MICIN", NULL, "Mic In"},
};
static int tonka_speaker_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_codec *codec = rtd->codec;
struct snd_soc_dapm_context *dapm = &codec->dapm;
int ret;
//snd_soc_dapm_nc_pin(dapm, "MIC3L");
//…
ret = snd_soc_add_controls(codec, tonka_controls_speaker,
ARRAY_SIZE(tonka_controls_speaker));
if (unlikely(ret < 0))
return ret;
ret = snd_soc_dapm_new_controls(dapm, tonka_dapm_widgets_speaker,
ARRAY_SIZE(tonka_dapm_widgets_speaker));
if (unlikely(ret < 0))
return ret;
ret = snd_soc_dapm_add_routes(dapm, tonka_dapm_routes_speaker,
ARRAY_SIZE(tonka_dapm_routes_speaker));
if (unlikely(ret < 0))
return ret;
return 0;
}
static struct snd_soc_dsp_link fe_media = {
.playback = true,
.capture = true,
.trigger =
{SND_SOC_DSP_TRIGGER_BESPOKE, SND_SOC_DSP_TRIGGER_BESPOKE},
};
static struct snd_soc_dsp_link fe_media_capture = {
.capture = true,
.trigger =
{SND_SOC_DSP_TRIGGER_BESPOKE, SND_SOC_DSP_TRIGGER_BESPOKE},
};
static struct snd_soc_dsp_link fe_tones = {
.playback = true,
.trigger =
{SND_SOC_DSP_TRIGGER_BESPOKE, SND_SOC_DSP_TRIGGER_BESPOKE},
};
static struct snd_soc_dsp_link fe_lp_media = {
.playback = true,
.trigger =
{SND_SOC_DSP_TRIGGER_BESPOKE, SND_SOC_DSP_TRIGGER_BESPOKE},
};
static struct snd_soc_dai_link tonka_dai[] = {
/*
* Frontend DAIs - i.e. userspace visible interfaces (ALSA PCMs)
*/
{
.name = "Tonka Media",
.stream_name = "Multimedia",
/* ABE components - MM-UL & MM_DL */
.cpu_dai_name = "MultiMedia1",
.platform_name = "omap-pcm-audio",
.dynamic = 1, /* BE is dynamic */
.dsp_link = &fe_media,
},
{
.name = "Tonka Media Capture",
.stream_name = "Multimedia Capture",
/* ABE components - MM-UL2 */
.cpu_dai_name = "MultiMedia2",
.platform_name = "omap-pcm-audio",
.dynamic = 1, /* BE is dynamic */
.dsp_link = &fe_media_capture,
},
{
.name = "Tonka Voice",
.stream_name = "Voice",
/* ABE components - VX-UL & VX-DL */
.cpu_dai_name = "Voice",
.platform_name = "omap-pcm-audio",
.dynamic = 1, /* BE is dynamic */
.dsp_link = &fe_media,
.no_host_mode = SND_SOC_DAI_LINK_OPT_HOST,
},
{
.name = "Tonka Tones Playback",
.stream_name = "Tone Playback",
/* ABE components - TONES_DL */
.cpu_dai_name = "Tones",
.platform_name = "omap-pcm-audio",
.dynamic = 1, /* BE is dynamic */
.dsp_link = &fe_tones,
},
{
.name = "Tonka Media LP",
.stream_name = "Multimedia",
/* ABE components - MM-DL (mmap) */
.cpu_dai_name = "MultiMedia1 LP",
.platform_name = "aess",
.dynamic = 1, /* BE is dynamic */
.dsp_link = &fe_lp_media,
},
/*
* Backend DAIs - i.e. dynamically matched interfaces, invisible to userspace.
* Matched to above interfaces at runtime, based upon use case.
*/
#if 0
{
.name = OMAP_ABE_BE_BT_VX_UL,
.stream_name = "BT Capture",
/* ABE components - MCBSP2 - BT-VX */
.cpu_dai_name = "omap-mcbsp-dai.1",
.platform_name = "aess",
/* Bluetooth */
.codec_dai_name = "tlv320aic23-hifi",
.codec_name = "tlv320aic23-codec.3-001b",
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS,
.init = tonka_display_init,
.no_pcm = 1, /* don't create ALSA pcm for this */
.be_hw_params_fixup = tonka_mcbsp_be_hw_params_fixup,
.ops = &tonka_mcbsp_ops,
.be_id = OMAP_ABE_DAI_BT_VX,
},
{
.name = OMAP_ABE_BE_BT_VX_DL,
.stream_name = "BT Playback",
/* ABE components - MCBSP2 - BT-VX */
.cpu_dai_name = "omap-mcbsp-dai.1",
.platform_name = "aess",
/* Bluetooth */
.codec_dai_name = "tlv320aic23-hifi",
.codec_name = "tlv320aic23-codec.3-001b",
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS,
//.init = tonka_display_init,
.no_pcm = 1, /* don't create ALSA pcm for this */
.be_hw_params_fixup = tonka_mcbsp_be_hw_params_fixup,
.ops = &tonka_mcbsp_ops,
.be_id = OMAP_ABE_DAI_BT_VX,
},
#endif
{
.name = "MM-EXT-UL",
.stream_name = "FM Capture",
/* ABE components - MCBSP1 - MM-EXT */
.cpu_dai_name = "omap-mcbsp-dai.0",
.platform_name = "aess",
/* FM */
.codec_dai_name = "tlv320aic23-hifi",
.codec_name = "tlv320aic23-codec.3-001a",
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS,
.init = tonka_speaker_init,
.no_pcm = 1, /* don't create ALSA pcm for this */
.be_hw_params_fixup = tonka_mcbsp_be_hw_params_fixup,
.ops = &tonka_mcbsp_ops,
.be_id = OMAP_ABE_DAI_MM_FM,
},
{
.name = "MM-EXT-DL",
.stream_name = "FM Playback",
/* ABE components - MCBSP1 - MM-EXT */
.cpu_dai_name = "omap-mcbsp-dai.0",
.platform_name = "aess",
/* FM */
.codec_dai_name = "tlv320aic23-hifi",
.codec_name = "tlv320aic23-codec.3-001a",
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS,
//.init = tonka_speaker_init,
.no_pcm = 1, /* don't create ALSA pcm for this */
.be_hw_params_fixup = tonka_mcbsp_be_hw_params_fixup,
.ops = &tonka_mcbsp_ops,
.be_id = OMAP_ABE_DAI_MM_FM,
},
};
static struct snd_soc_codec_conf tonka_codec_conf[] = {
#if 0
{
.dev_name = "tlv320aic23-codec.3-001b",
.name_prefix = "Display",
},
#endif
{
.dev_name = "tlv320aic23-codec.3-001a",
.name_prefix = "Speaker",
},
};
/* Audio machine driver */
static struct snd_soc_card snd_soc_tonka = {
.name = "Tonka",
.driver_name = "OMAP4",
.long_name = "TI OMAP4 Board",
.dai_link = tonka_dai,
.num_links = ARRAY_SIZE(tonka_dai),
.codec_conf = tonka_codec_conf,
.num_configs = ARRAY_SIZE(tonka_codec_conf),
.stream_event = sdp4430_stream_event,
};
static struct platform_device *tonka_snd_device;
static int __init tonka_soc_init(void)
{
int ret;
printk(KERN_INFO "Tonka SoC init\n");
tonka_snd_device = platform_device_alloc("soc-audio", -1);
if (!tonka_snd_device)
return -ENOMEM;
platform_set_drvdata(tonka_snd_device, &snd_soc_tonka);
ret = platform_device_add(tonka_snd_device);
if (ret)
goto err;
return 0;
err:
platform_device_put(tonka_snd_device);
return ret;
}
module_init(tonka_soc_init);
static void __exit tonka_soc_exit(void)
{
platform_device_unregister(tonka_snd_device);
}
module_exit(tonka_soc_exit);
MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
MODULE_DESCRIPTION("ALSA SoC Tonka");
MODULE_LICENSE("GPL");