ASoC: mediatek: mt6359: add MT6359 accdet jack driver

MT6359 audio codec supports jack detection feature, adds MT6359
accdet driver to support jack plugged detection and key detection.

Signed-off-by: Argus Lin <argus.lin@mediatek.com>
Link: https://lore.kernel.org/r/1615383186-18500-3-git-send-email-argus.lin@mediatek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Argus Lin 2021-03-10 21:33:06 +08:00 committed by Mark Brown
parent e61c589587
commit eef07b9e09
No known key found for this signature in database
GPG key ID: 24D68B725D5487D0
5 changed files with 2972 additions and 104 deletions

View file

@ -1812,6 +1812,14 @@ config SND_SOC_MT6359
Enable support for the platform which uses MT6359 as Enable support for the platform which uses MT6359 as
external codec device. external codec device.
config SND_SOC_MT6359_ACCDET
tristate "MediaTek MT6359 ACCDET driver"
depends on MTK_PMIC_WRAP
help
ACCDET means Accessory Detection technology, MediaTek develop it
for ASoC codec soc-jack detection mechanism.
Select N if you don't have jack on board.
config SND_SOC_MT6660 config SND_SOC_MT6660
tristate "Mediatek MT6660 Speaker Amplifier" tristate "Mediatek MT6660 Speaker Amplifier"
depends on I2C depends on I2C

View file

@ -136,6 +136,7 @@ snd-soc-msm8916-digital-objs := msm8916-wcd-digital.o
snd-soc-mt6351-objs := mt6351.o snd-soc-mt6351-objs := mt6351.o
snd-soc-mt6358-objs := mt6358.o snd-soc-mt6358-objs := mt6358.o
snd-soc-mt6359-objs := mt6359.o snd-soc-mt6359-objs := mt6359.o
snd-soc-mt6359-accdet-objs := mt6359-accdet.o
snd-soc-mt6660-objs := mt6660.o snd-soc-mt6660-objs := mt6660.o
snd-soc-nau8315-objs := nau8315.o snd-soc-nau8315-objs := nau8315.o
snd-soc-nau8540-objs := nau8540.o snd-soc-nau8540-objs := nau8540.o
@ -454,6 +455,7 @@ obj-$(CONFIG_SND_SOC_MSM8916_WCD_DIGITAL) +=snd-soc-msm8916-digital.o
obj-$(CONFIG_SND_SOC_MT6351) += snd-soc-mt6351.o obj-$(CONFIG_SND_SOC_MT6351) += snd-soc-mt6351.o
obj-$(CONFIG_SND_SOC_MT6358) += snd-soc-mt6358.o obj-$(CONFIG_SND_SOC_MT6358) += snd-soc-mt6358.o
obj-$(CONFIG_SND_SOC_MT6359) += snd-soc-mt6359.o obj-$(CONFIG_SND_SOC_MT6359) += snd-soc-mt6359.o
obj-$(CONFIG_SND_SOC_MT6359_ACCDET) += mt6359-accdet.o
obj-$(CONFIG_SND_SOC_MT6660) += snd-soc-mt6660.o obj-$(CONFIG_SND_SOC_MT6660) += snd-soc-mt6660.o
obj-$(CONFIG_SND_SOC_NAU8315) += snd-soc-nau8315.o obj-$(CONFIG_SND_SOC_NAU8315) += snd-soc-nau8315.o
obj-$(CONFIG_SND_SOC_NAU8540) += snd-soc-nau8540.o obj-$(CONFIG_SND_SOC_NAU8540) += snd-soc-nau8540.o

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,128 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2021 MediaTek Inc.
* Author: Argus Lin <argus.lin@mediatek.com>
*/
#ifndef _ACCDET_H_
#define _ACCDET_H_
#include <linux/ctype.h>
#include <linux/string.h>
#define ACCDET_DEVNAME "accdet"
#define HEADSET_MODE_1 (1)
#define HEADSET_MODE_2 (2)
#define HEADSET_MODE_6 (6)
#define MT6359_ACCDET_NUM_BUTTONS 4
#define MT6359_ACCDET_JACK_MASK (SND_JACK_HEADPHONE | \
SND_JACK_HEADSET | \
SND_JACK_BTN_0 | \
SND_JACK_BTN_1 | \
SND_JACK_BTN_2 | \
SND_JACK_BTN_3)
#define MT6359_ACCDET_BTN_MASK (SND_JACK_BTN_0 | \
SND_JACK_BTN_1 | \
SND_JACK_BTN_2 | \
SND_JACK_BTN_3)
enum eint_moisture_status {
M_PLUG_IN = 0,
M_WATER_IN = 1,
M_HP_PLUG_IN = 2,
M_PLUG_OUT = 3,
M_NO_ACT = 4,
M_UNKNOWN = 5,
};
enum {
accdet_state000 = 0,
accdet_state001,
accdet_state010,
accdet_state011,
accdet_auxadc,
eint_state000,
eint_state001,
eint_state010,
eint_state011,
eint_inverter_state000,
};
struct three_key_threshold {
unsigned int mid;
unsigned int up;
unsigned int down;
};
struct four_key_threshold {
unsigned int mid;
unsigned int voice;
unsigned int up;
unsigned int down;
};
struct pwm_deb_settings {
unsigned int pwm_width;
unsigned int pwm_thresh;
unsigned int fall_delay;
unsigned int rise_delay;
unsigned int debounce0;
unsigned int debounce1;
unsigned int debounce3;
unsigned int debounce4;
unsigned int eint_pwm_width;
unsigned int eint_pwm_thresh;
unsigned int eint_debounce0;
unsigned int eint_debounce1;
unsigned int eint_debounce2;
unsigned int eint_debounce3;
unsigned int eint_inverter_debounce;
};
struct dts_data {
unsigned int mic_vol;
unsigned int mic_mode;
unsigned int plugout_deb;
unsigned int eint_pol;
struct pwm_deb_settings *pwm_deb;
struct three_key_threshold three_key;
struct four_key_threshold four_key;
unsigned int moisture_detect_enable;
unsigned int eint_detect_mode;
unsigned int eint_use_ext_res;
unsigned int eint_comp_vth;
unsigned int moisture_detect_mode;
unsigned int moisture_comp_vth;
unsigned int moisture_comp_vref2;
unsigned int moisture_use_ext_res;
};
struct mt6359_accdet {
struct snd_soc_jack *jack;
struct device *dev;
struct regmap *regmap;
struct dts_data *data;
unsigned int caps;
int accdet_irq;
int accdet_eint0;
int accdet_eint1;
struct mutex res_lock; /* lock protection */
bool jack_plugged;
unsigned int jack_type;
unsigned int btn_type;
unsigned int accdet_status;
unsigned int pre_accdet_status;
unsigned int cali_voltage;
unsigned int jd_sts;
struct work_struct accdet_work;
struct workqueue_struct *accdet_workqueue;
struct work_struct jd_work;
struct workqueue_struct *jd_workqueue;
};
int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
struct snd_soc_jack *jack);
#endif

File diff suppressed because it is too large Load diff