Lines Matching +full:chip +full:- +full:to +full:- +full:chip
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
30 #include <linux/dma-mapping.h>
35 #include <asm/pci-bridge.h>
49 * we will allocate a single 'emergency' dbdma cmd block to use if the
51 * clones, either owing to a bug in dbdma or some interaction between
62 static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, struct pmac_dbdma *rec, int size) in snd_pmac_dbdma_alloc() argument
66 rec->space = dma_alloc_coherent(&chip->pdev->dev, rsize, in snd_pmac_dbdma_alloc()
67 &rec->dma_base, GFP_KERNEL); in snd_pmac_dbdma_alloc()
68 if (rec->space == NULL) in snd_pmac_dbdma_alloc()
69 return -ENOMEM; in snd_pmac_dbdma_alloc()
70 rec->size = size; in snd_pmac_dbdma_alloc()
71 memset(rec->space, 0, rsize); in snd_pmac_dbdma_alloc()
72 rec->cmds = (void __iomem *)DBDMA_ALIGN(rec->space); in snd_pmac_dbdma_alloc()
73 rec->addr = rec->dma_base + (unsigned long)((char *)rec->cmds - (char *)rec->space); in snd_pmac_dbdma_alloc()
78 static void snd_pmac_dbdma_free(struct snd_pmac *chip, struct pmac_dbdma *rec) in snd_pmac_dbdma_free() argument
80 if (rec->space) { in snd_pmac_dbdma_free()
81 unsigned int rsize = sizeof(struct dbdma_cmd) * (rec->size + 1); in snd_pmac_dbdma_free()
83 dma_free_coherent(&chip->pdev->dev, rsize, rec->space, rec->dma_base); in snd_pmac_dbdma_free()
96 unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec, unsigned int rate) in snd_pmac_rate_index() argument
100 ok = rec->cur_freqs; in snd_pmac_rate_index()
101 if (rate > chip->freq_table[0]) in snd_pmac_rate_index()
104 for (i = 0; i < chip->num_freqs; i++, ok >>= 1) { in snd_pmac_rate_index()
107 if (rate >= chip->freq_table[i]) in snd_pmac_rate_index()
143 static struct pmac_stream *snd_pmac_get_stream(struct snd_pmac *chip, int stream) in snd_pmac_get_stream() argument
147 return &chip->playback; in snd_pmac_get_stream()
149 return &chip->capture; in snd_pmac_get_stream()
163 while ((in_le32(&rec->dma->status) & RUN) && timeout-- > 0) in snd_pmac_wait_ack()
168 * set the format and rate to the chip.
171 static void snd_pmac_pcm_set_format(struct snd_pmac *chip) in snd_pmac_pcm_set_format() argument
174 out_le32(&chip->awacs->control, chip->control_mask | (chip->rate_index << 8)); in snd_pmac_pcm_set_format()
175 out_le32(&chip->awacs->byteswap, chip->format == SNDRV_PCM_FORMAT_S16_LE ? 1 : 0); in snd_pmac_pcm_set_format()
176 if (chip->set_format) in snd_pmac_pcm_set_format()
177 chip->set_format(chip); in snd_pmac_pcm_set_format()
185 out_le32(&rec->dma->control, (RUN|WAKE|FLUSH|PAUSE) << 16); in snd_pmac_dma_stop()
194 out_le32(&rec->dma->cmdptr, cmd->addr); in snd_pmac_dma_set_command()
202 out_le32(&rec->dma->control, status | (status << 16)); in snd_pmac_dma_run()
209 static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec, struct snd_pcm_subs… in snd_pmac_pcm_prepare() argument
213 struct snd_pcm_runtime *runtime = subs->runtime; in snd_pmac_pcm_prepare()
218 rec->dma_size = snd_pcm_lib_buffer_bytes(subs); in snd_pmac_pcm_prepare()
219 rec->period_size = snd_pcm_lib_period_bytes(subs); in snd_pmac_pcm_prepare()
220 rec->nperiods = rec->dma_size / rec->period_size; in snd_pmac_pcm_prepare()
221 rec->cur_period = 0; in snd_pmac_pcm_prepare()
222 rate_index = snd_pmac_rate_index(chip, rec, runtime->rate); in snd_pmac_pcm_prepare()
225 astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); in snd_pmac_pcm_prepare()
227 return -EINVAL; in snd_pmac_pcm_prepare()
228 astr->cur_freqs = 1 << rate_index; in snd_pmac_pcm_prepare()
229 astr->cur_formats = 1 << runtime->format; in snd_pmac_pcm_prepare()
230 chip->rate_index = rate_index; in snd_pmac_pcm_prepare()
231 chip->format = runtime->format; in snd_pmac_pcm_prepare()
233 /* We really want to execute a DMA stop command, after the AWACS in snd_pmac_pcm_prepare()
236 * common to many PowerBook G3 systems and random noise otherwise in snd_pmac_pcm_prepare()
237 * captured on iBook2's about every third time. -ReneR in snd_pmac_pcm_prepare()
239 spin_lock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
241 st_le16(&chip->extra_dma.cmds->command, DBDMA_STOP); in snd_pmac_pcm_prepare()
242 snd_pmac_dma_set_command(rec, &chip->extra_dma); in snd_pmac_pcm_prepare()
244 spin_unlock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
246 spin_lock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
248 * so we need to resolve the address here... in snd_pmac_pcm_prepare()
250 offset = runtime->dma_addr; in snd_pmac_pcm_prepare()
251 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) { in snd_pmac_pcm_prepare()
252 st_le32(&cp->phy_addr, offset); in snd_pmac_pcm_prepare()
253 st_le16(&cp->req_count, rec->period_size); in snd_pmac_pcm_prepare()
254 /*st_le16(&cp->res_count, 0);*/ in snd_pmac_pcm_prepare()
255 st_le16(&cp->xfer_status, 0); in snd_pmac_pcm_prepare()
256 offset += rec->period_size; in snd_pmac_pcm_prepare()
259 st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS); in snd_pmac_pcm_prepare()
260 st_le32(&cp->cmd_dep, rec->cmd.addr); in snd_pmac_pcm_prepare()
263 snd_pmac_dma_set_command(rec, &rec->cmd); in snd_pmac_pcm_prepare()
264 spin_unlock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
273 static int snd_pmac_pcm_trigger(struct snd_pmac *chip, struct pmac_stream *rec, in snd_pmac_pcm_trigger() argument
282 if (rec->running) in snd_pmac_pcm_trigger()
283 return -EBUSY; in snd_pmac_pcm_trigger()
284 command = (subs->stream == SNDRV_PCM_STREAM_PLAYBACK ? in snd_pmac_pcm_trigger()
286 spin_lock(&chip->reg_lock); in snd_pmac_pcm_trigger()
287 snd_pmac_beep_stop(chip); in snd_pmac_pcm_trigger()
288 snd_pmac_pcm_set_format(chip); in snd_pmac_pcm_trigger()
289 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) in snd_pmac_pcm_trigger()
290 out_le16(&cp->command, command); in snd_pmac_pcm_trigger()
291 snd_pmac_dma_set_command(rec, &rec->cmd); in snd_pmac_pcm_trigger()
292 (void)in_le32(&rec->dma->status); in snd_pmac_pcm_trigger()
294 rec->running = 1; in snd_pmac_pcm_trigger()
295 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_trigger()
300 spin_lock(&chip->reg_lock); in snd_pmac_pcm_trigger()
301 rec->running = 0; in snd_pmac_pcm_trigger()
304 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) in snd_pmac_pcm_trigger()
305 out_le16(&cp->command, DBDMA_STOP); in snd_pmac_pcm_trigger()
306 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_trigger()
310 return -EINVAL; in snd_pmac_pcm_trigger()
320 static snd_pcm_uframes_t snd_pmac_pcm_pointer(struct snd_pmac *chip, in snd_pmac_pcm_pointer() argument
328 volatile struct dbdma_cmd __iomem *cp = &rec->cmd.cmds[rec->cur_period]; in snd_pmac_pcm_pointer()
329 stat = ld_le16(&cp->xfer_status); in snd_pmac_pcm_pointer()
331 count = in_le16(&cp->res_count); in snd_pmac_pcm_pointer()
333 count = rec->period_size - count; in snd_pmac_pcm_pointer()
336 count += rec->cur_period * rec->period_size; in snd_pmac_pcm_pointer()
338 return bytes_to_frames(subs->runtime, count); in snd_pmac_pcm_pointer()
347 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_playback_prepare() local
348 return snd_pmac_pcm_prepare(chip, &chip->playback, subs); in snd_pmac_playback_prepare()
354 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_playback_trigger() local
355 return snd_pmac_pcm_trigger(chip, &chip->playback, subs, cmd); in snd_pmac_playback_trigger()
360 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_playback_pointer() local
361 return snd_pmac_pcm_pointer(chip, &chip->playback, subs); in snd_pmac_playback_pointer()
371 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_capture_prepare() local
372 return snd_pmac_pcm_prepare(chip, &chip->capture, subs); in snd_pmac_capture_prepare()
378 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_capture_trigger() local
379 return snd_pmac_pcm_trigger(chip, &chip->capture, subs, cmd); in snd_pmac_capture_trigger()
384 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_capture_pointer() local
385 return snd_pmac_pcm_pointer(chip, &chip->capture, subs); in snd_pmac_capture_pointer()
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
401 * On any subsequent DEAD result we just do the bump-ups (we know that we are
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.
409 * 'next_cmd' field will already point back to the original loop of blocks.
417 /* printk(KERN_WARNING "snd-powermac: DMA died - patching it up!\n"); */ in snd_pmac_pcm_dead_xfer()
419 /* to clear DEAD status we must first clear RUN in snd_pmac_pcm_dead_xfer()
420 set it to quiescent to be on the safe side */ in snd_pmac_pcm_dead_xfer()
421 (void)in_le32(&rec->dma->status); in snd_pmac_pcm_dead_xfer()
422 out_le32(&rec->dma->control, (RUN|PAUSE|FLUSH|WAKE) << 16); in snd_pmac_pcm_dead_xfer()
428 st_le16(&cp->xfer_status, 0); in snd_pmac_pcm_dead_xfer()
429 st_le16(&cp->req_count, rec->period_size); in snd_pmac_pcm_dead_xfer()
433 /* now bump the values to reflect the amount in snd_pmac_pcm_dead_xfer()
435 req = ld_le16(&cp->req_count); in snd_pmac_pcm_dead_xfer()
436 res = ld_le16(&cp->res_count); in snd_pmac_pcm_dead_xfer()
437 phy = ld_le32(&cp->phy_addr); in snd_pmac_pcm_dead_xfer()
438 phy += (req - res); in snd_pmac_pcm_dead_xfer()
439 st_le16(&cp->req_count, res); in snd_pmac_pcm_dead_xfer()
440 st_le16(&cp->res_count, 0); in snd_pmac_pcm_dead_xfer()
441 st_le16(&cp->xfer_status, 0); in snd_pmac_pcm_dead_xfer()
442 st_le32(&cp->phy_addr, phy); in snd_pmac_pcm_dead_xfer()
444 st_le32(&cp->cmd_dep, rec->cmd.addr in snd_pmac_pcm_dead_xfer()
445 + sizeof(struct dbdma_cmd)*((rec->cur_period+1)%rec->nperiods)); in snd_pmac_pcm_dead_xfer()
447 st_le16(&cp->command, OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS); in snd_pmac_pcm_dead_xfer()
450 out_le32(&rec->dma->cmdptr, emergency_dbdma.addr); in snd_pmac_pcm_dead_xfer()
452 /* we must re-start the controller */ in snd_pmac_pcm_dead_xfer()
453 (void)in_le32(&rec->dma->status); in snd_pmac_pcm_dead_xfer()
455 out_le32(&rec->dma->control, ((RUN|WAKE) << 16) + (RUN|WAKE)); in snd_pmac_pcm_dead_xfer()
461 static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec) in snd_pmac_pcm_update() argument
467 spin_lock(&chip->reg_lock); in snd_pmac_pcm_update()
468 if (rec->running) { in snd_pmac_pcm_update()
469 for (c = 0; c < rec->nperiods; c++) { /* at most all fragments */ in snd_pmac_pcm_update()
474 cp = &rec->cmd.cmds[rec->cur_period]; in snd_pmac_pcm_update()
476 stat = ld_le16(&cp->xfer_status); in snd_pmac_pcm_update()
489 /*printk(KERN_DEBUG "update frag %d\n", rec->cur_period);*/ in snd_pmac_pcm_update()
490 st_le16(&cp->xfer_status, 0); in snd_pmac_pcm_update()
491 st_le16(&cp->req_count, rec->period_size); in snd_pmac_pcm_update()
492 /*st_le16(&cp->res_count, 0);*/ in snd_pmac_pcm_update()
493 rec->cur_period++; in snd_pmac_pcm_update()
494 if (rec->cur_period >= rec->nperiods) { in snd_pmac_pcm_update()
495 rec->cur_period = 0; in snd_pmac_pcm_update()
498 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_update()
499 snd_pcm_period_elapsed(rec->substream); in snd_pmac_pcm_update()
500 spin_lock(&chip->reg_lock); in snd_pmac_pcm_update()
503 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_update()
554 struct snd_pmac *chip = rule->private;
555 struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]);
559 return -EINVAL;
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];
566 return snd_interval_list(hw_param_interval(params, rule->var),
573 struct snd_pmac *chip = rule->private;
574 struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]);
577 return -EINVAL;
579 rec->cur_formats);
583 static int snd_pmac_pcm_open(struct snd_pmac *chip, struct pmac_stream *rec, in snd_pmac_pcm_open() argument
586 struct snd_pcm_runtime *runtime = subs->runtime; in snd_pmac_pcm_open()
590 runtime->hw.rates = 0; in snd_pmac_pcm_open()
591 for (i = 0; i < chip->num_freqs; i++) in snd_pmac_pcm_open()
592 if (chip->freqs_ok & (1 << i)) in snd_pmac_pcm_open()
593 runtime->hw.rates |= in snd_pmac_pcm_open()
594 snd_pcm_rate_to_rate_bit(chip->freq_table[i]); in snd_pmac_pcm_open()
597 for (i = 0; i < chip->num_freqs; i++) { in snd_pmac_pcm_open()
598 if (chip->freqs_ok & (1 << i)) { in snd_pmac_pcm_open()
599 runtime->hw.rate_max = chip->freq_table[i]; in snd_pmac_pcm_open()
603 for (i = chip->num_freqs - 1; i >= 0; i--) { in snd_pmac_pcm_open()
604 if (chip->freqs_ok & (1 << i)) { in snd_pmac_pcm_open()
605 runtime->hw.rate_min = chip->freq_table[i]; in snd_pmac_pcm_open()
609 runtime->hw.formats = chip->formats_ok; in snd_pmac_pcm_open()
610 if (chip->can_capture) { in snd_pmac_pcm_open()
611 if (! chip->can_duplex) in snd_pmac_pcm_open()
612 runtime->hw.info |= SNDRV_PCM_INFO_HALF_DUPLEX; in snd_pmac_pcm_open()
613 runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; in snd_pmac_pcm_open()
615 runtime->private_data = rec; in snd_pmac_pcm_open()
616 rec->substream = subs; in snd_pmac_pcm_open()
620 snd_pmac_hw_rule_rate, chip, rec->stream, -1); in snd_pmac_pcm_open()
622 snd_pmac_hw_rule_format, chip, rec->stream, -1); in snd_pmac_pcm_open()
625 runtime->hw.periods_max = rec->cmd.size - 1; in snd_pmac_pcm_open()
627 /* constraints to fix choppy sound */ in snd_pmac_pcm_open()
632 static int snd_pmac_pcm_close(struct snd_pmac *chip, struct pmac_stream *rec, in snd_pmac_pcm_close() argument
639 astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); in snd_pmac_pcm_close()
641 return -EINVAL; in snd_pmac_pcm_close()
644 astr->cur_freqs = chip->freqs_ok; in snd_pmac_pcm_close()
645 astr->cur_formats = chip->formats_ok; in snd_pmac_pcm_close()
652 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_playback_open() local
654 subs->runtime->hw = snd_pmac_playback; in snd_pmac_playback_open()
655 return snd_pmac_pcm_open(chip, &chip->playback, subs); in snd_pmac_playback_open()
660 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_capture_open() local
662 subs->runtime->hw = snd_pmac_capture; in snd_pmac_capture_open()
663 return snd_pmac_pcm_open(chip, &chip->capture, subs); in snd_pmac_capture_open()
668 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_playback_close() local
670 return snd_pmac_pcm_close(chip, &chip->playback, subs); in snd_pmac_playback_close()
675 struct snd_pmac *chip = snd_pcm_substream_chip(subs); in snd_pmac_capture_close() local
677 return snd_pmac_pcm_close(chip, &chip->capture, subs); in snd_pmac_capture_close()
705 int __devinit snd_pmac_pcm_new(struct snd_pmac *chip) in snd_pmac_pcm_new() argument
711 if (! chip->can_capture) in snd_pmac_pcm_new()
713 err = snd_pcm_new(chip->card, chip->card->driver, 0, 1, num_captures, &pcm); in snd_pmac_pcm_new()
718 if (chip->can_capture) in snd_pmac_pcm_new()
721 pcm->private_data = chip; in snd_pmac_pcm_new()
722 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; in snd_pmac_pcm_new()
723 strcpy(pcm->name, chip->card->shortname); in snd_pmac_pcm_new()
724 chip->pcm = pcm; in snd_pmac_pcm_new()
726 chip->formats_ok = SNDRV_PCM_FMTBIT_S16_BE; in snd_pmac_pcm_new()
727 if (chip->can_byte_swap) in snd_pmac_pcm_new()
728 chip->formats_ok |= SNDRV_PCM_FMTBIT_S16_LE; in snd_pmac_pcm_new()
730 chip->playback.cur_formats = chip->formats_ok; in snd_pmac_pcm_new()
731 chip->capture.cur_formats = chip->formats_ok; in snd_pmac_pcm_new()
732 chip->playback.cur_freqs = chip->freqs_ok; in snd_pmac_pcm_new()
733 chip->capture.cur_freqs = chip->freqs_ok; in snd_pmac_pcm_new()
737 &chip->pdev->dev, in snd_pmac_pcm_new()
744 static void snd_pmac_dbdma_reset(struct snd_pmac *chip) in snd_pmac_dbdma_reset() argument
746 out_le32(&chip->playback.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16); in snd_pmac_dbdma_reset()
747 snd_pmac_wait_ack(&chip->playback); in snd_pmac_dbdma_reset()
748 out_le32(&chip->capture.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16); in snd_pmac_dbdma_reset()
749 snd_pmac_wait_ack(&chip->capture); in snd_pmac_dbdma_reset()
756 void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed) in snd_pmac_beep_dma_start() argument
758 struct pmac_stream *rec = &chip->playback; in snd_pmac_beep_dma_start()
761 st_le16(&chip->extra_dma.cmds->req_count, bytes); in snd_pmac_beep_dma_start()
762 st_le16(&chip->extra_dma.cmds->xfer_status, 0); in snd_pmac_beep_dma_start()
763 st_le32(&chip->extra_dma.cmds->cmd_dep, chip->extra_dma.addr); in snd_pmac_beep_dma_start()
764 st_le32(&chip->extra_dma.cmds->phy_addr, addr); in snd_pmac_beep_dma_start()
765 st_le16(&chip->extra_dma.cmds->command, OUTPUT_MORE + BR_ALWAYS); in snd_pmac_beep_dma_start()
766 out_le32(&chip->awacs->control, in snd_pmac_beep_dma_start()
767 (in_le32(&chip->awacs->control) & ~0x1f00) in snd_pmac_beep_dma_start()
769 out_le32(&chip->awacs->byteswap, 0); in snd_pmac_beep_dma_start()
770 snd_pmac_dma_set_command(rec, &chip->extra_dma); in snd_pmac_beep_dma_start()
774 void snd_pmac_beep_dma_stop(struct snd_pmac *chip) in snd_pmac_beep_dma_stop() argument
776 snd_pmac_dma_stop(&chip->playback); in snd_pmac_beep_dma_stop()
777 st_le16(&chip->extra_dma.cmds->command, DBDMA_STOP); in snd_pmac_beep_dma_stop()
778 snd_pmac_pcm_set_format(chip); /* reset format */ in snd_pmac_beep_dma_stop()
788 struct snd_pmac *chip = devid; in snd_pmac_tx_intr() local
789 snd_pmac_pcm_update(chip, &chip->playback); in snd_pmac_tx_intr()
797 struct snd_pmac *chip = devid; in snd_pmac_rx_intr() local
798 snd_pmac_pcm_update(chip, &chip->capture); in snd_pmac_rx_intr()
806 struct snd_pmac *chip = devid; in snd_pmac_ctrl_intr() local
807 int ctrl = in_le32(&chip->awacs->control); in snd_pmac_ctrl_intr()
812 if (chip->update_automute) in snd_pmac_ctrl_intr()
813 chip->update_automute(chip, 1); in snd_pmac_ctrl_intr()
816 int err = (in_le32(&chip->awacs->codec_stat) & MASK_ERRCODE) >> 16; in snd_pmac_ctrl_intr()
817 if (err && chip->model <= PMAC_SCREAMER) in snd_pmac_ctrl_intr()
820 /* Writing 1s to the CNTLERR and PORTCHG bits clears them... */ in snd_pmac_ctrl_intr()
821 out_le32(&chip->awacs->control, ctrl); in snd_pmac_ctrl_intr()
827 * a wrapper to feature call for compatibility
829 static void snd_pmac_sound_feature(struct snd_pmac *chip, int enable) in snd_pmac_sound_feature() argument
832 ppc_md.feature_call(PMAC_FTR_SOUND_CHIP_ENABLE, chip->node, 0, enable); in snd_pmac_sound_feature()
839 static int snd_pmac_free(struct snd_pmac *chip) in snd_pmac_free() argument
842 if (chip->initialized) { in snd_pmac_free()
843 snd_pmac_dbdma_reset(chip); in snd_pmac_free()
845 out_le32(&chip->awacs->control, in_le32(&chip->awacs->control) & 0xfff); in snd_pmac_free()
848 if (chip->node) in snd_pmac_free()
849 snd_pmac_sound_feature(chip, 0); in snd_pmac_free()
852 if (chip->mixer_free) in snd_pmac_free()
853 chip->mixer_free(chip); in snd_pmac_free()
855 snd_pmac_detach_beep(chip); in snd_pmac_free()
858 if (chip->irq >= 0) in snd_pmac_free()
859 free_irq(chip->irq, (void*)chip); in snd_pmac_free()
860 if (chip->tx_irq >= 0) in snd_pmac_free()
861 free_irq(chip->tx_irq, (void*)chip); in snd_pmac_free()
862 if (chip->rx_irq >= 0) in snd_pmac_free()
863 free_irq(chip->rx_irq, (void*)chip); in snd_pmac_free()
864 snd_pmac_dbdma_free(chip, &chip->playback.cmd); in snd_pmac_free()
865 snd_pmac_dbdma_free(chip, &chip->capture.cmd); in snd_pmac_free()
866 snd_pmac_dbdma_free(chip, &chip->extra_dma); in snd_pmac_free()
867 snd_pmac_dbdma_free(chip, &emergency_dbdma); in snd_pmac_free()
868 if (chip->macio_base) in snd_pmac_free()
869 iounmap(chip->macio_base); in snd_pmac_free()
870 if (chip->latch_base) in snd_pmac_free()
871 iounmap(chip->latch_base); in snd_pmac_free()
872 if (chip->awacs) in snd_pmac_free()
873 iounmap(chip->awacs); in snd_pmac_free()
874 if (chip->playback.dma) in snd_pmac_free()
875 iounmap(chip->playback.dma); in snd_pmac_free()
876 if (chip->capture.dma) in snd_pmac_free()
877 iounmap(chip->capture.dma); in snd_pmac_free()
879 if (chip->node) { in snd_pmac_free()
882 if (chip->requested & (1 << i)) in snd_pmac_free()
883 release_mem_region(chip->rsrc[i].start, in snd_pmac_free()
884 resource_size(&chip->rsrc[i])); in snd_pmac_free()
888 if (chip->pdev) in snd_pmac_free()
889 pci_dev_put(chip->pdev); in snd_pmac_free()
890 of_node_put(chip->node); in snd_pmac_free()
891 kfree(chip); in snd_pmac_free()
901 struct snd_pmac *chip = device->device_data; in snd_pmac_dev_free() local
902 return snd_pmac_free(chip); in snd_pmac_dev_free()
907 * check the machine support byteswap (little-endian)
910 static void __devinit detect_byte_swap(struct snd_pmac *chip) in detect_byte_swap() argument
914 /* if seems that Keylargo can't byte-swap */ in detect_byte_swap()
915 for (mio = chip->node->parent; mio; mio = mio->parent) { in detect_byte_swap()
916 if (strcmp(mio->name, "mac-io") == 0) { in detect_byte_swap()
918 chip->can_byte_swap = 0; in detect_byte_swap()
923 /* it seems the Pismo & iBook can't byte-swap in hardware. */ in detect_byte_swap()
926 chip->can_byte_swap = 0 ; in detect_byte_swap()
929 chip->can_duplex = 0; in detect_byte_swap()
934 * detect a sound chip
936 static int __devinit snd_pmac_detect(struct snd_pmac *chip) in snd_pmac_detect() argument
945 return -ENODEV; in snd_pmac_detect()
947 chip->subframe = 0; in snd_pmac_detect()
948 chip->revision = 0; in snd_pmac_detect()
949 chip->freqs_ok = 0xff; /* all ok */ in snd_pmac_detect()
950 chip->model = PMAC_AWACS; in snd_pmac_detect()
951 chip->can_byte_swap = 1; in snd_pmac_detect()
952 chip->can_duplex = 1; in snd_pmac_detect()
953 chip->can_capture = 1; in snd_pmac_detect()
954 chip->num_freqs = ARRAY_SIZE(awacs_freqs); in snd_pmac_detect()
955 chip->freq_table = awacs_freqs; in snd_pmac_detect()
956 chip->pdev = NULL; in snd_pmac_detect()
958 chip->control_mask = MASK_IEPC | MASK_IEE | 0x11; /* default */ in snd_pmac_detect()
963 chip->is_pbook_3400 = 1; in snd_pmac_detect()
966 chip->is_pbook_G3 = 1; in snd_pmac_detect()
967 chip->node = of_find_node_by_name(NULL, "awacs"); in snd_pmac_detect()
968 sound = of_node_get(chip->node); in snd_pmac_detect()
974 if (!chip->node) in snd_pmac_detect()
975 chip->node = of_find_node_by_name(NULL, "davbus"); in snd_pmac_detect()
977 * if we didn't find a davbus device, try 'i2s-a' since in snd_pmac_detect()
978 * this seems to be what iBooks have in snd_pmac_detect()
980 if (! chip->node) { in snd_pmac_detect()
981 chip->node = of_find_node_by_name(NULL, "i2s-a"); in snd_pmac_detect()
982 if (chip->node && chip->node->parent && in snd_pmac_detect()
983 chip->node->parent->parent) { in snd_pmac_detect()
984 if (of_device_is_compatible(chip->node->parent->parent, in snd_pmac_detect()
985 "K2-Keylargo")) in snd_pmac_detect()
986 chip->is_k2 = 1; in snd_pmac_detect()
989 if (! chip->node) in snd_pmac_detect()
990 return -ENODEV; in snd_pmac_detect()
994 while (sound && sound->parent != chip->node) in snd_pmac_detect()
998 of_node_put(chip->node); in snd_pmac_detect()
999 chip->node = NULL; in snd_pmac_detect()
1000 return -ENODEV; in snd_pmac_detect()
1002 prop = of_get_property(sound, "sub-frame", NULL); in snd_pmac_detect()
1004 chip->subframe = *prop; in snd_pmac_detect()
1005 prop = of_get_property(sound, "layout-id", NULL); in snd_pmac_detect()
1007 /* partly deprecate snd-powermac, for those machines in snd_pmac_detect()
1008 * that have a layout-id property for now */ in snd_pmac_detect()
1009 printk(KERN_INFO "snd-powermac no longer handles any " in snd_pmac_detect()
1010 "machines with a layout-id property " in snd_pmac_detect()
1011 "in the device-tree, use snd-aoa.\n"); in snd_pmac_detect()
1013 of_node_put(chip->node); in snd_pmac_detect()
1014 chip->node = NULL; in snd_pmac_detect()
1015 return -ENODEV; in snd_pmac_detect()
1019 chip->model = PMAC_SCREAMER; in snd_pmac_detect()
1020 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
1023 chip->model = PMAC_BURGUNDY; in snd_pmac_detect()
1024 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
1027 chip->model = PMAC_DACA; in snd_pmac_detect()
1028 chip->can_capture = 0; /* no capture */ in snd_pmac_detect()
1029 chip->can_duplex = 0; in snd_pmac_detect()
1030 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
1031 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
1034 chip->model = PMAC_TUMBLER; in snd_pmac_detect()
1035 chip->can_capture = of_machine_is_compatible("PowerMac4,2") in snd_pmac_detect()
1041 chip->can_duplex = 0; in snd_pmac_detect()
1042 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
1043 chip->num_freqs = ARRAY_SIZE(tumbler_freqs); in snd_pmac_detect()
1044 chip->freq_table = tumbler_freqs; in snd_pmac_detect()
1045 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
1048 chip->model = PMAC_SNAPPER; in snd_pmac_detect()
1049 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
1050 chip->num_freqs = ARRAY_SIZE(tumbler_freqs); in snd_pmac_detect()
1051 chip->freq_table = tumbler_freqs; in snd_pmac_detect()
1052 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
1054 prop = of_get_property(sound, "device-id", NULL); in snd_pmac_detect()
1056 chip->device_id = *prop; in snd_pmac_detect()
1058 chip->has_iic = (dn != NULL); in snd_pmac_detect()
1064 macio = macio_find(chip->node, macio_unknown); in snd_pmac_detect()
1066 printk(KERN_WARNING "snd-powermac: can't locate macio !\n"); in snd_pmac_detect()
1072 if (np && np == macio->of_node) { in snd_pmac_detect()
1073 chip->pdev = pdev; in snd_pmac_detect()
1078 if (chip->pdev == NULL) in snd_pmac_detect()
1079 printk(KERN_WARNING "snd-powermac: can't locate macio PCI" in snd_pmac_detect()
1082 detect_byte_swap(chip); in snd_pmac_detect()
1086 prop = of_get_property(sound, "sample-rates", &l); in snd_pmac_detect()
1088 prop = of_get_property(sound, "output-frame-rates", &l); in snd_pmac_detect()
1091 chip->freqs_ok = 0; in snd_pmac_detect()
1092 for (l /= sizeof(int); l > 0; --l) { in snd_pmac_detect()
1097 for (i = 0; i < chip->num_freqs; ++i) { in snd_pmac_detect()
1098 if (r == chip->freq_table[i]) { in snd_pmac_detect()
1099 chip->freqs_ok |= (1 << i); in snd_pmac_detect()
1106 chip->freqs_ok = 1; in snd_pmac_detect()
1115 * auto-mute
1120 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); in pmac_auto_mute_get() local
1121 ucontrol->value.integer.value[0] = chip->auto_mute; in pmac_auto_mute_get()
1128 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); in pmac_auto_mute_put() local
1129 if (ucontrol->value.integer.value[0] != chip->auto_mute) { in pmac_auto_mute_put()
1130 chip->auto_mute = !!ucontrol->value.integer.value[0]; in pmac_auto_mute_put()
1131 if (chip->update_automute) in pmac_auto_mute_put()
1132 chip->update_automute(chip, 1); in pmac_auto_mute_put()
1141 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); in pmac_hp_detect_get() local
1142 if (chip->detect_headphone) in pmac_hp_detect_get()
1143 ucontrol->value.integer.value[0] = chip->detect_headphone(chip); in pmac_hp_detect_get()
1145 ucontrol->value.integer.value[0] = 0; in pmac_hp_detect_get()
1164 int __devinit snd_pmac_add_automute(struct snd_pmac *chip) in snd_pmac_add_automute() argument
1167 chip->auto_mute = 1; in snd_pmac_add_automute()
1168 err = snd_ctl_add(chip->card, snd_ctl_new1(&auto_mute_controls[0], chip)); in snd_pmac_add_automute()
1170 printk(KERN_ERR "snd-powermac: Failed to add automute control\n"); in snd_pmac_add_automute()
1173 chip->hp_detect_ctl = snd_ctl_new1(&auto_mute_controls[1], chip); in snd_pmac_add_automute()
1174 return snd_ctl_add(chip->card, chip->hp_detect_ctl); in snd_pmac_add_automute()
1179 * create and detect a pmac chip record
1183 struct snd_pmac *chip; in snd_pmac_new() local
1194 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in snd_pmac_new()
1195 if (chip == NULL) in snd_pmac_new()
1196 return -ENOMEM; in snd_pmac_new()
1197 chip->card = card; in snd_pmac_new()
1199 spin_lock_init(&chip->reg_lock); in snd_pmac_new()
1200 chip->irq = chip->tx_irq = chip->rx_irq = -1; in snd_pmac_new()
1202 chip->playback.stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_pmac_new()
1203 chip->capture.stream = SNDRV_PCM_STREAM_CAPTURE; in snd_pmac_new()
1205 if ((err = snd_pmac_detect(chip)) < 0) in snd_pmac_new()
1208 if (snd_pmac_dbdma_alloc(chip, &chip->playback.cmd, PMAC_MAX_FRAGS + 1) < 0 || in snd_pmac_new()
1209 snd_pmac_dbdma_alloc(chip, &chip->capture.cmd, PMAC_MAX_FRAGS + 1) < 0 || in snd_pmac_new()
1210 snd_pmac_dbdma_alloc(chip, &chip->extra_dma, 2) < 0 || in snd_pmac_new()
1211 snd_pmac_dbdma_alloc(chip, &emergency_dbdma, 2) < 0) { in snd_pmac_new()
1212 err = -ENOMEM; in snd_pmac_new()
1216 np = chip->node; in snd_pmac_new()
1217 chip->requested = 0; in snd_pmac_new()
1218 if (chip->is_k2) { in snd_pmac_new()
1222 if (of_address_to_resource(np->parent, i, in snd_pmac_new()
1223 &chip->rsrc[i])) { in snd_pmac_new()
1226 err = -ENODEV; in snd_pmac_new()
1229 if (request_mem_region(chip->rsrc[i].start, in snd_pmac_new()
1230 resource_size(&chip->rsrc[i]), in snd_pmac_new()
1234 i, rnames[i], &chip->rsrc[i]); in snd_pmac_new()
1235 err = -ENODEV; in snd_pmac_new()
1238 chip->requested |= (1 << i); in snd_pmac_new()
1240 ctrl_addr = chip->rsrc[0].start; in snd_pmac_new()
1241 txdma_addr = chip->rsrc[1].start; in snd_pmac_new()
1248 &chip->rsrc[i])) { in snd_pmac_new()
1251 err = -ENODEV; in snd_pmac_new()
1254 if (request_mem_region(chip->rsrc[i].start, in snd_pmac_new()
1255 resource_size(&chip->rsrc[i]), in snd_pmac_new()
1259 i, rnames[i], &chip->rsrc[i]); in snd_pmac_new()
1260 err = -ENODEV; in snd_pmac_new()
1263 chip->requested |= (1 << i); in snd_pmac_new()
1265 ctrl_addr = chip->rsrc[0].start; in snd_pmac_new()
1266 txdma_addr = chip->rsrc[1].start; in snd_pmac_new()
1267 rxdma_addr = chip->rsrc[2].start; in snd_pmac_new()
1270 chip->awacs = ioremap(ctrl_addr, 0x1000); in snd_pmac_new()
1271 chip->playback.dma = ioremap(txdma_addr, 0x100); in snd_pmac_new()
1272 chip->capture.dma = ioremap(rxdma_addr, 0x100); in snd_pmac_new()
1273 if (chip->model <= PMAC_BURGUNDY) { in snd_pmac_new()
1276 "PMac", (void*)chip)) { in snd_pmac_new()
1277 snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", in snd_pmac_new()
1279 err = -EBUSY; in snd_pmac_new()
1282 chip->irq = irq; in snd_pmac_new()
1285 if (request_irq(irq, snd_pmac_tx_intr, 0, "PMac Output", (void*)chip)){ in snd_pmac_new()
1286 snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); in snd_pmac_new()
1287 err = -EBUSY; in snd_pmac_new()
1290 chip->tx_irq = irq; in snd_pmac_new()
1292 if (request_irq(irq, snd_pmac_rx_intr, 0, "PMac Input", (void*)chip)) { in snd_pmac_new()
1293 snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); in snd_pmac_new()
1294 err = -EBUSY; in snd_pmac_new()
1297 chip->rx_irq = irq; in snd_pmac_new()
1299 snd_pmac_sound_feature(chip, 1); in snd_pmac_new()
1302 if (chip->model <= PMAC_BURGUNDY) in snd_pmac_new()
1303 out_le32(&chip->awacs->control, chip->control_mask); in snd_pmac_new()
1306 an expansion-bay CD or sound from an internal modem in snd_pmac_new()
1307 or a PC-card modem. */ in snd_pmac_new()
1308 if (chip->is_pbook_3400) { in snd_pmac_new()
1309 /* Enable CD and PC-card sound inputs. */ in snd_pmac_new()
1311 * f301a000, + 0x10 to enable the expansion-bay in snd_pmac_new()
1312 * CD sound input, + 0x80 to enable the PC-card in snd_pmac_new()
1316 chip->latch_base = ioremap (0xf301a000, 0x1000); in snd_pmac_new()
1317 in_8(chip->latch_base + 0x190); in snd_pmac_new()
1318 } else if (chip->is_pbook_G3) { in snd_pmac_new()
1320 for (mio = chip->node->parent; mio; mio = mio->parent) { in snd_pmac_new()
1321 if (strcmp(mio->name, "mac-io") == 0) { in snd_pmac_new()
1324 chip->macio_base = in snd_pmac_new()
1330 /* The relevant bits for writing to this byte are 0x8f. in snd_pmac_new()
1335 * 4, 6, 8 - f enable the input from the modem. in snd_pmac_new()
1337 if (chip->macio_base) in snd_pmac_new()
1338 out_8(chip->macio_base + 0x37, 3); in snd_pmac_new()
1342 snd_pmac_dbdma_reset(chip); in snd_pmac_new()
1344 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) in snd_pmac_new()
1347 *chip_return = chip; in snd_pmac_new()
1351 snd_pmac_free(chip); in snd_pmac_new()
1363 * Save state when going to sleep, restore it afterwards.
1366 void snd_pmac_suspend(struct snd_pmac *chip) in snd_pmac_suspend() argument
1370 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); in snd_pmac_suspend()
1371 if (chip->suspend) in snd_pmac_suspend()
1372 chip->suspend(chip); in snd_pmac_suspend()
1373 snd_pcm_suspend_all(chip->pcm); in snd_pmac_suspend()
1374 spin_lock_irqsave(&chip->reg_lock, flags); in snd_pmac_suspend()
1375 snd_pmac_beep_stop(chip); in snd_pmac_suspend()
1376 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_pmac_suspend()
1377 if (chip->irq >= 0) in snd_pmac_suspend()
1378 disable_irq(chip->irq); in snd_pmac_suspend()
1379 if (chip->tx_irq >= 0) in snd_pmac_suspend()
1380 disable_irq(chip->tx_irq); in snd_pmac_suspend()
1381 if (chip->rx_irq >= 0) in snd_pmac_suspend()
1382 disable_irq(chip->rx_irq); in snd_pmac_suspend()
1383 snd_pmac_sound_feature(chip, 0); in snd_pmac_suspend()
1386 void snd_pmac_resume(struct snd_pmac *chip) in snd_pmac_resume() argument
1388 snd_pmac_sound_feature(chip, 1); in snd_pmac_resume()
1389 if (chip->resume) in snd_pmac_resume()
1390 chip->resume(chip); in snd_pmac_resume()
1392 if (chip->macio_base && chip->is_pbook_G3) in snd_pmac_resume()
1393 out_8(chip->macio_base + 0x37, 3); in snd_pmac_resume()
1394 else if (chip->is_pbook_3400) in snd_pmac_resume()
1395 in_8(chip->latch_base + 0x190); in snd_pmac_resume()
1397 snd_pmac_pcm_set_format(chip); in snd_pmac_resume()
1399 if (chip->irq >= 0) in snd_pmac_resume()
1400 enable_irq(chip->irq); in snd_pmac_resume()
1401 if (chip->tx_irq >= 0) in snd_pmac_resume()
1402 enable_irq(chip->tx_irq); in snd_pmac_resume()
1403 if (chip->rx_irq >= 0) in snd_pmac_resume()
1404 enable_irq(chip->rx_irq); in snd_pmac_resume()
1406 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); in snd_pmac_resume()