Lines Matching +full:irq +full:- +full:can +full:- +full:wake
1 // SPDX-License-Identifier: GPL-2.0-or-later
11 #include <asm/irq.h>
17 #include <linux/dma-mapping.h>
54 rec->space = dma_alloc_coherent(&chip->pdev->dev, rsize, in snd_pmac_dbdma_alloc()
55 &rec->dma_base, GFP_KERNEL); in snd_pmac_dbdma_alloc()
56 if (rec->space == NULL) in snd_pmac_dbdma_alloc()
57 return -ENOMEM; in snd_pmac_dbdma_alloc()
58 rec->size = size; in snd_pmac_dbdma_alloc()
59 memset(rec->space, 0, rsize); in snd_pmac_dbdma_alloc()
60 rec->cmds = (void __iomem *)DBDMA_ALIGN(rec->space); in snd_pmac_dbdma_alloc()
61 rec->addr = rec->dma_base + (unsigned long)((char *)rec->cmds - (char *)rec->space); in snd_pmac_dbdma_alloc()
68 if (rec->space) { in snd_pmac_dbdma_free()
69 unsigned int rsize = sizeof(struct dbdma_cmd) * (rec->size + 1); in snd_pmac_dbdma_free()
71 dma_free_coherent(&chip->pdev->dev, rsize, rec->space, rec->dma_base); in snd_pmac_dbdma_free()
88 ok = rec->cur_freqs; in snd_pmac_rate_index()
89 if (rate > chip->freq_table[0]) in snd_pmac_rate_index()
92 for (i = 0; i < chip->num_freqs; i++, ok >>= 1) { in snd_pmac_rate_index()
95 if (rate >= chip->freq_table[i]) in snd_pmac_rate_index()
117 return &chip->playback; in snd_pmac_get_stream()
119 return &chip->capture; in snd_pmac_get_stream()
133 while ((in_le32(&rec->dma->status) & RUN) && timeout-- > 0) in snd_pmac_wait_ack()
144 out_le32(&chip->awacs->control, chip->control_mask | (chip->rate_index << 8)); in snd_pmac_pcm_set_format()
145 out_le32(&chip->awacs->byteswap, chip->format == SNDRV_PCM_FORMAT_S16_LE ? 1 : 0); in snd_pmac_pcm_set_format()
146 if (chip->set_format) in snd_pmac_pcm_set_format()
147 chip->set_format(chip); in snd_pmac_pcm_set_format()
155 out_le32(&rec->dma->control, (RUN|WAKE|FLUSH|PAUSE) << 16); in snd_pmac_dma_stop()
164 out_le32(&rec->dma->cmdptr, cmd->addr); in snd_pmac_dma_set_command()
172 out_le32(&rec->dma->control, status | (status << 16)); in snd_pmac_dma_run()
183 struct snd_pcm_runtime *runtime = subs->runtime; in snd_pmac_pcm_prepare()
188 rec->dma_size = snd_pcm_lib_buffer_bytes(subs); in snd_pmac_pcm_prepare()
189 rec->period_size = snd_pcm_lib_period_bytes(subs); in snd_pmac_pcm_prepare()
190 rec->nperiods = rec->dma_size / rec->period_size; in snd_pmac_pcm_prepare()
191 rec->cur_period = 0; in snd_pmac_pcm_prepare()
192 rate_index = snd_pmac_rate_index(chip, rec, runtime->rate); in snd_pmac_pcm_prepare()
195 astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); in snd_pmac_pcm_prepare()
197 return -EINVAL; in snd_pmac_pcm_prepare()
198 astr->cur_freqs = 1 << rate_index; in snd_pmac_pcm_prepare()
199 astr->cur_formats = 1 << runtime->format; in snd_pmac_pcm_prepare()
200 chip->rate_index = rate_index; in snd_pmac_pcm_prepare()
201 chip->format = runtime->format; in snd_pmac_pcm_prepare()
207 * captured on iBook2's about every third time. -ReneR in snd_pmac_pcm_prepare()
209 spin_lock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
211 chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP); in snd_pmac_pcm_prepare()
212 snd_pmac_dma_set_command(rec, &chip->extra_dma); in snd_pmac_pcm_prepare()
214 spin_unlock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
216 spin_lock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
220 offset = runtime->dma_addr; in snd_pmac_pcm_prepare()
221 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) { in snd_pmac_pcm_prepare()
222 cp->phy_addr = cpu_to_le32(offset); in snd_pmac_pcm_prepare()
223 cp->req_count = cpu_to_le16(rec->period_size); in snd_pmac_pcm_prepare()
224 /*cp->res_count = cpu_to_le16(0);*/ in snd_pmac_pcm_prepare()
225 cp->xfer_status = cpu_to_le16(0); in snd_pmac_pcm_prepare()
226 offset += rec->period_size; in snd_pmac_pcm_prepare()
229 cp->command = cpu_to_le16(DBDMA_NOP | BR_ALWAYS); in snd_pmac_pcm_prepare()
230 cp->cmd_dep = cpu_to_le32(rec->cmd.addr); in snd_pmac_pcm_prepare()
233 snd_pmac_dma_set_command(rec, &rec->cmd); in snd_pmac_pcm_prepare()
234 spin_unlock_irq(&chip->reg_lock); in snd_pmac_pcm_prepare()
252 if (rec->running) in snd_pmac_pcm_trigger()
253 return -EBUSY; in snd_pmac_pcm_trigger()
254 command = (subs->stream == SNDRV_PCM_STREAM_PLAYBACK ? in snd_pmac_pcm_trigger()
256 spin_lock(&chip->reg_lock); in snd_pmac_pcm_trigger()
259 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) in snd_pmac_pcm_trigger()
260 out_le16(&cp->command, command); in snd_pmac_pcm_trigger()
261 snd_pmac_dma_set_command(rec, &rec->cmd); in snd_pmac_pcm_trigger()
262 (void)in_le32(&rec->dma->status); in snd_pmac_pcm_trigger()
263 snd_pmac_dma_run(rec, RUN|WAKE); in snd_pmac_pcm_trigger()
264 rec->running = 1; in snd_pmac_pcm_trigger()
265 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_trigger()
270 spin_lock(&chip->reg_lock); in snd_pmac_pcm_trigger()
271 rec->running = 0; in snd_pmac_pcm_trigger()
274 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) in snd_pmac_pcm_trigger()
275 out_le16(&cp->command, DBDMA_STOP); in snd_pmac_pcm_trigger()
276 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_trigger()
280 return -EINVAL; in snd_pmac_pcm_trigger()
296 #if 1 /* hmm.. how can we get the current dma pointer?? */ in snd_pmac_pcm_pointer()
298 volatile struct dbdma_cmd __iomem *cp = &rec->cmd.cmds[rec->cur_period]; in snd_pmac_pcm_pointer()
299 stat = le16_to_cpu(cp->xfer_status); in snd_pmac_pcm_pointer()
301 count = in_le16(&cp->res_count); in snd_pmac_pcm_pointer()
303 count = rec->period_size - count; in snd_pmac_pcm_pointer()
306 count += rec->cur_period * rec->period_size; in snd_pmac_pcm_pointer()
308 return bytes_to_frames(subs->runtime, count); in snd_pmac_pcm_pointer()
318 return snd_pmac_pcm_prepare(chip, &chip->playback, subs); in snd_pmac_playback_prepare()
325 return snd_pmac_pcm_trigger(chip, &chip->playback, subs, cmd); in snd_pmac_playback_trigger()
331 return snd_pmac_pcm_pointer(chip, &chip->playback, subs); in snd_pmac_playback_pointer()
342 return snd_pmac_pcm_prepare(chip, &chip->capture, subs); in snd_pmac_capture_prepare()
349 return snd_pmac_pcm_trigger(chip, &chip->capture, subs, cmd); in snd_pmac_capture_trigger()
355 return snd_pmac_pcm_pointer(chip, &chip->capture, subs); in snd_pmac_capture_pointer()
361 * if the TX status comes up "DEAD" - reported on some Power Computing machines
362 * we need to re-start the dbdma - but from a different physical start address
364 * with the normal dbdma_cmd blocks - we would have to re-write the buffer start
365 * addresses each time. So, we will keep a single dbdma_cmd block which can be
371 * On any subsequent DEAD result we just do the bump-ups (we know that we are
374 * xfers when the number of residual bytes gets below a certain value - I can
375 * see that this might cause a loop-forever if a too small transfer causes
376 * DEAD status. However this is a TODO for now - we'll see what gets reported.
387 /* printk(KERN_WARNING "snd-powermac: DMA died - patching it up!\n"); */ in snd_pmac_pcm_dead_xfer()
391 (void)in_le32(&rec->dma->status); in snd_pmac_pcm_dead_xfer()
392 out_le32(&rec->dma->control, (RUN|PAUSE|FLUSH|WAKE) << 16); in snd_pmac_pcm_dead_xfer()
398 cp->xfer_status = cpu_to_le16(0); in snd_pmac_pcm_dead_xfer()
399 cp->req_count = cpu_to_le16(rec->period_size); in snd_pmac_pcm_dead_xfer()
405 req = le16_to_cpu(cp->req_count); in snd_pmac_pcm_dead_xfer()
406 res = le16_to_cpu(cp->res_count); in snd_pmac_pcm_dead_xfer()
407 phy = le32_to_cpu(cp->phy_addr); in snd_pmac_pcm_dead_xfer()
408 phy += (req - res); in snd_pmac_pcm_dead_xfer()
409 cp->req_count = cpu_to_le16(res); in snd_pmac_pcm_dead_xfer()
410 cp->res_count = cpu_to_le16(0); in snd_pmac_pcm_dead_xfer()
411 cp->xfer_status = cpu_to_le16(0); in snd_pmac_pcm_dead_xfer()
412 cp->phy_addr = cpu_to_le32(phy); in snd_pmac_pcm_dead_xfer()
414 cp->cmd_dep = cpu_to_le32(rec->cmd.addr in snd_pmac_pcm_dead_xfer()
415 + sizeof(struct dbdma_cmd)*((rec->cur_period+1)%rec->nperiods)); in snd_pmac_pcm_dead_xfer()
417 cp->command = cpu_to_le16(OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS); in snd_pmac_pcm_dead_xfer()
420 out_le32(&rec->dma->cmdptr, emergency_dbdma.addr); in snd_pmac_pcm_dead_xfer()
422 /* we must re-start the controller */ in snd_pmac_pcm_dead_xfer()
423 (void)in_le32(&rec->dma->status); in snd_pmac_pcm_dead_xfer()
425 out_le32(&rec->dma->control, ((RUN|WAKE) << 16) + (RUN|WAKE)); in snd_pmac_pcm_dead_xfer()
437 spin_lock(&chip->reg_lock); in snd_pmac_pcm_update()
438 if (rec->running) { in snd_pmac_pcm_update()
439 for (c = 0; c < rec->nperiods; c++) { /* at most all fragments */ in snd_pmac_pcm_update()
444 cp = &rec->cmd.cmds[rec->cur_period]; in snd_pmac_pcm_update()
446 stat = le16_to_cpu(cp->xfer_status); in snd_pmac_pcm_update()
459 /*printk(KERN_DEBUG "update frag %d\n", rec->cur_period);*/ in snd_pmac_pcm_update()
460 cp->xfer_status = cpu_to_le16(0); in snd_pmac_pcm_update()
461 cp->req_count = cpu_to_le16(rec->period_size); in snd_pmac_pcm_update()
462 /*cp->res_count = cpu_to_le16(0);*/ in snd_pmac_pcm_update()
463 rec->cur_period++; in snd_pmac_pcm_update()
464 if (rec->cur_period >= rec->nperiods) { in snd_pmac_pcm_update()
465 rec->cur_period = 0; in snd_pmac_pcm_update()
468 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_update()
469 snd_pcm_period_elapsed(rec->substream); in snd_pmac_pcm_update()
470 spin_lock(&chip->reg_lock); in snd_pmac_pcm_update()
473 spin_unlock(&chip->reg_lock); in snd_pmac_pcm_update()
524 struct snd_pmac *chip = rule->private;
525 struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]);
529 return -EINVAL;
531 for (i = chip->num_freqs - 1; i >= 0; i--) {
532 if (rec->cur_freqs & (1 << i))
533 freq_table[num_freqs++] = chip->freq_table[i];
536 return snd_interval_list(hw_param_interval(params, rule->var),
543 struct snd_pmac *chip = rule->private;
544 struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]);
547 return -EINVAL;
549 rec->cur_formats);
556 struct snd_pcm_runtime *runtime = subs->runtime; in snd_pmac_pcm_open()
560 runtime->hw.rates = 0; in snd_pmac_pcm_open()
561 for (i = 0; i < chip->num_freqs; i++) in snd_pmac_pcm_open()
562 if (chip->freqs_ok & (1 << i)) in snd_pmac_pcm_open()
563 runtime->hw.rates |= in snd_pmac_pcm_open()
564 snd_pcm_rate_to_rate_bit(chip->freq_table[i]); in snd_pmac_pcm_open()
567 for (i = 0; i < chip->num_freqs; i++) { in snd_pmac_pcm_open()
568 if (chip->freqs_ok & (1 << i)) { in snd_pmac_pcm_open()
569 runtime->hw.rate_max = chip->freq_table[i]; in snd_pmac_pcm_open()
573 for (i = chip->num_freqs - 1; i >= 0; i--) { in snd_pmac_pcm_open()
574 if (chip->freqs_ok & (1 << i)) { in snd_pmac_pcm_open()
575 runtime->hw.rate_min = chip->freq_table[i]; in snd_pmac_pcm_open()
579 runtime->hw.formats = chip->formats_ok; in snd_pmac_pcm_open()
580 if (chip->can_capture) { in snd_pmac_pcm_open()
581 if (! chip->can_duplex) in snd_pmac_pcm_open()
582 runtime->hw.info |= SNDRV_PCM_INFO_HALF_DUPLEX; in snd_pmac_pcm_open()
583 runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; in snd_pmac_pcm_open()
585 runtime->private_data = rec; in snd_pmac_pcm_open()
586 rec->substream = subs; in snd_pmac_pcm_open()
590 snd_pmac_hw_rule_rate, chip, rec->stream, -1); in snd_pmac_pcm_open()
592 snd_pmac_hw_rule_format, chip, rec->stream, -1); in snd_pmac_pcm_open()
595 runtime->hw.periods_max = rec->cmd.size - 1; in snd_pmac_pcm_open()
609 astr = snd_pmac_get_stream(chip, another_stream(rec->stream)); in snd_pmac_pcm_close()
611 return -EINVAL; in snd_pmac_pcm_close()
614 astr->cur_freqs = chip->freqs_ok; in snd_pmac_pcm_close()
615 astr->cur_formats = chip->formats_ok; in snd_pmac_pcm_close()
624 subs->runtime->hw = snd_pmac_playback; in snd_pmac_playback_open()
625 return snd_pmac_pcm_open(chip, &chip->playback, subs); in snd_pmac_playback_open()
632 subs->runtime->hw = snd_pmac_capture; in snd_pmac_capture_open()
633 return snd_pmac_pcm_open(chip, &chip->capture, subs); in snd_pmac_capture_open()
640 return snd_pmac_pcm_close(chip, &chip->playback, subs); in snd_pmac_playback_close()
647 return snd_pmac_pcm_close(chip, &chip->capture, subs); in snd_pmac_capture_close()
675 if (! chip->can_capture) in snd_pmac_pcm_new()
677 err = snd_pcm_new(chip->card, chip->card->driver, 0, 1, num_captures, &pcm); in snd_pmac_pcm_new()
682 if (chip->can_capture) in snd_pmac_pcm_new()
685 pcm->private_data = chip; in snd_pmac_pcm_new()
686 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; in snd_pmac_pcm_new()
687 strcpy(pcm->name, chip->card->shortname); in snd_pmac_pcm_new()
688 chip->pcm = pcm; in snd_pmac_pcm_new()
690 chip->formats_ok = SNDRV_PCM_FMTBIT_S16_BE; in snd_pmac_pcm_new()
691 if (chip->can_byte_swap) in snd_pmac_pcm_new()
692 chip->formats_ok |= SNDRV_PCM_FMTBIT_S16_LE; in snd_pmac_pcm_new()
694 chip->playback.cur_formats = chip->formats_ok; in snd_pmac_pcm_new()
695 chip->capture.cur_formats = chip->formats_ok; in snd_pmac_pcm_new()
696 chip->playback.cur_freqs = chip->freqs_ok; in snd_pmac_pcm_new()
697 chip->capture.cur_freqs = chip->freqs_ok; in snd_pmac_pcm_new()
701 &chip->pdev->dev, in snd_pmac_pcm_new()
710 out_le32(&chip->playback.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16); in snd_pmac_dbdma_reset()
711 snd_pmac_wait_ack(&chip->playback); in snd_pmac_dbdma_reset()
712 out_le32(&chip->capture.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16); in snd_pmac_dbdma_reset()
713 snd_pmac_wait_ack(&chip->capture); in snd_pmac_dbdma_reset()
722 struct pmac_stream *rec = &chip->playback; in snd_pmac_beep_dma_start()
725 chip->extra_dma.cmds->req_count = cpu_to_le16(bytes); in snd_pmac_beep_dma_start()
726 chip->extra_dma.cmds->xfer_status = cpu_to_le16(0); in snd_pmac_beep_dma_start()
727 chip->extra_dma.cmds->cmd_dep = cpu_to_le32(chip->extra_dma.addr); in snd_pmac_beep_dma_start()
728 chip->extra_dma.cmds->phy_addr = cpu_to_le32(addr); in snd_pmac_beep_dma_start()
729 chip->extra_dma.cmds->command = cpu_to_le16(OUTPUT_MORE | BR_ALWAYS); in snd_pmac_beep_dma_start()
730 out_le32(&chip->awacs->control, in snd_pmac_beep_dma_start()
731 (in_le32(&chip->awacs->control) & ~0x1f00) in snd_pmac_beep_dma_start()
733 out_le32(&chip->awacs->byteswap, 0); in snd_pmac_beep_dma_start()
734 snd_pmac_dma_set_command(rec, &chip->extra_dma); in snd_pmac_beep_dma_start()
740 snd_pmac_dma_stop(&chip->playback); in snd_pmac_beep_dma_stop()
741 chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP); in snd_pmac_beep_dma_stop()
750 snd_pmac_tx_intr(int irq, void *devid) in snd_pmac_tx_intr() argument
753 snd_pmac_pcm_update(chip, &chip->playback); in snd_pmac_tx_intr()
759 snd_pmac_rx_intr(int irq, void *devid) in snd_pmac_rx_intr() argument
762 snd_pmac_pcm_update(chip, &chip->capture); in snd_pmac_rx_intr()
768 snd_pmac_ctrl_intr(int irq, void *devid) in snd_pmac_ctrl_intr() argument
771 int ctrl = in_le32(&chip->awacs->control); in snd_pmac_ctrl_intr()
776 if (chip->update_automute) in snd_pmac_ctrl_intr()
777 chip->update_automute(chip, 1); in snd_pmac_ctrl_intr()
780 int err = (in_le32(&chip->awacs->codec_stat) & MASK_ERRCODE) >> 16; in snd_pmac_ctrl_intr()
781 if (err && chip->model <= PMAC_SCREAMER) in snd_pmac_ctrl_intr()
785 out_le32(&chip->awacs->control, ctrl); in snd_pmac_ctrl_intr()
796 ppc_md.feature_call(PMAC_FTR_SOUND_CHIP_ENABLE, chip->node, 0, enable); in snd_pmac_sound_feature()
806 if (chip->initialized) { in snd_pmac_free()
809 out_le32(&chip->awacs->control, in_le32(&chip->awacs->control) & 0xfff); in snd_pmac_free()
812 if (chip->node) in snd_pmac_free()
816 if (chip->mixer_free) in snd_pmac_free()
817 chip->mixer_free(chip); in snd_pmac_free()
822 if (chip->irq >= 0) in snd_pmac_free()
823 free_irq(chip->irq, (void*)chip); in snd_pmac_free()
824 if (chip->tx_irq >= 0) in snd_pmac_free()
825 free_irq(chip->tx_irq, (void*)chip); in snd_pmac_free()
826 if (chip->rx_irq >= 0) in snd_pmac_free()
827 free_irq(chip->rx_irq, (void*)chip); in snd_pmac_free()
828 snd_pmac_dbdma_free(chip, &chip->playback.cmd); in snd_pmac_free()
829 snd_pmac_dbdma_free(chip, &chip->capture.cmd); in snd_pmac_free()
830 snd_pmac_dbdma_free(chip, &chip->extra_dma); in snd_pmac_free()
832 iounmap(chip->macio_base); in snd_pmac_free()
833 iounmap(chip->latch_base); in snd_pmac_free()
834 iounmap(chip->awacs); in snd_pmac_free()
835 iounmap(chip->playback.dma); in snd_pmac_free()
836 iounmap(chip->capture.dma); in snd_pmac_free()
838 if (chip->node) { in snd_pmac_free()
841 if (chip->requested & (1 << i)) in snd_pmac_free()
842 release_mem_region(chip->rsrc[i].start, in snd_pmac_free()
843 resource_size(&chip->rsrc[i])); in snd_pmac_free()
847 pci_dev_put(chip->pdev); in snd_pmac_free()
848 of_node_put(chip->node); in snd_pmac_free()
859 struct snd_pmac *chip = device->device_data; in snd_pmac_dev_free()
865 * check the machine support byteswap (little-endian)
872 /* if seems that Keylargo can't byte-swap */ in detect_byte_swap()
873 for (mio = chip->node->parent; mio; mio = mio->parent) { in detect_byte_swap()
874 if (of_node_name_eq(mio, "mac-io")) { in detect_byte_swap()
876 chip->can_byte_swap = 0; in detect_byte_swap()
881 /* it seems the Pismo & iBook can't byte-swap in hardware. */ in detect_byte_swap()
884 chip->can_byte_swap = 0 ; in detect_byte_swap()
887 chip->can_duplex = 0; in detect_byte_swap()
903 return -ENODEV; in snd_pmac_detect()
905 chip->subframe = 0; in snd_pmac_detect()
906 chip->revision = 0; in snd_pmac_detect()
907 chip->freqs_ok = 0xff; /* all ok */ in snd_pmac_detect()
908 chip->model = PMAC_AWACS; in snd_pmac_detect()
909 chip->can_byte_swap = 1; in snd_pmac_detect()
910 chip->can_duplex = 1; in snd_pmac_detect()
911 chip->can_capture = 1; in snd_pmac_detect()
912 chip->num_freqs = ARRAY_SIZE(awacs_freqs); in snd_pmac_detect()
913 chip->freq_table = awacs_freqs; in snd_pmac_detect()
914 chip->pdev = NULL; in snd_pmac_detect()
916 chip->control_mask = MASK_IEPC | MASK_IEE | 0x11; /* default */ in snd_pmac_detect()
921 chip->is_pbook_3400 = 1; in snd_pmac_detect()
924 chip->is_pbook_G3 = 1; in snd_pmac_detect()
925 chip->node = of_find_node_by_name(NULL, "awacs"); in snd_pmac_detect()
926 sound = of_node_get(chip->node); in snd_pmac_detect()
932 if (!chip->node) in snd_pmac_detect()
933 chip->node = of_find_node_by_name(NULL, "davbus"); in snd_pmac_detect()
935 * if we didn't find a davbus device, try 'i2s-a' since in snd_pmac_detect()
938 if (! chip->node) { in snd_pmac_detect()
939 chip->node = of_find_node_by_name(NULL, "i2s-a"); in snd_pmac_detect()
940 if (chip->node && chip->node->parent && in snd_pmac_detect()
941 chip->node->parent->parent) { in snd_pmac_detect()
942 if (of_device_is_compatible(chip->node->parent->parent, in snd_pmac_detect()
943 "K2-Keylargo")) in snd_pmac_detect()
944 chip->is_k2 = 1; in snd_pmac_detect()
947 if (! chip->node) in snd_pmac_detect()
948 return -ENODEV; in snd_pmac_detect()
952 if (sound->parent == chip->node) in snd_pmac_detect()
956 of_node_put(chip->node); in snd_pmac_detect()
957 chip->node = NULL; in snd_pmac_detect()
958 return -ENODEV; in snd_pmac_detect()
960 prop = of_get_property(sound, "sub-frame", NULL); in snd_pmac_detect()
962 chip->subframe = *prop; in snd_pmac_detect()
963 prop = of_get_property(sound, "layout-id", NULL); in snd_pmac_detect()
965 /* partly deprecate snd-powermac, for those machines in snd_pmac_detect()
966 * that have a layout-id property for now */ in snd_pmac_detect()
967 printk(KERN_INFO "snd-powermac no longer handles any " in snd_pmac_detect()
968 "machines with a layout-id property " in snd_pmac_detect()
969 "in the device-tree, use snd-aoa.\n"); in snd_pmac_detect()
971 of_node_put(chip->node); in snd_pmac_detect()
972 chip->node = NULL; in snd_pmac_detect()
973 return -ENODEV; in snd_pmac_detect()
977 chip->model = PMAC_SCREAMER; in snd_pmac_detect()
978 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
981 chip->model = PMAC_BURGUNDY; in snd_pmac_detect()
982 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
985 chip->model = PMAC_DACA; in snd_pmac_detect()
986 chip->can_capture = 0; /* no capture */ in snd_pmac_detect()
987 chip->can_duplex = 0; in snd_pmac_detect()
988 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
989 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
992 chip->model = PMAC_TUMBLER; in snd_pmac_detect()
993 chip->can_capture = of_machine_is_compatible("PowerMac4,2") in snd_pmac_detect()
999 chip->can_duplex = 0; in snd_pmac_detect()
1000 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
1001 chip->num_freqs = ARRAY_SIZE(tumbler_freqs); in snd_pmac_detect()
1002 chip->freq_table = tumbler_freqs; in snd_pmac_detect()
1003 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
1006 chip->model = PMAC_SNAPPER; in snd_pmac_detect()
1007 // chip->can_byte_swap = 0; /* FIXME: check this */ in snd_pmac_detect()
1008 chip->num_freqs = ARRAY_SIZE(tumbler_freqs); in snd_pmac_detect()
1009 chip->freq_table = tumbler_freqs; in snd_pmac_detect()
1010 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ in snd_pmac_detect()
1012 prop = of_get_property(sound, "device-id", NULL); in snd_pmac_detect()
1014 chip->device_id = *prop; in snd_pmac_detect()
1016 chip->has_iic = (dn != NULL); in snd_pmac_detect()
1022 macio = macio_find(chip->node, macio_unknown); in snd_pmac_detect()
1024 printk(KERN_WARNING "snd-powermac: can't locate macio !\n"); in snd_pmac_detect()
1030 if (np && np == macio->of_node) { in snd_pmac_detect()
1031 chip->pdev = pdev; in snd_pmac_detect()
1036 if (chip->pdev == NULL) in snd_pmac_detect()
1037 printk(KERN_WARNING "snd-powermac: can't locate macio PCI" in snd_pmac_detect()
1044 prop = of_get_property(sound, "sample-rates", &l); in snd_pmac_detect()
1046 prop = of_get_property(sound, "output-frame-rates", &l); in snd_pmac_detect()
1049 chip->freqs_ok = 0; in snd_pmac_detect()
1050 for (l /= sizeof(int); l > 0; --l) { in snd_pmac_detect()
1055 for (i = 0; i < chip->num_freqs; ++i) { in snd_pmac_detect()
1056 if (r == chip->freq_table[i]) { in snd_pmac_detect()
1057 chip->freqs_ok |= (1 << i); in snd_pmac_detect()
1064 chip->freqs_ok = 1; in snd_pmac_detect()
1073 * auto-mute
1079 ucontrol->value.integer.value[0] = chip->auto_mute; in pmac_auto_mute_get()
1087 if (ucontrol->value.integer.value[0] != chip->auto_mute) { in pmac_auto_mute_put()
1088 chip->auto_mute = !!ucontrol->value.integer.value[0]; in pmac_auto_mute_put()
1089 if (chip->update_automute) in pmac_auto_mute_put()
1090 chip->update_automute(chip, 1); in pmac_auto_mute_put()
1100 if (chip->detect_headphone) in pmac_hp_detect_get()
1101 ucontrol->value.integer.value[0] = chip->detect_headphone(chip); in pmac_hp_detect_get()
1103 ucontrol->value.integer.value[0] = 0; in pmac_hp_detect_get()
1125 chip->auto_mute = 1; in snd_pmac_add_automute()
1126 err = snd_ctl_add(chip->card, snd_ctl_new1(&auto_mute_controls[0], chip)); in snd_pmac_add_automute()
1128 printk(KERN_ERR "snd-powermac: Failed to add automute control\n"); in snd_pmac_add_automute()
1131 chip->hp_detect_ctl = snd_ctl_new1(&auto_mute_controls[1], chip); in snd_pmac_add_automute()
1132 return snd_ctl_add(chip->card, chip->hp_detect_ctl); in snd_pmac_add_automute()
1144 unsigned int irq; in snd_pmac_new() local
1154 return -ENOMEM; in snd_pmac_new()
1155 chip->card = card; in snd_pmac_new()
1157 spin_lock_init(&chip->reg_lock); in snd_pmac_new()
1158 chip->irq = chip->tx_irq = chip->rx_irq = -1; in snd_pmac_new()
1160 chip->playback.stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_pmac_new()
1161 chip->capture.stream = SNDRV_PCM_STREAM_CAPTURE; in snd_pmac_new()
1167 if (snd_pmac_dbdma_alloc(chip, &chip->playback.cmd, PMAC_MAX_FRAGS + 1) < 0 || in snd_pmac_new()
1168 snd_pmac_dbdma_alloc(chip, &chip->capture.cmd, PMAC_MAX_FRAGS + 1) < 0 || in snd_pmac_new()
1169 snd_pmac_dbdma_alloc(chip, &chip->extra_dma, 2) < 0 || in snd_pmac_new()
1171 err = -ENOMEM; in snd_pmac_new()
1175 np = chip->node; in snd_pmac_new()
1176 chip->requested = 0; in snd_pmac_new()
1177 if (chip->is_k2) { in snd_pmac_new()
1181 if (of_address_to_resource(np->parent, i, in snd_pmac_new()
1182 &chip->rsrc[i])) { in snd_pmac_new()
1183 printk(KERN_ERR "snd: can't translate rsrc " in snd_pmac_new()
1185 err = -ENODEV; in snd_pmac_new()
1188 if (request_mem_region(chip->rsrc[i].start, in snd_pmac_new()
1189 resource_size(&chip->rsrc[i]), in snd_pmac_new()
1191 printk(KERN_ERR "snd: can't request rsrc " in snd_pmac_new()
1193 i, rnames[i], &chip->rsrc[i]); in snd_pmac_new()
1194 err = -ENODEV; in snd_pmac_new()
1197 chip->requested |= (1 << i); in snd_pmac_new()
1199 ctrl_addr = chip->rsrc[0].start; in snd_pmac_new()
1200 txdma_addr = chip->rsrc[1].start; in snd_pmac_new()
1207 &chip->rsrc[i])) { in snd_pmac_new()
1208 printk(KERN_ERR "snd: can't translate rsrc " in snd_pmac_new()
1210 err = -ENODEV; in snd_pmac_new()
1213 if (request_mem_region(chip->rsrc[i].start, in snd_pmac_new()
1214 resource_size(&chip->rsrc[i]), in snd_pmac_new()
1216 printk(KERN_ERR "snd: can't request rsrc " in snd_pmac_new()
1218 i, rnames[i], &chip->rsrc[i]); in snd_pmac_new()
1219 err = -ENODEV; in snd_pmac_new()
1222 chip->requested |= (1 << i); in snd_pmac_new()
1224 ctrl_addr = chip->rsrc[0].start; in snd_pmac_new()
1225 txdma_addr = chip->rsrc[1].start; in snd_pmac_new()
1226 rxdma_addr = chip->rsrc[2].start; in snd_pmac_new()
1229 chip->awacs = ioremap(ctrl_addr, 0x1000); in snd_pmac_new()
1230 chip->playback.dma = ioremap(txdma_addr, 0x100); in snd_pmac_new()
1231 chip->capture.dma = ioremap(rxdma_addr, 0x100); in snd_pmac_new()
1232 if (chip->model <= PMAC_BURGUNDY) { in snd_pmac_new()
1233 irq = irq_of_parse_and_map(np, 0); in snd_pmac_new()
1234 if (request_irq(irq, snd_pmac_ctrl_intr, 0, in snd_pmac_new()
1236 snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", in snd_pmac_new()
1237 irq); in snd_pmac_new()
1238 err = -EBUSY; in snd_pmac_new()
1241 chip->irq = irq; in snd_pmac_new()
1243 irq = irq_of_parse_and_map(np, 1); in snd_pmac_new()
1244 if (request_irq(irq, snd_pmac_tx_intr, 0, "PMac Output", (void*)chip)){ in snd_pmac_new()
1245 snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); in snd_pmac_new()
1246 err = -EBUSY; in snd_pmac_new()
1249 chip->tx_irq = irq; in snd_pmac_new()
1250 irq = irq_of_parse_and_map(np, 2); in snd_pmac_new()
1251 if (request_irq(irq, snd_pmac_rx_intr, 0, "PMac Input", (void*)chip)) { in snd_pmac_new()
1252 snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); in snd_pmac_new()
1253 err = -EBUSY; in snd_pmac_new()
1256 chip->rx_irq = irq; in snd_pmac_new()
1261 if (chip->model <= PMAC_BURGUNDY) in snd_pmac_new()
1262 out_le32(&chip->awacs->control, chip->control_mask); in snd_pmac_new()
1265 an expansion-bay CD or sound from an internal modem in snd_pmac_new()
1266 or a PC-card modem. */ in snd_pmac_new()
1267 if (chip->is_pbook_3400) { in snd_pmac_new()
1268 /* Enable CD and PC-card sound inputs. */ in snd_pmac_new()
1270 * f301a000, + 0x10 to enable the expansion-bay in snd_pmac_new()
1271 * CD sound input, + 0x80 to enable the PC-card in snd_pmac_new()
1275 chip->latch_base = ioremap (0xf301a000, 0x1000); in snd_pmac_new()
1276 in_8(chip->latch_base + 0x190); in snd_pmac_new()
1277 } else if (chip->is_pbook_G3) { in snd_pmac_new()
1279 for (mio = chip->node->parent; mio; mio = mio->parent) { in snd_pmac_new()
1280 if (of_node_name_eq(mio, "mac-io")) { in snd_pmac_new()
1283 chip->macio_base = in snd_pmac_new()
1294 * 4, 6, 8 - f enable the input from the modem. in snd_pmac_new()
1296 if (chip->macio_base) in snd_pmac_new()
1297 out_8(chip->macio_base + 0x37, 3); in snd_pmac_new()
1330 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); in snd_pmac_suspend()
1331 if (chip->suspend) in snd_pmac_suspend()
1332 chip->suspend(chip); in snd_pmac_suspend()
1333 spin_lock_irqsave(&chip->reg_lock, flags); in snd_pmac_suspend()
1335 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_pmac_suspend()
1336 if (chip->irq >= 0) in snd_pmac_suspend()
1337 disable_irq(chip->irq); in snd_pmac_suspend()
1338 if (chip->tx_irq >= 0) in snd_pmac_suspend()
1339 disable_irq(chip->tx_irq); in snd_pmac_suspend()
1340 if (chip->rx_irq >= 0) in snd_pmac_suspend()
1341 disable_irq(chip->rx_irq); in snd_pmac_suspend()
1348 if (chip->resume) in snd_pmac_resume()
1349 chip->resume(chip); in snd_pmac_resume()
1351 if (chip->macio_base && chip->is_pbook_G3) in snd_pmac_resume()
1352 out_8(chip->macio_base + 0x37, 3); in snd_pmac_resume()
1353 else if (chip->is_pbook_3400) in snd_pmac_resume()
1354 in_8(chip->latch_base + 0x190); in snd_pmac_resume()
1358 if (chip->irq >= 0) in snd_pmac_resume()
1359 enable_irq(chip->irq); in snd_pmac_resume()
1360 if (chip->tx_irq >= 0) in snd_pmac_resume()
1361 enable_irq(chip->tx_irq); in snd_pmac_resume()
1362 if (chip->rx_irq >= 0) in snd_pmac_resume()
1363 enable_irq(chip->rx_irq); in snd_pmac_resume()
1365 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); in snd_pmac_resume()