Merge remote-tracking branch 'asoc/topic/new-pcm' into asoc-next
This commit is contained in:
commit
c8a538417e
|
@ -0,0 +1,18 @@
|
||||||
|
Texas Instruments pcm1792a DT bindings
|
||||||
|
|
||||||
|
This driver supports the SPI bus.
|
||||||
|
|
||||||
|
Required properties:
|
||||||
|
|
||||||
|
- compatible: "ti,pcm1792a"
|
||||||
|
|
||||||
|
For required properties on SPI, please consult
|
||||||
|
Documentation/devicetree/bindings/spi/spi-bus.txt
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
codec_spi: 1792a@0 {
|
||||||
|
compatible = "ti,pcm1792a";
|
||||||
|
spi-max-frequency = <600000>;
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
Texas Instruments PCM1681 8-channel PWM Processor
|
||||||
|
|
||||||
|
Required properties:
|
||||||
|
|
||||||
|
- compatible: Should contain "ti,pcm1681".
|
||||||
|
- reg: The i2c address. Should contain <0x4c>.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
i2c_bus {
|
||||||
|
pcm1681@4c {
|
||||||
|
compatible = "ti,pcm1681";
|
||||||
|
reg = <0x4c>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -56,6 +56,8 @@ config SND_SOC_ALL_CODECS
|
||||||
select SND_SOC_MC13783 if MFD_MC13XXX
|
select SND_SOC_MC13783 if MFD_MC13XXX
|
||||||
select SND_SOC_ML26124 if I2C
|
select SND_SOC_ML26124 if I2C
|
||||||
select SND_SOC_HDMI_CODEC
|
select SND_SOC_HDMI_CODEC
|
||||||
|
select SND_SOC_PCM1681 if I2C
|
||||||
|
select SND_SOC_PCM1792A if SPI_MASTER
|
||||||
select SND_SOC_PCM3008
|
select SND_SOC_PCM3008
|
||||||
select SND_SOC_RT5631 if I2C
|
select SND_SOC_RT5631 if I2C
|
||||||
select SND_SOC_RT5640 if I2C
|
select SND_SOC_RT5640 if I2C
|
||||||
|
@ -300,6 +302,12 @@ config SND_SOC_MAX9850
|
||||||
config SND_SOC_HDMI_CODEC
|
config SND_SOC_HDMI_CODEC
|
||||||
tristate
|
tristate
|
||||||
|
|
||||||
|
config SND_SOC_PCM1681
|
||||||
|
tristate
|
||||||
|
|
||||||
|
config SND_SOC_PCM1792A
|
||||||
|
tristate
|
||||||
|
|
||||||
config SND_SOC_PCM3008
|
config SND_SOC_PCM3008
|
||||||
tristate
|
tristate
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ snd-soc-max9850-objs := max9850.o
|
||||||
snd-soc-mc13783-objs := mc13783.o
|
snd-soc-mc13783-objs := mc13783.o
|
||||||
snd-soc-ml26124-objs := ml26124.o
|
snd-soc-ml26124-objs := ml26124.o
|
||||||
snd-soc-hdmi-codec-objs := hdmi.o
|
snd-soc-hdmi-codec-objs := hdmi.o
|
||||||
|
snd-soc-pcm1681-objs := pcm1681.o
|
||||||
|
snd-soc-pcm1792a-codec-objs := pcm1792a.o
|
||||||
snd-soc-pcm3008-objs := pcm3008.o
|
snd-soc-pcm3008-objs := pcm3008.o
|
||||||
snd-soc-rt5631-objs := rt5631.o
|
snd-soc-rt5631-objs := rt5631.o
|
||||||
snd-soc-rt5640-objs := rt5640.o
|
snd-soc-rt5640-objs := rt5640.o
|
||||||
|
@ -174,6 +176,8 @@ obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o
|
||||||
obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o
|
obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o
|
||||||
obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o
|
obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o
|
||||||
obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o
|
obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o
|
||||||
|
obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
|
||||||
|
obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
|
||||||
obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
|
obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
|
||||||
obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
|
obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
|
||||||
obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
|
obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
|
||||||
|
|
|
@ -0,0 +1,313 @@
|
||||||
|
/*
|
||||||
|
* PCM1681 ASoC codec driver
|
||||||
|
*
|
||||||
|
* Copyright (c) StreamUnlimited GmbH 2013
|
||||||
|
* Marek Belisko <marek.belisko@streamunlimited.com>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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/slab.h>
|
||||||
|
#include <linux/delay.h>
|
||||||
|
#include <linux/gpio.h>
|
||||||
|
#include <linux/i2c.h>
|
||||||
|
#include <linux/regmap.h>
|
||||||
|
#include <linux/of_device.h>
|
||||||
|
#include <linux/of_gpio.h>
|
||||||
|
#include <sound/pcm.h>
|
||||||
|
#include <sound/pcm_params.h>
|
||||||
|
#include <sound/soc.h>
|
||||||
|
#include <sound/tlv.h>
|
||||||
|
|
||||||
|
#define PCM1681_PCM_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
|
||||||
|
SNDRV_PCM_FMTBIT_S24_LE)
|
||||||
|
|
||||||
|
#define PCM1681_PCM_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | \
|
||||||
|
SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
|
||||||
|
SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | \
|
||||||
|
SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
|
||||||
|
|
||||||
|
#define PCM1681_SOFT_MUTE_ALL 0xff
|
||||||
|
#define PCM1681_DEEMPH_RATE_MASK 0x18
|
||||||
|
#define PCM1681_DEEMPH_MASK 0x01
|
||||||
|
|
||||||
|
#define PCM1681_ATT_CONTROL(X) (X <= 6 ? X : X + 9) /* Attenuation level */
|
||||||
|
#define PCM1681_SOFT_MUTE 0x07 /* Soft mute control register */
|
||||||
|
#define PCM1681_DAC_CONTROL 0x08 /* DAC operation control */
|
||||||
|
#define PCM1681_FMT_CONTROL 0x09 /* Audio interface data format */
|
||||||
|
#define PCM1681_DEEMPH_CONTROL 0x0a /* De-emphasis control */
|
||||||
|
#define PCM1681_ZERO_DETECT_STATUS 0x0e /* Zero detect status reg */
|
||||||
|
|
||||||
|
static const struct reg_default pcm1681_reg_defaults[] = {
|
||||||
|
{ 0x01, 0xff },
|
||||||
|
{ 0x02, 0xff },
|
||||||
|
{ 0x03, 0xff },
|
||||||
|
{ 0x04, 0xff },
|
||||||
|
{ 0x05, 0xff },
|
||||||
|
{ 0x06, 0xff },
|
||||||
|
{ 0x07, 0x00 },
|
||||||
|
{ 0x08, 0x00 },
|
||||||
|
{ 0x09, 0x06 },
|
||||||
|
{ 0x0A, 0x00 },
|
||||||
|
{ 0x0B, 0xff },
|
||||||
|
{ 0x0C, 0x0f },
|
||||||
|
{ 0x0D, 0x00 },
|
||||||
|
{ 0x10, 0xff },
|
||||||
|
{ 0x11, 0xff },
|
||||||
|
{ 0x12, 0x00 },
|
||||||
|
{ 0x13, 0x00 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool pcm1681_accessible_reg(struct device *dev, unsigned int reg)
|
||||||
|
{
|
||||||
|
return !((reg == 0x00) || (reg == 0x0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool pcm1681_writeable_reg(struct device *dev, unsigned register reg)
|
||||||
|
{
|
||||||
|
return pcm1681_accessible_reg(dev, reg) &&
|
||||||
|
(reg != PCM1681_ZERO_DETECT_STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pcm1681_private {
|
||||||
|
struct regmap *regmap;
|
||||||
|
unsigned int format;
|
||||||
|
/* Current deemphasis status */
|
||||||
|
unsigned int deemph;
|
||||||
|
/* Current rate for deemphasis control */
|
||||||
|
unsigned int rate;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int pcm1681_deemph[] = { 44100, 48000, 32000 };
|
||||||
|
|
||||||
|
static int pcm1681_set_deemph(struct snd_soc_codec *codec)
|
||||||
|
{
|
||||||
|
struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
int i = 0, val = -1, enable = 0;
|
||||||
|
|
||||||
|
if (priv->deemph)
|
||||||
|
for (i = 0; i < ARRAY_SIZE(pcm1681_deemph); i++)
|
||||||
|
if (pcm1681_deemph[i] == priv->rate)
|
||||||
|
val = i;
|
||||||
|
|
||||||
|
if (val != -1) {
|
||||||
|
regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL,
|
||||||
|
PCM1681_DEEMPH_RATE_MASK, val);
|
||||||
|
enable = 1;
|
||||||
|
} else
|
||||||
|
enable = 0;
|
||||||
|
|
||||||
|
/* enable/disable deemphasis functionality */
|
||||||
|
return regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL,
|
||||||
|
PCM1681_DEEMPH_MASK, enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1681_get_deemph(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
|
struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
|
||||||
|
ucontrol->value.enumerated.item[0] = priv->deemph;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1681_put_deemph(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
|
struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
|
||||||
|
priv->deemph = ucontrol->value.enumerated.item[0];
|
||||||
|
|
||||||
|
return pcm1681_set_deemph(codec);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1681_set_dai_fmt(struct snd_soc_dai *codec_dai,
|
||||||
|
unsigned int format)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = codec_dai->codec;
|
||||||
|
struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
|
||||||
|
/* The PCM1681 can only be slave to all clocks */
|
||||||
|
if ((format & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
|
||||||
|
dev_err(codec->dev, "Invalid clocking mode\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->format = format;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1681_digital_mute(struct snd_soc_dai *dai, int mute)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = dai->codec;
|
||||||
|
struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
int val;
|
||||||
|
|
||||||
|
if (mute)
|
||||||
|
val = PCM1681_SOFT_MUTE_ALL;
|
||||||
|
else
|
||||||
|
val = 0;
|
||||||
|
|
||||||
|
return regmap_write(priv->regmap, PCM1681_SOFT_MUTE, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1681_hw_params(struct snd_pcm_substream *substream,
|
||||||
|
struct snd_pcm_hw_params *params,
|
||||||
|
struct snd_soc_dai *dai)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = dai->codec;
|
||||||
|
struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
int val = 0, ret;
|
||||||
|
int pcm_format = params_format(params);
|
||||||
|
|
||||||
|
priv->rate = params_rate(params);
|
||||||
|
|
||||||
|
switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) {
|
||||||
|
case SND_SOC_DAIFMT_RIGHT_J:
|
||||||
|
if (pcm_format == SNDRV_PCM_FORMAT_S24_LE)
|
||||||
|
val = 0x00;
|
||||||
|
else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE)
|
||||||
|
val = 0x03;
|
||||||
|
break;
|
||||||
|
case SND_SOC_DAIFMT_I2S:
|
||||||
|
val = 0x04;
|
||||||
|
break;
|
||||||
|
case SND_SOC_DAIFMT_LEFT_J:
|
||||||
|
val = 0x05;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dev_err(codec->dev, "Invalid DAI format\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = regmap_update_bits(priv->regmap, PCM1681_FMT_CONTROL, 0x0f, val);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return pcm1681_set_deemph(codec);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct snd_soc_dai_ops pcm1681_dai_ops = {
|
||||||
|
.set_fmt = pcm1681_set_dai_fmt,
|
||||||
|
.hw_params = pcm1681_hw_params,
|
||||||
|
.digital_mute = pcm1681_digital_mute,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const DECLARE_TLV_DB_SCALE(pcm1681_dac_tlv, -6350, 50, 1);
|
||||||
|
|
||||||
|
static const struct snd_kcontrol_new pcm1681_controls[] = {
|
||||||
|
SOC_DOUBLE_R_TLV("Channel 1/2 Playback Volume",
|
||||||
|
PCM1681_ATT_CONTROL(1), PCM1681_ATT_CONTROL(2), 0,
|
||||||
|
0x7f, 0, pcm1681_dac_tlv),
|
||||||
|
SOC_DOUBLE_R_TLV("Channel 3/4 Playback Volume",
|
||||||
|
PCM1681_ATT_CONTROL(3), PCM1681_ATT_CONTROL(4), 0,
|
||||||
|
0x7f, 0, pcm1681_dac_tlv),
|
||||||
|
SOC_DOUBLE_R_TLV("Channel 5/6 Playback Volume",
|
||||||
|
PCM1681_ATT_CONTROL(5), PCM1681_ATT_CONTROL(6), 0,
|
||||||
|
0x7f, 0, pcm1681_dac_tlv),
|
||||||
|
SOC_DOUBLE_R_TLV("Channel 7/8 Playback Volume",
|
||||||
|
PCM1681_ATT_CONTROL(7), PCM1681_ATT_CONTROL(8), 0,
|
||||||
|
0x7f, 0, pcm1681_dac_tlv),
|
||||||
|
SOC_SINGLE_BOOL_EXT("De-emphasis Switch", 0,
|
||||||
|
pcm1681_get_deemph, pcm1681_put_deemph),
|
||||||
|
};
|
||||||
|
|
||||||
|
struct snd_soc_dai_driver pcm1681_dai = {
|
||||||
|
.name = "pcm1681-hifi",
|
||||||
|
.playback = {
|
||||||
|
.stream_name = "Playback",
|
||||||
|
.channels_min = 2,
|
||||||
|
.channels_max = 8,
|
||||||
|
.rates = PCM1681_PCM_RATES,
|
||||||
|
.formats = PCM1681_PCM_FORMATS,
|
||||||
|
},
|
||||||
|
.ops = &pcm1681_dai_ops,
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_OF
|
||||||
|
static const struct of_device_id pcm1681_dt_ids[] = {
|
||||||
|
{ .compatible = "ti,pcm1681", },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(of, pcm1681_dt_ids);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const struct regmap_config pcm1681_regmap = {
|
||||||
|
.reg_bits = 8,
|
||||||
|
.val_bits = 8,
|
||||||
|
.max_register = ARRAY_SIZE(pcm1681_reg_defaults) + 1,
|
||||||
|
.reg_defaults = pcm1681_reg_defaults,
|
||||||
|
.num_reg_defaults = ARRAY_SIZE(pcm1681_reg_defaults),
|
||||||
|
.writeable_reg = pcm1681_writeable_reg,
|
||||||
|
.readable_reg = pcm1681_accessible_reg,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct snd_soc_codec_driver soc_codec_dev_pcm1681 = {
|
||||||
|
.controls = pcm1681_controls,
|
||||||
|
.num_controls = ARRAY_SIZE(pcm1681_controls),
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct i2c_device_id pcm1681_i2c_id[] = {
|
||||||
|
{"pcm1681", 0},
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(i2c, pcm1681_i2c_id);
|
||||||
|
|
||||||
|
static int pcm1681_i2c_probe(struct i2c_client *client,
|
||||||
|
const struct i2c_device_id *id)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct pcm1681_private *priv;
|
||||||
|
|
||||||
|
priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
|
||||||
|
if (!priv)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
priv->regmap = devm_regmap_init_i2c(client, &pcm1681_regmap);
|
||||||
|
if (IS_ERR(priv->regmap)) {
|
||||||
|
ret = PTR_ERR(priv->regmap);
|
||||||
|
dev_err(&client->dev, "Failed to create regmap: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_set_clientdata(client, priv);
|
||||||
|
|
||||||
|
return snd_soc_register_codec(&client->dev, &soc_codec_dev_pcm1681,
|
||||||
|
&pcm1681_dai, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1681_i2c_remove(struct i2c_client *client)
|
||||||
|
{
|
||||||
|
snd_soc_unregister_codec(&client->dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct i2c_driver pcm1681_i2c_driver = {
|
||||||
|
.driver = {
|
||||||
|
.name = "pcm1681",
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
.of_match_table = of_match_ptr(pcm1681_dt_ids),
|
||||||
|
},
|
||||||
|
.id_table = pcm1681_i2c_id,
|
||||||
|
.probe = pcm1681_i2c_probe,
|
||||||
|
.remove = pcm1681_i2c_remove,
|
||||||
|
};
|
||||||
|
|
||||||
|
module_i2c_driver(pcm1681_i2c_driver);
|
||||||
|
|
||||||
|
MODULE_DESCRIPTION("Texas Instruments PCM1681 ALSA SoC Codec Driver");
|
||||||
|
MODULE_AUTHOR("Marek Belisko <marek.belisko@streamunlimited.com>");
|
||||||
|
MODULE_LICENSE("GPL");
|
|
@ -0,0 +1,245 @@
|
||||||
|
/*
|
||||||
|
* PCM1792A ASoC codec driver
|
||||||
|
*
|
||||||
|
* Copyright (c) Amarula Solutions B.V. 2013
|
||||||
|
*
|
||||||
|
* Michael Trimarchi <michael@amarulasolutions.com>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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/slab.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/device.h>
|
||||||
|
#include <linux/spi/spi.h>
|
||||||
|
|
||||||
|
#include <sound/core.h>
|
||||||
|
#include <sound/pcm.h>
|
||||||
|
#include <sound/pcm_params.h>
|
||||||
|
#include <sound/initval.h>
|
||||||
|
#include <sound/soc.h>
|
||||||
|
#include <sound/tlv.h>
|
||||||
|
#include <linux/of_device.h>
|
||||||
|
|
||||||
|
#include "pcm1792a.h"
|
||||||
|
|
||||||
|
#define PCM1792A_DAC_VOL_LEFT 0x10
|
||||||
|
#define PCM1792A_DAC_VOL_RIGHT 0x11
|
||||||
|
#define PCM1792A_FMT_CONTROL 0x12
|
||||||
|
#define PCM1792A_SOFT_MUTE PCM1792A_FMT_CONTROL
|
||||||
|
|
||||||
|
#define PCM1792A_FMT_MASK 0x70
|
||||||
|
#define PCM1792A_FMT_SHIFT 4
|
||||||
|
#define PCM1792A_MUTE_MASK 0x01
|
||||||
|
#define PCM1792A_MUTE_SHIFT 0
|
||||||
|
#define PCM1792A_ATLD_ENABLE (1 << 7)
|
||||||
|
|
||||||
|
static const struct reg_default pcm1792a_reg_defaults[] = {
|
||||||
|
{ 0x10, 0xff },
|
||||||
|
{ 0x11, 0xff },
|
||||||
|
{ 0x12, 0x50 },
|
||||||
|
{ 0x13, 0x00 },
|
||||||
|
{ 0x14, 0x00 },
|
||||||
|
{ 0x15, 0x01 },
|
||||||
|
{ 0x16, 0x00 },
|
||||||
|
{ 0x17, 0x00 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool pcm1792a_accessible_reg(struct device *dev, unsigned int reg)
|
||||||
|
{
|
||||||
|
return reg >= 0x10 && reg <= 0x17;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool pcm1792a_writeable_reg(struct device *dev, unsigned register reg)
|
||||||
|
{
|
||||||
|
bool accessible;
|
||||||
|
|
||||||
|
accessible = pcm1792a_accessible_reg(dev, reg);
|
||||||
|
|
||||||
|
return accessible && reg != 0x16 && reg != 0x17;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pcm1792a_private {
|
||||||
|
struct regmap *regmap;
|
||||||
|
unsigned int format;
|
||||||
|
unsigned int rate;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int pcm1792a_set_dai_fmt(struct snd_soc_dai *codec_dai,
|
||||||
|
unsigned int format)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = codec_dai->codec;
|
||||||
|
struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
|
||||||
|
priv->format = format;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1792a_digital_mute(struct snd_soc_dai *dai, int mute)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = dai->codec;
|
||||||
|
struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = regmap_update_bits(priv->regmap, PCM1792A_SOFT_MUTE,
|
||||||
|
PCM1792A_MUTE_MASK, !!mute);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1792a_hw_params(struct snd_pcm_substream *substream,
|
||||||
|
struct snd_pcm_hw_params *params,
|
||||||
|
struct snd_soc_dai *dai)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = dai->codec;
|
||||||
|
struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec);
|
||||||
|
int val = 0, ret;
|
||||||
|
int pcm_format = params_format(params);
|
||||||
|
|
||||||
|
priv->rate = params_rate(params);
|
||||||
|
|
||||||
|
switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) {
|
||||||
|
case SND_SOC_DAIFMT_RIGHT_J:
|
||||||
|
if (pcm_format == SNDRV_PCM_FORMAT_S24_LE ||
|
||||||
|
pcm_format == SNDRV_PCM_FORMAT_S32_LE)
|
||||||
|
val = 0x02;
|
||||||
|
else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE)
|
||||||
|
val = 0x00;
|
||||||
|
break;
|
||||||
|
case SND_SOC_DAIFMT_I2S:
|
||||||
|
if (pcm_format == SNDRV_PCM_FORMAT_S24_LE ||
|
||||||
|
pcm_format == SNDRV_PCM_FORMAT_S32_LE)
|
||||||
|
val = 0x05;
|
||||||
|
else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE)
|
||||||
|
val = 0x04;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dev_err(codec->dev, "Invalid DAI format\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = val << PCM1792A_FMT_SHIFT | PCM1792A_ATLD_ENABLE;
|
||||||
|
|
||||||
|
ret = regmap_update_bits(priv->regmap, PCM1792A_FMT_CONTROL,
|
||||||
|
PCM1792A_FMT_MASK | PCM1792A_ATLD_ENABLE, val);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct snd_soc_dai_ops pcm1792a_dai_ops = {
|
||||||
|
.set_fmt = pcm1792a_set_dai_fmt,
|
||||||
|
.hw_params = pcm1792a_hw_params,
|
||||||
|
.digital_mute = pcm1792a_digital_mute,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const DECLARE_TLV_DB_SCALE(pcm1792a_dac_tlv, -12000, 50, 1);
|
||||||
|
|
||||||
|
static const struct snd_kcontrol_new pcm1792a_controls[] = {
|
||||||
|
SOC_DOUBLE_R_RANGE_TLV("DAC Playback Volume", PCM1792A_DAC_VOL_LEFT,
|
||||||
|
PCM1792A_DAC_VOL_RIGHT, 0, 0xf, 0xff, 0,
|
||||||
|
pcm1792a_dac_tlv),
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct snd_soc_dai_driver pcm1792a_dai = {
|
||||||
|
.name = "pcm1792a-hifi",
|
||||||
|
.playback = {
|
||||||
|
.stream_name = "Playback",
|
||||||
|
.channels_min = 2,
|
||||||
|
.channels_max = 2,
|
||||||
|
.rates = PCM1792A_RATES,
|
||||||
|
.formats = PCM1792A_FORMATS, },
|
||||||
|
.capture = {
|
||||||
|
.channels_min = 0,
|
||||||
|
.channels_max = 0,
|
||||||
|
},
|
||||||
|
.ops = &pcm1792a_dai_ops,
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_OF
|
||||||
|
static const struct of_device_id pcm1792a_of_match[] = {
|
||||||
|
{ .compatible = "ti,pcm1792a", },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(of, pcm1792a_of_match);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const struct regmap_config pcm1792a_regmap = {
|
||||||
|
.reg_bits = 8,
|
||||||
|
.val_bits = 8,
|
||||||
|
.max_register = 24,
|
||||||
|
.reg_defaults = pcm1792a_reg_defaults,
|
||||||
|
.num_reg_defaults = ARRAY_SIZE(pcm1792a_reg_defaults),
|
||||||
|
.writeable_reg = pcm1792a_writeable_reg,
|
||||||
|
.readable_reg = pcm1792a_accessible_reg,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct snd_soc_codec_driver soc_codec_dev_pcm1792a = {
|
||||||
|
.controls = pcm1792a_controls,
|
||||||
|
.num_controls = ARRAY_SIZE(pcm1792a_controls),
|
||||||
|
};
|
||||||
|
|
||||||
|
static int pcm1792a_spi_probe(struct spi_device *spi)
|
||||||
|
{
|
||||||
|
struct pcm1792a_private *pcm1792a;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
pcm1792a = devm_kzalloc(&spi->dev, sizeof(struct pcm1792a_private),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!pcm1792a)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
spi_set_drvdata(spi, pcm1792a);
|
||||||
|
|
||||||
|
pcm1792a->regmap = devm_regmap_init_spi(spi, &pcm1792a_regmap);
|
||||||
|
if (IS_ERR(pcm1792a->regmap)) {
|
||||||
|
ret = PTR_ERR(pcm1792a->regmap);
|
||||||
|
dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return snd_soc_register_codec(&spi->dev,
|
||||||
|
&soc_codec_dev_pcm1792a, &pcm1792a_dai, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pcm1792a_spi_remove(struct spi_device *spi)
|
||||||
|
{
|
||||||
|
snd_soc_unregister_codec(&spi->dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct spi_device_id pcm1792a_spi_ids[] = {
|
||||||
|
{ "pcm1792a", 0 },
|
||||||
|
{ },
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(spi, pcm1792a_spi_ids);
|
||||||
|
|
||||||
|
static struct spi_driver pcm1792a_codec_driver = {
|
||||||
|
.driver = {
|
||||||
|
.name = "pcm1792a",
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
.of_match_table = pcm1792a_of_match,
|
||||||
|
},
|
||||||
|
.id_table = pcm1792a_spi_ids,
|
||||||
|
.probe = pcm1792a_spi_probe,
|
||||||
|
.remove = pcm1792a_spi_remove,
|
||||||
|
};
|
||||||
|
|
||||||
|
module_spi_driver(pcm1792a_codec_driver);
|
||||||
|
|
||||||
|
MODULE_DESCRIPTION("ASoC PCM1792A driver");
|
||||||
|
MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
|
||||||
|
MODULE_LICENSE("GPL");
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* definitions for PCM1792A
|
||||||
|
*
|
||||||
|
* Copyright 2013 Amarula Solutions
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PCM1792A_H__
|
||||||
|
#define __PCM1792A_H__
|
||||||
|
|
||||||
|
#define PCM1792A_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_8000_48000 | \
|
||||||
|
SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
|
||||||
|
|
||||||
|
#define PCM1792A_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE | \
|
||||||
|
SNDRV_PCM_FMTBIT_S16_LE)
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue