1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63#include <linux/acpi.h>
64#include <linux/device.h>
65#include <linux/irq.h>
66#include <linux/pci.h>
67#include <linux/pm_runtime.h>
68#include <linux/platform_device.h>
69
70#include "i915_drv.h"
71#include <linux/delay.h>
72#include <drm/intel_lpe_audio.h>
73
74#define HAS_LPE_AUDIO(dev_priv) ((dev_priv)->lpe_audio.platdev != NULL)
75
76static struct platform_device *
77lpe_audio_platdev_create(struct drm_i915_private *dev_priv)
78{
79 struct drm_device *dev = &dev_priv->drm;
80 struct platform_device_info pinfo = {};
81 struct resource *rsc;
82 struct platform_device *platdev;
83 struct intel_hdmi_lpe_audio_pdata *pdata;
84
85 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
86 if (!pdata)
87 return ERR_PTR(-ENOMEM);
88
89 rsc = kcalloc(2, sizeof(*rsc), GFP_KERNEL);
90 if (!rsc) {
91 kfree(pdata);
92 return ERR_PTR(-ENOMEM);
93 }
94
95 rsc[0].start = rsc[0].end = dev_priv->lpe_audio.irq;
96 rsc[0].flags = IORESOURCE_IRQ;
97 rsc[0].name = "hdmi-lpe-audio-irq";
98
99 rsc[1].start = pci_resource_start(dev->pdev, 0) +
100 I915_HDMI_LPE_AUDIO_BASE;
101 rsc[1].end = pci_resource_start(dev->pdev, 0) +
102 I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1;
103 rsc[1].flags = IORESOURCE_MEM;
104 rsc[1].name = "hdmi-lpe-audio-mmio";
105
106 pinfo.parent = dev->dev;
107 pinfo.name = "hdmi-lpe-audio";
108 pinfo.id = -1;
109 pinfo.res = rsc;
110 pinfo.num_res = 2;
111 pinfo.data = pdata;
112 pinfo.size_data = sizeof(*pdata);
113 pinfo.dma_mask = DMA_BIT_MASK(32);
114
115 pdata->num_pipes = INTEL_INFO(dev_priv)->num_pipes;
116 pdata->num_ports = IS_CHERRYVIEW(dev_priv) ? 3 : 2;
117 pdata->port[0].pipe = -1;
118 pdata->port[1].pipe = -1;
119 pdata->port[2].pipe = -1;
120 spin_lock_init(&pdata->lpe_audio_slock);
121
122 platdev = platform_device_register_full(&pinfo);
123 kfree(rsc);
124 kfree(pdata);
125
126 if (IS_ERR(platdev)) {
127 DRM_ERROR("Failed to allocate LPE audio platform device\n");
128 return platdev;
129 }
130
131 pm_runtime_no_callbacks(&platdev->dev);
132
133 return platdev;
134}
135
136static void lpe_audio_platdev_destroy(struct drm_i915_private *dev_priv)
137{
138
139
140
141
142
143
144
145
146 platform_device_unregister(dev_priv->lpe_audio.platdev);
147}
148
149static void lpe_audio_irq_unmask(struct irq_data *d)
150{
151}
152
153static void lpe_audio_irq_mask(struct irq_data *d)
154{
155}
156
157static struct irq_chip lpe_audio_irqchip = {
158 .name = "hdmi_lpe_audio_irqchip",
159 .irq_mask = lpe_audio_irq_mask,
160 .irq_unmask = lpe_audio_irq_unmask,
161};
162
163static int lpe_audio_irq_init(struct drm_i915_private *dev_priv)
164{
165 int irq = dev_priv->lpe_audio.irq;
166
167 WARN_ON(!intel_irqs_enabled(dev_priv));
168 irq_set_chip_and_handler_name(irq,
169 &lpe_audio_irqchip,
170 handle_simple_irq,
171 "hdmi_lpe_audio_irq_handler");
172
173 return irq_set_chip_data(irq, dev_priv);
174}
175
176static bool lpe_audio_detect(struct drm_i915_private *dev_priv)
177{
178 int lpe_present = false;
179
180 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
181 static const struct pci_device_id atom_hdaudio_ids[] = {
182
183 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f04)},
184
185 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2284)},
186 {}
187 };
188
189 if (!pci_dev_present(atom_hdaudio_ids)) {
190 DRM_INFO("HDaudio controller not detected, using LPE audio instead\n");
191 lpe_present = true;
192 }
193 }
194 return lpe_present;
195}
196
197static int lpe_audio_setup(struct drm_i915_private *dev_priv)
198{
199 int ret;
200
201 dev_priv->lpe_audio.irq = irq_alloc_desc(0);
202 if (dev_priv->lpe_audio.irq < 0) {
203 DRM_ERROR("Failed to allocate IRQ desc: %d\n",
204 dev_priv->lpe_audio.irq);
205 ret = dev_priv->lpe_audio.irq;
206 goto err;
207 }
208
209 DRM_DEBUG("irq = %d\n", dev_priv->lpe_audio.irq);
210
211 ret = lpe_audio_irq_init(dev_priv);
212
213 if (ret) {
214 DRM_ERROR("Failed to initialize irqchip for lpe audio: %d\n",
215 ret);
216 goto err_free_irq;
217 }
218
219 dev_priv->lpe_audio.platdev = lpe_audio_platdev_create(dev_priv);
220
221 if (IS_ERR(dev_priv->lpe_audio.platdev)) {
222 ret = PTR_ERR(dev_priv->lpe_audio.platdev);
223 DRM_ERROR("Failed to create lpe audio platform device: %d\n",
224 ret);
225 goto err_free_irq;
226 }
227
228
229
230
231 I915_WRITE(VLV_AUD_CHICKEN_BIT_REG, VLV_CHICKEN_BIT_DBG_ENABLE);
232
233 return 0;
234err_free_irq:
235 irq_free_desc(dev_priv->lpe_audio.irq);
236err:
237 dev_priv->lpe_audio.irq = -1;
238 dev_priv->lpe_audio.platdev = NULL;
239 return ret;
240}
241
242
243
244
245
246
247
248
249void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv)
250{
251 int ret;
252
253 if (!HAS_LPE_AUDIO(dev_priv))
254 return;
255
256 ret = generic_handle_irq(dev_priv->lpe_audio.irq);
257 if (ret)
258 DRM_ERROR_RATELIMITED("error handling LPE audio irq: %d\n",
259 ret);
260}
261
262
263
264
265
266
267
268
269
270int intel_lpe_audio_init(struct drm_i915_private *dev_priv)
271{
272 int ret = -ENODEV;
273
274 if (lpe_audio_detect(dev_priv)) {
275 ret = lpe_audio_setup(dev_priv);
276 if (ret < 0)
277 DRM_ERROR("failed to setup LPE Audio bridge\n");
278 }
279 return ret;
280}
281
282
283
284
285
286
287
288
289void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv)
290{
291 struct irq_desc *desc;
292
293 if (!HAS_LPE_AUDIO(dev_priv))
294 return;
295
296 desc = irq_to_desc(dev_priv->lpe_audio.irq);
297
298 lpe_audio_platdev_destroy(dev_priv);
299
300 irq_free_desc(dev_priv->lpe_audio.irq);
301
302 dev_priv->lpe_audio.irq = -1;
303 dev_priv->lpe_audio.platdev = NULL;
304}
305
306
307
308
309
310
311
312
313
314
315
316
317
318void intel_lpe_audio_notify(struct drm_i915_private *dev_priv,
319 enum pipe pipe, enum port port,
320 const void *eld, int ls_clock, bool dp_output)
321{
322 unsigned long irqflags;
323 struct intel_hdmi_lpe_audio_pdata *pdata;
324 struct intel_hdmi_lpe_audio_port_pdata *ppdata;
325 u32 audio_enable;
326
327 if (!HAS_LPE_AUDIO(dev_priv))
328 return;
329
330 pdata = dev_get_platdata(&dev_priv->lpe_audio.platdev->dev);
331 ppdata = &pdata->port[port - PORT_B];
332
333 spin_lock_irqsave(&pdata->lpe_audio_slock, irqflags);
334
335 audio_enable = I915_READ(VLV_AUD_PORT_EN_DBG(port));
336
337 if (eld != NULL) {
338 memcpy(ppdata->eld, eld, HDMI_MAX_ELD_BYTES);
339 ppdata->pipe = pipe;
340 ppdata->ls_clock = ls_clock;
341 ppdata->dp_output = dp_output;
342
343
344 I915_WRITE(VLV_AUD_PORT_EN_DBG(port),
345 audio_enable & ~VLV_AMP_MUTE);
346 } else {
347 memset(ppdata->eld, 0, HDMI_MAX_ELD_BYTES);
348 ppdata->pipe = -1;
349 ppdata->ls_clock = 0;
350 ppdata->dp_output = false;
351
352
353 I915_WRITE(VLV_AUD_PORT_EN_DBG(port),
354 audio_enable | VLV_AMP_MUTE);
355 }
356
357 if (pdata->notify_audio_lpe)
358 pdata->notify_audio_lpe(dev_priv->lpe_audio.platdev, port - PORT_B);
359
360 spin_unlock_irqrestore(&pdata->lpe_audio_slock, irqflags);
361}
362