Skip to contentSkip to conversation

Add support for Legacy Hdmi audio

RFC PATCH Superseded Jerome Anand 8 participants 23 messages Oct 11, 2016 – Nov 11, 2016

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for Legacy Hdmi audio

Legacy Hdmi audio drivers are added.
Added support for audio/ gfx interface using irq chip framework

Jerome Anand (8):
drm/i915: setup bridge for HDMI LPE audio driver
ALSA: add shell for Intel HDMI LPE audio driver
ALSA: Add support for hdmi audio driver
drm/i915: Add support for enabling/disabling hdmi audio interrupts drm/i915: Add support for audio driver notifications
hdmi_audio: Improve position reporting Using a hw register to
calculate sub-period position reports.
hdmi_audio: Fixup some monitor
hdmi_audio: continue audio playback even when display resolution
changes

 drivers/gpu/drm/i915/Makefile          |    3 +
 drivers/gpu/drm/i915/i915_drv.c        |   13 +-
 drivers/gpu/drm/i915/i915_drv.h        |   22 +
 drivers/gpu/drm/i915/i915_irq.c        |   83 ++
 drivers/gpu/drm/i915/i915_reg.h        |    3 +
 drivers/gpu/drm/i915/intel_audio.c     |    8 +
 drivers/gpu/drm/i915/intel_drv.h       |    2 +
 drivers/gpu/drm/i915/intel_hdmi.c      |   18 +-
 drivers/gpu/drm/i915/intel_lpe_audio.c |  406 +++++++
 include/drm/intel_lpe_audio.h          |   46 +
 sound/Kconfig                          |    2 +
 sound/Makefile                         |    2 +-
 sound/x86/Kconfig                      |   16 +
 sound/x86/Makefile                     |   10 +
 sound/x86/intel_hdmi_audio.c           | 1929 ++++++++++++++++++++++++++++++++
 sound/x86/intel_hdmi_audio.h           |  201 ++++
 sound/x86/intel_hdmi_audio_if.c        |  551 +++++++++
 sound/x86/intel_hdmi_lpe_audio.c       |  626 +++++++++++
 sound/x86/intel_hdmi_lpe_audio.h       |  692 ++++++++++++
 19 files changed, 4629 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lpe_audio.c
 create mode 100644 include/drm/intel_lpe_audio.h
 create mode 100644 sound/x86/Kconfig
 create mode 100644 sound/x86/Makefile
 create mode 100644 sound/x86/intel_hdmi_audio.c
 create mode 100644 sound/x86/intel_hdmi_audio.h
 create mode 100644 sound/x86/intel_hdmi_audio_if.c
 create mode 100644 sound/x86/intel_hdmi_lpe_audio.c
 create mode 100644 sound/x86/intel_hdmi_lpe_audio.h
Signature · 7 lines
2.9.3

base-commit: 2fbc239494fa3883e164cc89d35f54d22f0c9e1f
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

RFC PATCH v2 1/8 drm/i915: setup bridge for HDMI LPE audio driver

Enable support for HDMI LPE audio mode on Baytrail and Cherrytrail when HDaudio controller is not detected

Setup minimum required resources during i915_driver_load:
1. Create a platform device to share MMIO/IRQ resources
2. Make the platform device child of i915 device for runtime PM.
3. Create IRQ chip to forward HDMI LPE audio irqs.

HDMI LPE audio driver (a standalone sound driver) probes the LPE audio device and creates a new sound card.

---
 drivers/gpu/drm/i915/Makefile          |   3 +
 drivers/gpu/drm/i915/i915_drv.c        |  13 +-
 drivers/gpu/drm/i915/i915_drv.h        |  19 ++
 drivers/gpu/drm/i915/i915_irq.c        |  14 ++
 drivers/gpu/drm/i915/i915_reg.h        |   3 +
 drivers/gpu/drm/i915/intel_lpe_audio.c | 357 +++++++++++++++++++++++++++++++++
 include/drm/intel_lpe_audio.h          |  45 +++++
 7 files changed, 452 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lpe_audio.c
 create mode 100644 include/drm/intel_lpe_audio.h
drivers/gpu/drm/i915/Makefile +3 -0
index e6fe004..11f9741 100644
@@ -115,6 +115,9 @@ i915-y += intel_gvt.o
 include $(src)/gvt/Makefile
 endif
 
+# LPE Audio for VLV and CHT
+i915-y += intel_lpe_audio.o
+
 obj-$(CONFIG_DRM_I915) += i915.o
 
 CFLAGS_i915_trace_points.o := -I$(src)
drivers/gpu/drm/i915/i915_drv.c +11 -2
index 31b2b63..ab1e4768 100644
@@ -1141,7 +1141,13 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
 	if (IS_GEN5(dev_priv))
 		intel_gpu_ips_init(dev_priv);
 
-	i915_audio_component_init(dev_priv);
+	if (intel_lpe_audio_detect(dev_priv)) {
+		if (intel_lpe_audio_setup(dev_priv) < 0)
+			DRM_ERROR("failed to setup LPE Audio bridge\n");
+	}
+
+	if (!IS_LPE_AUDIO_ENABLED(dev_priv))
+		i915_audio_component_init(dev_priv);
 
 	/*
 	 * Some ports require correctly set-up hpd registers for detection to
@@ -1159,7 +1165,10 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
  */
 static void i915_driver_unregister(struct drm_i915_private *dev_priv)
 {
-	i915_audio_component_cleanup(dev_priv);
+	if (IS_LPE_AUDIO_ENABLED(dev_priv))
+		intel_lpe_audio_teardown(dev_priv);
+	else
+		i915_audio_component_cleanup(dev_priv);
 
 	intel_gpu_ips_teardown();
 	acpi_video_unregister();
drivers/gpu/drm/i915/i915_drv.h +19 -0
index 91ff3d7..399a8ee 100644
@@ -2087,6 +2087,12 @@ struct drm_i915_private {
 	/* Used to save the pipe-to-encoder mapping for audio */
 	struct intel_encoder *av_enc_map[I915_MAX_PIPES];
 
+	/* necessary resource sharing with HDMI LPE audio driver. */
+	struct {
+		struct platform_device *platdev;
+		int	irq;
+	} lpe_audio;
+
 	/*
 	 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
 	 * will be rejected. Instead look for a better place.
@@ -2827,6 +2833,13 @@ struct drm_i915_cmd_table {
 
 #define HAS_POOLED_EU(dev)	(INTEL_INFO(dev)->has_pooled_eu)
 
+#define HAS_LPE_AUDIO(dev)	(IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+#define IS_LPE_AUDIO_ENABLED(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.platdev != NULL)
+#define IS_LPE_AUDIO_IRQ_VALID(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.irq >= 0)
+
+
 #define INTEL_PCH_DEVICE_ID_MASK		0xff00
 #define INTEL_PCH_IBX_DEVICE_ID_TYPE		0x3b00
 #define INTEL_PCH_CPT_DEVICE_ID_TYPE		0x1c00
@@ -3579,6 +3592,12 @@ extern int i915_restore_state(struct drm_device *dev);
 void i915_setup_sysfs(struct drm_i915_private *dev_priv);
 void i915_teardown_sysfs(struct drm_i915_private *dev_priv);
 
+/* i915_lpe_audio.c */
+int  intel_lpe_audio_setup(struct drm_i915_private *dev_priv);
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv);
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv);
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
drivers/gpu/drm/i915/i915_irq.c +14 -0
index 6ed5b24..d8f515f 100644
@@ -1827,6 +1827,13 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
@@ -1907,6 +1914,13 @@ static irqreturn_t cherryview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
drivers/gpu/drm/i915/i915_reg.h +3 -0
index 8d44cee..fb734f2 100644
@@ -2137,6 +2137,9 @@ enum skl_disp_power_wells {
 #define I915_ASLE_INTERRUPT				(1<<0)
 #define I915_BSD_USER_INTERRUPT				(1<<25)
 
+#define I915_HDMI_LPE_AUDIO_BASE	(VLV_DISPLAY_BASE + 0x65000)
+#define I915_HDMI_LPE_AUDIO_SIZE	0x1000
+
 #define GEN6_BSD_RNCID			_MMIO(0x12198)
 
 #define GEN7_FF_THREAD_MODE		_MMIO(0x20a0)
drivers/gpu/drm/i915/intel_lpe_audio.c new file +357 -0

357 lines not on this page · raw message

include/drm/intel_lpe_audio.h new file +45 -0

45 lines not on this page · raw message

Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [RFC PATCH v2 1/8] drm/i915: setup bridge for HDMI LPE audio driver

Quoted 44 lines · Jerome Anand

Enable support for HDMI LPE audio mode on Baytrail and Cherrytrail when HDaudio controller is not detected

Setup minimum required resources during i915_driver_load:
1. Create a platform device to share MMIO/IRQ resources
2. Make the platform device child of i915 device for runtime PM.
3. Create IRQ chip to forward HDMI LPE audio irqs.

HDMI LPE audio driver (a standalone sound driver) probes the LPE audio device and creates a new sound card.

---
 drivers/gpu/drm/i915/Makefile          |   3 +
 drivers/gpu/drm/i915/i915_drv.c        |  13 +-
 drivers/gpu/drm/i915/i915_drv.h        |  19 ++
 drivers/gpu/drm/i915/i915_irq.c        |  14 ++
 drivers/gpu/drm/i915/i915_reg.h        |   3 +
 drivers/gpu/drm/i915/intel_lpe_audio.c | 357 +++++++++++++++++++++++++++++++++
 include/drm/intel_lpe_audio.h          |  45 +++++
 7 files changed, 452 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lpe_audio.c
 create mode 100644 include/drm/intel_lpe_audio.h
drivers/gpu/drm/i915/Makefile +3 -0
index e6fe004..11f9741 100644
@@ -115,6 +115,9 @@ i915-y += intel_gvt.o
 include $(src)/gvt/Makefile
 endif
 
+# LPE Audio for VLV and CHT
+i915-y += intel_lpe_audio.o
+
 obj-$(CONFIG_DRM_I915) += i915.o
 
 CFLAGS_i915_trace_points.o := -I$(src)
drivers/gpu/drm/i915/i915_drv.c +0 -0
index 31b2b63..ab1e4768 100644

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1147

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.c +4 -1
@@ -1141,7 +1141,13 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
 	if (IS_GEN5(dev_priv))
 		intel_gpu_ips_init(dev_priv);
 
-	i915_audio_component_init(dev_priv);
+	if (intel_lpe_audio_detect(dev_priv)) {
+		if (intel_lpe_audio_setup(dev_priv) < 0)
+			DRM_ERROR("failed to setup LPE Audio bridge\n");
+	}

I'd move all that into the lpe audio code. No need to have anything here but a single function call IMO.

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1149

Quoted 2 lines
drivers/gpu/drm/i915/i915_drv.c +2 -0
+
+	if (!IS_LPE_AUDIO_ENABLED(dev_priv))

I don't like that too much. I think I would just make that HAS_LPE_AUDIO(). The current IS_VLV||IS_CHV check can just be inlined into the init function.

Quoted 34 lines
drivers/gpu/drm/i915/i915_drv.c +5 -1
+		i915_audio_component_init(dev_priv);
 
 	/*
 	 * Some ports require correctly set-up hpd registers for detection to
@@ -1159,7 +1165,10 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
  */
 static void i915_driver_unregister(struct drm_i915_private *dev_priv)
 {
-	i915_audio_component_cleanup(dev_priv);
+	if (IS_LPE_AUDIO_ENABLED(dev_priv))
+		intel_lpe_audio_teardown(dev_priv);
+	else
+		i915_audio_component_cleanup(dev_priv);
 
 	intel_gpu_ips_teardown();
 	acpi_video_unregister();
drivers/gpu/drm/i915/i915_drv.h +6 -0
index 91ff3d7..399a8ee 100644
@@ -2087,6 +2087,12 @@ struct drm_i915_private {
 	/* Used to save the pipe-to-encoder mapping for audio */
 	struct intel_encoder *av_enc_map[I915_MAX_PIPES];
 
+	/* necessary resource sharing with HDMI LPE audio driver. */
+	struct {
+		struct platform_device *platdev;
+		int	irq;
+	} lpe_audio;
+
 	/*
 	 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
 	 * will be rejected. Instead look for a better place.

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_cmd_table { · line 2840

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
@@ -2827,6 +2833,13 @@ struct drm_i915_cmd_table {
 
 #define HAS_POOLED_EU(dev)	(INTEL_INFO(dev)->has_pooled_eu)
 
+#define HAS_LPE_AUDIO(dev)	(IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+#define IS_LPE_AUDIO_ENABLED(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.platdev != NULL)
+#define IS_LPE_AUDIO_IRQ_VALID(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.irq >= 0)

Seems useless. We should just not register the lpe audio thing if we have no irq.

Quoted 23 lines
drivers/gpu/drm/i915/i915_drv.h +8 -0
+
+
 #define INTEL_PCH_DEVICE_ID_MASK		0xff00
 #define INTEL_PCH_IBX_DEVICE_ID_TYPE		0x3b00
 #define INTEL_PCH_CPT_DEVICE_ID_TYPE		0x1c00
@@ -3579,6 +3592,12 @@ extern int i915_restore_state(struct drm_device *dev);
 void i915_setup_sysfs(struct drm_i915_private *dev_priv);
 void i915_teardown_sysfs(struct drm_i915_private *dev_priv);
 
+/* i915_lpe_audio.c */
+int  intel_lpe_audio_setup(struct drm_i915_private *dev_priv);
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv);
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv);
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
drivers/gpu/drm/i915/i915_irq.c +0 -0
index 6ed5b24..d8f515f 100644

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1831

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
@@ -1827,6 +1827,13 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))

I think both of these checks can be removed. We won't unmask the interrupts unless lpe is enabled, so the IIR bits will never be set in that case.

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t cherryview_irq_handler(int irq, void *arg) · line 1923

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +7 -0
@@ -1907,6 +1914,13 @@ static irqreturn_t cherryview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+

ditto

