ASoC: es8323: remove HP/Headset detect and HP/SPK controls

and to do these in machine driver

Signed-off-by: XiaoTan Luo <lxt@rock-chips.com>
Change-Id: Ic95b7329700d65164651b519c9f9bfac81f3e800
This commit is contained in:
XiaoTan Luo
2021-12-09 10:22:29 +08:00
committed by Tao Huang
parent 5ac62b80f7
commit 191b628750

View File

@@ -17,7 +17,6 @@
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/of_gpio.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -26,15 +25,8 @@
#include <sound/soc-dapm.h>
#include <sound/initval.h>
#include <linux/proc_fs.h>
#include <linux/extcon.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include "es8323.h"
#define ES8323_CODEC_SET_SPK 1
#define ES8323_CODEC_SET_HP 2
#define ES8323_EXTCON_ID EXTCON_JACK_HEADPHONE
#define NR_SUPPORTED_MCLK_LRCK_RATIOS 5
static const unsigned int supported_mclk_lrck_ratios[NR_SUPPORTED_MCLK_LRCK_RATIOS] = {
256, 384, 512, 768, 1024
@@ -101,57 +93,8 @@ struct es8323_priv {
struct snd_pcm_hw_constraint_list sysclk_constraints;
struct snd_soc_component *component;
struct regmap *regmap;
struct gpio_desc *hp_ctl_gpio;
struct gpio_desc *spk_ctl_gpio;
struct gpio_desc *hp_det_gpio;
bool hp_inserted;
struct notifier_block extcon_nb;
bool muted;
};
static int es8323_set_gpio(struct es8323_priv *es8323, int gpio, bool level)
{
if ((gpio & ES8323_CODEC_SET_SPK) && es8323->spk_ctl_gpio)
gpiod_set_value(es8323->spk_ctl_gpio, level);
if ((gpio & ES8323_CODEC_SET_HP) && es8323->hp_ctl_gpio)
gpiod_set_value(es8323->hp_ctl_gpio, level);
return 0;
}
static int es8323_extcon_notifier(struct notifier_block *self, unsigned long event, void *ptr)
{
struct es8323_priv *es8323 = container_of(self, struct es8323_priv,
extcon_nb);
/* Note: Don't enable speaker or headset here
* If headset removed or insert, The system will close sound card
* And Then reopening, those enable steps will be done in es8323_mute
*/
if (event)
es8323->hp_inserted = true;
else
es8323->hp_inserted = false;
return NOTIFY_DONE;
}
static irqreturn_t hp_det_irq_handler(int irq, void *dev_id)
{
struct es8323_priv *es8323 = dev_id;
if (es8323->muted == 0) {
if (gpiod_get_value(es8323->hp_det_gpio)) {
es8323_set_gpio(es8323, ES8323_CODEC_SET_SPK, 0);
es8323_set_gpio(es8323, ES8323_CODEC_SET_HP, 1);
} else {
es8323_set_gpio(es8323, ES8323_CODEC_SET_SPK, 1);
es8323_set_gpio(es8323, ES8323_CODEC_SET_HP, 0);
}
}
return IRQ_HANDLED;
}
static int es8323_reset(struct snd_soc_component *component)
{
snd_soc_component_write(component, ES8323_CONTROL1, 0x80);
@@ -288,12 +231,6 @@ static const struct snd_kcontrol_new es8323_right_mixer_controls[] = {
SOC_DAPM_SINGLE("Right Bypass Switch", ES8323_DACCONTROL20, 6, 1, 0),
};
/* Differential Mux */
//static const struct snd_kcontrol_new es8323_diffmux_controls =
//SOC_DAPM_ENUM("Route", es8323_enum[10]);
static const struct snd_soc_dapm_widget es8323_dapm_widgets[] = {
SND_SOC_DAPM_INPUT("LINPUT1"),
SND_SOC_DAPM_INPUT("LINPUT2"),
@@ -679,26 +616,6 @@ static int es8323_pcm_hw_params(struct snd_pcm_substream *substream,
static int es8323_mute(struct snd_soc_dai *dai, int mute, int stream)
{
struct snd_soc_component *component = dai->component;
struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component);
es8323->muted = mute;
if (mute) {
es8323_set_gpio(es8323, ES8323_CODEC_SET_SPK, 0);
es8323_set_gpio(es8323, ES8323_CODEC_SET_HP, 0);
usleep_range(18000, 20000);
snd_soc_component_write(component, ES8323_DACCONTROL3, 0x06);
} else {
snd_soc_component_write(component, ES8323_DACCONTROL3, 0x02);
snd_soc_component_write(component, 0x30, es8323_DEF_VOL);
snd_soc_component_write(component, 0x31, es8323_DEF_VOL);
msleep(50);
if (!es8323->hp_inserted)
es8323_set_gpio(es8323, ES8323_CODEC_SET_SPK, 1);
else
es8323_set_gpio(es8323, ES8323_CODEC_SET_HP, 1);
usleep_range(18000, 20000);
}
return 0;
}
@@ -913,10 +830,8 @@ static int es8323_i2c_probe(struct i2c_client *i2c,
{
struct es8323_priv *es8323;
int ret = -1;
int hp_irq = 0;
struct i2c_adapter *adapter = to_i2c_adapter(i2c->dev.parent);
char reg;
struct extcon_dev *edev;
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
dev_warn(&adapter->dev,
@@ -941,64 +856,6 @@ static int es8323_i2c_probe(struct i2c_client *i2c,
return ret;
}
es8323->spk_ctl_gpio = devm_gpiod_get_optional(&i2c->dev,
"spk-con",
GPIOD_OUT_LOW);
if (IS_ERR(es8323->spk_ctl_gpio))
return PTR_ERR(es8323->spk_ctl_gpio);
es8323->hp_ctl_gpio = devm_gpiod_get_optional(&i2c->dev,
"hp-con",
GPIOD_OUT_LOW);
if (IS_ERR(es8323->hp_ctl_gpio))
return PTR_ERR(es8323->hp_ctl_gpio);
es8323->hp_det_gpio = devm_gpiod_get_optional(&i2c->dev, "hp-det", GPIOD_IN);
if (IS_ERR(es8323->hp_det_gpio))
return PTR_ERR(es8323->hp_det_gpio);
if (device_property_read_bool(&i2c->dev, "extcon")) {
edev = extcon_get_edev_by_phandle(&i2c->dev, 0);
if (IS_ERR(edev)) {
if (PTR_ERR(edev) == -EPROBE_DEFER)
return -EPROBE_DEFER;
dev_err(&i2c->dev, "Invalid or missing extcon\n");
return PTR_ERR(edev);
}
es8323->extcon_nb.notifier_call = es8323_extcon_notifier;
ret = devm_extcon_register_notifier(&i2c->dev, edev,
EXTCON_JACK_HEADPHONE,
&es8323->extcon_nb);
if (ret < 0) {
dev_err(&i2c->dev, "register headphone notifier fail\n");
return ret;
}
ret = devm_extcon_register_notifier(&i2c->dev, edev,
EXTCON_JACK_MICROPHONE,
&es8323->extcon_nb);
if (ret < 0) {
dev_err(&i2c->dev, "register micphone notifier fail\n");
return ret;
}
es8323->hp_inserted = extcon_get_state(edev, EXTCON_JACK_HEADPHONE) ||
extcon_get_state(edev, EXTCON_JACK_MICROPHONE);
dev_info(&i2c->dev, "probe:hp_inserted %d", es8323->hp_inserted);
}
hp_irq = gpiod_to_irq(es8323->hp_det_gpio);
if (hp_irq > 0) {
ret = devm_request_threaded_irq(&i2c->dev, hp_irq, NULL,
hp_det_irq_handler,
IRQ_TYPE_EDGE_BOTH |
IRQF_ONESHOT,
"ES8323", es8323);
if (ret < 0) {
dev_err(&i2c->dev, "request_irq failed: %d\n", ret);
return ret;
}
}
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_codec_dev_es8323,
&es8323_dai, 1);
@@ -1022,9 +879,6 @@ static void es8323_i2c_shutdown(struct i2c_client *client)
{
struct es8323_priv *es8323 = i2c_get_clientdata(client);
es8323_set_gpio(es8323, ES8323_CODEC_SET_SPK, 0);
es8323_set_gpio(es8323, ES8323_CODEC_SET_HP, 0);
mdelay(20);
regmap_write(es8323->regmap, ES8323_CONTROL2, 0x58);
regmap_write(es8323->regmap, ES8323_CONTROL1, 0x32);
regmap_write(es8323->regmap, ES8323_CHIPPOWER, 0xf3);