Input: psmouse - fix breakage introduced by b7802c5c1ea
[safe/jmp/linux-2.6] / sound / arm / pxa2xx-ac97-lib.c
index 95f8ead..6fdca97 100644 (file)
@@ -21,8 +21,7 @@
 #include <sound/pxa2xx-lib.h>
 
 #include <asm/irq.h>
-#include <mach/hardware.h>
-#include <mach/pxa-regs.h>
+#include <mach/regs-ac97.h>
 #include <mach/pxa2xx-gpio.h>
 #include <mach/audio.h>
 
@@ -30,9 +29,8 @@ static DEFINE_MUTEX(car_mutex);
 static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
 static volatile long gsr_bits;
 static struct clk *ac97_clk;
-#ifdef CONFIG_PXA27x
 static struct clk *ac97conf_clk;
-#endif
+static int reset_gpio;
 
 /*
  * Beware PXA27x bugs:
@@ -44,6 +42,45 @@ static struct clk *ac97conf_clk;
  * 1 jiffy timeout if interrupt never comes).
  */
 
+enum {
+       RESETGPIO_FORCE_HIGH,
+       RESETGPIO_FORCE_LOW,
+       RESETGPIO_NORMAL_ALTFUNC
+};
+
+/**
+ * set_resetgpio_mode - computes and sets the AC97_RESET gpio mode on PXA
+ * @mode: chosen action
+ *
+ * As the PXA27x CPUs suffer from a AC97 bug, a manual control of the reset line
+ * must be done to insure proper work of AC97 reset line.  This function
+ * computes the correct gpio_mode for further use by reset functions, and
+ * applied the change through pxa_gpio_mode.
+ */
+static void set_resetgpio_mode(int resetgpio_action)
+{
+       int mode = 0;
+
+       if (reset_gpio)
+               switch (resetgpio_action) {
+               case RESETGPIO_NORMAL_ALTFUNC:
+                       if (reset_gpio == 113)
+                               mode = 113 | GPIO_ALT_FN_2_OUT;
+                       if (reset_gpio == 95)
+                               mode = 95 | GPIO_ALT_FN_1_OUT;
+                       break;
+               case RESETGPIO_FORCE_LOW:
+                       mode = reset_gpio | GPIO_OUT | GPIO_DFLT_LOW;
+                       break;
+               case RESETGPIO_FORCE_HIGH:
+                       mode = reset_gpio | GPIO_OUT | GPIO_DFLT_HIGH;
+                       break;
+               };
+
+       if (mode)
+               pxa_gpio_mode(mode);
+}
+
 unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
 {
        unsigned short val = -1;
@@ -52,14 +89,10 @@ unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
        mutex_lock(&car_mutex);
 
        /* set up primary or secondary codec space */
-#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
-       reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE;
-#else
-       if (reg == AC97_GPIO_STATUS)
+       if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
                reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE;
        else
                reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
-#endif
        reg_addr += (reg >> 1);
 
        /* start read access across the ac97 link */
@@ -96,14 +129,10 @@ void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
        mutex_lock(&car_mutex);
 
        /* set up primary or secondary codec space */
-#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
-       reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE;
-#else
-       if (reg == AC97_GPIO_STATUS)
+       if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
                reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE;
        else
                reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
-#endif
        reg_addr += (reg >> 1);
 
        GSR = GSR_CDONE | GSR_SDONE;
@@ -118,45 +147,73 @@ void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
 }
 EXPORT_SYMBOL_GPL(pxa2xx_ac97_write);
 
-bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
+#ifdef CONFIG_PXA25x
+static inline void pxa_ac97_warm_pxa25x(void)
 {
-#ifdef CONFIG_PXA3xx
-       int timeout = 100;
-#endif
        gsr_bits = 0;
 
+       GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN;
+       wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
+}
+
+static inline void pxa_ac97_cold_pxa25x(void)
+{
+       GCR &=  GCR_COLD_RST;  /* clear everything but nCRST */
+       GCR &= ~GCR_COLD_RST;  /* then assert nCRST */
+
+       gsr_bits = 0;
+
+       GCR = GCR_COLD_RST;
+       GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
+       wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
+}
+#endif
+
 #ifdef CONFIG_PXA27x
