27 #include <linux/slab.h>
29 #include <linux/pci.h>
35 #include <asm/pci-bridge.h>
39 static int awacs_freqs[8] = {
40 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
43 static int tumbler_freqs[1] = {
56 static int emergency_in_use;
64 unsigned int rsize =
sizeof(
struct dbdma_cmd) * (size + 1);
81 unsigned int rsize =
sizeof(
struct dbdma_cmd) * (rec->
size + 1);
104 for (i = 0; i < chip->
num_freqs; i++, ok >>= 1) {
105 if (! (ok & 1))
continue;
116 static inline int another_stream(
int stream)
171 static void snd_pmac_pcm_set_format(
struct snd_pmac *chip)
183 static inline void snd_pmac_dma_stop(
struct pmac_stream *rec)
186 snd_pmac_wait_ack(rec);
202 out_le32(&rec->
dma->control, status | (status << 16));
218 rec->
dma_size = snd_pcm_lib_buffer_bytes(subs);
225 astr = snd_pmac_get_stream(chip, another_stream(rec->
stream));
240 snd_pmac_dma_stop(rec);
241 st_le16(&chip->
extra_dma.cmds->command, DBDMA_STOP);
242 snd_pmac_dma_set_command(rec, &chip->
extra_dma);
243 snd_pmac_dma_run(rec,
RUN);
251 for (i = 0, cp = rec->
cmd.cmds; i < rec->
nperiods; i++, cp++) {
252 st_le32(&cp->phy_addr, offset);
255 st_le16(&cp->xfer_status, 0);
259 st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS);
260 st_le32(&cp->cmd_dep, rec->
cmd.addr);
262 snd_pmac_dma_stop(rec);
263 snd_pmac_dma_set_command(rec, &rec->
cmd);
288 snd_pmac_pcm_set_format(chip);
289 for (i = 0, cp = rec->
cmd.cmds; i < rec->nperiods; i++, cp++)
291 snd_pmac_dma_set_command(rec, &rec->
cmd);
293 snd_pmac_dma_run(rec,
RUN|
WAKE);
303 snd_pmac_dma_stop(rec);
304 for (i = 0, cp = rec->
cmd.cmds; i < rec->nperiods; i++, cp++)
329 stat = ld_le16(&cp->xfer_status);
331 count =
in_le16(&cp->res_count);
338 return bytes_to_frames(subs->
runtime, count);
348 return snd_pmac_pcm_prepare(chip, &chip->
playback, subs);
355 return snd_pmac_pcm_trigger(chip, &chip->
playback, subs, cmd);
361 return snd_pmac_pcm_pointer(chip, &chip->
playback, subs);
372 return snd_pmac_pcm_prepare(chip, &chip->
capture, subs);
379 return snd_pmac_pcm_trigger(chip, &chip->
capture, subs, cmd);
385 return snd_pmac_pcm_pointer(chip, &chip->
capture, subs);
411 static inline void snd_pmac_pcm_dead_xfer(
struct pmac_stream *rec,
412 volatile struct dbdma_cmd
__iomem *cp)
424 if (!emergency_in_use) {
425 memcpy((
void *)emergency_dbdma.cmds, (
void *)cp,
426 sizeof(
struct dbdma_cmd));
427 emergency_in_use = 1;
428 st_le16(&cp->xfer_status, 0);
430 cp = emergency_dbdma.cmds;
435 req = ld_le16(&cp->req_count);
436 res = ld_le16(&cp->res_count);
437 phy = ld_le32(&cp->phy_addr);
439 st_le16(&cp->req_count, res);
440 st_le16(&cp->res_count, 0);
441 st_le16(&cp->xfer_status, 0);
442 st_le32(&cp->phy_addr, phy);
444 st_le32(&cp->cmd_dep, rec->
cmd.addr
447 st_le16(&cp->command, OUTPUT_MORE | BR_ALWAYS |
INTR_ALWAYS);
469 for (c = 0; c < rec->
nperiods; c++) {
471 if (emergency_in_use)
472 cp = emergency_dbdma.cmds;
476 stat = ld_le16(&cp->xfer_status);
479 snd_pmac_pcm_dead_xfer(rec, cp);
483 if (emergency_in_use)
484 emergency_in_use = 0 ;
490 st_le16(&cp->xfer_status, 0);
561 for (i = chip->
num_freqs - 1; i >= 0; i--) {
567 num_freqs, freq_table, 0);
590 runtime->
hw.rates = 0;
603 for (i = chip->
num_freqs - 1; i >= 0; i--) {
620 snd_pmac_hw_rule_rate, chip, rec->
stream, -1);
622 snd_pmac_hw_rule_format, chip, rec->
stream, -1);
625 runtime->
hw.periods_max = rec->
cmd.size - 1;
637 snd_pmac_dma_stop(rec);
639 astr = snd_pmac_get_stream(chip, another_stream(rec->
stream));
654 subs->
runtime->hw = snd_pmac_playback;
655 return snd_pmac_pcm_open(chip, &chip->
playback, subs);
662 subs->
runtime->hw = snd_pmac_capture;
663 return snd_pmac_pcm_open(chip, &chip->
capture, subs);
670 return snd_pmac_pcm_close(chip, &chip->
playback, subs);
677 return snd_pmac_pcm_close(chip, &chip->
capture, subs);
683 static struct snd_pcm_ops snd_pmac_playback_ops = {
684 .open = snd_pmac_playback_open,
685 .close = snd_pmac_playback_close,
687 .hw_params = snd_pmac_pcm_hw_params,
688 .hw_free = snd_pmac_pcm_hw_free,
689 .prepare = snd_pmac_playback_prepare,
690 .trigger = snd_pmac_playback_trigger,
691 .pointer = snd_pmac_playback_pointer,
695 .open = snd_pmac_capture_open,
696 .close = snd_pmac_capture_close,
698 .hw_params = snd_pmac_pcm_hw_params,
699 .hw_free = snd_pmac_pcm_hw_free,
700 .prepare = snd_pmac_capture_prepare,
701 .trigger = snd_pmac_capture_trigger,
702 .pointer = snd_pmac_capture_pointer,
709 int num_captures = 1;
738 64 * 1024, 64 * 1024);
744 static void snd_pmac_dbdma_reset(
struct snd_pmac *chip)
749 snd_pmac_wait_ack(&chip->
capture);
760 snd_pmac_dma_stop(rec);
761 st_le16(&chip->
extra_dma.cmds->req_count, bytes);
762 st_le16(&chip->
extra_dma.cmds->xfer_status, 0);
764 st_le32(&chip->
extra_dma.cmds->phy_addr, addr);
765 st_le16(&chip->
extra_dma.cmds->command, OUTPUT_MORE + BR_ALWAYS);
770 snd_pmac_dma_set_command(rec, &chip->
extra_dma);
771 snd_pmac_dma_run(rec,
RUN);
777 st_le16(&chip->
extra_dma.cmds->command, DBDMA_STOP);
778 snd_pmac_pcm_set_format(chip);
786 snd_pmac_tx_intr(
int irq,
void *
devid)
789 snd_pmac_pcm_update(chip, &chip->
playback);
795 snd_pmac_rx_intr(
int irq,
void *
devid)
798 snd_pmac_pcm_update(chip, &chip->
capture);
804 snd_pmac_ctrl_intr(
int irq,
void *
devid)
829 static void snd_pmac_sound_feature(
struct snd_pmac *chip,
int enable)
832 ppc_md.feature_call(PMAC_FTR_SOUND_CHIP_ENABLE, chip->
node, 0, enable);
839 static int snd_pmac_free(
struct snd_pmac *chip)
843 snd_pmac_dbdma_reset(chip);
849 snd_pmac_sound_feature(chip, 0);
864 snd_pmac_dbdma_free(chip, &chip->
playback.cmd);
865 snd_pmac_dbdma_free(chip, &chip->
capture.cmd);
866 snd_pmac_dbdma_free(chip, &chip->
extra_dma);
867 snd_pmac_dbdma_free(chip, &emergency_dbdma);
881 for (i = 0; i < 3; i++) {
884 resource_size(&chip->
rsrc[i]));
890 of_node_put(chip->
node);
902 return snd_pmac_free(chip);
915 for (mio = chip->
node->parent; mio; mio = mio->
parent) {
940 const unsigned int *prop;
942 struct macio_chip* macio;
944 if (!machine_is(powermac))
968 sound = of_node_get(chip->
node);
982 if (chip->
node && chip->
node->parent &&
983 chip->
node->parent->parent) {
998 of_node_put(chip->
node);
1003 if (prop && *prop < 16)
1010 "machines with a layout-id property "
1011 "in the device-tree, use snd-aoa.\n");
1013 of_node_put(chip->
node);
1071 struct device_node *np = pci_device_to_OF_node(pdev);
1072 if (np && np == macio->of_node) {
1082 detect_byte_swap(chip);
1092 for (l /=
sizeof(
int); l > 0; --
l) {
1093 unsigned int r = *prop++;
1113 #ifdef PMAC_SUPPORT_AUTOMUTE
1117 static int pmac_auto_mute_get(
struct snd_kcontrol *kcontrol,
1125 static int pmac_auto_mute_put(
struct snd_kcontrol *kcontrol,
1138 static int pmac_hp_detect_get(
struct snd_kcontrol *kcontrol,
1145 ucontrol->
value.integer.value[0] = 0;
1151 .name =
"Auto Mute Switch",
1153 .get = pmac_auto_mute_get,
1154 .put = pmac_auto_mute_put,
1157 .name =
"Headphone Detection",
1160 .get = pmac_hp_detect_get,
1170 printk(
KERN_ERR "snd-powermac: Failed to add automute control\n");
1187 unsigned long ctrl_addr, txdma_addr, rxdma_addr;
1192 *chip_return =
NULL;
1205 if ((err = snd_pmac_detect(chip)) < 0)
1210 snd_pmac_dbdma_alloc(chip, &chip->
extra_dma, 2) < 0 ||
1211 snd_pmac_dbdma_alloc(chip, &emergency_dbdma, 2) < 0) {
1219 static char *rnames[] = {
1220 "Sound Control",
"Sound DMA" };
1221 for (i = 0; i < 2; i ++) {
1225 " %d (%s)\n", i, rnames[i]);
1230 resource_size(&chip->
rsrc[i]),
1231 rnames[i]) ==
NULL) {
1234 i, rnames[i], &chip->
rsrc[i]);
1240 ctrl_addr = chip->
rsrc[0].start;
1241 txdma_addr = chip->
rsrc[1].start;
1242 rxdma_addr = txdma_addr + 0x100;
1244 static char *rnames[] = {
1245 "Sound Control",
"Sound Tx DMA",
"Sound Rx DMA" };
1246 for (i = 0; i < 3; i ++) {
1250 " %d (%s)\n", i, rnames[i]);
1255 resource_size(&chip->
rsrc[i]),
1256 rnames[i]) ==
NULL) {
1259 i, rnames[i], &chip->
rsrc[i]);
1265 ctrl_addr = chip->
rsrc[0].start;
1266 txdma_addr = chip->
rsrc[1].start;
1267 rxdma_addr = chip->
rsrc[2].start;
1276 "PMac", (
void*)chip)) {
1285 if (
request_irq(irq, snd_pmac_tx_intr, 0,
"PMac Output", (
void*)chip)){
1292 if (
request_irq(irq, snd_pmac_rx_intr, 0,
"PMac Input", (
void*)chip)) {
1299 snd_pmac_sound_feature(chip, 1);
1320 for (mio = chip->
node->parent; mio; mio = mio->
parent) {
1342 snd_pmac_dbdma_reset(chip);
1347 *chip_return =
chip;
1351 snd_pmac_free(chip);
1366 void snd_pmac_suspend(
struct snd_pmac *chip)
1368 unsigned long flags;
1372 chip->suspend(chip);
1373 snd_pcm_suspend_all(chip->
pcm);
1376 spin_unlock_irqrestore(&chip->
reg_lock, flags);
1383 snd_pmac_sound_feature(chip, 0);
1386 void snd_pmac_resume(
struct snd_pmac *chip)
1388 snd_pmac_sound_feature(chip, 1);
1397 snd_pmac_pcm_set_format(chip);