| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Generic TXx9 ACLC platform driver |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Based on RBTX49xx patch from CELF patch archive. |
|---|
| 7 | 8 | * (C) Copyright TOSHIBA CORPORATION 2004-2006 |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 11 | | - * published by the Free Software Foundation. |
|---|
| 12 | 9 | */ |
|---|
| 13 | 10 | |
|---|
| 14 | 11 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 50 | 47 | .buffer_bytes_max = 32 * 1024, |
|---|
| 51 | 48 | }; |
|---|
| 52 | 49 | |
|---|
| 53 | | -static int txx9aclc_pcm_hw_params(struct snd_pcm_substream *substream, |
|---|
| 50 | +static int txx9aclc_pcm_hw_params(struct snd_soc_component *component, |
|---|
| 51 | + struct snd_pcm_substream *substream, |
|---|
| 54 | 52 | struct snd_pcm_hw_params *params) |
|---|
| 55 | 53 | { |
|---|
| 56 | | - struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
|---|
| 57 | 54 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| 58 | | - struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
|---|
| 59 | 55 | struct txx9aclc_dmadata *dmadata = runtime->private_data; |
|---|
| 60 | | - int ret; |
|---|
| 61 | | - |
|---|
| 62 | | - ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
|---|
| 63 | | - if (ret < 0) |
|---|
| 64 | | - return ret; |
|---|
| 65 | 56 | |
|---|
| 66 | 57 | dev_dbg(component->dev, |
|---|
| 67 | 58 | "runtime->dma_area = %#lx dma_addr = %#lx dma_bytes = %zd " |
|---|
| .. | .. |
|---|
| 79 | 70 | return 0; |
|---|
| 80 | 71 | } |
|---|
| 81 | 72 | |
|---|
| 82 | | -static int txx9aclc_pcm_hw_free(struct snd_pcm_substream *substream) |
|---|
| 83 | | -{ |
|---|
| 84 | | - return snd_pcm_lib_free_pages(substream); |
|---|
| 85 | | -} |
|---|
| 86 | | - |
|---|
| 87 | | -static int txx9aclc_pcm_prepare(struct snd_pcm_substream *substream) |
|---|
| 73 | +static int txx9aclc_pcm_prepare(struct snd_soc_component *component, |
|---|
| 74 | + struct snd_pcm_substream *substream) |
|---|
| 88 | 75 | { |
|---|
| 89 | 76 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| 90 | 77 | struct txx9aclc_dmadata *dmadata = runtime->private_data; |
|---|
| .. | .. |
|---|
| 115 | 102 | if (dmadata->frag_count >= 0) { |
|---|
| 116 | 103 | dmadata->dmacount--; |
|---|
| 117 | 104 | if (!WARN_ON(dmadata->dmacount < 0)) |
|---|
| 118 | | - tasklet_schedule(&dmadata->tasklet); |
|---|
| 105 | + queue_work(system_highpri_wq, &dmadata->work); |
|---|
| 119 | 106 | } |
|---|
| 120 | 107 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
|---|
| 121 | 108 | } |
|---|
| .. | .. |
|---|
| 147 | 134 | |
|---|
| 148 | 135 | #define NR_DMA_CHAIN 2 |
|---|
| 149 | 136 | |
|---|
| 150 | | -static void txx9aclc_dma_tasklet(unsigned long data) |
|---|
| 137 | +static void txx9aclc_dma_work(struct work_struct *work) |
|---|
| 151 | 138 | { |
|---|
| 152 | | - struct txx9aclc_dmadata *dmadata = (struct txx9aclc_dmadata *)data; |
|---|
| 139 | + struct txx9aclc_dmadata *dmadata = |
|---|
| 140 | + container_of(work, struct txx9aclc_dmadata, work); |
|---|
| 153 | 141 | struct dma_chan *chan = dmadata->dma_chan; |
|---|
| 154 | 142 | struct dma_async_tx_descriptor *desc; |
|---|
| 155 | 143 | struct snd_pcm_substream *substream = dmadata->substream; |
|---|
| .. | .. |
|---|
| 206 | 194 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
|---|
| 207 | 195 | } |
|---|
| 208 | 196 | |
|---|
| 209 | | -static int txx9aclc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
|---|
| 197 | +static int txx9aclc_pcm_trigger(struct snd_soc_component *component, |
|---|
| 198 | + struct snd_pcm_substream *substream, int cmd) |
|---|
| 210 | 199 | { |
|---|
| 211 | 200 | struct txx9aclc_dmadata *dmadata = substream->runtime->private_data; |
|---|
| 212 | 201 | struct txx9aclc_plat_drvdata *drvdata = txx9aclc_drvdata; |
|---|
| .. | .. |
|---|
| 220 | 209 | switch (cmd) { |
|---|
| 221 | 210 | case SNDRV_PCM_TRIGGER_START: |
|---|
| 222 | 211 | dmadata->frag_count = -1; |
|---|
| 223 | | - tasklet_schedule(&dmadata->tasklet); |
|---|
| 212 | + queue_work(system_highpri_wq, &dmadata->work); |
|---|
| 224 | 213 | break; |
|---|
| 225 | 214 | case SNDRV_PCM_TRIGGER_STOP: |
|---|
| 226 | 215 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
|---|
| .. | .. |
|---|
| 239 | 228 | } |
|---|
| 240 | 229 | |
|---|
| 241 | 230 | static snd_pcm_uframes_t |
|---|
| 242 | | -txx9aclc_pcm_pointer(struct snd_pcm_substream *substream) |
|---|
| 231 | +txx9aclc_pcm_pointer(struct snd_soc_component *component, |
|---|
| 232 | + struct snd_pcm_substream *substream) |
|---|
| 243 | 233 | { |
|---|
| 244 | 234 | struct txx9aclc_dmadata *dmadata = substream->runtime->private_data; |
|---|
| 245 | 235 | |
|---|
| 246 | 236 | return bytes_to_frames(substream->runtime, dmadata->pos); |
|---|
| 247 | 237 | } |
|---|
| 248 | 238 | |
|---|
| 249 | | -static int txx9aclc_pcm_open(struct snd_pcm_substream *substream) |
|---|
| 239 | +static int txx9aclc_pcm_open(struct snd_soc_component *component, |
|---|
| 240 | + struct snd_pcm_substream *substream) |
|---|
| 250 | 241 | { |
|---|
| 251 | 242 | struct txx9aclc_soc_device *dev = &txx9aclc_soc_device; |
|---|
| 252 | 243 | struct txx9aclc_dmadata *dmadata = &dev->dmadata[substream->stream]; |
|---|
| .. | .. |
|---|
| 264 | 255 | return 0; |
|---|
| 265 | 256 | } |
|---|
| 266 | 257 | |
|---|
| 267 | | -static int txx9aclc_pcm_close(struct snd_pcm_substream *substream) |
|---|
| 258 | +static int txx9aclc_pcm_close(struct snd_soc_component *component, |
|---|
| 259 | + struct snd_pcm_substream *substream) |
|---|
| 268 | 260 | { |
|---|
| 269 | 261 | struct txx9aclc_dmadata *dmadata = substream->runtime->private_data; |
|---|
| 270 | 262 | struct dma_chan *chan = dmadata->dma_chan; |
|---|
| .. | .. |
|---|
| 274 | 266 | return 0; |
|---|
| 275 | 267 | } |
|---|
| 276 | 268 | |
|---|
| 277 | | -static const struct snd_pcm_ops txx9aclc_pcm_ops = { |
|---|
| 278 | | - .open = txx9aclc_pcm_open, |
|---|
| 279 | | - .close = txx9aclc_pcm_close, |
|---|
| 280 | | - .ioctl = snd_pcm_lib_ioctl, |
|---|
| 281 | | - .hw_params = txx9aclc_pcm_hw_params, |
|---|
| 282 | | - .hw_free = txx9aclc_pcm_hw_free, |
|---|
| 283 | | - .prepare = txx9aclc_pcm_prepare, |
|---|
| 284 | | - .trigger = txx9aclc_pcm_trigger, |
|---|
| 285 | | - .pointer = txx9aclc_pcm_pointer, |
|---|
| 286 | | -}; |
|---|
| 287 | | - |
|---|
| 288 | | -static int txx9aclc_pcm_new(struct snd_soc_pcm_runtime *rtd) |
|---|
| 269 | +static int txx9aclc_pcm_new(struct snd_soc_component *component, |
|---|
| 270 | + struct snd_soc_pcm_runtime *rtd) |
|---|
| 289 | 271 | { |
|---|
| 290 | 272 | struct snd_card *card = rtd->card->snd_card; |
|---|
| 291 | | - struct snd_soc_dai *dai = rtd->cpu_dai; |
|---|
| 273 | + struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0); |
|---|
| 292 | 274 | struct snd_pcm *pcm = rtd->pcm; |
|---|
| 293 | | - struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); |
|---|
| 294 | 275 | struct platform_device *pdev = to_platform_device(component->dev); |
|---|
| 295 | 276 | struct txx9aclc_soc_device *dev; |
|---|
| 296 | 277 | struct resource *r; |
|---|
| .. | .. |
|---|
| 313 | 294 | if (ret) |
|---|
| 314 | 295 | goto exit; |
|---|
| 315 | 296 | } |
|---|
| 316 | | - return snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 297 | + |
|---|
| 298 | + snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
|---|
| 317 | 299 | card->dev, 64 * 1024, 4 * 1024 * 1024); |
|---|
| 300 | + return 0; |
|---|
| 318 | 301 | |
|---|
| 319 | 302 | exit: |
|---|
| 320 | 303 | for (i = 0; i < 2; i++) { |
|---|
| .. | .. |
|---|
| 370 | 353 | "playback" : "capture"); |
|---|
| 371 | 354 | return -EBUSY; |
|---|
| 372 | 355 | } |
|---|
| 373 | | - tasklet_init(&dmadata->tasklet, txx9aclc_dma_tasklet, |
|---|
| 374 | | - (unsigned long)dmadata); |
|---|
| 356 | + INIT_WORK(&dmadata->work, txx9aclc_dma_work); |
|---|
| 375 | 357 | return 0; |
|---|
| 376 | 358 | } |
|---|
| 377 | 359 | |
|---|
| .. | .. |
|---|
| 410 | 392 | .name = DRV_NAME, |
|---|
| 411 | 393 | .probe = txx9aclc_pcm_probe, |
|---|
| 412 | 394 | .remove = txx9aclc_pcm_remove, |
|---|
| 413 | | - .ops = &txx9aclc_pcm_ops, |
|---|
| 414 | | - .pcm_new = txx9aclc_pcm_new, |
|---|
| 395 | + .open = txx9aclc_pcm_open, |
|---|
| 396 | + .close = txx9aclc_pcm_close, |
|---|
| 397 | + .hw_params = txx9aclc_pcm_hw_params, |
|---|
| 398 | + .prepare = txx9aclc_pcm_prepare, |
|---|
| 399 | + .trigger = txx9aclc_pcm_trigger, |
|---|
| 400 | + .pointer = txx9aclc_pcm_pointer, |
|---|
| 401 | + .pcm_construct = txx9aclc_pcm_new, |
|---|
| 415 | 402 | }; |
|---|
| 416 | 403 | |
|---|
| 417 | 404 | static int txx9aclc_soc_platform_probe(struct platform_device *pdev) |
|---|