+static inline void pxa_ac97_warm_pxa27x(void)
+{
+       gsr_bits = 0;
+
        /* warm reset broken on Bulverde,
           so manually keep AC97 reset high */
-       pxa_gpio_mode(113 | GPIO_OUT | GPIO_DFLT_HIGH);
+       set_resetgpio_mode(RESETGPIO_FORCE_HIGH);
        udelay(10);
        GCR |= GCR_WARM_RST;
-       pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
+       set_resetgpio_mode(RESETGPIO_NORMAL_ALTFUNC);
        udelay(500);
-#elif defined(CONFIG_PXA3xx)
-       /* Can't use interrupts */
-       GCR |= GCR_WARM_RST;
-       while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
-               mdelay(1);
-#else
-       GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN;
-       wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
+}
+
+static inline void pxa_ac97_cold_pxa27x(void)
+{
+       GCR &=  GCR_COLD_RST;  /* clear everything but nCRST */
+       GCR &= ~GCR_COLD_RST;  /* then assert nCRST */
+
+       gsr_bits = 0;
+
+       /* PXA27x Developers Manual section 13.5.2.2.1 */
+       clk_enable(ac97conf_clk);
+       udelay(5);
+       clk_disable(ac97conf_clk);
+       GCR = GCR_COLD_RST;
+       udelay(50);
+}
 #endif
 
-       if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
-               printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
-                                __func__, gsr_bits);
+#ifdef CONFIG_PXA3xx
+static inline void pxa_ac97_warm_pxa3xx(void)
+{
+       int timeout = 100;
 
-               return false;
-       }
+       gsr_bits = 0;
 
-       return true;
+       /* Can't use interrupts */
+       GCR |= GCR_WARM_RST;
+       while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
+               mdelay(1);
 }
-EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset);
 
-bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
+static inline void pxa_ac97_cold_pxa3xx(void)
 {
-#ifdef CONFIG_PXA3xx
        int timeout = 1000;
 
        /* Hold CLKBPB for 100us */
@@ -164,35 +221,78 @@ bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
        GCR = GCR_CLKBPB;
        udelay(100);
        GCR = 0;
-#endif
 
        GCR &=  GCR_COLD_RST;  /* clear everything but nCRST */
        GCR &= ~GCR_COLD_RST;  /* then assert nCRST */
 
        gsr_bits = 0;
-#ifdef CONFIG_PXA27x
-       /* PXA27x Developers Manual section 13.5.2.2.1 */
-       clk_enable(ac97conf_clk);
-       udelay(5);
-       clk_disable(ac97conf_clk);
-       GCR = GCR_COLD_RST;
-       udelay(50);
-#elif defined(CONFIG_PXA3xx)
+
        /* Can't use interrupts on PXA3xx */
        GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
 
        GCR = GCR_WARM_RST | GCR_COLD_RST;
        while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
                mdelay(10);
-#else
-       GCR = GCR_COLD_RST;
-       GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
-       wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
+}
 #endif
 
-       if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
+bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
+{
+       unsigned long gsr;
+
+#ifdef CONFIG_PXA25x
+       if (cpu_is_pxa25x())
+               pxa_ac97_warm_pxa25x();
+       else
+#endif
+#ifdef CONFIG_PXA27x
+       if (cpu_is_pxa27x())
+               pxa_ac97_warm_pxa27x();
+       else
+#endif
+#ifdef CONFIG_PXA3xx
+       if (cpu_is_pxa3xx())
+               pxa_ac97_warm_pxa3xx();
+       else
+#endif
+               BUG();
+       gsr = GSR | gsr_bits;
+       if (!(gsr & (GSR_PCR | GSR_SCR))) {
+               printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
+                                __func__, gsr);
+
+               return false;
+       }
+
+       return true;
+}
+EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset);
+
+bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
+{
+       unsigned long gsr;
+
+#ifdef CONFIG_PXA25x
+       if (cpu_is_pxa25x())
+               pxa_ac97_cold_pxa25x();
+       else
+#endif
+#ifdef CONFIG_PXA27x
+       if (cpu_is_pxa27x())
+               pxa_ac97_cold_pxa27x();
+       else
+#endif
+#ifdef CONFIG_PXA3xx
+       if (cpu_is_pxa3xx())
+               pxa_ac97_cold_pxa3xx();
+       else
+#endif
+               BUG();
+
+       gsr = GSR | gsr_bits;
+       if (!(gsr & (GSR_PCR | GSR_SCR))) {
                printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
-                                __func__, gsr_bits);
+                                __func__, gsr);
 
                return false;
        }
@@ -219,14 +319,14 @@ static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id)
                gsr_bits |= status;
                wake_up(&gsr_wq);
 
-#ifdef CONFIG_PXA27x
                /* Although we don't use those we still need to clear them
                   since they tend to spuriously trigger when MMC is used
                   (hardware bug? go figure)... */
