diff --git a/sound/soc/codecs/wcd9xxx-mbhc.c b/sound/soc/codecs/wcd9xxx-mbhc.c index 852956bdcb57..03eb02d6a4da 100644 --- a/sound/soc/codecs/wcd9xxx-mbhc.c +++ b/sound/soc/codecs/wcd9xxx-mbhc.c @@ -4536,6 +4536,64 @@ static void wcd9xxx_cleanup_debugfs(struct wcd9xxx_mbhc *mbhc) } #endif +int wcd9xxx_mbhc_set_keycode(struct wcd9xxx_mbhc *mbhc) +{ + enum snd_jack_types type; + int i, ret, result = 0; + int *btn_key_code; + + btn_key_code = mbhc->mbhc_cfg->key_code; + + for (i = 0 ; i < 8 ; i++) { + if (btn_key_code[i] != 0) { + switch (i) { + case 0: + type = SND_JACK_BTN_0; + break; + case 1: + type = SND_JACK_BTN_1; + break; + case 2: + type = SND_JACK_BTN_2; + break; + case 3: + type = SND_JACK_BTN_3; + break; + case 4: + type = SND_JACK_BTN_4; + break; + case 5: + type = SND_JACK_BTN_5; + break; + case 6: + type = SND_JACK_BTN_6; + break; + case 7: + type = SND_JACK_BTN_7; + break; + default: + WARN_ONCE(1, "Wrong button number:%d\n", i); + result = -1; + break; + } + ret = snd_jack_set_key(mbhc->button_jack.jack, + type, + btn_key_code[i]); + if (ret) { + pr_err("%s: Failed to set code for %d\n", + __func__, btn_key_code[i]); + result = -1; + } + input_set_capability( + mbhc->button_jack.jack->input_dev, + EV_KEY, btn_key_code[i]); + pr_debug("%s: set btn%d key code:%d\n", __func__, + i, btn_key_code[i]); + } + } + return result; +} + int wcd9xxx_mbhc_start(struct wcd9xxx_mbhc *mbhc, struct wcd9xxx_mbhc_config *mbhc_cfg) { @@ -4559,6 +4617,10 @@ int wcd9xxx_mbhc_start(struct wcd9xxx_mbhc *mbhc, /* Save mbhc config */ mbhc->mbhc_cfg = mbhc_cfg; + /* Set btn key code */ + if (wcd9xxx_mbhc_set_keycode(mbhc)) + pr_err("Set btn key code error!!!\n"); + /* Get HW specific mbhc registers' address */ wcd9xxx_get_mbhc_micbias_regs(mbhc, MBHC_PRIMARY_MIC_MB); diff --git a/sound/soc/codecs/wcd9xxx-mbhc.h b/sound/soc/codecs/wcd9xxx-mbhc.h index 4eab53a39916..11a4d1d56f61 100644 --- a/sound/soc/codecs/wcd9xxx-mbhc.h +++ b/sound/soc/codecs/wcd9xxx-mbhc.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -275,6 +275,7 @@ struct wcd9xxx_mbhc_config { bool use_vddio_meas; bool enable_anc_mic_detect; enum hw_jack_type hw_jack_type; + int key_code[8]; }; struct wcd9xxx_cfilt_mode { @@ -470,6 +471,7 @@ struct wcd9xxx_mbhc { (cfg_ptr->_n_rload * \ (sizeof(cfg_ptr->_rload[0]) + sizeof(cfg_ptr->_alpha[0])))) +int wcd9xxx_mbhc_set_keycode(struct wcd9xxx_mbhc *mbhc); int wcd9xxx_mbhc_start(struct wcd9xxx_mbhc *mbhc, struct wcd9xxx_mbhc_config *mbhc_cfg); void wcd9xxx_mbhc_stop(struct wcd9xxx_mbhc *mbhc);