Skip to contentSkip to conversation

OMAPDSS: hdmi: Reconfigure and restart audio when display is enabled

PATCH Superseded Jyri Sarha 2 participants 4 messages Aug 28, 2015

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jyri Sarha

author
#0 lore raw

PATCH v2 1/1 OMAPDSS: hdmi: Reconfigure and restart audio when display is enabled

Reconfigure and restart audio when display is enabled, if audio playback was active before. The audio configuration is stored when is is successfully applied and a boolean is set when playback has started and unset when stopped. This data is used to reconfigure the audio when display is re-enabled. Abort audio playback if reconfiguration fails.

A new spin lock is introduced in order to protect state variables related to audio playback status. This is needed for the transitions from display enabled state (when audio start/stop commands can be written to HW) to display disabled state (when audio start/stop commands update only the hdmi.audio_playing variable) to always serialize correctly with the start/stop audio commands.

For example: when display is turned back on we take the spinlock and we can be sure that the audio start/stop status won't change while we update the HW according to hdmi.audio_playing state and set hdmi.display_enabled to true. After releasing the lock hdmi.display_enabled is true and all audio_start and audio_stop commands write their stuff directly to HW.

---
I dropped the ASoC maintainers from the recipient list as this patch hardly concerns them.

 drivers/video/fbdev/omap2/dss/hdmi.h  |  9 +++-
 drivers/video/fbdev/omap2/dss/hdmi4.c | 69 +++++++++++++++++++++++++-----
 drivers/video/fbdev/omap2/dss/hdmi5.c | 79 ++++++++++++++++++++++++++++-------
 3 files changed, 130 insertions(+), 27 deletions(-)
drivers/video/fbdev/omap2/dss/hdmi.h +8 -1
index e4a32fe..e48aefd 100644
@@ -351,13 +351,20 @@ struct omap_hdmi {
 	struct regulator *vdda_reg;
 
 	bool core_enabled;
-	bool display_enabled;
 
 	struct omap_dss_device output;
 
 	struct platform_device *audio_pdev;
 	void (*audio_abort_cb)(struct device *dev);
 	int wp_idlemode;
+
+	bool audio_configured;
+	struct omap_dss_audio audio_config;
+
+	/* This lock should be taken when booleas bellow is touched. */
+	spinlock_t audio_playing_lock;
+	bool audio_playing;
+	bool display_enabled;
 };
 
 #endif
drivers/video/fbdev/omap2/dss/hdmi4.c +58 -11

138 lines not on this page · raw message

drivers/video/fbdev/omap2/dss/hdmi5.c +63 -15

155 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#1 lore raw

drivers/video/fbdev/omap2/dss/hdmi4.c out: · line 605

Quoted 13 lines · Jyri Sarha
drivers/video/fbdev/omap2/dss/hdmi4.c +5 -0
@@ -565,9 +594,14 @@ out:
  static int hdmi_audio_shutdown(struct device *dev)
  {
  	struct omap_hdmi *hd = dev_get_drvdata(dev);
+	unsigned long flags;
 
  	mutex_lock(&hd->lock);
  	hd->audio_abort_cb = NULL;
+	hd->audio_configured = false;
+	spin_lock_irqsave(&hd->audio_playing_lock, flags);
+	hd->audio_playing = false;
+	spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
 

BTW, This extra locking (and the corresponding change in hdmi5.c) should not be needed. But it does not harm either. I'll fix that, but I'll wait first if there is anything else fix.

Best regards,
Jyri

#2 lore raw
In reply to Jyri Sarha

Hi,

Quoted 2 lines · Jyri Sarha

Reconfigure and restart audio when display is enabled, if audio playback was active before. The audio configuration is stored when is

'is' -> 'it' above

Quoted 4 lines

is successfully applied and a boolean is set when playback has started and unset when stopped. This data is used to reconfigure the audio when display is re-enabled. Abort audio playback if reconfiguration fails.

It would be good to start the description by telling what the current problem is. And probably the subject could also be better... This fixes the audio playback when a video mode change happens (or such), right?

Quoted 7 lines

A new spin lock is introduced in order to protect state variables related to audio playback status. This is needed for the transitions from display enabled state (when audio start/stop commands can be written to HW) to display disabled state (when audio start/stop commands update only the hdmi.audio_playing variable) to always serialize correctly with the start/stop audio commands.

Quoted 6 lines

For example: when display is turned back on we take the spinlock and we can be sure that the audio start/stop status won't change while we update the HW according to hdmi.audio_playing state and set hdmi.display_enabled to true. After releasing the lock hdmi.display_enabled is true and all audio_start and audio_stop commands write their stuff directly to HW.

The question is (which was my point in the earlier mail), we already have mutex, so why a new spinlock?

I think the answer is that audio start/stop (anything else?) are called in atomic context, so mutex cannot be used.

Also (not exactly related to this patch), if the audio callbacks must be atomic, could we use a workqueue to run the audio start/stop work in non-atomic context? Protecting the whole hdmi state with a single mutex would be much nicer.

Quoted 20 lines

---
I dropped the ASoC maintainers from the recipient list as this patch hardly concerns them.

 drivers/video/fbdev/omap2/dss/hdmi.h  |  9 +++-
 drivers/video/fbdev/omap2/dss/hdmi4.c | 69 +++++++++++++++++++++++++-----
 drivers/video/fbdev/omap2/dss/hdmi5.c | 79 ++++++++++++++++++++++++++++-------
 3 files changed, 130 insertions(+), 27 deletions(-)
drivers/video/fbdev/omap2/dss/hdmi.h +0 -1
index e4a32fe..e48aefd 100644
@@ -351,13 +351,20 @@ struct omap_hdmi {
 	struct regulator *vdda_reg;
 
 	bool core_enabled;
-	bool display_enabled;
 

drivers/video/fbdev/omap2/dss/hdmi.h struct omap_hdmi { · line 364

Quoted 10 lines
drivers/video/fbdev/omap2/dss/hdmi.h +5 -0
 	struct omap_dss_device output;
 
 	struct platform_device *audio_pdev;
 	void (*audio_abort_cb)(struct device *dev);
 	int wp_idlemode;
+
+	bool audio_configured;
+	struct omap_dss_audio audio_config;
+
+	/* This lock should be taken when booleas bellow is touched. */

typo above.

Otherwise, looks much cleaner than the previous one. I tested it and worked fine for me: I could play audio while turning on and off the video output, and the audio would resume, except when the video was off for long enough.

Tomi

author
#3 lore raw

On 08/28/15 16:04, Tomi Valkeinen wrote:
...

Quoted 6 lines

The question is (which was my point in the earlier mail), we already have mutex, so why a new spinlock?

I think the answer is that audio start/stop (anything else?) are called in atomic context, so mutex cannot be used.

Yes, that is correct.

Quoted 4 lines

Also (not exactly related to this patch), if the audio callbacks must be atomic, could we use a workqueue to run the audio start/stop work in non-atomic context? Protecting the whole hdmi state with a single mutex would be much nicer.

The reason why the audio start and stop are done in atomic context is for audio synchronization to other audio devices or video stream to be more accurate.

I guess in theory a work queue could be used to serialize the audio commands, but that would ruin the whole point of why the start and stop commands are atomic in the first place.

Cheers,
Jyri