Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / arch / arm / mach-pxa / pxa25x.c
index 6dfcca7..9732d5d 100644 (file)
@@ -20,7 +20,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/pm.h>
+#include <linux/suspend.h>
 
 #include <asm/hardware.h>
 #include <asm/arch/irqs.h>
@@ -30,6 +30,7 @@
 
 #include "generic.h"
 #include "devices.h"
+#include "clock.h"
 
 /*
  * Various clock factors driven by the CCCR register.
@@ -53,7 +54,7 @@ static unsigned char N2_clk_mult[8] = { 0, 0, 2, 3, 4, 0, 6, 0 };
  * We assume these values have been applied via a fcs.
  * If info is not 0 we also display the current settings.
  */
-unsigned int get_clk_frequency_khz(int info)
+unsigned int pxa25x_get_clk_frequency_khz(int info)
 {
        unsigned long cccr, turbo;
        unsigned int l, L, m, M, n2, N;
@@ -86,27 +87,48 @@ unsigned int get_clk_frequency_khz(int info)
        return (turbo & 1) ? (N/1000) : (M/1000);
 }
 
-EXPORT_SYMBOL(get_clk_frequency_khz);
-
 /*
  * Return the current memory clock frequency in units of 10kHz
  */
-unsigned int get_memclk_frequency_10khz(void)
+unsigned int pxa25x_get_memclk_frequency_10khz(void)
 {
        return L_clk_mult[(CCCR >> 0) & 0x1f] * BASE_CLK / 10000;
 }
 
-EXPORT_SYMBOL(get_memclk_frequency_10khz);
-
-/*
- * Return the current LCD clock frequency in units of 10kHz
- */
-unsigned int get_lcdclk_frequency_10khz(void)
+static unsigned long clk_pxa25x_lcd_getrate(struct clk *clk)
 {
-       return get_memclk_frequency_10khz();
+       return pxa25x_get_memclk_frequency_10khz() * 10000;
 }
 
-EXPORT_SYMBOL(get_lcdclk_frequency_10khz);
+static const struct clkops clk_pxa25x_lcd_ops = {
+       .enable         = clk_cken_enable,
+       .disable        = clk_cken_disable,
+       .getrate        = clk_pxa25x_lcd_getrate,
+};
+
+/*
+ * 3.6864MHz -> OST, GPIO, SSP, PWM, PLLs (95.842MHz, 147.456MHz)
+ * 95.842MHz -> MMC 19.169MHz, I2C 31.949MHz, FICP 47.923MHz, USB 47.923MHz
+ * 147.456MHz -> UART 14.7456MHz, AC97 12.288MHz, I2S 5.672MHz (allegedly)
+ */
+static struct clk pxa25x_clks[] = {
+       INIT_CK("LCDCLK", LCD, &clk_pxa25x_lcd_ops, &pxa_device_fb.dev),
+       INIT_CKEN("UARTCLK", FFUART, 14745600, 1, &pxa_device_ffuart.dev),
+       INIT_CKEN("UARTCLK", BTUART, 14745600, 1, &pxa_device_btuart.dev),
+       INIT_CKEN("UARTCLK", BTUART, 14745600, 1, &pxa_device_btuart.dev),
+       INIT_CKEN("UARTCLK", STUART, 14745600, 1, NULL),
+       INIT_CKEN("UDCCLK", USB, 47923000, 5, &pxa_device_udc.dev),
+       INIT_CKEN("MMCCLK", MMC, 19169000, 0, &pxa_device_mci.dev),
+       INIT_CKEN("I2CCLK", I2C, 31949000, 0, &pxa_device_i2c.dev),
+       /*
+       INIT_CKEN("PWMCLK",  PWM0, 3686400,  0, NULL),
+       INIT_CKEN("PWMCLK",  PWM0, 3686400,  0, NULL),
+       INIT_CKEN("SSPCLK",  SSP,  3686400,  0, NULL),
+       INIT_CKEN("I2SCLK",  I2S,  14745600, 0, NULL),
+       INIT_CKEN("NSSPCLK", NSSP, 3686400,  0, NULL),
+       */
+       INIT_CKEN("FICPCLK", FICP, 47923000, 0, NULL),
+};
 
 #ifdef CONFIG_PM
 
