xref: /dragonfly/sys/dev/drm/i915/intel_lpe_audio.c (revision 3f2dd94a)
1a85cb24fSFrançois Tigeot /*
2a85cb24fSFrançois Tigeot  * Copyright © 2016 Intel Corporation
3a85cb24fSFrançois Tigeot  *
4a85cb24fSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
5a85cb24fSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
6a85cb24fSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
7a85cb24fSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8a85cb24fSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
9a85cb24fSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
10a85cb24fSFrançois Tigeot  *
11a85cb24fSFrançois Tigeot  * The above copyright notice and this permission notice (including the next
12a85cb24fSFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
13a85cb24fSFrançois Tigeot  * Software.
14a85cb24fSFrançois Tigeot  *
15a85cb24fSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16a85cb24fSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17a85cb24fSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18a85cb24fSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19a85cb24fSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20a85cb24fSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21a85cb24fSFrançois Tigeot  * IN THE SOFTWARE.
22a85cb24fSFrançois Tigeot  *
23a85cb24fSFrançois Tigeot  * Authors:
24a85cb24fSFrançois Tigeot  *    Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
25a85cb24fSFrançois Tigeot  *    Jerome Anand <jerome.anand@intel.com>
26a85cb24fSFrançois Tigeot  *    based on VED patches
27a85cb24fSFrançois Tigeot  *
28a85cb24fSFrançois Tigeot  */
29a85cb24fSFrançois Tigeot 
30a85cb24fSFrançois Tigeot /**
31a85cb24fSFrançois Tigeot  * DOC: LPE Audio integration for HDMI or DP playback
32a85cb24fSFrançois Tigeot  *
33a85cb24fSFrançois Tigeot  * Motivation:
34a85cb24fSFrançois Tigeot  * Atom platforms (e.g. valleyview and cherryTrail) integrates a DMA-based
35a85cb24fSFrançois Tigeot  * interface as an alternative to the traditional HDaudio path. While this
36a85cb24fSFrançois Tigeot  * mode is unrelated to the LPE aka SST audio engine, the documentation refers
37a85cb24fSFrançois Tigeot  * to this mode as LPE so we keep this notation for the sake of consistency.
38a85cb24fSFrançois Tigeot  *
39a85cb24fSFrançois Tigeot  * The interface is handled by a separate standalone driver maintained in the
40a85cb24fSFrançois Tigeot  * ALSA subsystem for simplicity. To minimize the interaction between the two
41a85cb24fSFrançois Tigeot  * subsystems, a bridge is setup between the hdmi-lpe-audio and i915:
42a85cb24fSFrançois Tigeot  * 1. Create a platform device to share MMIO/IRQ resources
43a85cb24fSFrançois Tigeot  * 2. Make the platform device child of i915 device for runtime PM.
44a85cb24fSFrançois Tigeot  * 3. Create IRQ chip to forward the LPE audio irqs.
45a85cb24fSFrançois Tigeot  * the hdmi-lpe-audio driver probes the lpe audio device and creates a new
46a85cb24fSFrançois Tigeot  * sound card
47a85cb24fSFrançois Tigeot  *
48a85cb24fSFrançois Tigeot  * Threats:
49a85cb24fSFrançois Tigeot  * Due to the restriction in Linux platform device model, user need manually
50a85cb24fSFrançois Tigeot  * uninstall the hdmi-lpe-audio driver before uninstalling i915 module,
51a85cb24fSFrançois Tigeot  * otherwise we might run into use-after-free issues after i915 removes the
52a85cb24fSFrançois Tigeot  * platform device: even though hdmi-lpe-audio driver is released, the modules
53a85cb24fSFrançois Tigeot  * is still in "installed" status.
54a85cb24fSFrançois Tigeot  *
55a85cb24fSFrançois Tigeot  * Implementation:
56a85cb24fSFrançois Tigeot  * The MMIO/REG platform resources are created according to the registers
57a85cb24fSFrançois Tigeot  * specification.
58a85cb24fSFrançois Tigeot  * When forwarding LPE audio irqs, the flow control handler selection depends
59a85cb24fSFrançois Tigeot  * on the platform, for example on valleyview handle_simple_irq is enough.
60a85cb24fSFrançois Tigeot  *
61a85cb24fSFrançois Tigeot  */
62a85cb24fSFrançois Tigeot 
63a85cb24fSFrançois Tigeot #include <linux/acpi.h>
64a85cb24fSFrançois Tigeot #include <linux/device.h>
65a85cb24fSFrançois Tigeot #include <linux/pci.h>
66a85cb24fSFrançois Tigeot #include <linux/pm_runtime.h>
67a85cb24fSFrançois Tigeot 
68a85cb24fSFrançois Tigeot #include "i915_drv.h"
69a85cb24fSFrançois Tigeot #include <linux/delay.h>
70a85cb24fSFrançois Tigeot #include <drm/intel_lpe_audio.h>
71a85cb24fSFrançois Tigeot 
72a85cb24fSFrançois Tigeot #define HAS_LPE_AUDIO(dev_priv) ((dev_priv)->lpe_audio.platdev != NULL)
73a85cb24fSFrançois Tigeot 
74a85cb24fSFrançois Tigeot #if 0
75a85cb24fSFrançois Tigeot static struct platform_device *
76a85cb24fSFrançois Tigeot lpe_audio_platdev_create(struct drm_i915_private *dev_priv)
77a85cb24fSFrançois Tigeot {
78a85cb24fSFrançois Tigeot 	int ret;
79a85cb24fSFrançois Tigeot 	struct drm_device *dev = &dev_priv->drm;
80a85cb24fSFrançois Tigeot 	struct platform_device_info pinfo = {};
81a85cb24fSFrançois Tigeot 	struct resource *rsc;
82a85cb24fSFrançois Tigeot 	struct platform_device *platdev;
83a85cb24fSFrançois Tigeot 	struct intel_hdmi_lpe_audio_pdata *pdata;
84a85cb24fSFrançois Tigeot 
85a85cb24fSFrançois Tigeot 	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
86a85cb24fSFrançois Tigeot 	if (!pdata)
87a85cb24fSFrançois Tigeot 		return ERR_PTR(-ENOMEM);
88a85cb24fSFrançois Tigeot 
89a85cb24fSFrançois Tigeot 	rsc = kcalloc(2, sizeof(*rsc), GFP_KERNEL);
90a85cb24fSFrançois Tigeot 	if (!rsc) {
91a85cb24fSFrançois Tigeot 		kfree(pdata);
92a85cb24fSFrançois Tigeot 		return ERR_PTR(-ENOMEM);
93a85cb24fSFrançois Tigeot 	}
94a85cb24fSFrançois Tigeot 
95a85cb24fSFrançois Tigeot 	rsc[0].start    = rsc[0].end = dev_priv->lpe_audio.irq;
96a85cb24fSFrançois Tigeot 	rsc[0].flags    = IORESOURCE_IRQ;
97a85cb24fSFrançois Tigeot 	rsc[0].name     = "hdmi-lpe-audio-irq";
98a85cb24fSFrançois Tigeot 
99a85cb24fSFrançois Tigeot 	rsc[1].start    = pci_resource_start(dev->pdev, 0) +
100a85cb24fSFrançois Tigeot 		I915_HDMI_LPE_AUDIO_BASE;
101a85cb24fSFrançois Tigeot 	rsc[1].end      = pci_resource_start(dev->pdev, 0) +
102a85cb24fSFrançois Tigeot 		I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1;
103a85cb24fSFrançois Tigeot 	rsc[1].flags    = IORESOURCE_MEM;
104a85cb24fSFrançois Tigeot 	rsc[1].name     = "hdmi-lpe-audio-mmio";
105a85cb24fSFrançois Tigeot 
106a85cb24fSFrançois Tigeot 	pinfo.parent = dev->dev;
107a85cb24fSFrançois Tigeot 	pinfo.name = "hdmi-lpe-audio";
108a85cb24fSFrançois Tigeot 	pinfo.id = -1;
109a85cb24fSFrançois Tigeot 	pinfo.res = rsc;
110a85cb24fSFrançois Tigeot 	pinfo.num_res = 2;
111a85cb24fSFrançois Tigeot 	pinfo.data = pdata;
112a85cb24fSFrançois Tigeot 	pinfo.size_data = sizeof(*pdata);
113a85cb24fSFrançois Tigeot 	pinfo.dma_mask = DMA_BIT_MASK(32);
114a85cb24fSFrançois Tigeot 
115*3f2dd94aSFrançois Tigeot 	pdata->num_pipes = INTEL_INFO(dev_priv)->num_pipes;
116*3f2dd94aSFrançois Tigeot 	pdata->num_ports = IS_CHERRYVIEW(dev_priv) ? 3 : 2; /* B,C,D or B,C */
117*3f2dd94aSFrançois Tigeot 	pdata->port[0].pipe = -1;
118*3f2dd94aSFrançois Tigeot 	pdata->port[1].pipe = -1;
119*3f2dd94aSFrançois Tigeot 	pdata->port[2].pipe = -1;
120a85cb24fSFrançois Tigeot 	spin_lock_init(&pdata->lpe_audio_slock);
121a85cb24fSFrançois Tigeot 
122a85cb24fSFrançois Tigeot 	platdev = platform_device_register_full(&pinfo);
123a85cb24fSFrançois Tigeot 	if (IS_ERR(platdev)) {
124a85cb24fSFrançois Tigeot 		ret = PTR_ERR(platdev);
125a85cb24fSFrançois Tigeot 		DRM_ERROR("Failed to allocate LPE audio platform device\n");
126a85cb24fSFrançois Tigeot 		goto err;
127a85cb24fSFrançois Tigeot 	}
128a85cb24fSFrançois Tigeot 
129a85cb24fSFrançois Tigeot 	kfree(rsc);
130a85cb24fSFrançois Tigeot 
131a85cb24fSFrançois Tigeot 	pm_runtime_forbid(&platdev->dev);
132a85cb24fSFrançois Tigeot 	pm_runtime_set_active(&platdev->dev);
133a85cb24fSFrançois Tigeot 	pm_runtime_enable(&platdev->dev);
134a85cb24fSFrançois Tigeot 
135a85cb24fSFrançois Tigeot 	pm_runtime_forbid(&platdev->dev);
136a85cb24fSFrançois Tigeot 	pm_runtime_set_active(&platdev->dev);
137a85cb24fSFrançois Tigeot 	pm_runtime_enable(&platdev->dev);
138a85cb24fSFrançois Tigeot 
139a85cb24fSFrançois Tigeot 	return platdev;
140a85cb24fSFrançois Tigeot 
141a85cb24fSFrançois Tigeot err:
142a85cb24fSFrançois Tigeot 	kfree(rsc);
143a85cb24fSFrançois Tigeot 	kfree(pdata);
144a85cb24fSFrançois Tigeot 	return ERR_PTR(ret);
145a85cb24fSFrançois Tigeot }
146a85cb24fSFrançois Tigeot 
147a85cb24fSFrançois Tigeot static void lpe_audio_platdev_destroy(struct drm_i915_private *dev_priv)
148a85cb24fSFrançois Tigeot {
149a85cb24fSFrançois Tigeot 	/* XXX Note that platform_device_register_full() allocates a dma_mask
150a85cb24fSFrançois Tigeot 	 * and never frees it. We can't free it here as we cannot guarantee
151a85cb24fSFrançois Tigeot 	 * this is the last reference (i.e. that the dma_mask will not be
152a85cb24fSFrançois Tigeot 	 * used after our unregister). So ee choose to leak the sizeof(u64)
153a85cb24fSFrançois Tigeot 	 * allocation here - it should be fixed in the platform_device rather
154a85cb24fSFrançois Tigeot 	 * than us fiddle with its internals.
155a85cb24fSFrançois Tigeot 	 */
156a85cb24fSFrançois Tigeot 
157a85cb24fSFrançois Tigeot 	platform_device_unregister(dev_priv->lpe_audio.platdev);
158a85cb24fSFrançois Tigeot }
159a85cb24fSFrançois Tigeot 
160a85cb24fSFrançois Tigeot static void lpe_audio_irq_unmask(struct irq_data *d)
161a85cb24fSFrançois Tigeot {
162a85cb24fSFrançois Tigeot }
163a85cb24fSFrançois Tigeot 
164a85cb24fSFrançois Tigeot static void lpe_audio_irq_mask(struct irq_data *d)
165a85cb24fSFrançois Tigeot {
166a85cb24fSFrançois Tigeot }
167a85cb24fSFrançois Tigeot 
168a85cb24fSFrançois Tigeot static struct irq_chip lpe_audio_irqchip = {
169a85cb24fSFrançois Tigeot 	.name = "hdmi_lpe_audio_irqchip",
170a85cb24fSFrançois Tigeot 	.irq_mask = lpe_audio_irq_mask,
171a85cb24fSFrançois Tigeot 	.irq_unmask = lpe_audio_irq_unmask,
172a85cb24fSFrançois Tigeot };
173a85cb24fSFrançois Tigeot 
174a85cb24fSFrançois Tigeot static int lpe_audio_irq_init(struct drm_i915_private *dev_priv)
175a85cb24fSFrançois Tigeot {
176a85cb24fSFrançois Tigeot 	int irq = dev_priv->lpe_audio.irq;
177a85cb24fSFrançois Tigeot 
178a85cb24fSFrançois Tigeot 	WARN_ON(!intel_irqs_enabled(dev_priv));
179a85cb24fSFrançois Tigeot 	irq_set_chip_and_handler_name(irq,
180a85cb24fSFrançois Tigeot 				&lpe_audio_irqchip,
181a85cb24fSFrançois Tigeot 				handle_simple_irq,
182a85cb24fSFrançois Tigeot 				"hdmi_lpe_audio_irq_handler");
183a85cb24fSFrançois Tigeot 
184a85cb24fSFrançois Tigeot 	return irq_set_chip_data(irq, dev_priv);
185a85cb24fSFrançois Tigeot }
186a85cb24fSFrançois Tigeot 
187a85cb24fSFrançois Tigeot static bool lpe_audio_detect(struct drm_i915_private *dev_priv)
188a85cb24fSFrançois Tigeot {
189a85cb24fSFrançois Tigeot 	int lpe_present = false;
190a85cb24fSFrançois Tigeot 
191a85cb24fSFrançois Tigeot 	if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
192a85cb24fSFrançois Tigeot 		static const struct pci_device_id atom_hdaudio_ids[] = {
193a85cb24fSFrançois Tigeot 			/* Baytrail */
194a85cb24fSFrançois Tigeot 			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f04)},
195a85cb24fSFrançois Tigeot 			/* Braswell */
196a85cb24fSFrançois Tigeot 			{PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2284)},
197a85cb24fSFrançois Tigeot 			{}
198a85cb24fSFrançois Tigeot 		};
199a85cb24fSFrançois Tigeot 
200a85cb24fSFrançois Tigeot 		if (!pci_dev_present(atom_hdaudio_ids)) {
201*3f2dd94aSFrançois Tigeot 			DRM_INFO("HDaudio controller not detected, using LPE audio instead\n");
202a85cb24fSFrançois Tigeot 			lpe_present = true;
203a85cb24fSFrançois Tigeot 		}
204a85cb24fSFrançois Tigeot 	}
205a85cb24fSFrançois Tigeot 	return lpe_present;
206a85cb24fSFrançois Tigeot }
207a85cb24fSFrançois Tigeot 
208a85cb24fSFrançois Tigeot static int lpe_audio_setup(struct drm_i915_private *dev_priv)
209a85cb24fSFrançois Tigeot {
210a85cb24fSFrançois Tigeot 	int ret;
211a85cb24fSFrançois Tigeot 
212a85cb24fSFrançois Tigeot 	dev_priv->lpe_audio.irq = irq_alloc_desc(0);
213a85cb24fSFrançois Tigeot 	if (dev_priv->lpe_audio.irq < 0) {
214a85cb24fSFrançois Tigeot 		DRM_ERROR("Failed to allocate IRQ desc: %d\n",
215a85cb24fSFrançois Tigeot 			dev_priv->lpe_audio.irq);
216a85cb24fSFrançois Tigeot 		ret = dev_priv->lpe_audio.irq;
217a85cb24fSFrançois Tigeot 		goto err;
218a85cb24fSFrançois Tigeot 	}
219a85cb24fSFrançois Tigeot 
220a85cb24fSFrançois Tigeot 	DRM_DEBUG("irq = %d\n", dev_priv->lpe_audio.irq);
221a85cb24fSFrançois Tigeot 
222a85cb24fSFrançois Tigeot 	ret = lpe_audio_irq_init(dev_priv);
223a85cb24fSFrançois Tigeot 
224a85cb24fSFrançois Tigeot 	if (ret) {
225a85cb24fSFrançois Tigeot 		DRM_ERROR("Failed to initialize irqchip for lpe audio: %d\n",
226a85cb24fSFrançois Tigeot 			ret);
227a85cb24fSFrançois Tigeot 		goto err_free_irq;
228a85cb24fSFrançois Tigeot 	}
229a85cb24fSFrançois Tigeot 
230a85cb24fSFrançois Tigeot 	dev_priv->lpe_audio.platdev = lpe_audio_platdev_create(dev_priv);
231a85cb24fSFrançois Tigeot 
232a85cb24fSFrançois Tigeot 	if (IS_ERR(dev_priv->lpe_audio.platdev)) {
233a85cb24fSFrançois Tigeot 		ret = PTR_ERR(dev_priv->lpe_audio.platdev);
234a85cb24fSFrançois Tigeot 		DRM_ERROR("Failed to create lpe audio platform device: %d\n",
235a85cb24fSFrançois Tigeot 			ret);
236a85cb24fSFrançois Tigeot 		goto err_free_irq;
237a85cb24fSFrançois Tigeot 	}
238a85cb24fSFrançois Tigeot 
239a85cb24fSFrançois Tigeot 	/* enable chicken bit; at least this is required for Dell Wyse 3040
240a85cb24fSFrançois Tigeot 	 * with DP outputs (but only sometimes by some reason!)
241a85cb24fSFrançois Tigeot 	 */
242a85cb24fSFrançois Tigeot 	I915_WRITE(VLV_AUD_CHICKEN_BIT_REG, VLV_CHICKEN_BIT_DBG_ENABLE);
243a85cb24fSFrançois Tigeot 
244a85cb24fSFrançois Tigeot 	return 0;
245a85cb24fSFrançois Tigeot err_free_irq:
246a85cb24fSFrançois Tigeot 	irq_free_desc(dev_priv->lpe_audio.irq);
247a85cb24fSFrançois Tigeot err:
248a85cb24fSFrançois Tigeot 	dev_priv->lpe_audio.irq = -1;
249a85cb24fSFrançois Tigeot 	dev_priv->lpe_audio.platdev = NULL;
250a85cb24fSFrançois Tigeot 	return ret;
251a85cb24fSFrançois Tigeot }
252a85cb24fSFrançois Tigeot #endif
253a85cb24fSFrançois Tigeot 
254a85cb24fSFrançois Tigeot /**
255a85cb24fSFrançois Tigeot  * intel_lpe_audio_irq_handler() - forwards the LPE audio irq
256a85cb24fSFrançois Tigeot  * @dev_priv: the i915 drm device private data
257a85cb24fSFrançois Tigeot  *
258a85cb24fSFrançois Tigeot  * the LPE Audio irq is forwarded to the irq handler registered by LPE audio
259a85cb24fSFrançois Tigeot  * driver.
260a85cb24fSFrançois Tigeot  */
intel_lpe_audio_irq_handler(struct drm_i915_private * dev_priv)261a85cb24fSFrançois Tigeot void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv)
262a85cb24fSFrançois Tigeot {
263a85cb24fSFrançois Tigeot #if 0
264a85cb24fSFrançois Tigeot 	int ret;
265a85cb24fSFrançois Tigeot 
266a85cb24fSFrançois Tigeot 	if (!HAS_LPE_AUDIO(dev_priv))
267a85cb24fSFrançois Tigeot 		return;
268a85cb24fSFrançois Tigeot 
269a85cb24fSFrançois Tigeot 	ret = generic_handle_irq(dev_priv->lpe_audio.irq);
270a85cb24fSFrançois Tigeot 	if (ret)
271a85cb24fSFrançois Tigeot 		DRM_ERROR_RATELIMITED("error handling LPE audio irq: %d\n",
272a85cb24fSFrançois Tigeot 				ret);
273a85cb24fSFrançois Tigeot #endif
274a85cb24fSFrançois Tigeot }
275a85cb24fSFrançois Tigeot 
276a85cb24fSFrançois Tigeot /**
277a85cb24fSFrançois Tigeot  * intel_lpe_audio_init() - detect and setup the bridge between HDMI LPE Audio
278a85cb24fSFrançois Tigeot  * driver and i915
279a85cb24fSFrançois Tigeot  * @dev_priv: the i915 drm device private data
280a85cb24fSFrançois Tigeot  *
281a85cb24fSFrançois Tigeot  * Return: 0 if successful. non-zero if detection or
282a85cb24fSFrançois Tigeot  * llocation/initialization fails
283a85cb24fSFrançois Tigeot  */
intel_lpe_audio_init(struct drm_i915_private * dev_priv)284a85cb24fSFrançois Tigeot int intel_lpe_audio_init(struct drm_i915_private *dev_priv)
285a85cb24fSFrançois Tigeot {
286a85cb24fSFrançois Tigeot 	int ret = -ENODEV;
287a85cb24fSFrançois Tigeot 
288a85cb24fSFrançois Tigeot #if 0
289a85cb24fSFrançois Tigeot 	if (lpe_audio_detect(dev_priv)) {
290a85cb24fSFrançois Tigeot 		ret = lpe_audio_setup(dev_priv);
291a85cb24fSFrançois Tigeot 		if (ret < 0)
292a85cb24fSFrançois Tigeot 			DRM_ERROR("failed to setup LPE Audio bridge\n");
293a85cb24fSFrançois Tigeot 	}
294a85cb24fSFrançois Tigeot #endif
295a85cb24fSFrançois Tigeot 	return ret;
296a85cb24fSFrançois Tigeot }
297a85cb24fSFrançois Tigeot 
298a85cb24fSFrançois Tigeot /**
299a85cb24fSFrançois Tigeot  * intel_lpe_audio_teardown() - destroy the bridge between HDMI LPE
300a85cb24fSFrançois Tigeot  * audio driver and i915
301a85cb24fSFrançois Tigeot  * @dev_priv: the i915 drm device private data
302a85cb24fSFrançois Tigeot  *
303a85cb24fSFrançois Tigeot  * release all the resources for LPE audio <-> i915 bridge.
304a85cb24fSFrançois Tigeot  */
intel_lpe_audio_teardown(struct drm_i915_private * dev_priv)305a85cb24fSFrançois Tigeot void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv)
306a85cb24fSFrançois Tigeot {
307a85cb24fSFrançois Tigeot #if 0
308a85cb24fSFrançois Tigeot 	struct irq_desc *desc;
309a85cb24fSFrançois Tigeot 
310a85cb24fSFrançois Tigeot 	if (!HAS_LPE_AUDIO(dev_priv))
311a85cb24fSFrançois Tigeot 		return;
312a85cb24fSFrançois Tigeot 
313a85cb24fSFrançois Tigeot 	desc = irq_to_desc(dev_priv->lpe_audio.irq);
314a85cb24fSFrançois Tigeot 
315a85cb24fSFrançois Tigeot 	lpe_audio_platdev_destroy(dev_priv);
316a85cb24fSFrançois Tigeot 
317a85cb24fSFrançois Tigeot 	irq_free_desc(dev_priv->lpe_audio.irq);
318a85cb24fSFrançois Tigeot #endif
319a85cb24fSFrançois Tigeot }
320a85cb24fSFrançois Tigeot 
321a85cb24fSFrançois Tigeot 
322a85cb24fSFrançois Tigeot /**
323a85cb24fSFrançois Tigeot  * intel_lpe_audio_notify() - notify lpe audio event
324a85cb24fSFrançois Tigeot  * audio driver and i915
325a85cb24fSFrançois Tigeot  * @dev_priv: the i915 drm device private data
326*3f2dd94aSFrançois Tigeot  * @pipe: pipe
327*3f2dd94aSFrançois Tigeot  * @port: port
328a85cb24fSFrançois Tigeot  * @eld : ELD data
329*3f2dd94aSFrançois Tigeot  * @ls_clock: Link symbol clock in kHz
330*3f2dd94aSFrançois Tigeot  * @dp_output: Driving a DP output?
331a85cb24fSFrançois Tigeot  *
332a85cb24fSFrançois Tigeot  * Notify lpe audio driver of eld change.
333a85cb24fSFrançois Tigeot  */
intel_lpe_audio_notify(struct drm_i915_private * dev_priv,enum i915_pipe pipe,enum port port,const void * eld,int ls_clock,bool dp_output)334a85cb24fSFrançois Tigeot void intel_lpe_audio_notify(struct drm_i915_private *dev_priv,
335*3f2dd94aSFrançois Tigeot 			    enum i915_pipe pipe, enum port port,
336*3f2dd94aSFrançois Tigeot 			    const void *eld, int ls_clock, bool dp_output)
337a85cb24fSFrançois Tigeot {
338a85cb24fSFrançois Tigeot #if 0
339*3f2dd94aSFrançois Tigeot 	unsigned long irqflags;
340*3f2dd94aSFrançois Tigeot 	struct intel_hdmi_lpe_audio_pdata *pdata;
341*3f2dd94aSFrançois Tigeot 	struct intel_hdmi_lpe_audio_port_pdata *ppdata;
342a85cb24fSFrançois Tigeot 	u32 audio_enable;
343a85cb24fSFrançois Tigeot 
344a85cb24fSFrançois Tigeot 	if (!HAS_LPE_AUDIO(dev_priv))
345a85cb24fSFrançois Tigeot 		return;
346a85cb24fSFrançois Tigeot 
347*3f2dd94aSFrançois Tigeot 	pdata = dev_get_platdata(&dev_priv->lpe_audio.platdev->dev);
348*3f2dd94aSFrançois Tigeot 	ppdata = &pdata->port[port - PORT_B];
349a85cb24fSFrançois Tigeot 
350*3f2dd94aSFrançois Tigeot 	spin_lock_irqsave(&pdata->lpe_audio_slock, irqflags);
351a85cb24fSFrançois Tigeot 
352a85cb24fSFrançois Tigeot 	audio_enable = I915_READ(VLV_AUD_PORT_EN_DBG(port));
353a85cb24fSFrançois Tigeot 
354a85cb24fSFrançois Tigeot 	if (eld != NULL) {
355*3f2dd94aSFrançois Tigeot 		memcpy(ppdata->eld, eld, HDMI_MAX_ELD_BYTES);
356*3f2dd94aSFrançois Tigeot 		ppdata->pipe = pipe;
357*3f2dd94aSFrançois Tigeot 		ppdata->ls_clock = ls_clock;
358*3f2dd94aSFrançois Tigeot 		ppdata->dp_output = dp_output;
359a85cb24fSFrançois Tigeot 
360a85cb24fSFrançois Tigeot 		/* Unmute the amp for both DP and HDMI */
361a85cb24fSFrançois Tigeot 		I915_WRITE(VLV_AUD_PORT_EN_DBG(port),
362a85cb24fSFrançois Tigeot 			   audio_enable & ~VLV_AMP_MUTE);
363a85cb24fSFrançois Tigeot 	} else {
364*3f2dd94aSFrançois Tigeot 		memset(ppdata->eld, 0, HDMI_MAX_ELD_BYTES);
365*3f2dd94aSFrançois Tigeot 		ppdata->pipe = -1;
366*3f2dd94aSFrançois Tigeot 		ppdata->ls_clock = 0;
367*3f2dd94aSFrançois Tigeot 		ppdata->dp_output = false;
368a85cb24fSFrançois Tigeot 
369a85cb24fSFrançois Tigeot 		/* Mute the amp for both DP and HDMI */
370a85cb24fSFrançois Tigeot 		I915_WRITE(VLV_AUD_PORT_EN_DBG(port),
371a85cb24fSFrançois Tigeot 			   audio_enable | VLV_AMP_MUTE);
372a85cb24fSFrançois Tigeot 	}
373a85cb24fSFrançois Tigeot 
374a85cb24fSFrançois Tigeot 	if (pdata->notify_audio_lpe)
375*3f2dd94aSFrançois Tigeot 		pdata->notify_audio_lpe(dev_priv->lpe_audio.platdev, port - PORT_B);
376a85cb24fSFrançois Tigeot 
377*3f2dd94aSFrançois Tigeot 	spin_unlock_irqrestore(&pdata->lpe_audio_slock, irqflags);
378a85cb24fSFrançois Tigeot #endif
379a85cb24fSFrançois Tigeot }
380