rt5639: add rt5639 support

This commit is contained in:
邱建斌
2013-03-04 16:54:36 +08:00
parent 5a90385481
commit e512962e70
11 changed files with 6549 additions and 1 deletions

View File

@@ -82,6 +82,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_RT3261 if I2C
select SND_SOC_RT3224 if I2C
select SND_SOC_RT5623 if I2C
select SND_SOC_RT5639 if I2C
select SND_SOC_RK610 if I2C
select SND_SOC_WM8903 if I2C
select SND_SOC_WM8904 if I2C
@@ -330,6 +331,9 @@ config SND_SOC_RT5621
config SND_SOC_RT5623
tristate
config SND_SOC_RT5639
tristate
config SND_SOC_RT5631
tristate

View File

@@ -94,6 +94,7 @@ snd-soc-rk610-objs := rk610_codec.o
snd-soc-rt3261-objs := rt3261.o rt3261-dsp.o rt3261_ioctl.o rt_codec_ioctl.o
snd-soc-rt3224-objs := rt3261.o rt3261_ioctl.o rt_codec_ioctl.o
snd-soc-rk2928-objs := rk2928_codec.o
snd-soc-rt5639-objs := rt5639.o rt5639_ioctl.o rt56xx_ioctl.o
# Amp
snd-soc-lm4857-objs := lm4857.o
@@ -103,6 +104,7 @@ snd-soc-wm2000-objs := wm2000.o
snd-soc-wm9090-objs := wm9090.o
obj-$(CONFIG_SND_SOC_RT3261) += snd-soc-rt3261.o
obj-$(CONFIG_SND_SOC_RT3224) += snd-soc-rt3224.o
obj-$(CONFIG_SND_SOC_RT5639) += snd-soc-rt5639.o
obj-$(CONFIG_SND_SOC_88PM860X) += snd-soc-88pm860x.o
obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o

3377
sound/soc/codecs/rt5639.c Executable file

File diff suppressed because it is too large Load Diff

2146
sound/soc/codecs/rt5639.h Executable file

File diff suppressed because it is too large Load Diff

468
sound/soc/codecs/rt5639_ioctl.c Executable file
View File

