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