Quoted 104 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
drivers/gpu/drm/i915/i915_reg.h +3 -0
index 8d44cee..fb734f2 100644
@@ -2137,6 +2137,9 @@ enum skl_disp_power_wells {
 #define I915_ASLE_INTERRUPT				(1<<0)
 #define I915_BSD_USER_INTERRUPT				(1<<25)
 
+#define I915_HDMI_LPE_AUDIO_BASE	(VLV_DISPLAY_BASE + 0x65000)
+#define I915_HDMI_LPE_AUDIO_SIZE	0x1000
+
 #define GEN6_BSD_RNCID			_MMIO(0x12198)
 
 #define GEN7_FF_THREAD_MODE		_MMIO(0x20a0)
drivers/gpu/drm/i915/intel_lpe_audio.c new file +81 -0
new file mode 100644
index 0000000..acfe22f
@@ -0,0 +1,357 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Pierre-Louis Bossart <[email protected]>
+ *    Jerome Anand <[email protected]>
+ *    based on VED patches
+ *
+ */
+
+/**
+ * DOC: LPE Audio integration integration for HDMI or DP playback
+ *
+ * Motivation:
+ * Atom platforms (e.g. valleyview and cherryTrail) integrates a DMA-based
+ * interface as an alternative to the traditional HDaudio path. While this
+ * mode is unrelated to the LPE aka SST audio engine, the documentation refers
+ * to this mode as LPE so we keep this notation for the sake of consistency.
+ *
+ * The interface is handled by a separate standalone driver maintained in the
+ * ALSA subsystem for simplicity. To minimize the interaction between the two
+ * subsystems, a bridge is setup between the hdmi-lpe-audio and i915:
+ * 1. Create a platform device to share MMIO/IRQ resources
+ * 2. Make the platform device child of i915 device for runtime PM.
+ * 3. Create IRQ chip to forward the LPE audio irqs.
+ * the hdmi-lpe-audio driver probes the lpe audio device and creates a new
+ * sound card
+ *
+ * Threats:
+ * Due to the restriction in Linux platform device model, user need manually
+ * uninstall the hdmi-lpe-audio driver before uninstalling i915 module,
+ * otherwise we might run into use-after-free issues after i915 removes the
+ * platform device: even though hdmi-lpe-audio driver is released, the modules
+ * is still in "installed" status.
+ *
+ * Implementation:
+ * The MMIO/REG platform resources are created according to the registers
+ * specification.
+ * When forwarding LPE audio irqs, the flow control handler selection depends
+ * on the platform, for example on valleyview handle_simple_irq is enough.
+ *
+ */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/pci.h>
+
+#include "i915_drv.h"
+#include <linux/delay.h>
+#include <drm/intel_lpe_audio.h>
+
+static struct platform_device*
+lpe_audio_platdev_create(struct drm_i915_private *dev_priv)
+{
+	struct drm_device *dev = &dev_priv->drm;
+	int ret;
+	struct resource rsc[2] = {};
+	struct platform_device *platdev;
+	u64 *dma_mask;
+	struct intel_hdmi_lpe_audio_pdata *pdata;
+
+	if (dev_priv->lpe_audio.irq < 0)

drivers/gpu/drm/i915/intel_lpe_audio.c line 91

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+		return ERR_PTR(-EINVAL);
+
+	platdev = platform_device_alloc("hdmi-lpe-audio", -1);
+	if (!platdev) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate LPE audio platform device\n");
+		goto err;
+	}
+
+	/* to work-around check_addr in nommu_map_sg() */

What's this about?

Quoted 6 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +6 -0
+	dma_mask = kmalloc(sizeof(*platdev->dev.dma_mask), GFP_KERNEL);
+	if (!dma_mask) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate dma_mask\n");
+		goto err_put_dev;
+	}

drivers/gpu/drm/i915/intel_lpe_audio.c line 107

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+	*dma_mask = DMA_BIT_MASK(32);
+	platdev->dev.dma_mask = dma_mask;
+	platdev->dev.coherent_dma_mask = *dma_mask;
+
+	rsc[0].start    = rsc[0].end = dev_priv->lpe_audio.irq;
+	rsc[0].flags    = IORESOURCE_IRQ;
+	rsc[0].name     = "hdmi-lpe-audio-irq";
+
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[0] = 0x%x\n",
+		__func__, (int)(rsc[0].start));

__func__ pointless since DRM_DEBUG alreay adds it. Also saying "rsc.start[0]" in the message doesn't tell anyone anything useful. And I think irq numbers are usually printed in decimal.

drivers/gpu/drm/i915/intel_lpe_audio.c line 117

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+
+	rsc[1].start    = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE;
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1;
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "hdmi-lpe-audio-mmio";
+
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[1] = 0x%x\n",
+		__func__, (int)(rsc[1].start));

Again "rsc[0].start" doesn't seem like anything useful to print in a debug message. Don't see much point in the whole debug message TBH since the start/end are fixed.

Quoted 15 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +15 -0
+
+	ret = platform_device_add_resources(platdev, rsc, 2);
+	if (ret) {
+		DRM_ERROR("Failed to add resource for platform device: %d\n",
+			ret);
+		goto err_put_dev;
+	}
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+
+	if (pdata == NULL) {
+		ret = -ENOMEM;
+		goto err_put_dev;
+	}
+	platdev->dev.platform_data = pdata;

drivers/gpu/drm/i915/intel_lpe_audio.c line 142

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+
+	/* for LPE audio driver's runtime-PM */
+	platdev->dev.parent = dev->dev;
+	ret = platform_device_add(platdev);
+	if (ret) {
+		DRM_ERROR("Failed to add LPE audio platform device: %d\n",
+			ret);
+		goto err_put_dev;
+	}
+	spin_lock_init(&pdata->lpe_audio_slock);

Should init it before adding the device I suppose? It's not used in the patch so hard to say. In general the patch split is not the best due to not being able to see the use of things.

Quoted 5 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +5 -0
+
+	return platdev;
+err_put_dev:
+	platform_device_put(platdev);
+	kfree(dma_mask);

drivers/gpu/drm/i915/intel_lpe_audio.c line 157

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+err:
+	return ERR_PTR(ret);
+}
+
+static void lpe_audio_platdev_destroy(struct drm_i915_private *dev_priv)
+{
+	if (dev_priv->lpe_audio.platdev) {
+		platform_device_unregister(dev_priv->lpe_audio.platdev);
+		kfree(dev_priv->lpe_audio.platdev->dev.dma_mask);
+	}

I usually prefer

{
	if (!stuff)
		return;

	other stuff;
}

just to keep the indentation better in check.

Quoted 12 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +12 -0
+}
+
+static void lpe_audio_irq_unmask(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	unsigned long irqflags;
+	u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+		I915_LPE_PIPE_B_INTERRUPT |
+		I915_LPE_PIPE_C_INTERRUPT);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);

drivers/gpu/drm/i915/intel_lpe_audio.c line 179

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+
+	/*
+	 * VLV_IER is already set in the vlv_display_postinstall(),
+	 * we only change VLV_IIR and VLV_IMR
+	 */
+	dev_priv->irq_mask &= ~val;
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+

Extra newline here for some reason. No such thing in the counterpart.

Quoted 30 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +30 -0
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+static void lpe_audio_irq_mask(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	unsigned long irqflags;
+	u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+		I915_LPE_PIPE_B_INTERRUPT |
+		I915_LPE_PIPE_C_INTERRUPT);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	/*
+	 * VLV_IER is already set in the vlv_display_postinstall(),
+	 * we only change VLV_IIR and VLV_IMR
+	 */
+	dev_priv->irq_mask |= val;
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IIR, val);
+	POSTING_READ(VLV_IIR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+static struct irq_chip lpe_audio_irqchip = {

drivers/gpu/drm/i915/intel_lpe_audio.c line 219

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+	.name = "hdmi_lpe_audio_irqchip",
+	.irq_mask = lpe_audio_irq_mask,
+	.irq_unmask = lpe_audio_irq_unmask,
+};
+
+static int lpe_audio_irq_init(struct drm_i915_private *dev_priv)
+{
+	int irq = dev_priv->lpe_audio.irq;
+
+	WARN_ON(!intel_irqs_enabled(dev_priv));

Could leave a blank like here to make things look less convoluted.

drivers/gpu/drm/i915/intel_lpe_audio.c line 223

Quoted 4 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +4 -0
+	irq_set_chip_and_handler_name(irq,
+		&lpe_audio_irqchip,
+		handle_simple_irq,
+		"hdmi_lpe_audio_irq_handler");

Indentation isn't quite right.

Quoted 32 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +32 -0
+
+	return irq_set_chip_data(irq, &dev_priv->drm);
+}
+
+/**
+ * intel_lpe_audio_irq_handler() - forwards the LPE audio irq
+ * @dev_priv: the i915 drm device private data
+ *
+ * the LPE Audio irq is forwarded to the irq handler registered by LPE audio
+ * driver.
+ */
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	ret = generic_handle_irq(dev_priv->lpe_audio.irq);
+	if (ret)
+		DRM_ERROR_RATELIMITED("error handling LPE audio irq: %d\n",
+				ret);
+}
+
+/**
+ * intel_lpe_audio_detect() - check & setup lpe audio if present
+ * @dev_priv: the i915 drm device private data
+ *
+ * Detect if lpe audio is present
+ *
+ * Return: true if lpe audio present else Return = false
+ */
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv)
+{
+	int lpe_present = false;

drivers/gpu/drm/i915/intel_lpe_audio.c line 265

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+	struct drm_device *dev = &dev_priv->drm;
+
+	if (HAS_LPE_AUDIO(dev)) {
+		static const struct pci_device_id atom_hdaudio_ids[] = {
+			/* Baytrail */
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f04)},
+			/* Braswell */
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2284)},
+			{}
+		};

Hmm. Maybe I asked already, but could we use a class match instead? There's some kind of HDA class right?

Quoted 16 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +16 -0
+
+		if (!pci_dev_present(atom_hdaudio_ids)) {
+			DRM_INFO("%s%s\n", "HDaudio controller not detected,",
+				"using LPE audio instead\n");
+			lpe_present = true;
+		}
+	}
+	return lpe_present;
+}
+
+/**
+ * intel_lpe_audio_setup() - setup the bridge between HDMI LPE Audio
+ * driver and i915
+ * @dev_priv: the i915 drm device private data
+ *
+ * set up the minimum required resources for the bridge: irq chip,

drivers/gpu/drm/i915/intel_lpe_audio.c line 291

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+ * platform resource and platform device. i915 device is set as parent
+ * of the new platform device.
+ *
+ * Return: 0 if successful. non-zero if allocation/initialization fails
+ */
+int intel_lpe_audio_setup(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	dev_priv->lpe_audio.irq = irq_alloc_descs(-1, 0, 1, 0);

aka. irq_alloc_desc() ?

drivers/gpu/drm/i915/intel_lpe_audio.c line 299

Quoted 8 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +8 -0
+	if (dev_priv->lpe_audio.irq < 0) {
+		DRM_ERROR("Failed to allocate IRQ desc: %d\n",
+			dev_priv->lpe_audio.irq);
+		ret = dev_priv->lpe_audio.irq;
+		goto err;
+	}
+
+	DRM_DEBUG("%s : irq = %d\n", __func__, dev_priv->lpe_audio.irq);

Another __func__ that's not needed. And we're printing the irq twice now?

drivers/gpu/drm/i915/intel_lpe_audio.c line 306

Quoted 7 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +7 -0
+
+	ret = lpe_audio_irq_init(dev_priv);
+
+	if (ret) {
+
+		DRM_ERROR("Failed to initialize irqchip for lpe audio: %d\n",
+			ret);

Indentation looks off.

drivers/gpu/drm/i915/intel_lpe_audio.c line 315

Quoted 9 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +9 -0
+		goto err_free_irq;
+	}
+
+	dev_priv->lpe_audio.platdev = lpe_audio_platdev_create(dev_priv);
+
+	if (IS_ERR(dev_priv->lpe_audio.platdev)) {
+		ret = PTR_ERR(dev_priv->lpe_audio.platdev);
+		DRM_ERROR("Failed to create lpe audio platform device: %d\n",
+			ret);

ditto

Quoted 21 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +21 -0
+		goto err_free_irq;
+	}
+
+	return 0;
+err_free_irq:
+	irq_free_desc(dev_priv->lpe_audio.irq);
+err:
+	dev_priv->lpe_audio.irq = -1;
+	dev_priv->lpe_audio.platdev = NULL;
+	return ret;
+}
+
+/**
+ * intel_lpe_audio_teardown() - destroy the bridge between HDMI LPE
+ * audio driver and i915
+ * @dev_priv: the i915 drm device private data
+ *
+ * release all the resources for LPE audio <-> i915 bridge.
+ */
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv)
+{

drivers/gpu/drm/i915/intel_lpe_audio.c line 346

Quoted 10 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +10 -0
+	unsigned long irqflags;
+	struct irq_desc *desc;
+
+	desc = IS_LPE_AUDIO_IRQ_VALID(dev_priv) ?
+			irq_to_desc(dev_priv->lpe_audio.irq) : NULL;
+
+	/**
+	 * mask LPE audio irq before destroying
+	 */
+	if (desc)

Seems overly defensive. Should just check if we have the platform device at the start, and otherwise we can assume that all the things we need to free are there.

This looks racy too. We should unregister the platform device as the first thing, and only then free up the resources and whatnot.

Quoted 64 lines
drivers/gpu/drm/i915/intel_lpe_audio.c new file +11 -0
+		lpe_audio_irq_mask(&desc->irq_data);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	lpe_audio_platdev_destroy(dev_priv);
+
+	if (desc)
+		irq_free_desc(dev_priv->lpe_audio.irq);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
include/drm/intel_lpe_audio.h new file +45 -0
new file mode 100644
index 0000000..a64c449
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef _INTEL_LPE_AUDIO_H_
+#define _INTEL_LPE_AUDIO_H_
+
+#include <linux/types.h>
+
+#define HDMI_MAX_ELD_BYTES	128
+
+struct intel_hdmi_lpe_audio_eld {
+	int port_id;
+	unsigned char eld_data[HDMI_MAX_ELD_BYTES];
+};
+
+struct intel_hdmi_lpe_audio_pdata {
+	bool notify_pending;
+	int tmds_clock_speed;
+	bool hdmi_connected;
+	struct intel_hdmi_lpe_audio_eld eld;
+	void (*notify_audio_lpe)(void *audio_ptr);
+	spinlock_t lpe_audio_slock;
+};
+
+#endif /* _I915_LPE_AUDIO_H_ */
Signature · 1 line
2.9.3
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

Re: [RFC PATCH v2 1/8] drm/i915: setup bridge for HDMI LPE audio driver

Thanks Ville for the review. A lot of the comments are related to the initial VED code we took pretty much as is, no issues to clean-up further.

BTW, it looks like Jerome's patches were stuck for 10+ days on the intel-gfx server for some reason so not everyone saw the initial post?

Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/i915_drv.c +0 -0
@@ -1141,7 +1141,13 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
 	if (IS_GEN5(dev_priv))
 		intel_gpu_ips_init(dev_priv);
 
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1147

Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.c +4 -1
-	i915_audio_component_init(dev_priv);
+	if (intel_lpe_audio_detect(dev_priv)) {
+		if (intel_lpe_audio_setup(dev_priv) < 0)
+			DRM_ERROR("failed to setup LPE Audio bridge\n");
+	}

I'd move all that into the lpe audio code. No need to have anything here but a single function call IMO.

something like intel_lpe_audio_init() for symmetry with the hda component stuff, with both detection and setup handled internally?

Quoted 7 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1149

Quoted 3 lines
drivers/gpu/drm/i915/i915_drv.c +2 -0
+
+	if (!IS_LPE_AUDIO_ENABLED(dev_priv))

I don't like that too much. I think I would just make that HAS_LPE_AUDIO(). The current IS_VLV||IS_CHV check can just be inlined into the init function.

ok

Quoted 11 lines

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_cmd_table { · line 2840

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
 #define HAS_POOLED_EU(dev)	(INTEL_INFO(dev)->has_pooled_eu)
 
+#define HAS_LPE_AUDIO(dev)	(IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+#define IS_LPE_AUDIO_ENABLED(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.platdev != NULL)
+#define IS_LPE_AUDIO_IRQ_VALID(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.irq >= 0)

Seems useless. We should just not register the lpe audio thing if we have no irq.

ok

Quoted 13 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1831

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
@@ -1827,6 +1827,13 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))

I think both of these checks can be removed. We won't unmask the interrupts unless lpe is enabled, so the IIR bits will never be set in that case.

Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1836

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+

ok.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
@@ -1907,6 +1914,13 @@ static irqreturn_t cherryview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
Quoted 9 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1836

Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +7 -0
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+

