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