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