1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
5 * lpass-platform.c -- ALSA SoC platform driver for QTi LPASS
8 #include <linux/dma-mapping.h>
9 #include <linux/export.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <sound/pcm_params.h>
14 #include <linux/regmap.h>
15 #include <sound/soc.h>
16 #include "lpass-lpaif-reg.h"
19 #define DRV_NAME "lpass-platform"
21 struct lpass_pcm_data {
26 #define LPASS_PLATFORM_BUFFER_SIZE (24 * 2 * 1024)
27 #define LPASS_PLATFORM_PERIODS 2
29 static const struct snd_pcm_hardware lpass_platform_pcm_hardware = {
30 .info = SNDRV_PCM_INFO_MMAP |
31 SNDRV_PCM_INFO_MMAP_VALID |
32 SNDRV_PCM_INFO_INTERLEAVED |
33 SNDRV_PCM_INFO_PAUSE |
34 SNDRV_PCM_INFO_RESUME,
35 .formats = SNDRV_PCM_FMTBIT_S16 |
36 SNDRV_PCM_FMTBIT_S24 |
38 .rates = SNDRV_PCM_RATE_8000_192000,
43 .buffer_bytes_max = LPASS_PLATFORM_BUFFER_SIZE,
44 .period_bytes_max = LPASS_PLATFORM_BUFFER_SIZE /
45 LPASS_PLATFORM_PERIODS,
46 .period_bytes_min = LPASS_PLATFORM_BUFFER_SIZE /
47 LPASS_PLATFORM_PERIODS,
48 .periods_min = LPASS_PLATFORM_PERIODS,
49 .periods_max = LPASS_PLATFORM_PERIODS,
53 static int lpass_platform_alloc_dmactl_fields(struct device *dev,
56 struct lpass_data *drvdata = dev_get_drvdata(dev);
57 struct lpass_variant *v = drvdata->variant;
58 struct lpaif_dmactl *rd_dmactl, *wr_dmactl;
61 drvdata->rd_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl),
63 if (drvdata->rd_dmactl == NULL)
66 drvdata->wr_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl),
68 if (drvdata->wr_dmactl == NULL)
71 rd_dmactl = drvdata->rd_dmactl;
72 wr_dmactl = drvdata->wr_dmactl;
74 rval = devm_regmap_field_bulk_alloc(dev, map, &rd_dmactl->intf,
79 return devm_regmap_field_bulk_alloc(dev, map, &wr_dmactl->intf,
83 static int lpass_platform_alloc_hdmidmactl_fields(struct device *dev,
86 struct lpass_data *drvdata = dev_get_drvdata(dev);
87 struct lpass_variant *v = drvdata->variant;
88 struct lpaif_dmactl *rd_dmactl;
90 rd_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl), GFP_KERNEL);
91 if (rd_dmactl == NULL)
94 drvdata->hdmi_rd_dmactl = rd_dmactl;
96 return devm_regmap_field_bulk_alloc(dev, map, &rd_dmactl->bursten,
97 &v->hdmi_rdma_bursten, 8);
100 static int lpass_platform_pcmops_open(struct snd_soc_component *component,
101 struct snd_pcm_substream *substream)
103 struct snd_pcm_runtime *runtime = substream->runtime;
104 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
105 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
106 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
107 struct lpass_variant *v = drvdata->variant;
108 int ret, dma_ch, dir = substream->stream;
109 struct lpass_pcm_data *data;
111 unsigned int dai_id = cpu_dai->driver->id;
113 component->id = dai_id;
114 data = kzalloc(sizeof(*data), GFP_KERNEL);
118 data->i2s_port = cpu_dai->driver->id;
119 runtime->private_data = data;
121 if (v->alloc_dma_channel)
122 dma_ch = v->alloc_dma_channel(drvdata, dir, dai_id);
131 if (cpu_dai->driver->id == LPASS_DP_RX) {
132 map = drvdata->hdmiif_map;
133 drvdata->hdmi_substream[dma_ch] = substream;
135 map = drvdata->lpaif_map;
136 drvdata->substream[dma_ch] = substream;
138 data->dma_ch = dma_ch;
139 ret = regmap_write(map,
140 LPAIF_DMACTL_REG(v, dma_ch, dir, data->i2s_port), 0);
142 dev_err(soc_runtime->dev,
143 "error writing to rdmactl reg: %d\n", ret);
146 snd_soc_set_runtime_hwparams(substream, &lpass_platform_pcm_hardware);
148 runtime->dma_bytes = lpass_platform_pcm_hardware.buffer_bytes_max;
150 ret = snd_pcm_hw_constraint_integer(runtime,
151 SNDRV_PCM_HW_PARAM_PERIODS);
154 dev_err(soc_runtime->dev, "setting constraints failed: %d\n",
159 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
164 static int lpass_platform_pcmops_close(struct snd_soc_component *component,
165 struct snd_pcm_substream *substream)
167 struct snd_pcm_runtime *runtime = substream->runtime;
168 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
169 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
170 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
171 struct lpass_variant *v = drvdata->variant;
172 struct lpass_pcm_data *data;
173 unsigned int dai_id = cpu_dai->driver->id;
175 data = runtime->private_data;
176 if (dai_id == LPASS_DP_RX)
177 drvdata->hdmi_substream[data->dma_ch] = NULL;
179 drvdata->substream[data->dma_ch] = NULL;
180 if (v->free_dma_channel)
181 v->free_dma_channel(drvdata, data->dma_ch, dai_id);
187 static int lpass_platform_pcmops_hw_params(struct snd_soc_component *component,
188 struct snd_pcm_substream *substream,
189 struct snd_pcm_hw_params *params)
191 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
192 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
193 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
194 struct snd_pcm_runtime *rt = substream->runtime;
195 struct lpass_pcm_data *pcm_data = rt->private_data;
196 struct lpass_variant *v = drvdata->variant;
197 snd_pcm_format_t format = params_format(params);
198 unsigned int channels = params_channels(params);
200 struct lpaif_dmactl *dmactl;
201 int id, dir = substream->stream;
203 int ret, dma_port = pcm_data->i2s_port + v->dmactl_audif_start;
204 unsigned int dai_id = cpu_dai->driver->id;
206 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
207 id = pcm_data->dma_ch;
208 if (dai_id == LPASS_DP_RX)
209 dmactl = drvdata->hdmi_rd_dmactl;
211 dmactl = drvdata->rd_dmactl;
214 dmactl = drvdata->wr_dmactl;
215 id = pcm_data->dma_ch - v->wrdma_channel_start;
218 bitwidth = snd_pcm_format_width(format);
220 dev_err(soc_runtime->dev, "invalid bit width given: %d\n",
225 ret = regmap_fields_write(dmactl->bursten, id, LPAIF_DMACTL_BURSTEN_INCR4);
227 dev_err(soc_runtime->dev, "error updating bursten field: %d\n", ret);
231 ret = regmap_fields_write(dmactl->fifowm, id, LPAIF_DMACTL_FIFOWM_8);
233 dev_err(soc_runtime->dev, "error updating fifowm field: %d\n", ret);
239 ret = regmap_fields_write(dmactl->burst8, id,
240 LPAIF_DMACTL_BURSTEN_INCR4);
242 dev_err(soc_runtime->dev, "error updating burst8en field: %d\n", ret);
245 ret = regmap_fields_write(dmactl->burst16, id,
246 LPAIF_DMACTL_BURSTEN_INCR4);
248 dev_err(soc_runtime->dev, "error updating burst16en field: %d\n", ret);
251 ret = regmap_fields_write(dmactl->dynburst, id,
252 LPAIF_DMACTL_BURSTEN_INCR4);
254 dev_err(soc_runtime->dev, "error updating dynbursten field: %d\n", ret);
260 ret = regmap_fields_write(dmactl->intf, id,
261 LPAIF_DMACTL_AUDINTF(dma_port));
263 dev_err(soc_runtime->dev, "error updating audio interface field: %d\n",
270 dev_err(soc_runtime->dev, "%s: invalid interface: %d\n", __func__, dai_id);
278 regval = LPAIF_DMACTL_WPSCNT_ONE;
281 regval = LPAIF_DMACTL_WPSCNT_TWO;
284 regval = LPAIF_DMACTL_WPSCNT_THREE;
287 regval = LPAIF_DMACTL_WPSCNT_FOUR;
290 dev_err(soc_runtime->dev, "invalid PCM config given: bw=%d, ch=%u\n",
299 regval = LPAIF_DMACTL_WPSCNT_ONE;
302 regval = (dai_id == LPASS_DP_RX ?
303 LPAIF_DMACTL_WPSCNT_ONE :
304 LPAIF_DMACTL_WPSCNT_TWO);
307 regval = (dai_id == LPASS_DP_RX ?
308 LPAIF_DMACTL_WPSCNT_TWO :
309 LPAIF_DMACTL_WPSCNT_FOUR);
312 regval = (dai_id == LPASS_DP_RX ?
313 LPAIF_DMACTL_WPSCNT_THREE :
314 LPAIF_DMACTL_WPSCNT_SIX);
317 regval = (dai_id == LPASS_DP_RX ?
318 LPAIF_DMACTL_WPSCNT_FOUR :
319 LPAIF_DMACTL_WPSCNT_EIGHT);
322 dev_err(soc_runtime->dev, "invalid PCM config given: bw=%d, ch=%u\n",
328 dev_err(soc_runtime->dev, "invalid PCM config given: bw=%d, ch=%u\n",
333 ret = regmap_fields_write(dmactl->wpscnt, id, regval);
335 dev_err(soc_runtime->dev, "error writing to dmactl reg: %d\n",
343 static int lpass_platform_pcmops_hw_free(struct snd_soc_component *component,
344 struct snd_pcm_substream *substream)
346 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
347 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
348 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
349 struct snd_pcm_runtime *rt = substream->runtime;
350 struct lpass_pcm_data *pcm_data = rt->private_data;
351 struct lpass_variant *v = drvdata->variant;
355 unsigned int dai_id = cpu_dai->driver->id;
357 if (dai_id == LPASS_DP_RX)
358 map = drvdata->hdmiif_map;
360 map = drvdata->lpaif_map;
362 reg = LPAIF_DMACTL_REG(v, pcm_data->dma_ch, substream->stream, dai_id);
363 ret = regmap_write(map, reg, 0);
365 dev_err(soc_runtime->dev, "error writing to rdmactl reg: %d\n",
371 static int lpass_platform_pcmops_prepare(struct snd_soc_component *component,
372 struct snd_pcm_substream *substream)
374 struct snd_pcm_runtime *runtime = substream->runtime;
375 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
376 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
377 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
378 struct snd_pcm_runtime *rt = substream->runtime;
379 struct lpass_pcm_data *pcm_data = rt->private_data;
380 struct lpass_variant *v = drvdata->variant;
381 struct lpaif_dmactl *dmactl;
383 int ret, id, ch, dir = substream->stream;
384 unsigned int dai_id = cpu_dai->driver->id;
387 ch = pcm_data->dma_ch;
388 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
389 if (dai_id == LPASS_DP_RX) {
390 dmactl = drvdata->hdmi_rd_dmactl;
391 map = drvdata->hdmiif_map;
393 dmactl = drvdata->rd_dmactl;
394 map = drvdata->lpaif_map;
397 id = pcm_data->dma_ch;
399 dmactl = drvdata->wr_dmactl;
400 id = pcm_data->dma_ch - v->wrdma_channel_start;
401 map = drvdata->lpaif_map;
404 ret = regmap_write(map, LPAIF_DMABASE_REG(v, ch, dir, dai_id),
407 dev_err(soc_runtime->dev, "error writing to rdmabase reg: %d\n",
412 ret = regmap_write(map, LPAIF_DMABUFF_REG(v, ch, dir, dai_id),
413 (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1);
415 dev_err(soc_runtime->dev, "error writing to rdmabuff reg: %d\n",
420 ret = regmap_write(map, LPAIF_DMAPER_REG(v, ch, dir, dai_id),
421 (snd_pcm_lib_period_bytes(substream) >> 2) - 1);
423 dev_err(soc_runtime->dev, "error writing to rdmaper reg: %d\n",
428 ret = regmap_fields_write(dmactl->enable, id, LPAIF_DMACTL_ENABLE_ON);
430 dev_err(soc_runtime->dev, "error writing to rdmactl reg: %d\n",
438 static int lpass_platform_pcmops_trigger(struct snd_soc_component *component,
439 struct snd_pcm_substream *substream,
442 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
443 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
444 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
445 struct snd_pcm_runtime *rt = substream->runtime;
446 struct lpass_pcm_data *pcm_data = rt->private_data;
447 struct lpass_variant *v = drvdata->variant;
448 struct lpaif_dmactl *dmactl;
451 int dir = substream->stream;
452 unsigned int reg_irqclr = 0, val_irqclr = 0;
453 unsigned int reg_irqen = 0, val_irqen = 0, val_mask = 0;
454 unsigned int dai_id = cpu_dai->driver->id;
456 ch = pcm_data->dma_ch;
457 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
458 id = pcm_data->dma_ch;
459 if (dai_id == LPASS_DP_RX) {
460 dmactl = drvdata->hdmi_rd_dmactl;
461 map = drvdata->hdmiif_map;
463 dmactl = drvdata->rd_dmactl;
464 map = drvdata->lpaif_map;
467 dmactl = drvdata->wr_dmactl;
468 id = pcm_data->dma_ch - v->wrdma_channel_start;
469 map = drvdata->lpaif_map;
473 case SNDRV_PCM_TRIGGER_START:
474 case SNDRV_PCM_TRIGGER_RESUME:
475 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
476 ret = regmap_fields_write(dmactl->enable, id,
477 LPAIF_DMACTL_ENABLE_ON);
479 dev_err(soc_runtime->dev,
480 "error writing to rdmactl reg: %d\n", ret);
485 ret = regmap_fields_write(dmactl->dyncclk, id,
486 LPAIF_DMACTL_DYNCLK_ON);
488 dev_err(soc_runtime->dev,
489 "error writing to rdmactl reg: %d\n", ret);
492 reg_irqclr = LPASS_HDMITX_APP_IRQCLEAR_REG(v);
493 val_irqclr = (LPAIF_IRQ_ALL(ch) |
494 LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
495 LPAIF_IRQ_HDMI_METADONE |
496 LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
498 reg_irqen = LPASS_HDMITX_APP_IRQEN_REG(v);
499 val_mask = (LPAIF_IRQ_ALL(ch) |
500 LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
501 LPAIF_IRQ_HDMI_METADONE |
502 LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
503 val_irqen = (LPAIF_IRQ_ALL(ch) |
504 LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
505 LPAIF_IRQ_HDMI_METADONE |
506 LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
510 reg_irqclr = LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST);
511 val_irqclr = LPAIF_IRQ_ALL(ch);
514 reg_irqen = LPAIF_IRQEN_REG(v, LPAIF_IRQ_PORT_HOST);
515 val_mask = LPAIF_IRQ_ALL(ch);
516 val_irqen = LPAIF_IRQ_ALL(ch);
519 dev_err(soc_runtime->dev, "%s: invalid %d interface\n", __func__, dai_id);
523 ret = regmap_write(map, reg_irqclr, val_irqclr);
525 dev_err(soc_runtime->dev, "error writing to irqclear reg: %d\n", ret);
528 ret = regmap_update_bits(map, reg_irqen, val_mask, val_irqen);
530 dev_err(soc_runtime->dev, "error writing to irqen reg: %d\n", ret);
534 case SNDRV_PCM_TRIGGER_STOP:
535 case SNDRV_PCM_TRIGGER_SUSPEND:
536 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
537 ret = regmap_fields_write(dmactl->enable, id,
538 LPAIF_DMACTL_ENABLE_OFF);
540 dev_err(soc_runtime->dev,
541 "error writing to rdmactl reg: %d\n", ret);
546 ret = regmap_fields_write(dmactl->dyncclk, id,
547 LPAIF_DMACTL_DYNCLK_OFF);
549 dev_err(soc_runtime->dev,
550 "error writing to rdmactl reg: %d\n", ret);
553 reg_irqen = LPASS_HDMITX_APP_IRQEN_REG(v);
554 val_mask = (LPAIF_IRQ_ALL(ch) |
555 LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
556 LPAIF_IRQ_HDMI_METADONE |
557 LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
562 reg_irqen = LPAIF_IRQEN_REG(v, LPAIF_IRQ_PORT_HOST);
563 val_mask = LPAIF_IRQ_ALL(ch);
567 dev_err(soc_runtime->dev, "%s: invalid %d interface\n", __func__, dai_id);
571 ret = regmap_update_bits(map, reg_irqen, val_mask, val_irqen);
573 dev_err(soc_runtime->dev,
574 "error writing to irqen reg: %d\n", ret);
583 static snd_pcm_uframes_t lpass_platform_pcmops_pointer(
584 struct snd_soc_component *component,
585 struct snd_pcm_substream *substream)
587 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
588 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
589 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
590 struct snd_pcm_runtime *rt = substream->runtime;
591 struct lpass_pcm_data *pcm_data = rt->private_data;
592 struct lpass_variant *v = drvdata->variant;
593 unsigned int base_addr, curr_addr;
594 int ret, ch, dir = substream->stream;
596 unsigned int dai_id = cpu_dai->driver->id;
598 if (dai_id == LPASS_DP_RX)
599 map = drvdata->hdmiif_map;
601 map = drvdata->lpaif_map;
603 ch = pcm_data->dma_ch;
605 ret = regmap_read(map,
606 LPAIF_DMABASE_REG(v, ch, dir, dai_id), &base_addr);
608 dev_err(soc_runtime->dev,
609 "error reading from rdmabase reg: %d\n", ret);
613 ret = regmap_read(map,
614 LPAIF_DMACURR_REG(v, ch, dir, dai_id), &curr_addr);
616 dev_err(soc_runtime->dev,
617 "error reading from rdmacurr reg: %d\n", ret);
621 return bytes_to_frames(substream->runtime, curr_addr - base_addr);
624 static int lpass_platform_pcmops_mmap(struct snd_soc_component *component,
625 struct snd_pcm_substream *substream,
626 struct vm_area_struct *vma)
628 struct snd_pcm_runtime *runtime = substream->runtime;
630 return dma_mmap_coherent(component->dev, vma, runtime->dma_area,
631 runtime->dma_addr, runtime->dma_bytes);
634 static irqreturn_t lpass_dma_interrupt_handler(
635 struct snd_pcm_substream *substream,
636 struct lpass_data *drvdata,
637 int chan, u32 interrupts)
639 struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
640 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
641 struct lpass_variant *v = drvdata->variant;
642 irqreturn_t ret = IRQ_NONE;
644 unsigned int reg = 0, val = 0;
646 unsigned int dai_id = cpu_dai->driver->id;
650 map = drvdata->hdmiif_map;
651 reg = LPASS_HDMITX_APP_IRQCLEAR_REG(v);
652 val = (LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(chan) |
653 LPAIF_IRQ_HDMI_METADONE |
654 LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(chan));
658 map = drvdata->lpaif_map;
659 reg = LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST);
663 dev_err(soc_runtime->dev, "%s: invalid %d interface\n", __func__, dai_id);
666 if (interrupts & LPAIF_IRQ_PER(chan)) {
668 rv = regmap_write(map, reg, LPAIF_IRQ_PER(chan) | val);
670 dev_err(soc_runtime->dev,
671 "error writing to irqclear reg: %d\n", rv);
674 snd_pcm_period_elapsed(substream);
678 if (interrupts & LPAIF_IRQ_XRUN(chan)) {
679 rv = regmap_write(map, reg, LPAIF_IRQ_XRUN(chan) | val);
681 dev_err(soc_runtime->dev,
682 "error writing to irqclear reg: %d\n", rv);
685 dev_warn(soc_runtime->dev, "xrun warning\n");
686 snd_pcm_stop_xrun(substream);
690 if (interrupts & LPAIF_IRQ_ERR(chan)) {
691 rv = regmap_write(map, reg, LPAIF_IRQ_ERR(chan) | val);
693 dev_err(soc_runtime->dev,
694 "error writing to irqclear reg: %d\n", rv);
697 dev_err(soc_runtime->dev, "bus access error\n");
698 snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
702 if (interrupts & val) {
703 rv = regmap_write(map, reg, val);
705 dev_err(soc_runtime->dev,
706 "error writing to irqclear reg: %d\n", rv);
715 static irqreturn_t lpass_platform_lpaif_irq(int irq, void *data)
717 struct lpass_data *drvdata = data;
718 struct lpass_variant *v = drvdata->variant;
722 rv = regmap_read(drvdata->lpaif_map,
723 LPAIF_IRQSTAT_REG(v, LPAIF_IRQ_PORT_HOST), &irqs);
725 pr_err("error reading from irqstat reg: %d\n", rv);
729 /* Handle per channel interrupts */
730 for (chan = 0; chan < LPASS_MAX_DMA_CHANNELS; chan++) {
731 if (irqs & LPAIF_IRQ_ALL(chan) && drvdata->substream[chan]) {
732 rv = lpass_dma_interrupt_handler(
733 drvdata->substream[chan],
734 drvdata, chan, irqs);
735 if (rv != IRQ_HANDLED)
743 static irqreturn_t lpass_platform_hdmiif_irq(int irq, void *data)
745 struct lpass_data *drvdata = data;
746 struct lpass_variant *v = drvdata->variant;
750 rv = regmap_read(drvdata->hdmiif_map,
751 LPASS_HDMITX_APP_IRQSTAT_REG(v), &irqs);
753 pr_err("error reading from irqstat reg: %d\n", rv);
757 /* Handle per channel interrupts */
758 for (chan = 0; chan < LPASS_MAX_HDMI_DMA_CHANNELS; chan++) {
759 if (irqs & (LPAIF_IRQ_ALL(chan) | LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(chan) |
760 LPAIF_IRQ_HDMI_METADONE |
761 LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(chan))
762 && drvdata->hdmi_substream[chan]) {
763 rv = lpass_dma_interrupt_handler(
764 drvdata->hdmi_substream[chan],
765 drvdata, chan, irqs);
766 if (rv != IRQ_HANDLED)
774 static int lpass_platform_pcm_new(struct snd_soc_component *component,
775 struct snd_soc_pcm_runtime *soc_runtime)
777 struct snd_pcm *pcm = soc_runtime->pcm;
778 struct snd_pcm_substream *psubstream, *csubstream;
780 size_t size = lpass_platform_pcm_hardware.buffer_bytes_max;
782 psubstream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
784 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
786 size, &psubstream->dma_buffer);
788 dev_err(soc_runtime->dev, "Cannot allocate buffer(s)\n");
793 csubstream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
795 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
797 size, &csubstream->dma_buffer);
799 dev_err(soc_runtime->dev, "Cannot allocate buffer(s)\n");
801 snd_dma_free_pages(&psubstream->dma_buffer);
810 static void lpass_platform_pcm_free(struct snd_soc_component *component,
813 struct snd_pcm_substream *substream;
816 for_each_pcm_streams(i) {
817 substream = pcm->streams[i].substream;
819 snd_dma_free_pages(&substream->dma_buffer);
820 substream->dma_buffer.area = NULL;
821 substream->dma_buffer.addr = 0;
826 static int lpass_platform_pcmops_suspend(struct snd_soc_component *component)
828 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
830 unsigned int dai_id = component->id;
832 if (dai_id == LPASS_DP_RX)
833 map = drvdata->hdmiif_map;
835 map = drvdata->lpaif_map;
837 regcache_cache_only(map, true);
838 regcache_mark_dirty(map);
843 static int lpass_platform_pcmops_resume(struct snd_soc_component *component)
845 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
847 unsigned int dai_id = component->id;
849 if (dai_id == LPASS_DP_RX)
850 map = drvdata->hdmiif_map;
852 map = drvdata->lpaif_map;
854 regcache_cache_only(map, false);
855 return regcache_sync(map);
859 static const struct snd_soc_component_driver lpass_component_driver = {
861 .open = lpass_platform_pcmops_open,
862 .close = lpass_platform_pcmops_close,
863 .hw_params = lpass_platform_pcmops_hw_params,
864 .hw_free = lpass_platform_pcmops_hw_free,
865 .prepare = lpass_platform_pcmops_prepare,
866 .trigger = lpass_platform_pcmops_trigger,
867 .pointer = lpass_platform_pcmops_pointer,
868 .mmap = lpass_platform_pcmops_mmap,
869 .pcm_construct = lpass_platform_pcm_new,
870 .pcm_destruct = lpass_platform_pcm_free,
871 .suspend = lpass_platform_pcmops_suspend,
872 .resume = lpass_platform_pcmops_resume,
876 int asoc_qcom_lpass_platform_register(struct platform_device *pdev)
878 struct lpass_data *drvdata = platform_get_drvdata(pdev);
879 struct lpass_variant *v = drvdata->variant;
882 drvdata->lpaif_irq = platform_get_irq_byname(pdev, "lpass-irq-lpaif");
883 if (drvdata->lpaif_irq < 0)
886 /* ensure audio hardware is disabled */
887 ret = regmap_write(drvdata->lpaif_map,
888 LPAIF_IRQEN_REG(v, LPAIF_IRQ_PORT_HOST), 0);
890 dev_err(&pdev->dev, "error writing to irqen reg: %d\n", ret);
894 ret = devm_request_irq(&pdev->dev, drvdata->lpaif_irq,
895 lpass_platform_lpaif_irq, IRQF_TRIGGER_RISING,
896 "lpass-irq-lpaif", drvdata);
898 dev_err(&pdev->dev, "irq request failed: %d\n", ret);
902 ret = lpass_platform_alloc_dmactl_fields(&pdev->dev,
906 "error initializing dmactl fields: %d\n", ret);
910 if (drvdata->hdmi_port_enable) {
911 drvdata->hdmiif_irq = platform_get_irq_byname(pdev, "lpass-irq-hdmi");
912 if (drvdata->hdmiif_irq < 0)
915 ret = devm_request_irq(&pdev->dev, drvdata->hdmiif_irq,
916 lpass_platform_hdmiif_irq, 0, "lpass-irq-hdmi", drvdata);
918 dev_err(&pdev->dev, "irq hdmi request failed: %d\n", ret);
921 ret = regmap_write(drvdata->hdmiif_map,
922 LPASS_HDMITX_APP_IRQEN_REG(v), 0);
924 dev_err(&pdev->dev, "error writing to hdmi irqen reg: %d\n", ret);
928 ret = lpass_platform_alloc_hdmidmactl_fields(&pdev->dev,
929 drvdata->hdmiif_map);
932 "error initializing hdmidmactl fields: %d\n", ret);
936 return devm_snd_soc_register_component(&pdev->dev,
937 &lpass_component_driver, NULL, 0);
939 EXPORT_SYMBOL_GPL(asoc_qcom_lpass_platform_register);
941 MODULE_DESCRIPTION("QTi LPASS Platform Driver");
942 MODULE_LICENSE("GPL v2");