ditto

ok

Quoted 10 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t cherryview_irq_handler(int irq, void *arg)

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +8 -0
+	platdev = platform_device_alloc("hdmi-lpe-audio", -1);
+	if (!platdev) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate LPE audio platform device\n");
+		goto err;
+	}
+
+	/* to work-around check_addr in nommu_map_sg() */

What's this about?

Dunno, this was in the original VED series that we used as a baseline. Unless someone has memories from that time, i'll just remove this comment.

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 2 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[0] = 0x%x\n",
+		__func__, (int)(rsc[0].start));

__func__ pointless since DRM_DEBUG alreay adds it. Also saying "rsc.start[0]" in the message doesn't tell anyone anything useful. And I think irq numbers are usually printed in decimal.

Same, this was taken from the VED series, no issue to clean-up.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c +10 -0
+
+	rsc[1].start    = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE;
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1;
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "hdmi-lpe-audio-mmio";
+
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[1] = 0x%x\n",
+		__func__, (int)(rsc[1].start));

Again "rsc[0].start" doesn't seem like anything useful to print in a debug message. Don't see much point in the whole debug message TBH since the start/end are fixed.

so are you saying we should remove the code or move the level to DRM_INFO - for extra verbose debug?

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/i915/i915_irq.c +21 -0
+
+	ret = platform_device_add_resources(platdev, rsc, 2);
+	if (ret) {
+		DRM_ERROR("Failed to add resource for platform device: %d\n",
+			ret);
+		goto err_put_dev;
+	}
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+
+	if (pdata == NULL) {
+		ret = -ENOMEM;
+		goto err_put_dev;
+	}
+	platdev->dev.platform_data = pdata;
+
+	/* for LPE audio driver's runtime-PM */
+	platdev->dev.parent = dev->dev;
+	ret = platform_device_add(platdev);
+	if (ret) {
+		DRM_ERROR("Failed to add LPE audio platform device: %d\n",
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
+			ret);
+		goto err_put_dev;
+	}
+	spin_lock_init(&pdata->lpe_audio_slock);

Should init it before adding the device I suppose? It's not used in the patch so hard to say. In general the patch split is not the best due to not being able to see the use of things.

ok. we'll look into this.

Quoted 9 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+static void lpe_audio_platdev_destroy(struct drm_i915_private *dev_priv)
+{
+	if (dev_priv->lpe_audio.platdev) {
+		platform_device_unregister(dev_priv->lpe_audio.platdev);
+		kfree(dev_priv->lpe_audio.platdev->dev.dma_mask);
+	}

I usually prefer

Quoted 8 lines
{
	if (!stuff)
		return;

	other stuff;
}

just to keep the indentation better in check.

ok

Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/i915/i915_irq.c +16 -0
+}
+
+static void lpe_audio_irq_unmask(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	unsigned long irqflags;
+	u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+		I915_LPE_PIPE_B_INTERRUPT |
+		I915_LPE_PIPE_C_INTERRUPT);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	/*
+	 * VLV_IER is already set in the vlv_display_postinstall(),
+	 * we only change VLV_IIR and VLV_IMR
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+	 */
+	dev_priv->irq_mask &= ~val;
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+

Extra newline here for some reason. No such thing in the counterpart.

ok

Quoted 7 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+static int lpe_audio_irq_init(struct drm_i915_private *dev_priv)
+{
+	int irq = dev_priv->lpe_audio.irq;
+
+	WARN_ON(!intel_irqs_enabled(dev_priv));

Could leave a blank like here to make things look less convoluted.

ok

Quoted 7 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
+	irq_set_chip_and_handler_name(irq,
+		&lpe_audio_irqchip,
+		handle_simple_irq,
+		"hdmi_lpe_audio_irq_handler");

Indentation isn't quite right.

ok

Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/i915/i915_irq.c +37 -0
+
+	return irq_set_chip_data(irq, &dev_priv->drm);
+}
+
+/**
+ * intel_lpe_audio_irq_handler() - forwards the LPE audio irq
+ * @dev_priv: the i915 drm device private data
+ *
+ * the LPE Audio irq is forwarded to the irq handler registered by LPE audio
+ * driver.
+ */
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	ret = generic_handle_irq(dev_priv->lpe_audio.irq);
+	if (ret)
+		DRM_ERROR_RATELIMITED("error handling LPE audio irq: %d\n",
+				ret);
+}
+
+/**
+ * intel_lpe_audio_detect() - check & setup lpe audio if present
+ * @dev_priv: the i915 drm device private data
+ *
+ * Detect if lpe audio is present
+ *
+ * Return: true if lpe audio present else Return = false
+ */
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv)
+{
+	int lpe_present = false;
+	struct drm_device *dev = &dev_priv->drm;
+
+	if (HAS_LPE_AUDIO(dev)) {
+		static const struct pci_device_id atom_hdaudio_ids[] = {
+			/* Baytrail */
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f04)},
+			/* Braswell */
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2284)},
+			{}
+		};

Hmm. Maybe I asked already, but could we use a class match instead? There's some kind of HDA class right?

I am not aware of any class, this is really the only means we found to test if the HDaudio controller is disabled or fused out. Maybe a question for Takashi?

Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/i915/i915_irq.c +20 -0
+
+		if (!pci_dev_present(atom_hdaudio_ids)) {
+			DRM_INFO("%s%s\n", "HDaudio controller not detected,",
+				"using LPE audio instead\n");
+			lpe_present = true;
+		}
+	}
+	return lpe_present;
+}
+
+/**
+ * intel_lpe_audio_setup() - setup the bridge between HDMI LPE Audio
+ * driver and i915
+ * @dev_priv: the i915 drm device private data
+ *
+ * set up the minimum required resources for the bridge: irq chip,
+ * platform resource and platform device. i915 device is set as parent
+ * of the new platform device.
+ *
+ * Return: 0 if successful. non-zero if allocation/initialization fails
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines

+ */

drivers/gpu/drm/i915/i915_irq.c +5 -0
+int intel_lpe_audio_setup(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	dev_priv->lpe_audio.irq = irq_alloc_descs(-1, 0, 1, 0);

aka. irq_alloc_desc() ?

not sure, will look into this.

Quoted 12 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +8 -0
+	if (dev_priv->lpe_audio.irq < 0) {
+		DRM_ERROR("Failed to allocate IRQ desc: %d\n",
+			dev_priv->lpe_audio.irq);
+		ret = dev_priv->lpe_audio.irq;
+		goto err;
+	}
+
+	DRM_DEBUG("%s : irq = %d\n", __func__, dev_priv->lpe_audio.irq);

Another __func__ that's not needed. And we're printing the irq twice now?

ok

Quoted 10 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +7 -0
+
+	ret = lpe_audio_irq_init(dev_priv);
+
+	if (ret) {
+
+		DRM_ERROR("Failed to initialize irqchip for lpe audio: %d\n",
+			ret);

Indentation looks off.

ok

Quoted 12 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +9 -0
+		goto err_free_irq;
+	}
+
+	dev_priv->lpe_audio.platdev = lpe_audio_platdev_create(dev_priv);
+
+	if (IS_ERR(dev_priv->lpe_audio.platdev)) {
+		ret = PTR_ERR(dev_priv->lpe_audio.platdev);
+		DRM_ERROR("Failed to create lpe audio platform device: %d\n",
+			ret);

ditto

ok

Quoted 17 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 12 lines
drivers/gpu/drm/i915/i915_irq.c +12 -0
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	struct irq_desc *desc;
+
+	desc = IS_LPE_AUDIO_IRQ_VALID(dev_priv) ?
+			irq_to_desc(dev_priv->lpe_audio.irq) : NULL;
+
+	/**
+	 * mask LPE audio irq before destroying
+	 */
+	if (desc)

Seems overly defensive. Should just check if we have the platform device at the start, and otherwise we can assume that all the things we need to free are there.

Quoted 2 lines

This looks racy too. We should unregister the platform device as the first thing, and only then free up the resources and whatnot.

will clean up

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw

Re: [RFC PATCH v2 1/8] drm/i915: setup bridge for HDMI LPE audio driver

Quoted 5 lines · Pierre-Louis Bossart

Thanks Ville for the review. A lot of the comments are related to the initial VED code we took pretty much as is, no issues to clean-up further.

BTW, it looks like Jerome's patches were stuck for 10+ days on the intel-gfx server for some reason so not everyone saw the initial post?

Did they make it to the list? Jani told me they didn't, nor were they in the moderation queue apparently. So no idea where they went. I tried bouncing them to the list, but I'm not sure they came through that time either.

Quoted 375 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.c +0 -0
@@ -1141,7 +1141,13 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
 	if (IS_GEN5(dev_priv))
 		intel_gpu_ips_init(dev_priv);
 
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1147

Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.c +4 -1
-	i915_audio_component_init(dev_priv);
+	if (intel_lpe_audio_detect(dev_priv)) {
+		if (intel_lpe_audio_setup(dev_priv) < 0)
+			DRM_ERROR("failed to setup LPE Audio bridge\n");
+	}

I'd move all that into the lpe audio code. No need to have anything here but a single function call IMO.

something like intel_lpe_audio_init() for symmetry with the hda component stuff, with both detection and setup handled internally?

Quoted 7 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1149

Quoted 3 lines
drivers/gpu/drm/i915/i915_drv.c +2 -0
+
+	if (!IS_LPE_AUDIO_ENABLED(dev_priv))

I don't like that too much. I think I would just make that HAS_LPE_AUDIO(). The current IS_VLV||IS_CHV check can just be inlined into the init function.

ok

Quoted 11 lines

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_cmd_table { · line 2840

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
 #define HAS_POOLED_EU(dev)	(INTEL_INFO(dev)->has_pooled_eu)
 
+#define HAS_LPE_AUDIO(dev)	(IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+#define IS_LPE_AUDIO_ENABLED(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.platdev != NULL)
+#define IS_LPE_AUDIO_IRQ_VALID(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.irq >= 0)

Seems useless. We should just not register the lpe audio thing if we have no irq.

ok

Quoted 13 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1831

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
@@ -1827,6 +1827,13 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))

I think both of these checks can be removed. We won't unmask the interrupts unless lpe is enabled, so the IIR bits will never be set in that case.

Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1836

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+

ok.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
@@ -1907,6 +1914,13 @@ static irqreturn_t cherryview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
Quoted 9 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1836

Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +7 -0
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+

ditto

ok

Quoted 10 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t cherryview_irq_handler(int irq, void *arg)

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +8 -0
+	platdev = platform_device_alloc("hdmi-lpe-audio", -1);
+	if (!platdev) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate LPE audio platform device\n");
+		goto err;
+	}
+
+	/* to work-around check_addr in nommu_map_sg() */

What's this about?

Dunno, this was in the original VED series that we used as a baseline. Unless someone has memories from that time, i'll just remove this comment.

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 2 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[0] = 0x%x\n",
+		__func__, (int)(rsc[0].start));

__func__ pointless since DRM_DEBUG alreay adds it. Also saying "rsc.start[0]" in the message doesn't tell anyone anything useful. And I think irq numbers are usually printed in decimal.

Same, this was taken from the VED series, no issue to clean-up.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c +10 -0
+
+	rsc[1].start    = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE;
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1;
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "hdmi-lpe-audio-mmio";
+
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[1] = 0x%x\n",
+		__func__, (int)(rsc[1].start));

Again "rsc[0].start" doesn't seem like anything useful to print in a debug message. Don't see much point in the whole debug message TBH since the start/end are fixed.

so are you saying we should remove the code or move the level to DRM_INFO - for extra verbose debug?

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/i915/i915_irq.c +21 -0
+
+	ret = platform_device_add_resources(platdev, rsc, 2);
+	if (ret) {
+		DRM_ERROR("Failed to add resource for platform device: %d\n",
+			ret);
+		goto err_put_dev;
+	}
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+
+	if (pdata == NULL) {
+		ret = -ENOMEM;
+		goto err_put_dev;
+	}
+	platdev->dev.platform_data = pdata;
+
+	/* for LPE audio driver's runtime-PM */
+	platdev->dev.parent = dev->dev;
+	ret = platform_device_add(platdev);
+	if (ret) {
+		DRM_ERROR("Failed to add LPE audio platform device: %d\n",
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
+			ret);
+		goto err_put_dev;
+	}
+	spin_lock_init(&pdata->lpe_audio_slock);

Should init it before adding the device I suppose? It's not used in the patch so hard to say. In general the patch split is not the best due to not being able to see the use of things.

ok. we'll look into this.

Quoted 9 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+static void lpe_audio_platdev_destroy(struct drm_i915_private *dev_priv)
+{
+	if (dev_priv->lpe_audio.platdev) {
+		platform_device_unregister(dev_priv->lpe_audio.platdev);
+		kfree(dev_priv->lpe_audio.platdev->dev.dma_mask);
+	}

I usually prefer

Quoted 8 lines
{
	if (!stuff)
		return;

	other stuff;
}

just to keep the indentation better in check.

ok

Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/i915/i915_irq.c +16 -0
+}
+
+static void lpe_audio_irq_unmask(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	unsigned long irqflags;
+	u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+		I915_LPE_PIPE_B_INTERRUPT |
+		I915_LPE_PIPE_C_INTERRUPT);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	/*
+	 * VLV_IER is already set in the vlv_display_postinstall(),
+	 * we only change VLV_IIR and VLV_IMR
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+	 */
+	dev_priv->irq_mask &= ~val;
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+

Extra newline here for some reason. No such thing in the counterpart.

ok

Quoted 7 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+static int lpe_audio_irq_init(struct drm_i915_private *dev_priv)
+{
+	int irq = dev_priv->lpe_audio.irq;
+
+	WARN_ON(!intel_irqs_enabled(dev_priv));

Could leave a blank like here to make things look less convoluted.

ok

Quoted 7 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
+	irq_set_chip_and_handler_name(irq,
+		&lpe_audio_irqchip,
+		handle_simple_irq,
+		"hdmi_lpe_audio_irq_handler");

Indentation isn't quite right.

ok

Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/i915/i915_irq.c +37 -0
+
+	return irq_set_chip_data(irq, &dev_priv->drm);
+}
+
+/**
+ * intel_lpe_audio_irq_handler() - forwards the LPE audio irq
+ * @dev_priv: the i915 drm device private data
+ *
+ * the LPE Audio irq is forwarded to the irq handler registered by LPE audio
+ * driver.
+ */
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	ret = generic_handle_irq(dev_priv->lpe_audio.irq);
+	if (ret)
+		DRM_ERROR_RATELIMITED("error handling LPE audio irq: %d\n",
+				ret);
+}
+
+/**
+ * intel_lpe_audio_detect() - check & setup lpe audio if present
+ * @dev_priv: the i915 drm device private data
+ *
+ * Detect if lpe audio is present
+ *
+ * Return: true if lpe audio present else Return = false
+ */
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv)
+{
+	int lpe_present = false;
+	struct drm_device *dev = &dev_priv->drm;
+
+	if (HAS_LPE_AUDIO(dev)) {
+		static const struct pci_device_id atom_hdaudio_ids[] = {
+			/* Baytrail */
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f04)},
+			/* Braswell */
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2284)},
+			{}
+		};

Hmm. Maybe I asked already, but could we use a class match instead? There's some kind of HDA class right?

