Commit ac40b4d1 authored by Vaibhav Agarwal's avatar Vaibhav Agarwal Committed by Greg Kroah-Hartman

staging: greybus: audio: Maintain jack list within GB Audio module

As per the current implementation for GB codec driver, a jack list is
maintained for each module. And it expects the list to be populated by
the snd_soc_jack structure which would require modifications in
mainstream code.

However, this is not a necessary requirement and the list can be easily
maintained within gbaudio_module_info as well. This patch provides the
relevant changes for the same.
Signed-off-by: default avatarVaibhav Agarwal <vaibhav.sr@gmail.com>
Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/4ee030af7a8e203f89a6e513313e36f4e2991e5b.1594290158.git.vaibhav.sr@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b503aef3
...@@ -712,6 +712,7 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, ...@@ -712,6 +712,7 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module,
struct snd_soc_card *card) struct snd_soc_card *card)
{ {
int ret; int ret;
struct gbaudio_jack *jack, *n;
struct snd_soc_jack_pin *headset, *button; struct snd_soc_jack_pin *headset, *button;
if (!module->jack_mask) if (!module->jack_mask)
...@@ -726,14 +727,16 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, ...@@ -726,14 +727,16 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module,
headset->pin = module->jack_name; headset->pin = module->jack_name;
headset->mask = module->jack_mask; headset->mask = module->jack_mask;
ret = snd_soc_card_jack_new(card, module->jack_name, module->jack_mask, ret = snd_soc_card_jack_new(card, module->jack_name, module->jack_mask,
&module->headset_jack, headset, 1); &module->headset.jack, headset, 1);
if (ret) { if (ret) {
dev_err(module->dev, "Failed to create new jack\n"); dev_err(module->dev, "Failed to create new jack\n");
return ret; return ret;
} }
/* Add to module's jack list */
list_add(&module->headset.list, &module->jack_list);
if (!module->button_mask) if (!module->button_mask)
return 0; return 0;
...@@ -742,20 +745,22 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, ...@@ -742,20 +745,22 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module,
button = devm_kzalloc(module->dev, sizeof(*button), GFP_KERNEL); button = devm_kzalloc(module->dev, sizeof(*button), GFP_KERNEL);
if (!button) { if (!button) {
ret = -ENOMEM; ret = -ENOMEM;
goto free_headset; goto free_jacks;
} }
button->pin = module->button_name; button->pin = module->button_name;
button->mask = module->button_mask; button->mask = module->button_mask;
ret = snd_soc_card_jack_new(card, module->button_name, ret = snd_soc_card_jack_new(card, module->button_name,
module->button_mask, &module->button_jack, module->button_mask, &module->button.jack,
button, 1); button, 1);
if (ret) { if (ret) {
dev_err(module->dev, "Failed to create button jack\n"); dev_err(module->dev, "Failed to create button jack\n");
goto free_headset; goto free_jacks;
} }
/* Add to module's jack list */
list_add(&module->button.list, &module->jack_list);
/* /*
* Currently, max 4 buttons are supported with following key mapping * Currently, max 4 buttons are supported with following key mapping
* BTN_0 = KEY_MEDIA * BTN_0 = KEY_MEDIA
...@@ -765,56 +770,54 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, ...@@ -765,56 +770,54 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module,
*/ */
if (module->button_mask & SND_JACK_BTN_0) { if (module->button_mask & SND_JACK_BTN_0) {
ret = snd_jack_set_key(module->button_jack.jack, SND_JACK_BTN_0, ret = snd_jack_set_key(module->button.jack.jack, SND_JACK_BTN_0,
KEY_MEDIA); KEY_MEDIA);
if (ret) { if (ret) {
dev_err(module->dev, "Failed to set BTN_0\n"); dev_err(module->dev, "Failed to set BTN_0\n");
goto free_button; goto free_jacks;
} }
} }
if (module->button_mask & SND_JACK_BTN_1) { if (module->button_mask & SND_JACK_BTN_1) {
ret = snd_jack_set_key(module->button_jack.jack, SND_JACK_BTN_1, ret = snd_jack_set_key(module->button.jack.jack, SND_JACK_BTN_1,
KEY_VOICECOMMAND); KEY_VOICECOMMAND);
if (ret) { if (ret) {
dev_err(module->dev, "Failed to set BTN_1\n"); dev_err(module->dev, "Failed to set BTN_1\n");
goto free_button; goto free_jacks;
} }
} }
if (module->button_mask & SND_JACK_BTN_2) { if (module->button_mask & SND_JACK_BTN_2) {
ret = snd_jack_set_key(module->button_jack.jack, SND_JACK_BTN_2, ret = snd_jack_set_key(module->button.jack.jack, SND_JACK_BTN_2,
KEY_VOLUMEUP); KEY_VOLUMEUP);
if (ret) { if (ret) {
dev_err(module->dev, "Failed to set BTN_2\n"); dev_err(module->dev, "Failed to set BTN_2\n");
goto free_button; goto free_jacks;
} }
} }
if (module->button_mask & SND_JACK_BTN_3) { if (module->button_mask & SND_JACK_BTN_3) {
ret = snd_jack_set_key(module->button_jack.jack, SND_JACK_BTN_3, ret = snd_jack_set_key(module->button.jack.jack, SND_JACK_BTN_3,
KEY_VOLUMEDOWN); KEY_VOLUMEDOWN);
if (ret) { if (ret) {
dev_err(module->dev, "Failed to set BTN_0\n"); dev_err(module->dev, "Failed to set BTN_0\n");
goto free_button; goto free_jacks;
} }
} }
/* FIXME /* FIXME
* verify if this is really required * verify if this is really required
set_bit(INPUT_PROP_NO_DUMMY_RELEASE, set_bit(INPUT_PROP_NO_DUMMY_RELEASE,
module->button_jack.jack->input_dev->propbit); module->button.jack.jack->input_dev->propbit);
*/ */
return 0; return 0;
free_button: free_jacks:
snd_device_free(card->snd_card, module->button_jack.jack); list_for_each_entry_safe(jack, n, &module->jack_list, list) {
list_del(&module->button_jack.list); snd_device_free(card->snd_card, jack->jack.jack);
list_del(&jack->list);
free_headset: }
snd_device_free(card->snd_card, module->headset_jack.jack);
list_del(&module->headset_jack.list);
return ret; return ret;
} }
...@@ -824,7 +827,7 @@ int gbaudio_register_module(struct gbaudio_module_info *module) ...@@ -824,7 +827,7 @@ int gbaudio_register_module(struct gbaudio_module_info *module)
int ret; int ret;
struct snd_soc_codec *codec; struct snd_soc_codec *codec;
struct snd_card *card; struct snd_card *card;
struct snd_soc_jack *jack = NULL; struct gbaudio_jack *jack = NULL;
if (!gbcodec) { if (!gbcodec) {
dev_err(module->dev, "GB Codec not yet probed\n"); dev_err(module->dev, "GB Codec not yet probed\n");
...@@ -869,11 +872,9 @@ int gbaudio_register_module(struct gbaudio_module_info *module) ...@@ -869,11 +872,9 @@ int gbaudio_register_module(struct gbaudio_module_info *module)
* register jack devices for this module * register jack devices for this module
* from codec->jack_list * from codec->jack_list
*/ */
list_for_each_entry(jack, &codec->jack_list, list) { list_for_each_entry(jack, &module->jack_list, list) {
if ((jack == &module->headset_jack) ||
(jack == &module->button_jack))
snd_device_register(codec->card->snd_card, snd_device_register(codec->card->snd_card,
jack->jack); jack->jack.jack);
} }
#endif #endif
} }
...@@ -957,7 +958,7 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module) ...@@ -957,7 +958,7 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module)
{ {
struct snd_soc_codec *codec = gbcodec->codec; struct snd_soc_codec *codec = gbcodec->codec;
struct snd_card *card = codec->card->snd_card; struct snd_card *card = codec->card->snd_card;
struct snd_soc_jack *jack, *next_j; struct gbaudio_jack *jack, *n;
int mask; int mask;
dev_dbg(codec->dev, "Unregister %s module\n", module->name); dev_dbg(codec->dev, "Unregister %s module\n", module->name);
...@@ -970,20 +971,19 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module) ...@@ -970,20 +971,19 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module)
mutex_unlock(&gbcodec->lock); mutex_unlock(&gbcodec->lock);
#ifdef CONFIG_SND_JACK #ifdef CONFIG_SND_JACK
/* free jack devices for this module from codec->jack_list */ /* free jack devices for this module jack_list */
list_for_each_entry_safe(jack, next_j, &component->card->jack_list, list_for_each_entry_safe(jack, n, &module->jack_list, list) {
list) { if (jack == &module->headset)
if (jack == &module->headset_jack)
mask = GBCODEC_JACK_MASK; mask = GBCODEC_JACK_MASK;
else if (jack == &module->button_jack) else if (jack == &module->button)
mask = GBCODEC_JACK_BUTTON_MASK; mask = GBCODEC_JACK_BUTTON_MASK;
else else
mask = 0; mask = 0;
if (mask) { if (mask) {
dev_dbg(module->dev, "Report %s removal\n", dev_dbg(module->dev, "Report %s removal\n",
jack->jack->id); jack->jack.jack->id);
snd_soc_jack_report(jack, 0, mask); snd_soc_jack_report(&jack->jack, 0, mask);
snd_device_free(codec->card->snd_card, jack->jack); snd_device_free(codec->card->snd_card, jack->jack.jack);
list_del(&jack->list); list_del(&jack->list);
} }
} }
......
...@@ -106,6 +106,11 @@ enum gbaudio_module_state { ...@@ -106,6 +106,11 @@ enum gbaudio_module_state {
GBAUDIO_MODULE_ON, GBAUDIO_MODULE_ON,
}; };
struct gbaudio_jack {
struct snd_soc_jack jack;
struct list_head list;
};
struct gbaudio_module_info { struct gbaudio_module_info {
/* module info */ /* module info */
struct device *dev; struct device *dev;
...@@ -130,8 +135,8 @@ struct gbaudio_module_info { ...@@ -130,8 +135,8 @@ struct gbaudio_module_info {
int jack_mask; int jack_mask;
int button_mask; int button_mask;
int button_status; int button_status;
struct snd_soc_jack headset_jack; struct gbaudio_jack headset;
struct snd_soc_jack button_jack; struct gbaudio_jack button;
/* connection info */ /* connection info */
struct gb_connection *mgmt_connection; struct gb_connection *mgmt_connection;
...@@ -155,6 +160,7 @@ struct gbaudio_module_info { ...@@ -155,6 +160,7 @@ struct gbaudio_module_info {
struct list_head widget_list; struct list_head widget_list;
struct list_head ctl_list; struct list_head ctl_list;
struct list_head widget_ctl_list; struct list_head widget_ctl_list;
struct list_head jack_list;
struct gb_audio_topology *topology; struct gb_audio_topology *topology;
}; };
......
...@@ -21,8 +21,8 @@ static int gbaudio_request_jack(struct gbaudio_module_info *module, ...@@ -21,8 +21,8 @@ static int gbaudio_request_jack(struct gbaudio_module_info *module,
struct gb_audio_jack_event_request *req) struct gb_audio_jack_event_request *req)
{ {
int report; int report;
struct snd_jack *jack = module->headset_jack.jack; struct snd_jack *jack = module->headset.jack.jack;
struct snd_jack *btn_jack = module->button_jack.jack; struct snd_jack *btn_jack = module->button.jack.jack;
if (!jack) { if (!jack) {
dev_err_ratelimited(module->dev, dev_err_ratelimited(module->dev,
...@@ -38,11 +38,11 @@ static int gbaudio_request_jack(struct gbaudio_module_info *module, ...@@ -38,11 +38,11 @@ static int gbaudio_request_jack(struct gbaudio_module_info *module,
if (req->event == GB_AUDIO_JACK_EVENT_REMOVAL) { if (req->event == GB_AUDIO_JACK_EVENT_REMOVAL) {
module->jack_type = 0; module->jack_type = 0;
if (btn_jack && module->button_status) { if (btn_jack && module->button_status) {
snd_soc_jack_report(&module->button_jack, 0, snd_soc_jack_report(&module->button.jack, 0,
module->button_mask); module->button_mask);
module->button_status = 0; module->button_status = 0;
} }
snd_soc_jack_report(&module->headset_jack, 0, snd_soc_jack_report(&module->headset.jack, 0,
module->jack_mask); module->jack_mask);
return 0; return 0;
} }
...@@ -61,7 +61,7 @@ static int gbaudio_request_jack(struct gbaudio_module_info *module, ...@@ -61,7 +61,7 @@ static int gbaudio_request_jack(struct gbaudio_module_info *module,
module->jack_type, report); module->jack_type, report);
module->jack_type = report; module->jack_type = report;
snd_soc_jack_report(&module->headset_jack, report, module->jack_mask); snd_soc_jack_report(&module->headset.jack, report, module->jack_mask);
return 0; return 0;
} }
...@@ -70,7 +70,7 @@ static int gbaudio_request_button(struct gbaudio_module_info *module, ...@@ -70,7 +70,7 @@ static int gbaudio_request_button(struct gbaudio_module_info *module,
struct gb_audio_button_event_request *req) struct gb_audio_button_event_request *req)
{ {
int soc_button_id, report; int soc_button_id, report;
struct snd_jack *btn_jack = module->button_jack.jack; struct snd_jack *btn_jack = module->button.jack.jack;
if (!btn_jack) { if (!btn_jack) {
dev_err_ratelimited(module->dev, dev_err_ratelimited(module->dev,
...@@ -124,7 +124,7 @@ static int gbaudio_request_button(struct gbaudio_module_info *module, ...@@ -124,7 +124,7 @@ static int gbaudio_request_button(struct gbaudio_module_info *module,
module->button_status = report; module->button_status = report;
snd_soc_jack_report(&module->button_jack, report, module->button_mask); snd_soc_jack_report(&module->button.jack, report, module->button_mask);
return 0; return 0;
} }
...@@ -258,6 +258,7 @@ static int gb_audio_probe(struct gb_bundle *bundle, ...@@ -258,6 +258,7 @@ static int gb_audio_probe(struct gb_bundle *bundle,
INIT_LIST_HEAD(&gbmodule->widget_list); INIT_LIST_HEAD(&gbmodule->widget_list);
INIT_LIST_HEAD(&gbmodule->ctl_list); INIT_LIST_HEAD(&gbmodule->ctl_list);
INIT_LIST_HEAD(&gbmodule->widget_ctl_list); INIT_LIST_HEAD(&gbmodule->widget_ctl_list);
INIT_LIST_HEAD(&gbmodule->jack_list);
gbmodule->dev = dev; gbmodule->dev = dev;
snprintf(gbmodule->name, NAME_SIZE, "%s.%s", dev->driver->name, snprintf(gbmodule->name, NAME_SIZE, "%s.%s", dev->driver->name,
dev_name(dev)); dev_name(dev));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment