From 5e678e8d2a2fc2c4c2dde812811f9dd267f17189 Mon Sep 17 00:00:00 2001 From: Francisco Mendez Date: Wed, 6 Jan 2016 19:31:21 -0600 Subject: [PATCH 1/2] Adding button press flag and organizing jd2 code T100 device has not support for button press from headset a flag is added to avoid trying to enable unsupported gpios and avoid some initializing errors. When jack detection 2 pin is used (T100) some registers needs to be configured. This code has been changed to a function to clean up it a little. MICBIAS1 has been fixed from lowercase Signed-off-by: Francisco Mendez --- sound/soc/intel/boards/byt_cr_board_configs.h | 5 +- sound/soc/intel/boards/bytcr_rt5640.c | 185 ++++++++++-------- 2 files changed, 103 insertions(+), 87 deletions(-) diff --git a/sound/soc/intel/boards/byt_cr_board_configs.h b/sound/soc/intel/boards/byt_cr_board_configs.h index 50de4b500610a5..616e5d0dfc7605 100644 --- a/sound/soc/intel/boards/byt_cr_board_configs.h +++ b/sound/soc/intel/boards/byt_cr_board_configs.h @@ -42,6 +42,8 @@ enum { #define BYT_RT5640_JACK_INT2 BIT(22) #define BYT_RT5640_JACK_BP_CODEC BIT(23) #define BYT_RT5640_JACK_BP_MICBIAS BIT(24) +#define BYT_RT5640_JACK_DET_PIN2 BIT(25) /* default 0 */ +#define BYT_RT5640_JACK_BP_EN BIT(26) static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP | @@ -64,7 +66,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | - BYT_RT5640_MCLK_EN), + BYT_RT5640_MCLK_EN | + BYT_RT5640_JACK_DET_PIN2), }, { .callback = byt_rt5640_quirk_cb, diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c index 2023355798bc35..9ae79e96aef72c 100644 --- a/sound/soc/intel/boards/bytcr_rt5640.c +++ b/sound/soc/intel/boards/bytcr_rt5640.c @@ -93,21 +93,21 @@ struct byt_drvdata { static inline struct snd_soc_dai *byt_get_codec_dai(struct snd_soc_card *card) { - int i; + int i; for (i = 0; i < card->num_rtd; i++) { struct snd_soc_pcm_runtime *rtd; rtd = card->rtd + i; if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI, - strlen(BYT_CODEC_DAI))) + strlen(BYT_CODEC_DAI))) return rtd->codec_dai; } return NULL; } static int platform_clock_control(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *k, int event) + struct snd_kcontrol *k, int event) { struct snd_soc_dapm_context *dapm = w->dapm; struct snd_soc_card *card = dapm->card; @@ -117,7 +117,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, codec_dai = byt_get_codec_dai(card); if (!codec_dai) { dev_err(card->dev, - "Codec dai not found; Unable to set platform clock\n"); + "Codec dai not found; Unable to set platform clock\n"); return -EIO; } @@ -125,32 +125,32 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) { ret = vlv2_plat_configure_clock(VLV2_PLT_CLK_AUDIO, - VLV2_PLT_CLK_CONFG_FORCE_ON); + VLV2_PLT_CLK_CONFG_FORCE_ON); if (ret < 0) { dev_err(card->dev, - "could not configure MCLK state"); + "could not configure MCLK state"); return ret; } } ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, - 48000 * 512, - SND_SOC_CLOCK_IN); + 48000 * 512, + SND_SOC_CLOCK_IN); } else { /* Set codec clock source to internal clock before turning off the platform clock. Codec needs clock for Jack detection and button press */ ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK, - 0, - SND_SOC_CLOCK_IN); + 0, + SND_SOC_CLOCK_IN); if (!ret) { if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) { ret = vlv2_plat_configure_clock( - VLV2_PLT_CLK_AUDIO, - VLV2_PLT_CLK_CONFG_FORCE_OFF); + VLV2_PLT_CLK_AUDIO, + VLV2_PLT_CLK_CONFG_FORCE_OFF); if (ret) { dev_err(card->dev, - "could not configure MCLK state"); + "could not configure MCLK state"); return ret; } } @@ -246,10 +246,10 @@ static inline void byt_set_mic_bias_ldo(struct snd_soc_codec *codec, struct snd_soc_dapm_context *dapm; dapm = snd_soc_codec_get_dapm(codec); if (enable) { - byt_force_enable_pin(codec, "micbias1", true); + byt_force_enable_pin(codec, "MICBIAS1", true); byt_force_enable_pin(codec, "LDO2", true); } else { - byt_force_enable_pin(codec, "micbias1", false); + byt_force_enable_pin(codec, "MICBIAS1", false); byt_force_enable_pin(codec, "LDO2", false); } @@ -297,7 +297,7 @@ static int byt_bp_check(struct byt_drvdata *drvdata, bool is_recheck) } if (((val == 0) && !(jack->status & SND_JACK_BTN_0)) || - ((val > 0) && (jack->status & SND_JACK_BTN_0))) { + ((val > 0) && (jack->status & SND_JACK_BTN_0))) { pr_debug("%s: No change (%d).\n", __func__, val); return false; } @@ -315,7 +315,7 @@ static int byt_bp_check(struct byt_drvdata *drvdata, bool is_recheck) if (!is_recheck) { pr_debug("%s: Button press (preliminary).\n", __func__); schedule_delayed_work(&drvdata->bp_recheck, - drvdata->t_buttons_recheck); + drvdata->t_buttons_recheck); return false; } else { jack->status |= SND_JACK_BTN_0; @@ -540,57 +540,60 @@ static void byt_init_gpios(struct snd_soc_codec *codec, pr_err("%s: GPIOs - JD-int: Not present!\n", __func__); } - desc = devm_gpiod_get_index(codec->dev, NULL, RT5640_GPIO_JD_INT2, GPIOD_ASIS); - if (!IS_ERR(desc)) { - drvdata->gpios.jd_int2_gpio = desc_to_gpio(desc); - byt_export_gpio(desc, "JD-int2"); + /* FIXME: Define which GPIOS should be enabled */ + if (byt_rt5640_quirk & BYT_RT5640_JACK_BP_EN) { + desc = devm_gpiod_get_index(codec->dev, NULL, RT5640_GPIO_JD_INT2, GPIOD_ASIS); + if (!IS_ERR(desc)) { + drvdata->gpios.jd_int2_gpio = desc_to_gpio(desc); + byt_export_gpio(desc, "JD-int2"); - pr_info("%s: GPIOs - JD-int2: %d (pol = %d, val = %d)\n", - __func__, drvdata->gpios.jd_int2_gpio, - gpiod_is_active_low(desc), gpiod_get_value(desc)); + pr_info("%s: GPIOs - JD-int2: %d (pol = %d, val = %d)\n", + __func__, drvdata->gpios.jd_int2_gpio, + gpiod_is_active_low(desc), gpiod_get_value(desc)); - devm_gpiod_put(codec->dev, desc); - } else { - drvdata->gpios.jd_int2_gpio = RT5640_GPIO_NA; - pr_warn("%s: GPIOs - JD-int2: Not present!\n", __func__); - } + devm_gpiod_put(codec->dev, desc); + } else { + drvdata->gpios.jd_int2_gpio = RT5640_GPIO_NA; + pr_warn("%s: GPIOs - JD-int2: Not present!\n", __func__); + } - desc = devm_gpiod_get_index(codec->dev, NULL, RT5640_GPIO_JD_BUTTONS, GPIOD_ASIS); - if (!IS_ERR(desc)) { - drvdata->gpios.jd_buttons_gpio = desc_to_gpio(desc); - byt_export_gpio(desc, "JD-buttons"); + desc = devm_gpiod_get_index(codec->dev, NULL, RT5640_GPIO_JD_BUTTONS, GPIOD_ASIS); + if (!IS_ERR(desc)) { + drvdata->gpios.jd_buttons_gpio = desc_to_gpio(desc); + byt_export_gpio(desc, "JD-buttons"); - pr_info("%s: GPIOs - JD-buttons: %d (pol = %d, val = %d)\n", - __func__, drvdata->gpios.jd_buttons_gpio, - gpiod_is_active_low(desc), gpiod_get_value(desc)); + pr_info("%s: GPIOs - JD-buttons: %d (pol = %d, val = %d)\n", + __func__, drvdata->gpios.jd_buttons_gpio, + gpiod_is_active_low(desc), gpiod_get_value(desc)); - devm_gpiod_put(codec->dev, desc); - } else { - drvdata->gpios.jd_buttons_gpio = RT5640_GPIO_NA; - pr_warn("%s: GPIOs - JD-buttons: Not present!\n", __func__); - } + devm_gpiod_put(codec->dev, desc); + } else { + drvdata->gpios.jd_buttons_gpio = RT5640_GPIO_NA; + pr_warn("%s: GPIOs - JD-buttons: Not present!\n", __func__); + } - desc = devm_gpiod_get_index(codec->dev, NULL, RT5640_GPIO_I2S_TRISTATE, GPIOD_ASIS); - if (!IS_ERR(desc)) { - drvdata->gpios.i2s_tristate_en_gpio = desc_to_gpio(desc); + desc = devm_gpiod_get_index(codec->dev, NULL, RT5640_GPIO_I2S_TRISTATE, GPIOD_ASIS); + if (!IS_ERR(desc)) { + drvdata->gpios.i2s_tristate_en_gpio = desc_to_gpio(desc); - ret = gpiod_direction_output(desc, 0); - if (ret) - pr_warn("%s: Failed to set direction for GPIO%d (err = %d)!\n", - __func__, drvdata->gpios.i2s_tristate_en_gpio, - ret); + ret = gpiod_direction_output(desc, 0); + if (ret) + pr_warn("%s: Failed to set direction for GPIO%d (err = %d)!\n", + __func__, drvdata->gpios.i2s_tristate_en_gpio, + ret); - byt_export_gpio(desc, "I2S-Tristate-En"); + byt_export_gpio(desc, "I2S-Tristate-En"); - pr_info("%s: GPIOs - I2S-Tristate-En: %d (pol = %d, val = %d)\n", - __func__, drvdata->gpios.i2s_tristate_en_gpio, - gpiod_is_active_low(desc), gpiod_get_value(desc)); + pr_info("%s: GPIOs - I2S-Tristate-En: %d (pol = %d, val = %d)\n", + __func__, drvdata->gpios.i2s_tristate_en_gpio, + gpiod_is_active_low(desc), gpiod_get_value(desc)); - devm_gpiod_put(codec->dev, desc); - } else { - drvdata->gpios.i2s_tristate_en_gpio = RT5640_GPIO_NA; - pr_warn("%s: GPIOs - i2s_tristate_en-mux: Not present!\n", - __func__); + devm_gpiod_put(codec->dev, desc); + } else { + drvdata->gpios.i2s_tristate_en_gpio = RT5640_GPIO_NA; + pr_warn("%s: GPIOs - i2s_tristate_en-mux: Not present!\n", + __func__); + } } } @@ -653,7 +656,9 @@ static int byt_config_jack_gpios(struct byt_drvdata *drvdata) } - if ((int_sel == JACK_INT1) || (bp_sel == JACK_BP_CODEC)) { + if ((int_sel == JACK_INT1) || + (bp_sel == JACK_BP_CODEC && (byt_rt5640_quirk & BYT_RT5640_JACK_BP_EN))) { + jack_gpio_int1[0].gpio = int1_gpio; jack_gpio_int1[0].data = drvdata; jack_gpio_int1[0].report = (int_sel == JACK_INT1) ? @@ -676,7 +681,7 @@ static int byt_config_jack_gpios(struct byt_drvdata *drvdata) } } - if (bp_sel == JACK_BP_MICBIAS) { + if ((byt_rt5640_quirk & BYT_RT5640_JACK_BP_EN) && bp_sel == JACK_BP_MICBIAS) { jack_gpio_micbias[0].gpio = bp_gpio; jack_gpio_micbias[0].data = drvdata; pr_debug("%s: Add micbias-GPIO (%d).\n", __func__, bp_gpio); @@ -733,6 +738,29 @@ static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream, return 0; } +static void byt_rt5640_configure_jd2(struct snd_soc_codec *codec) +{ /* only for devices using JD2 pin like T100 */ + /* FIXME it's ugly, is there a better way? */ + snd_soc_write(codec, RT5640_JD_CTRL, 0x6003); + snd_soc_write(codec, RT5640_IN3_IN4, 0x0000); + snd_soc_write(codec, RT5640_IN1_IN2, 0x51c0); + + /* selecting pin as an interrupt */ + snd_soc_write(codec, RT5640_GPIO_CTRL1, 0x8400); + /* set GPIO1 output */ + snd_soc_write(codec, RT5640_GPIO_CTRL3, 0x0004); + + /* enabling jd2 in general control 1 */ + snd_soc_write(codec, RT5640_DUMMY1, 0x3f41); + + /* enabling jd2 in general control 2 */ + snd_soc_write(codec, RT5640_DUMMY2, 0x4001); + + snd_soc_write(codec, RT5640_REC_L2_MIXER, 0x007f); + + /* FIXME end */ +} + static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) { int ret; @@ -781,28 +809,15 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) } /* Other jack/bp stuff */ - /* JACK_DET_N signal as JD-source */ - /* FIXME start */ - //snd_soc_update_bits(byt_get_codec(card), RT5640_JD_CTRL, - // RT5640_JD_MASK, RT5640_JD_JD2_IN4N); - snd_soc_write(codec, RT5640_JD_CTRL, 0x6003); - snd_soc_write(codec, RT5640_IN3_IN4, 0x0000); - snd_soc_write(codec, RT5640_IN1_IN2, 0x51c0); - - /* selecting pin as an interrupt */ - snd_soc_write(codec, RT5640_GPIO_CTRL1, 0x8400); - /* set GPIO1 output */ - snd_soc_write(codec, RT5640_GPIO_CTRL3, 0x0004); - - /* enabling jd2 in general control 1 */ - snd_soc_write(codec, RT5640_DUMMY1, 0x3f41); - - /* enabling jd2 in general control 2 */ - snd_soc_write(codec, RT5640_DUMMY2, 0x4001); - - snd_soc_write(codec, RT5640_REC_L2_MIXER, 0x007f); + /* for devices using JD2 pin should be configured some registers */ + if (byt_rt5640_quirk & BYT_RT5640_JACK_DET_PIN2) { + byt_rt5640_configure_jd2(codec); + } else { + /* JACK_DET_N signal as JD-source */ + snd_soc_update_bits(codec, RT5640_JD_CTRL, + RT5640_JD_MASK, RT5640_JD_JD2_IN4N); + } - /* FIXME end */ /* Prevent sta_jd_internal to trigger IRQ in CODEC-mode */ if (drvdata->jack_bp_sel == JACK_BP_CODEC) snd_soc_write(codec, RT5640_IRQ_CTRL1, 0x0000); @@ -1060,7 +1075,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) } /* register the soc card */ - byt_rt5640_card.dev = &pdev->dev; + card->dev = &pdev->dev; mach = byt_rt5640_card.dev->platform_data; /* fixup codec name based on HID */ @@ -1088,14 +1103,12 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) drvdata->jack_bp_sel = JACK_BP_MICBIAS; } - /* register the soc card */ - card->dev = &pdev->dev; snd_soc_card_set_drvdata(card, drvdata); - ret_val = devm_snd_soc_register_card(&pdev->dev, card); + ret_val = devm_snd_soc_register_card(card->dev, card); if (ret_val) { - dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", + dev_err(card->dev, "devm_snd_soc_register_card failed %d\n", ret_val); return ret_val; } From d19ef0951a3d8ad9dfc4816b4d8d35d4084f8ff3 Mon Sep 17 00:00:00 2001 From: Francisco Mendez Date: Thu, 7 Jan 2016 16:10:08 -0600 Subject: [PATCH 2/2] Clean up interruption functions and gpios the current interrupt functions are a little weird, because int1 is used sometimes for jack detection but other for bp. This definitions has been changed and now there are only 2 interruptions functions, only for jack always and the other for but as well. INT1 and INT2 flags have been removed and all the logic is only using MICBIAS or CODEC button press flags. Signed-off-by: Francisco Mendez --- sound/soc/intel/boards/byt_cr_board_configs.h | 25 +-- sound/soc/intel/boards/bytcr_rt5640.c | 179 ++++++------------ 2 files changed, 60 insertions(+), 144 deletions(-) diff --git a/sound/soc/intel/boards/byt_cr_board_configs.h b/sound/soc/intel/boards/byt_cr_board_configs.h index 616e5d0dfc7605..f4583405a33b22 100644 --- a/sound/soc/intel/boards/byt_cr_board_configs.h +++ b/sound/soc/intel/boards/byt_cr_board_configs.h @@ -38,12 +38,10 @@ enum { #define BYT_RT5640_MCLK_25MHZ BIT(18) #define BYT_RT5640_JACK_DET_EN BIT(19) #define BYT_RT5640_JACK_ACTIVE_LOW BIT(20) /* default 0 */ -#define BYT_RT5640_JACK_INT1 BIT(21) -#define BYT_RT5640_JACK_INT2 BIT(22) -#define BYT_RT5640_JACK_BP_CODEC BIT(23) -#define BYT_RT5640_JACK_BP_MICBIAS BIT(24) -#define BYT_RT5640_JACK_DET_PIN2 BIT(25) /* default 0 */ -#define BYT_RT5640_JACK_BP_EN BIT(26) +#define BYT_RT5640_JACK_BP_CODEC BIT(21) +#define BYT_RT5640_JACK_BP_MICBIAS BIT(22) +#define BYT_RT5640_JACK_DET_PIN2 BIT(23) /* default 0 */ +#define BYT_RT5640_JACK_BP_EN BIT(24) static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP | @@ -64,7 +62,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { }, .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | BYT_RT5640_JACK_DET_EN | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN | BYT_RT5640_JACK_DET_PIN2), @@ -105,7 +102,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { }, .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN), }, @@ -119,7 +115,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT2 | BYT_RT5640_JACK_BP_CODEC | BYT_RT5640_MCLK_EN), }, @@ -132,7 +127,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT2 | BYT_RT5640_JACK_BP_CODEC | BYT_RT5640_MCLK_EN), }, @@ -145,7 +139,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT2 | BYT_RT5640_JACK_BP_CODEC | BYT_RT5640_MCLK_EN), }, @@ -158,7 +151,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT2 | BYT_RT5640_JACK_BP_CODEC | BYT_RT5640_MCLK_EN), }, @@ -171,7 +163,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT2 | BYT_RT5640_JACK_BP_CODEC | BYT_RT5640_MCLK_EN), }, @@ -184,7 +175,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT2 | BYT_RT5640_JACK_BP_CODEC | BYT_RT5640_MCLK_EN), }, @@ -197,7 +187,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN), }, @@ -210,7 +199,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT2 | BYT_RT5640_JACK_BP_CODEC | BYT_RT5640_MCLK_EN), }, @@ -224,7 +212,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN), }, @@ -237,7 +224,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN), }, @@ -250,7 +236,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN), }, @@ -263,7 +248,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN), }, @@ -276,7 +260,6 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = { .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | BYT_RT5640_JACK_DET_EN | BYT_RT5640_JACK_ACTIVE_LOW | - BYT_RT5640_JACK_INT1 | BYT_RT5640_JACK_BP_MICBIAS | BYT_RT5640_MCLK_EN), }, diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c index 9ae79e96aef72c..fe2f41a4e909cb 100644 --- a/sound/soc/intel/boards/bytcr_rt5640.c +++ b/sound/soc/intel/boards/bytcr_rt5640.c @@ -45,11 +45,6 @@ #define RT5640_GPIO_NA -1 -enum jack_int_select { - JACK_INT1, /* AUDIO_INT */ - JACK_INT2, /* JACK_DET */ -}; - enum jack_bp_select { JACK_BP_CODEC, JACK_BP_MICBIAS, @@ -76,7 +71,6 @@ struct byt_drvdata { struct snd_soc_codec *codec; int jack_active_low; - enum jack_int_select jack_int_sel; enum jack_bp_select jack_bp_sel; struct snd_soc_jack jack; @@ -262,7 +256,7 @@ static inline bool byt_hs_inserted(struct byt_drvdata *drvdata) const struct gpio_desc *desc; int gpio; - if (drvdata->jack_int_sel == JACK_INT1) + if (drvdata->jack_bp_sel == JACK_BP_MICBIAS) gpio = drvdata->gpios.jd_int_gpio; else /* JACK_INT2 */ gpio = drvdata->gpios.jd_int2_gpio; @@ -273,9 +267,9 @@ static inline bool byt_hs_inserted(struct byt_drvdata *drvdata) if (drvdata->jack_active_low) val = !val; - pr_info("%s: val = %d (pin = %d, active_low = %d, jack_int_sel = %d)\n", + pr_info("%s: val = %d (pin = %d, active_low = %d, jack_bp_sel = %d)\n", __func__, val, gpio, drvdata->jack_active_low, - drvdata->jack_int_sel); + drvdata->jack_bp_sel); return val; } @@ -381,8 +375,7 @@ static bool byt_jack_check(struct byt_drvdata *drvdata, bool is_recheck, } else if (status == RT5640_HEADSET_DET) { pr_info("%s: Headset present.\n", __func__); byt_set_mic_bias_ldo(codec, true); - if (drvdata->jack_bp_sel == - JACK_BP_CODEC) + if (drvdata->jack_bp_sel == JACK_BP_CODEC) rt5640_enable_ovcd_interrupt(codec, true); jack->status |= SND_JACK_HEADSET; @@ -398,8 +391,7 @@ static bool byt_jack_check(struct byt_drvdata *drvdata, bool is_recheck, jack->status &= ~SND_JACK_HEADSET; changed = true; byt_set_mic_bias_ldo(codec, false); - if (drvdata->jack_bp_sel == - JACK_BP_CODEC) + if (drvdata->jack_bp_sel == JACK_BP_CODEC) rt5640_enable_ovcd_interrupt(codec, false); pr_info("%s: Headset removed.\n", __func__); @@ -431,7 +423,7 @@ static void byt_jack_recheck(struct work_struct *work) } /* Interrupt on micbias (JACK_DET_BAK/HOOK_INT) */ -static int byt_micbias_interrupt(void *data) +static int byt_bp_detection_interrupt(void *data) { struct byt_drvdata *drvdata = (struct byt_drvdata *)data; struct snd_soc_jack *jack = &drvdata->jack; @@ -451,18 +443,12 @@ static int byt_micbias_interrupt(void *data) return jack->status; } -/* Interrupt on int2 (JACK_DET) */ -static int byt_jack_int2_interrupt(void *data) +/* Jack detection Interrupt */ +static int byt_jack_detection_interrupt(void *data) { struct byt_drvdata *drvdata = (struct byt_drvdata *)data; struct snd_soc_jack *jack = &drvdata->jack; - if ((drvdata->jack_bp_sel == JACK_BP_MICBIAS) && - (drvdata->jack_int_sel == JACK_INT1)) { - pr_debug("%s: INT2 not used. Returning...\n", __func__); - return jack->status; - } - mutex_lock(&drvdata->jack_mlock); pr_debug("%s: Enter (jack->status = %d).\n", __func__, jack->status); @@ -471,47 +457,12 @@ static int byt_jack_int2_interrupt(void *data) if (cancel_delayed_work_sync(&drvdata->jack_recheck)) pr_debug("%s: jack-recheck interrupted!\n", __func__); - /* Check for jack-events */ byt_jack_check(drvdata, false, false); mutex_unlock(&drvdata->jack_mlock); return jack->status; } -/* Interrupt on int1 (AUDIO_INT) */ -static int byt_jack_int1_interrupt(void *data) -{ - struct byt_drvdata *drvdata = (struct byt_drvdata *)data; - struct snd_soc_jack *jack = &drvdata->jack; - - if ((drvdata->jack_bp_sel == JACK_BP_MICBIAS) && - (drvdata->jack_int_sel == JACK_INT2)) { - pr_debug("%s: INT1 not used. Returning...\n", __func__); - return jack->status; - } - - mutex_lock(&drvdata->jack_mlock); - pr_debug("%s: Enter (jack->status = %d).\n", __func__, jack->status); - - if (cancel_delayed_work_sync(&drvdata->bp_recheck)) - pr_debug("%s: bp-recheck interrupted!\n", __func__); - if (drvdata->jack_bp_sel == JACK_BP_MICBIAS) - if (cancel_delayed_work_sync(&drvdata->jack_recheck)) - pr_debug("%s: jack-recheck interrupted!\n", __func__); - - /* Check for button-events if a headset is present (codec-mode only) */ - if (drvdata->jack_bp_sel == JACK_BP_CODEC) { - if (jack->status & SND_JACK_MICROPHONE) - if (byt_bp_check(drvdata, false)) - snd_soc_jack_report(jack, jack->status, - SND_JACK_BTN_0); - } else /* In micbias-mode we use int1 for jack-check */ - byt_jack_check(drvdata, false, false); - - mutex_unlock(&drvdata->jack_mlock); - return jack->status; -} - static void byt_export_gpio(struct gpio_desc *desc, char *name) { int ret = gpiod_export(desc, true); @@ -557,6 +508,7 @@ static void byt_init_gpios(struct snd_soc_codec *codec, pr_warn("%s: GPIOs - JD-int2: Not present!\n", __func__); } + /* this GPIO is used for MICBIAS button detection */ desc = devm_gpiod_get_index(codec->dev, NULL, RT5640_GPIO_JD_BUTTONS, GPIOD_ASIS); if (!IS_ERR(desc)) { drvdata->gpios.jd_buttons_gpio = desc_to_gpio(desc); @@ -601,95 +553,81 @@ static void byt_init_gpios(struct snd_soc_codec *codec, static struct snd_soc_jack_gpio jack_gpio_int1[] = { { .name = "byt-int1-int", - .report = 0, /* Set dynamically */ .debounce_time = BYT_JD_INTR_DEBOUNCE, - .jack_status_check = byt_jack_int1_interrupt, }, }; static struct snd_soc_jack_gpio jack_gpio_int2[] = { {/*jack detection*/ .name = "byt-int2-int", - .report = SND_JACK_HEADSET, .debounce_time = BYT_JD_INTR_DEBOUNCE, - .jack_status_check = byt_jack_int2_interrupt, }, }; -static struct snd_soc_jack_gpio jack_gpio_micbias[] = { - { - .name = "byt-micbias-int", - .report = SND_JACK_BTN_0, - .debounce_time = BYT_JD_INTR_DEBOUNCE, - .jack_status_check = byt_micbias_interrupt, - }, -}; static int byt_config_jack_gpios(struct byt_drvdata *drvdata) { - int int_sel = drvdata->jack_int_sel; int bp_sel = drvdata->jack_bp_sel; int int1_gpio = drvdata->gpios.jd_int_gpio; int int2_gpio = drvdata->gpios.jd_int2_gpio; int bp_gpio = drvdata->gpios.jd_buttons_gpio; - - pr_info("%s: Jack-GPIO config: jack_bp_sel = %d, jack_int_sel = %d\n", - __func__, bp_sel, int_sel); - - if ((bp_sel == JACK_BP_CODEC) && (int_sel == JACK_INT1)) { - pr_err("%s: Unsupported jack-config (jack_bp_sel = %d, jack_int_sel = %d)!\n", - __func__, JACK_BP_CODEC, JACK_INT1); - return -EINVAL; - } - - if ((bp_sel == JACK_BP_MICBIAS) && (bp_gpio == RT5640_GPIO_NA)) { - pr_err("%s: Micbias-GPIO missing (jack_bp_sel = %d, jack_int_sel = %d)!\n", - __func__, JACK_BP_MICBIAS, int_sel); - return -EINVAL; - } - - if (((int_sel == JACK_INT1) && (int1_gpio == RT5640_GPIO_NA)) || - ((int_sel == JACK_INT2) && (int2_gpio == RT5640_GPIO_NA))) { - pr_err("%s: Missing jack-GPIO (jack_bp_sel = %d, jack_int_sel = %d, )\n", - __func__, bp_sel, int_sel); - return -EINVAL; + bool int1_en = false; + bool int2_en = false; + + pr_info("%s: Jack-GPIO config: jack_bp_sel = %s\n", + __func__, (bp_sel == JACK_BP_MICBIAS)? "MICBIAS" : "CODEC"); + + /* int1 is always used depending the configuration of button detecion */ + jack_gpio_int1[0].gpio = int1_gpio; + jack_gpio_int1[0].data = drvdata; + if (bp_sel == JACK_BP_MICBIAS) { /* int1 is used for jack detection */ + jack_gpio_int1[0].report = SND_JACK_HEADSET; + jack_gpio_int1[0].jack_status_check = byt_jack_detection_interrupt; + int1_en = true; + } else { /* int1 is used for button */ + if (byt_rt5640_quirk & BYT_RT5640_JACK_BP_EN) { + jack_gpio_int1[0].report = SND_JACK_BTN_0; + jack_gpio_int1[0].jack_status_check = byt_bp_detection_interrupt; + int1_en = true; + } } - - if ((int_sel == JACK_INT1) || - (bp_sel == JACK_BP_CODEC && (byt_rt5640_quirk & BYT_RT5640_JACK_BP_EN))) { - - jack_gpio_int1[0].gpio = int1_gpio; - jack_gpio_int1[0].data = drvdata; - jack_gpio_int1[0].report = (int_sel == JACK_INT1) ? - SND_JACK_HEADSET : SND_JACK_BTN_0; - pr_err("%s: Add jack-GPIO 1 (%d).\n", __func__, int1_gpio); - if (snd_soc_jack_add_gpios(&drvdata->jack, 1, - &jack_gpio_int1[0])) { - pr_err("%s: Failed to add jack-GPIO 1!\n", __func__); - return -EIO; + /* setting int2 */ + jack_gpio_int2[0].data = drvdata; + if (bp_sel == JACK_BP_MICBIAS) { /* int2 is for bp micbias */ + if (byt_rt5640_quirk & BYT_RT5640_JACK_BP_EN) { + jack_gpio_int2[0].gpio = bp_gpio; /*this is micbias GPIO */ + jack_gpio_int2[0].report = SND_JACK_BTN_0; + jack_gpio_int2[0].jack_status_check = byt_bp_detection_interrupt; + int2_en = true; } - } - if (int_sel == JACK_INT2) { + } else { jack_gpio_int2[0].gpio = int2_gpio; - jack_gpio_int2[0].data = drvdata; - pr_err("%s: Add jack-GPIO 2 (%d).\n", __func__, int2_gpio); + jack_gpio_int2[0].report = SND_JACK_HEADSET; + jack_gpio_int2[0].jack_status_check = byt_jack_detection_interrupt; + int2_en = true; + } + + /* adding gpios */ + if (int1_en) { if (snd_soc_jack_add_gpios(&drvdata->jack, 1, - &jack_gpio_int2[0])) { - pr_err("%s: Failed to add jack-GPIO 2!\n", __func__); + &jack_gpio_int1[0])) { + pr_err("%s: Failed to add jack-GPIO %d!\n", __func__, jack_gpio_int1[0].gpio); return -EIO; - } + } else + pr_info("%s: Add jack-GPIO %d (%s).\n", __func__, jack_gpio_int1[0].gpio, + (bp_sel == JACK_BP_MICBIAS) ? "jack detection" : "button detection"); } - if ((byt_rt5640_quirk & BYT_RT5640_JACK_BP_EN) && bp_sel == JACK_BP_MICBIAS) { - jack_gpio_micbias[0].gpio = bp_gpio; - jack_gpio_micbias[0].data = drvdata; - pr_debug("%s: Add micbias-GPIO (%d).\n", __func__, bp_gpio); + + if (int2_en) { if (snd_soc_jack_add_gpios(&drvdata->jack, 1, - &jack_gpio_micbias[0])) { - pr_err("%s: Failed to add micbias-GPIO!\n", __func__); + &jack_gpio_int2[0])) { + pr_err("%s: Failed to add jack-GPIO %d!\n", __func__, jack_gpio_int2[0].gpio); return -EIO; - } + } else + pr_err("%s: Add jack-GPIO %d (%s).\n", __func__, jack_gpio_int2[0].gpio, + (bp_sel == JACK_BP_MICBIAS) ? "button detection" : "jack detection"); } return 0; @@ -1092,11 +1030,6 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) else drvdata->jack_active_low = 0; - if (byt_rt5640_quirk & BYT_RT5640_JACK_INT1) - drvdata->jack_int_sel = JACK_INT1; - else - drvdata->jack_int_sel = JACK_INT2; - if (byt_rt5640_quirk & BYT_RT5640_JACK_BP_CODEC) drvdata->jack_bp_sel = JACK_BP_CODEC; else