Commit 8d8084d8 authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branches 'asoc/topic/isabelle', 'asoc/topic/jz4740',...

Merge remote-tracking branches 'asoc/topic/isabelle', 'asoc/topic/jz4740', 'asoc/topic/lm49453', 'asoc/topic/max9759' and 'asoc/topic/max98088' into asoc-next
Maxim MAX9759 Speaker Amplifier
===============================
Required properties:
- compatible : "maxim,max9759"
- shutdown-gpios : the gpio connected to the shutdown pin
- mute-gpios : the gpio connected to the mute pin
- gain-gpios : the 2 gpios connected to the g1 and g2 pins
Example:
max9759: analog-amplifier {
compatible = "maxim,max9759";
shutdown-gpios = <&gpio3 20 GPIO_ACTIVE_LOW>;
mute-gpios = <&gpio3 19 GPIO_ACTIVE_LOW>;
gain-gpios = <&gpio3 23 GPIO_ACTIVE_LOW>,
<&gpio3 25 GPIO_ACTIVE_LOW>;
};
......@@ -101,6 +101,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_MAX98373 if I2C
select SND_SOC_MAX9850 if I2C
select SND_SOC_MAX9860 if I2C
select SND_SOC_MAX9759
select SND_SOC_MAX9768 if I2C
select SND_SOC_MAX9877 if I2C
select SND_SOC_MC13783 if MFD_MC13XXX
......@@ -1223,6 +1224,10 @@ config SND_SOC_ZX_AUD96P22
config SND_SOC_LM4857
tristate
config SND_SOC_MAX9759
tristate "Maxim MAX9759 speaker Amplifier"
select GPIOLIB
config SND_SOC_MAX9768
tristate
......
......@@ -84,6 +84,7 @@ snd-soc-jz4740-codec-objs := jz4740.o
snd-soc-l3-objs := l3.o
snd-soc-lm4857-objs := lm4857.o
snd-soc-lm49453-objs := lm49453.o
snd-soc-max9759-objs := max9759.o
snd-soc-max9768-objs := max9768.o
snd-soc-max98088-objs := max98088.o
snd-soc-max98090-objs := max98090.o
......@@ -335,6 +336,7 @@ obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
obj-$(CONFIG_SND_SOC_LM4857) += snd-soc-lm4857.o
obj-$(CONFIG_SND_SOC_LM49453) += snd-soc-lm49453.o
obj-$(CONFIG_SND_SOC_MAX9759) += snd-soc-max9759.o
obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o
obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o
obj-$(CONFIG_SND_SOC_MAX98090) += snd-soc-max98090.o
......
......@@ -867,7 +867,7 @@ static const struct snd_soc_dapm_route isabelle_intercon[] = {
static int isabelle_hs_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, ISABELLE_DAC1_SOFTRAMP_REG,
snd_soc_component_update_bits(dai->component, ISABELLE_DAC1_SOFTRAMP_REG,
BIT(4), (mute ? BIT(4) : 0));
return 0;
......@@ -875,7 +875,7 @@ static int isabelle_hs_mute(struct snd_soc_dai *dai, int mute)
static int isabelle_hf_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, ISABELLE_DAC2_SOFTRAMP_REG,
snd_soc_component_update_bits(dai->component, ISABELLE_DAC2_SOFTRAMP_REG,
BIT(4), (mute ? BIT(4) : 0));
return 0;
......@@ -883,13 +883,13 @@ static int isabelle_hf_mute(struct snd_soc_dai *dai, int mute)
static int isabelle_line_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, ISABELLE_DAC3_SOFTRAMP_REG,
snd_soc_component_update_bits(dai->component, ISABELLE_DAC3_SOFTRAMP_REG,
BIT(4), (mute ? BIT(4) : 0));
return 0;
}
static int isabelle_set_bias_level(struct snd_soc_codec *codec,
static int isabelle_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level)
{
switch (level) {
......@@ -899,12 +899,12 @@ static int isabelle_set_bias_level(struct snd_soc_codec *codec,
break;
case SND_SOC_BIAS_STANDBY:
snd_soc_update_bits(codec, ISABELLE_PWR_EN_REG,
snd_soc_component_update_bits(component, ISABELLE_PWR_EN_REG,
ISABELLE_CHIP_EN, BIT(0));
break;
case SND_SOC_BIAS_OFF:
snd_soc_update_bits(codec, ISABELLE_PWR_EN_REG,
snd_soc_component_update_bits(component, ISABELLE_PWR_EN_REG,
ISABELLE_CHIP_EN, 0);
break;
}
......@@ -916,7 +916,7 @@ static int isabelle_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 snd_soc_component *component = dai->component;
u16 aif = 0;
unsigned int fs_val = 0;
......@@ -952,7 +952,7 @@ static int isabelle_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
snd_soc_update_bits(codec, ISABELLE_FS_RATE_CFG_REG,
snd_soc_component_update_bits(component, ISABELLE_FS_RATE_CFG_REG,
ISABELLE_FS_RATE_MASK, fs_val);
/* bit size */
......@@ -967,7 +967,7 @@ static int isabelle_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
snd_soc_update_bits(codec, ISABELLE_INTF_CFG_REG,
snd_soc_component_update_bits(component, ISABELLE_INTF_CFG_REG,
ISABELLE_AIF_LENGTH_MASK, aif);
return 0;
......@@ -975,7 +975,7 @@ static int isabelle_hw_params(struct snd_pcm_substream *substream,
static int isabelle_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct snd_soc_component *component = codec_dai->component;
unsigned int aif_val = 0;
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
......@@ -1003,7 +1003,7 @@ static int isabelle_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
return -EINVAL;
}
snd_soc_update_bits(codec, ISABELLE_INTF_CFG_REG,
snd_soc_component_update_bits(component, ISABELLE_INTF_CFG_REG,
(ISABELLE_AIF_MS | ISABELLE_AIF_FMT_MASK), aif_val);
return 0;
......@@ -1087,17 +1087,17 @@ static struct snd_soc_dai_driver isabelle_dai[] = {
},
};
static const struct snd_soc_codec_driver soc_codec_dev_isabelle = {
.set_bias_level = isabelle_set_bias_level,
.component_driver = {
.controls = isabelle_snd_controls,
.num_controls = ARRAY_SIZE(isabelle_snd_controls),
.dapm_widgets = isabelle_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(isabelle_dapm_widgets),
.dapm_routes = isabelle_intercon,
.num_dapm_routes = ARRAY_SIZE(isabelle_intercon),
},
.idle_bias_off = true,
static const struct snd_soc_component_driver soc_component_dev_isabelle = {
.set_bias_level = isabelle_set_bias_level,
.controls = isabelle_snd_controls,
.num_controls = ARRAY_SIZE(isabelle_snd_controls),
.dapm_widgets = isabelle_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(isabelle_dapm_widgets),
.dapm_routes = isabelle_intercon,
.num_dapm_routes = ARRAY_SIZE(isabelle_intercon),
.use_pmdown_time = 1,
.endianness = 1,
.non_legacy_dai_naming = 1,
};
static const struct regmap_config isabelle_regmap_config = {
......@@ -1125,23 +1125,17 @@ static int isabelle_i2c_probe(struct i2c_client *i2c,
}
i2c_set_clientdata(i2c, isabelle_regmap);
ret = snd_soc_register_codec(&i2c->dev,
&soc_codec_dev_isabelle, isabelle_dai,
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_isabelle, isabelle_dai,
ARRAY_SIZE(isabelle_dai));
if (ret < 0) {
dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
dev_err(&i2c->dev, "Failed to register component: %d\n", ret);
return ret;
}
return ret;
}
static int isabelle_i2c_remove(struct i2c_client *client)
{
snd_soc_unregister_codec(&client->dev);
return 0;
}
static const struct i2c_device_id isabelle_i2c_id[] = {
{ "isabelle", 0 },
{ }
......@@ -1153,7 +1147,6 @@ static struct i2c_driver isabelle_i2c_driver = {
.name = "isabelle",
},
.probe = isabelle_i2c_probe,
.remove = isabelle_i2c_remove,
.id_table = isabelle_i2c_id,
};
......
......@@ -157,7 +157,7 @@ static const struct snd_soc_dapm_route jz4740_codec_dapm_routes[] = {
static int jz4740_codec_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{
struct jz4740_codec *jz4740_codec = snd_soc_codec_get_drvdata(dai->codec);
struct jz4740_codec *jz4740_codec = snd_soc_component_get_drvdata(dai->component);
uint32_t val;
switch (params_rate(params)) {
......@@ -236,10 +236,10 @@ static void jz4740_codec_wakeup(struct regmap *regmap)
regcache_sync(regmap);
}
static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec,
static int jz4740_codec_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level)
{
struct jz4740_codec *jz4740_codec = snd_soc_codec_get_drvdata(codec);
struct jz4740_codec *jz4740_codec = snd_soc_component_get_drvdata(component);
struct regmap *regmap = jz4740_codec->regmap;
unsigned int mask;
unsigned int value;
......@@ -257,7 +257,7 @@ static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec,
break;
case SND_SOC_BIAS_STANDBY:
/* The only way to clear the suspend flag is to reset the codec */
if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF)
jz4740_codec_wakeup(regmap);
mask = JZ4740_CODEC_1_VREF_DISABLE |
......@@ -283,9 +283,9 @@ static int jz4740_codec_set_bias_level(struct snd_soc_codec *codec,
return 0;
}
static int jz4740_codec_dev_probe(struct snd_soc_codec *codec)
static int jz4740_codec_dev_probe(struct snd_soc_component *component)
{
struct jz4740_codec *jz4740_codec = snd_soc_codec_get_drvdata(codec);
struct jz4740_codec *jz4740_codec = snd_soc_component_get_drvdata(component);
regmap_update_bits(jz4740_codec->regmap, JZ4740_REG_CODEC_1,
JZ4740_CODEC_1_SW2_ENABLE, JZ4740_CODEC_1_SW2_ENABLE);
......@@ -293,19 +293,21 @@ static int jz4740_codec_dev_probe(struct snd_soc_codec *codec)
return 0;
}
static const struct snd_soc_codec_driver soc_codec_dev_jz4740_codec = {
.probe = jz4740_codec_dev_probe,
.set_bias_level = jz4740_codec_set_bias_level,
.suspend_bias_off = true,
.component_driver = {
.controls = jz4740_codec_controls,
.num_controls = ARRAY_SIZE(jz4740_codec_controls),
.dapm_widgets = jz4740_codec_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(jz4740_codec_dapm_widgets),
.dapm_routes = jz4740_codec_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(jz4740_codec_dapm_routes),
},
static const struct snd_soc_component_driver soc_codec_dev_jz4740_codec = {
.probe = jz4740_codec_dev_probe,
.set_bias_level = jz4740_codec_set_bias_level,
.controls = jz4740_codec_controls,
.num_controls = ARRAY_SIZE(jz4740_codec_controls),
.dapm_widgets = jz4740_codec_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(jz4740_codec_dapm_widgets),
.dapm_routes = jz4740_codec_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(jz4740_codec_dapm_routes),
.suspend_bias_off = 1,
.idle_bias_on = 1,
.use_pmdown_time = 1,
.endianness = 1,
.non_legacy_dai_naming = 1,
};
static const struct regmap_config jz4740_codec_regmap_config = {
......@@ -343,7 +345,7 @@ static int jz4740_codec_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, jz4740_codec);
ret = snd_soc_register_codec(&pdev->dev,
ret = devm_snd_soc_register_component(&pdev->dev,
&soc_codec_dev_jz4740_codec, &jz4740_codec_dai, 1);
if (ret)
dev_err(&pdev->dev, "Failed to register codec\n");
......@@ -351,16 +353,8 @@ static int jz4740_codec_probe(struct platform_device *pdev)
return ret;
}
static int jz4740_codec_remove(struct platform_device *pdev)
{
snd_soc_unregister_codec(&pdev->dev);
return 0;
}
static struct platform_driver jz4740_codec_driver = {
.probe = jz4740_codec_probe,
.remove = jz4740_codec_remove,
.driver = {
.name = "jz4740-codec",
},
......
......@@ -1110,7 +1110,7 @@ static int lm49453_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 snd_soc_component *component = dai->component;
u16 clk_div = 0;
/* Setting DAC clock dividers based on substream sample rate. */
......@@ -1134,15 +1134,15 @@ static int lm49453_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
snd_soc_write(codec, LM49453_P0_ADC_CLK_DIV_REG, clk_div);
snd_soc_write(codec, LM49453_P0_DAC_HP_CLK_DIV_REG, clk_div);
snd_soc_component_write(component, LM49453_P0_ADC_CLK_DIV_REG, clk_div);
snd_soc_component_write(component, LM49453_P0_DAC_HP_CLK_DIV_REG, clk_div);
return 0;
}
static int lm49453_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
{
struct snd_soc_codec *codec = codec_dai->codec;
struct snd_soc_component *component = codec_dai->component;
u16 aif_val;
int mode = 0;
......@@ -1185,11 +1185,11 @@ static int lm49453_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
return -EINVAL;
}
snd_soc_update_bits(codec, LM49453_P0_AUDIO_PORT1_BASIC_REG,
snd_soc_component_update_bits(component, LM49453_P0_AUDIO_PORT1_BASIC_REG,
LM49453_AUDIO_PORT1_BASIC_FMT_MASK|BIT(0)|BIT(5),
(aif_val | mode | clk_phase));
snd_soc_write(codec, LM49453_P0_AUDIO_PORT1_RX_MSB_REG, clk_shift);
snd_soc_component_write(component, LM49453_P0_AUDIO_PORT1_RX_MSB_REG, clk_shift);
return 0;
}
......@@ -1197,7 +1197,7 @@ static int lm49453_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
static int lm49453_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
unsigned int freq, int dir)
{
struct snd_soc_codec *codec = dai->codec;
struct snd_soc_component *component = dai->component;
u16 pll_clk = 0;
switch (freq) {
......@@ -1216,50 +1216,50 @@ static int lm49453_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
return -EINVAL;
}
snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG, BIT(4), pll_clk);
snd_soc_component_update_bits(component, LM49453_P0_PMC_SETUP_REG, BIT(4), pll_clk);
return 0;
}
static int lm49453_hp_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(1)|BIT(0),
snd_soc_component_update_bits(dai->component, LM49453_P0_DAC_DSP_REG, BIT(1)|BIT(0),
(mute ? (BIT(1)|BIT(0)) : 0));
return 0;
}
static int lm49453_lo_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(3)|BIT(2),
snd_soc_component_update_bits(dai->component, LM49453_P0_DAC_DSP_REG, BIT(3)|BIT(2),
(mute ? (BIT(3)|BIT(2)) : 0));
return 0;
}
static int lm49453_ls_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(5)|BIT(4),
snd_soc_component_update_bits(dai->component, LM49453_P0_DAC_DSP_REG, BIT(5)|BIT(4),
(mute ? (BIT(5)|BIT(4)) : 0));
return 0;
}
static int lm49453_ep_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(4),
snd_soc_component_update_bits(dai->component, LM49453_P0_DAC_DSP_REG, BIT(4),
(mute ? BIT(4) : 0));
return 0;
}
static int lm49453_ha_mute(struct snd_soc_dai *dai, int mute)
{
snd_soc_update_bits(dai->codec, LM49453_P0_DAC_DSP_REG, BIT(7)|BIT(6),
snd_soc_component_update_bits(dai->component, LM49453_P0_DAC_DSP_REG, BIT(7)|BIT(6),
(mute ? (BIT(7)|BIT(6)) : 0));
return 0;
}
static int lm49453_set_bias_level(struct snd_soc_codec *codec,
static int lm49453_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level)
{
struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec);
struct lm49453_priv *lm49453 = snd_soc_component_get_drvdata(component);
switch (level) {
case SND_SOC_BIAS_ON:
......@@ -1267,15 +1267,15 @@ static int lm49453_set_bias_level(struct snd_soc_codec *codec,
break;
case SND_SOC_BIAS_STANDBY:
if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF)
if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF)
regcache_sync(lm49453->regmap);
snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG,
snd_soc_component_update_bits(component, LM49453_P0_PMC_SETUP_REG,
LM49453_PMC_SETUP_CHIP_EN, LM49453_CHIP_EN);
break;
case SND_SOC_BIAS_OFF:
snd_soc_update_bits(codec, LM49453_P0_PMC_SETUP_REG,
snd_soc_component_update_bits(component, LM49453_P0_PMC_SETUP_REG,
LM49453_PMC_SETUP_CHIP_EN, 0);
break;
}
......@@ -1389,17 +1389,17 @@ static struct snd_soc_dai_driver lm49453_dai[] = {
},
};
static const struct snd_soc_codec_driver soc_codec_dev_lm49453 = {
.set_bias_level = lm49453_set_bias_level,
.component_driver = {
.controls = lm49453_snd_controls,
.num_controls = ARRAY_SIZE(lm49453_snd_controls),
.dapm_widgets = lm49453_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(lm49453_dapm_widgets),
.dapm_routes = lm49453_audio_map,
.num_dapm_routes = ARRAY_SIZE(lm49453_audio_map),
},
.idle_bias_off = true,
static const struct snd_soc_component_driver soc_component_dev_lm49453 = {
.set_bias_level = lm49453_set_bias_level,
.controls = lm49453_snd_controls,
.num_controls = ARRAY_SIZE(lm49453_snd_controls),
.dapm_widgets = lm49453_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(lm49453_dapm_widgets),
.dapm_routes = lm49453_audio_map,
.num_dapm_routes = ARRAY_SIZE(lm49453_audio_map),
.use_pmdown_time = 1,
.endianness = 1,
.non_legacy_dai_naming = 1,
};
static const struct regmap_config lm49453_regmap_config = {
......@@ -1434,18 +1434,17 @@ static int lm49453_i2c_probe(struct i2c_client *i2c,
return ret;
}
ret = snd_soc_register_codec(&i2c->dev,
&soc_codec_dev_lm49453,
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_lm49453,
lm49453_dai, ARRAY_SIZE(lm49453_dai));
if (ret < 0)
dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
dev_err(&i2c->dev, "Failed to register component: %d\n", ret);
return ret;
}
static int lm49453_i2c_remove(struct i2c_client *client)
{
snd_soc_unregister_codec(&client->dev);
return 0;
}
......
// SPDX-Licence-Identifier: GPL-2.0
/*
* MAX9759 Amplifier Driver
*
* Copyright (c) 2017 BayLibre, SAS.
* Author: Neil Armstrong <narmstrong@baylibre.com>
*/
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <sound/tlv.h>
#define DRV_NAME "max9759"
struct max9759 {
struct gpio_desc *gpiod_shutdown;
struct gpio_desc *gpiod_mute;
struct gpio_descs *gpiod_gain;
bool is_mute;
unsigned int gain;
};
static int pga_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *control, int event)
{
struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
struct max9759 *priv = snd_soc_component_get_drvdata(c);
if (SND_SOC_DAPM_EVENT_ON(event))
gpiod_set_value_cansleep(priv->gpiod_shutdown, 0);
else
gpiod_set_value_cansleep(priv->gpiod_shutdown, 1);
return 0;
}
/* From 6dB to 24dB in steps of 6dB */
static const DECLARE_TLV_DB_SCALE(speaker_gain_tlv, 600, 600, 0);
static int speaker_gain_control_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
struct max9759 *priv = snd_soc_component_get_drvdata(c);
ucontrol->value.integer.value[0] = priv->gain;
return 0;
}
static const bool speaker_gain_table[4][2] = {
/* G1, G2 */
{true, true}, /* +6dB */
{false, true}, /* +12dB */
{true, false}, /* +18dB */
{false, false}, /* +24dB */
};
static int speaker_gain_control_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
struct max9759 *priv = snd_soc_component_get_drvdata(c);
if (ucontrol->value.integer.value[0] > 3)
return -EINVAL;
priv->gain = ucontrol->value.integer.value[0];
/* G1 */
gpiod_set_value_cansleep(priv->gpiod_gain->desc[0],
speaker_gain_table[priv->gain][0]);
/* G2 */
gpiod_set_value_cansleep(priv->gpiod_gain->desc[1],
speaker_gain_table[priv->gain][1]);
return 1;
}
static int speaker_mute_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
struct max9759 *priv = snd_soc_component_get_drvdata(c);
ucontrol->value.integer.value[0] = !priv->is_mute;
return 0;
}
static int speaker_mute_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
struct max9759 *priv = snd_soc_component_get_drvdata(c);
priv->is_mute = !ucontrol->value.integer.value[0];
gpiod_set_value_cansleep(priv->gpiod_mute, priv->is_mute);
return 1;
}
static const struct snd_kcontrol_new max9759_dapm_controls[] = {
SOC_SINGLE_EXT_TLV("Speaker Gain Volume", 0, 0, 3, 0,
speaker_gain_control_get, speaker_gain_control_put,
speaker_gain_tlv),
SOC_SINGLE_BOOL_EXT("Playback Switch", 0,
speaker_mute_get, speaker_mute_put),
};
static const struct snd_soc_dapm_widget max9759_dapm_widgets[] = {
SND_SOC_DAPM_INPUT("INL"),
SND_SOC_DAPM_INPUT("INR"),
SND_SOC_DAPM_PGA_E("PGA", SND_SOC_NOPM, 0, 0, NULL, 0, pga_event,
(SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)),
SND_SOC_DAPM_OUTPUT("OUTL"),
SND_SOC_DAPM_OUTPUT("OUTR"),
};
static const struct snd_soc_dapm_route max9759_dapm_routes[] = {
{ "PGA", NULL, "INL" },
{ "PGA", NULL, "INR" },
{ "OUTL", NULL, "PGA" },
{ "OUTR", NULL, "PGA" },
};
static const struct snd_soc_component_driver max9759_component_driver = {
.controls = max9759_dapm_controls,
.num_controls = ARRAY_SIZE(max9759_dapm_controls),
.dapm_widgets = max9759_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(max9759_dapm_widgets),
.dapm_routes = max9759_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(max9759_dapm_routes),
};
static int max9759_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct max9759 *priv;
int err;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
platform_set_drvdata(pdev, priv);
priv->gpiod_shutdown = devm_gpiod_get(dev, "shutdown", GPIOD_OUT_HIGH);
if (IS_ERR(priv->gpiod_shutdown)) {
err = PTR_ERR(priv->gpiod_shutdown);
if (err != -EPROBE_DEFER)
dev_err(dev, "Failed to get 'shutdown' gpio: %d", err);
return err;
}
priv->gpiod_mute = devm_gpiod_get(dev, "mute", GPIOD_OUT_HIGH);
if (IS_ERR(priv->gpiod_mute)) {
err = PTR_ERR(priv->gpiod_mute);
if (err != -EPROBE_DEFER)
dev_err(dev, "Failed to get 'mute' gpio: %d", err);
return err;
}
priv->is_mute = true;
priv->gpiod_gain = devm_gpiod_get_array(dev, "gain", GPIOD_OUT_HIGH);
if (IS_ERR(priv->gpiod_gain)) {
err = PTR_ERR(priv->gpiod_gain);
if (err != -EPROBE_DEFER)
dev_err(dev, "Failed to get 'gain' gpios: %d", err);
return err;
}
priv->gain = 0;
if (priv->gpiod_gain->ndescs != 2) {
dev_err(dev, "Invalid 'gain' gpios count: %d",
priv->gpiod_gain->ndescs);
return -EINVAL;
}
return devm_snd_soc_register_component(dev, &max9759_component_driver,
NULL, 0);
}
#ifdef CONFIG_OF
static const struct of_device_id max9759_ids[] = {
{ .compatible = "maxim,max9759", },
{ }
};
MODULE_DEVICE_TABLE(of, max9759_ids);
#endif
static struct platform_driver max9759_driver = {
.driver = {
.name = DRV_NAME,
.of_match_table = of_match_ptr(max9759_ids),
},
.probe = max9759_probe,
};
module_platform_driver(max9759_driver);
MODULE_DESCRIPTION("ASoC MAX9759 amplifier driver");
MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
MODULE_LICENSE("GPL");
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment