X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=sound%2Fppc%2Fpmac.c;h=85081172403f25ec056a99eb58a341fbd5d57370;hb=55051feb57eba600b366006757304a0af3ada2bd;hp=4f0a4204516d6d7d87befcd5d90bd62bf64a5ef2;hpb=5e12bea0833e47117c31f13b528e31dc8112de57;p=safe%2Fjmp%2Flinux-2.6 diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c index 4f0a420..8508117 100644 --- a/sound/ppc/pmac.c +++ b/sound/ppc/pmac.c @@ -20,7 +20,6 @@ */ -#include #include #include #include @@ -45,6 +44,18 @@ static int tumbler_freqs[1] = { 44100 }; + +/* + * we will allocate a single 'emergency' dbdma cmd block to use if the + * tx status comes up "DEAD". This happens on some PowerComputing Pmac + * clones, either owing to a bug in dbdma or some interaction between + * IDE and sound. However, this measure would deal with DEAD status if + * it appeared elsewhere. + */ +static struct pmac_dbdma emergency_dbdma; +static int emergency_in_use; + + /* * allocate DBDMA command arrays */ @@ -66,7 +77,7 @@ static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, struct pmac_dbdma *rec, i static void snd_pmac_dbdma_free(struct snd_pmac *chip, struct pmac_dbdma *rec) { - if (rec) { + if (rec->space) { unsigned int rsize = sizeof(struct dbdma_cmd) * (rec->size + 1); dma_free_coherent(&chip->pdev->dev, rsize, rec->space, rec->dma_base); @@ -203,7 +214,7 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec, int rate_index; long offset; struct pmac_stream *astr; - + rec->dma_size = snd_pcm_lib_buffer_bytes(subs); rec->period_size = snd_pcm_lib_period_bytes(subs); rec->nperiods = rec->dma_size / rec->period_size; @@ -288,7 +299,7 @@ static int snd_pmac_pcm_trigger(struct snd_pmac *chip, struct pmac_stream *rec, case SNDRV_PCM_TRIGGER_SUSPEND: spin_lock(&chip->reg_lock); rec->running = 0; - /*printk("stopped!!\n");*/ + /*printk(KERN_DEBUG "stopped!!\n");*/ snd_pmac_dma_stop(rec); for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) out_le16(&cp->command, DBDMA_STOP); @@ -323,7 +334,7 @@ static snd_pcm_uframes_t snd_pmac_pcm_pointer(struct snd_pmac *chip, } #endif count += rec->cur_period * rec->period_size; - /*printk("pointer=%d\n", count);*/ + /*printk(KERN_DEBUG "pointer=%d\n", count);*/ return bytes_to_frames(subs->runtime, count); } @@ -376,6 +387,75 @@ static snd_pcm_uframes_t snd_pmac_capture_pointer(struct snd_pcm_substream *subs /* + * Handle DEAD DMA transfers: + * if the TX status comes up "DEAD" - reported on some Power Computing machines + * we need to re-start the dbdma - but from a different physical start address + * and with a different transfer length. It would get very messy to do this + * with the normal dbdma_cmd blocks - we would have to re-write the buffer start + * addresses each time. So, we will keep a single dbdma_cmd block which can be + * fiddled with. + * When DEAD status is first reported the content of the faulted dbdma block is + * copied into the emergency buffer and we note that the buffer is in use. + * we then bump the start physical address by the amount that was successfully + * output before it died. + * On any subsequent DEAD result we just do the bump-ups (we know that we are + * already using the emergency dbdma_cmd). + * CHECK: this just tries to "do it". It is possible that we should abandon + * xfers when the number of residual bytes gets below a certain value - I can + * see that this might cause a loop-forever if a too small transfer causes + * DEAD status. However this is a TODO for now - we'll see what gets reported. + * When we get a successful transfer result with the emergency buffer we just + * pretend that it completed using the original dmdma_cmd and carry on. The + * 'next_cmd' field will already point back to the original loop of blocks. + */ +static inline void snd_pmac_pcm_dead_xfer(struct pmac_stream *rec, + volatile struct dbdma_cmd __iomem *cp) +{ + unsigned short req, res ; + unsigned int phy ; + + /* printk(KERN_WARNING "snd-powermac: DMA died - patching it up!\n"); */ + + /* to clear DEAD status we must first clear RUN + set it to quiescent to be on the safe side */ + (void)in_le32(&rec->dma->status); + out_le32(&rec->dma->control, (RUN|PAUSE|FLUSH|WAKE) << 16); + + if (!emergency_in_use) { /* new problem */ + memcpy((void *)emergency_dbdma.cmds, (void *)cp, + sizeof(struct dbdma_cmd)); + emergency_in_use = 1; + st_le16(&cp->xfer_status, 0); + st_le16(&cp->req_count, rec->period_size); + cp = emergency_dbdma.cmds; + } + + /* now bump the values to reflect the amount + we haven't yet shifted */ + req = ld_le16(&cp->req_count); + res = ld_le16(&cp->res_count); + phy = ld_le32(&cp->phy_addr); + phy += (req - res); + st_le16(&cp->req_count, res); + st_le16(&cp->res_count, 0); + st_le16(&cp->xfer_status, 0); + st_le32(&cp->phy_addr, phy); + + st_le32(&cp->cmd_dep, rec->cmd.addr + + sizeof(struct dbdma_cmd)*((rec->cur_period+1)%rec->nperiods)); + + st_le16(&cp->command, OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS); + + /* point at our patched up command block */ + out_le32(&rec->dma->cmdptr, emergency_dbdma.addr); + + /* we must re-start the controller */ + (void)in_le32(&rec->dma->status); + /* should complete clearing the DEAD status */ + out_le32(&rec->dma->control, ((RUN|WAKE) << 16) + (RUN|WAKE)); +} + +/* * update playback/capture pointer from interrupts */ static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec) @@ -386,21 +466,35 @@ static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec) spin_lock(&chip->reg_lock); if (rec->running) { - cp = &rec->cmd.cmds[rec->cur_period]; for (c = 0; c < rec->nperiods; c++) { /* at most all fragments */ + + if (emergency_in_use) /* already using DEAD xfer? */ + cp = emergency_dbdma.cmds; + else + cp = &rec->cmd.cmds[rec->cur_period]; + stat = ld_le16(&cp->xfer_status); + + if (stat & DEAD) { + snd_pmac_pcm_dead_xfer(rec, cp); + break; /* this block is still going */ + } + + if (emergency_in_use) + emergency_in_use = 0 ; /* done that */ + if (! (stat & ACTIVE)) break; - /*printk("update frag %d\n", rec->cur_period);*/ + + /*printk(KERN_DEBUG "update frag %d\n", rec->cur_period);*/ st_le16(&cp->xfer_status, 0); st_le16(&cp->req_count, rec->period_size); /*st_le16(&cp->res_count, 0);*/ rec->cur_period++; if (rec->cur_period >= rec->nperiods) { rec->cur_period = 0; - cp = rec->cmd.cmds; - } else - cp++; + } + spin_unlock(&chip->reg_lock); snd_pcm_period_elapsed(rec->substream); spin_lock(&chip->reg_lock); @@ -490,35 +584,14 @@ static int snd_pmac_pcm_open(struct snd_pmac *chip, struct pmac_stream *rec, struct snd_pcm_substream *subs) { struct snd_pcm_runtime *runtime = subs->runtime; - int i, j, fflags; - static int typical_freqs[] = { - 44100, - 22050, - 11025, - 0, - }; - static int typical_freq_flags[] = { - SNDRV_PCM_RATE_44100, - SNDRV_PCM_RATE_22050, - SNDRV_PCM_RATE_11025, - 0, - }; + int i; /* look up frequency table and fill bit mask */ runtime->hw.rates = 0; - fflags = chip->freqs_ok; - for (i = 0; typical_freqs[i]; i++) { - for (j = 0; j < chip->num_freqs; j++) { - if ((chip->freqs_ok & (1 << j)) && - chip->freq_table[j] == typical_freqs[i]) { - runtime->hw.rates |= typical_freq_flags[i]; - fflags &= ~(1 << j); - break; - } - } - } - if (fflags) /* rest */ - runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; + for (i = 0; i < chip->num_freqs; i++) + if (chip->freqs_ok & (1 << i)) + runtime->hw.rates |= + snd_pcm_rate_to_rate_bit(chip->freq_table[i]); /* check for minimum and maximum rates */ for (i = 0; i < chip->num_freqs; i++) { @@ -551,9 +624,6 @@ static int snd_pmac_pcm_open(struct snd_pmac *chip, struct pmac_stream *rec, runtime->hw.periods_max = rec->cmd.size - 1; - if (chip->can_duplex) - snd_pcm_set_sync(subs); - /* constraints to fix choppy sound */ snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); return 0; @@ -573,7 +643,7 @@ static int snd_pmac_pcm_close(struct snd_pmac *chip, struct pmac_stream *rec, /* reset constraints */ astr->cur_freqs = chip->freqs_ok; astr->cur_formats = chip->formats_ok; - + return 0; } @@ -632,7 +702,7 @@ static struct snd_pcm_ops snd_pmac_capture_ops = { .pointer = snd_pmac_capture_pointer, }; -int __init snd_pmac_pcm_new(struct snd_pmac *chip) +int __devinit snd_pmac_pcm_new(struct snd_pmac *chip) { struct snd_pcm *pcm; int err; @@ -713,7 +783,7 @@ void snd_pmac_beep_dma_stop(struct snd_pmac *chip) * interrupt handlers */ static irqreturn_t -snd_pmac_tx_intr(int irq, void *devid, struct pt_regs *regs) +snd_pmac_tx_intr(int irq, void *devid) { struct snd_pmac *chip = devid; snd_pmac_pcm_update(chip, &chip->playback); @@ -722,7 +792,7 @@ snd_pmac_tx_intr(int irq, void *devid, struct pt_regs *regs) static irqreturn_t -snd_pmac_rx_intr(int irq, void *devid, struct pt_regs *regs) +snd_pmac_rx_intr(int irq, void *devid) { struct snd_pmac *chip = devid; snd_pmac_pcm_update(chip, &chip->capture); @@ -731,12 +801,12 @@ snd_pmac_rx_intr(int irq, void *devid, struct pt_regs *regs) static irqreturn_t -snd_pmac_ctrl_intr(int irq, void *devid, struct pt_regs *regs) +snd_pmac_ctrl_intr(int irq, void *devid) { struct snd_pmac *chip = devid; int ctrl = in_le32(&chip->awacs->control); - /*printk("pmac: control interrupt.. 0x%x\n", ctrl);*/ + /*printk(KERN_DEBUG "pmac: control interrupt.. 0x%x\n", ctrl);*/ if (ctrl & MASK_PORTCHG) { /* do something when headphone is plugged/unplugged? */ if (chip->update_automute) @@ -775,7 +845,8 @@ static int snd_pmac_free(struct snd_pmac *chip) out_le32(&chip->awacs->control, in_le32(&chip->awacs->control) & 0xfff); } - snd_pmac_sound_feature(chip, 0); + if (chip->node) + snd_pmac_sound_feature(chip, 0); /* clean up mixer if any */ if (chip->mixer_free) @@ -793,6 +864,7 @@ static int snd_pmac_free(struct snd_pmac *chip) snd_pmac_dbdma_free(chip, &chip->playback.cmd); snd_pmac_dbdma_free(chip, &chip->capture.cmd); snd_pmac_dbdma_free(chip, &chip->extra_dma); + snd_pmac_dbdma_free(chip, &emergency_dbdma); if (chip->macio_base) iounmap(chip->macio_base); if (chip->latch_base) @@ -803,23 +875,20 @@ static int snd_pmac_free(struct snd_pmac *chip) iounmap(chip->playback.dma); if (chip->capture.dma) iounmap(chip->capture.dma); -#ifndef CONFIG_PPC64 + if (chip->node) { int i; - for (i = 0; i < 3; i++) { - if (chip->of_requested & (1 << i)) { - if (chip->is_k2) - release_OF_resource(chip->node->parent, - i); - else - release_OF_resource(chip->node, i); - } + if (chip->requested & (1 << i)) + release_mem_region(chip->rsrc[i].start, + chip->rsrc[i].end - + chip->rsrc[i].start + 1); } } -#endif /* CONFIG_PPC64 */ + if (chip->pdev) pci_dev_put(chip->pdev); + of_node_put(chip->node); kfree(chip); return 0; } @@ -839,25 +908,25 @@ static int snd_pmac_dev_free(struct snd_device *device) * check the machine support byteswap (little-endian) */ -static void __init detect_byte_swap(struct snd_pmac *chip) +static void __devinit detect_byte_swap(struct snd_pmac *chip) { struct device_node *mio; /* if seems that Keylargo can't byte-swap */ for (mio = chip->node->parent; mio; mio = mio->parent) { if (strcmp(mio->name, "mac-io") == 0) { - if (device_is_compatible(mio, "Keylargo")) + if (of_device_is_compatible(mio, "Keylargo")) chip->can_byte_swap = 0; break; } } /* it seems the Pismo & iBook can't byte-swap in hardware. */ - if (machine_is_compatible("PowerBook3,1") || - machine_is_compatible("PowerBook2,1")) + if (of_machine_is_compatible("PowerBook3,1") || + of_machine_is_compatible("PowerBook2,1")) chip->can_byte_swap = 0 ; - if (machine_is_compatible("PowerBook2,1")) + if (of_machine_is_compatible("PowerBook2,1")) chip->can_duplex = 0; } @@ -865,15 +934,15 @@ static void __init detect_byte_swap(struct snd_pmac *chip) /* * detect a sound chip */ -static int __init snd_pmac_detect(struct snd_pmac *chip) +static int __devinit snd_pmac_detect(struct snd_pmac *chip) { - struct device_node *sound = NULL; - unsigned int *prop, l; + struct device_node *sound; + struct device_node *dn; + const unsigned int *prop; + unsigned int l; struct macio_chip* macio; - u32 layout_id = 0; - - if (_machine != _MACH_Pmac) + if (!machine_is(powermac)) return -ENODEV; chip->subframe = 0; @@ -885,35 +954,35 @@ static int __init snd_pmac_detect(struct snd_pmac *chip) chip->can_capture = 1; chip->num_freqs = ARRAY_SIZE(awacs_freqs); chip->freq_table = awacs_freqs; + chip->pdev = NULL; chip->control_mask = MASK_IEPC | MASK_IEE | 0x11; /* default */ /* check machine type */ - if (machine_is_compatible("AAPL,3400/2400") - || machine_is_compatible("AAPL,3500")) + if (of_machine_is_compatible("AAPL,3400/2400") + || of_machine_is_compatible("AAPL,3500")) chip->is_pbook_3400 = 1; - else if (machine_is_compatible("PowerBook1,1") - || machine_is_compatible("AAPL,PowerBook1998")) + else if (of_machine_is_compatible("PowerBook1,1") + || of_machine_is_compatible("AAPL,PowerBook1998")) chip->is_pbook_G3 = 1; - chip->node = find_devices("awacs"); - if (chip->node) - sound = chip->node; + chip->node = of_find_node_by_name(NULL, "awacs"); + sound = of_node_get(chip->node); /* * powermac G3 models have a node called "davbus" * with a child called "sound". */ if (!chip->node) - chip->node = find_devices("davbus"); + chip->node = of_find_node_by_name(NULL, "davbus"); /* * if we didn't find a davbus device, try 'i2s-a' since * this seems to be what iBooks have */ if (! chip->node) { - chip->node = find_devices("i2s-a"); + chip->node = of_find_node_by_name(NULL, "i2s-a"); if (chip->node && chip->node->parent && chip->node->parent->parent) { - if (device_is_compatible(chip->node->parent->parent, + if (of_device_is_compatible(chip->node->parent->parent, "K2-Keylargo")) chip->is_k2 = 1; } @@ -922,81 +991,69 @@ static int __init snd_pmac_detect(struct snd_pmac *chip) return -ENODEV; if (!sound) { - sound = find_devices("sound"); + sound = of_find_node_by_name(NULL, "sound"); while (sound && sound->parent != chip->node) - sound = sound->next; + sound = of_find_node_by_name(sound, "sound"); } - if (! sound) + if (! sound) { + of_node_put(chip->node); + chip->node = NULL; return -ENODEV; - prop = (unsigned int *) get_property(sound, "sub-frame", NULL); + } + prop = of_get_property(sound, "sub-frame", NULL); if (prop && *prop < 16) chip->subframe = *prop; - prop = (unsigned int *) get_property(sound, "layout-id", NULL); - if (prop) - layout_id = *prop; + prop = of_get_property(sound, "layout-id", NULL); + if (prop) { + /* partly deprecate snd-powermac, for those machines + * that have a layout-id property for now */ + printk(KERN_INFO "snd-powermac no longer handles any " + "machines with a layout-id property " + "in the device-tree, use snd-aoa.\n"); + of_node_put(sound); + of_node_put(chip->node); + chip->node = NULL; + return -ENODEV; + } /* This should be verified on older screamers */ - if (device_is_compatible(sound, "screamer")) { + if (of_device_is_compatible(sound, "screamer")) { chip->model = PMAC_SCREAMER; // chip->can_byte_swap = 0; /* FIXME: check this */ } - if (device_is_compatible(sound, "burgundy")) { + if (of_device_is_compatible(sound, "burgundy")) { chip->model = PMAC_BURGUNDY; chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ } - if (device_is_compatible(sound, "daca")) { + if (of_device_is_compatible(sound, "daca")) { chip->model = PMAC_DACA; chip->can_capture = 0; /* no capture */ chip->can_duplex = 0; // chip->can_byte_swap = 0; /* FIXME: check this */ chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ } - if (device_is_compatible(sound, "tumbler")) { + if (of_device_is_compatible(sound, "tumbler")) { chip->model = PMAC_TUMBLER; - chip->can_capture = 0; /* no capture */ + chip->can_capture = of_machine_is_compatible("PowerMac4,2") + || of_machine_is_compatible("PowerBook4,1"); chip->can_duplex = 0; // chip->can_byte_swap = 0; /* FIXME: check this */ chip->num_freqs = ARRAY_SIZE(tumbler_freqs); chip->freq_table = tumbler_freqs; chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ } - if (device_is_compatible(sound, "snapper")) { + if (of_device_is_compatible(sound, "snapper")) { chip->model = PMAC_SNAPPER; // chip->can_byte_swap = 0; /* FIXME: check this */ chip->num_freqs = ARRAY_SIZE(tumbler_freqs); chip->freq_table = tumbler_freqs; chip->control_mask = MASK_IEPC | 0x11; /* disable IEE */ } - if (device_is_compatible(sound, "AOAKeylargo") || - device_is_compatible(sound, "AOAbase") || - device_is_compatible(sound, "AOAK2")) { - /* For now, only support very basic TAS3004 based machines with - * single frequency until proper i2s control is implemented - */ - switch(layout_id) { - case 0x48: - case 0x46: - case 0x33: - case 0x29: - case 0x24: - case 0x50: - case 0x5c: - chip->num_freqs = ARRAY_SIZE(tumbler_freqs); - chip->model = PMAC_SNAPPER; - chip->can_byte_swap = 0; /* FIXME: check this */ - chip->control_mask = MASK_IEPC | 0x11;/* disable IEE */ - break; - case 0x3a: - chip->num_freqs = ARRAY_SIZE(tumbler_freqs); - chip->model = PMAC_TOONIE; - chip->can_byte_swap = 0; /* FIXME: check this */ - chip->control_mask = MASK_IEPC | 0x11;/* disable IEE */ - break; - } - } - prop = (unsigned int *)get_property(sound, "device-id", NULL); + prop = of_get_property(sound, "device-id", NULL); if (prop) chip->device_id = *prop; - chip->has_iic = (find_devices("perch") != NULL); + dn = of_find_node_by_name(NULL, "perch"); + chip->has_iic = (dn != NULL); + of_node_put(dn); /* We need the PCI device for DMA allocations, let's use a crude method * for now ... @@ -1023,10 +1080,9 @@ static int __init snd_pmac_detect(struct snd_pmac *chip) /* look for a property saying what sample rates are available */ - prop = (unsigned int *) get_property(sound, "sample-rates", &l); + prop = of_get_property(sound, "sample-rates", &l); if (! prop) - prop = (unsigned int *) get_property(sound, - "output-frame-rates", &l); + prop = of_get_property(sound, "output-frame-rates", &l); if (prop) { int i; chip->freqs_ok = 0; @@ -1047,29 +1103,7 @@ static int __init snd_pmac_detect(struct snd_pmac *chip) chip->freqs_ok = 1; } - return 0; -} - -/* - * exported - boolean info callbacks for ease of programming - */ -int snd_pmac_boolean_stereo_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - uinfo->count = 2; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 1; - return 0; -} - -int snd_pmac_boolean_mono_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - uinfo->count = 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 1; + of_node_put(sound); return 0; } @@ -1090,7 +1124,7 @@ static int pmac_auto_mute_put(struct snd_kcontrol *kcontrol, { struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); if (ucontrol->value.integer.value[0] != chip->auto_mute) { - chip->auto_mute = ucontrol->value.integer.value[0]; + chip->auto_mute = !!ucontrol->value.integer.value[0]; if (chip->update_automute) chip->update_automute(chip, 1); return 1; @@ -1109,7 +1143,7 @@ static int pmac_hp_detect_get(struct snd_kcontrol *kcontrol, return 0; } -static struct snd_kcontrol_new auto_mute_controls[] __initdata = { +static struct snd_kcontrol_new auto_mute_controls[] __devinitdata = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Auto Mute Switch", .info = snd_pmac_boolean_mono_info, @@ -1124,7 +1158,7 @@ static struct snd_kcontrol_new auto_mute_controls[] __initdata = { }, }; -int __init snd_pmac_add_automute(struct snd_pmac *chip) +int __devinit snd_pmac_add_automute(struct snd_pmac *chip) { int err; chip->auto_mute = 1; @@ -1141,11 +1175,12 @@ int __init snd_pmac_add_automute(struct snd_pmac *chip) /* * create and detect a pmac chip record */ -int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return) +int __devinit snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return) { struct snd_pmac *chip; struct device_node *np; int i, err; + unsigned int irq; unsigned long ctrl_addr, txdma_addr, rxdma_addr; static struct snd_device_ops ops = { .dev_free = snd_pmac_dev_free, @@ -1169,86 +1204,106 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return) if (snd_pmac_dbdma_alloc(chip, &chip->playback.cmd, PMAC_MAX_FRAGS + 1) < 0 || snd_pmac_dbdma_alloc(chip, &chip->capture.cmd, PMAC_MAX_FRAGS + 1) < 0 || - snd_pmac_dbdma_alloc(chip, &chip->extra_dma, 2) < 0) { + snd_pmac_dbdma_alloc(chip, &chip->extra_dma, 2) < 0 || + snd_pmac_dbdma_alloc(chip, &emergency_dbdma, 2) < 0) { err = -ENOMEM; goto __error; } np = chip->node; + chip->requested = 0; if (chip->is_k2) { - if (np->parent->n_addrs < 2 || np->n_intrs < 3) { - err = -ENODEV; - goto __error; - } - for (i = 0; i < 2; i++) { -#ifndef CONFIG_PPC64 - static char *name[2] = { "- Control", "- DMA" }; - if (! request_OF_resource(np->parent, i, name[i])) { - snd_printk(KERN_ERR "pmac: can't request resource %d!\n", i); + static char *rnames[] = { + "Sound Control", "Sound DMA" }; + for (i = 0; i < 2; i ++) { + if (of_address_to_resource(np->parent, i, + &chip->rsrc[i])) { + printk(KERN_ERR "snd: can't translate rsrc " + " %d (%s)\n", i, rnames[i]); + err = -ENODEV; + goto __error; + } + if (request_mem_region(chip->rsrc[i].start, + chip->rsrc[i].end - + chip->rsrc[i].start + 1, + rnames[i]) == NULL) { + printk(KERN_ERR "snd: can't request rsrc " + " %d (%s: 0x%016llx:%016llx)\n", + i, rnames[i], + (unsigned long long)chip->rsrc[i].start, + (unsigned long long)chip->rsrc[i].end); err = -ENODEV; goto __error; } - chip->of_requested |= (1 << i); -#endif /* CONFIG_PPC64 */ - ctrl_addr = np->parent->addrs[0].address; - txdma_addr = np->parent->addrs[1].address; - rxdma_addr = txdma_addr + 0x100; + chip->requested |= (1 << i); } - + ctrl_addr = chip->rsrc[0].start; + txdma_addr = chip->rsrc[1].start; + rxdma_addr = txdma_addr + 0x100; } else { - if (np->n_addrs < 3 || np->n_intrs < 3) { - err = -ENODEV; - goto __error; - } - - for (i = 0; i < 3; i++) { -#ifndef CONFIG_PPC64 - static char *name[3] = { "- Control", "- Tx DMA", "- Rx DMA" }; - if (! request_OF_resource(np, i, name[i])) { - snd_printk(KERN_ERR "pmac: can't request resource %d!\n", i); + static char *rnames[] = { + "Sound Control", "Sound Tx DMA", "Sound Rx DMA" }; + for (i = 0; i < 3; i ++) { + if (of_address_to_resource(np, i, + &chip->rsrc[i])) { + printk(KERN_ERR "snd: can't translate rsrc " + " %d (%s)\n", i, rnames[i]); err = -ENODEV; goto __error; } - chip->of_requested |= (1 << i); -#endif /* CONFIG_PPC64 */ - ctrl_addr = np->addrs[0].address; - txdma_addr = np->addrs[1].address; - rxdma_addr = np->addrs[2].address; + if (request_mem_region(chip->rsrc[i].start, + chip->rsrc[i].end - + chip->rsrc[i].start + 1, + rnames[i]) == NULL) { + printk(KERN_ERR "snd: can't request rsrc " + " %d (%s: 0x%016llx:%016llx)\n", + i, rnames[i], + (unsigned long long)chip->rsrc[i].start, + (unsigned long long)chip->rsrc[i].end); + err = -ENODEV; + goto __error; + } + chip->requested |= (1 << i); } + ctrl_addr = chip->rsrc[0].start; + txdma_addr = chip->rsrc[1].start; + rxdma_addr = chip->rsrc[2].start; } chip->awacs = ioremap(ctrl_addr, 0x1000); chip->playback.dma = ioremap(txdma_addr, 0x100); chip->capture.dma = ioremap(rxdma_addr, 0x100); if (chip->model <= PMAC_BURGUNDY) { - if (request_irq(np->intrs[0].line, snd_pmac_ctrl_intr, 0, + irq = irq_of_parse_and_map(np, 0); + if (request_irq(irq, snd_pmac_ctrl_intr, 0, "PMac", (void*)chip)) { - snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", np->intrs[0].line); + snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", + irq); err = -EBUSY; goto __error; } - chip->irq = np->intrs[0].line; + chip->irq = irq; } - if (request_irq(np->intrs[1].line, snd_pmac_tx_intr, 0, - "PMac Output", (void*)chip)) { - snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", np->intrs[1].line); + irq = irq_of_parse_and_map(np, 1); + if (request_irq(irq, snd_pmac_tx_intr, 0, "PMac Output", (void*)chip)){ + snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); err = -EBUSY; goto __error; } - chip->tx_irq = np->intrs[1].line; - if (request_irq(np->intrs[2].line, snd_pmac_rx_intr, 0, - "PMac Input", (void*)chip)) { - snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", np->intrs[2].line); + chip->tx_irq = irq; + irq = irq_of_parse_and_map(np, 2); + if (request_irq(irq, snd_pmac_rx_intr, 0, "PMac Input", (void*)chip)) { + snd_printk(KERN_ERR "pmac: unable to grab IRQ %d\n", irq); err = -EBUSY; goto __error; } - chip->rx_irq = np->intrs[2].line; + chip->rx_irq = irq; snd_pmac_sound_feature(chip, 1); - /* reset */ - if (chip->model == PMAC_AWACS) - out_le32(&chip->awacs->control, 0x11); + /* reset & enable interrupts */ + if (chip->model <= PMAC_BURGUNDY) + out_le32(&chip->awacs->control, chip->control_mask); /* Powerbooks have odd ways of enabling inputs such as an expansion-bay CD or sound from an internal modem @@ -1266,9 +1321,11 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return) } else if (chip->is_pbook_G3) { struct device_node* mio; for (mio = chip->node->parent; mio; mio = mio->parent) { - if (strcmp(mio->name, "mac-io") == 0 - && mio->n_addrs > 0) { - chip->macio_base = ioremap(mio->addrs[0].address, 0x40); + if (strcmp(mio->name, "mac-io") == 0) { + struct resource r; + if (of_address_to_resource(mio, 0, &r) == 0) + chip->macio_base = + ioremap(r.start, 0x40); break; } } @@ -1294,8 +1351,6 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return) return 0; __error: - if (chip->pdev) - pci_dev_put(chip->pdev); snd_pmac_free(chip); return err; }