I am not aware of any class, this is really the only means we found to test if the HDaudio controller is disabled or fused out. Maybe a question for Takashi?

Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/i915/i915_irq.c +20 -0
+
+		if (!pci_dev_present(atom_hdaudio_ids)) {
+			DRM_INFO("%s%s\n", "HDaudio controller not detected,",
+				"using LPE audio instead\n");
+			lpe_present = true;
+		}
+	}
+	return lpe_present;
+}
+
+/**
+ * intel_lpe_audio_setup() - setup the bridge between HDMI LPE Audio
+ * driver and i915
+ * @dev_priv: the i915 drm device private data
+ *
+ * set up the minimum required resources for the bridge: irq chip,
+ * platform resource and platform device. i915 device is set as parent
+ * of the new platform device.
+ *
+ * Return: 0 if successful. non-zero if allocation/initialization fails
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines

+ */

drivers/gpu/drm/i915/i915_irq.c +5 -0
+int intel_lpe_audio_setup(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	dev_priv->lpe_audio.irq = irq_alloc_descs(-1, 0, 1, 0);

aka. irq_alloc_desc() ?

not sure, will look into this.

Quoted 12 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +8 -0
+	if (dev_priv->lpe_audio.irq < 0) {
+		DRM_ERROR("Failed to allocate IRQ desc: %d\n",
+			dev_priv->lpe_audio.irq);
+		ret = dev_priv->lpe_audio.irq;
+		goto err;
+	}
+
+	DRM_DEBUG("%s : irq = %d\n", __func__, dev_priv->lpe_audio.irq);

Another __func__ that's not needed. And we're printing the irq twice now?

ok

Quoted 10 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +7 -0
+
+	ret = lpe_audio_irq_init(dev_priv);
+
+	if (ret) {
+
+		DRM_ERROR("Failed to initialize irqchip for lpe audio: %d\n",
+			ret);

Indentation looks off.

ok

Quoted 12 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +9 -0
+		goto err_free_irq;
+	}
+
+	dev_priv->lpe_audio.platdev = lpe_audio_platdev_create(dev_priv);
+
+	if (IS_ERR(dev_priv->lpe_audio.platdev)) {
+		ret = PTR_ERR(dev_priv->lpe_audio.platdev);
+		DRM_ERROR("Failed to create lpe audio platform device: %d\n",
+			ret);

ditto

ok

Quoted 17 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 12 lines
drivers/gpu/drm/i915/i915_irq.c +12 -0
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	struct irq_desc *desc;
+
+	desc = IS_LPE_AUDIO_IRQ_VALID(dev_priv) ?
+			irq_to_desc(dev_priv->lpe_audio.irq) : NULL;
+
+	/**
+	 * mask LPE audio irq before destroying
+	 */
+	if (desc)

Seems overly defensive. Should just check if we have the platform device at the start, and otherwise we can assume that all the things we need to free are there.

Quoted 2 lines

This looks racy too. We should unregister the platform device as the first thing, and only then free up the resources and whatnot.

will clean up

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#5 lore raw

Re: [RFC PATCH v2 1/8] drm/i915: setup bridge for HDMI LPE audio driver

Quoted 11 lines · Ville Syrjälä
Quoted 5 lines · Pierre-Louis Bossart

Thanks Ville for the review. A lot of the comments are related to the initial VED code we took pretty much as is, no issues to clean-up further.

BTW, it looks like Jerome's patches were stuck for 10+ days on the intel-gfx server for some reason so not everyone saw the initial post?

Did they make it to the list? Jani told me they didn't, nor were they in the moderation queue apparently. So no idea where they went. I tried bouncing them to the list, but I'm not sure they came through that time either.

The patches as bounced by Ville made it to the list, but the original ones were lost and I have no idea what happened. They were not in moderation and there was no trace of them.

BR,
Jani.

Quoted 376 lines
Quoted 376 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.c +0 -0
@@ -1141,7 +1141,13 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
 	if (IS_GEN5(dev_priv))
 		intel_gpu_ips_init(dev_priv);
 
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1147

Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.c +4 -1
-	i915_audio_component_init(dev_priv);
+	if (intel_lpe_audio_detect(dev_priv)) {
+		if (intel_lpe_audio_setup(dev_priv) < 0)
+			DRM_ERROR("failed to setup LPE Audio bridge\n");
+	}

I'd move all that into the lpe audio code. No need to have anything here but a single function call IMO.

something like intel_lpe_audio_init() for symmetry with the hda component stuff, with both detection and setup handled internally?

Quoted 7 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1149

Quoted 3 lines
drivers/gpu/drm/i915/i915_drv.c +2 -0
+
+	if (!IS_LPE_AUDIO_ENABLED(dev_priv))

I don't like that too much. I think I would just make that HAS_LPE_AUDIO(). The current IS_VLV||IS_CHV check can just be inlined into the init function.

ok

Quoted 11 lines

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_cmd_table { · line 2840

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
 #define HAS_POOLED_EU(dev)	(INTEL_INFO(dev)->has_pooled_eu)
 
+#define HAS_LPE_AUDIO(dev)	(IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+#define IS_LPE_AUDIO_ENABLED(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.platdev != NULL)
+#define IS_LPE_AUDIO_IRQ_VALID(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.irq >= 0)

Seems useless. We should just not register the lpe audio thing if we have no irq.

ok

Quoted 13 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1831

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
@@ -1827,6 +1827,13 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))

I think both of these checks can be removed. We won't unmask the interrupts unless lpe is enabled, so the IIR bits will never be set in that case.

Quoted 5 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1836

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+

ok.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +0 -0
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
@@ -1907,6 +1914,13 @@ static irqreturn_t cherryview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
Quoted 9 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 1836

Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +7 -0
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+

ditto

ok

Quoted 10 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t cherryview_irq_handler(int irq, void *arg)

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +8 -0
+	platdev = platform_device_alloc("hdmi-lpe-audio", -1);
+	if (!platdev) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate LPE audio platform device\n");
+		goto err;
+	}
+
+	/* to work-around check_addr in nommu_map_sg() */

What's this about?

Dunno, this was in the original VED series that we used as a baseline. Unless someone has memories from that time, i'll just remove this comment.

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 2 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[0] = 0x%x\n",
+		__func__, (int)(rsc[0].start));

__func__ pointless since DRM_DEBUG alreay adds it. Also saying "rsc.start[0]" in the message doesn't tell anyone anything useful. And I think irq numbers are usually printed in decimal.

Same, this was taken from the VED series, no issue to clean-up.

Quoted 15 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 11 lines
drivers/gpu/drm/i915/i915_irq.c +10 -0
+
+	rsc[1].start    = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE;
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1;
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "hdmi-lpe-audio-mmio";
+
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[1] = 0x%x\n",
+		__func__, (int)(rsc[1].start));

Again "rsc[0].start" doesn't seem like anything useful to print in a debug message. Don't see much point in the whole debug message TBH since the start/end are fixed.

so are you saying we should remove the code or move the level to DRM_INFO - for extra verbose debug?

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/i915/i915_irq.c +21 -0
+
+	ret = platform_device_add_resources(platdev, rsc, 2);
+	if (ret) {
+		DRM_ERROR("Failed to add resource for platform device: %d\n",
+			ret);
+		goto err_put_dev;
+	}
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+
+	if (pdata == NULL) {
+		ret = -ENOMEM;
+		goto err_put_dev;
+	}
+	platdev->dev.platform_data = pdata;
+
+	/* for LPE audio driver's runtime-PM */
+	platdev->dev.parent = dev->dev;
+	ret = platform_device_add(platdev);
+	if (ret) {
+		DRM_ERROR("Failed to add LPE audio platform device: %d\n",
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 4 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
+			ret);
+		goto err_put_dev;
+	}
+	spin_lock_init(&pdata->lpe_audio_slock);

Should init it before adding the device I suppose? It's not used in the patch so hard to say. In general the patch split is not the best due to not being able to see the use of things.

ok. we'll look into this.

Quoted 9 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+static void lpe_audio_platdev_destroy(struct drm_i915_private *dev_priv)
+{
+	if (dev_priv->lpe_audio.platdev) {
+		platform_device_unregister(dev_priv->lpe_audio.platdev);
+		kfree(dev_priv->lpe_audio.platdev->dev.dma_mask);
+	}

I usually prefer

Quoted 8 lines
{
	if (!stuff)
		return;

	other stuff;
}

just to keep the indentation better in check.

ok

Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/i915/i915_irq.c +16 -0
+}
+
+static void lpe_audio_irq_unmask(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	unsigned long irqflags;
+	u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+		I915_LPE_PIPE_B_INTERRUPT |
+		I915_LPE_PIPE_C_INTERRUPT);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	/*
+	 * VLV_IER is already set in the vlv_display_postinstall(),
+	 * we only change VLV_IIR and VLV_IMR
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+	 */
+	dev_priv->irq_mask &= ~val;
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+

Extra newline here for some reason. No such thing in the counterpart.

ok

Quoted 7 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+static int lpe_audio_irq_init(struct drm_i915_private *dev_priv)
+{
+	int irq = dev_priv->lpe_audio.irq;
+
+	WARN_ON(!intel_irqs_enabled(dev_priv));

Could leave a blank like here to make things look less convoluted.

ok

Quoted 7 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
+	irq_set_chip_and_handler_name(irq,
+		&lpe_audio_irqchip,
+		handle_simple_irq,
+		"hdmi_lpe_audio_irq_handler");

Indentation isn't quite right.

ok

Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/i915/i915_irq.c +37 -0
+
+	return irq_set_chip_data(irq, &dev_priv->drm);
+}
+
+/**
+ * intel_lpe_audio_irq_handler() - forwards the LPE audio irq
+ * @dev_priv: the i915 drm device private data
+ *
+ * the LPE Audio irq is forwarded to the irq handler registered by LPE audio
+ * driver.
+ */
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	ret = generic_handle_irq(dev_priv->lpe_audio.irq);
+	if (ret)
+		DRM_ERROR_RATELIMITED("error handling LPE audio irq: %d\n",
+				ret);
+}
+
+/**
+ * intel_lpe_audio_detect() - check & setup lpe audio if present
+ * @dev_priv: the i915 drm device private data
+ *
+ * Detect if lpe audio is present
+ *
+ * Return: true if lpe audio present else Return = false
+ */
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv)
+{
+	int lpe_present = false;
+	struct drm_device *dev = &dev_priv->drm;
+
+	if (HAS_LPE_AUDIO(dev)) {
+		static const struct pci_device_id atom_hdaudio_ids[] = {
+			/* Baytrail */
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f04)},
+			/* Braswell */
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2284)},
+			{}
+		};

Hmm. Maybe I asked already, but could we use a class match instead? There's some kind of HDA class right?

I am not aware of any class, this is really the only means we found to test if the HDaudio controller is disabled or fused out. Maybe a question for Takashi?

Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/i915/i915_irq.c +20 -0
+
+		if (!pci_dev_present(atom_hdaudio_ids)) {
+			DRM_INFO("%s%s\n", "HDaudio controller not detected,",
+				"using LPE audio instead\n");
+			lpe_present = true;
+		}
+	}
+	return lpe_present;
+}
+
+/**
+ * intel_lpe_audio_setup() - setup the bridge between HDMI LPE Audio
+ * driver and i915
+ * @dev_priv: the i915 drm device private data
+ *
+ * set up the minimum required resources for the bridge: irq chip,
+ * platform resource and platform device. i915 device is set as parent
+ * of the new platform device.
+ *
+ * Return: 0 if successful. non-zero if allocation/initialization fails
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 6 lines

+ */

