MLK-17156-4: ASoC: rpmsg_wm8960: add rpmsg_wm8960 codec
This codec is accessed by rpmsg. As the wm8960 is controlled mainly by M4, so we only add volume in this rpmsg_wm8960 codec. Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com> Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
This commit is contained in:
parent
49e4648fd9
commit
00fde5e57f
|
@ -222,6 +222,7 @@ config SND_SOC_ALL_CODECS
|
|||
select SND_SOC_WM9705 if SND_SOC_AC97_BUS
|
||||
select SND_SOC_WM9712 if SND_SOC_AC97_BUS
|
||||
select SND_SOC_WM9713 if SND_SOC_AC97_BUS
|
||||
select SND_SOC_RPMSG_WM8960
|
||||
help
|
||||
Normally ASoC codec drivers are only built if a machine driver which
|
||||
uses them is also built since they are only usable with a machine
|
||||
|
@ -1175,6 +1176,9 @@ config SND_SOC_ZX_AUD96P22
|
|||
depends on I2C
|
||||
select REGMAP_I2C
|
||||
|
||||
config SND_SOC_RPMSG_WM8960
|
||||
tristate
|
||||
|
||||
# Amp
|
||||
config SND_SOC_LM4857
|
||||
tristate
|
||||
|
|
|
@ -236,6 +236,7 @@ snd-soc-wm9712-objs := wm9712.o
|
|||
snd-soc-wm9713-objs := wm9713.o
|
||||
snd-soc-wm-hubs-objs := wm_hubs.o
|
||||
snd-soc-zx-aud96p22-objs := zx_aud96p22.o
|
||||
snd-soc-rpmsg-wm8960-objs := rpmsg_wm8960.o
|
||||
# Amp
|
||||
snd-soc-dio2125-objs := dio2125.o
|
||||
snd-soc-max9877-objs := max9877.o
|
||||
|
@ -480,6 +481,7 @@ obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
|
|||
obj-$(CONFIG_SND_SOC_WM_ADSP) += snd-soc-wm-adsp.o
|
||||
obj-$(CONFIG_SND_SOC_WM_HUBS) += snd-soc-wm-hubs.o
|
||||
obj-$(CONFIG_SND_SOC_ZX_AUD96P22) += snd-soc-zx-aud96p22.o
|
||||
obj-$(CONFIG_SND_SOC_RPMSG_WM8960) += snd-soc-rpmsg-wm8960.o
|
||||
|
||||
# Amp
|
||||
obj-$(CONFIG_SND_SOC_DIO2125) += snd-soc-dio2125.o
|
||||
|
|
178
sound/soc/codecs/rpmsg_wm8960.c
Normal file
178
sound/soc/codecs/rpmsg_wm8960.c
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2017 NXP
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <sound/core.h>
|
||||
#include <sound/pcm.h>
|
||||
#include <sound/pcm_params.h>
|
||||
#include <sound/soc.h>
|
||||
#include <sound/tlv.h>
|
||||
#include "../fsl/fsl_rpmsg_i2s.h"
|
||||
|
||||
#define WM8960_LINVOL 0x0
|
||||
#define WM8960_RINVOL 0x1
|
||||
#define WM8960_LOUT1 0x2
|
||||
#define WM8960_ROUT1 0x3
|
||||
#define WM8960_LDAC 0xa
|
||||
#define WM8960_RDAC 0xb
|
||||
#define WM8960_LADC 0x15
|
||||
#define WM8960_RADC 0x16
|
||||
#define WM8960_LOUT2 0x28
|
||||
#define WM8960_ROUT2 0x29
|
||||
|
||||
static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1);
|
||||
static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1725, 75, 0);
|
||||
static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
|
||||
static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
|
||||
|
||||
static struct snd_kcontrol_new rpmsg_wm8960_ctrls[] = {
|
||||
SOC_DOUBLE_R_TLV("Capture Volume", WM8960_LINVOL, WM8960_RINVOL,
|
||||
0, 63, 0, inpga_tlv),
|
||||
SOC_DOUBLE_R_TLV("Playback Volume", WM8960_LDAC, WM8960_RDAC,
|
||||
0, 255, 0, dac_tlv),
|
||||
SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8960_LOUT1, WM8960_ROUT1,
|
||||
0, 127, 0, out_tlv),
|
||||
SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8960_LOUT2, WM8960_ROUT2,
|
||||
0, 127, 0, out_tlv),
|
||||
SOC_DOUBLE_R_TLV("ADC PCM Capture Volume", WM8960_LADC, WM8960_RADC,
|
||||
0, 255, 0, adc_tlv),
|
||||
};
|
||||
|
||||
#define RPMSG_RATES (SNDRV_PCM_RATE_8000_48000 |\
|
||||
SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
|
||||
|
||||
#define RPMSG_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
|
||||
SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
|
||||
|
||||
static struct snd_soc_dai_driver rpmsg_wm8960_codec_dai = {
|
||||
.name = "rpmsg-wm8960-hifi",
|
||||
.playback = {
|
||||
.stream_name = "Playback",
|
||||
.channels_min = 2,
|
||||
.channels_max = 2,
|
||||
.rates = RPMSG_RATES,
|
||||
.formats = RPMSG_FORMATS,
|
||||
},
|
||||
.capture = {
|
||||
.stream_name = "Capture",
|
||||
.channels_min = 2,
|
||||
.channels_max = 2,
|
||||
.rates = RPMSG_RATES,
|
||||
.formats = RPMSG_FORMATS,
|
||||
},
|
||||
};
|
||||
|
||||
static unsigned int rpmsg_wm8960_read(struct snd_soc_codec *codec, unsigned int reg)
|
||||
{
|
||||
struct fsl_rpmsg_i2s *rpmsg_i2s = snd_soc_codec_get_drvdata(codec);
|
||||
struct i2s_info *i2s_info = &rpmsg_i2s->i2s_info;
|
||||
struct i2s_rpmsg_s *rpmsg = &i2s_info->send_msg[RPMSG_AUDIO_I2C];
|
||||
int err, reg_val;
|
||||
|
||||
mutex_lock(&i2s_info->i2c_lock);
|
||||
rpmsg->param.buffer_addr = reg;
|
||||
rpmsg->header.cmd = GET_CODEC_VALUE;
|
||||
err = i2s_info->send_message(rpmsg, i2s_info);
|
||||
reg_val = rpmsg->param.buffer_size;
|
||||
mutex_unlock(&i2s_info->i2c_lock);
|
||||
if (err)
|
||||
return 0;
|
||||
|
||||
return reg_val;
|
||||
}
|
||||
|
||||
static int rpmsg_wm8960_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int val)
|
||||
{
|
||||
struct fsl_rpmsg_i2s *rpmsg_i2s = snd_soc_codec_get_drvdata(codec);
|
||||
struct i2s_info *i2s_info = &rpmsg_i2s->i2s_info;
|
||||
struct i2s_rpmsg_s *rpmsg = &i2s_info->send_msg[RPMSG_AUDIO_I2C];
|
||||
int err;
|
||||
|
||||
mutex_lock(&i2s_info->i2c_lock);
|
||||
rpmsg->param.buffer_addr = reg;
|
||||
rpmsg->param.buffer_size = val;
|
||||
rpmsg->header.cmd = SET_CODEC_VALUE;
|
||||
err = i2s_info->send_message(rpmsg, i2s_info);
|
||||
mutex_unlock(&i2s_info->i2c_lock);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rpmsg_wm8960_probe(struct snd_soc_codec *codec)
|
||||
{
|
||||
snd_soc_update_bits(codec, WM8960_LINVOL, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_RINVOL, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_LADC, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_RADC, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_LDAC, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_RDAC, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_LOUT1, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_ROUT1, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_LOUT2, 0x100, 0x100);
|
||||
snd_soc_update_bits(codec, WM8960_ROUT2, 0x100, 0x100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct snd_soc_codec_driver rpmsg_wm8960_codec = {
|
||||
.probe = rpmsg_wm8960_probe,
|
||||
.read = rpmsg_wm8960_read,
|
||||
.write = rpmsg_wm8960_write,
|
||||
.component_driver = {
|
||||
.controls = rpmsg_wm8960_ctrls,
|
||||
.num_controls = ARRAY_SIZE(rpmsg_wm8960_ctrls),
|
||||
},
|
||||
};
|
||||
|
||||
static int rpmsg_wm8960_codec_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct fsl_rpmsg_i2s *rpmsg_i2s = dev_get_drvdata(pdev->dev.parent);
|
||||
int ret;
|
||||
|
||||
ret = snd_soc_register_codec(dev,
|
||||
&rpmsg_wm8960_codec,
|
||||
&rpmsg_wm8960_codec_dai,
|
||||
1);
|
||||
if (ret) {
|
||||
dev_err(dev, "%s: snd_soc_register_codec() failed (%d)\n",
|
||||
__func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev_set_drvdata(dev, rpmsg_i2s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rpmsg_wm8960_codec_remove(struct platform_device *pdev)
|
||||
{
|
||||
snd_soc_unregister_codec(&pdev->dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver rpmsg_wm8960_codec_driver = {
|
||||
.driver = {
|
||||
.name = RPMSG_CODEC_DRV_NAME,
|
||||
},
|
||||
.probe = rpmsg_wm8960_codec_probe,
|
||||
.remove = rpmsg_wm8960_codec_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(rpmsg_wm8960_codec_driver);
|
||||
|
||||
MODULE_DESCRIPTION("rpmsg wm8960 Codec Driver");
|
||||
MODULE_LICENSE("GPL");
|
Loading…
Reference in a new issue