Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Generic TXx9 ACLC platform driver |
| 4 | * |
| 5 | * Copyright (C) 2009 Atsushi Nemoto |
| 6 | * |
| 7 | * Based on RBTX49xx patch from CELF patch archive. |
| 8 | * (C) Copyright TOSHIBA CORPORATION 2004-2006 |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/scatterlist.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Lars-Peter Clausen | ff495d3 | 2014-08-19 17:48:07 +0200 | [diff] [blame] | 16 | #include <linux/dmaengine.h> |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 17 | #include <sound/core.h> |
| 18 | #include <sound/pcm.h> |
| 19 | #include <sound/pcm_params.h> |
| 20 | #include <sound/soc.h> |
| 21 | #include "txx9aclc.h" |
| 22 | |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 23 | #define DRV_NAME "txx9aclc" |
| 24 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 25 | static struct txx9aclc_soc_device { |
| 26 | struct txx9aclc_dmadata dmadata[2]; |
| 27 | } txx9aclc_soc_device; |
| 28 | |
| 29 | /* REVISIT: How to find txx9aclc_drvdata from snd_ac97? */ |
| 30 | static struct txx9aclc_plat_drvdata *txx9aclc_drvdata; |
| 31 | |
| 32 | static int txx9aclc_dma_init(struct txx9aclc_soc_device *dev, |
| 33 | struct txx9aclc_dmadata *dmadata); |
| 34 | |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 35 | static const struct snd_pcm_hardware txx9aclc_pcm_hardware = { |
| 36 | /* |
| 37 | * REVISIT: SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
| 38 | * needs more works for noncoherent MIPS. |
| 39 | */ |
| 40 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 41 | SNDRV_PCM_INFO_BATCH | |
| 42 | SNDRV_PCM_INFO_PAUSE, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 43 | .period_bytes_min = 1024, |
| 44 | .period_bytes_max = 8 * 1024, |
| 45 | .periods_min = 2, |
| 46 | .periods_max = 4096, |
| 47 | .buffer_bytes_max = 32 * 1024, |
| 48 | }; |
| 49 | |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 50 | static int txx9aclc_pcm_hw_params(struct snd_soc_component *component, |
| 51 | struct snd_pcm_substream *substream, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 52 | struct snd_pcm_hw_params *params) |
| 53 | { |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 54 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 55 | struct txx9aclc_dmadata *dmadata = runtime->private_data; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 56 | |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 57 | dev_dbg(component->dev, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 58 | "runtime->dma_area = %#lx dma_addr = %#lx dma_bytes = %zd " |
| 59 | "runtime->min_align %ld\n", |
| 60 | (unsigned long)runtime->dma_area, |
| 61 | (unsigned long)runtime->dma_addr, runtime->dma_bytes, |
| 62 | runtime->min_align); |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 63 | dev_dbg(component->dev, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 64 | "periods %d period_bytes %d stream %d\n", |
| 65 | params_periods(params), params_period_bytes(params), |
| 66 | substream->stream); |
| 67 | |
| 68 | dmadata->substream = substream; |
| 69 | dmadata->pos = 0; |
| 70 | return 0; |
| 71 | } |
| 72 | |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 73 | static int txx9aclc_pcm_prepare(struct snd_soc_component *component, |
| 74 | struct snd_pcm_substream *substream) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 75 | { |
| 76 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 77 | struct txx9aclc_dmadata *dmadata = runtime->private_data; |
| 78 | |
| 79 | dmadata->dma_addr = runtime->dma_addr; |
| 80 | dmadata->buffer_bytes = snd_pcm_lib_buffer_bytes(substream); |
| 81 | dmadata->period_bytes = snd_pcm_lib_period_bytes(substream); |
| 82 | |
| 83 | if (dmadata->buffer_bytes == dmadata->period_bytes) { |
| 84 | dmadata->frag_bytes = dmadata->period_bytes >> 1; |
| 85 | dmadata->frags = 2; |
| 86 | } else { |
| 87 | dmadata->frag_bytes = dmadata->period_bytes; |
| 88 | dmadata->frags = dmadata->buffer_bytes / dmadata->period_bytes; |
| 89 | } |
| 90 | dmadata->frag_count = 0; |
| 91 | dmadata->pos = 0; |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static void txx9aclc_dma_complete(void *arg) |
| 96 | { |
| 97 | struct txx9aclc_dmadata *dmadata = arg; |
| 98 | unsigned long flags; |
| 99 | |
| 100 | /* dma completion handler cannot submit new operations */ |
| 101 | spin_lock_irqsave(&dmadata->dma_lock, flags); |
| 102 | if (dmadata->frag_count >= 0) { |
| 103 | dmadata->dmacount--; |
Takashi Iwai | cb1b102 | 2013-11-05 18:40:07 +0100 | [diff] [blame] | 104 | if (!WARN_ON(dmadata->dmacount < 0)) |
| 105 | tasklet_schedule(&dmadata->tasklet); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 106 | } |
| 107 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
| 108 | } |
| 109 | |
| 110 | static struct dma_async_tx_descriptor * |
| 111 | txx9aclc_dma_submit(struct txx9aclc_dmadata *dmadata, dma_addr_t buf_dma_addr) |
| 112 | { |
| 113 | struct dma_chan *chan = dmadata->dma_chan; |
| 114 | struct dma_async_tx_descriptor *desc; |
| 115 | struct scatterlist sg; |
| 116 | |
| 117 | sg_init_table(&sg, 1); |
| 118 | sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf_dma_addr)), |
| 119 | dmadata->frag_bytes, buf_dma_addr & (PAGE_SIZE - 1)); |
| 120 | sg_dma_address(&sg) = buf_dma_addr; |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 121 | desc = dmaengine_prep_slave_sg(chan, &sg, 1, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 122 | dmadata->substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
Vinod Koul | 35e1658 | 2011-10-14 10:49:30 +0530 | [diff] [blame] | 123 | DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 124 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 125 | if (!desc) { |
| 126 | dev_err(&chan->dev->device, "cannot prepare slave dma\n"); |
| 127 | return NULL; |
| 128 | } |
| 129 | desc->callback = txx9aclc_dma_complete; |
| 130 | desc->callback_param = dmadata; |
Lars-Peter Clausen | ff495d3 | 2014-08-19 17:48:07 +0200 | [diff] [blame] | 131 | dmaengine_submit(desc); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 132 | return desc; |
| 133 | } |
| 134 | |
| 135 | #define NR_DMA_CHAIN 2 |
| 136 | |
| 137 | static void txx9aclc_dma_tasklet(unsigned long data) |
| 138 | { |
| 139 | struct txx9aclc_dmadata *dmadata = (struct txx9aclc_dmadata *)data; |
| 140 | struct dma_chan *chan = dmadata->dma_chan; |
| 141 | struct dma_async_tx_descriptor *desc; |
| 142 | struct snd_pcm_substream *substream = dmadata->substream; |
| 143 | u32 ctlbit = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 144 | ACCTL_AUDODMA : ACCTL_AUDIDMA; |
| 145 | int i; |
| 146 | unsigned long flags; |
| 147 | |
| 148 | spin_lock_irqsave(&dmadata->dma_lock, flags); |
| 149 | if (dmadata->frag_count < 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 150 | struct txx9aclc_plat_drvdata *drvdata = txx9aclc_drvdata; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 151 | void __iomem *base = drvdata->base; |
| 152 | |
| 153 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
Lars-Peter Clausen | ff495d3 | 2014-08-19 17:48:07 +0200 | [diff] [blame] | 154 | dmaengine_terminate_all(chan); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 155 | /* first time */ |
| 156 | for (i = 0; i < NR_DMA_CHAIN; i++) { |
| 157 | desc = txx9aclc_dma_submit(dmadata, |
| 158 | dmadata->dma_addr + i * dmadata->frag_bytes); |
| 159 | if (!desc) |
| 160 | return; |
| 161 | } |
| 162 | dmadata->dmacount = NR_DMA_CHAIN; |
Lars-Peter Clausen | ff495d3 | 2014-08-19 17:48:07 +0200 | [diff] [blame] | 163 | dma_async_issue_pending(chan); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 164 | spin_lock_irqsave(&dmadata->dma_lock, flags); |
| 165 | __raw_writel(ctlbit, base + ACCTLEN); |
| 166 | dmadata->frag_count = NR_DMA_CHAIN % dmadata->frags; |
| 167 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
| 168 | return; |
| 169 | } |
Takashi Iwai | cb1b102 | 2013-11-05 18:40:07 +0100 | [diff] [blame] | 170 | if (WARN_ON(dmadata->dmacount >= NR_DMA_CHAIN)) { |
| 171 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
| 172 | return; |
| 173 | } |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 174 | while (dmadata->dmacount < NR_DMA_CHAIN) { |
| 175 | dmadata->dmacount++; |
| 176 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
| 177 | desc = txx9aclc_dma_submit(dmadata, |
| 178 | dmadata->dma_addr + |
| 179 | dmadata->frag_count * dmadata->frag_bytes); |
| 180 | if (!desc) |
| 181 | return; |
Lars-Peter Clausen | ff495d3 | 2014-08-19 17:48:07 +0200 | [diff] [blame] | 182 | dma_async_issue_pending(chan); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 183 | |
| 184 | spin_lock_irqsave(&dmadata->dma_lock, flags); |
| 185 | dmadata->frag_count++; |
| 186 | dmadata->frag_count %= dmadata->frags; |
| 187 | dmadata->pos += dmadata->frag_bytes; |
| 188 | dmadata->pos %= dmadata->buffer_bytes; |
| 189 | if ((dmadata->frag_count * dmadata->frag_bytes) % |
| 190 | dmadata->period_bytes == 0) |
| 191 | snd_pcm_period_elapsed(substream); |
| 192 | } |
| 193 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
| 194 | } |
| 195 | |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 196 | static int txx9aclc_pcm_trigger(struct snd_soc_component *component, |
| 197 | struct snd_pcm_substream *substream, int cmd) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 198 | { |
| 199 | struct txx9aclc_dmadata *dmadata = substream->runtime->private_data; |
Codrut Grosu | 8405265 | 2017-02-25 12:12:21 +0200 | [diff] [blame] | 200 | struct txx9aclc_plat_drvdata *drvdata = txx9aclc_drvdata; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 201 | void __iomem *base = drvdata->base; |
| 202 | unsigned long flags; |
| 203 | int ret = 0; |
| 204 | u32 ctlbit = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 205 | ACCTL_AUDODMA : ACCTL_AUDIDMA; |
| 206 | |
| 207 | spin_lock_irqsave(&dmadata->dma_lock, flags); |
| 208 | switch (cmd) { |
| 209 | case SNDRV_PCM_TRIGGER_START: |
| 210 | dmadata->frag_count = -1; |
| 211 | tasklet_schedule(&dmadata->tasklet); |
| 212 | break; |
| 213 | case SNDRV_PCM_TRIGGER_STOP: |
| 214 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 215 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 216 | __raw_writel(ctlbit, base + ACCTLDIS); |
| 217 | break; |
| 218 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 219 | case SNDRV_PCM_TRIGGER_RESUME: |
| 220 | __raw_writel(ctlbit, base + ACCTLEN); |
| 221 | break; |
| 222 | default: |
| 223 | ret = -EINVAL; |
| 224 | } |
| 225 | spin_unlock_irqrestore(&dmadata->dma_lock, flags); |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | static snd_pcm_uframes_t |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 230 | txx9aclc_pcm_pointer(struct snd_soc_component *component, |
| 231 | struct snd_pcm_substream *substream) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 232 | { |
| 233 | struct txx9aclc_dmadata *dmadata = substream->runtime->private_data; |
| 234 | |
| 235 | return bytes_to_frames(substream->runtime, dmadata->pos); |
| 236 | } |
| 237 | |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 238 | static int txx9aclc_pcm_open(struct snd_soc_component *component, |
| 239 | struct snd_pcm_substream *substream) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 240 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 241 | struct txx9aclc_soc_device *dev = &txx9aclc_soc_device; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 242 | struct txx9aclc_dmadata *dmadata = &dev->dmadata[substream->stream]; |
| 243 | int ret; |
| 244 | |
| 245 | ret = snd_soc_set_runtime_hwparams(substream, &txx9aclc_pcm_hardware); |
| 246 | if (ret) |
| 247 | return ret; |
| 248 | /* ensure that buffer size is a multiple of period size */ |
| 249 | ret = snd_pcm_hw_constraint_integer(substream->runtime, |
| 250 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 251 | if (ret < 0) |
| 252 | return ret; |
| 253 | substream->runtime->private_data = dmadata; |
| 254 | return 0; |
| 255 | } |
| 256 | |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 257 | static int txx9aclc_pcm_close(struct snd_soc_component *component, |
| 258 | struct snd_pcm_substream *substream) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 259 | { |
| 260 | struct txx9aclc_dmadata *dmadata = substream->runtime->private_data; |
| 261 | struct dma_chan *chan = dmadata->dma_chan; |
| 262 | |
| 263 | dmadata->frag_count = -1; |
Lars-Peter Clausen | ff495d3 | 2014-08-19 17:48:07 +0200 | [diff] [blame] | 264 | dmaengine_terminate_all(chan); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 268 | static int txx9aclc_pcm_new(struct snd_soc_component *component, |
| 269 | struct snd_soc_pcm_runtime *rtd) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 270 | { |
Ralf Baechle | 06132fd | 2011-07-28 12:26:16 +0100 | [diff] [blame] | 271 | struct snd_card *card = rtd->card->snd_card; |
Kuninori Morimoto | f7c48801 | 2020-03-23 14:21:21 +0900 | [diff] [blame] | 272 | struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0); |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 273 | struct snd_pcm *pcm = rtd->pcm; |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 274 | struct platform_device *pdev = to_platform_device(component->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 275 | struct txx9aclc_soc_device *dev; |
| 276 | struct resource *r; |
| 277 | int i; |
| 278 | int ret; |
| 279 | |
| 280 | /* at this point onwards the AC97 component has probed and this will be valid */ |
| 281 | dev = snd_soc_dai_get_drvdata(dai); |
| 282 | |
| 283 | dev->dmadata[0].stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 284 | dev->dmadata[1].stream = SNDRV_PCM_STREAM_CAPTURE; |
| 285 | for (i = 0; i < 2; i++) { |
| 286 | r = platform_get_resource(pdev, IORESOURCE_DMA, i); |
| 287 | if (!r) { |
| 288 | ret = -EBUSY; |
| 289 | goto exit; |
| 290 | } |
| 291 | dev->dmadata[i].dma_res = r; |
| 292 | ret = txx9aclc_dma_init(dev, &dev->dmadata[i]); |
| 293 | if (ret) |
| 294 | goto exit; |
| 295 | } |
Takashi Iwai | 4f39e4c | 2019-02-04 16:40:37 +0100 | [diff] [blame] | 296 | |
Takashi Iwai | ffe1193 | 2019-12-10 15:26:04 +0100 | [diff] [blame] | 297 | snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 298 | card->dev, 64 * 1024, 4 * 1024 * 1024); |
Takashi Iwai | 4f39e4c | 2019-02-04 16:40:37 +0100 | [diff] [blame] | 299 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 300 | |
| 301 | exit: |
| 302 | for (i = 0; i < 2; i++) { |
| 303 | if (dev->dmadata[i].dma_chan) |
| 304 | dma_release_channel(dev->dmadata[i].dma_chan); |
| 305 | dev->dmadata[i].dma_chan = NULL; |
| 306 | } |
| 307 | return ret; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static bool filter(struct dma_chan *chan, void *param) |
| 311 | { |
| 312 | struct txx9aclc_dmadata *dmadata = param; |
Atsushi Nemoto | 647613e | 2009-06-25 22:36:58 +0900 | [diff] [blame] | 313 | char *devname; |
| 314 | bool found = false; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 315 | |
Atsushi Nemoto | 647613e | 2009-06-25 22:36:58 +0900 | [diff] [blame] | 316 | devname = kasprintf(GFP_KERNEL, "%s.%d", dmadata->dma_res->name, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 317 | (int)dmadata->dma_res->start); |
| 318 | if (strcmp(dev_name(chan->device->dev), devname) == 0) { |
| 319 | chan->private = &dmadata->dma_slave; |
Atsushi Nemoto | 647613e | 2009-06-25 22:36:58 +0900 | [diff] [blame] | 320 | found = true; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 321 | } |
Atsushi Nemoto | 647613e | 2009-06-25 22:36:58 +0900 | [diff] [blame] | 322 | kfree(devname); |
| 323 | return found; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static int txx9aclc_dma_init(struct txx9aclc_soc_device *dev, |
| 327 | struct txx9aclc_dmadata *dmadata) |
| 328 | { |
Codrut Grosu | 8405265 | 2017-02-25 12:12:21 +0200 | [diff] [blame] | 329 | struct txx9aclc_plat_drvdata *drvdata = txx9aclc_drvdata; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 330 | struct txx9dmac_slave *ds = &dmadata->dma_slave; |
| 331 | dma_cap_mask_t mask; |
| 332 | |
| 333 | spin_lock_init(&dmadata->dma_lock); |
| 334 | |
| 335 | ds->reg_width = sizeof(u32); |
| 336 | if (dmadata->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 337 | ds->tx_reg = drvdata->physbase + ACAUDODAT; |
| 338 | ds->rx_reg = 0; |
| 339 | } else { |
| 340 | ds->tx_reg = 0; |
| 341 | ds->rx_reg = drvdata->physbase + ACAUDIDAT; |
| 342 | } |
| 343 | |
| 344 | /* Try to grab a DMA channel */ |
| 345 | dma_cap_zero(mask); |
| 346 | dma_cap_set(DMA_SLAVE, mask); |
| 347 | dmadata->dma_chan = dma_request_channel(mask, filter, dmadata); |
| 348 | if (!dmadata->dma_chan) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 349 | printk(KERN_ERR |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 350 | "DMA channel for %s is not available\n", |
| 351 | dmadata->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 352 | "playback" : "capture"); |
| 353 | return -EBUSY; |
| 354 | } |
| 355 | tasklet_init(&dmadata->tasklet, txx9aclc_dma_tasklet, |
| 356 | (unsigned long)dmadata); |
| 357 | return 0; |
| 358 | } |
| 359 | |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 360 | static int txx9aclc_pcm_probe(struct snd_soc_component *component) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 361 | { |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 362 | snd_soc_component_set_drvdata(component, &txx9aclc_soc_device); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 363 | return 0; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 364 | } |
| 365 | |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 366 | static void txx9aclc_pcm_remove(struct snd_soc_component *component) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 367 | { |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 368 | struct txx9aclc_soc_device *dev = snd_soc_component_get_drvdata(component); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 369 | struct txx9aclc_plat_drvdata *drvdata = txx9aclc_drvdata; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 370 | void __iomem *base = drvdata->base; |
| 371 | int i; |
| 372 | |
| 373 | /* disable all FIFO DMAs */ |
| 374 | __raw_writel(ACCTL_AUDODMA | ACCTL_AUDIDMA, base + ACCTLDIS); |
| 375 | /* dummy R/W to clear pending DMAREQ if any */ |
| 376 | __raw_writel(__raw_readl(base + ACAUDIDAT), base + ACAUDODAT); |
| 377 | |
| 378 | for (i = 0; i < 2; i++) { |
| 379 | struct txx9aclc_dmadata *dmadata = &dev->dmadata[i]; |
| 380 | struct dma_chan *chan = dmadata->dma_chan; |
Codrut Grosu | c2dcce3 | 2017-02-25 21:17:53 +0200 | [diff] [blame] | 381 | |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 382 | if (chan) { |
| 383 | dmadata->frag_count = -1; |
Lars-Peter Clausen | ff495d3 | 2014-08-19 17:48:07 +0200 | [diff] [blame] | 384 | dmaengine_terminate_all(chan); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 385 | dma_release_channel(chan); |
| 386 | } |
| 387 | dev->dmadata[i].dma_chan = NULL; |
| 388 | } |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 389 | } |
| 390 | |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 391 | static const struct snd_soc_component_driver txx9aclc_soc_component = { |
| 392 | .name = DRV_NAME, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 393 | .probe = txx9aclc_pcm_probe, |
| 394 | .remove = txx9aclc_pcm_remove, |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 395 | .open = txx9aclc_pcm_open, |
| 396 | .close = txx9aclc_pcm_close, |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 397 | .hw_params = txx9aclc_pcm_hw_params, |
Kuninori Morimoto | a857e07 | 2019-10-02 14:32:41 +0900 | [diff] [blame] | 398 | .prepare = txx9aclc_pcm_prepare, |
| 399 | .trigger = txx9aclc_pcm_trigger, |
| 400 | .pointer = txx9aclc_pcm_pointer, |
| 401 | .pcm_construct = txx9aclc_pcm_new, |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 402 | }; |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 403 | |
Bill Pemberton | d8628d1 | 2012-12-07 09:26:34 -0500 | [diff] [blame] | 404 | static int txx9aclc_soc_platform_probe(struct platform_device *pdev) |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 405 | { |
Kuninori Morimoto | e049cf4 | 2018-01-29 02:51:26 +0000 | [diff] [blame] | 406 | return devm_snd_soc_register_component(&pdev->dev, |
| 407 | &txx9aclc_soc_component, NULL, 0); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 408 | } |
| 409 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 410 | static struct platform_driver txx9aclc_pcm_driver = { |
| 411 | .driver = { |
| 412 | .name = "txx9aclc-pcm-audio", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 413 | }, |
| 414 | |
| 415 | .probe = txx9aclc_soc_platform_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 416 | }; |
| 417 | |
Axel Lin | 33d316c | 2011-11-25 10:16:10 +0800 | [diff] [blame] | 418 | module_platform_driver(txx9aclc_pcm_driver); |
Atsushi Nemoto | e24805d | 2009-05-19 22:12:15 +0900 | [diff] [blame] | 419 | |
| 420 | MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); |
| 421 | MODULE_DESCRIPTION("TXx9 ACLC Audio DMA driver"); |
| 422 | MODULE_LICENSE("GPL"); |