From 22f5d9f8217656fc30a038d1ebb5a68f03b57a65 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Wed, 10 Jun 2015 11:54:13 +0800 Subject: [PATCH 1/7] ASoC: rt5645: Lock mutex in rt5645_enable_push_button_irq rt5645_enable_push_button_irq uses snd_soc_dapm_*_unlocked functions, so it needs to lock the required dapm mutex. Signed-off-by: Nicolas Boichat Signed-off-by: Mark Brown --- sound/soc/codecs/rt5645.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index aaede45a2f4b..abedf35f37b8 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -2762,6 +2762,7 @@ static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec, struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); if (enable) { + snd_soc_dapm_mutex_lock(&codec->dapm); snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm, "ADC L power"); snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm, @@ -2771,6 +2772,8 @@ static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec, snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm, "Mic Det Power"); snd_soc_dapm_sync_unlocked(&codec->dapm); + snd_soc_dapm_mutex_unlock(&codec->dapm); + snd_soc_update_bits(codec, RT5645_INT_IRQ_ST, 0x8, 0x8); snd_soc_update_bits(codec, @@ -2781,6 +2784,8 @@ static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec, } else { snd_soc_update_bits(codec, RT5650_4BTN_IL_CMD2, 0x8000, 0x0); snd_soc_update_bits(codec, RT5645_INT_IRQ_ST, 0x8, 0x0); + + snd_soc_dapm_mutex_lock(&codec->dapm); snd_soc_dapm_disable_pin_unlocked(&codec->dapm, "ADC L power"); snd_soc_dapm_disable_pin_unlocked(&codec->dapm, @@ -2791,6 +2796,7 @@ static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec, snd_soc_dapm_disable_pin_unlocked(&codec->dapm, "Mic Det Power"); snd_soc_dapm_sync_unlocked(&codec->dapm); + snd_soc_dapm_mutex_unlock(&codec->dapm); } } From 1fcb76dbd16f3cf4c121e6141ae27446fd732267 Mon Sep 17 00:00:00 2001 From: Oder Chiou Date: Wed, 10 Jun 2015 14:34:29 +0800 Subject: [PATCH 2/7] ASoC: rt5645: make RT5650_TDM_CTRL_4 readable Register RT5650_TDM_CTRL_4(0x7A) is readable and used for mixer setting. It should be added in rt5645_readable_register function. Signed-off-by: Bard Liao Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- sound/soc/codecs/rt5645.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index abedf35f37b8..1e207cceeb4a 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -349,6 +349,7 @@ static bool rt5645_readable_register(struct device *dev, unsigned int reg) case RT5645_TDM_CTRL_1: case RT5645_TDM_CTRL_2: case RT5645_TDM_CTRL_3: + case RT5650_TDM_CTRL_4: case RT5645_GLB_CLK: case RT5645_PLL_CTRL1: case RT5645_PLL_CTRL2: From fb5ab0e7473d41e2a9db0fcb569faf337d595838 Mon Sep 17 00:00:00 2001 From: Oder Chiou Date: Wed, 10 Jun 2015 14:27:58 +0800 Subject: [PATCH 3/7] ASoC: rt5645: add device tree support Modify the RT5645 driver to parse platform data from device tree. Write a DT binding document to describe those properties. Signed-off-by: Bard Liao Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- .../devicetree/bindings/sound/rt5645.txt | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/rt5645.txt diff --git a/Documentation/devicetree/bindings/sound/rt5645.txt b/Documentation/devicetree/bindings/sound/rt5645.txt new file mode 100644 index 000000000000..7cee1f518f59 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/rt5645.txt @@ -0,0 +1,72 @@ +RT5650/RT5645 audio CODEC + +This device supports I2C only. + +Required properties: + +- compatible : One of "realtek,rt5645" or "realtek,rt5650". + +- reg : The I2C address of the device. + +- interrupts : The CODEC's interrupt output. + +Optional properties: + +- hp-detect-gpios: + a GPIO spec for the external headphone detect pin. If jd-mode = 0, + we will get the JD status by getting the value of hp-detect-gpios. + +- realtek,in2-differential + Boolean. Indicate MIC2 input are differential, rather than single-ended. + +- realtek,dmic1-data-pin + 0: dmic1 is not used + 1: using IN2P pin as dmic1 data pin + 2: using GPIO6 pin as dmic1 data pin + 3: using GPIO10 pin as dmic1 data pin + 4: using GPIO12 pin as dmic1 data pin + +- realtek,dmic2-data-pin + 0: dmic2 is not used + 1: using IN2N pin as dmic2 data pin + 2: using GPIO5 pin as dmic2 data pin + 3: using GPIO11 pin as dmic2 data pin + +-- realtek,jd-mode : The JD mode of rt5645/rt5650 + 0 : rt5645/rt5650 JD function is not used + 1 : Mode-0 (VDD=3.3V), two port jack detection + 2 : Mode-1 (VDD=3.3V), one port jack detection + 3 : Mode-2 (VDD=1.8V), one port jack detection + +Pins on the device (for linking into audio routes) for RT5645/RT5650: + + * DMIC L1 + * DMIC R1 + * DMIC L2 + * DMIC R2 + * IN1P + * IN1N + * IN2P + * IN2N + * Haptic Generator + * HPOL + * HPOR + * LOUTL + * LOUTR + * PDM1L + * PDM1R + * SPOL + * SPOR + +Example: + +codec: rt5650@1a { + compatible = "realtek,rt5650"; + reg = <0x1a>; + hp-detect-gpios = <&gpio 19 0>; + interrupt-parent = <&gpio>; + interrupts = <7 IRQ_TYPE_EDGE_FALLING>; + realtek,dmic-en = "true"; + realtek,en-jd-func = "true"; + realtek,jd-mode = <3>; +}; \ No newline at end of file From 0b0cefc8fd105f379989164f3ef7e5b4a0d44c1f Mon Sep 17 00:00:00 2001 From: Oder Chiou Date: Wed, 10 Jun 2015 14:27:57 +0800 Subject: [PATCH 4/7] ASoC: rt5645: change gpio to gpiod APIs Move gpio to gpio_desc and use gpiod APIs in codec driver. Signed-off-by: Bard Liao Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- include/sound/rt5645.h | 3 --- sound/soc/codecs/rt5645.c | 47 ++++++++++----------------------------- sound/soc/codecs/rt5645.h | 1 + 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/include/sound/rt5645.h b/include/sound/rt5645.h index 652cb9e4afe5..22734bc3ffd4 100644 --- a/include/sound/rt5645.h +++ b/include/sound/rt5645.h @@ -20,9 +20,6 @@ struct rt5645_platform_data { unsigned int dmic2_data_pin; /* 0 = IN2P; 1 = GPIO6; 2 = GPIO10; 3 = GPIO12 */ - unsigned int hp_det_gpio; - bool gpio_hp_det_active_high; - unsigned int jd_mode; }; diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index a949b77291db..7d04b1aa74f0 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -2944,17 +2944,11 @@ static int rt5645_irq_detection(struct rt5645_priv *rt5645) switch (rt5645->pdata.jd_mode) { case 0: /* Not using rt5645 JD */ - if (gpio_is_valid(rt5645->pdata.hp_det_gpio)) { - gpio_state = gpio_get_value(rt5645->pdata.hp_det_gpio); - dev_dbg(rt5645->codec->dev, "gpio = %d(%d)\n", - rt5645->pdata.hp_det_gpio, gpio_state); - } - if ((rt5645->pdata.gpio_hp_det_active_high && gpio_state) || - (!rt5645->pdata.gpio_hp_det_active_high && - !gpio_state)) { - report = rt5645_jack_detect(rt5645->codec, 1); - } else { - report = rt5645_jack_detect(rt5645->codec, 0); + if (rt5645->gpiod_hp_det) { + gpio_state = gpiod_get_value(rt5645->gpiod_hp_det); + dev_dbg(rt5645->codec->dev, "gpio_state = %d\n", + gpio_state); + report = rt5645_jack_detect(rt5645->codec, gpio_state); } snd_soc_jack_report(rt5645->hp_jack, report, SND_JACK_HEADPHONE); @@ -3244,7 +3238,6 @@ static int rt5645_i2c_probe(struct i2c_client *i2c, struct rt5645_priv *rt5645; int ret; unsigned int val; - struct gpio_desc *gpiod; rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv), GFP_KERNEL); @@ -3259,19 +3252,16 @@ static int rt5645_i2c_probe(struct i2c_client *i2c, } else { if (dmi_check_system(dmi_platform_intel_braswell)) { rt5645->pdata = *rt5645_pdata; - gpiod = devm_gpiod_get_index(&i2c->dev, "rt5645", 0); - - if (IS_ERR(gpiod) || gpiod_direction_input(gpiod)) { - rt5645->pdata.hp_det_gpio = -1; - dev_err(&i2c->dev, "failed to initialize gpiod\n"); - } else { - rt5645->pdata.hp_det_gpio = desc_to_gpio(gpiod); - rt5645->pdata.gpio_hp_det_active_high - = !gpiod_is_active_low(gpiod); - } } } + rt5645->gpiod_hp_det = devm_gpiod_get(&i2c->dev, "hp-detect", GPIOD_IN); + + if (IS_ERR(rt5645->gpiod_hp_det)) { + rt5645->gpiod_hp_det = NULL; + dev_err(&i2c->dev, "failed to initialize gpiod\n"); + } + rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5645_regmap); if (IS_ERR(rt5645->regmap)) { ret = PTR_ERR(rt5645->regmap); @@ -3433,16 +3423,6 @@ static int rt5645_i2c_probe(struct i2c_client *i2c, dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); } - if (gpio_is_valid(rt5645->pdata.hp_det_gpio)) { - ret = gpio_request(rt5645->pdata.hp_det_gpio, "rt5645"); - if (ret) - dev_err(&i2c->dev, "Fail gpio_request hp_det_gpio\n"); - - ret = gpio_direction_input(rt5645->pdata.hp_det_gpio); - if (ret) - dev_err(&i2c->dev, "Fail gpio_direction hp_det_gpio\n"); - } - return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645, rt5645_dai, ARRAY_SIZE(rt5645_dai)); } @@ -3456,9 +3436,6 @@ static int rt5645_i2c_remove(struct i2c_client *i2c) cancel_delayed_work_sync(&rt5645->jack_detect_work); - if (gpio_is_valid(rt5645->pdata.hp_det_gpio)) - gpio_free(rt5645->pdata.hp_det_gpio); - snd_soc_unregister_codec(&i2c->dev); return 0; diff --git a/sound/soc/codecs/rt5645.h b/sound/soc/codecs/rt5645.h index 9ec4e899795d..0353a6a273ab 100644 --- a/sound/soc/codecs/rt5645.h +++ b/sound/soc/codecs/rt5645.h @@ -2182,6 +2182,7 @@ struct rt5645_priv { struct rt5645_platform_data pdata; struct regmap *regmap; struct i2c_client *i2c; + struct gpio_desc *gpiod_hp_det; struct snd_soc_jack *hp_jack; struct snd_soc_jack *mic_jack; struct snd_soc_jack *btn_jack; From 48edaa4b4fb6e75b890942394f0d0c2571d5c90d Mon Sep 17 00:00:00 2001 From: Oder Chiou Date: Fri, 12 Jun 2015 14:47:36 +0800 Subject: [PATCH 5/7] ASoC: rt5645: Add the device tree parser Modify the RT5645 driver to parse platform data from device tree. This is missing from previous patch in sound/soc/codecs/rt5645.c, that was present in v3. Signed-off-by: Bard Liao Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- sound/soc/codecs/rt5645.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index 7d04b1aa74f0..18842642a34e 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -3231,6 +3231,20 @@ static struct dmi_system_id dmi_platform_intel_braswell[] = { { } }; +static int rt5645_parse_dt(struct rt5645_priv *rt5645, struct device *dev) +{ + rt5645->pdata.in2_diff = device_property_read_bool(dev, + "realtek,in2-differential"); + device_property_read_u32(dev, + "realtek,dmic1-data-pin", &rt5645->pdata.dmic1_data_pin); + device_property_read_u32(dev, + "realtek,dmic2-data-pin", &rt5645->pdata.dmic2_data_pin); + device_property_read_u32(dev, + "realtek,jd-mode", &rt5645->pdata.jd_mode); + + return 0; +} + static int rt5645_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -3247,13 +3261,12 @@ static int rt5645_i2c_probe(struct i2c_client *i2c, rt5645->i2c = i2c; i2c_set_clientdata(i2c, rt5645); - if (pdata) { + if (pdata) rt5645->pdata = *pdata; - } else { - if (dmi_check_system(dmi_platform_intel_braswell)) { - rt5645->pdata = *rt5645_pdata; - } - } + else if (dmi_check_system(dmi_platform_intel_braswell)) + rt5645->pdata = *rt5645_pdata; + else + rt5645_parse_dt(rt5645, &i2c->dev); rt5645->gpiod_hp_det = devm_gpiod_get(&i2c->dev, "hp-detect", GPIOD_IN); From 25c8888ad65f812c847ae58398a5f8f1b20b0a95 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 12 Jun 2015 17:19:15 +0800 Subject: [PATCH 6/7] ASoC: rt5645: Use devm_gpiod_get_optional for hp-detect Since hp-detect is optional, use devm_gpiod_get_optional instead. In additional, it should return error if devm_gpiod_get_optional fails. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- sound/soc/codecs/rt5645.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index 18842642a34e..43440436fd7b 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -3268,11 +3268,12 @@ static int rt5645_i2c_probe(struct i2c_client *i2c, else rt5645_parse_dt(rt5645, &i2c->dev); - rt5645->gpiod_hp_det = devm_gpiod_get(&i2c->dev, "hp-detect", GPIOD_IN); + rt5645->gpiod_hp_det = devm_gpiod_get_optional(&i2c->dev, "hp-detect", + GPIOD_IN); if (IS_ERR(rt5645->gpiod_hp_det)) { - rt5645->gpiod_hp_det = NULL; dev_err(&i2c->dev, "failed to initialize gpiod\n"); + return PTR_ERR(rt5645->gpiod_hp_det); } rt5645->regmap = devm_regmap_init_i2c(i2c, &rt5645_regmap); From 851b81e8675127989a0cc084d2e9d76fb4c2ab05 Mon Sep 17 00:00:00 2001 From: Michele Curti Date: Mon, 15 Jun 2015 10:44:11 +0800 Subject: [PATCH 7/7] ASoC: rt5645: move RT5650 muxes to rt5650_specific_dapm_widgets Developing a driver for an Asus X205TA laptop I get these dmesg errors: rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 ADC1 Swap Mux has no paths rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 ADC2 Swap Mux has no paths rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 ADC3 Swap Mux has no paths rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 ADC Mux has no paths rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 DAC1 L Mux has no paths rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 DAC1 R Mux has no paths rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 DAC2 L Mux has no paths rt5645 i2c-10EC5648:00: ASoC: mux RT5650 IF1 DAC2 R Mux has no paths so, move these muxes to the rt5650_specific_dapm_widgets[] list. Signed-off-by: Michele Curti Signed-off-by: Oder Chiou Signed-off-by: Mark Brown --- sound/soc/codecs/rt5645.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index 43440436fd7b..9ce311e088fc 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -1706,15 +1706,6 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = { SND_SOC_DAPM_MUX("RT5645 IF1 ADC Mux", SND_SOC_NOPM, 0, 0, &rt5645_if1_adc_in_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 ADC1 Swap Mux", SND_SOC_NOPM, - 0, 0, &rt5650_if1_adc1_in_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 ADC2 Swap Mux", SND_SOC_NOPM, - 0, 0, &rt5650_if1_adc2_in_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 ADC3 Swap Mux", SND_SOC_NOPM, - 0, 0, &rt5650_if1_adc3_in_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 ADC Mux", SND_SOC_NOPM, - 0, 0, &rt5650_if1_adc_in_mux), - SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM, 0, 0, &rt5645_if2_adc_in_mux), @@ -1733,14 +1724,6 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = { &rt5645_if1_dac2_tdm_sel_mux), SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 R Mux", SND_SOC_NOPM, 0, 0, &rt5645_if1_dac3_tdm_sel_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 L Mux", SND_SOC_NOPM, 0, 0, - &rt5650_if1_dac0_tdm_sel_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 R Mux", SND_SOC_NOPM, 0, 0, - &rt5650_if1_dac1_tdm_sel_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 L Mux", SND_SOC_NOPM, 0, 0, - &rt5650_if1_dac2_tdm_sel_mux), - SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 R Mux", SND_SOC_NOPM, 0, 0, - &rt5650_if1_dac3_tdm_sel_mux), SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0), SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0), SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0), @@ -1882,6 +1865,24 @@ static const struct snd_soc_dapm_widget rt5650_specific_dapm_widgets[] = { 0, 0, &rt5650_a_dac2_l_mux), SND_SOC_DAPM_MUX("A DAC2 R Mux", SND_SOC_NOPM, 0, 0, &rt5650_a_dac2_r_mux), + + SND_SOC_DAPM_MUX("RT5650 IF1 ADC1 Swap Mux", SND_SOC_NOPM, + 0, 0, &rt5650_if1_adc1_in_mux), + SND_SOC_DAPM_MUX("RT5650 IF1 ADC2 Swap Mux", SND_SOC_NOPM, + 0, 0, &rt5650_if1_adc2_in_mux), + SND_SOC_DAPM_MUX("RT5650 IF1 ADC3 Swap Mux", SND_SOC_NOPM, + 0, 0, &rt5650_if1_adc3_in_mux), + SND_SOC_DAPM_MUX("RT5650 IF1 ADC Mux", SND_SOC_NOPM, + 0, 0, &rt5650_if1_adc_in_mux), + + SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 L Mux", SND_SOC_NOPM, 0, 0, + &rt5650_if1_dac0_tdm_sel_mux), + SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 R Mux", SND_SOC_NOPM, 0, 0, + &rt5650_if1_dac1_tdm_sel_mux), + SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 L Mux", SND_SOC_NOPM, 0, 0, + &rt5650_if1_dac2_tdm_sel_mux), + SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 R Mux", SND_SOC_NOPM, 0, 0, + &rt5650_if1_dac3_tdm_sel_mux), }; static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {