~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/kirkwood/kirkwood-dma.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/kirkwood/kirkwood-dma.c (Version linux-6.12-rc7) and /sound/soc/kirkwood/kirkwood-dma.c (Version linux-5.19.17)


  1 // SPDX-License-Identifier: GPL-2.0-or-later        1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*                                                  2 /*
  3  * kirkwood-dma.c                                   3  * kirkwood-dma.c
  4  *                                                  4  *
  5  * (c) 2010 Arnaud Patard <apatard@mandriva.co      5  * (c) 2010 Arnaud Patard <apatard@mandriva.com>
  6  * (c) 2010 Arnaud Patard <arnaud.patard@rtp-n      6  * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
  7  */                                                 7  */
  8                                                     8 
  9 #include <linux/init.h>                             9 #include <linux/init.h>
 10 #include <linux/module.h>                          10 #include <linux/module.h>
 11 #include <linux/device.h>                          11 #include <linux/device.h>
 12 #include <linux/io.h>                              12 #include <linux/io.h>
 13 #include <linux/slab.h>                            13 #include <linux/slab.h>
 14 #include <linux/interrupt.h>                       14 #include <linux/interrupt.h>
 15 #include <linux/dma-mapping.h>                     15 #include <linux/dma-mapping.h>
 16 #include <linux/mbus.h>                            16 #include <linux/mbus.h>
 17 #include <sound/soc.h>                             17 #include <sound/soc.h>
 18 #include "kirkwood.h"                              18 #include "kirkwood.h"
 19                                                    19 
 20 static struct kirkwood_dma_data *kirkwood_priv     20 static struct kirkwood_dma_data *kirkwood_priv(struct snd_pcm_substream *subs)
 21 {                                                  21 {
 22         struct snd_soc_pcm_runtime *soc_runtim !!  22         struct snd_soc_pcm_runtime *soc_runtime = subs->private_data;
 23         return snd_soc_dai_get_drvdata(snd_soc !!  23         return snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(soc_runtime, 0));
 24 }                                                  24 }
 25                                                    25 
 26 static const struct snd_pcm_hardware kirkwood_     26 static const struct snd_pcm_hardware kirkwood_dma_snd_hw = {
 27         .info = SNDRV_PCM_INFO_INTERLEAVED |       27         .info = SNDRV_PCM_INFO_INTERLEAVED |
 28                 SNDRV_PCM_INFO_MMAP |              28                 SNDRV_PCM_INFO_MMAP |
 29                 SNDRV_PCM_INFO_MMAP_VALID |        29                 SNDRV_PCM_INFO_MMAP_VALID |
 30                 SNDRV_PCM_INFO_BLOCK_TRANSFER      30                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
 31                 SNDRV_PCM_INFO_PAUSE |             31                 SNDRV_PCM_INFO_PAUSE |
 32                 SNDRV_PCM_INFO_NO_PERIOD_WAKEU     32                 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
 33         .buffer_bytes_max       = KIRKWOOD_SND     33         .buffer_bytes_max       = KIRKWOOD_SND_MAX_BUFFER_BYTES,
 34         .period_bytes_min       = KIRKWOOD_SND     34         .period_bytes_min       = KIRKWOOD_SND_MIN_PERIOD_BYTES,
 35         .period_bytes_max       = KIRKWOOD_SND     35         .period_bytes_max       = KIRKWOOD_SND_MAX_PERIOD_BYTES,
 36         .periods_min            = KIRKWOOD_SND     36         .periods_min            = KIRKWOOD_SND_MIN_PERIODS,
 37         .periods_max            = KIRKWOOD_SND     37         .periods_max            = KIRKWOOD_SND_MAX_PERIODS,
 38         .fifo_size              = 0,               38         .fifo_size              = 0,
 39 };                                                 39 };
 40                                                    40 
 41 static irqreturn_t kirkwood_dma_irq(int irq, v     41 static irqreturn_t kirkwood_dma_irq(int irq, void *dev_id)
 42 {                                                  42 {
 43         struct kirkwood_dma_data *priv = dev_i     43         struct kirkwood_dma_data *priv = dev_id;
 44         unsigned long mask, status, cause;         44         unsigned long mask, status, cause;
 45                                                    45 
 46         mask = readl(priv->io + KIRKWOOD_INT_M     46         mask = readl(priv->io + KIRKWOOD_INT_MASK);
 47         status = readl(priv->io + KIRKWOOD_INT     47         status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask;
 48                                                    48 
 49         cause = readl(priv->io + KIRKWOOD_ERR_     49         cause = readl(priv->io + KIRKWOOD_ERR_CAUSE);
 50         if (unlikely(cause)) {                     50         if (unlikely(cause)) {
 51                 printk(KERN_WARNING "%s: got e     51                 printk(KERN_WARNING "%s: got err interrupt 0x%lx\n",
 52                                 __func__, caus     52                                 __func__, cause);
 53                 writel(cause, priv->io + KIRKW     53                 writel(cause, priv->io + KIRKWOOD_ERR_CAUSE);
 54         }                                          54         }
 55                                                    55 
 56         /* we've enabled only bytes interrupts     56         /* we've enabled only bytes interrupts ... */
 57         if (status & ~(KIRKWOOD_INT_CAUSE_PLAY     57         if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \
 58                         KIRKWOOD_INT_CAUSE_REC     58                         KIRKWOOD_INT_CAUSE_REC_BYTES)) {
 59                 printk(KERN_WARNING "%s: unexp     59                 printk(KERN_WARNING "%s: unexpected interrupt %lx\n",
 60                         __func__, status);         60                         __func__, status);
 61                 return IRQ_NONE;                   61                 return IRQ_NONE;
 62         }                                          62         }
 63                                                    63 
 64         /* ack int */                              64         /* ack int */
 65         writel(status, priv->io + KIRKWOOD_INT     65         writel(status, priv->io + KIRKWOOD_INT_CAUSE);
 66                                                    66 
 67         if (status & KIRKWOOD_INT_CAUSE_PLAY_B     67         if (status & KIRKWOOD_INT_CAUSE_PLAY_BYTES)
 68                 snd_pcm_period_elapsed(priv->s     68                 snd_pcm_period_elapsed(priv->substream_play);
 69                                                    69 
 70         if (status & KIRKWOOD_INT_CAUSE_REC_BY     70         if (status & KIRKWOOD_INT_CAUSE_REC_BYTES)
 71                 snd_pcm_period_elapsed(priv->s     71                 snd_pcm_period_elapsed(priv->substream_rec);
 72                                                    72 
 73         return IRQ_HANDLED;                        73         return IRQ_HANDLED;
 74 }                                                  74 }
 75                                                    75 
 76 static void                                        76 static void
 77 kirkwood_dma_conf_mbus_windows(void __iomem *b     77 kirkwood_dma_conf_mbus_windows(void __iomem *base, int win,
 78                                unsigned long d     78                                unsigned long dma,
 79                                const struct mb     79                                const struct mbus_dram_target_info *dram)
 80 {                                                  80 {
 81         int i;                                     81         int i;
 82                                                    82 
 83         /* First disable and clear windows */      83         /* First disable and clear windows */
 84         writel(0, base + KIRKWOOD_AUDIO_WIN_CT     84         writel(0, base + KIRKWOOD_AUDIO_WIN_CTRL_REG(win));
 85         writel(0, base + KIRKWOOD_AUDIO_WIN_BA     85         writel(0, base + KIRKWOOD_AUDIO_WIN_BASE_REG(win));
 86                                                    86 
 87         /* try to find matching cs for current     87         /* try to find matching cs for current dma address */
 88         for (i = 0; i < dram->num_cs; i++) {       88         for (i = 0; i < dram->num_cs; i++) {
 89                 const struct mbus_dram_window  !!  89                 const struct mbus_dram_window *cs = dram->cs + i;
 90                 if ((cs->base & 0xffff0000) <      90                 if ((cs->base & 0xffff0000) < (dma & 0xffff0000)) {
 91                         writel(cs->base & 0xff     91                         writel(cs->base & 0xffff0000,
 92                                 base + KIRKWOO     92                                 base + KIRKWOOD_AUDIO_WIN_BASE_REG(win));
 93                         writel(((cs->size - 1)     93                         writel(((cs->size - 1) & 0xffff0000) |
 94                                 (cs->mbus_attr     94                                 (cs->mbus_attr << 8) |
 95                                 (dram->mbus_dr     95                                 (dram->mbus_dram_target_id << 4) | 1,
 96                                 base + KIRKWOO     96                                 base + KIRKWOOD_AUDIO_WIN_CTRL_REG(win));
 97                 }                                  97                 }
 98         }                                          98         }
 99 }                                                  99 }
100                                                   100 
101 static int kirkwood_dma_open(struct snd_soc_co    101 static int kirkwood_dma_open(struct snd_soc_component *component,
102                              struct snd_pcm_su    102                              struct snd_pcm_substream *substream)
103 {                                                 103 {
104         int err;                                  104         int err;
105         struct snd_pcm_runtime *runtime = subs    105         struct snd_pcm_runtime *runtime = substream->runtime;
106         struct kirkwood_dma_data *priv = kirkw    106         struct kirkwood_dma_data *priv = kirkwood_priv(substream);
107                                                   107 
108         snd_soc_set_runtime_hwparams(substream    108         snd_soc_set_runtime_hwparams(substream, &kirkwood_dma_snd_hw);
109                                                   109 
110         /* Ensure that all constraints linked     110         /* Ensure that all constraints linked to dma burst are fulfilled */
111         err = snd_pcm_hw_constraint_minmax(run    111         err = snd_pcm_hw_constraint_minmax(runtime,
112                         SNDRV_PCM_HW_PARAM_BUF    112                         SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
113                         priv->burst * 2,          113                         priv->burst * 2,
114                         KIRKWOOD_AUDIO_BUF_MAX    114                         KIRKWOOD_AUDIO_BUF_MAX-1);
115         if (err < 0)                              115         if (err < 0)
116                 return err;                       116                 return err;
117                                                   117 
118         err = snd_pcm_hw_constraint_step(runti    118         err = snd_pcm_hw_constraint_step(runtime, 0,
119                         SNDRV_PCM_HW_PARAM_BUF    119                         SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
120                         priv->burst);             120                         priv->burst);
121         if (err < 0)                              121         if (err < 0)
122                 return err;                       122                 return err;
123                                                   123 
124         err = snd_pcm_hw_constraint_step(subst    124         err = snd_pcm_hw_constraint_step(substream->runtime, 0,
125                          SNDRV_PCM_HW_PARAM_PE    125                          SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
126                          priv->burst);            126                          priv->burst);
127         if (err < 0)                              127         if (err < 0)
128                 return err;                       128                 return err;
129                                                   129 
130         if (!priv->substream_play && !priv->su    130         if (!priv->substream_play && !priv->substream_rec) {
131                 err = request_irq(priv->irq, k    131                 err = request_irq(priv->irq, kirkwood_dma_irq, IRQF_SHARED,
132                                   "kirkwood-i2    132                                   "kirkwood-i2s", priv);
133                 if (err)                          133                 if (err)
134                         return err;               134                         return err;
135                                                   135 
136                 /*                                136                 /*
137                  * Enable Error interrupts. We    137                  * Enable Error interrupts. We're only ack'ing them but
138                  * it's useful for diagnostics    138                  * it's useful for diagnostics
139                  */                               139                  */
140                 writel((unsigned int)-1, priv-    140                 writel((unsigned int)-1, priv->io + KIRKWOOD_ERR_MASK);
141         }                                         141         }
142                                                   142 
143         if (substream->stream == SNDRV_PCM_STR    143         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
144                 if (priv->substream_play)         144                 if (priv->substream_play)
145                         return -EBUSY;            145                         return -EBUSY;
146                 priv->substream_play = substre    146                 priv->substream_play = substream;
147         } else {                                  147         } else {
148                 if (priv->substream_rec)          148                 if (priv->substream_rec)
149                         return -EBUSY;            149                         return -EBUSY;
150                 priv->substream_rec = substrea    150                 priv->substream_rec = substream;
151         }                                         151         }
152                                                   152 
153         return 0;                                 153         return 0;
154 }                                                 154 }
155                                                   155 
156 static int kirkwood_dma_close(struct snd_soc_c    156 static int kirkwood_dma_close(struct snd_soc_component *component,
157                               struct snd_pcm_s    157                               struct snd_pcm_substream *substream)
158 {                                                 158 {
159         struct kirkwood_dma_data *priv = kirkw    159         struct kirkwood_dma_data *priv = kirkwood_priv(substream);
160                                                   160 
161         if (!priv)                                161         if (!priv)
162                 return 0;                         162                 return 0;
163                                                   163 
164         if (substream->stream == SNDRV_PCM_STR    164         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
165                 priv->substream_play = NULL;      165                 priv->substream_play = NULL;
166         else                                      166         else
167                 priv->substream_rec = NULL;       167                 priv->substream_rec = NULL;
168                                                   168 
169         if (!priv->substream_play && !priv->su    169         if (!priv->substream_play && !priv->substream_rec) {
170                 writel(0, priv->io + KIRKWOOD_    170                 writel(0, priv->io + KIRKWOOD_ERR_MASK);
171                 free_irq(priv->irq, priv);        171                 free_irq(priv->irq, priv);
172         }                                         172         }
173                                                   173 
174         return 0;                                 174         return 0;
175 }                                                 175 }
176                                                   176 
177 static int kirkwood_dma_hw_params(struct snd_s    177 static int kirkwood_dma_hw_params(struct snd_soc_component *component,
178                                   struct snd_p    178                                   struct snd_pcm_substream *substream,
179                                   struct snd_p    179                                   struct snd_pcm_hw_params *params)
180 {                                                 180 {
181         struct kirkwood_dma_data *priv = kirkw    181         struct kirkwood_dma_data *priv = kirkwood_priv(substream);
182         const struct mbus_dram_target_info *dr    182         const struct mbus_dram_target_info *dram = mv_mbus_dram_info();
183         unsigned long addr = substream->runtim    183         unsigned long addr = substream->runtime->dma_addr;
184                                                << 
185         if (!dram)                             << 
186                 return 0;                      << 
187                                                   184 
188         if (substream->stream == SNDRV_PCM_STR    185         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
189                 kirkwood_dma_conf_mbus_windows    186                 kirkwood_dma_conf_mbus_windows(priv->io,
190                         KIRKWOOD_PLAYBACK_WIN,    187                         KIRKWOOD_PLAYBACK_WIN, addr, dram);
191         else                                      188         else
192                 kirkwood_dma_conf_mbus_windows    189                 kirkwood_dma_conf_mbus_windows(priv->io,
193                         KIRKWOOD_RECORD_WIN, a    190                         KIRKWOOD_RECORD_WIN, addr, dram);
194         return 0;                                 191         return 0;
195 }                                                 192 }
196                                                   193 
197 static int kirkwood_dma_prepare(struct snd_soc    194 static int kirkwood_dma_prepare(struct snd_soc_component *component,
198                                 struct snd_pcm    195                                 struct snd_pcm_substream *substream)
199 {                                                 196 {
200         struct snd_pcm_runtime *runtime = subs    197         struct snd_pcm_runtime *runtime = substream->runtime;
201         struct kirkwood_dma_data *priv = kirkw    198         struct kirkwood_dma_data *priv = kirkwood_priv(substream);
202         unsigned long size, count;                199         unsigned long size, count;
203                                                   200 
204         /* compute buffer size in term of "wor    201         /* compute buffer size in term of "words" as requested in specs */
205         size = frames_to_bytes(runtime, runtim    202         size = frames_to_bytes(runtime, runtime->buffer_size);
206         size = (size>>2)-1;                       203         size = (size>>2)-1;
207         count = snd_pcm_lib_period_bytes(subst    204         count = snd_pcm_lib_period_bytes(substream);
208                                                   205 
209         if (substream->stream == SNDRV_PCM_STR    206         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
210                 writel(count, priv->io + KIRKW    207                 writel(count, priv->io + KIRKWOOD_PLAY_BYTE_INT_COUNT);
211                 writel(runtime->dma_addr, priv    208                 writel(runtime->dma_addr, priv->io + KIRKWOOD_PLAY_BUF_ADDR);
212                 writel(size, priv->io + KIRKWO    209                 writel(size, priv->io + KIRKWOOD_PLAY_BUF_SIZE);
213         } else {                                  210         } else {
214                 writel(count, priv->io + KIRKW    211                 writel(count, priv->io + KIRKWOOD_REC_BYTE_INT_COUNT);
215                 writel(runtime->dma_addr, priv    212                 writel(runtime->dma_addr, priv->io + KIRKWOOD_REC_BUF_ADDR);
216                 writel(size, priv->io + KIRKWO    213                 writel(size, priv->io + KIRKWOOD_REC_BUF_SIZE);
217         }                                         214         }
218                                                   215 
219                                                   216 
220         return 0;                                 217         return 0;
221 }                                                 218 }
222                                                   219 
223 static snd_pcm_uframes_t kirkwood_dma_pointer(    220 static snd_pcm_uframes_t kirkwood_dma_pointer(
224         struct snd_soc_component *component,      221         struct snd_soc_component *component,
225         struct snd_pcm_substream *substream)      222         struct snd_pcm_substream *substream)
226 {                                                 223 {
227         struct kirkwood_dma_data *priv = kirkw    224         struct kirkwood_dma_data *priv = kirkwood_priv(substream);
228         snd_pcm_uframes_t count;                  225         snd_pcm_uframes_t count;
229                                                   226 
230         if (substream->stream == SNDRV_PCM_STR    227         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
231                 count = bytes_to_frames(substr    228                 count = bytes_to_frames(substream->runtime,
232                         readl(priv->io + KIRKW    229                         readl(priv->io + KIRKWOOD_PLAY_BYTE_COUNT));
233         else                                      230         else
234                 count = bytes_to_frames(substr    231                 count = bytes_to_frames(substream->runtime,
235                         readl(priv->io + KIRKW    232                         readl(priv->io + KIRKWOOD_REC_BYTE_COUNT));
236                                                   233 
237         return count;                             234         return count;
238 }                                                 235 }
239                                                   236 
240 static int kirkwood_dma_new(struct snd_soc_com    237 static int kirkwood_dma_new(struct snd_soc_component *component,
241                             struct snd_soc_pcm    238                             struct snd_soc_pcm_runtime *rtd)
242 {                                                 239 {
243         size_t size = kirkwood_dma_snd_hw.buff    240         size_t size = kirkwood_dma_snd_hw.buffer_bytes_max;
244         struct snd_card *card = rtd->card->snd    241         struct snd_card *card = rtd->card->snd_card;
245         int ret;                                  242         int ret;
246                                                   243 
247         ret = dma_coerce_mask_and_coherent(car    244         ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
248         if (ret)                                  245         if (ret)
249                 return ret;                       246                 return ret;
250                                                   247 
251         snd_pcm_set_managed_buffer_all(rtd->pc    248         snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV,
252                                        card->d    249                                        card->dev, size, size);
253                                                   250 
254         return 0;                                 251         return 0;
255 }                                                 252 }
256                                                   253 
257 const struct snd_soc_component_driver kirkwood    254 const struct snd_soc_component_driver kirkwood_soc_component = {
258         .name           = DRV_NAME,               255         .name           = DRV_NAME,
259         .open           = kirkwood_dma_open,      256         .open           = kirkwood_dma_open,
260         .close          = kirkwood_dma_close,     257         .close          = kirkwood_dma_close,
261         .hw_params      = kirkwood_dma_hw_para    258         .hw_params      = kirkwood_dma_hw_params,
262         .prepare        = kirkwood_dma_prepare    259         .prepare        = kirkwood_dma_prepare,
263         .pointer        = kirkwood_dma_pointer    260         .pointer        = kirkwood_dma_pointer,
264         .pcm_construct  = kirkwood_dma_new,       261         .pcm_construct  = kirkwood_dma_new,
265 };                                                262 };
266                                                   263 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php