From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <[email protected]>
---
sound/soc/codecs/rt5645.c | 161 +++++++++++++++++++-------------------
1 file changed, 80 insertions(+), 81 deletions(-)
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 8a9af260e5f7..4a74b90bd3f6 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -3325,93 +3325,92 @@ static void rt5645_jack_detect_work(struct work_struct *work)
if (!rt5645->component)
return;
- mutex_lock(&rt5645->jd_mutex);
-
- switch (rt5645->pdata.jd_mode) {
- case 0: /* Not using rt5645 JD */
- if (rt5645->gpiod_hp_det) {
- gpio_state = gpiod_get_value(rt5645->gpiod_hp_det);
- if (rt5645->pdata.inv_hp_pol)
- gpio_state ^= 1;
- dev_dbg(rt5645->component->dev, "gpio_state = %d\n",
- gpio_state);
- report = rt5645_jack_detect(rt5645->component, gpio_state);
- }
- snd_soc_jack_report(rt5645->hp_jack,
- report, SND_JACK_HEADPHONE);
- snd_soc_jack_report(rt5645->mic_jack,
- report, SND_JACK_MICROPHONE);
- mutex_unlock(&rt5645->jd_mutex);
- return;
- case 4:
- val = snd_soc_component_read(rt5645->component, RT5645_A_JD_CTRL1) & 0x0020;
- break;
- default: /* read rt5645 jd1_1 status */
- val = snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x1000;
- break;
+ scoped_guard(mutex, &rt5645->jd_mutex) {
+ switch (rt5645->pdata.jd_mode) {
+ case 0: /* Not using rt5645 JD */
+ if (rt5645->gpiod_hp_det) {
+ gpio_state = gpiod_get_value(rt5645->gpiod_hp_det);
+ if (rt5645->pdata.inv_hp_pol)
+ gpio_state ^= 1;
+ dev_dbg(rt5645->component->dev, "gpio_state = %d\n",
+ gpio_state);
+ report = rt5645_jack_detect(rt5645->component, gpio_state);
+ }
+ snd_soc_jack_report(rt5645->hp_jack,
+ report, SND_JACK_HEADPHONE);
+ snd_soc_jack_report(rt5645->mic_jack,
+ report, SND_JACK_MICROPHONE);
+ return;
+ case 4:
+ val = snd_soc_component_read(rt5645->component, RT5645_A_JD_CTRL1) & 0x0020;
+ break;
+ default: /* read rt5645 jd1_1 status */
+ val = snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x1000;
+ break;
- }
+ }
- if (!val && (rt5645->jack_type == 0)) { /* jack in */
- report = rt5645_jack_detect(rt5645->component, 1);
- } else if (!val && rt5645->jack_type == SND_JACK_HEADSET) {
- /* for push button and jack out */
- btn_type = 0;
- if (snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x4) {
- /* button pressed */
- report = SND_JACK_HEADSET;
- btn_type = rt5645_button_detect(rt5645->component);
- /* rt5650 can report three kinds of button behavior,
- one click, double click and hold. However,
- currently we will report button pressed/released
- event. So all the three button behaviors are
- treated as button pressed. */
- switch (btn_type) {
- case 0x8000:
- case 0x4000:
- case 0x2000:
- report |= SND_JACK_BTN_0;
- break;
- case 0x1000:
- case 0x0800:
- case 0x0400:
- report |= SND_JACK_BTN_1;
- break;
- case 0x0200:
- case 0x0100:
- case 0x0080:
- report |= SND_JACK_BTN_2;
- break;
- case 0x0040:
- case 0x0020:
- case 0x0010:
- report |= SND_JACK_BTN_3;
- break;
- case 0x0000: /* unpressed */
- break;
- default:
- dev_err(rt5645->component->dev,
- "Unexpected button code 0x%04x\n",
- btn_type);
- break;
+ if (!val && (rt5645->jack_type == 0)) { /* jack in */
+ report = rt5645_jack_detect(rt5645->component, 1);
+ } else if (!val && rt5645->jack_type == SND_JACK_HEADSET) {
+ /* for push button and jack out */
+ btn_type = 0;
+ if (snd_soc_component_read(rt5645->component, RT5645_INT_IRQ_ST) & 0x4) {
+ /* button pressed */
+ report = SND_JACK_HEADSET;
+ btn_type = rt5645_button_detect(rt5645->component);
+ /*
+ * rt5650 can report three kinds of button behavior,
+ * one click, double click and hold. However,
+ * currently we will report button pressed/released
+ * event. So all the three button behaviors are
+ * treated as button pressed.
+ */
+ switch (btn_type) {
+ case 0x8000:
+ case 0x4000:
+ case 0x2000:
+ report |= SND_JACK_BTN_0;
+ break;
+ case 0x1000:
+ case 0x0800:
+ case 0x0400:
+ report |= SND_JACK_BTN_1;
+ break;
+ case 0x0200:
+ case 0x0100:
+ case 0x0080:
+ report |= SND_JACK_BTN_2;
+ break;
+ case 0x0040:
+ case 0x0020:
+ case 0x0010:
+ report |= SND_JACK_BTN_3;
+ break;
+ case 0x0000: /* unpressed */
+ break;
+ default:
+ dev_err(rt5645->component->dev,
+ "Unexpected button code 0x%04x\n",
+ btn_type);
+ break;
+ }
}
+ if (btn_type == 0)/* button release */
+ report = rt5645->jack_type;
+ else {
+ mod_timer(&rt5645->btn_check_timer,
+ msecs_to_jiffies(100));
+ }
+ } else {
+ /* jack out */
+ report = 0;
+ snd_soc_component_update_bits(rt5645->component,
+ RT5645_INT_IRQ_ST, 0x1, 0x0);
+ rt5645_jack_detect(rt5645->component, 0);
}
- if (btn_type == 0)/* button release */
- report = rt5645->jack_type;
- else {
- mod_timer(&rt5645->btn_check_timer,
- msecs_to_jiffies(100));
- }
- } else {
- /* jack out */
- report = 0;
- snd_soc_component_update_bits(rt5645->component,
- RT5645_INT_IRQ_ST, 0x1, 0x0);
- rt5645_jack_detect(rt5645->component, 0);
}
- mutex_unlock(&rt5645->jd_mutex);
-
snd_soc_jack_report(rt5645->hp_jack, report, SND_JACK_HEADPHONE);
snd_soc_jack_report(rt5645->mic_jack, report, SND_JACK_MICROPHONE);
if (rt5645->en_button_func)
--
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.