hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/soc/qcom/lpass-platform.c
....@@ -1,14 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 and
6
- * only version 2 as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
124 *
135 * lpass-platform.c -- ALSA SoC platform driver for QTi LPASS
146 */
....@@ -31,7 +23,7 @@
3123 int i2s_port;
3224 };
3325
34
-#define LPASS_PLATFORM_BUFFER_SIZE (16 * 1024)
26
+#define LPASS_PLATFORM_BUFFER_SIZE (24 * 2 * 1024)
3527 #define LPASS_PLATFORM_PERIODS 2
3628
3729 static const struct snd_pcm_hardware lpass_platform_pcm_hardware = {
....@@ -58,17 +50,67 @@
5850 .fifo_size = 0,
5951 };
6052
61
-static int lpass_platform_pcmops_open(struct snd_pcm_substream *substream)
53
+static int lpass_platform_alloc_dmactl_fields(struct device *dev,
54
+ struct regmap *map)
55
+{
56
+ struct lpass_data *drvdata = dev_get_drvdata(dev);
57
+ struct lpass_variant *v = drvdata->variant;
58
+ struct lpaif_dmactl *rd_dmactl, *wr_dmactl;
59
+ int rval;
60
+
61
+ drvdata->rd_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl),
62
+ GFP_KERNEL);
63
+ if (drvdata->rd_dmactl == NULL)
64
+ return -ENOMEM;
65
+
66
+ drvdata->wr_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl),
67
+ GFP_KERNEL);
68
+ if (drvdata->wr_dmactl == NULL)
69
+ return -ENOMEM;
70
+
71
+ rd_dmactl = drvdata->rd_dmactl;
72
+ wr_dmactl = drvdata->wr_dmactl;
73
+
74
+ rval = devm_regmap_field_bulk_alloc(dev, map, &rd_dmactl->intf,
75
+ &v->rdma_intf, 6);
76
+ if (rval)
77
+ return rval;
78
+
79
+ return devm_regmap_field_bulk_alloc(dev, map, &wr_dmactl->intf,
80
+ &v->wrdma_intf, 6);
81
+}
82
+
83
+static int lpass_platform_alloc_hdmidmactl_fields(struct device *dev,
84
+ struct regmap *map)
85
+{
86
+ struct lpass_data *drvdata = dev_get_drvdata(dev);
87
+ struct lpass_variant *v = drvdata->variant;
88
+ struct lpaif_dmactl *rd_dmactl;
89
+
90
+ rd_dmactl = devm_kzalloc(dev, sizeof(struct lpaif_dmactl), GFP_KERNEL);
91
+ if (rd_dmactl == NULL)
92
+ return -ENOMEM;
93
+
94
+ drvdata->hdmi_rd_dmactl = rd_dmactl;
95
+
96
+ return devm_regmap_field_bulk_alloc(dev, map, &rd_dmactl->bursten,
97
+ &v->hdmi_rdma_bursten, 8);
98
+}
99
+
100
+static int lpass_platform_pcmops_open(struct snd_soc_component *component,
101
+ struct snd_pcm_substream *substream)
62102 {
63103 struct snd_pcm_runtime *runtime = substream->runtime;
64
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
65
- struct snd_soc_dai *cpu_dai = soc_runtime->cpu_dai;
66
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
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);
67106 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
68107 struct lpass_variant *v = drvdata->variant;
69108 int ret, dma_ch, dir = substream->stream;
70109 struct lpass_pcm_data *data;
110
+ struct regmap *map;
111
+ unsigned int dai_id = cpu_dai->driver->id;
71112
113
+ component->id = dai_id;
72114 data = kzalloc(sizeof(*data), GFP_KERNEL);
73115 if (!data)
74116 return -ENOMEM;
....@@ -77,7 +119,7 @@
77119 runtime->private_data = data;
78120
79121 if (v->alloc_dma_channel)
80
- dma_ch = v->alloc_dma_channel(drvdata, dir);
122
+ dma_ch = v->alloc_dma_channel(drvdata, dir, dai_id);
81123 else
82124 dma_ch = 0;
83125
....@@ -86,18 +128,21 @@
86128 return dma_ch;
87129 }
88130
89
- drvdata->substream[dma_ch] = substream;
90
-
91
- ret = regmap_write(drvdata->lpaif_map,
92
- LPAIF_DMACTL_REG(v, dma_ch, dir), 0);
131
+ if (cpu_dai->driver->id == LPASS_DP_RX) {
132
+ map = drvdata->hdmiif_map;
133
+ drvdata->hdmi_substream[dma_ch] = substream;
134
+ } else {
135
+ map = drvdata->lpaif_map;
136
+ drvdata->substream[dma_ch] = substream;
137
+ }
138
+ data->dma_ch = dma_ch;
139
+ ret = regmap_write(map,
140
+ LPAIF_DMACTL_REG(v, dma_ch, dir, data->i2s_port), 0);
93141 if (ret) {
94142 dev_err(soc_runtime->dev,
95143 "error writing to rdmactl reg: %d\n", ret);
96
- return ret;
144
+ return ret;
97145 }
98
-
99
- data->dma_ch = dma_ch;
100
-
101146 snd_soc_set_runtime_hwparams(substream, &lpass_platform_pcm_hardware);
102147
103148 runtime->dma_bytes = lpass_platform_pcm_hardware.buffer_bytes_max;
....@@ -116,29 +161,35 @@
116161 return 0;
117162 }
118163
119
-static int lpass_platform_pcmops_close(struct snd_pcm_substream *substream)
164
+static int lpass_platform_pcmops_close(struct snd_soc_component *component,
165
+ struct snd_pcm_substream *substream)
120166 {
121167 struct snd_pcm_runtime *runtime = substream->runtime;
122
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
123
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
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);
124170 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
125171 struct lpass_variant *v = drvdata->variant;
126172 struct lpass_pcm_data *data;
173
+ unsigned int dai_id = cpu_dai->driver->id;
127174
128175 data = runtime->private_data;
129
- drvdata->substream[data->dma_ch] = NULL;
176
+ if (dai_id == LPASS_DP_RX)
177
+ drvdata->hdmi_substream[data->dma_ch] = NULL;
178
+ else
179
+ drvdata->substream[data->dma_ch] = NULL;
130180 if (v->free_dma_channel)
131
- v->free_dma_channel(drvdata, data->dma_ch);
181
+ v->free_dma_channel(drvdata, data->dma_ch, dai_id);
132182
133183 kfree(data);
134184 return 0;
135185 }
136186
137
-static int lpass_platform_pcmops_hw_params(struct snd_pcm_substream *substream,
138
- struct snd_pcm_hw_params *params)
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)
139190 {
140
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
141
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
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);
142193 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
143194 struct snd_pcm_runtime *rt = substream->runtime;
144195 struct lpass_pcm_data *pcm_data = rt->private_data;
....@@ -146,11 +197,23 @@
146197 snd_pcm_format_t format = params_format(params);
147198 unsigned int channels = params_channels(params);
148199 unsigned int regval;
149
- int ch, dir = substream->stream;
200
+ struct lpaif_dmactl *dmactl;
201
+ int id, dir = substream->stream;
150202 int bitwidth;
151203 int ret, dma_port = pcm_data->i2s_port + v->dmactl_audif_start;
204
+ unsigned int dai_id = cpu_dai->driver->id;
152205
153
- ch = pcm_data->dma_ch;
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;
210
+ else
211
+ dmactl = drvdata->rd_dmactl;
212
+
213
+ } else {
214
+ dmactl = drvdata->wr_dmactl;
215
+ id = pcm_data->dma_ch - v->wrdma_channel_start;
216
+ }
154217
155218 bitwidth = snd_pcm_format_width(format);
156219 if (bitwidth < 0) {
....@@ -159,29 +222,75 @@
159222 return bitwidth;
160223 }
161224
162
- regval = LPAIF_DMACTL_BURSTEN_INCR4 |
163
- LPAIF_DMACTL_AUDINTF(dma_port) |
164
- LPAIF_DMACTL_FIFOWM_8;
225
+ ret = regmap_fields_write(dmactl->bursten, id, LPAIF_DMACTL_BURSTEN_INCR4);
226
+ if (ret) {
227
+ dev_err(soc_runtime->dev, "error updating bursten field: %d\n", ret);
228
+ return ret;
229
+ }
165230
231
+ ret = regmap_fields_write(dmactl->fifowm, id, LPAIF_DMACTL_FIFOWM_8);
232
+ if (ret) {
233
+ dev_err(soc_runtime->dev, "error updating fifowm field: %d\n", ret);
234
+ return ret;
235
+ }
236
+
237
+ switch (dai_id) {
238
+ case LPASS_DP_RX:
239
+ ret = regmap_fields_write(dmactl->burst8, id,
240
+ LPAIF_DMACTL_BURSTEN_INCR4);
241
+ if (ret) {
242
+ dev_err(soc_runtime->dev, "error updating burst8en field: %d\n", ret);
243
+ return ret;
244
+ }
245
+ ret = regmap_fields_write(dmactl->burst16, id,
246
+ LPAIF_DMACTL_BURSTEN_INCR4);
247
+ if (ret) {
248
+ dev_err(soc_runtime->dev, "error updating burst16en field: %d\n", ret);
249
+ return ret;
250
+ }
251
+ ret = regmap_fields_write(dmactl->dynburst, id,
252
+ LPAIF_DMACTL_BURSTEN_INCR4);
253
+ if (ret) {
254
+ dev_err(soc_runtime->dev, "error updating dynbursten field: %d\n", ret);
255
+ return ret;
256
+ }
257
+ break;
258
+ case MI2S_PRIMARY:
259
+ case MI2S_SECONDARY:
260
+ case MI2S_TERTIARY:
261
+ case MI2S_QUATERNARY:
262
+ case MI2S_QUINARY:
263
+ ret = regmap_fields_write(dmactl->intf, id,
264
+ LPAIF_DMACTL_AUDINTF(dma_port));
265
+ if (ret) {
266
+ dev_err(soc_runtime->dev, "error updating audio interface field: %d\n",
267
+ ret);
268
+ return ret;
269
+ }
270
+
271
+ break;
272
+ default:
273
+ dev_err(soc_runtime->dev, "%s: invalid interface: %d\n", __func__, dai_id);
274
+ break;
275
+ }
166276 switch (bitwidth) {
167277 case 16:
168278 switch (channels) {
169279 case 1:
170280 case 2:
171
- regval |= LPAIF_DMACTL_WPSCNT_ONE;
281
+ regval = LPAIF_DMACTL_WPSCNT_ONE;
172282 break;
173283 case 4:
174
- regval |= LPAIF_DMACTL_WPSCNT_TWO;
284
+ regval = LPAIF_DMACTL_WPSCNT_TWO;
175285 break;
176286 case 6:
177
- regval |= LPAIF_DMACTL_WPSCNT_THREE;
287
+ regval = LPAIF_DMACTL_WPSCNT_THREE;
178288 break;
179289 case 8:
180
- regval |= LPAIF_DMACTL_WPSCNT_FOUR;
290
+ regval = LPAIF_DMACTL_WPSCNT_FOUR;
181291 break;
182292 default:
183
- dev_err(soc_runtime->dev,
184
- "invalid PCM config given: bw=%d, ch=%u\n",
293
+ dev_err(soc_runtime->dev, "invalid PCM config given: bw=%d, ch=%u\n",
185294 bitwidth, channels);
186295 return -EINVAL;
187296 }
....@@ -190,23 +299,30 @@
190299 case 32:
191300 switch (channels) {
192301 case 1:
193
- regval |= LPAIF_DMACTL_WPSCNT_ONE;
302
+ regval = LPAIF_DMACTL_WPSCNT_ONE;
194303 break;
195304 case 2:
196
- regval |= LPAIF_DMACTL_WPSCNT_TWO;
305
+ regval = (dai_id == LPASS_DP_RX ?
306
+ LPAIF_DMACTL_WPSCNT_ONE :
307
+ LPAIF_DMACTL_WPSCNT_TWO);
197308 break;
198309 case 4:
199
- regval |= LPAIF_DMACTL_WPSCNT_FOUR;
310
+ regval = (dai_id == LPASS_DP_RX ?
311
+ LPAIF_DMACTL_WPSCNT_TWO :
312
+ LPAIF_DMACTL_WPSCNT_FOUR);
200313 break;
201314 case 6:
202
- regval |= LPAIF_DMACTL_WPSCNT_SIX;
315
+ regval = (dai_id == LPASS_DP_RX ?
316
+ LPAIF_DMACTL_WPSCNT_THREE :
317
+ LPAIF_DMACTL_WPSCNT_SIX);
203318 break;
204319 case 8:
205
- regval |= LPAIF_DMACTL_WPSCNT_EIGHT;
320
+ regval = (dai_id == LPASS_DP_RX ?
321
+ LPAIF_DMACTL_WPSCNT_FOUR :
322
+ LPAIF_DMACTL_WPSCNT_EIGHT);
206323 break;
207324 default:
208
- dev_err(soc_runtime->dev,
209
- "invalid PCM config given: bw=%d, ch=%u\n",
325
+ dev_err(soc_runtime->dev, "invalid PCM config given: bw=%d, ch=%u\n",
210326 bitwidth, channels);
211327 return -EINVAL;
212328 }
....@@ -217,10 +333,9 @@
217333 return -EINVAL;
218334 }
219335
220
- ret = regmap_write(drvdata->lpaif_map,
221
- LPAIF_DMACTL_REG(v, ch, dir), regval);
336
+ ret = regmap_fields_write(dmactl->wpscnt, id, regval);
222337 if (ret) {
223
- dev_err(soc_runtime->dev, "error writing to rdmactl reg: %d\n",
338
+ dev_err(soc_runtime->dev, "error writing to dmactl reg: %d\n",
224339 ret);
225340 return ret;
226341 }
....@@ -228,19 +343,27 @@
228343 return 0;
229344 }
230345
231
-static int lpass_platform_pcmops_hw_free(struct snd_pcm_substream *substream)
346
+static int lpass_platform_pcmops_hw_free(struct snd_soc_component *component,
347
+ struct snd_pcm_substream *substream)
232348 {
233
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
234
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
349
+ struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
350
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
235351 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
236352 struct snd_pcm_runtime *rt = substream->runtime;
237353 struct lpass_pcm_data *pcm_data = rt->private_data;
238354 struct lpass_variant *v = drvdata->variant;
239355 unsigned int reg;
240356 int ret;
357
+ struct regmap *map;
358
+ unsigned int dai_id = cpu_dai->driver->id;
241359
242
- reg = LPAIF_DMACTL_REG(v, pcm_data->dma_ch, substream->stream);
243
- ret = regmap_write(drvdata->lpaif_map, reg, 0);
360
+ if (dai_id == LPASS_DP_RX)
361
+ map = drvdata->hdmiif_map;
362
+ else
363
+ map = drvdata->lpaif_map;
364
+
365
+ reg = LPAIF_DMACTL_REG(v, pcm_data->dma_ch, substream->stream, dai_id);
366
+ ret = regmap_write(map, reg, 0);
244367 if (ret)
245368 dev_err(soc_runtime->dev, "error writing to rdmactl reg: %d\n",
246369 ret);
....@@ -248,30 +371,48 @@
248371 return ret;
249372 }
250373
251
-static int lpass_platform_pcmops_prepare(struct snd_pcm_substream *substream)
374
+static int lpass_platform_pcmops_prepare(struct snd_soc_component *component,
375
+ struct snd_pcm_substream *substream)
252376 {
253377 struct snd_pcm_runtime *runtime = substream->runtime;
254
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
255
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
378
+ struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
379
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
256380 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
257381 struct snd_pcm_runtime *rt = substream->runtime;
258382 struct lpass_pcm_data *pcm_data = rt->private_data;
259383 struct lpass_variant *v = drvdata->variant;
260
- int ret, ch, dir = substream->stream;
384
+ struct lpaif_dmactl *dmactl;
385
+ struct regmap *map;
386
+ int ret, id, ch, dir = substream->stream;
387
+ unsigned int dai_id = cpu_dai->driver->id;
388
+
261389
262390 ch = pcm_data->dma_ch;
391
+ if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
392
+ if (dai_id == LPASS_DP_RX) {
393
+ dmactl = drvdata->hdmi_rd_dmactl;
394
+ map = drvdata->hdmiif_map;
395
+ } else {
396
+ dmactl = drvdata->rd_dmactl;
397
+ map = drvdata->lpaif_map;
398
+ }
263399
264
- ret = regmap_write(drvdata->lpaif_map,
265
- LPAIF_DMABASE_REG(v, ch, dir),
266
- runtime->dma_addr);
400
+ id = pcm_data->dma_ch;
401
+ } else {
402
+ dmactl = drvdata->wr_dmactl;
403
+ id = pcm_data->dma_ch - v->wrdma_channel_start;
404
+ map = drvdata->lpaif_map;
405
+ }
406
+
407
+ ret = regmap_write(map, LPAIF_DMABASE_REG(v, ch, dir, dai_id),
408
+ runtime->dma_addr);
267409 if (ret) {
268410 dev_err(soc_runtime->dev, "error writing to rdmabase reg: %d\n",
269411 ret);
270412 return ret;
271413 }
272414
273
- ret = regmap_write(drvdata->lpaif_map,
274
- LPAIF_DMABUFF_REG(v, ch, dir),
415
+ ret = regmap_write(map, LPAIF_DMABUFF_REG(v, ch, dir, dai_id),
275416 (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1);
276417 if (ret) {
277418 dev_err(soc_runtime->dev, "error writing to rdmabuff reg: %d\n",
....@@ -279,8 +420,7 @@
279420 return ret;
280421 }
281422
282
- ret = regmap_write(drvdata->lpaif_map,
283
- LPAIF_DMAPER_REG(v, ch, dir),
423
+ ret = regmap_write(map, LPAIF_DMAPER_REG(v, ch, dir, dai_id),
284424 (snd_pcm_lib_period_bytes(substream) >> 2) - 1);
285425 if (ret) {
286426 dev_err(soc_runtime->dev, "error writing to rdmaper reg: %d\n",
....@@ -288,9 +428,7 @@
288428 return ret;
289429 }
290430
291
- ret = regmap_update_bits(drvdata->lpaif_map,
292
- LPAIF_DMACTL_REG(v, ch, dir),
293
- LPAIF_DMACTL_ENABLE_MASK, LPAIF_DMACTL_ENABLE_ON);
431
+ ret = regmap_fields_write(dmactl->enable, id, LPAIF_DMACTL_ENABLE_ON);
294432 if (ret) {
295433 dev_err(soc_runtime->dev, "error writing to rdmactl reg: %d\n",
296434 ret);
....@@ -300,69 +438,146 @@
300438 return 0;
301439 }
302440
303
-static int lpass_platform_pcmops_trigger(struct snd_pcm_substream *substream,
304
- int cmd)
441
+static int lpass_platform_pcmops_trigger(struct snd_soc_component *component,
442
+ struct snd_pcm_substream *substream,
443
+ int cmd)
305444 {
306
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
307
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
445
+ struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
446
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
308447 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
309448 struct snd_pcm_runtime *rt = substream->runtime;
310449 struct lpass_pcm_data *pcm_data = rt->private_data;
311450 struct lpass_variant *v = drvdata->variant;
312
- int ret, ch, dir = substream->stream;
451
+ struct lpaif_dmactl *dmactl;
452
+ struct regmap *map;
453
+ int ret, ch, id;
454
+ int dir = substream->stream;
455
+ unsigned int reg_irqclr = 0, val_irqclr = 0;
456
+ unsigned int reg_irqen = 0, val_irqen = 0, val_mask = 0;
457
+ unsigned int dai_id = cpu_dai->driver->id;
313458
314459 ch = pcm_data->dma_ch;
460
+ if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
461
+ id = pcm_data->dma_ch;
462
+ if (dai_id == LPASS_DP_RX) {
463
+ dmactl = drvdata->hdmi_rd_dmactl;
464
+ map = drvdata->hdmiif_map;
465
+ } else {
466
+ dmactl = drvdata->rd_dmactl;
467
+ map = drvdata->lpaif_map;
468
+ }
469
+ } else {
470
+ dmactl = drvdata->wr_dmactl;
471
+ id = pcm_data->dma_ch - v->wrdma_channel_start;
472
+ map = drvdata->lpaif_map;
473
+ }
315474
316475 switch (cmd) {
317476 case SNDRV_PCM_TRIGGER_START:
318477 case SNDRV_PCM_TRIGGER_RESUME:
319478 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
320
- /* clear status before enabling interrupts */
321
- ret = regmap_write(drvdata->lpaif_map,
322
- LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST),
323
- LPAIF_IRQ_ALL(ch));
324
- if (ret) {
325
- dev_err(soc_runtime->dev,
326
- "error writing to irqclear reg: %d\n", ret);
327
- return ret;
328
- }
329
-
330
- ret = regmap_update_bits(drvdata->lpaif_map,
331
- LPAIF_IRQEN_REG(v, LPAIF_IRQ_PORT_HOST),
332
- LPAIF_IRQ_ALL(ch),
333
- LPAIF_IRQ_ALL(ch));
334
- if (ret) {
335
- dev_err(soc_runtime->dev,
336
- "error writing to irqen reg: %d\n", ret);
337
- return ret;
338
- }
339
-
340
- ret = regmap_update_bits(drvdata->lpaif_map,
341
- LPAIF_DMACTL_REG(v, ch, dir),
342
- LPAIF_DMACTL_ENABLE_MASK,
343
- LPAIF_DMACTL_ENABLE_ON);
479
+ ret = regmap_fields_write(dmactl->enable, id,
480
+ LPAIF_DMACTL_ENABLE_ON);
344481 if (ret) {
345482 dev_err(soc_runtime->dev,
346483 "error writing to rdmactl reg: %d\n", ret);
484
+ return ret;
485
+ }
486
+ switch (dai_id) {
487
+ case LPASS_DP_RX:
488
+ ret = regmap_fields_write(dmactl->dyncclk, id,
489
+ LPAIF_DMACTL_DYNCLK_ON);
490
+ if (ret) {
491
+ dev_err(soc_runtime->dev,
492
+ "error writing to rdmactl reg: %d\n", ret);
493
+ return ret;
494
+ }
495
+ reg_irqclr = LPASS_HDMITX_APP_IRQCLEAR_REG(v);
496
+ val_irqclr = (LPAIF_IRQ_ALL(ch) |
497
+ LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
498
+ LPAIF_IRQ_HDMI_METADONE |
499
+ LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
500
+
501
+ reg_irqen = LPASS_HDMITX_APP_IRQEN_REG(v);
502
+ val_mask = (LPAIF_IRQ_ALL(ch) |
503
+ LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
504
+ LPAIF_IRQ_HDMI_METADONE |
505
+ LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
506
+ val_irqen = (LPAIF_IRQ_ALL(ch) |
507
+ LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
508
+ LPAIF_IRQ_HDMI_METADONE |
509
+ LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
510
+ break;
511
+ case MI2S_PRIMARY:
512
+ case MI2S_SECONDARY:
513
+ case MI2S_TERTIARY:
514
+ case MI2S_QUATERNARY:
515
+ case MI2S_QUINARY:
516
+ reg_irqclr = LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST);
517
+ val_irqclr = LPAIF_IRQ_ALL(ch);
518
+
519
+
520
+ reg_irqen = LPAIF_IRQEN_REG(v, LPAIF_IRQ_PORT_HOST);
521
+ val_mask = LPAIF_IRQ_ALL(ch);
522
+ val_irqen = LPAIF_IRQ_ALL(ch);
523
+ break;
524
+ default:
525
+ dev_err(soc_runtime->dev, "%s: invalid %d interface\n", __func__, dai_id);
526
+ return -EINVAL;
527
+ }
528
+
529
+ ret = regmap_write(map, reg_irqclr, val_irqclr);
530
+ if (ret) {
531
+ dev_err(soc_runtime->dev, "error writing to irqclear reg: %d\n", ret);
532
+ return ret;
533
+ }
534
+ ret = regmap_update_bits(map, reg_irqen, val_mask, val_irqen);
535
+ if (ret) {
536
+ dev_err(soc_runtime->dev, "error writing to irqen reg: %d\n", ret);
347537 return ret;
348538 }
349539 break;
350540 case SNDRV_PCM_TRIGGER_STOP:
351541 case SNDRV_PCM_TRIGGER_SUSPEND:
352542 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
353
- ret = regmap_update_bits(drvdata->lpaif_map,
354
- LPAIF_DMACTL_REG(v, ch, dir),
355
- LPAIF_DMACTL_ENABLE_MASK,
356
- LPAIF_DMACTL_ENABLE_OFF);
543
+ ret = regmap_fields_write(dmactl->enable, id,
544
+ LPAIF_DMACTL_ENABLE_OFF);
357545 if (ret) {
358546 dev_err(soc_runtime->dev,
359547 "error writing to rdmactl reg: %d\n", ret);
360548 return ret;
361549 }
550
+ switch (dai_id) {
551
+ case LPASS_DP_RX:
552
+ ret = regmap_fields_write(dmactl->dyncclk, id,
553
+ LPAIF_DMACTL_DYNCLK_OFF);
554
+ if (ret) {
555
+ dev_err(soc_runtime->dev,
556
+ "error writing to rdmactl reg: %d\n", ret);
557
+ return ret;
558
+ }
559
+ reg_irqen = LPASS_HDMITX_APP_IRQEN_REG(v);
560
+ val_mask = (LPAIF_IRQ_ALL(ch) |
561
+ LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(ch) |
562
+ LPAIF_IRQ_HDMI_METADONE |
563
+ LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(ch));
564
+ val_irqen = 0;
565
+ break;
566
+ case MI2S_PRIMARY:
567
+ case MI2S_SECONDARY:
568
+ case MI2S_TERTIARY:
569
+ case MI2S_QUATERNARY:
570
+ case MI2S_QUINARY:
571
+ reg_irqen = LPAIF_IRQEN_REG(v, LPAIF_IRQ_PORT_HOST);
572
+ val_mask = LPAIF_IRQ_ALL(ch);
573
+ val_irqen = 0;
574
+ break;
575
+ default:
576
+ dev_err(soc_runtime->dev, "%s: invalid %d interface\n", __func__, dai_id);
577
+ return -EINVAL;
578
+ }
362579
363
- ret = regmap_update_bits(drvdata->lpaif_map,
364
- LPAIF_IRQEN_REG(v, LPAIF_IRQ_PORT_HOST),
365
- LPAIF_IRQ_ALL(ch), 0);
580
+ ret = regmap_update_bits(map, reg_irqen, val_mask, val_irqen);
366581 if (ret) {
367582 dev_err(soc_runtime->dev,
368583 "error writing to irqen reg: %d\n", ret);
....@@ -375,29 +590,37 @@
375590 }
376591
377592 static snd_pcm_uframes_t lpass_platform_pcmops_pointer(
593
+ struct snd_soc_component *component,
378594 struct snd_pcm_substream *substream)
379595 {
380
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
381
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
596
+ struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
597
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
382598 struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
383599 struct snd_pcm_runtime *rt = substream->runtime;
384600 struct lpass_pcm_data *pcm_data = rt->private_data;
385601 struct lpass_variant *v = drvdata->variant;
386602 unsigned int base_addr, curr_addr;
387603 int ret, ch, dir = substream->stream;
604
+ struct regmap *map;
605
+ unsigned int dai_id = cpu_dai->driver->id;
606
+
607
+ if (dai_id == LPASS_DP_RX)
608
+ map = drvdata->hdmiif_map;
609
+ else
610
+ map = drvdata->lpaif_map;
388611
389612 ch = pcm_data->dma_ch;
390613
391
- ret = regmap_read(drvdata->lpaif_map,
392
- LPAIF_DMABASE_REG(v, ch, dir), &base_addr);
614
+ ret = regmap_read(map,
615
+ LPAIF_DMABASE_REG(v, ch, dir, dai_id), &base_addr);
393616 if (ret) {
394617 dev_err(soc_runtime->dev,
395618 "error reading from rdmabase reg: %d\n", ret);
396619 return ret;
397620 }
398621
399
- ret = regmap_read(drvdata->lpaif_map,
400
- LPAIF_DMACURR_REG(v, ch, dir), &curr_addr);
622
+ ret = regmap_read(map,
623
+ LPAIF_DMACURR_REG(v, ch, dir, dai_id), &curr_addr);
401624 if (ret) {
402625 dev_err(soc_runtime->dev,
403626 "error reading from rdmacurr reg: %d\n", ret);
....@@ -407,42 +630,54 @@
407630 return bytes_to_frames(substream->runtime, curr_addr - base_addr);
408631 }
409632
410
-static int lpass_platform_pcmops_mmap(struct snd_pcm_substream *substream,
411
- struct vm_area_struct *vma)
633
+static int lpass_platform_pcmops_mmap(struct snd_soc_component *component,
634
+ struct snd_pcm_substream *substream,
635
+ struct vm_area_struct *vma)
412636 {
413637 struct snd_pcm_runtime *runtime = substream->runtime;
414638
415
- return dma_mmap_coherent(substream->pcm->card->dev, vma,
416
- runtime->dma_area, runtime->dma_addr,
417
- runtime->dma_bytes);
639
+ return dma_mmap_coherent(component->dev, vma, runtime->dma_area,
640
+ runtime->dma_addr, runtime->dma_bytes);
418641 }
419
-
420
-static const struct snd_pcm_ops lpass_platform_pcm_ops = {
421
- .open = lpass_platform_pcmops_open,
422
- .close = lpass_platform_pcmops_close,
423
- .ioctl = snd_pcm_lib_ioctl,
424
- .hw_params = lpass_platform_pcmops_hw_params,
425
- .hw_free = lpass_platform_pcmops_hw_free,
426
- .prepare = lpass_platform_pcmops_prepare,
427
- .trigger = lpass_platform_pcmops_trigger,
428
- .pointer = lpass_platform_pcmops_pointer,
429
- .mmap = lpass_platform_pcmops_mmap,
430
-};
431642
432643 static irqreturn_t lpass_dma_interrupt_handler(
433644 struct snd_pcm_substream *substream,
434645 struct lpass_data *drvdata,
435646 int chan, u32 interrupts)
436647 {
437
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
648
+ struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
649
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
438650 struct lpass_variant *v = drvdata->variant;
439651 irqreturn_t ret = IRQ_NONE;
440652 int rv;
653
+ unsigned int reg = 0, val = 0;
654
+ struct regmap *map;
655
+ unsigned int dai_id = cpu_dai->driver->id;
441656
657
+ switch (dai_id) {
658
+ case LPASS_DP_RX:
659
+ map = drvdata->hdmiif_map;
660
+ reg = LPASS_HDMITX_APP_IRQCLEAR_REG(v);
661
+ val = (LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(chan) |
662
+ LPAIF_IRQ_HDMI_METADONE |
663
+ LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(chan));
664
+ break;
665
+ case MI2S_PRIMARY:
666
+ case MI2S_SECONDARY:
667
+ case MI2S_TERTIARY:
668
+ case MI2S_QUATERNARY:
669
+ case MI2S_QUINARY:
670
+ map = drvdata->lpaif_map;
671
+ reg = LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST);
672
+ val = 0;
673
+ break;
674
+ default:
675
+ dev_err(soc_runtime->dev, "%s: invalid %d interface\n", __func__, dai_id);
676
+ return -EINVAL;
677
+ }
442678 if (interrupts & LPAIF_IRQ_PER(chan)) {
443
- rv = regmap_write(drvdata->lpaif_map,
444
- LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST),
445
- LPAIF_IRQ_PER(chan));
679
+
680
+ rv = regmap_write(map, reg, LPAIF_IRQ_PER(chan) | val);
446681 if (rv) {
447682 dev_err(soc_runtime->dev,
448683 "error writing to irqclear reg: %d\n", rv);
....@@ -453,9 +688,7 @@
453688 }
454689
455690 if (interrupts & LPAIF_IRQ_XRUN(chan)) {
456
- rv = regmap_write(drvdata->lpaif_map,
457
- LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST),
458
- LPAIF_IRQ_XRUN(chan));
691
+ rv = regmap_write(map, reg, LPAIF_IRQ_XRUN(chan) | val);
459692 if (rv) {
460693 dev_err(soc_runtime->dev,
461694 "error writing to irqclear reg: %d\n", rv);
....@@ -467,9 +700,7 @@
467700 }
468701
469702 if (interrupts & LPAIF_IRQ_ERR(chan)) {
470
- rv = regmap_write(drvdata->lpaif_map,
471
- LPAIF_IRQCLEAR_REG(v, LPAIF_IRQ_PORT_HOST),
472
- LPAIF_IRQ_ERR(chan));
703
+ rv = regmap_write(map, reg, LPAIF_IRQ_ERR(chan) | val);
473704 if (rv) {
474705 dev_err(soc_runtime->dev,
475706 "error writing to irqclear reg: %d\n", rv);
....@@ -477,6 +708,16 @@
477708 }
478709 dev_err(soc_runtime->dev, "bus access error\n");
479710 snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
711
+ ret = IRQ_HANDLED;
712
+ }
713
+
714
+ if (interrupts & val) {
715
+ rv = regmap_write(map, reg, val);
716
+ if (rv) {
717
+ dev_err(soc_runtime->dev,
718
+ "error writing to irqclear reg: %d\n", rv);
719
+ return IRQ_NONE;
720
+ }
480721 ret = IRQ_HANDLED;
481722 }
482723
....@@ -511,11 +752,42 @@
511752 return IRQ_HANDLED;
512753 }
513754
514
-static int lpass_platform_pcm_new(struct snd_soc_pcm_runtime *soc_runtime)
755
+static irqreturn_t lpass_platform_hdmiif_irq(int irq, void *data)
756
+{
757
+ struct lpass_data *drvdata = data;
758
+ struct lpass_variant *v = drvdata->variant;
759
+ unsigned int irqs;
760
+ int rv, chan;
761
+
762
+ rv = regmap_read(drvdata->hdmiif_map,
763
+ LPASS_HDMITX_APP_IRQSTAT_REG(v), &irqs);
764
+ if (rv) {
765
+ pr_err("error reading from irqstat reg: %d\n", rv);
766
+ return IRQ_NONE;
767
+ }
768
+
769
+ /* Handle per channel interrupts */
770
+ for (chan = 0; chan < LPASS_MAX_HDMI_DMA_CHANNELS; chan++) {
771
+ if (irqs & (LPAIF_IRQ_ALL(chan) | LPAIF_IRQ_HDMI_REQ_ON_PRELOAD(chan) |
772
+ LPAIF_IRQ_HDMI_METADONE |
773
+ LPAIF_IRQ_HDMI_SDEEP_AUD_DIS(chan))
774
+ && drvdata->hdmi_substream[chan]) {
775
+ rv = lpass_dma_interrupt_handler(
776
+ drvdata->hdmi_substream[chan],
777
+ drvdata, chan, irqs);
778
+ if (rv != IRQ_HANDLED)
779
+ return rv;
780
+ }
781
+ }
782
+
783
+ return IRQ_HANDLED;
784
+}
785
+
786
+static int lpass_platform_pcm_new(struct snd_soc_component *component,
787
+ struct snd_soc_pcm_runtime *soc_runtime)
515788 {
516789 struct snd_pcm *pcm = soc_runtime->pcm;
517790 struct snd_pcm_substream *psubstream, *csubstream;
518
- struct snd_soc_component *component = snd_soc_rtdcom_lookup(soc_runtime, DRV_NAME);
519791 int ret = -EINVAL;
520792 size_t size = lpass_platform_pcm_hardware.buffer_bytes_max;
521793
....@@ -547,12 +819,13 @@
547819 return 0;
548820 }
549821
550
-static void lpass_platform_pcm_free(struct snd_pcm *pcm)
822
+static void lpass_platform_pcm_free(struct snd_soc_component *component,
823
+ struct snd_pcm *pcm)
551824 {
552825 struct snd_pcm_substream *substream;
553826 int i;
554827
555
- for (i = 0; i < ARRAY_SIZE(pcm->streams); i++) {
828
+ for_each_pcm_streams(i) {
556829 substream = pcm->streams[i].substream;
557830 if (substream) {
558831 snd_dma_free_pages(&substream->dma_buffer);
....@@ -564,9 +837,17 @@
564837
565838 static const struct snd_soc_component_driver lpass_component_driver = {
566839 .name = DRV_NAME,
567
- .pcm_new = lpass_platform_pcm_new,
568
- .pcm_free = lpass_platform_pcm_free,
569
- .ops = &lpass_platform_pcm_ops,
840
+ .open = lpass_platform_pcmops_open,
841
+ .close = lpass_platform_pcmops_close,
842
+ .hw_params = lpass_platform_pcmops_hw_params,
843
+ .hw_free = lpass_platform_pcmops_hw_free,
844
+ .prepare = lpass_platform_pcmops_prepare,
845
+ .trigger = lpass_platform_pcmops_trigger,
846
+ .pointer = lpass_platform_pcmops_pointer,
847
+ .mmap = lpass_platform_pcmops_mmap,
848
+ .pcm_construct = lpass_platform_pcm_new,
849
+ .pcm_destruct = lpass_platform_pcm_free,
850
+
570851 };
571852
572853 int asoc_qcom_lpass_platform_register(struct platform_device *pdev)
....@@ -576,11 +857,8 @@
576857 int ret;
577858
578859 drvdata->lpaif_irq = platform_get_irq_byname(pdev, "lpass-irq-lpaif");
579
- if (drvdata->lpaif_irq < 0) {
580
- dev_err(&pdev->dev, "error getting irq handle: %d\n",
581
- drvdata->lpaif_irq);
860
+ if (drvdata->lpaif_irq < 0)
582861 return -ENODEV;
583
- }
584862
585863 /* ensure audio hardware is disabled */
586864 ret = regmap_write(drvdata->lpaif_map,
....@@ -598,7 +876,40 @@
598876 return ret;
599877 }
600878
879
+ ret = lpass_platform_alloc_dmactl_fields(&pdev->dev,
880
+ drvdata->lpaif_map);
881
+ if (ret) {
882
+ dev_err(&pdev->dev,
883
+ "error initializing dmactl fields: %d\n", ret);
884
+ return ret;
885
+ }
601886
887
+ if (drvdata->hdmi_port_enable) {
888
+ drvdata->hdmiif_irq = platform_get_irq_byname(pdev, "lpass-irq-hdmi");
889
+ if (drvdata->hdmiif_irq < 0)
890
+ return -ENODEV;
891
+
892
+ ret = devm_request_irq(&pdev->dev, drvdata->hdmiif_irq,
893
+ lpass_platform_hdmiif_irq, 0, "lpass-irq-hdmi", drvdata);
894
+ if (ret) {
895
+ dev_err(&pdev->dev, "irq hdmi request failed: %d\n", ret);
896
+ return ret;
897
+ }
898
+ ret = regmap_write(drvdata->hdmiif_map,
899
+ LPASS_HDMITX_APP_IRQEN_REG(v), 0);
900
+ if (ret) {
901
+ dev_err(&pdev->dev, "error writing to hdmi irqen reg: %d\n", ret);
902
+ return ret;
903
+ }
904
+
905
+ ret = lpass_platform_alloc_hdmidmactl_fields(&pdev->dev,
906
+ drvdata->hdmiif_map);
907
+ if (ret) {
908
+ dev_err(&pdev->dev,
909
+ "error initializing hdmidmactl fields: %d\n", ret);
910
+ return ret;
911
+ }
912
+ }
602913 return devm_snd_soc_register_component(&pdev->dev,
603914 &lpass_component_driver, NULL, 0);
604915 }