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