-               MISR = MISR_EOC;
-               PISR = PISR_EOC;
-               MCSR = MCSR_EOC;
-#endif
+               if (cpu_is_pxa27x()) {
+                       MISR = MISR_EOC;
+                       PISR = PISR_EOC;
+                       MCSR = MCSR_EOC;
+               }
 
                return IRQ_HANDLED;
        }
@@ -245,14 +345,16 @@ EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_suspend);
 
 int pxa2xx_ac97_hw_resume(void)
 {
-       pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
-       pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
-       pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
-       pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
-#ifdef CONFIG_PXA27x
-       /* Use GPIO 113 as AC97 Reset on Bulverde */
-       pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
-#endif
+       if (cpu_is_pxa25x() || cpu_is_pxa27x()) {
+               pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
+               pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
+               pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
+               pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
+       }
+       if (cpu_is_pxa27x()) {
+               /* Use GPIO 113 or 95 as AC97 Reset on Bulverde */
+               set_resetgpio_mode(RESETGPIO_NORMAL_ALTFUNC);
+       }
        clk_enable(ac97_clk);
        return 0;
 }
@@ -262,45 +364,74 @@ EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_resume);
 int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev)
 {
        int ret;
+       pxa2xx_audio_ops_t *pdata = dev->dev.platform_data;
+
+       if (pdata) {
+               switch (pdata->reset_gpio) {
+               case 95:
+               case 113:
+                       reset_gpio = pdata->reset_gpio;
+                       break;
+               case 0:
+                       reset_gpio = 113;
+                       break;
+               case -1:
+                       break;
+               default:
+                       dev_err(&dev->dev, "Invalid reset GPIO %d\n",
+                               pdata->reset_gpio);
+               }
+       } else {
+               if (cpu_is_pxa27x())
+                       reset_gpio = 113;
+       }
 
-       ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL);
-       if (ret < 0)
-               goto err;
+       if (cpu_is_pxa25x() || cpu_is_pxa27x()) {
+               pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
+               pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
+               pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
+               pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
+       }
 
-       pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
-       pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
-       pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
-       pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
-#ifdef CONFIG_PXA27x
-       /* Use GPIO 113 as AC97 Reset on Bulverde */
-       pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
-       ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
-       if (IS_ERR(ac97conf_clk)) {
-               ret = PTR_ERR(ac97conf_clk);
-               ac97conf_clk = NULL;
-               goto err_irq;
+       if (cpu_is_pxa27x()) {
+               /* Use GPIO 113 as AC97 Reset on Bulverde */
+               set_resetgpio_mode(RESETGPIO_NORMAL_ALTFUNC);
+               ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
+               if (IS_ERR(ac97conf_clk)) {
+                       ret = PTR_ERR(ac97conf_clk);
+                       ac97conf_clk = NULL;
+                       goto err_conf;
+               }
        }
-#endif
 
        ac97_clk = clk_get(&dev->dev, "AC97CLK");
        if (IS_ERR(ac97_clk)) {
                ret = PTR_ERR(ac97_clk);
                ac97_clk = NULL;
-               goto err_irq;
+               goto err_clk;
        }
 
-       return clk_enable(ac97_clk);
+       ret = clk_enable(ac97_clk);
+       if (ret)
+               goto err_clk2;
+
+       ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, IRQF_DISABLED, "AC97", NULL);
+       if (ret < 0)
+               goto err_irq;
+
+       return 0;
 
 err_irq:
        GCR |= GCR_ACLINK_OFF;
-#ifdef CONFIG_PXA27x
+err_clk2:
+       clk_put(ac97_clk);
+       ac97_clk = NULL;
+err_clk:
        if (ac97conf_clk) {
                clk_put(ac97conf_clk);
                ac97conf_clk = NULL;
        }
-#endif
-       free_irq(IRQ_AC97, NULL);
-err:
+err_conf:
        return ret;
 }
 EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_probe);
@@ -309,10 +440,10 @@ void pxa2xx_ac97_hw_remove(struct platform_device *dev)
 {
        GCR |= GCR_ACLINK_OFF;
        free_irq(IRQ_AC97, NULL);
-#ifdef CONFIG_PXA27x
-       clk_put(ac97conf_clk);
-       ac97conf_clk = NULL;
-#endif
+       if (ac97conf_clk) {
+               clk_put(ac97conf_clk);
+               ac97conf_clk = NULL;
+       }
        clk_disable(ac97_clk);
        clk_put(ac97_clk);
        ac97_clk = NULL;