drivers/gpu/drm/i915/i915_irq.c +5 -0
+int intel_lpe_audio_setup(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	dev_priv->lpe_audio.irq = irq_alloc_descs(-1, 0, 1, 0);

aka. irq_alloc_desc() ?

not sure, will look into this.

Quoted 12 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +8 -0
+	if (dev_priv->lpe_audio.irq < 0) {
+		DRM_ERROR("Failed to allocate IRQ desc: %d\n",
+			dev_priv->lpe_audio.irq);
+		ret = dev_priv->lpe_audio.irq;
+		goto err;
+	}
+
+	DRM_DEBUG("%s : irq = %d\n", __func__, dev_priv->lpe_audio.irq);

Another __func__ that's not needed. And we're printing the irq twice now?

ok

Quoted 10 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +7 -0
+
+	ret = lpe_audio_irq_init(dev_priv);
+
+	if (ret) {
+
+		DRM_ERROR("Failed to initialize irqchip for lpe audio: %d\n",
+			ret);

Indentation looks off.

ok

Quoted 12 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +9 -0
+		goto err_free_irq;
+	}
+
+	dev_priv->lpe_audio.platdev = lpe_audio_platdev_create(dev_priv);
+
+	if (IS_ERR(dev_priv->lpe_audio.platdev)) {
+		ret = PTR_ERR(dev_priv->lpe_audio.platdev);
+		DRM_ERROR("Failed to create lpe audio platform device: %d\n",
+			ret);

ditto

ok

Quoted 17 lines

drivers/gpu/drm/i915/i915_irq.c

Quoted 12 lines
drivers/gpu/drm/i915/i915_irq.c +12 -0
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	struct irq_desc *desc;
+
+	desc = IS_LPE_AUDIO_IRQ_VALID(dev_priv) ?
+			irq_to_desc(dev_priv->lpe_audio.irq) : NULL;
+
+	/**
+	 * mask LPE audio irq before destroying
+	 */
+	if (desc)

Seems overly defensive. Should just check if we have the platform device at the start, and otherwise we can assume that all the things we need to free are there.

Quoted 2 lines

This looks racy too. We should unregister the platform device as the first thing, and only then free up the resources and whatnot.

will clean up

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

Re: [RFC PATCH v2 1/8] drm/i915: setup bridge for HDMI LPE audio driver

In reply to Jerome Anand
Quoted 8 lines · Jerome Anand

Enable support for HDMI LPE audio mode on Baytrail and Cherrytrail when HDaudio controller is not detected

Setup minimum required resources during i915_driver_load:
1. Create a platform device to share MMIO/IRQ resources
2. Make the platform device child of i915 device for runtime PM.
3. Create IRQ chip to forward HDMI LPE audio irqs.

Quoted 5 lines

HDMI LPE audio driver (a standalone sound driver) probes the LPE audio device and creates a new sound card.

You need to add an include-stanza to Documentation/gpu/i915.rst, otherwise the kerneldoc won't show up. Please also do some docs for the structures, and then run

$ make htmldocs

to check the output looks reasonable.

Thanks, Daniel

Quoted 567 lines
---
 drivers/gpu/drm/i915/Makefile          |   3 +
 drivers/gpu/drm/i915/i915_drv.c        |  13 +-
 drivers/gpu/drm/i915/i915_drv.h        |  19 ++
 drivers/gpu/drm/i915/i915_irq.c        |  14 ++
 drivers/gpu/drm/i915/i915_reg.h        |   3 +
 drivers/gpu/drm/i915/intel_lpe_audio.c | 357 +++++++++++++++++++++++++++++++++
 include/drm/intel_lpe_audio.h          |  45 +++++
 7 files changed, 452 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lpe_audio.c
 create mode 100644 include/drm/intel_lpe_audio.h
drivers/gpu/drm/i915/Makefile +3 -0
index e6fe004..11f9741 100644
@@ -115,6 +115,9 @@ i915-y += intel_gvt.o
 include $(src)/gvt/Makefile
 endif
 
+# LPE Audio for VLV and CHT
+i915-y += intel_lpe_audio.o
+
 obj-$(CONFIG_DRM_I915) += i915.o
 
 CFLAGS_i915_trace_points.o := -I$(src)
drivers/gpu/drm/i915/i915_drv.c +11 -2
index 31b2b63..ab1e4768 100644
@@ -1141,7 +1141,13 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
 	if (IS_GEN5(dev_priv))
 		intel_gpu_ips_init(dev_priv);
 
-	i915_audio_component_init(dev_priv);
+	if (intel_lpe_audio_detect(dev_priv)) {
+		if (intel_lpe_audio_setup(dev_priv) < 0)
+			DRM_ERROR("failed to setup LPE Audio bridge\n");
+	}
+
+	if (!IS_LPE_AUDIO_ENABLED(dev_priv))
+		i915_audio_component_init(dev_priv);
 
 	/*
 	 * Some ports require correctly set-up hpd registers for detection to
@@ -1159,7 +1165,10 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
  */
 static void i915_driver_unregister(struct drm_i915_private *dev_priv)
 {
-	i915_audio_component_cleanup(dev_priv);
+	if (IS_LPE_AUDIO_ENABLED(dev_priv))
+		intel_lpe_audio_teardown(dev_priv);
+	else
+		i915_audio_component_cleanup(dev_priv);
 
 	intel_gpu_ips_teardown();
 	acpi_video_unregister();
drivers/gpu/drm/i915/i915_drv.h +19 -0
index 91ff3d7..399a8ee 100644
@@ -2087,6 +2087,12 @@ struct drm_i915_private {
 	/* Used to save the pipe-to-encoder mapping for audio */
 	struct intel_encoder *av_enc_map[I915_MAX_PIPES];
 
+	/* necessary resource sharing with HDMI LPE audio driver. */
+	struct {
+		struct platform_device *platdev;
+		int	irq;
+	} lpe_audio;
+
 	/*
 	 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
 	 * will be rejected. Instead look for a better place.
@@ -2827,6 +2833,13 @@ struct drm_i915_cmd_table {
 
 #define HAS_POOLED_EU(dev)	(INTEL_INFO(dev)->has_pooled_eu)
 
+#define HAS_LPE_AUDIO(dev)	(IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+#define IS_LPE_AUDIO_ENABLED(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.platdev != NULL)
+#define IS_LPE_AUDIO_IRQ_VALID(dev_priv) \
+				(__I915__(dev_priv)->lpe_audio.irq >= 0)
+
+
 #define INTEL_PCH_DEVICE_ID_MASK		0xff00
 #define INTEL_PCH_IBX_DEVICE_ID_TYPE		0x3b00
 #define INTEL_PCH_CPT_DEVICE_ID_TYPE		0x1c00
@@ -3579,6 +3592,12 @@ extern int i915_restore_state(struct drm_device *dev);
 void i915_setup_sysfs(struct drm_i915_private *dev_priv);
 void i915_teardown_sysfs(struct drm_i915_private *dev_priv);
 
+/* i915_lpe_audio.c */
+int  intel_lpe_audio_setup(struct drm_i915_private *dev_priv);
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv);
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv);
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
drivers/gpu/drm/i915/i915_irq.c +14 -0
index 6ed5b24..d8f515f 100644
@@ -1827,6 +1827,13 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
@@ -1907,6 +1914,13 @@ static irqreturn_t cherryview_irq_handler(int irq, void *arg)
 		 * signalled in iir */
 		valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
 
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			if (IS_LPE_AUDIO_IRQ_VALID(dev_priv))
+				if (iir & (I915_LPE_PIPE_A_INTERRUPT |
+					I915_LPE_PIPE_B_INTERRUPT |
+					I915_LPE_PIPE_C_INTERRUPT))
+					intel_lpe_audio_irq_handler(dev_priv);
+
 		/*
 		 * VLV_IIR is single buffered, and reflects the level
 		 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
drivers/gpu/drm/i915/i915_reg.h +3 -0
index 8d44cee..fb734f2 100644
@@ -2137,6 +2137,9 @@ enum skl_disp_power_wells {
 #define I915_ASLE_INTERRUPT				(1<<0)
 #define I915_BSD_USER_INTERRUPT				(1<<25)
 
+#define I915_HDMI_LPE_AUDIO_BASE	(VLV_DISPLAY_BASE + 0x65000)
+#define I915_HDMI_LPE_AUDIO_SIZE	0x1000
+
 #define GEN6_BSD_RNCID			_MMIO(0x12198)
 
 #define GEN7_FF_THREAD_MODE		_MMIO(0x20a0)
drivers/gpu/drm/i915/intel_lpe_audio.c new file +357 -0
new file mode 100644
index 0000000..acfe22f
@@ -0,0 +1,357 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Pierre-Louis Bossart <[email protected]>
+ *    Jerome Anand <[email protected]>
+ *    based on VED patches
+ *
+ */
+
+/**
+ * DOC: LPE Audio integration integration for HDMI or DP playback
+ *
+ * Motivation:
+ * Atom platforms (e.g. valleyview and cherryTrail) integrates a DMA-based
+ * interface as an alternative to the traditional HDaudio path. While this
+ * mode is unrelated to the LPE aka SST audio engine, the documentation refers
+ * to this mode as LPE so we keep this notation for the sake of consistency.
+ *
+ * The interface is handled by a separate standalone driver maintained in the
+ * ALSA subsystem for simplicity. To minimize the interaction between the two
+ * subsystems, a bridge is setup between the hdmi-lpe-audio and i915:
+ * 1. Create a platform device to share MMIO/IRQ resources
+ * 2. Make the platform device child of i915 device for runtime PM.
+ * 3. Create IRQ chip to forward the LPE audio irqs.
+ * the hdmi-lpe-audio driver probes the lpe audio device and creates a new
+ * sound card
+ *
+ * Threats:
+ * Due to the restriction in Linux platform device model, user need manually
+ * uninstall the hdmi-lpe-audio driver before uninstalling i915 module,
+ * otherwise we might run into use-after-free issues after i915 removes the
+ * platform device: even though hdmi-lpe-audio driver is released, the modules
+ * is still in "installed" status.
+ *
+ * Implementation:
+ * The MMIO/REG platform resources are created according to the registers
+ * specification.
+ * When forwarding LPE audio irqs, the flow control handler selection depends
+ * on the platform, for example on valleyview handle_simple_irq is enough.
+ *
+ */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/pci.h>
+
+#include "i915_drv.h"
+#include <linux/delay.h>
+#include <drm/intel_lpe_audio.h>
+
+static struct platform_device*
+lpe_audio_platdev_create(struct drm_i915_private *dev_priv)
+{
+	struct drm_device *dev = &dev_priv->drm;
+	int ret;
+	struct resource rsc[2] = {};
+	struct platform_device *platdev;
+	u64 *dma_mask;
+	struct intel_hdmi_lpe_audio_pdata *pdata;
+
+	if (dev_priv->lpe_audio.irq < 0)
+		return ERR_PTR(-EINVAL);
+
+	platdev = platform_device_alloc("hdmi-lpe-audio", -1);
+	if (!platdev) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate LPE audio platform device\n");
+		goto err;
+	}
+
+	/* to work-around check_addr in nommu_map_sg() */
+	dma_mask = kmalloc(sizeof(*platdev->dev.dma_mask), GFP_KERNEL);
+	if (!dma_mask) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate dma_mask\n");
+		goto err_put_dev;
+	}
+	*dma_mask = DMA_BIT_MASK(32);
+	platdev->dev.dma_mask = dma_mask;
+	platdev->dev.coherent_dma_mask = *dma_mask;
+
+	rsc[0].start    = rsc[0].end = dev_priv->lpe_audio.irq;
+	rsc[0].flags    = IORESOURCE_IRQ;
+	rsc[0].name     = "hdmi-lpe-audio-irq";
+
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[0] = 0x%x\n",
+		__func__, (int)(rsc[0].start));
+
+	rsc[1].start    = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE;
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) +
+		I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1;
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "hdmi-lpe-audio-mmio";
+
+	DRM_DEBUG("%s: HDMI_AUDIO rsc.start[1] = 0x%x\n",
+		__func__, (int)(rsc[1].start));
+
+	ret = platform_device_add_resources(platdev, rsc, 2);
+	if (ret) {
+		DRM_ERROR("Failed to add resource for platform device: %d\n",
+			ret);
+		goto err_put_dev;
+	}
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+
+	if (pdata == NULL) {
+		ret = -ENOMEM;
+		goto err_put_dev;
+	}
+	platdev->dev.platform_data = pdata;
+
+	/* for LPE audio driver's runtime-PM */
+	platdev->dev.parent = dev->dev;
+	ret = platform_device_add(platdev);
+	if (ret) {
+		DRM_ERROR("Failed to add LPE audio platform device: %d\n",
+			ret);
+		goto err_put_dev;
+	}
+	spin_lock_init(&pdata->lpe_audio_slock);
+
+	return platdev;
+err_put_dev:
+	platform_device_put(platdev);
+	kfree(dma_mask);
+err:
+	return ERR_PTR(ret);
+}
+
+static void lpe_audio_platdev_destroy(struct drm_i915_private *dev_priv)
+{
+	if (dev_priv->lpe_audio.platdev) {
+		platform_device_unregister(dev_priv->lpe_audio.platdev);
+		kfree(dev_priv->lpe_audio.platdev->dev.dma_mask);
+	}
+}
+
+static void lpe_audio_irq_unmask(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	unsigned long irqflags;
+	u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+		I915_LPE_PIPE_B_INTERRUPT |
+		I915_LPE_PIPE_C_INTERRUPT);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	/*
+	 * VLV_IER is already set in the vlv_display_postinstall(),
+	 * we only change VLV_IIR and VLV_IMR
+	 */
+	dev_priv->irq_mask &= ~val;
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+static void lpe_audio_irq_mask(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = to_i915(dev);
+	unsigned long irqflags;
+	u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+		I915_LPE_PIPE_B_INTERRUPT |
+		I915_LPE_PIPE_C_INTERRUPT);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	/*
+	 * VLV_IER is already set in the vlv_display_postinstall(),
+	 * we only change VLV_IIR and VLV_IMR
+	 */
+	dev_priv->irq_mask |= val;
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+	I915_WRITE(VLV_IIR, val);
+	I915_WRITE(VLV_IIR, val);
+	POSTING_READ(VLV_IIR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+static struct irq_chip lpe_audio_irqchip = {
+	.name = "hdmi_lpe_audio_irqchip",
+	.irq_mask = lpe_audio_irq_mask,
+	.irq_unmask = lpe_audio_irq_unmask,
+};
+
+static int lpe_audio_irq_init(struct drm_i915_private *dev_priv)
+{
+	int irq = dev_priv->lpe_audio.irq;
+
+	WARN_ON(!intel_irqs_enabled(dev_priv));
+	irq_set_chip_and_handler_name(irq,
+		&lpe_audio_irqchip,
+		handle_simple_irq,
+		"hdmi_lpe_audio_irq_handler");
+
+	return irq_set_chip_data(irq, &dev_priv->drm);
+}
+
+/**
+ * intel_lpe_audio_irq_handler() - forwards the LPE audio irq
+ * @dev_priv: the i915 drm device private data
+ *
+ * the LPE Audio irq is forwarded to the irq handler registered by LPE audio
+ * driver.
+ */
+void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	ret = generic_handle_irq(dev_priv->lpe_audio.irq);
+	if (ret)
+		DRM_ERROR_RATELIMITED("error handling LPE audio irq: %d\n",
+				ret);
+}
+
+/**
+ * intel_lpe_audio_detect() - check & setup lpe audio if present
+ * @dev_priv: the i915 drm device private data
+ *
+ * Detect if lpe audio is present
+ *
+ * Return: true if lpe audio present else Return = false
+ */
+int intel_lpe_audio_detect(struct drm_i915_private *dev_priv)
+{
+	int lpe_present = false;
+	struct drm_device *dev = &dev_priv->drm;
+
+	if (HAS_LPE_AUDIO(dev)) {
+		static const struct pci_device_id atom_hdaudio_ids[] = {
+			/* Baytrail */
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f04)},
+			/* Braswell */
+			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2284)},
+			{}
+		};
+
+		if (!pci_dev_present(atom_hdaudio_ids)) {
+			DRM_INFO("%s%s\n", "HDaudio controller not detected,",
+				"using LPE audio instead\n");
+			lpe_present = true;
+		}
+	}
+	return lpe_present;
+}
+
+/**
+ * intel_lpe_audio_setup() - setup the bridge between HDMI LPE Audio
+ * driver and i915
+ * @dev_priv: the i915 drm device private data
+ *
+ * set up the minimum required resources for the bridge: irq chip,
+ * platform resource and platform device. i915 device is set as parent
+ * of the new platform device.
+ *
+ * Return: 0 if successful. non-zero if allocation/initialization fails
+ */
+int intel_lpe_audio_setup(struct drm_i915_private *dev_priv)
+{
+	int ret;
+
+	dev_priv->lpe_audio.irq = irq_alloc_descs(-1, 0, 1, 0);
+	if (dev_priv->lpe_audio.irq < 0) {
+		DRM_ERROR("Failed to allocate IRQ desc: %d\n",
+			dev_priv->lpe_audio.irq);
+		ret = dev_priv->lpe_audio.irq;
+		goto err;
+	}
+
+	DRM_DEBUG("%s : irq = %d\n", __func__, dev_priv->lpe_audio.irq);
+
+	ret = lpe_audio_irq_init(dev_priv);
+
+	if (ret) {
+
+		DRM_ERROR("Failed to initialize irqchip for lpe audio: %d\n",
+			ret);
+		goto err_free_irq;
+	}
+
+	dev_priv->lpe_audio.platdev = lpe_audio_platdev_create(dev_priv);
+
+	if (IS_ERR(dev_priv->lpe_audio.platdev)) {
+		ret = PTR_ERR(dev_priv->lpe_audio.platdev);
+		DRM_ERROR("Failed to create lpe audio platform device: %d\n",
+			ret);
+		goto err_free_irq;
+	}
+
+	return 0;
+err_free_irq:
+	irq_free_desc(dev_priv->lpe_audio.irq);
+err:
+	dev_priv->lpe_audio.irq = -1;
+	dev_priv->lpe_audio.platdev = NULL;
+	return ret;
+}
+
+/**
+ * intel_lpe_audio_teardown() - destroy the bridge between HDMI LPE
+ * audio driver and i915
+ * @dev_priv: the i915 drm device private data
+ *
+ * release all the resources for LPE audio <-> i915 bridge.
+ */
+void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	struct irq_desc *desc;
+
+	desc = IS_LPE_AUDIO_IRQ_VALID(dev_priv) ?
+			irq_to_desc(dev_priv->lpe_audio.irq) : NULL;
+
+	/**
+	 * mask LPE audio irq before destroying
+	 */
+	if (desc)
+		lpe_audio_irq_mask(&desc->irq_data);
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	lpe_audio_platdev_destroy(dev_priv);
+
+	if (desc)
+		irq_free_desc(dev_priv->lpe_audio.irq);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
include/drm/intel_lpe_audio.h new file +45 -0
new file mode 100644
index 0000000..a64c449
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef _INTEL_LPE_AUDIO_H_
+#define _INTEL_LPE_AUDIO_H_
+
+#include <linux/types.h>
+
+#define HDMI_MAX_ELD_BYTES	128
+
+struct intel_hdmi_lpe_audio_eld {
+	int port_id;
+	unsigned char eld_data[HDMI_MAX_ELD_BYTES];
+};
+
+struct intel_hdmi_lpe_audio_pdata {
+	bool notify_pending;
+	int tmds_clock_speed;
+	bool hdmi_connected;
+	struct intel_hdmi_lpe_audio_eld eld;
+	void (*notify_audio_lpe)(void *audio_ptr);
+	spinlock_t lpe_audio_slock;
+};
+
+#endif /* _I915_LPE_AUDIO_H_ */
Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

