[AIO-3288C] kernel->sound:add two standard hp detection

This commit is contained in:
sujl
2018-05-02 15:18:26 +08:00
parent 14924a220c
commit d22c8be32f

View File

@ -41,6 +41,16 @@
#include <linux/interrupt.h>
#include <linux/irq.h>
#define INVALID_GPIO -1
#if defined(CONFIG_FIREFLY_RK3288_DEVICE_AIO_3288C)
#include <linux/iio/iio.h>
#include <linux/iio/machine.h>
#include <linux/iio/driver.h>
#include <linux/iio/consumer.h>
int es8323_adc_gpio = INVALID_GPIO;
#endif
#if 0
#define DBG(x...) printk(KERN_INFO x)
#else
@ -52,7 +62,6 @@ static int set_spk = 1; // add by xhc when insert hdmi 0, no
#ifdef CONFIG_MACH_RK_FAC
int es8323_hdmi_ctrl=0;
#endif
#define INVALID_GPIO -1
int es8323_spk_con_gpio = INVALID_GPIO;
int es8323_spk_con_gpio_active = 0;
int es8323_earphone_con_gpio = INVALID_GPIO;
@ -1273,9 +1282,47 @@ void spk_timer_callback(unsigned long data )
}
#endif
#if defined(CONFIG_FIREFLY_RK3288_DEVICE_AIO_3288C)
#define VREF 1800
struct iio_channel *chan;
void hp_jack_adc(unsigned long flags)
{
int ret,raw;
chan = iio_channel_get(es8323_codec->dev, NULL);
if (IS_ERR(chan))
{
chan = NULL;
printk("%s() have not set adc chan\n", __FUNCTION__);
return;
}
ret = iio_read_channel_raw(chan, &raw);
if (ret < 0) {
printk("read hook adc channel() error: %d\n", ret);
return;
}
if(es8323_mic_state == 0) {
if(flags == 1){
printk("mic use extern\n");
snd_soc_write(es8323_codec, 0x0b,0x82);
if(raw <= 240)
gpio_direction_output(es8323_adc_gpio,1);
}else {
printk("mic use intern\n");
snd_soc_write(es8323_codec, 0x0b,0x02);
gpio_direction_output(es8323_adc_gpio,0);
}
if(line_in_state == 1) spk_detect_do_switch(1);
}
}
#endif
static int es8323_hp_jack_change(struct notifier_block *nb,
unsigned long flags, void *data)
{
#if defined(CONFIG_FIREFLY_RK3288_DEVICE_AIO_3288C)
hp_jack_adc(flags);
#else
if(es8323_mic_state == 0) {
if(flags == 1){
printk("mic use extern\n");
@ -1286,7 +1333,7 @@ static int es8323_hp_jack_change(struct notifier_block *nb,
}
if(line_in_state == 1) spk_detect_do_switch(1);
}
#endif
return NOTIFY_OK;
}
@ -1434,6 +1481,9 @@ static int es8323_probe(struct snd_soc_codec *codec)
static int es8323_remove(struct snd_soc_codec *codec)
{
es8323_set_bias_level(codec, SND_SOC_BIAS_OFF);
#if defined(CONFIG_FIREFLY_RK3288_DEVICE_AIO_3288C)
iio_channel_release(chan);
#endif
return 0;
}
@ -1739,6 +1789,20 @@ static int es8323_i2c_probe(struct i2c_client *i2c,
es8323_hp_det_gpio = INVALID_GPIO;
}
#if defined(CONFIG_FIREFLY_RK3288_DEVICE_AIO_3288C)
es8323_adc_gpio = of_get_named_gpio(i2c->dev.of_node, "adc-gpio", 0);
if (es8323_adc_gpio < 0) {
DBG("%s() Can not read property adc-en-gpio\n", __FUNCTION__);
es8323_adc_gpio = INVALID_GPIO;
}
ret = gpio_request(es8323_adc_gpio, "adc_det");
if (ret != 0) {
printk("%s request adc_det error", __func__);
return ret;
}
#endif
es8323_line_det_gpio = of_get_named_gpio(i2c->dev.of_node, "line-det-gpio", 0);
if (es8323_line_det_gpio < 0) {
DBG("%s() Can not read property es8323_line_det_gpio\n", __FUNCTION__);