2009-03-28 12:47:02 -06:00
|
|
|
/*
|
|
|
|
* ASoC driver for Stretch s6105 IP camera platform
|
|
|
|
*
|
|
|
|
* Author: Daniel Gloeckner, <dg@emlix.com>
|
|
|
|
* Copyright: (C) 2009 emlix GmbH <info@emlix.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
2009-08-20 15:50:42 -06:00
|
|
|
#include <linux/i2c.h>
|
2009-03-28 12:47:02 -06:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
|
|
|
#include <variant/dmac.h>
|
|
|
|
|
|
|
|
#include "s6000-pcm.h"
|
|
|
|
#include "s6000-i2s.h"
|
|
|
|
|
|
|
|
#define S6105_CAM_CODEC_CLOCK 12288000
|
|
|
|
|
|
|
|
static int s6105_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-17 14:15:21 -06:00
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
2009-03-28 12:47:02 -06:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* set codec DAI configuration */
|
|
|
|
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
|
|
|
|
SND_SOC_DAIFMT_CBM_CFM);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* set cpu DAI configuration */
|
|
|
|
ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
|
2009-04-06 03:50:22 -06:00
|
|
|
SND_SOC_DAIFMT_NB_NF);
|
2009-03-28 12:47:02 -06:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* set the codec system clock */
|
|
|
|
ret = snd_soc_dai_set_sysclk(codec_dai, 0, S6105_CAM_CODEC_CLOCK,
|
|
|
|
SND_SOC_CLOCK_OUT);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_soc_ops s6105_ops = {
|
|
|
|
.hw_params = s6105_hw_params,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* s6105 machine dapm widgets */
|
|
|
|
static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_LINE("Audio Out Differential", NULL),
|
|
|
|
SND_SOC_DAPM_LINE("Audio Out Stereo", NULL),
|
|
|
|
SND_SOC_DAPM_LINE("Audio In", NULL),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* s6105 machine audio_mapnections to the codec pins */
|
|
|
|
static const struct snd_soc_dapm_route audio_map[] = {
|
|
|
|
/* Audio Out connected to HPLOUT, HPLCOM, HPROUT */
|
|
|
|
{"Audio Out Differential", NULL, "HPLOUT"},
|
|
|
|
{"Audio Out Differential", NULL, "HPLCOM"},
|
|
|
|
{"Audio Out Stereo", NULL, "HPLOUT"},
|
|
|
|
{"Audio Out Stereo", NULL, "HPROUT"},
|
|
|
|
|
|
|
|
/* Audio In connected to LINE1L, LINE1R */
|
|
|
|
{"LINE1L", NULL, "Audio In"},
|
|
|
|
{"LINE1R", NULL, "Audio In"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int output_type_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
|
|
|
uinfo->count = 1;
|
|
|
|
uinfo->value.enumerated.items = 2;
|
|
|
|
if (uinfo->value.enumerated.item) {
|
|
|
|
uinfo->value.enumerated.item = 1;
|
|
|
|
strcpy(uinfo->value.enumerated.name, "HPLOUT/HPROUT");
|
|
|
|
} else {
|
|
|
|
strcpy(uinfo->value.enumerated.name, "HPLOUT/HPLCOM");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int output_type_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
ucontrol->value.enumerated.item[0] = kcontrol->private_value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int output_type_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = kcontrol->private_data;
|
2010-11-05 07:53:46 -06:00
|
|
|
struct snd_soc_dapm_context *dapm = &codec->dapm;
|
2009-03-28 12:47:02 -06:00
|
|
|
unsigned int val = (ucontrol->value.enumerated.item[0] != 0);
|
|
|
|
char *differential = "Audio Out Differential";
|
|
|
|
char *stereo = "Audio Out Stereo";
|
|
|
|
|
|
|
|
if (kcontrol->private_value == val)
|
|
|
|
return 0;
|
|
|
|
kcontrol->private_value = val;
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_disable_pin(dapm, val ? differential : stereo);
|
|
|
|
snd_soc_dapm_sync(dapm);
|
|
|
|
snd_soc_dapm_enable_pin(dapm, val ? stereo : differential);
|
|
|
|
snd_soc_dapm_sync(dapm);
|
2009-03-28 12:47:02 -06:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new audio_out_mux = {
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "Master Output Mux",
|
|
|
|
.index = 0,
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
|
|
|
|
.info = output_type_info,
|
|
|
|
.get = output_type_get,
|
|
|
|
.put = output_type_put,
|
|
|
|
.private_value = 1 /* default to stereo */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Logic for a aic3x as connected on the s6105 ip camera ref design */
|
2010-03-17 14:15:21 -06:00
|
|
|
static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd)
|
2009-03-28 12:47:02 -06:00
|
|
|
{
|
2010-03-17 14:15:21 -06:00
|
|
|
struct snd_soc_codec *codec = rtd->codec;
|
2010-11-05 07:53:46 -06:00
|
|
|
struct snd_soc_dapm_context *dapm = &codec->dapm;
|
2010-03-17 14:15:21 -06:00
|
|
|
|
2009-03-28 12:47:02 -06:00
|
|
|
/* Add s6105 specific widgets */
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
|
2009-03-28 12:47:02 -06:00
|
|
|
ARRAY_SIZE(aic3x_dapm_widgets));
|
|
|
|
|
|
|
|
/* Set up s6105 specific audio path audio_map */
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
|
2009-03-28 12:47:02 -06:00
|
|
|
|
|
|
|
/* not present */
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
|
|
|
|
snd_soc_dapm_nc_pin(dapm, "LINE2L");
|
|
|
|
snd_soc_dapm_nc_pin(dapm, "LINE2R");
|
2009-03-28 12:47:02 -06:00
|
|
|
|
|
|
|
/* not connected */
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_nc_pin(dapm, "MIC3L"); /* LINE2L on this chip */
|
|
|
|
snd_soc_dapm_nc_pin(dapm, "MIC3R"); /* LINE2R on this chip */
|
|
|
|
snd_soc_dapm_nc_pin(dapm, "LLOUT");
|
|
|
|
snd_soc_dapm_nc_pin(dapm, "RLOUT");
|
|
|
|
snd_soc_dapm_nc_pin(dapm, "HPRCOM");
|
2009-03-28 12:47:02 -06:00
|
|
|
|
|
|
|
/* always connected */
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_enable_pin(dapm, "Audio In");
|
2009-03-28 12:47:02 -06:00
|
|
|
|
|
|
|
/* must correspond to audio_out_mux.private_value initializer */
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_disable_pin(dapm, "Audio Out Differential");
|
|
|
|
snd_soc_dapm_sync(dapm);
|
|
|
|
snd_soc_dapm_enable_pin(dapm, "Audio Out Stereo");
|
2009-03-28 12:47:02 -06:00
|
|
|
|
2010-11-05 07:53:46 -06:00
|
|
|
snd_soc_dapm_sync(dapm);
|
2009-03-28 12:47:02 -06:00
|
|
|
|
2010-11-29 17:00:18 -07:00
|
|
|
snd_ctl_add(codec->card->snd_card, snd_ctl_new1(&audio_out_mux, codec));
|
2009-03-28 12:47:02 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* s6105 digital audio interface glue - connects codec <--> CPU */
|
|
|
|
static struct snd_soc_dai_link s6105_dai = {
|
|
|
|
.name = "TLV320AIC31",
|
|
|
|
.stream_name = "AIC31",
|
2010-03-17 14:15:21 -06:00
|
|
|
.cpu_dai_name = "s6000-i2s",
|
|
|
|
.codec_dai_name = "tlv320aic3x-hifi",
|
|
|
|
.platform_name = "s6000-pcm-audio",
|
|
|
|
.codec_name = "tlv320aic3x-codec.0-001a",
|
2009-03-28 12:47:02 -06:00
|
|
|
.init = s6105_aic3x_init,
|
|
|
|
.ops = &s6105_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* s6105 audio machine driver */
|
|
|
|
static struct snd_soc_card snd_soc_card_s6105 = {
|
|
|
|
.name = "Stretch IP Camera",
|
|
|
|
.dai_link = &s6105_dai,
|
|
|
|
.num_links = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct s6000_snd_platform_data __initdata s6105_snd_data = {
|
|
|
|
.wide = 0,
|
|
|
|
.channel_in = 0,
|
|
|
|
.channel_out = 1,
|
|
|
|
.lines_in = 1,
|
|
|
|
.lines_out = 1,
|
|
|
|
.same_rate = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *s6105_snd_device;
|
|
|
|
|
2009-08-20 15:50:42 -06:00
|
|
|
/* temporary i2c device creation until this can be moved into the machine
|
|
|
|
* support file.
|
|
|
|
*/
|
|
|
|
static struct i2c_board_info i2c_device[] = {
|
|
|
|
{ I2C_BOARD_INFO("tlv320aic33", 0x18), }
|
|
|
|
};
|
|
|
|
|
2009-03-28 12:47:02 -06:00
|
|
|
static int __init s6105_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2009-08-20 15:50:42 -06:00
|
|
|
i2c_register_board_info(0, i2c_device, ARRAY_SIZE(i2c_device));
|
|
|
|
|
2009-03-28 12:47:02 -06:00
|
|
|
s6105_snd_device = platform_device_alloc("soc-audio", -1);
|
|
|
|
if (!s6105_snd_device)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
platform_set_drvdata(s6105_snd_device, &snd_soc_card_s6105);
|
2009-03-28 12:47:02 -06:00
|
|
|
platform_device_add_data(s6105_snd_device, &s6105_snd_data,
|
|
|
|
sizeof(s6105_snd_data));
|
|
|
|
|
|
|
|
ret = platform_device_add(s6105_snd_device);
|
|
|
|
if (ret)
|
|
|
|
platform_device_put(s6105_snd_device);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit s6105_exit(void)
|
|
|
|
{
|
|
|
|
platform_device_unregister(s6105_snd_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(s6105_init);
|
|
|
|
module_exit(s6105_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Daniel Gloeckner");
|
|
|
|
MODULE_DESCRIPTION("Stretch s6105 IP camera ASoC driver");
|
|
|
|
MODULE_LICENSE("GPL");
|