RFC PATCH v2 2/8 ALSA: add shell for Intel HDMI LPE audio driver

In reply to Jerome Anand

On Baytrail and Cherrytrail, HDaudio may be fused out or disabled by the BIOS. This driver enables an alternate path to the i915 display registers and DMA.

Although there is no hardware path between i915 display and LPE/SST audio clusters, this HDMI capability is referred to in the documentation as "HDMI LPE Audio" so we keep the name for consistency. There is no hardware path or control dependencies with the LPE/SST DSP functionality.

The hdmi-lpe-audio driver will be probed when the i915 driver creates a child platform device.

Since this driver is neither SoC nor PCI, a new x86 folder is added

---
 sound/Kconfig                    |   2 +
 sound/Makefile                   |   2 +-
 sound/x86/Kconfig                |  16 +
 sound/x86/Makefile               |   8 +
 sound/x86/intel_hdmi_lpe_audio.c | 622 +++++++++++++++++++++++++++++++++++
 sound/x86/intel_hdmi_lpe_audio.h | 692 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 1341 insertions(+), 1 deletion(-)
 create mode 100644 sound/x86/Kconfig
 create mode 100644 sound/x86/Makefile
 create mode 100644 sound/x86/intel_hdmi_lpe_audio.c
 create mode 100644 sound/x86/intel_hdmi_lpe_audio.h
sound/Kconfig +2 -0
index 5a240e0..ee2e69a 100644
@@ -108,6 +108,8 @@ source "sound/parisc/Kconfig"
 
 source "sound/soc/Kconfig"
 
+source "sound/x86/Kconfig"
+
 endif # SND
 
 menuconfig SOUND_PRIME
sound/Makefile +1 -1
index c41bdf5..6de45d2 100644
@@ -5,7 +5,7 @@ obj-$(CONFIG_SOUND) += soundcore.o
 obj-$(CONFIG_SOUND_PRIME) += oss/
 obj-$(CONFIG_DMASOUND) += oss/
 obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
-	firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/
+	firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/
 obj-$(CONFIG_SND_AOA) += aoa/
 
 # This one must be compilable even if sound is configured out
sound/x86/Kconfig new file +16 -0
new file mode 100644
index 0000000..182adf3
@@ -0,0 +1,16 @@
+menuconfig SND_X86
+	tristate "X86 sound devices"
+	---help---
+
+	  X86 sound devices that don't fall under SoC or PCI categories
+
+if SND_X86
+
+config HDMI_LPE_AUDIO
+	tristate "HDMI audio without HDaudio on Intel Atom platforms"
+	depends on DRM_I915
+        default n
+        help
+          Choose this option to support HDMI LPE Audio mode
+
+endif	# SND_X86
sound/x86/Makefile new file +8 -0
new file mode 100644
index 0000000..78b2ae1
@@ -0,0 +1,8 @@
+DRIVER_NAME := hdmi_lpe_audio
+
+ccflags-y += -Idrivers/gpu/drm/i915
+
+$(DRIVER_NAME)-objs += \
+	intel_hdmi_lpe_audio.o
+
+obj-$(CONFIG_HDMI_LPE_AUDIO) += $(DRIVER_NAME).o
sound/x86/intel_hdmi_lpe_audio.c new file +622 -0

622 lines not on this page · raw message

sound/x86/intel_hdmi_lpe_audio.h new file +692 -0

692 lines not on this page · raw message

Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

RFC PATCH v2 3/8 ALSA: Add support for hdmi audio driver

In reply to Jerome Anand

Hdmi audio driver based on the child platform device created by gfx driver is implemented.

This audio driver is derived from legacy intel hdmi audio driver.
The interfaces for interaction between gfx and audio are updated and the driver implementation updated to derive interrupts in its own address space based on irq chip framework

---
 sound/x86/Makefile               |    2 +
 sound/x86/intel_hdmi_audio.c     | 1904 ++++++++++++++++++++++++++++++++++++++
 sound/x86/intel_hdmi_audio.h     |  201 ++++
 sound/x86/intel_hdmi_audio_if.c  |  551 +++++++++++
 sound/x86/intel_hdmi_lpe_audio.c |   16 +-
 5 files changed, 2668 insertions(+), 6 deletions(-)
 create mode 100644 sound/x86/intel_hdmi_audio.c
 create mode 100644 sound/x86/intel_hdmi_audio.h
 create mode 100644 sound/x86/intel_hdmi_audio_if.c
sound/x86/Makefile +2 -0
index 78b2ae1..bc074d0 100644
@@ -3,6 +3,8 @@ DRIVER_NAME := hdmi_lpe_audio
 ccflags-y += -Idrivers/gpu/drm/i915
 
 $(DRIVER_NAME)-objs += \
+	intel_hdmi_audio.o \
+	intel_hdmi_audio_if.o \
 	intel_hdmi_lpe_audio.o
 
 obj-$(CONFIG_HDMI_LPE_AUDIO) += $(DRIVER_NAME).o
sound/x86/intel_hdmi_audio.c new file +1904 -0

1,904 lines not on this page · raw message

sound/x86/intel_hdmi_audio.h new file +201 -0

201 lines not on this page · raw message

sound/x86/intel_hdmi_audio_if.c new file +551 -0

551 lines not on this page · raw message

sound/x86/intel_hdmi_lpe_audio.c +10 -6
index f31ab72..16194c6 100644
@@ -36,6 +36,7 @@
 #include <sound/initval.h>
 #include <drm/intel_lpe_audio.h>
 #include "intel_hdmi_lpe_audio.h"
+#include "intel_hdmi_audio.h"
 
 /* globals*/
 struct platform_device *gpdev;
@@ -461,9 +462,9 @@ static void notify_audio_lpe(void *audio_ptr)
 /**
  * hdmi_lpe_audio_probe - start bridge with i915
  *
- * This function is called when the i915 driver creates the hdmi-lpe-audio
- * platform device. Card creation is deferred until a hot plug event is
- * received
+ * This function is called when the i915 driver creates the
+ * hdmi-lpe-audio platform device. Card creation is deferred until a
+ * hot plug event is received
  */
 static int hdmi_lpe_audio_probe(struct platform_device *pdev)
 {
@@ -505,8 +506,8 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
 		(unsigned int)res_mmio->start, (unsigned int)res_mmio->end);
 
 	mmio_start = ioremap_nocache(res_mmio->start,
-				(size_t)((res_mmio->end - res_mmio->start)
-						+ 1));
+				(size_t)((res_mmio->end -
+					res_mmio->start) + 1));
 	if (!mmio_start) {
 		pr_err("Could not get ioremap\n");
 		return -EACCES;
@@ -556,11 +557,12 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, ctx);
 
+	ret = hdmi_audio_probe((void *)pdev);
+
 	pr_debug("hdmi lpe audio: setting pin eld notify callback\n");
 
 	spin_lock_irqsave(&pdata->lpe_audio_slock, flag_irq);
 	pdata->notify_audio_lpe = notify_audio_lpe;
-
 	if (pdata->notify_pending) {
 
 		pr_debug("%s: handle pending notification\n", __func__);
@@ -584,6 +586,8 @@ static int hdmi_lpe_audio_remove(struct platform_device *pdev)
 
 	pr_debug("Enter %s\n", __func__);
 
+	hdmi_audio_remove(pdev);
+
 	/* get context, release resources */
 	ctx = platform_get_drvdata(pdev);
 	iounmap(ctx->mmio_start);
Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

RFC PATCH v2 4/8 drm/i915: Add support for enabling/disabling hdmi audio interrupts

In reply to Jerome Anand

API definitions for enabling/disabling hdmi audio interrupts in different hdmi pipes are implemented.

---
 drivers/gpu/drm/i915/i915_irq.c  | 69 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_drv.h |  2 ++
 2 files changed, 71 insertions(+)
drivers/gpu/drm/i915/i915_irq.c +69 -0
index d8f515f..1e3663f 100644
@@ -2867,6 +2867,67 @@ static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
 }
 
+/* Added for HDMI Audio */
+int i915_enable_hdmi_audio_int(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	u32 imr, int_bit;
+	int pipe = -1;
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	imr = I915_READ(VLV_IMR);
+
+	if (IS_CHERRYVIEW(&dev_priv->drm)) {
+		pipe = PIPE_C;
+		int_bit = (pipe ? (I915_LPE_PIPE_B_INTERRUPT >>
+					((pipe - 1) * 9)) :
+					I915_LPE_PIPE_A_INTERRUPT);
+		imr &= ~int_bit;
+	} else {
+		/* Audio is on Stream A but uses HDMI PIPE B */
+		pipe = PIPE_B;
+		imr &= ~I915_LPE_PIPE_B_INTERRUPT;
+	}
+
+	I915_WRITE(VLV_IMR, imr);
+	I915_WRITE(VLV_IER, ~imr);
+	POSTING_READ(VLV_IER);
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+
+	return 0;
+}
+
+/* Added for HDMI Audio */
+int i915_disable_hdmi_audio_int(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	u32 imr, int_bit;
+	int pipe = -1;
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+	imr = I915_READ(VLV_IMR);
+
+	if (IS_CHERRYVIEW(&dev_priv->drm)) {
+		pipe = PIPE_C;
+		int_bit = (pipe ? (I915_LPE_PIPE_B_INTERRUPT >>
+					((pipe - 1) * 9)) :
+					I915_LPE_PIPE_A_INTERRUPT);
+		imr |= int_bit;
+	} else {
+		pipe = PIPE_B;
+		imr |= I915_LPE_PIPE_B_INTERRUPT;
+	}
+
+	I915_WRITE(VLV_IER, ~imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+
+	return 0;
+}
+
 static bool
 ipehr_is_semaphore_wait(struct intel_engine_cs *engine, u32 ipehr)
 {
@@ -3364,6 +3425,14 @@ static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
 
 	WARN_ON(dev_priv->irq_mask != ~0);
 
+	if (IS_LPE_AUDIO_ENABLED(dev_priv)) {
+		u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+			I915_LPE_PIPE_B_INTERRUPT |
+			I915_LPE_PIPE_C_INTERRUPT);
+
+		enable_mask |= val;
+	}
+
 	dev_priv->irq_mask = ~enable_mask;
 
 	GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
drivers/gpu/drm/i915/intel_drv.h +2 -0
index 30e3f49..e6504ea 100644
@@ -1116,6 +1116,8 @@ void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv);
 u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask);
 void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv);
 void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv);
+int i915_enable_hdmi_audio_int(struct drm_i915_private *dev_priv);
+int i915_disable_hdmi_audio_int(struct drm_i915_private *dev_priv);
 static inline bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
 {
 	/*
Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

Re: [RFC PATCH v2 4/8] drm/i915: Add support for enabling/disabling hdmi audio interrupts

Quoted 23 lines · Jerome Anand

API definitions for enabling/disabling hdmi audio interrupts in different hdmi pipes are implemented.

---
 drivers/gpu/drm/i915/i915_irq.c  | 69 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_drv.h |  2 ++
 2 files changed, 71 insertions(+)
drivers/gpu/drm/i915/i915_irq.c +6 -0
index d8f515f..1e3663f 100644
@@ -2867,6 +2867,67 @@ static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
 	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
 }
 
+/* Added for HDMI Audio */
+int i915_enable_hdmi_audio_int(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	u32 imr, int_bit;
+	int pipe = -1;

drivers/gpu/drm/i915/i915_irq.c static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe) · line 2885

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +10 -0
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	imr = I915_READ(VLV_IMR);
+
+	if (IS_CHERRYVIEW(&dev_priv->drm)) {
+		pipe = PIPE_C;
+		int_bit = (pipe ? (I915_LPE_PIPE_B_INTERRUPT >>
+					((pipe - 1) * 9)) :
+					I915_LPE_PIPE_A_INTERRUPT);

Either parametrize the I915_LPE_PIPE_INTERRUPT macro, or just have eg. a switch here.

But the bigger issue here is the mess with selecting the right bit. I assume it should either depend on the pipe or port. I can't figure out what is going on here.

And actually I don't understand why we even need this function. The irqchip should take care to unmask all the interrupts when the audio device does its request_irq.

Quoted 49 lines
drivers/gpu/drm/i915/i915_irq.c +45 -0
+		imr &= ~int_bit;
+	} else {
+		/* Audio is on Stream A but uses HDMI PIPE B */
+		pipe = PIPE_B;
+		imr &= ~I915_LPE_PIPE_B_INTERRUPT;
+	}
+
+	I915_WRITE(VLV_IMR, imr);
+	I915_WRITE(VLV_IER, ~imr);
+	POSTING_READ(VLV_IER);
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+
+	return 0;
+}
+
+/* Added for HDMI Audio */
+int i915_disable_hdmi_audio_int(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	u32 imr, int_bit;
+	int pipe = -1;
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+	imr = I915_READ(VLV_IMR);
+
+	if (IS_CHERRYVIEW(&dev_priv->drm)) {
+		pipe = PIPE_C;
+		int_bit = (pipe ? (I915_LPE_PIPE_B_INTERRUPT >>
+					((pipe - 1) * 9)) :
+					I915_LPE_PIPE_A_INTERRUPT);
+		imr |= int_bit;
+	} else {
+		pipe = PIPE_B;
+		imr |= I915_LPE_PIPE_B_INTERRUPT;
+	}
+
+	I915_WRITE(VLV_IER, ~imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+
+	return 0;
+}
+
 static bool
 ipehr_is_semaphore_wait(struct intel_engine_cs *engine, u32 ipehr)
 {

drivers/gpu/drm/i915/i915_irq.c static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) · line 3431

Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
@@ -3364,6 +3425,14 @@ static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
 
 	WARN_ON(dev_priv->irq_mask != ~0);
 
+	if (IS_LPE_AUDIO_ENABLED(dev_priv)) {
+		u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+			I915_LPE_PIPE_B_INTERRUPT |
+			I915_LPE_PIPE_C_INTERRUPT);

'val' seems like a rather pointless local variable.

Quoted 22 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
+
+		enable_mask |= val;
+	}
+
 	dev_priv->irq_mask = ~enable_mask;
 
 	GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
drivers/gpu/drm/i915/intel_drv.h +2 -0
index 30e3f49..e6504ea 100644
@@ -1116,6 +1116,8 @@ void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv);
 u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask);
 void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv);
 void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv);
