Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * PMac DBDMA lowlevel functions |
| 4 | * |
| 5 | * Copyright (c) by Takashi Iwai <tiwai@suse.de> |
| 6 | * code based on dmasound.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 10 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/irq.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/interrupt.h> |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 16 | #include <linux/pci.h> |
| 17 | #include <linux/dma-mapping.h> |
Rob Herring | 5af5073 | 2013-09-17 14:28:33 -0500 | [diff] [blame] | 18 | #include <linux/of_address.h> |
| 19 | #include <linux/of_irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <sound/core.h> |
| 21 | #include "pmac.h" |
| 22 | #include <sound/pcm_params.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/pmac_feature.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* fixed frequency table for awacs, screamer, burgundy, DACA (44100 max) */ |
| 27 | static int awacs_freqs[8] = { |
| 28 | 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350 |
| 29 | }; |
| 30 | /* fixed frequency table for tumbler */ |
| 31 | static int tumbler_freqs[1] = { |
| 32 | 44100 |
| 33 | }; |
| 34 | |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * we will allocate a single 'emergency' dbdma cmd block to use if the |
| 38 | * tx status comes up "DEAD". This happens on some PowerComputing Pmac |
| 39 | * clones, either owing to a bug in dbdma or some interaction between |
| 40 | * IDE and sound. However, this measure would deal with DEAD status if |
| 41 | * it appeared elsewhere. |
| 42 | */ |
| 43 | static struct pmac_dbdma emergency_dbdma; |
| 44 | static int emergency_in_use; |
| 45 | |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /* |
| 48 | * allocate DBDMA command arrays |
| 49 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 50 | static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, struct pmac_dbdma *rec, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 52 | unsigned int rsize = sizeof(struct dbdma_cmd) * (size + 1); |
| 53 | |
| 54 | rec->space = dma_alloc_coherent(&chip->pdev->dev, rsize, |
| 55 | &rec->dma_base, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | if (rec->space == NULL) |
| 57 | return -ENOMEM; |
| 58 | rec->size = size; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 59 | memset(rec->space, 0, rsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | rec->cmds = (void __iomem *)DBDMA_ALIGN(rec->space); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 61 | rec->addr = rec->dma_base + (unsigned long)((char *)rec->cmds - (char *)rec->space); |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 66 | static void snd_pmac_dbdma_free(struct snd_pmac *chip, struct pmac_dbdma *rec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Benjamin Herrenschmidt | 367636e | 2006-02-08 15:04:18 +1100 | [diff] [blame] | 68 | if (rec->space) { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 69 | unsigned int rsize = sizeof(struct dbdma_cmd) * (rec->size + 1); |
| 70 | |
| 71 | dma_free_coherent(&chip->pdev->dev, rsize, rec->space, rec->dma_base); |
| 72 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | * pcm stuff |
| 78 | */ |
| 79 | |
| 80 | /* |
| 81 | * look up frequency table |
| 82 | */ |
| 83 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 84 | unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec, unsigned int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
| 86 | int i, ok, found; |
| 87 | |
| 88 | ok = rec->cur_freqs; |
| 89 | if (rate > chip->freq_table[0]) |
| 90 | return 0; |
| 91 | found = 0; |
| 92 | for (i = 0; i < chip->num_freqs; i++, ok >>= 1) { |
| 93 | if (! (ok & 1)) continue; |
| 94 | found = i; |
| 95 | if (rate >= chip->freq_table[i]) |
| 96 | break; |
| 97 | } |
| 98 | return found; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * check whether another stream is active |
| 103 | */ |
| 104 | static inline int another_stream(int stream) |
| 105 | { |
| 106 | return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
| 107 | SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * allocate buffers |
| 112 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 113 | static int snd_pmac_pcm_hw_params(struct snd_pcm_substream *subs, |
| 114 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | return snd_pcm_lib_malloc_pages(subs, params_buffer_bytes(hw_params)); |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * release buffers |
| 121 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 122 | static int snd_pmac_pcm_hw_free(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | snd_pcm_lib_free_pages(subs); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * get a stream of the opposite direction |
| 130 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 131 | static struct pmac_stream *snd_pmac_get_stream(struct snd_pmac *chip, int stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
| 133 | switch (stream) { |
| 134 | case SNDRV_PCM_STREAM_PLAYBACK: |
| 135 | return &chip->playback; |
| 136 | case SNDRV_PCM_STREAM_CAPTURE: |
| 137 | return &chip->capture; |
| 138 | default: |
| 139 | snd_BUG(); |
| 140 | return NULL; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * wait while run status is on |
| 146 | */ |
Jesper Juhl | 77933d7 | 2005-07-27 11:46:09 -0700 | [diff] [blame] | 147 | static inline void |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 148 | snd_pmac_wait_ack(struct pmac_stream *rec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
| 150 | int timeout = 50000; |
| 151 | while ((in_le32(&rec->dma->status) & RUN) && timeout-- > 0) |
| 152 | udelay(1); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * set the format and rate to the chip. |
| 157 | * call the lowlevel function if defined (e.g. for AWACS). |
| 158 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 159 | static void snd_pmac_pcm_set_format(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | /* set up frequency and format */ |
| 162 | out_le32(&chip->awacs->control, chip->control_mask | (chip->rate_index << 8)); |
| 163 | out_le32(&chip->awacs->byteswap, chip->format == SNDRV_PCM_FORMAT_S16_LE ? 1 : 0); |
| 164 | if (chip->set_format) |
| 165 | chip->set_format(chip); |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * stop the DMA transfer |
| 170 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 171 | static inline void snd_pmac_dma_stop(struct pmac_stream *rec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | out_le32(&rec->dma->control, (RUN|WAKE|FLUSH|PAUSE) << 16); |
| 174 | snd_pmac_wait_ack(rec); |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * set the command pointer address |
| 179 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 180 | static inline void snd_pmac_dma_set_command(struct pmac_stream *rec, struct pmac_dbdma *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
| 182 | out_le32(&rec->dma->cmdptr, cmd->addr); |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * start the DMA |
| 187 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 188 | static inline void snd_pmac_dma_run(struct pmac_stream *rec, int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | out_le32(&rec->dma->control, status | (status << 16)); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /* |
| 195 | * prepare playback/capture stream |
| 196 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 197 | static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec, struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | int i; |
| 200 | volatile struct dbdma_cmd __iomem *cp; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 201 | struct snd_pcm_runtime *runtime = subs->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | int rate_index; |
| 203 | long offset; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 204 | struct pmac_stream *astr; |
Risto Suominen | 946cda7 | 2008-04-16 13:16:05 +0200 | [diff] [blame] | 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | rec->dma_size = snd_pcm_lib_buffer_bytes(subs); |
| 207 | rec->period_size = snd_pcm_lib_period_bytes(subs); |
| 208 | rec->nperiods = rec->dma_size / rec->period_size; |
| 209 | rec->cur_period = 0; |
| 210 | rate_index = snd_pmac_rate_index(chip, rec, runtime->rate); |
| 211 | |
| 212 | /* set up constraints */ |
| 213 | astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 214 | if (! astr) |
| 215 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | astr->cur_freqs = 1 << rate_index; |
| 217 | astr->cur_formats = 1 << runtime->format; |
| 218 | chip->rate_index = rate_index; |
| 219 | chip->format = runtime->format; |
| 220 | |
| 221 | /* We really want to execute a DMA stop command, after the AWACS |
| 222 | * is initialized. |
| 223 | * For reasons I don't understand, it stops the hissing noise |
| 224 | * common to many PowerBook G3 systems and random noise otherwise |
| 225 | * captured on iBook2's about every third time. -ReneR |
| 226 | */ |
| 227 | spin_lock_irq(&chip->reg_lock); |
| 228 | snd_pmac_dma_stop(rec); |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 229 | chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | snd_pmac_dma_set_command(rec, &chip->extra_dma); |
| 231 | snd_pmac_dma_run(rec, RUN); |
| 232 | spin_unlock_irq(&chip->reg_lock); |
| 233 | mdelay(5); |
| 234 | spin_lock_irq(&chip->reg_lock); |
| 235 | /* continuous DMA memory type doesn't provide the physical address, |
| 236 | * so we need to resolve the address here... |
| 237 | */ |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 238 | offset = runtime->dma_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) { |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 240 | cp->phy_addr = cpu_to_le32(offset); |
| 241 | cp->req_count = cpu_to_le16(rec->period_size); |
| 242 | /*cp->res_count = cpu_to_le16(0);*/ |
| 243 | cp->xfer_status = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | offset += rec->period_size; |
| 245 | } |
| 246 | /* make loop */ |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 247 | cp->command = cpu_to_le16(DBDMA_NOP + BR_ALWAYS); |
| 248 | cp->cmd_dep = cpu_to_le32(rec->cmd.addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | snd_pmac_dma_stop(rec); |
| 251 | snd_pmac_dma_set_command(rec, &rec->cmd); |
| 252 | spin_unlock_irq(&chip->reg_lock); |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | /* |
| 259 | * PCM trigger/stop |
| 260 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 261 | static int snd_pmac_pcm_trigger(struct snd_pmac *chip, struct pmac_stream *rec, |
| 262 | struct snd_pcm_substream *subs, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
| 264 | volatile struct dbdma_cmd __iomem *cp; |
| 265 | int i, command; |
| 266 | |
| 267 | switch (cmd) { |
| 268 | case SNDRV_PCM_TRIGGER_START: |
| 269 | case SNDRV_PCM_TRIGGER_RESUME: |
| 270 | if (rec->running) |
| 271 | return -EBUSY; |
| 272 | command = (subs->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 273 | OUTPUT_MORE : INPUT_MORE) + INTR_ALWAYS; |
| 274 | spin_lock(&chip->reg_lock); |
| 275 | snd_pmac_beep_stop(chip); |
| 276 | snd_pmac_pcm_set_format(chip); |
| 277 | for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) |
| 278 | out_le16(&cp->command, command); |
| 279 | snd_pmac_dma_set_command(rec, &rec->cmd); |
| 280 | (void)in_le32(&rec->dma->status); |
| 281 | snd_pmac_dma_run(rec, RUN|WAKE); |
| 282 | rec->running = 1; |
| 283 | spin_unlock(&chip->reg_lock); |
| 284 | break; |
| 285 | |
| 286 | case SNDRV_PCM_TRIGGER_STOP: |
| 287 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 288 | spin_lock(&chip->reg_lock); |
| 289 | rec->running = 0; |
Takashi Iwai | 6da6711 | 2009-02-05 16:02:46 +0100 | [diff] [blame] | 290 | /*printk(KERN_DEBUG "stopped!!\n");*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | snd_pmac_dma_stop(rec); |
| 292 | for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) |
| 293 | out_le16(&cp->command, DBDMA_STOP); |
| 294 | spin_unlock(&chip->reg_lock); |
| 295 | break; |
| 296 | |
| 297 | default: |
| 298 | return -EINVAL; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * return the current pointer |
| 306 | */ |
| 307 | inline |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 308 | static snd_pcm_uframes_t snd_pmac_pcm_pointer(struct snd_pmac *chip, |
| 309 | struct pmac_stream *rec, |
| 310 | struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
| 312 | int count = 0; |
| 313 | |
| 314 | #if 1 /* hmm.. how can we get the current dma pointer?? */ |
| 315 | int stat; |
| 316 | volatile struct dbdma_cmd __iomem *cp = &rec->cmd.cmds[rec->cur_period]; |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 317 | stat = le16_to_cpu(cp->xfer_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (stat & (ACTIVE|DEAD)) { |
| 319 | count = in_le16(&cp->res_count); |
| 320 | if (count) |
| 321 | count = rec->period_size - count; |
| 322 | } |
| 323 | #endif |
| 324 | count += rec->cur_period * rec->period_size; |
Takashi Iwai | 6da6711 | 2009-02-05 16:02:46 +0100 | [diff] [blame] | 325 | /*printk(KERN_DEBUG "pointer=%d\n", count);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return bytes_to_frames(subs->runtime, count); |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * playback |
| 331 | */ |
| 332 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 333 | static int snd_pmac_playback_prepare(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 335 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return snd_pmac_pcm_prepare(chip, &chip->playback, subs); |
| 337 | } |
| 338 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 339 | static int snd_pmac_playback_trigger(struct snd_pcm_substream *subs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | int cmd) |
| 341 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 342 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return snd_pmac_pcm_trigger(chip, &chip->playback, subs, cmd); |
| 344 | } |
| 345 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 346 | static snd_pcm_uframes_t snd_pmac_playback_pointer(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 348 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | return snd_pmac_pcm_pointer(chip, &chip->playback, subs); |
| 350 | } |
| 351 | |
| 352 | |
| 353 | /* |
| 354 | * capture |
| 355 | */ |
| 356 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 357 | static int snd_pmac_capture_prepare(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 359 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return snd_pmac_pcm_prepare(chip, &chip->capture, subs); |
| 361 | } |
| 362 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 363 | static int snd_pmac_capture_trigger(struct snd_pcm_substream *subs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | int cmd) |
| 365 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 366 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return snd_pmac_pcm_trigger(chip, &chip->capture, subs, cmd); |
| 368 | } |
| 369 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 370 | static snd_pcm_uframes_t snd_pmac_capture_pointer(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 372 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return snd_pmac_pcm_pointer(chip, &chip->capture, subs); |
| 374 | } |
| 375 | |
| 376 | |
| 377 | /* |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 378 | * Handle DEAD DMA transfers: |
| 379 | * if the TX status comes up "DEAD" - reported on some Power Computing machines |
| 380 | * we need to re-start the dbdma - but from a different physical start address |
| 381 | * and with a different transfer length. It would get very messy to do this |
| 382 | * with the normal dbdma_cmd blocks - we would have to re-write the buffer start |
| 383 | * addresses each time. So, we will keep a single dbdma_cmd block which can be |
| 384 | * fiddled with. |
| 385 | * When DEAD status is first reported the content of the faulted dbdma block is |
| 386 | * copied into the emergency buffer and we note that the buffer is in use. |
| 387 | * we then bump the start physical address by the amount that was successfully |
| 388 | * output before it died. |
| 389 | * On any subsequent DEAD result we just do the bump-ups (we know that we are |
| 390 | * already using the emergency dbdma_cmd). |
| 391 | * CHECK: this just tries to "do it". It is possible that we should abandon |
| 392 | * xfers when the number of residual bytes gets below a certain value - I can |
| 393 | * see that this might cause a loop-forever if a too small transfer causes |
| 394 | * DEAD status. However this is a TODO for now - we'll see what gets reported. |
| 395 | * When we get a successful transfer result with the emergency buffer we just |
| 396 | * pretend that it completed using the original dmdma_cmd and carry on. The |
| 397 | * 'next_cmd' field will already point back to the original loop of blocks. |
| 398 | */ |
| 399 | static inline void snd_pmac_pcm_dead_xfer(struct pmac_stream *rec, |
| 400 | volatile struct dbdma_cmd __iomem *cp) |
| 401 | { |
| 402 | unsigned short req, res ; |
| 403 | unsigned int phy ; |
| 404 | |
| 405 | /* printk(KERN_WARNING "snd-powermac: DMA died - patching it up!\n"); */ |
| 406 | |
| 407 | /* to clear DEAD status we must first clear RUN |
| 408 | set it to quiescent to be on the safe side */ |
| 409 | (void)in_le32(&rec->dma->status); |
| 410 | out_le32(&rec->dma->control, (RUN|PAUSE|FLUSH|WAKE) << 16); |
| 411 | |
| 412 | if (!emergency_in_use) { /* new problem */ |
| 413 | memcpy((void *)emergency_dbdma.cmds, (void *)cp, |
| 414 | sizeof(struct dbdma_cmd)); |
| 415 | emergency_in_use = 1; |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 416 | cp->xfer_status = cpu_to_le16(0); |
| 417 | cp->req_count = cpu_to_le16(rec->period_size); |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 418 | cp = emergency_dbdma.cmds; |
| 419 | } |
| 420 | |
| 421 | /* now bump the values to reflect the amount |
| 422 | we haven't yet shifted */ |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 423 | req = le16_to_cpu(cp->req_count); |
| 424 | res = le16_to_cpu(cp->res_count); |
| 425 | phy = le32_to_cpu(cp->phy_addr); |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 426 | phy += (req - res); |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 427 | cp->req_count = cpu_to_le16(res); |
| 428 | cp->res_count = cpu_to_le16(0); |
| 429 | cp->xfer_status = cpu_to_le16(0); |
| 430 | cp->phy_addr = cpu_to_le32(phy); |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 431 | |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 432 | cp->cmd_dep = cpu_to_le32(rec->cmd.addr |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 433 | + sizeof(struct dbdma_cmd)*((rec->cur_period+1)%rec->nperiods)); |
| 434 | |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 435 | cp->command = cpu_to_le16(OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS); |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 436 | |
| 437 | /* point at our patched up command block */ |
| 438 | out_le32(&rec->dma->cmdptr, emergency_dbdma.addr); |
| 439 | |
| 440 | /* we must re-start the controller */ |
| 441 | (void)in_le32(&rec->dma->status); |
| 442 | /* should complete clearing the DEAD status */ |
| 443 | out_le32(&rec->dma->control, ((RUN|WAKE) << 16) + (RUN|WAKE)); |
| 444 | } |
| 445 | |
| 446 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | * update playback/capture pointer from interrupts |
| 448 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 449 | static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { |
| 451 | volatile struct dbdma_cmd __iomem *cp; |
| 452 | int c; |
| 453 | int stat; |
| 454 | |
| 455 | spin_lock(&chip->reg_lock); |
| 456 | if (rec->running) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | for (c = 0; c < rec->nperiods; c++) { /* at most all fragments */ |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 458 | |
| 459 | if (emergency_in_use) /* already using DEAD xfer? */ |
| 460 | cp = emergency_dbdma.cmds; |
| 461 | else |
| 462 | cp = &rec->cmd.cmds[rec->cur_period]; |
| 463 | |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 464 | stat = le16_to_cpu(cp->xfer_status); |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 465 | |
| 466 | if (stat & DEAD) { |
| 467 | snd_pmac_pcm_dead_xfer(rec, cp); |
| 468 | break; /* this block is still going */ |
| 469 | } |
| 470 | |
| 471 | if (emergency_in_use) |
| 472 | emergency_in_use = 0 ; /* done that */ |
| 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | if (! (stat & ACTIVE)) |
| 475 | break; |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 476 | |
Takashi Iwai | 6da6711 | 2009-02-05 16:02:46 +0100 | [diff] [blame] | 477 | /*printk(KERN_DEBUG "update frag %d\n", rec->cur_period);*/ |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 478 | cp->xfer_status = cpu_to_le16(0); |
| 479 | cp->req_count = cpu_to_le16(rec->period_size); |
| 480 | /*cp->res_count = cpu_to_le16(0);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | rec->cur_period++; |
| 482 | if (rec->cur_period >= rec->nperiods) { |
| 483 | rec->cur_period = 0; |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 484 | } |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | spin_unlock(&chip->reg_lock); |
| 487 | snd_pcm_period_elapsed(rec->substream); |
| 488 | spin_lock(&chip->reg_lock); |
| 489 | } |
| 490 | } |
| 491 | spin_unlock(&chip->reg_lock); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | /* |
| 496 | * hw info |
| 497 | */ |
| 498 | |
Bhumika Goyal | 21bf6cf | 2017-08-17 14:45:56 +0530 | [diff] [blame] | 499 | static const struct snd_pcm_hardware snd_pmac_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
| 501 | .info = (SNDRV_PCM_INFO_INTERLEAVED | |
| 502 | SNDRV_PCM_INFO_MMAP | |
| 503 | SNDRV_PCM_INFO_MMAP_VALID | |
| 504 | SNDRV_PCM_INFO_RESUME), |
| 505 | .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S16_LE, |
| 506 | .rates = SNDRV_PCM_RATE_8000_44100, |
| 507 | .rate_min = 7350, |
| 508 | .rate_max = 44100, |
| 509 | .channels_min = 2, |
| 510 | .channels_max = 2, |
| 511 | .buffer_bytes_max = 131072, |
| 512 | .period_bytes_min = 256, |
| 513 | .period_bytes_max = 16384, |
| 514 | .periods_min = 3, |
| 515 | .periods_max = PMAC_MAX_FRAGS, |
| 516 | }; |
| 517 | |
Bhumika Goyal | 21bf6cf | 2017-08-17 14:45:56 +0530 | [diff] [blame] | 518 | static const struct snd_pcm_hardware snd_pmac_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
| 520 | .info = (SNDRV_PCM_INFO_INTERLEAVED | |
| 521 | SNDRV_PCM_INFO_MMAP | |
| 522 | SNDRV_PCM_INFO_MMAP_VALID | |
| 523 | SNDRV_PCM_INFO_RESUME), |
| 524 | .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S16_LE, |
| 525 | .rates = SNDRV_PCM_RATE_8000_44100, |
| 526 | .rate_min = 7350, |
| 527 | .rate_max = 44100, |
| 528 | .channels_min = 2, |
| 529 | .channels_max = 2, |
| 530 | .buffer_bytes_max = 131072, |
| 531 | .period_bytes_min = 256, |
| 532 | .period_bytes_max = 16384, |
| 533 | .periods_min = 3, |
| 534 | .periods_max = PMAC_MAX_FRAGS, |
| 535 | }; |
| 536 | |
| 537 | |
| 538 | #if 0 // NYI |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 539 | static int snd_pmac_hw_rule_rate(struct snd_pcm_hw_params *params, |
| 540 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 542 | struct snd_pmac *chip = rule->private; |
| 543 | struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | int i, freq_table[8], num_freqs; |
| 545 | |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 546 | if (! rec) |
| 547 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | num_freqs = 0; |
| 549 | for (i = chip->num_freqs - 1; i >= 0; i--) { |
| 550 | if (rec->cur_freqs & (1 << i)) |
| 551 | freq_table[num_freqs++] = chip->freq_table[i]; |
| 552 | } |
| 553 | |
| 554 | return snd_interval_list(hw_param_interval(params, rule->var), |
| 555 | num_freqs, freq_table, 0); |
| 556 | } |
| 557 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 558 | static int snd_pmac_hw_rule_format(struct snd_pcm_hw_params *params, |
| 559 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 561 | struct snd_pmac *chip = rule->private; |
| 562 | struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 564 | if (! rec) |
| 565 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | return snd_mask_refine_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), |
| 567 | rec->cur_formats); |
| 568 | } |
| 569 | #endif // NYI |
| 570 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 571 | static int snd_pmac_pcm_open(struct snd_pmac *chip, struct pmac_stream *rec, |
| 572 | struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 574 | struct snd_pcm_runtime *runtime = subs->runtime; |
Clemens Ladisch | 918f3a0 | 2007-08-13 17:40:54 +0200 | [diff] [blame] | 575 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | /* look up frequency table and fill bit mask */ |
| 578 | runtime->hw.rates = 0; |
Clemens Ladisch | 918f3a0 | 2007-08-13 17:40:54 +0200 | [diff] [blame] | 579 | for (i = 0; i < chip->num_freqs; i++) |
| 580 | if (chip->freqs_ok & (1 << i)) |
| 581 | runtime->hw.rates |= |
| 582 | snd_pcm_rate_to_rate_bit(chip->freq_table[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | /* check for minimum and maximum rates */ |
| 585 | for (i = 0; i < chip->num_freqs; i++) { |
| 586 | if (chip->freqs_ok & (1 << i)) { |
| 587 | runtime->hw.rate_max = chip->freq_table[i]; |
| 588 | break; |
| 589 | } |
| 590 | } |
| 591 | for (i = chip->num_freqs - 1; i >= 0; i--) { |
| 592 | if (chip->freqs_ok & (1 << i)) { |
| 593 | runtime->hw.rate_min = chip->freq_table[i]; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | runtime->hw.formats = chip->formats_ok; |
| 598 | if (chip->can_capture) { |
| 599 | if (! chip->can_duplex) |
| 600 | runtime->hw.info |= SNDRV_PCM_INFO_HALF_DUPLEX; |
| 601 | runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 602 | } |
| 603 | runtime->private_data = rec; |
| 604 | rec->substream = subs; |
| 605 | |
| 606 | #if 0 /* FIXME: still under development.. */ |
| 607 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 608 | snd_pmac_hw_rule_rate, chip, rec->stream, -1); |
| 609 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, |
| 610 | snd_pmac_hw_rule_format, chip, rec->stream, -1); |
| 611 | #endif |
| 612 | |
| 613 | runtime->hw.periods_max = rec->cmd.size - 1; |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | /* constraints to fix choppy sound */ |
| 616 | snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); |
| 617 | return 0; |
| 618 | } |
| 619 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 620 | static int snd_pmac_pcm_close(struct snd_pmac *chip, struct pmac_stream *rec, |
| 621 | struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 623 | struct pmac_stream *astr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | snd_pmac_dma_stop(rec); |
| 626 | |
| 627 | astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 628 | if (! astr) |
| 629 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | /* reset constraints */ |
| 632 | astr->cur_freqs = chip->freqs_ok; |
| 633 | astr->cur_formats = chip->formats_ok; |
Risto Suominen | 946cda7 | 2008-04-16 13:16:05 +0200 | [diff] [blame] | 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 638 | static int snd_pmac_playback_open(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 640 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
| 642 | subs->runtime->hw = snd_pmac_playback; |
| 643 | return snd_pmac_pcm_open(chip, &chip->playback, subs); |
| 644 | } |
| 645 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 646 | static int snd_pmac_capture_open(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 648 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | subs->runtime->hw = snd_pmac_capture; |
| 651 | return snd_pmac_pcm_open(chip, &chip->capture, subs); |
| 652 | } |
| 653 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 654 | static int snd_pmac_playback_close(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 656 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
| 658 | return snd_pmac_pcm_close(chip, &chip->playback, subs); |
| 659 | } |
| 660 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 661 | static int snd_pmac_capture_close(struct snd_pcm_substream *subs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 663 | struct snd_pmac *chip = snd_pcm_substream_chip(subs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
| 665 | return snd_pmac_pcm_close(chip, &chip->capture, subs); |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | */ |
| 670 | |
Arvind Yadav | 3179a3e | 2017-08-18 13:15:17 +0530 | [diff] [blame] | 671 | static const struct snd_pcm_ops snd_pmac_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | .open = snd_pmac_playback_open, |
| 673 | .close = snd_pmac_playback_close, |
| 674 | .ioctl = snd_pcm_lib_ioctl, |
| 675 | .hw_params = snd_pmac_pcm_hw_params, |
| 676 | .hw_free = snd_pmac_pcm_hw_free, |
| 677 | .prepare = snd_pmac_playback_prepare, |
| 678 | .trigger = snd_pmac_playback_trigger, |
| 679 | .pointer = snd_pmac_playback_pointer, |
| 680 | }; |
| 681 | |
Arvind Yadav | 3179a3e | 2017-08-18 13:15:17 +0530 | [diff] [blame] | 682 | static const struct snd_pcm_ops snd_pmac_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | .open = snd_pmac_capture_open, |
| 684 | .close = snd_pmac_capture_close, |
| 685 | .ioctl = snd_pcm_lib_ioctl, |
| 686 | .hw_params = snd_pmac_pcm_hw_params, |
| 687 | .hw_free = snd_pmac_pcm_hw_free, |
| 688 | .prepare = snd_pmac_capture_prepare, |
| 689 | .trigger = snd_pmac_capture_trigger, |
| 690 | .pointer = snd_pmac_capture_pointer, |
| 691 | }; |
| 692 | |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 693 | int snd_pmac_pcm_new(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 695 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | int err; |
| 697 | int num_captures = 1; |
| 698 | |
| 699 | if (! chip->can_capture) |
| 700 | num_captures = 0; |
| 701 | err = snd_pcm_new(chip->card, chip->card->driver, 0, 1, num_captures, &pcm); |
| 702 | if (err < 0) |
| 703 | return err; |
| 704 | |
| 705 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_pmac_playback_ops); |
| 706 | if (chip->can_capture) |
| 707 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_pmac_capture_ops); |
| 708 | |
| 709 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 711 | strcpy(pcm->name, chip->card->shortname); |
| 712 | chip->pcm = pcm; |
| 713 | |
| 714 | chip->formats_ok = SNDRV_PCM_FMTBIT_S16_BE; |
| 715 | if (chip->can_byte_swap) |
| 716 | chip->formats_ok |= SNDRV_PCM_FMTBIT_S16_LE; |
| 717 | |
| 718 | chip->playback.cur_formats = chip->formats_ok; |
| 719 | chip->capture.cur_formats = chip->formats_ok; |
| 720 | chip->playback.cur_freqs = chip->freqs_ok; |
| 721 | chip->capture.cur_freqs = chip->freqs_ok; |
| 722 | |
| 723 | /* preallocate 64k buffer */ |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 724 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 725 | &chip->pdev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | 64 * 1024, 64 * 1024); |
| 727 | |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 732 | static void snd_pmac_dbdma_reset(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | { |
| 734 | out_le32(&chip->playback.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16); |
| 735 | snd_pmac_wait_ack(&chip->playback); |
| 736 | out_le32(&chip->capture.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16); |
| 737 | snd_pmac_wait_ack(&chip->capture); |
| 738 | } |
| 739 | |
| 740 | |
| 741 | /* |
| 742 | * handling beep |
| 743 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 744 | void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 746 | struct pmac_stream *rec = &chip->playback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | snd_pmac_dma_stop(rec); |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 749 | chip->extra_dma.cmds->req_count = cpu_to_le16(bytes); |
| 750 | chip->extra_dma.cmds->xfer_status = cpu_to_le16(0); |
| 751 | chip->extra_dma.cmds->cmd_dep = cpu_to_le32(chip->extra_dma.addr); |
| 752 | chip->extra_dma.cmds->phy_addr = cpu_to_le32(addr); |
| 753 | chip->extra_dma.cmds->command = cpu_to_le16(OUTPUT_MORE + BR_ALWAYS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | out_le32(&chip->awacs->control, |
| 755 | (in_le32(&chip->awacs->control) & ~0x1f00) |
| 756 | | (speed << 8)); |
| 757 | out_le32(&chip->awacs->byteswap, 0); |
| 758 | snd_pmac_dma_set_command(rec, &chip->extra_dma); |
| 759 | snd_pmac_dma_run(rec, RUN); |
| 760 | } |
| 761 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 762 | void snd_pmac_beep_dma_stop(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
| 764 | snd_pmac_dma_stop(&chip->playback); |
David Gibson | f571872 | 2015-02-03 16:36:21 +1100 | [diff] [blame] | 765 | chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | snd_pmac_pcm_set_format(chip); /* reset format */ |
| 767 | } |
| 768 | |
| 769 | |
| 770 | /* |
| 771 | * interrupt handlers |
| 772 | */ |
| 773 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 774 | snd_pmac_tx_intr(int irq, void *devid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 776 | struct snd_pmac *chip = devid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | snd_pmac_pcm_update(chip, &chip->playback); |
| 778 | return IRQ_HANDLED; |
| 779 | } |
| 780 | |
| 781 | |
| 782 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 783 | snd_pmac_rx_intr(int irq, void *devid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 785 | struct snd_pmac *chip = devid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | snd_pmac_pcm_update(chip, &chip->capture); |
| 787 | return IRQ_HANDLED; |
| 788 | } |
| 789 | |
| 790 | |
| 791 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 792 | snd_pmac_ctrl_intr(int irq, void *devid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 794 | struct snd_pmac *chip = devid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | int ctrl = in_le32(&chip->awacs->control); |
| 796 | |
Takashi Iwai | 6da6711 | 2009-02-05 16:02:46 +0100 | [diff] [blame] | 797 | /*printk(KERN_DEBUG "pmac: control interrupt.. 0x%x\n", ctrl);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (ctrl & MASK_PORTCHG) { |
| 799 | /* do something when headphone is plugged/unplugged? */ |
| 800 | if (chip->update_automute) |
| 801 | chip->update_automute(chip, 1); |
| 802 | } |
| 803 | if (ctrl & MASK_CNTLERR) { |
| 804 | int err = (in_le32(&chip->awacs->codec_stat) & MASK_ERRCODE) >> 16; |
| 805 | if (err && chip->model <= PMAC_SCREAMER) |
| 806 | snd_printk(KERN_DEBUG "error %x\n", err); |
| 807 | } |
| 808 | /* Writing 1s to the CNTLERR and PORTCHG bits clears them... */ |
| 809 | out_le32(&chip->awacs->control, ctrl); |
| 810 | return IRQ_HANDLED; |
| 811 | } |
| 812 | |
| 813 | |
| 814 | /* |
| 815 | * a wrapper to feature call for compatibility |
| 816 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 817 | static void snd_pmac_sound_feature(struct snd_pmac *chip, int enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | { |
David Woodhouse | 4e6a06e | 2005-08-17 11:36:35 +0100 | [diff] [blame] | 819 | if (ppc_md.feature_call) |
| 820 | ppc_md.feature_call(PMAC_FTR_SOUND_CHIP_ENABLE, chip->node, 0, enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | /* |
| 824 | * release resources |
| 825 | */ |
| 826 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 827 | static int snd_pmac_free(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | /* stop sounds */ |
| 830 | if (chip->initialized) { |
| 831 | snd_pmac_dbdma_reset(chip); |
| 832 | /* disable interrupts from awacs interface */ |
| 833 | out_le32(&chip->awacs->control, in_le32(&chip->awacs->control) & 0xfff); |
| 834 | } |
| 835 | |
Benjamin Herrenschmidt | 41e904d | 2007-06-19 14:37:39 +1000 | [diff] [blame] | 836 | if (chip->node) |
| 837 | snd_pmac_sound_feature(chip, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | /* clean up mixer if any */ |
| 840 | if (chip->mixer_free) |
| 841 | chip->mixer_free(chip); |
| 842 | |
| 843 | snd_pmac_detach_beep(chip); |
| 844 | |
| 845 | /* release resources */ |
| 846 | if (chip->irq >= 0) |
| 847 | free_irq(chip->irq, (void*)chip); |
| 848 | if (chip->tx_irq >= 0) |
| 849 | free_irq(chip->tx_irq, (void*)chip); |
| 850 | if (chip->rx_irq >= 0) |
| 851 | free_irq(chip->rx_irq, (void*)chip); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 852 | snd_pmac_dbdma_free(chip, &chip->playback.cmd); |
| 853 | snd_pmac_dbdma_free(chip, &chip->capture.cmd); |
| 854 | snd_pmac_dbdma_free(chip, &chip->extra_dma); |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 855 | snd_pmac_dbdma_free(chip, &emergency_dbdma); |
Markus Elfring | ff6defa | 2015-01-03 22:55:54 +0100 | [diff] [blame] | 856 | iounmap(chip->macio_base); |
| 857 | iounmap(chip->latch_base); |
| 858 | iounmap(chip->awacs); |
| 859 | iounmap(chip->playback.dma); |
| 860 | iounmap(chip->capture.dma); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | if (chip->node) { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 863 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | for (i = 0; i < 3; i++) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 865 | if (chip->requested & (1 << i)) |
| 866 | release_mem_region(chip->rsrc[i].start, |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 867 | resource_size(&chip->rsrc[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
| 869 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 870 | |
Markus Elfring | 1ea7a56 | 2014-11-17 13:35:54 +0100 | [diff] [blame] | 871 | pci_dev_put(chip->pdev); |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 872 | of_node_put(chip->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | kfree(chip); |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | |
| 878 | /* |
| 879 | * free the device |
| 880 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 881 | static int snd_pmac_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 883 | struct snd_pmac *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | return snd_pmac_free(chip); |
| 885 | } |
| 886 | |
| 887 | |
| 888 | /* |
| 889 | * check the machine support byteswap (little-endian) |
| 890 | */ |
| 891 | |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 892 | static void detect_byte_swap(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | { |
| 894 | struct device_node *mio; |
| 895 | |
| 896 | /* if seems that Keylargo can't byte-swap */ |
| 897 | for (mio = chip->node->parent; mio; mio = mio->parent) { |
Rob Herring | 157ab88 | 2018-12-05 13:50:46 -0600 | [diff] [blame] | 898 | if (of_node_name_eq(mio, "mac-io")) { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 899 | if (of_device_is_compatible(mio, "Keylargo")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | chip->can_byte_swap = 0; |
| 901 | break; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | /* it seems the Pismo & iBook can't byte-swap in hardware. */ |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 906 | if (of_machine_is_compatible("PowerBook3,1") || |
| 907 | of_machine_is_compatible("PowerBook2,1")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | chip->can_byte_swap = 0 ; |
| 909 | |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 910 | if (of_machine_is_compatible("PowerBook2,1")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | chip->can_duplex = 0; |
| 912 | } |
| 913 | |
| 914 | |
| 915 | /* |
| 916 | * detect a sound chip |
| 917 | */ |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 918 | static int snd_pmac_detect(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | { |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 920 | struct device_node *sound; |
| 921 | struct device_node *dn; |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 922 | const unsigned int *prop; |
| 923 | unsigned int l; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 924 | struct macio_chip* macio; |
| 925 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 926 | if (!machine_is(powermac)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | return -ENODEV; |
| 928 | |
| 929 | chip->subframe = 0; |
| 930 | chip->revision = 0; |
| 931 | chip->freqs_ok = 0xff; /* all ok */ |
| 932 | chip->model = PMAC_AWACS; |
| 933 | chip->can_byte_swap = 1; |
| 934 | chip->can_duplex = 1; |
| 935 | chip->can_capture = 1; |
| 936 | chip->num_freqs = ARRAY_SIZE(awacs_freqs); |
| 937 | chip->freq_table = awacs_freqs; |
Benjamin Herrenschmidt | 367636e | 2006-02-08 15:04:18 +1100 | [diff] [blame] | 938 | chip->pdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
| 940 | chip->control_mask = MASK_IEPC | MASK_IEE | 0x11; /* default */ |
| 941 | |
| 942 | /* check machine type */ |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 943 | if (of_machine_is_compatible("AAPL,3400/2400") |
| 944 | || of_machine_is_compatible("AAPL,3500")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | chip->is_pbook_3400 = 1; |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 946 | else if (of_machine_is_compatible("PowerBook1,1") |
| 947 | || of_machine_is_compatible("AAPL,PowerBook1998")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | chip->is_pbook_G3 = 1; |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 949 | chip->node = of_find_node_by_name(NULL, "awacs"); |
| 950 | sound = of_node_get(chip->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | /* |
| 953 | * powermac G3 models have a node called "davbus" |
| 954 | * with a child called "sound". |
| 955 | */ |
Benjamin Herrenschmidt | 5218064 | 2005-05-18 16:31:51 +0200 | [diff] [blame] | 956 | if (!chip->node) |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 957 | chip->node = of_find_node_by_name(NULL, "davbus"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | /* |
| 959 | * if we didn't find a davbus device, try 'i2s-a' since |
| 960 | * this seems to be what iBooks have |
| 961 | */ |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 962 | if (! chip->node) { |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 963 | chip->node = of_find_node_by_name(NULL, "i2s-a"); |
Benjamin Herrenschmidt | 5218064 | 2005-05-18 16:31:51 +0200 | [diff] [blame] | 964 | if (chip->node && chip->node->parent && |
| 965 | chip->node->parent->parent) { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 966 | if (of_device_is_compatible(chip->node->parent->parent, |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 967 | "K2-Keylargo")) |
| 968 | chip->is_k2 = 1; |
| 969 | } |
| 970 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | if (! chip->node) |
| 972 | return -ENODEV; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 973 | |
Benjamin Herrenschmidt | 5218064 | 2005-05-18 16:31:51 +0200 | [diff] [blame] | 974 | if (!sound) { |
Grant Likely | ccdb8ed | 2014-06-04 16:42:26 +0100 | [diff] [blame] | 975 | for_each_node_by_name(sound, "sound") |
| 976 | if (sound->parent == chip->node) |
| 977 | break; |
Benjamin Herrenschmidt | 5218064 | 2005-05-18 16:31:51 +0200 | [diff] [blame] | 978 | } |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 979 | if (! sound) { |
| 980 | of_node_put(chip->node); |
Benjamin Herrenschmidt | 41e904d | 2007-06-19 14:37:39 +1000 | [diff] [blame] | 981 | chip->node = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | return -ENODEV; |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 983 | } |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 984 | prop = of_get_property(sound, "sub-frame", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | if (prop && *prop < 16) |
| 986 | chip->subframe = *prop; |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 987 | prop = of_get_property(sound, "layout-id", NULL); |
Johannes Berg | 55c385a | 2006-06-21 15:43:44 +0200 | [diff] [blame] | 988 | if (prop) { |
| 989 | /* partly deprecate snd-powermac, for those machines |
| 990 | * that have a layout-id property for now */ |
| 991 | printk(KERN_INFO "snd-powermac no longer handles any " |
| 992 | "machines with a layout-id property " |
| 993 | "in the device-tree, use snd-aoa.\n"); |
Benjamin Herrenschmidt | 41e904d | 2007-06-19 14:37:39 +1000 | [diff] [blame] | 994 | of_node_put(sound); |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 995 | of_node_put(chip->node); |
Benjamin Herrenschmidt | 41e904d | 2007-06-19 14:37:39 +1000 | [diff] [blame] | 996 | chip->node = NULL; |
Johannes Berg | 55c385a | 2006-06-21 15:43:44 +0200 | [diff] [blame] | 997 | return -ENODEV; |
| 998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | /* This should be verified on older screamers */ |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1000 | if (of_device_is_compatible(sound, "screamer")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | chip->model = PMAC_SCREAMER; |
| 1002 | // chip->can_byte_swap = 0; /* FIXME: check this */ |
| 1003 | } |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1004 | if (of_device_is_compatible(sound, "burgundy")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | chip->model = PMAC_BURGUNDY; |
| 1006 | chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ |
| 1007 | } |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1008 | if (of_device_is_compatible(sound, "daca")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | chip->model = PMAC_DACA; |
| 1010 | chip->can_capture = 0; /* no capture */ |
| 1011 | chip->can_duplex = 0; |
| 1012 | // chip->can_byte_swap = 0; /* FIXME: check this */ |
| 1013 | chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ |
| 1014 | } |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1015 | if (of_device_is_compatible(sound, "tumbler")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | chip->model = PMAC_TUMBLER; |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 1017 | chip->can_capture = of_machine_is_compatible("PowerMac4,2") |
Risto Suominen | 8460ae7 | 2011-02-28 10:38:45 +0200 | [diff] [blame] | 1018 | || of_machine_is_compatible("PowerBook3,2") |
| 1019 | || of_machine_is_compatible("PowerBook3,3") |
| 1020 | || of_machine_is_compatible("PowerBook4,1") |
| 1021 | || of_machine_is_compatible("PowerBook4,2") |
| 1022 | || of_machine_is_compatible("PowerBook4,3"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | chip->can_duplex = 0; |
| 1024 | // chip->can_byte_swap = 0; /* FIXME: check this */ |
| 1025 | chip->num_freqs = ARRAY_SIZE(tumbler_freqs); |
| 1026 | chip->freq_table = tumbler_freqs; |
| 1027 | chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ |
| 1028 | } |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1029 | if (of_device_is_compatible(sound, "snapper")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | chip->model = PMAC_SNAPPER; |
| 1031 | // chip->can_byte_swap = 0; /* FIXME: check this */ |
| 1032 | chip->num_freqs = ARRAY_SIZE(tumbler_freqs); |
| 1033 | chip->freq_table = tumbler_freqs; |
| 1034 | chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ |
| 1035 | } |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1036 | prop = of_get_property(sound, "device-id", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | if (prop) |
| 1038 | chip->device_id = *prop; |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1039 | dn = of_find_node_by_name(NULL, "perch"); |
| 1040 | chip->has_iic = (dn != NULL); |
| 1041 | of_node_put(dn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1043 | /* We need the PCI device for DMA allocations, let's use a crude method |
| 1044 | * for now ... |
| 1045 | */ |
| 1046 | macio = macio_find(chip->node, macio_unknown); |
| 1047 | if (macio == NULL) |
| 1048 | printk(KERN_WARNING "snd-powermac: can't locate macio !\n"); |
| 1049 | else { |
| 1050 | struct pci_dev *pdev = NULL; |
| 1051 | |
| 1052 | for_each_pci_dev(pdev) { |
| 1053 | struct device_node *np = pci_device_to_OF_node(pdev); |
| 1054 | if (np && np == macio->of_node) { |
| 1055 | chip->pdev = pdev; |
| 1056 | break; |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | if (chip->pdev == NULL) |
Benjamin Herrenschmidt | 5218064 | 2005-05-18 16:31:51 +0200 | [diff] [blame] | 1061 | printk(KERN_WARNING "snd-powermac: can't locate macio PCI" |
| 1062 | " device !\n"); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | detect_byte_swap(chip); |
| 1065 | |
| 1066 | /* look for a property saying what sample rates |
| 1067 | are available */ |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1068 | prop = of_get_property(sound, "sample-rates", &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | if (! prop) |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1070 | prop = of_get_property(sound, "output-frame-rates", &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | if (prop) { |
| 1072 | int i; |
| 1073 | chip->freqs_ok = 0; |
| 1074 | for (l /= sizeof(int); l > 0; --l) { |
| 1075 | unsigned int r = *prop++; |
| 1076 | /* Apple 'Fixed' format */ |
| 1077 | if (r >= 0x10000) |
| 1078 | r >>= 16; |
| 1079 | for (i = 0; i < chip->num_freqs; ++i) { |
| 1080 | if (r == chip->freq_table[i]) { |
| 1081 | chip->freqs_ok |= (1 << i); |
| 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | } else { |
| 1087 | /* assume only 44.1khz */ |
| 1088 | chip->freqs_ok = 1; |
| 1089 | } |
| 1090 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1091 | of_node_put(sound); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | return 0; |
| 1093 | } |
| 1094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | #ifdef PMAC_SUPPORT_AUTOMUTE |
| 1096 | /* |
| 1097 | * auto-mute |
| 1098 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1099 | static int pmac_auto_mute_get(struct snd_kcontrol *kcontrol, |
| 1100 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1102 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | ucontrol->value.integer.value[0] = chip->auto_mute; |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1107 | static int pmac_auto_mute_put(struct snd_kcontrol *kcontrol, |
| 1108 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1110 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | if (ucontrol->value.integer.value[0] != chip->auto_mute) { |
Takashi Iwai | d4079ac | 2007-11-15 16:14:12 +0100 | [diff] [blame] | 1112 | chip->auto_mute = !!ucontrol->value.integer.value[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | if (chip->update_automute) |
| 1114 | chip->update_automute(chip, 1); |
| 1115 | return 1; |
| 1116 | } |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1120 | static int pmac_hp_detect_get(struct snd_kcontrol *kcontrol, |
| 1121 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1123 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | if (chip->detect_headphone) |
| 1125 | ucontrol->value.integer.value[0] = chip->detect_headphone(chip); |
| 1126 | else |
| 1127 | ucontrol->value.integer.value[0] = 0; |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 1131 | static struct snd_kcontrol_new auto_mute_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1133 | .name = "Auto Mute Switch", |
| 1134 | .info = snd_pmac_boolean_mono_info, |
| 1135 | .get = pmac_auto_mute_get, |
| 1136 | .put = pmac_auto_mute_put, |
| 1137 | }, |
| 1138 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1139 | .name = "Headphone Detection", |
| 1140 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1141 | .info = snd_pmac_boolean_mono_info, |
| 1142 | .get = pmac_hp_detect_get, |
| 1143 | }, |
| 1144 | }; |
| 1145 | |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 1146 | int snd_pmac_add_automute(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
| 1148 | int err; |
| 1149 | chip->auto_mute = 1; |
| 1150 | err = snd_ctl_add(chip->card, snd_ctl_new1(&auto_mute_controls[0], chip)); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1151 | if (err < 0) { |
| 1152 | printk(KERN_ERR "snd-powermac: Failed to add automute control\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | return err; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | chip->hp_detect_ctl = snd_ctl_new1(&auto_mute_controls[1], chip); |
| 1156 | return snd_ctl_add(chip->card, chip->hp_detect_ctl); |
| 1157 | } |
| 1158 | #endif /* PMAC_SUPPORT_AUTOMUTE */ |
| 1159 | |
| 1160 | /* |
| 1161 | * create and detect a pmac chip record |
| 1162 | */ |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 1163 | int snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1165 | struct snd_pmac *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | struct device_node *np; |
| 1167 | int i, err; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1168 | unsigned int irq; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1169 | unsigned long ctrl_addr, txdma_addr, rxdma_addr; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1170 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | .dev_free = snd_pmac_dev_free, |
| 1172 | }; |
| 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | *chip_return = NULL; |
| 1175 | |
Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 1176 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | if (chip == NULL) |
| 1178 | return -ENOMEM; |
| 1179 | chip->card = card; |
| 1180 | |
| 1181 | spin_lock_init(&chip->reg_lock); |
| 1182 | chip->irq = chip->tx_irq = chip->rx_irq = -1; |
| 1183 | |
| 1184 | chip->playback.stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 1185 | chip->capture.stream = SNDRV_PCM_STREAM_CAPTURE; |
| 1186 | |
| 1187 | if ((err = snd_pmac_detect(chip)) < 0) |
| 1188 | goto __error; |
| 1189 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1190 | if (snd_pmac_dbdma_alloc(chip, &chip->playback.cmd, PMAC_MAX_FRAGS + 1) < 0 || |
| 1191 | snd_pmac_dbdma_alloc(chip, &chip->capture.cmd, PMAC_MAX_FRAGS + 1) < 0 || |
T. H. Huth | e70515dd5 | 2008-01-16 15:57:08 +0100 | [diff] [blame] | 1192 | snd_pmac_dbdma_alloc(chip, &chip->extra_dma, 2) < 0 || |
| 1193 | snd_pmac_dbdma_alloc(chip, &emergency_dbdma, 2) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | err = -ENOMEM; |
| 1195 | goto __error; |
| 1196 | } |
| 1197 | |
| 1198 | np = chip->node; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1199 | chip->requested = 0; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1200 | if (chip->is_k2) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1201 | static char *rnames[] = { |
| 1202 | "Sound Control", "Sound DMA" }; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1203 | for (i = 0; i < 2; i ++) { |
| 1204 | if (of_address_to_resource(np->parent, i, |
| 1205 | &chip->rsrc[i])) { |
| 1206 | printk(KERN_ERR "snd: can't translate rsrc " |
| 1207 | " %d (%s)\n", i, rnames[i]); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1208 | err = -ENODEV; |
| 1209 | goto __error; |
| 1210 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1211 | if (request_mem_region(chip->rsrc[i].start, |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 1212 | resource_size(&chip->rsrc[i]), |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1213 | rnames[i]) == NULL) { |
| 1214 | printk(KERN_ERR "snd: can't request rsrc " |
Joe Perches | 2fb50f1 | 2010-11-12 13:38:04 -0800 | [diff] [blame] | 1215 | " %d (%s: %pR)\n", |
| 1216 | i, rnames[i], &chip->rsrc[i]); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1217 | err = -ENODEV; |
| 1218 | goto __error; |
| 1219 | } |
| 1220 | chip->requested |= (1 << i); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1221 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1222 | ctrl_addr = chip->rsrc[0].start; |
| 1223 | txdma_addr = chip->rsrc[1].start; |
| 1224 | rxdma_addr = txdma_addr + 0x100; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1225 | } else { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1226 | static char *rnames[] = { |
| 1227 | "Sound Control", "Sound Tx DMA", "Sound Rx DMA" }; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1228 | for (i = 0; i < 3; i ++) { |
Benjamin Herrenschmidt | 88356e9 | 2006-02-01 03:04:43 -0800 | [diff] [blame] | 1229 | if (of_address_to_resource(np, i, |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1230 | &chip->rsrc[i])) { |
| 1231 | printk(KERN_ERR "snd: can't translate rsrc " |
| 1232 | " %d (%s)\n", i, rnames[i]); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1233 | err = -ENODEV; |
| 1234 | goto __error; |
| 1235 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1236 | if (request_mem_region(chip->rsrc[i].start, |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 1237 | resource_size(&chip->rsrc[i]), |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1238 | rnames[i]) == NULL) { |
| 1239 | printk(KERN_ERR "snd: can't request rsrc " |
Joe Perches | 2fb50f1 | 2010-11-12 13:38:04 -0800 | [diff] [blame] | 1240 | " %d (%s: %pR)\n", |
| 1241 | i, rnames[i], &chip->rsrc[i]); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1242 | err = -ENODEV; |
| 1243 | goto __error; |
| 1244 | } |
| 1245 | chip->requested |= (1 << i); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1246 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1247 | ctrl_addr = chip->rsrc[0].start; |
| 1248 | txdma_addr = chip->rsrc[1].start; |
| 1249 | rxdma_addr = chip->rsrc[2].start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1252 | chip->awacs = ioremap(ctrl_addr, 0x1000); |
| 1253 | chip->playback.dma = ioremap(txdma_addr, 0x100); |
| 1254 | chip->capture.dma = ioremap(rxdma_addr, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | if (chip->model <= PMAC_BURGUNDY) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1256 | irq = irq_of_parse_and_map(np, 0); |
| 1257 | if (request_irq(irq, snd_pmac_ctrl_intr, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | "PMac", (void*)chip)) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1259 | snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", |
| 1260 | irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | err = -EBUSY; |
| 1262 | goto __error; |
| 1263 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1264 | chip->irq = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1266 | irq = irq_of_parse_and_map(np, 1); |
| 1267 | if (request_irq(irq, snd_pmac_tx_intr, 0, "PMac Output", (void*)chip)){ |
| 1268 | snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | err = -EBUSY; |
| 1270 | goto __error; |
| 1271 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1272 | chip->tx_irq = irq; |
| 1273 | irq = irq_of_parse_and_map(np, 2); |
| 1274 | if (request_irq(irq, snd_pmac_rx_intr, 0, "PMac Input", (void*)chip)) { |
| 1275 | snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | err = -EBUSY; |
| 1277 | goto __error; |
| 1278 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1279 | chip->rx_irq = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
| 1281 | snd_pmac_sound_feature(chip, 1); |
| 1282 | |
Risto Suominen | 9a4f20f | 2008-04-16 13:15:38 +0200 | [diff] [blame] | 1283 | /* reset & enable interrupts */ |
| 1284 | if (chip->model <= PMAC_BURGUNDY) |
| 1285 | out_le32(&chip->awacs->control, chip->control_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
| 1287 | /* Powerbooks have odd ways of enabling inputs such as |
| 1288 | an expansion-bay CD or sound from an internal modem |
| 1289 | or a PC-card modem. */ |
| 1290 | if (chip->is_pbook_3400) { |
| 1291 | /* Enable CD and PC-card sound inputs. */ |
| 1292 | /* This is done by reading from address |
| 1293 | * f301a000, + 0x10 to enable the expansion-bay |
| 1294 | * CD sound input, + 0x80 to enable the PC-card |
| 1295 | * sound input. The 0x100 enables the SCSI bus |
| 1296 | * terminator power. |
| 1297 | */ |
| 1298 | chip->latch_base = ioremap (0xf301a000, 0x1000); |
| 1299 | in_8(chip->latch_base + 0x190); |
| 1300 | } else if (chip->is_pbook_G3) { |
| 1301 | struct device_node* mio; |
| 1302 | for (mio = chip->node->parent; mio; mio = mio->parent) { |
Rob Herring | 157ab88 | 2018-12-05 13:50:46 -0600 | [diff] [blame] | 1303 | if (of_node_name_eq(mio, "mac-io")) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1304 | struct resource r; |
| 1305 | if (of_address_to_resource(mio, 0, &r) == 0) |
| 1306 | chip->macio_base = |
| 1307 | ioremap(r.start, 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | break; |
| 1309 | } |
| 1310 | } |
| 1311 | /* Enable CD sound input. */ |
| 1312 | /* The relevant bits for writing to this byte are 0x8f. |
| 1313 | * I haven't found out what the 0x80 bit does. |
| 1314 | * For the 0xf bits, writing 3 or 7 enables the CD |
| 1315 | * input, any other value disables it. Values |
| 1316 | * 1, 3, 5, 7 enable the microphone. Values 0, 2, |
| 1317 | * 4, 6, 8 - f enable the input from the modem. |
| 1318 | */ |
| 1319 | if (chip->macio_base) |
| 1320 | out_8(chip->macio_base + 0x37, 3); |
| 1321 | } |
| 1322 | |
| 1323 | /* Reset dbdma channels */ |
| 1324 | snd_pmac_dbdma_reset(chip); |
| 1325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) |
| 1327 | goto __error; |
| 1328 | |
| 1329 | *chip_return = chip; |
| 1330 | return 0; |
| 1331 | |
| 1332 | __error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | snd_pmac_free(chip); |
| 1334 | return err; |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | /* |
| 1339 | * sleep notify for powerbook |
| 1340 | */ |
| 1341 | |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 1342 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | |
| 1344 | /* |
| 1345 | * Save state when going to sleep, restore it afterwards. |
| 1346 | */ |
| 1347 | |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 1348 | void snd_pmac_suspend(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | unsigned long flags; |
| 1351 | |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 1352 | snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | if (chip->suspend) |
| 1354 | chip->suspend(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1356 | snd_pmac_beep_stop(chip); |
| 1357 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1358 | if (chip->irq >= 0) |
| 1359 | disable_irq(chip->irq); |
| 1360 | if (chip->tx_irq >= 0) |
| 1361 | disable_irq(chip->tx_irq); |
| 1362 | if (chip->rx_irq >= 0) |
| 1363 | disable_irq(chip->rx_irq); |
| 1364 | snd_pmac_sound_feature(chip, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 1367 | void snd_pmac_resume(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | snd_pmac_sound_feature(chip, 1); |
| 1370 | if (chip->resume) |
| 1371 | chip->resume(chip); |
| 1372 | /* enable CD sound input */ |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 1373 | if (chip->macio_base && chip->is_pbook_G3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | out_8(chip->macio_base + 0x37, 3); |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 1375 | else if (chip->is_pbook_3400) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | in_8(chip->latch_base + 0x190); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
| 1378 | snd_pmac_pcm_set_format(chip); |
| 1379 | |
| 1380 | if (chip->irq >= 0) |
| 1381 | enable_irq(chip->irq); |
| 1382 | if (chip->tx_irq >= 0) |
| 1383 | enable_irq(chip->tx_irq); |
| 1384 | if (chip->rx_irq >= 0) |
| 1385 | enable_irq(chip->rx_irq); |
| 1386 | |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 1387 | snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 1390 | #endif /* CONFIG_PM */ |
| 1391 | |