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