+int i915_enable_hdmi_audio_int(struct drm_i915_private *dev_priv);
+int i915_disable_hdmi_audio_int(struct drm_i915_private *dev_priv);
 static inline bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
 {
 	/*
Signature · 1 line
2.9.3
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw

Re: [RFC PATCH v2 4/8] drm/i915: Add support for enabling/disabling hdmi audio interrupts

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/i915/i915_irq.c +11 -0
+/* Added for HDMI Audio */
+int i915_enable_hdmi_audio_int(struct drm_i915_private *dev_priv)
+{
+	unsigned long irqflags;
+	u32 imr, int_bit;
+	int pipe = -1;
+
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	imr = I915_READ(VLV_IMR);
+
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe) · line 2885

Quoted 5 lines
drivers/gpu/drm/i915/i915_irq.c +5 -0
+	if (IS_CHERRYVIEW(&dev_priv->drm)) {
+		pipe = PIPE_C;
+		int_bit = (pipe ? (I915_LPE_PIPE_B_INTERRUPT >>
+					((pipe - 1) * 9)) :
+					I915_LPE_PIPE_A_INTERRUPT);

Either parametrize the I915_LPE_PIPE_INTERRUPT macro, or just have eg. a switch here.

ok

Quoted 8 lines

But the bigger issue here is the mess with selecting the right bit. I assume it should either depend on the pipe or port. I can't figure out what is going on here.

And actually I don't understand why we even need this function. The irqchip should take care to unmask all the interrupts when the audio device does its request_irq.

agree, it's not clear to me either. I'll work with Jerome to figure out if/how this can be removed.

Quoted 11 lines

drivers/gpu/drm/i915/i915_irq.c static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) · line 3431

Quoted 8 lines
drivers/gpu/drm/i915/i915_irq.c +4 -0
@@ -3364,6 +3425,14 @@ static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
 
 	WARN_ON(dev_priv->irq_mask != ~0);
 
+	if (IS_LPE_AUDIO_ENABLED(dev_priv)) {
+		u32 val = (I915_LPE_PIPE_A_INTERRUPT |
+			I915_LPE_PIPE_B_INTERRUPT |
+			I915_LPE_PIPE_C_INTERRUPT);

'val' seems like a rather pointless local variable.

Quoted 2 lines

drivers/gpu/drm/i915/i915_irq.c static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) · line 3433

Quoted 2 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
+
+		enable_mask |= val;

indeed, will fix.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#12 lore raw

RFC PATCH v2 5/8 drm/i915: Add support for audio driver notifications

In reply to Jerome Anand

Notifiations like mode change, hot plug and edid to the audio driver are added. This is inturn used by the audio driver for its functionality.
A new interface file capturing the notifications needed by the audio driver is added

---
 drivers/gpu/drm/i915/i915_drv.h        |  3 +++
 drivers/gpu/drm/i915/intel_audio.c     |  8 ++++++
 drivers/gpu/drm/i915/intel_hdmi.c      | 18 ++++++++++++-
 drivers/gpu/drm/i915/intel_lpe_audio.c | 49 ++++++++++++++++++++++++++++++++++
 include/drm/intel_lpe_audio.h          |  1 +
 5 files changed, 78 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +3 -0
index 399a8ee..51a6d71 100644
@@ -3597,6 +3597,9 @@ int  intel_lpe_audio_setup(struct drm_i915_private *dev_priv);
 void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv);
 void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv);
 int intel_lpe_audio_detect(struct drm_i915_private *dev_priv);
+void intel_lpe_audio_notify(struct drm_i915_private *dev_priv,
+			void *eld, int port, int tmds_clk_speed,
+			bool connected);
 
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
drivers/gpu/drm/i915/intel_audio.c +8 -0
index 9583f43..61a9a98 100644
@@ -24,6 +24,7 @@
 #include <linux/kernel.h>
 #include <linux/component.h>
 #include <drm/i915_component.h>
+#include <drm/intel_lpe_audio.h>
 #include "intel_drv.h"
 
 #include <drm/drmP.h>
@@ -528,6 +529,10 @@ void intel_audio_codec_enable(struct intel_encoder *intel_encoder)
 	if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify)
 		acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr,
 						 (int) port, (int) pipe);
+
+	if (IS_LPE_AUDIO_ENABLED(dev_priv))
+		intel_lpe_audio_notify(dev_priv, connector->eld, port,
+			crtc->config->port_clock, true);
 }
 
 /**
@@ -561,6 +566,9 @@ void intel_audio_codec_disable(struct intel_encoder *intel_encoder)
 	if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify)
 		acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr,
 						 (int) port, (int) pipe);
+
+	if (IS_LPE_AUDIO_ENABLED(dev_priv))
+		intel_lpe_audio_notify(dev_priv, NULL, port, 0, true);
 }
 
 /**
drivers/gpu/drm/i915/intel_hdmi.c +17 -1
index 8d46f58..0e20788 100644
@@ -36,6 +36,7 @@
 #include <drm/drm_edid.h>
 #include "intel_drv.h"
 #include <drm/i915_drm.h>
+#include <drm/intel_lpe_audio.h>
 #include "i915_drv.h"
 
 static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
@@ -1501,9 +1502,24 @@ intel_hdmi_detect(struct drm_connector *connector, bool force)
 
 		hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
 		status = connector_status_connected;
-	} else
+
+		i915_enable_hdmi_audio_int(dev_priv);
+
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			intel_lpe_audio_notify(dev_priv,
+				connector->eld, 0,
+				0, true);
+	} else {
 		status = connector_status_disconnected;
 
+		i915_disable_hdmi_audio_int(dev_priv);
+
+		if (IS_LPE_AUDIO_ENABLED(dev_priv))
+			intel_lpe_audio_notify(dev_priv,
+				NULL, 0,
+				0, false);
+	}
+
 	intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
 
 	return status;
drivers/gpu/drm/i915/intel_lpe_audio.c +49 -0

52 lines not on this page · raw message

include/drm/intel_lpe_audio.h +1 -0
index a64c449..952de05 100644
@@ -25,6 +25,7 @@
 #define _INTEL_LPE_AUDIO_H_
 
 #include <linux/types.h>
+#include <linux/spinlock_types.h>
 
 #define HDMI_MAX_ELD_BYTES	128
 
Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

RFC PATCH v2 6/8 hdmi_audio: Improve position reporting Using a hw register to calculate sub-period position reports.

In reply to Jerome Anand

This makes PulseAudio happier.

---
 sound/x86/intel_hdmi_audio.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
sound/x86/intel_hdmi_audio.c +11 -1
index 2dc0881..0802b29 100644
@@ -1491,6 +1491,8 @@ static snd_pcm_uframes_t snd_intelhad_pcm_pointer(
 {
 	struct snd_intelhad *intelhaddata;
 	u32 bytes_rendered = 0;
+	u32 t;
+	int buf_id;
 
 	/* pr_debug("snd_intelhad_pcm_pointer called\n"); */
 
@@ -1501,6 +1503,14 @@ static snd_pcm_uframes_t snd_intelhad_pcm_pointer(
 		return SNDRV_PCM_POS_XRUN;
 	}
 
+	buf_id = intelhaddata->curr_buf % 4;
+	had_read_register(AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH), &t);
+	if (t == 0) {
+		pr_debug("discovered buffer done for buf %d\n", buf_id);
+		/* had_process_buffer_done(intelhaddata); */
+	}
+	t = intelhaddata->buf_info[buf_id].buf_size - t;
+
 	if (intelhaddata->stream_info.buffer_rendered)
 		div_u64_rem(intelhaddata->stream_info.buffer_rendered,
 			intelhaddata->stream_info.ring_buf_size,
@@ -1508,7 +1518,7 @@ static snd_pcm_uframes_t snd_intelhad_pcm_pointer(
 
 	intelhaddata->stream_info.buffer_ptr = bytes_to_frames(
 						substream->runtime,
-						bytes_rendered);
+						bytes_rendered + t);
 	return intelhaddata->stream_info.buffer_ptr;
 }
 
Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw

RFC PATCH v2 7/8 hdmi_audio: Fixup some monitor

In reply to Jerome Anand

I think this change was given to us, and they claimed it fixed an issue on some monitor brand. I'm not sure what this patch actually does.

---
 sound/x86/intel_hdmi_audio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/x86/intel_hdmi_audio.c +2 -2
