Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: qcom: Add helper function to get dma control and lpaif handle

Add support function to get dma control and lpaif handle to avoid
repeated code in platform driver

Signed-off-by: Srinivasa Rao Mandadapu <quic_srivasam@quicinc.com>
Co-developed-by: Venkata Prasad Potturu <quic_potturu@quicinc.com>
Signed-off-by: Venkata Prasad Potturu <quic_potturu@quicinc.com>
Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/1645716828-15305-4-git-send-email-quic_srivasam@quicinc.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Srinivasa Rao Mandadapu and committed by
Mark Brown
16413d5c ddd60045

+80 -51
+80 -51
sound/soc/qcom/lpass-platform.c
··· 177 177 return 0; 178 178 } 179 179 180 + static struct lpaif_dmactl *__lpass_get_dmactl_handle(const struct snd_pcm_substream *substream, 181 + struct snd_soc_component *component) 182 + { 183 + struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream); 184 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0); 185 + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component); 186 + struct lpaif_dmactl *dmactl = NULL; 187 + 188 + switch (cpu_dai->driver->id) { 189 + case MI2S_PRIMARY ... MI2S_QUINARY: 190 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 191 + dmactl = drvdata->rd_dmactl; 192 + else 193 + dmactl = drvdata->wr_dmactl; 194 + break; 195 + case LPASS_DP_RX: 196 + dmactl = drvdata->hdmi_rd_dmactl; 197 + break; 198 + } 199 + 200 + return dmactl; 201 + } 202 + 203 + static int __lpass_get_id(const struct snd_pcm_substream *substream, 204 + struct snd_soc_component *component) 205 + { 206 + struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream); 207 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0); 208 + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component); 209 + struct snd_pcm_runtime *rt = substream->runtime; 210 + struct lpass_pcm_data *pcm_data = rt->private_data; 211 + struct lpass_variant *v = drvdata->variant; 212 + int id; 213 + 214 + switch (cpu_dai->driver->id) { 215 + case MI2S_PRIMARY ... MI2S_QUINARY: 216 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 217 + id = pcm_data->dma_ch; 218 + else 219 + id = pcm_data->dma_ch - v->wrdma_channel_start; 220 + break; 221 + case LPASS_DP_RX: 222 + id = pcm_data->dma_ch; 223 + break; 224 + } 225 + 226 + return id; 227 + } 228 + 229 + static struct regmap *__lpass_get_regmap_handle(const struct snd_pcm_substream *substream, 230 + struct snd_soc_component *component) 231 + { 232 + struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream); 233 + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0); 234 + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component); 235 + struct regmap *map = NULL; 236 + 237 + switch (cpu_dai->driver->id) { 238 + case MI2S_PRIMARY ... MI2S_QUINARY: 239 + map = drvdata->lpaif_map; 240 + break; 241 + case LPASS_DP_RX: 242 + map = drvdata->hdmiif_map; 243 + break; 244 + } 245 + 246 + return map; 247 + } 248 + 180 249 static int lpass_platform_pcmops_hw_params(struct snd_soc_component *component, 181 250 struct snd_pcm_substream *substream, 182 251 struct snd_pcm_hw_params *params) ··· 260 191 unsigned int channels = params_channels(params); 261 192 unsigned int regval; 262 193 struct lpaif_dmactl *dmactl; 263 - int id, dir = substream->stream; 194 + int id; 264 195 int bitwidth; 265 196 int ret, dma_port = pcm_data->i2s_port + v->dmactl_audif_start; 266 197 unsigned int dai_id = cpu_dai->driver->id; 267 198 268 - if (dir == SNDRV_PCM_STREAM_PLAYBACK) { 269 - id = pcm_data->dma_ch; 270 - if (dai_id == LPASS_DP_RX) 271 - dmactl = drvdata->hdmi_rd_dmactl; 272 - else 273 - dmactl = drvdata->rd_dmactl; 274 - 275 - } else { 276 - dmactl = drvdata->wr_dmactl; 277 - id = pcm_data->dma_ch - v->wrdma_channel_start; 278 - } 199 + dmactl = __lpass_get_dmactl_handle(substream, component); 200 + id = __lpass_get_id(substream, component); 279 201 280 202 bitwidth = snd_pcm_format_width(format); 281 203 if (bitwidth < 0) { ··· 410 350 struct regmap *map; 411 351 unsigned int dai_id = cpu_dai->driver->id; 412 352 413 - if (dai_id == LPASS_DP_RX) 414 - map = drvdata->hdmiif_map; 415 - else 416 - map = drvdata->lpaif_map; 353 + map = __lpass_get_regmap_handle(substream, component); 417 354 418 355 reg = LPAIF_DMACTL_REG(v, pcm_data->dma_ch, substream->stream, dai_id); 419 356 ret = regmap_write(map, reg, 0); ··· 436 379 int ret, id, ch, dir = substream->stream; 437 380 unsigned int dai_id = cpu_dai->driver->id; 438 381 439 - 440 382 ch = pcm_data->dma_ch; 441 - if (dir == SNDRV_PCM_STREAM_PLAYBACK) { 442 - if (dai_id == LPASS_DP_RX) { 443 - dmactl = drvdata->hdmi_rd_dmactl; 444 - map = drvdata->hdmiif_map; 445 - } else { 446 - dmactl = drvdata->rd_dmactl; 447 - map = drvdata->lpaif_map; 448 - } 449 383 450 - id = pcm_data->dma_ch; 451 - } else { 452 - dmactl = drvdata->wr_dmactl; 453 - id = pcm_data->dma_ch - v->wrdma_channel_start; 454 - map = drvdata->lpaif_map; 455 - } 384 + dmactl = __lpass_get_dmactl_handle(substream, component); 385 + id = __lpass_get_id(substream, component); 386 + map = __lpass_get_regmap_handle(substream, component); 456 387 457 388 ret = regmap_write(map, LPAIF_DMABASE_REG(v, ch, dir, dai_id), 458 389 runtime->dma_addr); ··· 489 444 struct lpaif_dmactl *dmactl; 490 445 struct regmap *map; 491 446 int ret, ch, id; 492 - int dir = substream->stream; 493 447 unsigned int reg_irqclr = 0, val_irqclr = 0; 494 448 unsigned int reg_irqen = 0, val_irqen = 0, val_mask = 0; 495 449 unsigned int dai_id = cpu_dai->driver->id; 496 450 497 451 ch = pcm_data->dma_ch; 498 - if (dir == SNDRV_PCM_STREAM_PLAYBACK) { 499 - id = pcm_data->dma_ch; 500 - if (dai_id == LPASS_DP_RX) { 501 - dmactl = drvdata->hdmi_rd_dmactl; 502 - map = drvdata->hdmiif_map; 503 - } else { 504 - dmactl = drvdata->rd_dmactl; 505 - map = drvdata->lpaif_map; 506 - } 507 - } else { 508 - dmactl = drvdata->wr_dmactl; 509 - id = pcm_data->dma_ch - v->wrdma_channel_start; 510 - map = drvdata->lpaif_map; 511 - } 452 + dmactl = __lpass_get_dmactl_handle(substream, component); 453 + id = __lpass_get_id(substream, component); 454 + map = __lpass_get_regmap_handle(substream, component); 512 455 513 456 switch (cmd) { 514 457 case SNDRV_PCM_TRIGGER_START: ··· 630 597 struct regmap *map; 631 598 unsigned int dai_id = cpu_dai->driver->id; 632 599 633 - if (dai_id == LPASS_DP_RX) 634 - map = drvdata->hdmiif_map; 635 - else 636 - map = drvdata->lpaif_map; 637 - 600 + map = __lpass_get_regmap_handle(substream, component); 638 601 ch = pcm_data->dma_ch; 639 602 640 603 ret = regmap_read(map,