X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=sound%2Farm%2Fpxa2xx-ac97.c;h=dede954b2c657e0c1db1f135c38da9f630e5442b;hb=d907dd2efd69195f4a5fc584a0eaecc599ca4c2c;hp=d9efc37393eebb0ad0e82086e47795492dff110c;hpb=d18f83764e376dea9e14a8ac53d1e14004fa9c13;p=safe%2Fjmp%2Flinux-2.6 diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c index d9efc37..dede954 100644 --- a/sound/arm/pxa2xx-ac97.c +++ b/sound/arm/pxa2xx-ac97.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -33,45 +33,53 @@ #include "pxa2xx-pcm.h" -static DECLARE_MUTEX(car_mutex); +static DEFINE_MUTEX(car_mutex); static DECLARE_WAIT_QUEUE_HEAD(gsr_wq); static volatile long gsr_bits; +/* + * Beware PXA27x bugs: + * + * o Slot 12 read from modem space will hang controller. + * o CDONE, SDONE interrupt fails after any slot 12 IO. + * + * We therefore have an hybrid approach for waiting on SDONE (interrupt or + * 1 jiffy timeout if interrupt never comes). + */ + static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg) { unsigned short val = -1; volatile u32 *reg_addr; - down(&car_mutex); - if (CAR & CAR_CAIP) { - printk(KERN_CRIT"%s: CAR_CAIP already set\n", __FUNCTION__); - goto out; - } + mutex_lock(&car_mutex); /* set up primary or secondary codec space */ reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE; reg_addr += (reg >> 1); /* start read access across the ac97 link */ + GSR = GSR_CDONE | GSR_SDONE; gsr_bits = 0; val = *reg_addr; if (reg == AC97_GPIO_STATUS) goto out; - wait_event_timeout(gsr_wq, gsr_bits & GSR_SDONE, 1); - if (!gsr_bits & GSR_SDONE) { + if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && + !((GSR | gsr_bits) & GSR_SDONE)) { printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", - __FUNCTION__, reg, gsr_bits); + __FUNCTION__, reg, GSR | gsr_bits); val = -1; goto out; } /* valid data now */ + GSR = GSR_CDONE | GSR_SDONE; gsr_bits = 0; val = *reg_addr; /* but we've just started another cycle... */ - wait_event_timeout(gsr_wq, gsr_bits & GSR_SDONE, 1); + wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); -out: up(&car_mutex); +out: mutex_unlock(&car_mutex); return val; } @@ -79,24 +87,21 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigne { volatile u32 *reg_addr; - down(&car_mutex); - - if (CAR & CAR_CAIP) { - printk(KERN_CRIT "%s: CAR_CAIP already set\n", __FUNCTION__); - goto out; - } + mutex_lock(&car_mutex); /* set up primary or secondary codec space */ reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE; reg_addr += (reg >> 1); + + GSR = GSR_CDONE | GSR_SDONE; gsr_bits = 0; *reg_addr = val; - wait_event_timeout(gsr_wq, gsr_bits & GSR_CDONE, 1); - if (!gsr_bits & GSR_SDONE) + if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && + !((GSR | gsr_bits) & GSR_CDONE)) printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", - __FUNCTION__, reg, gsr_bits); + __FUNCTION__, reg, GSR | gsr_bits); -out: up(&car_mutex); + mutex_unlock(&car_mutex); } static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) @@ -147,7 +152,7 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) GCR |= GCR_SDONE_IE|GCR_CDONE_IE; } -static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id, struct pt_regs *regs) +static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id) { long status; @@ -247,30 +252,28 @@ static struct pxa2xx_pcm_client pxa2xx_ac97_pcm_client = { static int pxa2xx_ac97_do_suspend(struct snd_card *card, pm_message_t state) { - if (card->power_state != SNDRV_CTL_POWER_D3cold) { - pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; - snd_pcm_suspend_all(pxa2xx_ac97_pcm); - snd_ac97_suspend(pxa2xx_ac97_ac97); - snd_power_change_state(card, SNDRV_CTL_POWER_D3cold); - if (platform_ops && platform_ops->suspend) - platform_ops->suspend(platform_ops->priv); - GCR |= GCR_ACLINK_OFF; - pxa_set_cken(CKEN2_AC97, 0); - } + pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; + + snd_power_change_state(card, SNDRV_CTL_POWER_D3cold); + snd_pcm_suspend_all(pxa2xx_ac97_pcm); + snd_ac97_suspend(pxa2xx_ac97_ac97); + if (platform_ops && platform_ops->suspend) + platform_ops->suspend(platform_ops->priv); + GCR |= GCR_ACLINK_OFF; + pxa_set_cken(CKEN2_AC97, 0); return 0; } static int pxa2xx_ac97_do_resume(struct snd_card *card) { - if (card->power_state != SNDRV_CTL_POWER_D0) { - pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; - pxa_set_cken(CKEN2_AC97, 1); - if (platform_ops && platform_ops->resume) - platform_ops->resume(platform_ops->priv); - snd_ac97_resume(pxa2xx_ac97_ac97); - snd_power_change_state(card, SNDRV_CTL_POWER_D0); - } + pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; + + pxa_set_cken(CKEN2_AC97, 1); + if (platform_ops && platform_ops->resume) + platform_ops->resume(platform_ops->priv); + snd_ac97_resume(pxa2xx_ac97_ac97); + snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } @@ -349,8 +352,6 @@ static int pxa2xx_ac97_probe(struct platform_device *dev) snprintf(card->longname, sizeof(card->longname), "%s (%s)", dev->dev.driver->name, card->mixername); - snd_card_set_pm_callback(card, pxa2xx_ac97_do_suspend, - pxa2xx_ac97_do_resume, NULL); ret = snd_card_register(card); if (ret == 0) { platform_set_drvdata(dev, card);