@@ -156,13 +178,19 @@ static void pxa25x_cpu_pm_save(unsigned long *sleep_save)
        SAVE(GAFR1_L); SAVE(GAFR1_U);
        SAVE(GAFR2_L); SAVE(GAFR2_U);
 
-       SAVE(ICMR);
+       SAVE(ICMR); ICMR = 0;
        SAVE(CKEN);
        SAVE(PSTR);
+
+       /* Clear GPIO transition detect bits */
+       GEDR0 = GEDR0; GEDR1 = GEDR1; GEDR2 = GEDR2;
 }
 
 static void pxa25x_cpu_pm_restore(unsigned long *sleep_save)
 {
+       /* ensure not to come back here if it wasn't intended */
+       PSPR = 0;
+
        /* restore registers */
        RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1); RESTORE_GPLEVEL(2);
        RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2);
@@ -173,7 +201,12 @@ static void pxa25x_cpu_pm_restore(unsigned long *sleep_save)
        RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2);
        RESTORE(PGSR0); RESTORE(PGSR1); RESTORE(PGSR2);
 
+       PSSR = PSSR_RDH | PSSR_PH;
+
        RESTORE(CKEN);
+
+       ICLR = 0;
+       ICCR = 1;
        RESTORE(ICMR);
        RESTORE(PSTR);
 }
@@ -193,7 +226,7 @@ static void pxa25x_cpu_pm_enter(suspend_state_t state)
 
 static struct pxa_cpu_pm_fns pxa25x_cpu_pm_fns = {
        .save_size      = SLEEP_SAVE_SIZE,
-       .valid          = pm_valid_only_mem,
+       .valid          = suspend_valid_only_mem,
        .save           = pxa25x_cpu_pm_save,
        .restore        = pxa25x_cpu_pm_restore,
        .enter          = pxa25x_cpu_pm_enter,
@@ -205,10 +238,52 @@ static void __init pxa25x_init_pm(void)
 }
 #endif
 
+/* PXA25x: supports wakeup from GPIO0..GPIO15 and RTC alarm
+ */
+
+static int pxa25x_set_wake(unsigned int irq, unsigned int on)
+{
+       int gpio = IRQ_TO_GPIO(irq);
+       uint32_t gpio_bit, mask = 0;
+
+       if (gpio >= 0 && gpio <= 15) {
+               gpio_bit = GPIO_bit(gpio);
+               mask = gpio_bit;
+               if (on) {
+                       if (GRER(gpio) | gpio_bit)
+                               PRER |= gpio_bit;
+                       else
+                               PRER &= ~gpio_bit;
+
+                       if (GFER(gpio) | gpio_bit)
+                               PFER |= gpio_bit;
+                       else
+                               PFER &= ~gpio_bit;
+               }
+               goto set_pwer;
+       }
+
+       if (irq == IRQ_RTCAlrm) {
+               mask = PWER_RTC;
+               goto set_pwer;
+       }
+
+       return -EINVAL;
+
+set_pwer:
+       if (on)
+               PWER |= mask;
+       else
+               PWER &=~mask;
+
+       return 0;
+}
+
 void __init pxa25x_init_irq(void)
 {
        pxa_init_irq_low();
        pxa_init_irq_gpio(85);
+       pxa_init_irq_set_wake(pxa25x_set_wake);
 }
 
 static struct platform_device *pxa25x_devices[] __initdata = {
@@ -229,6 +304,8 @@ static int __init pxa25x_init(void)
        int ret = 0;
 
        if (cpu_is_pxa21x() || cpu_is_pxa25x()) {
+               clks_register(pxa25x_clks, ARRAY_SIZE(pxa25x_clks));
+
                if ((ret = pxa_init_dma(16)))
                        return ret;
 #ifdef CONFIG_PM