@@ -0,0 +1,468 @@
/*
* rt5639_ioctl.h -- RT5639 ALSA SoC audio driver IO control
*
* Copyright 2012 Realtek Microelectronics
* Author: Bard <bardliao@realtek.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/spi/spi.h>
#include <sound/soc.h>
#include "rt56xx_ioctl.h"
#include "rt5639_ioctl.h"
#include "rt5639.h"
#ifdef CONFIG_SND_SOC_RT5642
#include "rt5639-dsp.h"
#endif
hweq_t hweq_param[] = {
{/* NORMAL */
{0},
{0},
0x0000,
},
{/* SPK */
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2},
{0x1c10,0x01f4, 0xc5e9, 0x1a98, 0x1d2c, 0xc882, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0x1c10, 0x01f4, 0x2000, 0x0000, 0x2000},
0x0000,
},
{/* HP */
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2},
{0x1c10,0x01f4, 0xc5e9, 0x1a98, 0x1d2c, 0xc882, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0x1c10, 0x01f4, 0x2000, 0x0000, 0x2000},
0x0000,
},
};
#define RT5639_HWEQ_LEN ARRAY_SIZE(hweq_param)
int rt5639_update_eqmode(
struct snd_soc_codec *codec, int mode)
{
struct rt56xx_ops *ioctl_ops = rt56xx_get_ioctl_ops();
int i;
static int eqmode;
if(codec == NULL || mode >= RT5639_HWEQ_LEN)
return -EINVAL;
dev_dbg(codec->dev, "%s(): mode=%d\n", __func__, mode);
if(mode == eqmode)
return 0;
for(i = 0; i <= EQ_REG_NUM; i++) {
if(hweq_param[mode].reg[i])
ioctl_ops->index_write(codec, hweq_param[mode].reg[i],
hweq_param[mode].value[i]);
else
break;
}
snd_soc_update_bits(codec, RT5639_EQ_CTRL2, RT5639_EQ_CTRL_MASK,
hweq_param[mode].ctrl);
snd_soc_update_bits(codec, RT5639_EQ_CTRL1,
RT5639_EQ_UPD, RT5639_EQ_UPD);
snd_soc_update_bits(codec, RT5639_EQ_CTRL1, RT5639_EQ_UPD, 0);
eqmode = mode;
return 0;
}
void set_drc_agc_enable(struct snd_soc_codec *codec, int enable, int path)
{
snd_soc_update_bits(codec, RT5639_DRC_AGC_1, RT5639_DRC_AGC_P_MASK |
RT5639_DRC_AGC_MASK | RT5639_DRC_AGC_UPD,
enable << RT5639_DRC_AGC_SFT | path << RT5639_DRC_AGC_P_SFT |
1 << RT5639_DRC_AGC_UPD_BIT);
}
void set_drc_agc_parameters(struct snd_soc_codec *codec, int attack_rate,
int sample_rate, int recovery_rate, int limit_level)
{
snd_soc_update_bits(codec, RT5639_DRC_AGC_3, RT5639_DRC_AGC_TAR_MASK,
limit_level << RT5639_DRC_AGC_TAR_SFT);
snd_soc_update_bits(codec, RT5639_DRC_AGC_1, RT5639_DRC_AGC_AR_MASK |
RT5639_DRC_AGC_R_MASK | RT5639_DRC_AGC_UPD |
RT5639_DRC_AGC_RC_MASK, attack_rate << RT5639_DRC_AGC_AR_SFT |
sample_rate << RT5639_DRC_AGC_R_SFT |
recovery_rate << RT5639_DRC_AGC_RC_SFT |
0x1 << RT5639_DRC_AGC_UPD_BIT);
}
void set_digital_boost_gain(struct snd_soc_codec *codec,
int post_gain, int pre_gain)
{
snd_soc_update_bits(codec, RT5639_DRC_AGC_2,
RT5639_DRC_AGC_POB_MASK | RT5639_DRC_AGC_PRB_MASK,
post_gain << RT5639_DRC_AGC_POB_SFT |
pre_gain << RT5639_DRC_AGC_PRB_SFT);
snd_soc_update_bits(codec, RT5639_DRC_AGC_1,
RT5639_DRC_AGC_UPD, 1 << RT5639_DRC_AGC_UPD_BIT);
}
void set_noise_gate(struct snd_soc_codec *codec, int noise_gate_en,
int noise_gate_hold_en, int compression_gain, int noise_gate_th)
{
snd_soc_update_bits(codec, RT5639_DRC_AGC_3,
RT5639_DRC_AGC_NGB_MASK | RT5639_DRC_AGC_NG_MASK |
RT5639_DRC_AGC_NGH_MASK | RT5639_DRC_AGC_NGT_MASK,
noise_gate_en << RT5639_DRC_AGC_NG_SFT |
noise_gate_hold_en << RT5639_DRC_AGC_NGH_SFT |
compression_gain << RT5639_DRC_AGC_NGB_SFT |
noise_gate_th << RT5639_DRC_AGC_NGT_SFT);
snd_soc_update_bits(codec, RT5639_DRC_AGC_1,
RT5639_DRC_AGC_UPD, 1 << RT5639_DRC_AGC_UPD_BIT);
}
void set_drc_agc_compression(struct snd_soc_codec *codec,
int compression_en, int compression_ratio)
{
snd_soc_update_bits(codec, RT5639_DRC_AGC_2,
RT5639_DRC_AGC_CP_MASK | RT5639_DRC_AGC_CPR_MASK,
compression_en << RT5639_DRC_AGC_CP_SFT |
compression_ratio << RT5639_DRC_AGC_CPR_SFT);
snd_soc_update_bits(codec, RT5639_DRC_AGC_1,
RT5639_DRC_AGC_UPD, 1 << RT5639_DRC_AGC_UPD_BIT);
}
void get_drc_agc_enable(struct snd_soc_codec *codec, int *enable, int *path)
{
unsigned int reg = snd_soc_read(codec, RT5639_DRC_AGC_1);
*enable = (reg & RT5639_DRC_AGC_MASK) >> RT5639_DRC_AGC_SFT;
*path = (reg & RT5639_DRC_AGC_P_MASK) >> RT5639_DRC_AGC_P_SFT;
}
void get_drc_agc_parameters(struct snd_soc_codec *codec, int *attack_rate,
int *sample_rate, int *recovery_rate, int *limit_level)
{
unsigned int reg = snd_soc_read(codec, RT5639_DRC_AGC_3);
*limit_level = (reg & RT5639_DRC_AGC_TAR_MASK) >>
RT5639_DRC_AGC_TAR_SFT;
reg = snd_soc_read(codec, RT5639_DRC_AGC_1);
*attack_rate = (reg & RT5639_DRC_AGC_AR_MASK) >> RT5639_DRC_AGC_AR_SFT;
*sample_rate = (reg & RT5639_DRC_AGC_R_MASK) >> RT5639_DRC_AGC_R_SFT;
*recovery_rate = (reg & RT5639_DRC_AGC_RC_MASK) >>
RT5639_DRC_AGC_RC_SFT;
}
void get_digital_boost_gain(struct snd_soc_codec *codec,
int *post_gain, int *pre_gain)
{
unsigned int reg = snd_soc_read(codec, RT5639_DRC_AGC_2);
*post_gain = (reg & RT5639_DRC_AGC_POB_MASK) >> RT5639_DRC_AGC_POB_SFT;
*pre_gain = (reg & RT5639_DRC_AGC_PRB_MASK) >> RT5639_DRC_AGC_PRB_SFT;
}
void get_noise_gate(struct snd_soc_codec *codec, int *noise_gate_en,
int *noise_gate_hold_en, int *compression_gain, int *noise_gate_th)
{
unsigned int reg = snd_soc_read(codec, RT5639_DRC_AGC_3);
printk("get_noise_gate reg=0x%04x\n",reg);
*noise_gate_en = (reg & RT5639_DRC_AGC_NG_MASK) >>
RT5639_DRC_AGC_NG_SFT;
*noise_gate_hold_en = (reg & RT5639_DRC_AGC_NGH_MASK) >>
RT5639_DRC_AGC_NGH_SFT;
*compression_gain = (reg & RT5639_DRC_AGC_NGB_MASK) >>
RT5639_DRC_AGC_NGB_SFT;
*noise_gate_th = (reg & RT5639_DRC_AGC_NGT_MASK) >>
RT5639_DRC_AGC_NGT_SFT;
}
void get_drc_agc_compression(struct snd_soc_codec *codec,
int *compression_en, int *compression_ratio)
{
unsigned int reg = snd_soc_read(codec, RT5639_DRC_AGC_2);
*compression_en = (reg & RT5639_DRC_AGC_CP_MASK) >>
RT5639_DRC_AGC_CP_SFT;
*compression_ratio = (reg & RT5639_DRC_AGC_CPR_MASK) >>
RT5639_DRC_AGC_CPR_SFT;
}
int rt5639_ioctl_common(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct snd_soc_codec *codec = hw->private_data;
struct rt56xx_cmd __user *_rt56xx = (struct rt56xx_cmd *)arg;
struct rt56xx_cmd rt56xx;
struct rt56xx_ops *ioctl_ops = rt56xx_get_ioctl_ops();
int *buf, mask1 = 0, mask2 = 0;
static int eq_mode;
if (copy_from_user(&rt56xx, _rt56xx, sizeof(rt56xx))) {
dev_err(codec->dev,"copy_from_user faild\n");
return -EFAULT;
}
dev_dbg(codec->dev, "%s(): rt56xx.number=%d, cmd=%d\n",
__func__, rt56xx.number, cmd);
buf = kmalloc(sizeof(*buf) * rt56xx.number, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
if (copy_from_user(buf, rt56xx.buf, sizeof(*buf) * rt56xx.number)) {
goto err;
}
switch (cmd) {
case RT_SET_CODEC_HWEQ_IOCTL:
if (eq_mode == *buf)
break;
eq_mode = *buf;
rt5639_update_eqmode(codec, eq_mode);
break;
case RT_GET_CODEC_ID:
*buf = snd_soc_read(codec, RT5639_VENDOR_ID2);
if (copy_to_user(rt56xx.buf, buf, sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_SET_CODEC_SPK_VOL_IOCTL:
if(*(buf) <= 0x27) {
snd_soc_update_bits(codec, RT5639_SPK_VOL,
RT5639_L_VOL_MASK | RT5639_R_VOL_MASK,
*(buf) << RT5639_L_VOL_SFT |
*(buf) << RT5639_R_VOL_SFT);
}
break;
case RT_SET_CODEC_MIC_GAIN_IOCTL:
if(*(buf) <= 0x8) {
snd_soc_update_bits(codec, RT5639_IN1_IN2,
RT5639_BST_MASK1, *(buf) << RT5639_BST_SFT1);
snd_soc_update_bits(codec, RT5639_IN3_IN4,
RT5639_BST_MASK2, *(buf) << RT5639_BST_SFT2);
}
break;
case RT_SET_CODEC_3D_SPK_IOCTL:
if(rt56xx.number < 4)
break;
if (NULL == ioctl_ops->index_update_bits)
break;
mask1 = 0;
if(*buf != -1)
mask1 |= RT5639_3D_SPK_MASK;
if(*(buf + 1) != -1)
mask1 |= RT5639_3D_SPK_M_MASK;
if(*(buf + 2) != -1)
mask1 |= RT5639_3D_SPK_CG_MASK;
if(*(buf + 3) != -1)
mask1 |= RT5639_3D_SPK_SG_MASK;
ioctl_ops->index_update_bits(codec, RT5639_3D_SPK, mask1,
*(buf) << RT5639_3D_SPK_SFT |
*(buf + 1) << RT5639_3D_SPK_M_SFT |
*(buf + 2) << RT5639_3D_SPK_CG_SFT |
*(buf + 3) << RT5639_3D_SPK_SG_SFT);
break;
case RT_SET_CODEC_MP3PLUS_IOCTL:
if(rt56xx.number < 5)
break;
mask1 = mask2 = 0;
if(*buf != -1)
mask1 |= RT5639_M_MP3_MASK;
if(*(buf + 1) != -1)
mask1 |= RT5639_EG_MP3_MASK;
if(*(buf + 2) != -1)
mask2 |= RT5639_OG_MP3_MASK;
if(*(buf + 3) != -1)
mask2 |= RT5639_HG_MP3_MASK;
if(*(buf + 4) != -1)
mask2 |= RT5639_MP3_WT_MASK;
snd_soc_update_bits(codec, RT5639_MP3_PLUS1, mask1,
*(buf) << RT5639_M_MP3_SFT |
*(buf + 1) << RT5639_EG_MP3_SFT);
snd_soc_update_bits(codec, RT5639_MP3_PLUS2, mask2,
*(buf + 2) << RT5639_OG_MP3_SFT |
*(buf + 3) << RT5639_HG_MP3_SFT |
*(buf + 4) << RT5639_MP3_WT_SFT);
break;
case RT_SET_CODEC_3D_HEADPHONE_IOCTL:
if(rt56xx.number < 4)
break;
if (NULL == ioctl_ops->index_update_bits)
break;
mask1 = 0;
if(*buf != -1)
mask1 |= RT5639_3D_HP_MASK;
if(*(buf + 1) != -1)
mask1 |= RT5639_3D_BT_MASK;
if(*(buf + 2) != -1)
mask1 |= RT5639_3D_1F_MIX_MASK;
if(*(buf + 3) != -1)
mask1 |= RT5639_3D_HP_M_MASK;
snd_soc_update_bits(codec, RT5639_3D_HP, mask1,
*(buf)<<RT5639_3D_HP_SFT |
*(buf + 1) << RT5639_3D_BT_SFT |
*(buf + 2) << RT5639_3D_1F_MIX_SFT |
*(buf + 3) << RT5639_3D_HP_M_SFT);
if(*(buf + 4) != -1)
ioctl_ops->index_update_bits(codec,
0x59, 0x1f, *(buf+4));
break;
case RT_SET_CODEC_BASS_BACK_IOCTL:
if(rt56xx.number < 3)
break;
mask1 = 0;
if(*buf != -1)
mask1 |= RT5639_BB_MASK;
if(*(buf + 1) != -1)
mask1 |= RT5639_BB_CT_MASK;
if(*(buf + 2) != -1)
mask1 |= RT5639_G_BB_BST_MASK;
snd_soc_update_bits(codec, RT5639_BASE_BACK, mask1,
*(buf) << RT5639_BB_SFT |
*(buf + 1) << RT5639_BB_CT_SFT |
*(buf + 2) << RT5639_G_BB_BST_SFT);
break;
case RT_SET_CODEC_DIPOLE_SPK_IOCTL:
if(rt56xx.number < 2)
break;
if (NULL == ioctl_ops->index_update_bits)
break;
mask1 = 0;
if(*buf != -1)
mask1 |= RT5639_DP_SPK_MASK;
if(*(buf + 1) != -1)
mask1 |= RT5639_DP_ATT_MASK;
ioctl_ops->index_update_bits(codec, RT5639_DIP_SPK_INF,
mask1, *(buf) << RT5639_DP_SPK_SFT |
*(buf + 1) << RT5639_DP_ATT_SFT );
break;
case RT_SET_CODEC_DRC_AGC_ENABLE_IOCTL:
if(rt56xx.number < 2)
break;
set_drc_agc_enable(codec, *(buf), *(buf + 1));
break;
case RT_SET_CODEC_DRC_AGC_PAR_IOCTL:
if(rt56xx.number < 4)
break;
set_drc_agc_parameters(codec, *(buf), *(buf + 1),
*(buf + 2), *(buf + 3));
break;
case RT_SET_CODEC_DIGI_BOOST_GAIN_IOCTL:
if(rt56xx.number < 2)
break;
set_digital_boost_gain(codec, *(buf), *(buf + 1));
break;
case RT_SET_CODEC_NOISE_GATE_IOCTL:
if(rt56xx.number < 4)
break;
set_noise_gate(codec, *(buf), *(buf + 1),
*(buf + 2), *(buf + 3));
break;
case RT_SET_CODEC_DRC_AGC_COMP_IOCTL:
if(rt56xx.number < 2)
break;
set_drc_agc_compression(codec, *(buf), *(buf + 1));
break;
case RT_SET_CODEC_WNR_ENABLE_IOCTL:
if (NULL == ioctl_ops->index_update_bits)
break;
ioctl_ops->index_update_bits(codec, RT5639_WND_1,
RT5639_WND_MASK, *(buf) << RT5639_WND_SFT );
break;
case RT_GET_CODEC_DRC_AGC_ENABLE_IOCTL:
if(rt56xx.number < 2)
break;
get_drc_agc_enable(codec, (buf), (buf + 1));
if (copy_to_user(rt56xx.buf, buf, sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_GET_CODEC_DRC_AGC_PAR_IOCTL:
if(rt56xx.number < 4)
break;
get_drc_agc_parameters(codec, (buf), (buf + 1),
(buf + 2), (buf + 3));
if (copy_to_user(rt56xx.buf, buf,
sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_GET_CODEC_DIGI_BOOST_GAIN_IOCTL:
if(rt56xx.number < 2)
break;
get_digital_boost_gain(codec, (buf), (buf + 1));
if (copy_to_user(rt56xx.buf, buf,
sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_GET_CODEC_NOISE_GATE_IOCTL:
if(rt56xx.number < 4)
break;
get_noise_gate(codec, (buf), (buf + 1), (buf + 2), (buf + 3));
if (copy_to_user(rt56xx.buf, buf,
sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_GET_CODEC_DRC_AGC_COMP_IOCTL:
if(rt56xx.number < 2)
break;
get_drc_agc_compression(codec, (buf), (buf + 1));
if (copy_to_user(rt56xx.buf, buf,
sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_GET_CODEC_SPK_VOL_IOCTL:
*buf = (snd_soc_read(codec, RT5639_SPK_VOL) & RT5639_L_VOL_MASK)
>> RT5639_L_VOL_SFT;
if (copy_to_user(rt56xx.buf, buf, sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_GET_CODEC_MIC_GAIN_IOCTL:
*buf = (snd_soc_read(codec, RT5639_IN1_IN2) & RT5639_BST_MASK1)
>> RT5639_BST_SFT1;
if (copy_to_user(rt56xx.buf, buf, sizeof(*buf) * rt56xx.number))
goto err;
break;
#ifdef CONFIG_SND_SOC_RT5642
case RT_READ_CODEC_DSP_IOCTL:
case RT_WRITE_CODEC_DSP_IOCTL:
case RT_GET_CODEC_DSP_MODE_IOCTL:
return rt56xx_dsp_ioctl_common(hw, file, cmd, arg);
#endif
case RT_GET_CODEC_HWEQ_IOCTL:
case RT_GET_CODEC_3D_SPK_IOCTL:
case RT_GET_CODEC_MP3PLUS_IOCTL:
case RT_GET_CODEC_3D_HEADPHONE_IOCTL:
case RT_GET_CODEC_BASS_BACK_IOCTL:
case RT_GET_CODEC_DIPOLE_SPK_IOCTL:
default:
break;
}
kfree(buf);
return 0;
err:
kfree(buf);
return -EFAULT;
}
EXPORT_SYMBOL_GPL(rt5639_ioctl_common);

37
sound/soc/codecs/rt5639_ioctl.h Executable file
View File

@@ -0,0 +1,37 @@
/*
* rt5639_ioctl.h -- RT5639 ALSA SoC audio driver IO control
*
* Copyright 2012 Realtek Microelectronics
* Author: Bard <bardliao@realtek.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.
*/
#ifndef __RT5639_IOCTL_H__
#define __RT5639_IOCTL_H__
#include <sound/hwdep.h>
#include <linux/ioctl.h>
enum {
NORMAL=0,
SPK,
HP,
MODE_NUM,
};
#define EQ_REG_NUM 19
typedef struct hweq_s {
unsigned int reg[EQ_REG_NUM];
unsigned int value[EQ_REG_NUM];
unsigned int ctrl;
} hweq_t;
int rt5639_ioctl_common(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg);
int rt5639_update_eqmode(
struct snd_soc_codec *codec, int mode);
#endif /* __RT5639_IOCTL_H__ */

179
sound/soc/codecs/rt56xx_ioctl.c Executable file
View File

@@ -0,0 +1,179 @@
/*
* rt56xx_ioctl.h -- RT56XX ALSA SoC audio driver IO control
*
* Copyright 2012 Realtek Microelectronics
* Author: Bard <bardliao@realtek.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/spi/spi.h>
#include <sound/soc.h>
#include "rt56xx_ioctl.h"
static struct rt56xx_ops rt56xx_ioctl_ops;
#if defined(CONFIG_SND_HWDEP) || defined(CONFIG_SND_HWDEP_MODULE)
#define RT_CE_CODEC_HWDEP_NAME "rt56xx hwdep "
static int rt56xx_hwdep_open(struct snd_hwdep *hw, struct file *file)
{
struct snd_soc_codec *codec = hw->private_data;
dev_dbg(codec->dev, "%s()\n", __func__);
return 0;
}
static int rt56xx_hwdep_release(struct snd_hwdep *hw, struct file *file)
{
struct snd_soc_codec *codec = hw->private_data;
dev_dbg(codec->dev, "%s()\n", __func__);
return 0;
}
static int rt56xx_hwdep_ioctl_common(struct snd_hwdep *hw,
struct file *file, unsigned int cmd, unsigned long arg)
{
struct snd_soc_codec *codec = hw->private_data;
struct rt56xx_cmd __user *_rt56xx = (struct rt56xx_cmd *)arg;
struct rt56xx_cmd rt56xx;
int *buf, *p;
if (copy_from_user(&rt56xx, _rt56xx, sizeof(rt56xx))) {
dev_err(codec->dev,"copy_from_user faild\n");
return -EFAULT;
}
dev_dbg(codec->dev, "%s(): rt56xx.number=%d, cmd=%d\n",
__func__, rt56xx.number, cmd);
buf = kmalloc(sizeof(*buf) * rt56xx.number, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
if (copy_from_user(buf, rt56xx.buf, sizeof(*buf) * rt56xx.number)) {
goto err;
}
switch (cmd) {
case RT_READ_CODEC_REG_IOCTL:
for (p = buf; p < buf + rt56xx.number / 2; p++) {
*(p + rt56xx.number / 2) = snd_soc_read(codec, *p);
}
if (copy_to_user(rt56xx.buf, buf, sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_WRITE_CODEC_REG_IOCTL:
for (p = buf; p < buf + rt56xx.number / 2; p++)
snd_soc_write(codec, *p, *(p + rt56xx.number / 2));
break;
case RT_READ_CODEC_INDEX_IOCTL:
if (NULL == rt56xx_ioctl_ops.index_read)
goto err;
for (p = buf; p < buf + rt56xx.number / 2; p++)
*(p+rt56xx.number/2) = rt56xx_ioctl_ops.index_read(
codec, *p);
if (copy_to_user(rt56xx.buf, buf,
sizeof(*buf) * rt56xx.number))
goto err;
break;
case RT_WRITE_CODEC_INDEX_IOCTL:
if (NULL == rt56xx_ioctl_ops.index_write)
goto err;
for (p = buf; p < buf + rt56xx.number / 2; p++)
rt56xx_ioctl_ops.index_write(codec, *p,
*(p+rt56xx.number/2));
break;
default:
if (NULL == rt56xx_ioctl_ops.ioctl_common)
goto err;
rt56xx_ioctl_ops.ioctl_common(hw, file, cmd, arg);
break;
}
kfree(buf);
return 0;
err:
kfree(buf);
return -EFAULT;
}
static int rt56xx_codec_dump_reg(struct snd_hwdep *hw,
struct file *file, unsigned long arg)
{
struct snd_soc_codec *codec = hw->private_data;
struct rt56xx_cmd __user *_rt56xx =(struct rt56xx_cmd *)arg;
struct rt56xx_cmd rt56xx;
int i, *buf, number = codec->driver->reg_cache_size;
dev_dbg(codec->dev, "enter %s, number = %d\n", __func__, number);
if (copy_from_user(&rt56xx, _rt56xx, sizeof(rt56xx)))
return -EFAULT;
buf = kmalloc(sizeof(*buf) * number, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
for (i = 0; i < number/2; i++) {
buf[i] = i << 1;
buf[i + number / 2] = codec->read(codec, buf[i]);
}
if (copy_to_user(rt56xx.buf, buf, sizeof(*buf) * i))
goto err;
rt56xx.number = number;
if (copy_to_user(_rt56xx, &rt56xx, sizeof(rt56xx)))
goto err;
kfree(buf);
return 0;
err:
kfree(buf);
return -EFAULT;
}
static int rt56xx_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg)
{
switch (cmd) {
case RT_READ_ALL_CODEC_REG_IOCTL:
return rt56xx_codec_dump_reg(hw, file, arg);
default:
return rt56xx_hwdep_ioctl_common(hw, file, cmd, arg);
}
return 0;
}
int realtek_ce_init_hwdep(struct snd_soc_codec *codec)
{
struct snd_hwdep *hw;
struct snd_card *card = codec->card->snd_card;
int err;
dev_dbg(codec->dev, "enter %s\n", __func__);
if ((err = snd_hwdep_new(card, RT_CE_CODEC_HWDEP_NAME, 0, &hw)) < 0)
return err;
strcpy(hw->name, RT_CE_CODEC_HWDEP_NAME);
hw->private_data = codec;
hw->ops.open = rt56xx_hwdep_open;
hw->ops.release = rt56xx_hwdep_release;
hw->ops.ioctl = rt56xx_hwdep_ioctl;
return 0;
}
EXPORT_SYMBOL_GPL(realtek_ce_init_hwdep);
#endif
struct rt56xx_ops *rt56xx_get_ioctl_ops(void)
{
return &rt56xx_ioctl_ops;
}
EXPORT_SYMBOL_GPL(rt56xx_get_ioctl_ops);

78
sound/soc/codecs/rt56xx_ioctl.h Executable file
View File

@@ -0,0 +1,78 @@
/*
* rt56xx_ioctl.h -- RT56XX ALSA SoC audio driver IO control
*
* Copyright 2012 Realtek Microelectronics
* Author: Bard <bardliao@realtek.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.
*/
#ifndef __RT56XX_IOCTL_H__
#define __RT56XX_IOCTL_H__
#include <sound/hwdep.h>
#include <linux/ioctl.h>
struct rt56xx_cmd {
size_t number;
int __user *buf;
};
struct rt56xx_ops {
int (*index_write)(struct snd_soc_codec *codec,
unsigned int reg, unsigned int value);
unsigned int (*index_read)(struct snd_soc_codec *codec,
unsigned int reg);
int (*index_update_bits)(struct snd_soc_codec *codec,
unsigned int reg, unsigned int mask, unsigned int value);
int (*ioctl_common)(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg);
};
enum {
RT_READ_CODEC_REG_IOCTL = _IOR('R', 0x01, struct rt56xx_cmd),
RT_WRITE_CODEC_REG_IOCTL = _IOW('R', 0x01, struct rt56xx_cmd),
RT_READ_ALL_CODEC_REG_IOCTL = _IOR('R', 0x02, struct rt56xx_cmd),
RT_READ_CODEC_INDEX_IOCTL = _IOR('R', 0x03, struct rt56xx_cmd),
RT_WRITE_CODEC_INDEX_IOCTL = _IOW('R', 0x03, struct rt56xx_cmd),
RT_READ_CODEC_DSP_IOCTL = _IOR('R', 0x04, struct rt56xx_cmd),
RT_WRITE_CODEC_DSP_IOCTL = _IOW('R', 0x04, struct rt56xx_cmd),
RT_SET_CODEC_HWEQ_IOCTL = _IOW('R', 0x05, struct rt56xx_cmd),
RT_GET_CODEC_HWEQ_IOCTL = _IOR('R', 0x05, struct rt56xx_cmd),
RT_SET_CODEC_SPK_VOL_IOCTL = _IOW('R', 0x06, struct rt56xx_cmd),
RT_GET_CODEC_SPK_VOL_IOCTL = _IOR('R', 0x06, struct rt56xx_cmd),
RT_SET_CODEC_MIC_GAIN_IOCTL = _IOW('R', 0x07, struct rt56xx_cmd),
RT_GET_CODEC_MIC_GAIN_IOCTL = _IOR('R', 0x07, struct rt56xx_cmd),
RT_SET_CODEC_3D_SPK_IOCTL = _IOW('R', 0x08, struct rt56xx_cmd),
RT_GET_CODEC_3D_SPK_IOCTL = _IOR('R', 0x08, struct rt56xx_cmd),
RT_SET_CODEC_MP3PLUS_IOCTL = _IOW('R', 0x09, struct rt56xx_cmd),
RT_GET_CODEC_MP3PLUS_IOCTL = _IOR('R', 0x09, struct rt56xx_cmd),
RT_SET_CODEC_3D_HEADPHONE_IOCTL = _IOW('R', 0x0a, struct rt56xx_cmd),
RT_GET_CODEC_3D_HEADPHONE_IOCTL = _IOR('R', 0x0a, struct rt56xx_cmd),
RT_SET_CODEC_BASS_BACK_IOCTL = _IOW('R', 0x0b, struct rt56xx_cmd),
RT_GET_CODEC_BASS_BACK_IOCTL = _IOR('R', 0x0b, struct rt56xx_cmd),
RT_SET_CODEC_DIPOLE_SPK_IOCTL = _IOW('R', 0x0c, struct rt56xx_cmd),
RT_GET_CODEC_DIPOLE_SPK_IOCTL = _IOR('R', 0x0c, struct rt56xx_cmd),
RT_SET_CODEC_DRC_AGC_ENABLE_IOCTL = _IOW('R', 0x0d, struct rt56xx_cmd),
RT_GET_CODEC_DRC_AGC_ENABLE_IOCTL = _IOR('R', 0x0d, struct rt56xx_cmd),
RT_SET_CODEC_DSP_MODE_IOCTL = _IOW('R', 0x0e, struct rt56xx_cmd),
RT_GET_CODEC_DSP_MODE_IOCTL = _IOR('R', 0x0e, struct rt56xx_cmd),
RT_SET_CODEC_WNR_ENABLE_IOCTL = _IOW('R', 0x0f, struct rt56xx_cmd),
RT_GET_CODEC_WNR_ENABLE_IOCTL = _IOR('R', 0x0f, struct rt56xx_cmd),
RT_SET_CODEC_DRC_AGC_PAR_IOCTL = _IOW('R', 0x10, struct rt56xx_cmd),
RT_GET_CODEC_DRC_AGC_PAR_IOCTL = _IOR('R', 0x10, struct rt56xx_cmd),
RT_SET_CODEC_DIGI_BOOST_GAIN_IOCTL = _IOW('R', 0x11, struct rt56xx_cmd),
RT_GET_CODEC_DIGI_BOOST_GAIN_IOCTL = _IOR('R', 0x11, struct rt56xx_cmd),
RT_SET_CODEC_NOISE_GATE_IOCTL = _IOW('R', 0x12, struct rt56xx_cmd),
RT_GET_CODEC_NOISE_GATE_IOCTL = _IOR('R', 0x12, struct rt56xx_cmd),
RT_SET_CODEC_DRC_AGC_COMP_IOCTL = _IOW('R', 0x13, struct rt56xx_cmd),
RT_GET_CODEC_DRC_AGC_COMP_IOCTL = _IOR('R', 0x13, struct rt56xx_cmd),
RT_GET_CODEC_ID = _IOR('R', 0x30, struct rt56xx_cmd),
};
int realtek_ce_init_hwdep(struct snd_soc_codec *codec);
struct rt56xx_ops *rt56xx_get_ioctl_ops(void);
#endif /* __RT56XX_IOCTL_H__ */

View File

@@ -144,7 +144,15 @@ config SND_RK29_SOC_RT3224
select SND_SOC_RT3224
help
RT3224 is pin to pin as RT3261, but not have dsp function.
config SND_RK29_SOC_RT5639
tristate "SoC I2S Audio support for rockchip - RT5639"
depends on SND_RK29_SOC
select SND_RK29_SOC_I2S
select SND_SOC_RT5639
help
rt5639
config SND_RK29_SOC_RT3261
tristate "SoC I2S Audio support for rockchip - RT3261"
depends on SND_RK29_SOC

View File

@@ -19,6 +19,7 @@ snd-soc-rt5631-phone-objs := rk29_rt5631_phone.o
snd-soc-rt5625-objs := rk29_rt5625.o
snd-soc-rt3261-objs := rk29_rt3261.o
snd-soc-rt3224-objs := rk29_rt3261.o
snd-soc-rt5639-objs := rk29_rt5639.o
snd-soc-cs42l52-objs := rk29_cs42l52.o
snd-soc-aic3111-objs := rk29_aic3111.o
snd-soc-wm8988-objs := rk29_wm8988.o
@@ -38,6 +39,7 @@ obj-$(CONFIG_SND_RK29_SOC_RT5631_PHONE) += snd-soc-rt5631-phone.o
obj-$(CONFIG_SND_RK29_SOC_RT5625) += snd-soc-rt5625.o
obj-$(CONFIG_SND_RK29_SOC_RT3261) += snd-soc-rt3261.o
obj-$(CONFIG_SND_RK29_SOC_RT3224) += snd-soc-rt3224.o
obj-$(CONFIG_SND_RK29_SOC_RT5639) += snd-soc-rt5639.o
obj-$(CONFIG_SND_RK29_SOC_RK1000) += snd-soc-rk1000.o
obj-$(CONFIG_SND_RK29_SOC_CS42L52) += snd-soc-cs42l52.o
obj-$(CONFIG_SND_RK29_SOC_AIC3111) += snd-soc-aic3111.o

247
sound/soc/rk29/rk29_rt5639.c Executable file
View File

@@ -0,0 +1,247 @@
/*
* rk29_rt5625.c -- SoC audio for rockchip
*
* Driver for rockchip rt5625 audio
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
*
*/
#include <linux/module.h>
#include <linux/device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <asm/io.h>
#include <mach/hardware.h>
#include "../codecs/rt3261.h"
#include "rk29_pcm.h"
#include "rk29_i2s.h"
#if 1
#define DBG(x...) printk(KERN_INFO x)
#else
#define DBG(x...)
#endif
static int rk29_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;
unsigned int pll_out = 0;
int ret;
DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
/*by Vincent Hsiung for EQ Vol Change*/
#define HW_PARAMS_FLAG_EQVOL_ON 0x21
#define HW_PARAMS_FLAG_EQVOL_OFF 0x22
if (codec_dai->driver->ops->hw_params && ((params->flags == HW_PARAMS_FLAG_EQVOL_ON) || (params->flags == HW_PARAMS_FLAG_EQVOL_OFF)))
{
ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai); //by Vincent
DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
} else {
/* set codec DAI configuration */
#if defined (CONFIG_SND_RK29_CODEC_SOC_SLAVE)
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
#endif
#if defined (CONFIG_SND_RK29_CODEC_SOC_MASTER)
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM );
#endif
if (ret < 0)
return ret;
/* set cpu DAI configuration */
#if defined (CONFIG_SND_RK29_CODEC_SOC_SLAVE)
ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
#endif
#if defined (CONFIG_SND_RK29_CODEC_SOC_MASTER)
ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
#endif
if (ret < 0)
return ret;
}
switch(params_rate(params)) {
case 8000:
case 16000:
case 24000:
case 32000:
case 48000:
pll_out = 12288000;
break;
case 11025:
case 22050:
case 44100:
pll_out = 11289600;
break;
default:
DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
return -EINVAL;
break;
}
DBG("Enter:%s, %d, rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
/*Set the system clk for codec*/
ret = snd_soc_dai_set_sysclk(codec_dai, 0, pll_out, SND_SOC_CLOCK_IN);
if (ret < 0)
{
DBG("rk29_hw_params_rt5625:failed to set the sysclk for codec side\n");
return ret;
}
snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_BCLK, (pll_out/4)/params_rate(params)-1);
snd_soc_dai_set_clkdiv(cpu_dai, ROCKCHIP_DIV_MCLK, 3);
DBG("Enter:%s, %d, pll_out/4/params_rate(params) = %d \n", __FUNCTION__, __LINE__, (pll_out/4)/params_rate(params));
return 0;
}
static int rt3261_voice_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;
unsigned int pll_out = 0;
int ret;
DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
/* set codec DAI configuration */
//#if defined (CONFIG_SND_CODEC_SOC_SLAVE)
DBG("Enter::%s----codec slave\n",__FUNCTION__);
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |
SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS);
/*#endif
//#if defined (CONFIG_SND_CODEC_SOC_MASTER)
DBG("Enter::%s----codec master\n",__FUNCTION__);
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |
SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBM_CFM );
#endif*/
switch(params_rate(params)) {
case 8000:
case 16000:
case 24000:
case 32000:
case 48000:
pll_out = 12288000;
break;
case 11025:
case 22050:
case 44100:
pll_out = 11289600;
break;
default:
DBG("Enter:%s, %d, Error rate=%d\n", __FUNCTION__, __LINE__, params_rate(params));
return -EINVAL;
break;
}
//snd_soc_dai_set_pll(codec_dai, RT5625_PLL_MCLK_TO_VSYSCLK, 0, pll_out, 24576000);???????
/*Set the system clk for codec*/
ret = snd_soc_dai_set_sysclk(codec_dai, 0, 24576000, SND_SOC_CLOCK_IN);
if (ret < 0) {
printk("rk29_hw_params_rt5625:failed to set the sysclk for codec side\n");
return ret;
}
ret = snd_soc_dai_set_sysclk(cpu_dai, 0, pll_out, 0);
return 0;
}
static struct snd_soc_ops rk29_ops = {
.hw_params = rk29_hw_params,
};
static struct snd_soc_ops rt5639_voice_ops = {
.hw_params = rt3261_voice_hw_params,
};
static struct snd_soc_dai_link rk29_dai[] = {
{
.name = "RT5639 I2S1",
.stream_name = "RT5639 PCM",
.codec_name = "rt5639.0-001c",
.platform_name = "rockchip-audio",
.cpu_dai_name = "rk29_i2s.0",
.codec_dai_name = "rt5639-aif1",
.ops = &rk29_ops,
},
{
.name = "RT5639 I2S2",
.stream_name = "RT5639 PCM",
.codec_name = "rt5639.0-001c",
.platform_name = "rockchip-audio",
.cpu_dai_name = "rk29_i2s.0",
.codec_dai_name = "rt5639-aif2",
.ops = &rt5639_voice_ops,
},
};
static struct snd_soc_card snd_soc_card_rk29 = {
.name = "RK29_RT5639",
.dai_link = rk29_dai,
.num_links = 2,
};
static struct platform_device *rk29_snd_device;
static int __init audio_card_init(void)
{
int ret =0;
DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__);
rk29_snd_device = platform_device_alloc("soc-audio", -1);
if (!rk29_snd_device) {
printk("platform device allocation failed\n");
return -ENOMEM;
}
platform_set_drvdata(rk29_snd_device, &snd_soc_card_rk29);
ret = platform_device_add(rk29_snd_device);
if (ret) {
printk("platform device add failed\n");
platform_device_put(rk29_snd_device);
return ret;
}
return ret;
}
static void __exit audio_card_exit(void)
{
platform_device_unregister(rk29_snd_device);
}
module_init(audio_card_init);
module_exit(audio_card_exit);
/* Module information */
MODULE_AUTHOR("rockchip");
MODULE_DESCRIPTION("ROCKCHIP i2s ASoC Interface");
MODULE_LICENSE("GPL");