Lines Matching refs:chip

50 static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, struct pmac_dbdma *rec, int size)
54 rec->space = dma_alloc_coherent(&chip->pdev->dev, rsize,
66 static void snd_pmac_dbdma_free(struct snd_pmac *chip, struct pmac_dbdma *rec)
71 dma_free_coherent(&chip->pdev->dev, rsize, rec->space, rec->dma_base);
84 unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec, unsigned int rate)
89 if (rate > chip->freq_table[0])
92 for (i = 0; i < chip->num_freqs; i++, ok >>= 1) {
95 if (rate >= chip->freq_table[i])
113 static struct pmac_stream *snd_pmac_get_stream(struct snd_pmac *chip, int stream)
117 return &chip->playback;
119 return &chip->capture;
138 * set the format and rate to the chip.
141 static void snd_pmac_pcm_set_format(struct snd_pmac *chip)
144 out_le32(&chip->awacs->control, chip->control_mask | (chip->rate_index << 8));
145 out_le32(&chip->awacs->byteswap, chip->format == SNDRV_PCM_FORMAT_S16_LE ? 1 : 0);
146 if (chip->set_format)
147 chip->set_format(chip);
179 static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec, struct snd_pcm_substream *subs)
192 rate_index = snd_pmac_rate_index(chip, rec, runtime->rate);
195 astr = snd_pmac_get_stream(chip, another_stream(rec->stream));
200 chip->rate_index = rate_index;
201 chip->format = runtime->format;
209 spin_lock_irq(&chip->reg_lock);
211 chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP);
212 snd_pmac_dma_set_command(rec, &chip->extra_dma);
214 spin_unlock_irq(&chip->reg_lock);
216 spin_lock_irq(&chip->reg_lock);
234 spin_unlock_irq(&chip->reg_lock);
243 static int snd_pmac_pcm_trigger(struct snd_pmac *chip, struct pmac_stream *rec,
256 spin_lock(&chip->reg_lock);
257 snd_pmac_beep_stop(chip);
258 snd_pmac_pcm_set_format(chip);
265 spin_unlock(&chip->reg_lock);
270 spin_lock(&chip->reg_lock);
276 spin_unlock(&chip->reg_lock);
290 static snd_pcm_uframes_t snd_pmac_pcm_pointer(struct snd_pmac *chip,
317 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
318 return snd_pmac_pcm_prepare(chip, &chip->playback, subs);
324 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
325 return snd_pmac_pcm_trigger(chip, &chip->playback, subs, cmd);
330 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
331 return snd_pmac_pcm_pointer(chip, &chip->playback, subs);
341 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
342 return snd_pmac_pcm_prepare(chip, &chip->capture, subs);
348 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
349 return snd_pmac_pcm_trigger(chip, &chip->capture, subs, cmd);
354 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
355 return snd_pmac_pcm_pointer(chip, &chip->capture, subs);
431 static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec)
437 spin_lock(&chip->reg_lock);
468 spin_unlock(&chip->reg_lock);
470 spin_lock(&chip->reg_lock);
473 spin_unlock(&chip->reg_lock);
524 struct snd_pmac *chip = rule->private;
525 struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]);
531 for (i = chip->num_freqs - 1; i >= 0; i--) {
533 freq_table[num_freqs++] = chip->freq_table[i];
543 struct snd_pmac *chip = rule->private;
544 struct pmac_stream *rec = snd_pmac_get_stream(chip, rule->deps[0]);
553 static int snd_pmac_pcm_open(struct snd_pmac *chip, struct pmac_stream *rec,
561 for (i = 0; i < chip->num_freqs; i++)
562 if (chip->freqs_ok & (1 << i))
564 snd_pcm_rate_to_rate_bit(chip->freq_table[i]);
567 for (i = 0; i < chip->num_freqs; i++) {
568 if (chip->freqs_ok & (1 << i)) {
569 runtime->hw.rate_max = chip->freq_table[i];
573 for (i = chip->num_freqs - 1; i >= 0; i--) {
574 if (chip->freqs_ok & (1 << i)) {
575 runtime->hw.rate_min = chip->freq_table[i];
579 runtime->hw.formats = chip->formats_ok;
580 if (chip->can_capture) {
581 if (! chip->can_duplex)
590 snd_pmac_hw_rule_rate, chip, rec->stream, -1);
592 snd_pmac_hw_rule_format, chip, rec->stream, -1);
602 static int snd_pmac_pcm_close(struct snd_pmac *chip, struct pmac_stream *rec,
609 astr = snd_pmac_get_stream(chip, another_stream(rec->stream));
614 astr->cur_freqs = chip->freqs_ok;
615 astr->cur_formats = chip->formats_ok;
622 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
625 return snd_pmac_pcm_open(chip, &chip->playback, subs);
630 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
633 return snd_pmac_pcm_open(chip, &chip->capture, subs);
638 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
640 return snd_pmac_pcm_close(chip, &chip->playback, subs);
645 struct snd_pmac *chip = snd_pcm_substream_chip(subs);
647 return snd_pmac_pcm_close(chip, &chip->capture, subs);
669 int snd_pmac_pcm_new(struct snd_pmac *chip)
675 if (! chip->can_capture)
677 err = snd_pcm_new(chip->card, chip->card->driver, 0, 1, num_captures, &pcm);
682 if (chip->can_capture)
685 pcm->private_data = chip;
687 strcpy(pcm->name, chip->card->shortname);
688 chip->pcm = pcm;
690 chip->formats_ok = SNDRV_PCM_FMTBIT_S16_BE;
691 if (chip->can_byte_swap)
692 chip->formats_ok |= SNDRV_PCM_FMTBIT_S16_LE;
694 chip->playback.cur_formats = chip->formats_ok;
695 chip->capture.cur_formats = chip->formats_ok;
696 chip->playback.cur_freqs = chip->freqs_ok;
697 chip->capture.cur_freqs = chip->freqs_ok;
701 &chip->pdev->dev,
708 static void snd_pmac_dbdma_reset(struct snd_pmac *chip)
710 out_le32(&chip->playback.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
711 snd_pmac_wait_ack(&chip->playback);
712 out_le32(&chip->capture.dma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
713 snd_pmac_wait_ack(&chip->capture);
720 void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed)
722 struct pmac_stream *rec = &chip->playback;
725 chip->extra_dma.cmds->req_count = cpu_to_le16(bytes);
726 chip->extra_dma.cmds->xfer_status = cpu_to_le16(0);
727 chip->extra_dma.cmds->cmd_dep = cpu_to_le32(chip->extra_dma.addr);
728 chip->extra_dma.cmds->phy_addr = cpu_to_le32(addr);
729 chip->extra_dma.cmds->command = cpu_to_le16(OUTPUT_MORE | BR_ALWAYS);
730 out_le32(&chip->awacs->control,
731 (in_le32(&chip->awacs->control) & ~0x1f00)
733 out_le32(&chip->awacs->byteswap, 0);
734 snd_pmac_dma_set_command(rec, &chip->extra_dma);
738 void snd_pmac_beep_dma_stop(struct snd_pmac *chip)
740 snd_pmac_dma_stop(&chip->playback);
741 chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP);
742 snd_pmac_pcm_set_format(chip); /* reset format */
752 struct snd_pmac *chip = devid;
753 snd_pmac_pcm_update(chip, &chip->playback);
761 struct snd_pmac *chip = devid;
762 snd_pmac_pcm_update(chip, &chip->capture);
770 struct snd_pmac *chip = devid;
771 int ctrl = in_le32(&chip->awacs->control);
776 if (chip->update_automute)
777 chip->update_automute(chip, 1);
780 int err = (in_le32(&chip->awacs->codec_stat) & MASK_ERRCODE) >> 16;
781 if (err && chip->model <= PMAC_SCREAMER)
785 out_le32(&chip->awacs->control, ctrl);
793 static void snd_pmac_sound_feature(struct snd_pmac *chip, int enable)
796 ppc_md.feature_call(PMAC_FTR_SOUND_CHIP_ENABLE, chip->node, 0, enable);
803 static int snd_pmac_free(struct snd_pmac *chip)
806 if (chip->initialized) {
807 snd_pmac_dbdma_reset(chip);
809 out_le32(&chip->awacs->control, in_le32(&chip->awacs->control) & 0xfff);
812 if (chip->node)
813 snd_pmac_sound_feature(chip, 0);
816 if (chip->mixer_free)
817 chip->mixer_free(chip);
819 snd_pmac_detach_beep(chip);
822 if (chip->irq >= 0)
823 free_irq(chip->irq, (void*)chip);
824 if (chip->tx_irq >= 0)
825 free_irq(chip->tx_irq, (void*)chip);
826 if (chip->rx_irq >= 0)
827 free_irq(chip->rx_irq, (void*)chip);
828 snd_pmac_dbdma_free(chip, &chip->playback.cmd);
829 snd_pmac_dbdma_free(chip, &chip->capture.cmd);
830 snd_pmac_dbdma_free(chip, &chip->extra_dma);
831 snd_pmac_dbdma_free(chip, &emergency_dbdma);
832 iounmap(chip->macio_base);
833 iounmap(chip->latch_base);
834 iounmap(chip->awacs);
835 iounmap(chip->playback.dma);
836 iounmap(chip->capture.dma);
838 if (chip->node) {
841 if (chip->requested & (1 << i))
842 release_mem_region(chip->rsrc[i].start,
843 resource_size(&chip->rsrc[i]));
847 pci_dev_put(chip->pdev);
848 of_node_put(chip->node);
849 kfree(chip);
859 struct snd_pmac *chip = device->device_data;
860 return snd_pmac_free(chip);
868 static void detect_byte_swap(struct snd_pmac *chip)
873 for (mio = chip->node->parent; mio; mio = mio->parent) {
876 chip->can_byte_swap = 0;
884 chip->can_byte_swap = 0 ;
887 chip->can_duplex = 0;
892 * detect a sound chip
894 static int snd_pmac_detect(struct snd_pmac *chip)
905 chip->subframe = 0;
906 chip->revision = 0;
907 chip->freqs_ok = 0xff; /* all ok */
908 chip->model = PMAC_AWACS;
909 chip->can_byte_swap = 1;
910 chip->can_duplex = 1;
911 chip->can_capture = 1;
912 chip->num_freqs = ARRAY_SIZE(awacs_freqs);
913 chip->freq_table = awacs_freqs;
914 chip->pdev = NULL;
916 chip->control_mask = MASK_IEPC | MASK_IEE | 0x11; /* default */
921 chip->is_pbook_3400 = 1;
924 chip->is_pbook_G3 = 1;
925 chip->node = of_find_node_by_name(NULL, "awacs");
926 sound = of_node_get(chip->node);
932 if (!chip->node)
933 chip->node = of_find_node_by_name(NULL, "davbus");
938 if (! chip->node) {
939 chip->node = of_find_node_by_name(NULL, "i2s-a");
940 if (chip->node && chip->node->parent &&
941 chip->node->parent->parent) {
942 if (of_device_is_compatible(chip->node->parent->parent,
944 chip->is_k2 = 1;
947 if (! chip->node)
952 if (sound->parent == chip->node)
956 of_node_put(chip->node);
957 chip->node = NULL;
962 chip->subframe = *prop;
971 of_node_put(chip->node);
972 chip->node = NULL;
977 chip->model = PMAC_SCREAMER;
978 // chip->can_byte_swap = 0; /* FIXME: check this */
981 chip->model = PMAC_BURGUNDY;
982 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */
985 chip->model = PMAC_DACA;
986 chip->can_capture = 0; /* no capture */
987 chip->can_duplex = 0;
988 // chip->can_byte_swap = 0; /* FIXME: check this */
989 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */
992 chip->model = PMAC_TUMBLER;
993 chip->can_capture = of_machine_is_compatible("PowerMac4,2")
999 chip->can_duplex = 0;
1000 // chip->can_byte_swap = 0; /* FIXME: check this */
1001 chip->num_freqs = ARRAY_SIZE(tumbler_freqs);
1002 chip->freq_table = tumbler_freqs;
1003 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */
1006 chip->model = PMAC_SNAPPER;
1007 // chip->can_byte_swap = 0; /* FIXME: check this */
1008 chip->num_freqs = ARRAY_SIZE(tumbler_freqs);
1009 chip->freq_table = tumbler_freqs;
1010 chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */
1014 chip->device_id = *prop;
1016 chip->has_iic = (dn != NULL);
1022 macio = macio_find(chip->node, macio_unknown);
1031 chip->pdev = pdev;
1036 if (chip->pdev == NULL)
1040 detect_byte_swap(chip);
1049 chip->freqs_ok = 0;
1055 for (i = 0; i < chip->num_freqs; ++i) {
1056 if (r == chip->freq_table[i]) {
1057 chip->freqs_ok |= (1 << i);
1064 chip->freqs_ok = 1;
1078 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
1079 ucontrol->value.integer.value[0] = chip->auto_mute;
1086 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
1087 if (ucontrol->value.integer.value[0] != chip->auto_mute) {
1088 chip->auto_mute = !!ucontrol->value.integer.value[0];
1089 if (chip->update_automute)
1090 chip->update_automute(chip, 1);
1099 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
1100 if (chip->detect_headphone)
1101 ucontrol->value.integer.value[0] = chip->detect_headphone(chip);
1122 int snd_pmac_add_automute(struct snd_pmac *chip)
1125 chip->auto_mute = 1;
1126 err = snd_ctl_add(chip->card, snd_ctl_new1(&auto_mute_controls[0], chip));
1131 chip->hp_detect_ctl = snd_ctl_new1(&auto_mute_controls[1], chip);
1132 return snd_ctl_add(chip->card, chip->hp_detect_ctl);
1137 * create and detect a pmac chip record
1141 struct snd_pmac *chip;
1152 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1153 if (chip == NULL)
1155 chip->card = card;
1157 spin_lock_init(&chip->reg_lock);
1158 chip->irq = chip->tx_irq = chip->rx_irq = -1;
1160 chip->playback.stream = SNDRV_PCM_STREAM_PLAYBACK;
1161 chip->capture.stream = SNDRV_PCM_STREAM_CAPTURE;
1163 err = snd_pmac_detect(chip);
1167 if (snd_pmac_dbdma_alloc(chip, &chip->playback.cmd, PMAC_MAX_FRAGS + 1) < 0 ||
1168 snd_pmac_dbdma_alloc(chip, &chip->capture.cmd, PMAC_MAX_FRAGS + 1) < 0 ||
1169 snd_pmac_dbdma_alloc(chip, &chip->extra_dma, 2) < 0 ||
1170 snd_pmac_dbdma_alloc(chip, &emergency_dbdma, 2) < 0) {
1175 np = chip->node;
1176 chip->requested = 0;
1177 if (chip->is_k2) {
1182 &chip->rsrc[i])) {
1188 if (request_mem_region(chip->rsrc[i].start,
1189 resource_size(&chip->rsrc[i]),
1193 i, rnames[i], &chip->rsrc[i]);
1197 chip->requested |= (1 << i);
1199 ctrl_addr = chip->rsrc[0].start;
1200 txdma_addr = chip->rsrc[1].start;
1207 &chip->rsrc[i])) {
1213 if (request_mem_region(chip->rsrc[i].start,
1214 resource_size(&chip->rsrc[i]),
1218 i, rnames[i], &chip->rsrc[i]);
1222 chip->requested |= (1 << i);
1224 ctrl_addr = chip->rsrc[0].start;
1225 txdma_addr = chip->rsrc[1].start;
1226 rxdma_addr = chip->rsrc[2].start;
1229 chip->awacs = ioremap(ctrl_addr, 0x1000);
1230 chip->playback.dma = ioremap(txdma_addr, 0x100);
1231 chip->capture.dma = ioremap(rxdma_addr, 0x100);
1232 if (chip->model <= PMAC_BURGUNDY) {
1235 "PMac", (void*)chip)) {
1241 chip->irq = irq;
1244 if (request_irq(irq, snd_pmac_tx_intr, 0, "PMac Output", (void*)chip)){
1249 chip->tx_irq = irq;
1251 if (request_irq(irq, snd_pmac_rx_intr, 0, "PMac Input", (void*)chip)) {
1256 chip->rx_irq = irq;
1258 snd_pmac_sound_feature(chip, 1);
1261 if (chip->model <= PMAC_BURGUNDY)
1262 out_le32(&chip->awacs->control, chip->control_mask);
1267 if (chip->is_pbook_3400) {
1275 chip->latch_base = ioremap (0xf301a000, 0x1000);
1276 in_8(chip->latch_base + 0x190);
1277 } else if (chip->is_pbook_G3) {
1279 for (mio = chip->node->parent; mio; mio = mio->parent) {
1283 chip->macio_base =
1296 if (chip->macio_base)
1297 out_8(chip->macio_base + 0x37, 3);
1301 snd_pmac_dbdma_reset(chip);
1303 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1307 *chip_return = chip;
1311 snd_pmac_free(chip);
1326 void snd_pmac_suspend(struct snd_pmac *chip)
1330 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
1331 if (chip->suspend)
1332 chip->suspend(chip);
1333 spin_lock_irqsave(&chip->reg_lock, flags);
1334 snd_pmac_beep_stop(chip);
1335 spin_unlock_irqrestore(&chip->reg_lock, flags);
1336 if (chip->irq >= 0)
1337 disable_irq(chip->irq);
1338 if (chip->tx_irq >= 0)
1339 disable_irq(chip->tx_irq);
1340 if (chip->rx_irq >= 0)
1341 disable_irq(chip->rx_irq);
1342 snd_pmac_sound_feature(chip, 0);
1345 void snd_pmac_resume(struct snd_pmac *chip)
1347 snd_pmac_sound_feature(chip, 1);
1348 if (chip->resume)
1349 chip->resume(chip);
1351 if (chip->macio_base && chip->is_pbook_G3)
1352 out_8(chip->macio_base + 0x37, 3);
1353 else if (chip->is_pbook_3400)
1354 in_8(chip->latch_base + 0x190);
1356 snd_pmac_pcm_set_format(chip);
1358 if (chip->irq >= 0)
1359 enable_irq(chip->irq);
1360 if (chip->tx_irq >= 0)
1361 enable_irq(chip->tx_irq);
1362 if (chip->rx_irq >= 0)
1363 enable_irq(chip->rx_irq);
1365 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);