cyb4_linux/sound/soc/s3c/smdk2416_rt5627.c

582 lines
14 KiB
C

/*
* smdk6400_rt5627.c -- SoC audio for Neo1973
*
*
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <sound/driver.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <asm/mach-types.h>
#include <asm/hardware/scoop.h>
#include <asm/arch/regs-iis.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>
#include <asm/arch/audio.h>
#include <asm/io.h>
#include <asm/arch/spi-gpio.h>
//#if !defined(CONFIG_CPU_S3C6400) && !defined(CONFIG_CPU_S3C6410)
//#include <asm/arch/regs-clock.h>
//#else
//#include <asm/arch/regs-s3c6400-clock.h>
//#endif
//////////////////////////
//HIKO : for 2416 setting
//////////////////////////
//#include <asm-arm/arch-s3c2410/regs-s3c6400-clock.h>
//#include <asm-arm/arch-s3c2410/regs-s3c2416-clock.h>
#include <asm/arch/regs-s3c2450-clock.h>
#include <asm-arm/delay.h>
//#include <asm/arch/regs-s3c6400-clock.h>
//HIKO DEBUG: for REALTEK 5627 on ebook proj
//#include <asm-arm/arch-s3c2410/regs-gpio.h>
#include "../codecs/rt5627.h"
#include "s3c-pcm.h"
#include "s3c-i2s.h"
/* define the scenarios */
#define SMDK6400_AUDIO_OFF 0
#define SMDK6400_CAPTURE_MIC1 3
#define SMDK6400_STEREO_TO_HEADPHONES 2
#define SMDK6400_CAPTURE_LINE_IN 1
#ifdef CONFIG_SND_DEBUG
#define s3cdbg(x...) printk(x)
#else
#define s3cdbg(x...)
#endif
static int smdk6400_hifi_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_codec_dai *codec_dai = rtd->dai->codec_dai;
struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
unsigned int pll_out = 0/*, bclk = 0*/;
int ret = 0;
unsigned int regs;
unsigned int prescaler=0;
//s3cdbg("Entered %s, rate = %d\n", __FUNCTION__, params_rate(params));
printk("Entered %s, rate = %d\n", __FUNCTION__, params_rate(params));
/* Select Clock source EPLL */
// regs = ioremap(S3C2410_PA_CLKPWR,0x20);
regs = readl(S3C2443_CLKSRC);
regs &= ~(3<<12);
regs &= ~(3<<14);
regs |= S3C2450_CLKSRC_I2S1_EPLL;
regs = (regs & ~(3<<7))|(2<<7);
writel(regs, S3C2443_CLKSRC);
regs |= (1<<6);
writel(regs, S3C2443_CLKSRC);
regs = readl(S3C2443_SCLKCON);
regs |= S3C2443_SCLKCON_I2SCLK_1;
writel(regs, S3C2443_SCLKCON);
//s3cdbg("%s: %d , params = %d \n", __FUNCTION__, __LINE__, params_rate(params));
printk("%s: %d , params = %d \n", __FUNCTION__, __LINE__, params_rate(params));
switch (params_rate(params)) {
case 8000:
case 16000:
case 32000:
case 48000:
case 64000:
case 96000:
writel(9962, S3C2450_EPLLCON_K);
writel((49<<16)|(1<<8)|(3<<0) ,S3C2443_EPLLCON);
break;
case 11025:
case 22050:
case 44100:
case 88200:
writel(10381, S3C2450_EPLLCON_K);
writel((45<<16)|(1<<8)|(2<<0) ,S3C2443_EPLLCON);
break;
default:
printk("Unsupported rate = %d\n", params_rate(params));
break;
}
switch (params_rate(params)) {
case 8000:
// bclk = WM8753_BCLK_DIV_16;
pll_out = 18432000;
prescaler = 24;
break;
case 11025:
// bclk = WM8753_BCLK_DIV_16;
pll_out = 16934400;
prescaler = 32;
break;
case 16000:
// bclk = WM8753_BCLK_DIV_8;
pll_out = 18432000;
prescaler = 12;
break;
case 22050:
// bclk = WM8753_BCLK_DIV_2;
pll_out = 16934400;
prescaler = 16;
break;
case 32000:
// bclk = WM8753_BCLK_DIV_4;
pll_out = 18432000;
prescaler = 6;
break;
case 44100:
// bclk = WM8753_BCLK_DIV_4;
pll_out = 16934400;
prescaler = 8;
break;
case 48000:
// bclk = WM8753_BCLK_DIV_4;
pll_out = 18432000;
prescaler = 4;
break;
case 64000:
// bclk = WM8753_BCLK_DIV_4;
pll_out = 18432000;
prescaler = 3;
break;
case 88200:
// bclk = WM8753_BCLK_DIV_4;
pll_out = 16934400;
prescaler = 4;
break;
case 96000:
// bclk = WM8753_BCLK_DIV_4;
pll_out = 18432000;
prescaler = 2;
break;
}
/* set codec DAI configuration */
ret = codec_dai->dai_ops.set_fmt(codec_dai,
SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS );
if (ret < 0)
return ret;
/* set cpu DAI configuration */
ret = cpu_dai->dai_ops.set_fmt(cpu_dai,
SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS );
if (ret < 0)
return ret;
#if 0
/* set the codec system clock for DAC and ADC */
ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8753_MCLK, pll_out,
SND_SOC_CLOCK_IN);
if (ret < 0)
return ret;
#endif //0
/* set MCLK division for sample rate */
ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
S3C2410_IISMOD_32FS );
if (ret < 0)
return ret;
#if 0
/* set codec BCLK division for sample rate */
ret = codec_dai->dai_ops.set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
if (ret < 0)
return ret;
/* set prescaler division for sample rate */
ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
((prescaler/2 - 1) << 0x8));
if (ret < 0)
return ret;
#endif //0
#if 0
/* set the codec register set for capture and play */
ret = codec_dai->dai_ops.set_tdm_slot(codec_dai, substream->stream, 2);
if (ret < 0)
return ret;
#endif
return 0;
}
static int smdk6400_hifi_hw_free(struct snd_pcm_substream *substream)
{
// struct snd_soc_pcm_runtime *rtd = substream->private_data;
// struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
return 0;
}
/*
* Neo1973 rt5627 HiFi DAI opserations.
*/
static struct snd_soc_ops smdk6400_hifi_ops = {
.hw_params = smdk6400_hifi_hw_params,
.hw_free = smdk6400_hifi_hw_free,
};
static int smdk6400_scenario = 0;
static int smdk6400_get_scenario(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
ucontrol->value.integer.value[0] = smdk6400_scenario;
return 0;
}
static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
{
switch(smdk6400_scenario) {
case SMDK6400_AUDIO_OFF:
snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
snd_soc_dapm_set_endpoint(codec, "Mic1 Jack", 0);
snd_soc_dapm_set_endpoint(codec, "Line In Jack", 0);
break;
case SMDK6400_STEREO_TO_HEADPHONES:
snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
snd_soc_dapm_set_endpoint(codec, "Mic1 Jack", 0);
snd_soc_dapm_set_endpoint(codec, "Line In Jack", 0);
break;
case SMDK6400_CAPTURE_MIC1:
snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
snd_soc_dapm_set_endpoint(codec, "Mic1 Jack", 1);
snd_soc_dapm_set_endpoint(codec, "Line In Jack", 0);
break;
case SMDK6400_CAPTURE_LINE_IN:
snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
snd_soc_dapm_set_endpoint(codec, "Mic1 Jack", 0);
snd_soc_dapm_set_endpoint(codec, "Line In Jack", 1);
break;
default:
snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
snd_soc_dapm_set_endpoint(codec, "Mic1 Jack", 1);
snd_soc_dapm_set_endpoint(codec, "Line In Jack", 1);
break;
}
snd_soc_dapm_sync_endpoints(codec);
return 0;
}
static int smdk6400_set_scenario(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
if (smdk6400_scenario == ucontrol->value.integer.value[0])
return 0;
smdk6400_scenario = ucontrol->value.integer.value[0];
set_scenario_endpoints(codec, smdk6400_scenario);
return 1;
}
static const struct snd_soc_dapm_widget rt5627_dapm_widgets[] = {
SND_SOC_DAPM_HP("Headphone Jack", NULL),
SND_SOC_DAPM_MIC("Mic1 Jack", NULL),
SND_SOC_DAPM_LINE("Line In Jack", NULL),
};
/* example machine audio_mapnections */
static const char* audio_map[][3] = {
{"Headphone Jack", NULL, "LOUT1"},
{"Headphone Jack", NULL, "ROUT1"},
/* mic is connected to mic1 - with bias */
/* mic is connected to mic1 - with bias */
{"MIC1", NULL, "Mic1 Jack"},
{"LINE1", NULL, "Line In Jack"},
{"LINE2", NULL, "Line In Jack"},
/* Connect the ALC pins */
{"ACIN", NULL, "ACOP"},
{NULL, NULL, NULL},
};
static const char *smdk_scenarios[] = {
"Off",
"Capture Line In",
"Headphones",
"Capture Mic1",
};
static const struct soc_enum smdk_scenario_enum[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(smdk_scenarios),smdk_scenarios),
};
static const struct snd_kcontrol_new rt5627_smdk6400_controls[] = {
SOC_ENUM_EXT("SMDK Mode", smdk_scenario_enum[0],
smdk6400_get_scenario, smdk6400_set_scenario),
};
/*
* This is an example machine initialisation for a rt5627 connected to a
* smdk6400. It is missing logic to detect hp/mic insertions and logic
* to re-route the audio in such an event.
*/
static int smdk6400_rt5627_init(struct snd_soc_codec *codec)
{
int i, err;
/* set endpoints to default mode */
set_scenario_endpoints(codec, SMDK6400_AUDIO_OFF);
printk(KERN_NOTICE "[HIKO AUDIO]smdk6400_rt5627_init()\n");
/* Add smdk6400 specific widgets */
for (i = 0; i < ARRAY_SIZE(rt5627_dapm_widgets); i++)
snd_soc_dapm_new_control(codec, &rt5627_dapm_widgets[i]);
/* add smdk6400 specific controls */
for (i = 0; i < ARRAY_SIZE(rt5627_smdk6400_controls); i++) {
err = snd_ctl_add(codec->card,
snd_soc_cnew(&rt5627_smdk6400_controls[i],
codec, NULL));
if (err < 0)
return err;
}
/* set up smdk6400 specific audio path audio_mapnects */
for (i = 0; audio_map[i][0] != NULL; i++) {
snd_soc_dapm_connect_input(codec, audio_map[i][0],
audio_map[i][1], audio_map[i][2]);
}
/* always connected */
snd_soc_dapm_set_endpoint(codec, "Mic1 Jack", 1);
snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
snd_soc_dapm_set_endpoint(codec, "Line In Jack", 1);
snd_soc_dapm_sync_endpoints(codec);
return 0;
}
static struct snd_soc_dai_link smdk6400_dai[] = {
{ /* Hifi Playback - for similatious use with voice below */
.name = "RT5627",
.stream_name = "RT5627 HiFi",
.cpu_dai = &s3c_i2s_dai,
.codec_dai = &rt5627_dai,
.init = smdk6400_rt5627_init,
.ops = &smdk6400_hifi_ops,
},
};
static struct snd_soc_machine smdk6400 = {
.name = "smdk2416",
.dai_link = smdk6400_dai,
.num_links = ARRAY_SIZE(smdk6400_dai),
};
//ALC5627 need check A1,ALC5628 dedicate 0x18
static struct rt5627_setup_data smdk6400_rt5627_setup = {
// .i2c_address = 0x18,
.i2c_address = 0x19,
};
static struct snd_soc_device smdk6400_snd_devdata = {
.machine = &smdk6400,
.platform = &s3c24xx_soc_platform,
.codec_dev = &soc_codec_dev_rt5627,
.codec_data = &smdk6400_rt5627_setup,
};
static struct platform_device *smdk6400_snd_device;
static int __init smdk6400_init(void)
{
int ret;
#if 0
//////////////////////////////////////////////////
//HIKO DEBUG: init process for REALTEK 5627
//////////////////////////////////////////////////
//AUDIO [i2s] MCLK setting
s3c2410_gpio_cfgpin(S3C2410_GPE2, S3C2410_GPE2_CDCLK);
//AUDIO [i2s] LRCK setting
s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK);
//AUDIO [i2s] BCLK setting
s3c2410_gpio_cfgpin(S3C2410_GPE1, S3C2410_GPE1_I2SSCLK);
//AUDIO [i2s] DACDAT setting
s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO);
/* set MCLK division for sample rate */
{
//11MHz
// s3c_i2s_set_iispcr_clkdiv_rt5627(5);
// udelay(5);
}
{
void __iomem *regs;
regs = ioremap(S3C2410_PA_IIS, 0x100);
writel(S3C2410_IISCON_IISEN, regs + S3C2410_IISCON);
}
#endif //0
//HIKO DEBUG: for RT5627 which should let MCLK workable firse befor i2c {
// rt5627_i2s_init();
// rt5627_power();
//HIKO DEBUG: for RT5627 which should let MCLK workable firse befor i2c }
//AUDIO Enable pin
// rt5627_i2s_init()
#if 0
/*Set I2C port to controll RT5627 codec*/
s3c2410_gpio_pullup(S3C2410_GPE14, 0);
s3c2410_gpio_pullup(S3C2410_GPE15, 0);
//AUDIO [i2c] SCLK setting
s3c2410_gpio_cfgpin(S3C2410_GPE14, S3C2410_GPE14_IICSCL);
//AUDIO [i2c] SDA setting
s3c2410_gpio_cfgpin(S3C2410_GPE15, S3C2410_GPE15_IICSDA);
udelay(10);
#endif //0
printk(KERN_NOTICE "[HIKO AUDIO]Enable AUDIO HW proc\n");
smdk6400_snd_device = platform_device_alloc("soc-audio", -1);
if (!smdk6400_snd_device)
return -ENOMEM;
platform_set_drvdata(smdk6400_snd_device, &smdk6400_snd_devdata);
smdk6400_snd_devdata.dev = &smdk6400_snd_device->dev;
ret = platform_device_add(smdk6400_snd_device);
if (ret)
platform_device_put(smdk6400_snd_device);
return ret;
}
static void __exit smdk6400_exit(void)
{
platform_device_unregister(smdk6400_snd_device);
}
/*
** The I2S init process for RT5627
*/
void rt5627_i2s_init()
{
void __iomem *regs;
printk("[HIKO]rt5627_i2s_init()\n");
//////////////////////////////////////////////////
//HIKO DEBUG: init process for REALTEK 5627
//////////////////////////////////////////////////
//AUDIO [i2s] LRCK setting
s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK);
//AUDIO [i2s] BCLK setting
s3c2410_gpio_cfgpin(S3C2410_GPE1, S3C2410_GPE1_I2SSCLK);
//AUDIO [i2s] DACDAT setting
s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO);
//AUDIO [i2s] MCLK setting
s3c2410_gpio_cfgpin(S3C2410_GPE2, S3C2410_GPE2_CDCLK);
//MCLK 11MHz
s3c_i2s_set_iispcr_clkdiv_rt5627(5);
//BCLK
//s3c_i2s_set_iisclk_clkdiv_rt5627(0);
regs = ioremap(S3C2410_PA_IIS, 0x100);
writel(S3C2410_IISCON_IISEN, regs + S3C2410_IISCON);
// udelay(10);
}
EXPORT_SYMBOL_GPL(rt5627_i2s_init);
/*
** The I2S init process for RT5627
*/
void rt5627_i2c_init()
{
printk("[HIKO]rt5627_i2c_init()\n");
//AUDIO [i2c] SCLK setting
//I2C PIC_33 enable pin
s3c2410_gpio_cfgpin(S3C2410_GPG3, S3C2410_GPG3_OUTP);
s3c2410_gpio_setpin(S3C2410_GPG3, 1);
s3c2410_gpio_pullup(S3C2410_GPE14, 0);
s3c2410_gpio_pullup(S3C2410_GPE15, 0);
//AUDIO [i2c] SCLK setting
s3c2410_gpio_cfgpin(S3C2410_GPE14, S3C2410_GPE14_IICSCL);
//AUDIO [i2c] SDA setting
s3c2410_gpio_cfgpin(S3C2410_GPE15, S3C2410_GPE15_IICSDA);
// udelay(10);
}
EXPORT_SYMBOL_GPL(rt5627_i2c_init);
/*
** The I2S init process for RT5627
*/
void rt5627_power(bool on)
{
// void __iomem *regs;
printk("[HIKO]rt5627_power(%x)\n", on);
//AUDIO Enable pin
s3c2410_gpio_cfgpin(S3C2410_GPB10, S3C2410_GPB10_OUTP);
s3c2410_gpio_setpin(S3C2410_GPB10, 1);
// udelay(5);
}
EXPORT_SYMBOL_GPL(rt5627_power);
module_init(smdk6400_init);
module_exit(smdk6400_exit);
/* Module information */
MODULE_AUTHOR("flove");
MODULE_DESCRIPTION("ALSA SoC rt5627 Neo1973");
MODULE_LICENSE("GPL");