index 0802b29..7fd90ff 100644
@@ -337,6 +337,7 @@ static void snd_intelhad_reset_audio_v2(u8 reset)
 static int had_prog_status_reg(struct snd_pcm_substream *substream,
 			struct snd_intelhad *intelhaddata)
 {
+	union aud_cfg cfg_val = {.cfg_regval = 0};
 	union aud_ch_status_0 ch_stat0 = {.status_0_regval = 0};
 	union aud_ch_status_1 ch_stat1 = {.status_1_regval = 0};
 	int format;
@@ -347,6 +348,7 @@ static int had_prog_status_reg(struct snd_pcm_substream *substream,
 						IEC958_AES0_NONAUDIO)>>1;
 	ch_stat0.status_0_regx.clk_acc = (intelhaddata->aes_bits &
 						IEC958_AES3_CON_CLOCK)>>4;
+	cfg_val.cfg_regx.val_bit = ch_stat0.status_0_regx.lpcm_id;
 
 	switch (substream->runtime->rate) {
 	case AUD_SAMPLE_RATE_32:
@@ -426,7 +428,6 @@ int snd_intelhad_prog_audio_ctrl_v2(struct snd_pcm_substream *substream,
 	else
 		cfg_val.cfg_regx_v2.layout = LAYOUT1;
 
-	cfg_val.cfg_regx_v2.val_bit = 1;
 	had_write_register(AUD_CONFIG, cfg_val.cfg_regval);
 	return 0;
 }
@@ -482,7 +483,6 @@ int snd_intelhad_prog_audio_ctrl_v1(struct snd_pcm_substream *substream,
 
 	}
 
-	cfg_val.cfg_regx.val_bit = 1;
 	had_write_register(AUD_CONFIG, cfg_val.cfg_regval);
 	return 0;
 }
Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#15 lore raw

RFC PATCH v2 8/8 hdmi_audio: continue audio playback even when display resolution changes

In reply to Jerome Anand

When the display resolution changes, the drm disables the display pipes due to which audio rendering stops. At this time, we need to ensure the existing audio pointers and buffers are cleared out so that the playback can restarted once the display pipe is enabled with a different N/CTS values

---
 sound/x86/intel_hdmi_audio.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
sound/x86/intel_hdmi_audio.c +18 -3
index 7fd90ff..8415a32 100644
@@ -43,6 +43,7 @@ static DEFINE_MUTEX(had_mutex);
 static int hdmi_card_index = SNDRV_DEFAULT_IDX1;
 static char *hdmi_card_id = SNDRV_DEFAULT_STR1;
 static struct snd_intelhad *had_data;
+static int underrun_count;
 
 module_param(hdmi_card_index, int, 0444);
 MODULE_PARM_DESC(hdmi_card_index,
@@ -1114,6 +1115,7 @@ static int snd_intelhad_open(struct snd_pcm_substream *substream)
 	intelhaddata = snd_pcm_substream_chip(substream);
 	had_stream = intelhaddata->private_data;
 	runtime = substream->runtime;
+	underrun_count = 0;
 
 	pm_runtime_get(intelhaddata->dev);
 
@@ -1505,10 +1507,23 @@ static snd_pcm_uframes_t snd_intelhad_pcm_pointer(
 
 	buf_id = intelhaddata->curr_buf % 4;
 	had_read_register(AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH), &t);
-	if (t == 0) {
-		pr_debug("discovered buffer done for buf %d\n", buf_id);
-		/* had_process_buffer_done(intelhaddata); */
+
+	if ((t == 0) || (t == ((u32)-1L))) {
+		underrun_count++;
+		pr_debug("discovered buffer done for buf %d, count = %d\n",
+			buf_id, underrun_count);
+
+		if (underrun_count > (HAD_MIN_PERIODS/2)) {
+			pr_debug("assume audio_codec_reset, underrun = %d - do xrun\n",
+				underrun_count);
+			underrun_count = 0;
+			return SNDRV_PCM_POS_XRUN;
+		}
+	} else {
+		/* Reset Counter */
+		underrun_count = 0;
 	}
+
 	t = intelhaddata->buf_info[buf_id].buf_size - t;
 
 	if (intelhaddata->stream_info.buffer_rendered)
Signature · 5 lines
2.9.3
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#16 lore raw

✗ Fi.CI.BAT: warning for Add support for Legacy Hdmi audio

In reply to Jerome Anand
== Series Details ==

== Series Details ==

Series: Add support for Legacy Hdmi audio
URL : https://patchwork.freedesktop.org/series/13661/
State : warning

== Summary ==

Series 13661v1 Add support for Legacy Hdmi audio
https://patchwork.freedesktop.org/api/1.0/series/13661/revisions/1/mbox/

Test drv_module_reload_basic:

                skip       -> PASS       (fi-skl-6770hq)
Test kms_flip:
        Subgroup basic-flip-vs-dpms:
                pass       -> DMESG-WARN (fi-snb-2520m)
        Subgroup basic-flip-vs-modeset:
                dmesg-warn -> PASS       (fi-skl-6770hq)
Test kms_pipe_crc_basic:
        Subgroup nonblocking-crc-pipe-a:
                pass       -> DMESG-WARN (fi-ilk-650)
Test kms_psr_sink_crc:
        Subgroup psr_basic:
                dmesg-warn -> PASS       (fi-skl-6700hq)
Test vgem_basic:
        Subgroup unload:
                skip       -> PASS       (fi-hsw-4770)
                skip       -> PASS       (fi-kbl-7200u)
fi-bdw-5557u     total:248  pass:232  dwarn:0   dfail:0   fail:0   skip:16 
fi-bsw-n3050     total:248  pass:205  dwarn:0   dfail:0   fail:0   skip:43 
fi-byt-j1900     total:248  pass:213  dwarn:2   dfail:0   fail:1   skip:32 
fi-byt-n2820     total:248  pass:211  dwarn:0   dfail:0   fail:1   skip:36 
fi-hsw-4770      total:248  pass:225  dwarn:0   dfail:0   fail:0   skip:23 
fi-hsw-4770r     total:248  pass:225  dwarn:0   dfail:0   fail:0   skip:23 
fi-ilk-650       total:248  pass:184  dwarn:1   dfail:0   fail:2   skip:61 
fi-ivb-3520m     total:248  pass:222  dwarn:0   dfail:0   fail:0   skip:26 
fi-ivb-3770      total:248  pass:222  dwarn:0   dfail:0   fail:0   skip:26 
fi-kbl-7200u     total:248  pass:223  dwarn:0   dfail:0   fail:0   skip:25 
fi-skl-6260u     total:248  pass:233  dwarn:0   dfail:0   fail:0   skip:15 
fi-skl-6700hq    total:248  pass:225  dwarn:0   dfail:0   fail:0   skip:23 
fi-skl-6700k     total:248  pass:222  dwarn:1   dfail:0   fail:0   skip:25 
fi-skl-6770hq    total:248  pass:231  dwarn:1   dfail:0   fail:1   skip:15 
fi-snb-2520m     total:248  pass:210  dwarn:1   dfail:0   fail:0   skip:37 
fi-snb-2600      total:248  pass:210  dwarn:0   dfail:0   fail:0   skip:38 

fi-bxt-t5700 failed to collect. IGT log at Patchwork_2693/fi-bxt-t5700/igt.log

Results at /archive/results/CI_IGT_test/Patchwork_2693/

14740bb25ec36fe4ce8042af3eb48aeb45e5bc13 drm-intel-nightly: 2016y-10m-12d-16h-18m-24s UTC integration manifest f326d3c hdmi_audio: continue audio playback even when display resolution changes
4a31c16 hdmi_audio: Fixup some monitor
0f6f765 hdmi_audio: Improve position reporting Using a hw register to calculate sub-period position reports. 98ed9c5 drm/i915: Add support for audio driver notifications
f5a7592 drm/i915: Add support for enabling/disabling hdmi audio interrupts
c8bed7a ALSA: Add support for hdmi audio driver
d8bab54 ALSA: add shell for Intel HDMI LPE audio driver
daa4014 drm/i915: setup bridge for HDMI LPE audio driver

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#17 lore raw

Re: ✗ Fi.CI.BAT: warning for Add support for Legacy Hdmi audio

Quoted 8 lines

== Series Details ==

Series: Add support for Legacy Hdmi audio
URL : https://patchwork.freedesktop.org/series/13661/
State : warning

== Summary ==

Quoted 8 lines

Series 13661v1 Add support for Legacy Hdmi audio
https://patchwork.freedesktop.org/api/1.0/series/13661/revisions/1/mbox/

Test drv_module_reload_basic:

                skip       -> PASS       (fi-skl-6770hq)
Test kms_flip:
        Subgroup basic-flip-vs-dpms:
                pass       -> DMESG-WARN (fi-snb-2520m)

[drm:drm_edid_block_valid] *ERROR* EDID checksum is invalid, remainder is 236 [drm:drm_edid_block_valid] *ERROR* EDID checksum is invalid, remainder is 236

Quoted 5 lines
        Subgroup basic-flip-vs-modeset:
                dmesg-warn -> PASS       (fi-skl-6770hq)
Test kms_pipe_crc_basic:
        Subgroup nonblocking-crc-pipe-a:
                pass       -> DMESG-WARN (fi-ilk-650)

[drm:intel_pch_fifo_underrun_irq_handler [i915]] *ERROR* PCH transcoder B FIFO underrun [drm:intel_cpu_fifo_underrun_irq_handler [i915]] *ERROR* CPU pipe B FIFO underrun

Quoted 28 lines

Test kms_psr_sink_crc:

        Subgroup psr_basic:
                dmesg-warn -> PASS       (fi-skl-6700hq)
Test vgem_basic:
        Subgroup unload:
                skip       -> PASS       (fi-hsw-4770)
                skip       -> PASS       (fi-kbl-7200u)
fi-bdw-5557u     total:248  pass:232  dwarn:0   dfail:0   fail:0   skip:16
fi-bsw-n3050     total:248  pass:205  dwarn:0   dfail:0   fail:0   skip:43
fi-byt-j1900     total:248  pass:213  dwarn:2   dfail:0   fail:1   skip:32
fi-byt-n2820     total:248  pass:211  dwarn:0   dfail:0   fail:1   skip:36
fi-hsw-4770      total:248  pass:225  dwarn:0   dfail:0   fail:0   skip:23
fi-hsw-4770r     total:248  pass:225  dwarn:0   dfail:0   fail:0   skip:23
fi-ilk-650       total:248  pass:184  dwarn:1   dfail:0   fail:2   skip:61
fi-ivb-3520m     total:248  pass:222  dwarn:0   dfail:0   fail:0   skip:26
fi-ivb-3770      total:248  pass:222  dwarn:0   dfail:0   fail:0   skip:26
fi-kbl-7200u     total:248  pass:223  dwarn:0   dfail:0   fail:0   skip:25
fi-skl-6260u     total:248  pass:233  dwarn:0   dfail:0   fail:0   skip:15
fi-skl-6700hq    total:248  pass:225  dwarn:0   dfail:0   fail:0   skip:23
fi-skl-6700k     total:248  pass:222  dwarn:1   dfail:0   fail:0   skip:25
fi-skl-6770hq    total:248  pass:231  dwarn:1   dfail:0   fail:1   skip:15
fi-snb-2520m     total:248  pass:210  dwarn:1   dfail:0   fail:0   skip:37
fi-snb-2600      total:248  pass:210  dwarn:0   dfail:0   fail:0   skip:38

fi-bxt-t5700 failed to collect. IGT log at Patchwork_2693/fi-bxt-t5700/igt.log

Results at /archive/results/CI_IGT_test/Patchwork_2693/

Quoted 11 lines

14740bb25ec36fe4ce8042af3eb48aeb45e5bc13 drm-intel-nightly: 2016y-10m- 12d-16h-18m-24s UTC integration manifest f326d3c hdmi_audio: continue audio playback even when display resolution changes
4a31c16 hdmi_audio: Fixup some monitor
0f6f765 hdmi_audio: Improve position reporting Using a hw register to calculate sub-period position reports.
98ed9c5 drm/i915: Add support for audio driver notifications f5a7592 drm/i915: Add support for enabling/disabling hdmi audio interrupts c8bed7a ALSA: Add support for hdmi audio driver
d8bab54 ALSA: add shell for Intel HDMI LPE audio driver daa4014 drm/i915: setup bridge for HDMI LPE audio driver

Jani Saarinen
Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#18 lore raw
In reply to Jerome Anand
Quoted 2 lines · Jerome Anand

Legacy Hdmi audio drivers are added.
Added support for audio/ gfx interface using irq chip framework

Just discussed this with Rakesh here at LPC and also with Mark Brown and since earlier this years there's no a standard way to do this in include/sound/hdmi-codec.h. I think it'd be good to port this over to this new interface before merging. And if it makes sense (and ofc afterwards when there's time) to port over the existing i915_component.h to hdmi-codec.h.

Cheers, Daniel

Quoted 51 lines

Jerome Anand (8):
drm/i915: setup bridge for HDMI LPE audio driver
ALSA: add shell for Intel HDMI LPE audio driver
ALSA: Add support for hdmi audio driver
drm/i915: Add support for enabling/disabling hdmi audio interrupts drm/i915: Add support for audio driver notifications
hdmi_audio: Improve position reporting Using a hw register to
calculate sub-period position reports.
hdmi_audio: Fixup some monitor
hdmi_audio: continue audio playback even when display resolution
changes

 drivers/gpu/drm/i915/Makefile          |    3 +
 drivers/gpu/drm/i915/i915_drv.c        |   13 +-
 drivers/gpu/drm/i915/i915_drv.h        |   22 +
 drivers/gpu/drm/i915/i915_irq.c        |   83 ++
 drivers/gpu/drm/i915/i915_reg.h        |    3 +
 drivers/gpu/drm/i915/intel_audio.c     |    8 +
 drivers/gpu/drm/i915/intel_drv.h       |    2 +
 drivers/gpu/drm/i915/intel_hdmi.c      |   18 +-
 drivers/gpu/drm/i915/intel_lpe_audio.c |  406 +++++++
 include/drm/intel_lpe_audio.h          |   46 +
 sound/Kconfig                          |    2 +
 sound/Makefile                         |    2 +-
 sound/x86/Kconfig                      |   16 +
 sound/x86/Makefile                     |   10 +
 sound/x86/intel_hdmi_audio.c           | 1929 ++++++++++++++++++++++++++++++++
 sound/x86/intel_hdmi_audio.h           |  201 ++++
 sound/x86/intel_hdmi_audio_if.c        |  551 +++++++++
 sound/x86/intel_hdmi_lpe_audio.c       |  626 +++++++++++
 sound/x86/intel_hdmi_lpe_audio.h       |  692 ++++++++++++
 19 files changed, 4629 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_lpe_audio.c
 create mode 100644 include/drm/intel_lpe_audio.h
 create mode 100644 sound/x86/Kconfig
 create mode 100644 sound/x86/Makefile
 create mode 100644 sound/x86/intel_hdmi_audio.c
 create mode 100644 sound/x86/intel_hdmi_audio.h
 create mode 100644 sound/x86/intel_hdmi_audio_if.c
 create mode 100644 sound/x86/intel_hdmi_lpe_audio.c
 create mode 100644 sound/x86/intel_hdmi_lpe_audio.h

--
2.9.3

base-commit: 2fbc239494fa3883e164cc89d35f54d22f0c9e1f
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#19 lore raw
Quoted 10 lines · Daniel Vetter
Quoted 2 lines · Jerome Anand

Legacy Hdmi audio drivers are added.
Added support for audio/ gfx interface using irq chip framework

Just discussed this with Rakesh here at LPC and also with Mark Brown and since earlier this years there's no a standard way to do this in include/sound/hdmi-codec.h. I think it'd be good to port this over to this new interface before merging. And if it makes sense (and ofc afterwards when there's time) to port over the existing i915_component.h to hdmi-codec.h.

I am all for convergence when it makes sense but I don't see how hdmi-codec.h provides equivalent functionality for BYT/CHT with what was suggested in this patchset -derived from VED patches- and discussed earlier with intel-gfx folks, specifically how LPE pipe interrupts are masked/unmasked and passed to the audio driver? The BYT/CHT HDMI functionality is also not modeled as an ASoC codec - which seems a dependency from the comments in hdmi-codec.h - since it's really part of the i915 hardware and exposed only as a set of registers+DMA, without any serial link interface typically needed for an external device or the internal HDAudio-display link.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#20 lore raw
Quoted 5 lines · Pierre-Louis Bossart

I am all for convergence when it makes sense but I don't see how hdmi-codec.h provides equivalent functionality for BYT/CHT with what was suggested in this patchset -derived from VED patches- and discussed earlier with intel-gfx folks, specifically how LPE pipe interrupts are masked/unmasked and passed to the audio driver? The BYT/CHT HDMI

Without knowing what these things are it's hard to comment but it does seem that if Intel has a reasonable use case for them then so too will other vendors at some point.

Quoted 5 lines

functionality is also not modeled as an ASoC codec - which seems a dependency from the comments in hdmi-codec.h - since it's really part of the i915 hardware and exposed only as a set of registers+DMA, without any serial link interface typically needed for an external device or the internal HDAudio-display link.

None of which is at all unusal. The Intel hardware really doesn't seem like the sort of special snowflake that people appear to believe it to be.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#21 lore raw
Quoted 18 lines · Mark Brown
Quoted 5 lines · Pierre-Louis Bossart

I am all for convergence when it makes sense but I don't see how hdmi-codec.h provides equivalent functionality for BYT/CHT with what was suggested in this patchset -derived from VED patches- and discussed earlier with intel-gfx folks, specifically how LPE pipe interrupts are masked/unmasked and passed to the audio driver? The BYT/CHT HDMI

Without knowing what these things are it's hard to comment but it does seem that if Intel has a reasonable use case for them then so too will other vendors at some point.

Quoted 5 lines

functionality is also not modeled as an ASoC codec - which seems a dependency from the comments in hdmi-codec.h - since it's really part of the i915 hardware and exposed only as a set of registers+DMA, without any serial link interface typically needed for an external device or the internal HDAudio-display link.

Quoted 3 lines

None of which is at all unusal. The Intel hardware really doesn't seem like the sort of special snowflake that people appear to believe it to be.

I am not sure if this reply was British humor, sarcasm or a proposal? Again the hardware for Baytrail and Cherrytrail is very simple, the display subsystem exposes a DMA interface with a 4 descriptors pointing to buffers in system memory and a window of registers to enable DMA transfers and signal interrupts for DMA events. Rather than adding ALSA related code in the i915 driver, the proposal is to create a subdevice that is given access to the relevant register window and a matching driver in sound/x86 that would take care of creating a card and implementing ALSA-related initializations and buffer/periods management. The interaction between the two gfx and audio parts is based on a very limited set of pdata variables and callbacks. From the gfx perspective this minimizes the code changes and dependencies on ALSA. The hdmi-codec interface seems to assume an ASoC implementation which seems over-engineered in this case. There is no specific power management issues, no real need for cpu- or codec-dai and not physical link such as I2S/SPDIF. The only thing that seems directly useful if the pdata part which I already had. If I missed anything I am all ears.

Note that I am not trying to solve HDAudio-gfx interaction, just to get audio support for baytrail and cherrytrail compute sticks in the mainline. I've been porting patches to help users since 4.4, starting from the work Canonical did and internal patches, and it gets tiring. At this point I am looking for either agreement to proceed with the solution suggested in these patches which works fine with minimal impacts to either the drm or alsa domains, or an actual useful/pragmatic counter-proposal. If there is a grand plan of transition to a unified TBD interface for all HDMI cases then I would ask that this is done in a second step after the audio functionality is added.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#22 lore raw
Quoted 7 lines · Pierre-Louis Bossart
Quoted 3 lines · Mark Brown

None of which is at all unusal. The Intel hardware really doesn't seem like the sort of special snowflake that people appear to believe it to be.

I am not sure if this reply was British humor, sarcasm or a proposal? Again

I'm not particularly trying to be funny here, I'm just saying that without having seen any of the code involved (I got CCed in part way through this thread...) this sounds like fairly normal HDMI hardware so it's hard to understand why it can't use the framework code (perhaps with a bit of extension). It does seem to be an unfortunate pattern with HDMI in particular that people seem to see their hardware as needing to use a separate implementation of everything which gets a bit frustrating.

Quoted 8 lines

the hardware for Baytrail and Cherrytrail is very simple, the display subsystem exposes a DMA interface with a 4 descriptors pointing to buffers in system memory and a window of registers to enable DMA transfers and signal interrupts for DMA events. Rather than adding ALSA related code in the i915 driver, the proposal is to create a subdevice that is given access to the relevant register window and a matching driver in sound/x86 that would take care of creating a card and implementing ALSA-related initializations and buffer/periods management. The interaction between the

That all sounds totally sensible - I think the only real issue here is exactly what the ALSA subdevice ends up looking like.

Quoted 3 lines

two gfx and audio parts is based on a very limited set of pdata variables and callbacks. From the gfx perspective this minimizes the code changes and dependencies on ALSA.

Sure, and that's what the hdmi-codec interface was supposed to be doing as well.

Quoted 5 lines

The hdmi-codec interface seems to assume an ASoC implementation which seems over-engineered in this case. There is no specific power management issues, no real need for cpu- or codec-dai and not physical link such as I2S/SPDIF. The only thing that seems directly useful if the pdata part which I already had. If I missed anything I am all ears.

If it's doing the same thing as hdmi-codec then simply not adding another implementation of essentially the same thing ought to be a win.

If the problem is that it's a bit too much work to fill in the dummy DAIs then let's just make it easier to instantiate them and a simple-card to tie everything together.

Quoted 4 lines

Note that I am not trying to solve HDAudio-gfx interaction, just to get audio support for baytrail and cherrytrail compute sticks in the mainline. I've been porting patches to help users since 4.4, starting from the work Canonical did and internal patches, and it gets tiring. At this point I am

Like I say I've not seen these patches (if they're not currently ASoC patches that's not surprising), I don't know why they've not been accepted so I can't really comment on that.

Quoted 6 lines

looking for either agreement to proceed with the solution suggested in these patches which works fine with minimal impacts to either the drm or alsa domains, or an actual useful/pragmatic counter-proposal. If there is a grand plan of transition to a unified TBD interface for all HDMI cases then I would ask that this is done in a second step after the audio functionality is added.

Like I say there's probably room for some helpers for setting this up in simpler cases but even without them it is very common to end up with dummy ASoC devices so I'm not sure I'd say they're impractical. It'd be good to at least have a concrete assessment of why it's unreasonably difficult.

I don't have a particularly strong opinion either way on merging the current code as it is, if there's a commitment to fixing it up then that's the main thing.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx