pandora: reserve CMA area for c64_tools
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3pandora.c
index c6ec4b6..6f98ba0 100644 (file)
@@ -37,6 +37,8 @@
 #include <linux/mmc/card.h>
 #include <linux/regulator/fixed.h>
 #include <linux/i2c/vsense.h>
+#include <linux/dma-mapping.h>
+#include <linux/dma-contiguous.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -52,6 +54,7 @@
 
 #include "mux.h"
 #include "sdram-micron-mt46h32m32lf-6.h"
+#include "sdram-micron-mt29c4g96mazapcjg-5.h"
 #include "hsmmc.h"
 #include "common-board-devices.h"
 
@@ -91,6 +94,7 @@ static struct omap_nand_platform_data pandora_nand_data = {
        .xfer_type      = NAND_OMAP_PREFETCH_DMA,
        .parts          = omap3pandora_nand_partitions,
        .nr_parts       = ARRAY_SIZE(omap3pandora_nand_partitions),
+       .dev_ready      = true,
 };
 
 static struct gpio_led pandora_gpio_leds[] = {
@@ -130,10 +134,11 @@ static struct led_pwm pandora_pwm_leds[] = {
                .pwm_id                 = 0, /* LEDA */
        }, {
                .name                   = "pandora::power",
+               .default_trigger        = "default-on",
                .pwm_id                 = 1, /* LEDB */
        }, {
                .name                   = "pandora::charger",
-               .default_trigger        = "bq27500-0-charging",
+               .default_trigger        = "twl4030_bci-charging",
                .pwm_id                 = 3, /* PWM1 */
        }
 };
@@ -345,7 +350,7 @@ static void pandora_wl1251_init_card(struct mmc_card *card)
        card->cis.vendor = 0x104c;
        card->cis.device = 0x9066;
        card->cis.blksize = 512;
-       card->cis.max_dtr = 20000000;
+       card->cis.max_dtr = 24000000;
 }
 
 static struct omap2_hsmmc_info omap3pandora_mmc[] = {
@@ -353,14 +358,16 @@ static struct omap2_hsmmc_info omap3pandora_mmc[] = {
                .mmc            = 1,
                .caps           = MMC_CAP_4_BIT_DATA,
                .gpio_cd        = -EINVAL,
-               .gpio_wp        = 126,
+               //.gpio_wp      = 126,
+               .gpio_wp        = -EINVAL,
                .ext_clock      = 0,
        },
        {
                .mmc            = 2,
                .caps           = MMC_CAP_4_BIT_DATA,
                .gpio_cd        = -EINVAL,
-               .gpio_wp        = 127,
+               //.gpio_wp      = 127,
+               .gpio_wp        = -EINVAL,
                .ext_clock      = 1,
                .transceiver    = true,
        },
@@ -425,7 +432,7 @@ static struct regulator_consumer_supply pandora_vcc_lcd_supply[] = {
 };
 
 static struct regulator_consumer_supply pandora_usb_phy_supply[] = {
-       REGULATOR_SUPPLY("hsusb0", "ehci-omap.0"),
+       REGULATOR_SUPPLY("hsusb1", "ehci-omap.0"),
 };
 
 /* ads7846 on SPI and 2 nub controllers on I2C */
@@ -437,6 +444,7 @@ static struct regulator_consumer_supply pandora_vaux4_supplies[] = {
 
 static struct regulator_consumer_supply pandora_adac_supply[] = {
        REGULATOR_SUPPLY("vcc", "soc-audio"),
+       REGULATOR_SUPPLY("lidsw", NULL),
 };
 
 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
@@ -502,8 +510,8 @@ static struct regulator_init_data pandora_vaux2 = {
 /* VAUX4 for ads7846 and nubs */
 static struct regulator_init_data pandora_vaux4 = {
        .constraints = {
-               .min_uV                 = 2800000,
-               .max_uV                 = 2800000,
+               .min_uV                 = 3000000,
+               .max_uV                 = 3000000,
                .apply_uV               = true,
                .valid_modes_mask       = REGULATOR_MODE_NORMAL
                                        | REGULATOR_MODE_STANDBY,
@@ -684,34 +692,203 @@ static void __init pandora_usb_host_init(void)
                pr_err("Cannot set vbus GPIO, ret=%d\n", ret);
 }
 
+#include <linux/spi/ads7846.h>
+#include <asm/system.h>
+
+static DECLARE_COMPLETION(ts_completion);
+static struct timespec ts_last_framedone;
+static int pendown_state;
+
+static void vsync_irq_wait_handler(void *data, u32 mask)
+{
+       getnstimeofday(&ts_last_framedone);
+
+       /* reliable to read here */
+       pendown_state = !gpio_get_value(OMAP3_PANDORA_TS_GPIO);
+
+       complete(&ts_completion);
+}
+
+static void ads7846_wait_for_sync(void)
+{
+       struct timespec now, diff;
+       u32 diff_us;
+
+       getnstimeofday(&now);
+       diff = timespec_sub(now, ts_last_framedone);
+       diff_us = diff.tv_nsec / NSEC_PER_USEC + diff.tv_sec * USEC_PER_SEC;
+       if (diff_us < 1023 || diff_us > 40000)
+               /* still blanking or display inactive */
+               return;
+
+       /* wait for blanking period */
+       disable_hlt();
+       wait_for_completion_timeout(&ts_completion, HZ / 30);
+       enable_hlt();
+}
+
+static int pandora_pendown_state(void)
+{
+       static int val_old;
+       struct timespec now, diff;
+       u32 diff_us;
+       int val;
+       int ret;
+       
+       /* This line is a noisy mess. It doesn't trigger spuriously, i.e.
+        * there is no signal when pen is up, but when it's down we have
+        * white noise of sorts. */
+       val = !gpio_get_value(OMAP3_PANDORA_TS_GPIO);
+       pendown_state |= val;
+
+       if (in_irq() || in_atomic())
+               /* no time to fight noise.. */
+               return val | pendown_state;
+
+       if (val == 0) {
+               getnstimeofday(&now);
+               diff = timespec_sub(now, ts_last_framedone);
+               diff_us = diff.tv_nsec / NSEC_PER_USEC + diff.tv_sec * USEC_PER_SEC;
+
+               if (diff_us < 40000)
+                       /* assume pendown_state is up-to-date */
+                       val = pendown_state;
+               else
+                       pendown_state = 0;
+       }
+
+       if (val != val_old) {
+               init_completion(&ts_completion);
+               dispc_runtime_get();
+               if (val)
+                       ret = omap_dispc_register_isr(vsync_irq_wait_handler,
+                               NULL, DISPC_IRQ_VSYNC);
+               else
+                       ret = omap_dispc_unregister_isr(vsync_irq_wait_handler,
+                               NULL, DISPC_IRQ_VSYNC);
+               dispc_runtime_put();
+               if (ret != 0)
+                       pr_err("%s: can't (un)register isr: %d %d\n",
+                               __func__, val, ret);
+               val_old = val;
+       }
+
+       return val;
+}
+
+static struct ads7846_platform_data pandora_ads7846_cfg = {
+       .x_max                  = 0x0fff,
+       .y_max                  = 0x0fff,
+       .x_plate_ohms           = 180,
+       .pressure_max           = 255,
+       .debounce_max           = 10,
+       .debounce_tol           = 3,
+       .debounce_rep           = 1,
+       .gpio_pendown           = OMAP3_PANDORA_TS_GPIO,
+       .keep_vref_on           = 1,
+       .wait_for_sync          = ads7846_wait_for_sync,
+       .get_pendown_state      = pandora_pendown_state,
+};
+
+static struct platform_device pandora_ram_console = {
+       .name   = "ram_console",
+       .id     = -1,
+};
+
+static struct platform_device pandora_c64_tools = {
+       .name   = "c64_tools",
+       .dev    = {
+               .coherent_dma_mask = DMA_BIT_MASK(32),
+       },
+};
+
 static struct platform_device *omap3pandora_devices[] __initdata = {
        &pandora_leds_gpio,
        &pandora_leds_pwm,
        &pandora_bl,
        &pandora_keys_gpio,
        &pandora_vwlan_device,
+       &pandora_ram_console,
+       &pandora_c64_tools,
 };
 
 static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
 
-       .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
-       .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED,
+       .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
+       .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
        .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
 
        .phy_reset  = true,
-       .reset_gpio_port[0]  = 16,
-       .reset_gpio_port[1]  = -EINVAL,
+       .reset_gpio_port[0]  = -EINVAL,
+       .reset_gpio_port[1]  = 16,
        .reset_gpio_port[2]  = -EINVAL
 };
 
 #ifdef CONFIG_OMAP_MUX
 static struct omap_board_mux board_mux[] __initdata = {
+       /* enable wakeup for pandora button (GPIO99) */
+       OMAP3_MUX(CAM_D0, OMAP_INPUT_EN | OMAP_WAKEUP_EN | OMAP_MUX_MODE4),
+       /* noisy unused signal from LCD cable */
+       OMAP3_MUX(CAM_VS, OMAP_INPUT_EN | OMAP_PULL_ENA | OMAP_PULL_UP | OMAP_MUX_MODE7),
        { .reg_offset = OMAP_MUX_TERMINATOR },
 };
 #endif
 
+static struct regulator *lid_switch_power;
+
+#ifdef CONFIG_PM_SLEEP
+static int pandora_pm_suspend(struct device *dev)
+{
+       if (!IS_ERR_OR_NULL(lid_switch_power))
+               regulator_disable(lid_switch_power);
+
+       return 0;
+}
+
+static int pandora_pm_resume(struct device *dev)
+{
+       if (!IS_ERR_OR_NULL(lid_switch_power))
+               regulator_enable(lid_switch_power);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(pandora_pm, pandora_pm_suspend, pandora_pm_resume);
+
+static int __devinit pandora_pm_probe(struct platform_device *pdev)
+{
+       lid_switch_power = regulator_get(NULL, "lidsw");
+       if (!IS_ERR(lid_switch_power))
+               regulator_enable(lid_switch_power);
+
+       return 0;
+}
+
+static struct platform_driver pandora_pm_driver = {
+       .probe          = pandora_pm_probe,
+       .driver         = {
+               .name   = "pandora-pm",
+               .pm     = &pandora_pm,
+       },
+};
+
+static struct platform_device pandora_pm_dev = {
+       .name   = "pandora-pm",
+       .id     = -1,
+};
+
+static int __init pandora_pm_drv_reg(void)
+{
+       platform_device_register(&pandora_pm_dev);
+       return platform_driver_register(&pandora_pm_driver);
+}
+late_initcall(pandora_pm_drv_reg);
+
 static void __init omap3pandora_init(void)
 {
+       struct omap_sdrc_params *sdrc_params;
+
        omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
        pandora_usb_host_init();
        omap3pandora_i2c_init();
@@ -720,11 +897,15 @@ static void __init omap3pandora_init(void)
                        ARRAY_SIZE(omap3pandora_devices));
        omap_display_init(&pandora_dss_data);
        omap_serial_init();
-       omap_sdrc_init(mt46h32m32lf6_sdrc_params,
-                                 mt46h32m32lf6_sdrc_params);
+
+       sdrc_params = mt46h32m32lf6_sdrc_params;
+       if (cpu_is_omap3630() || omap_rev() >= OMAP3430_REV_ES3_0)
+               sdrc_params = mt29c4g96mazapcjg5_sdrc_params;
+       omap_sdrc_init(sdrc_params, sdrc_params);
+
        spi_register_board_info(omap3pandora_spi_board_info,
                        ARRAY_SIZE(omap3pandora_spi_board_info));
-       omap_ads7846_init(1, OMAP3_PANDORA_TS_GPIO, 0, NULL);
+       omap_ads7846_init(1, OMAP3_PANDORA_TS_GPIO, 31, &pandora_ads7846_cfg);
        usbhs_init(&usbhs_bdata);
        usb_musb_init(NULL);
        gpmc_nand_init(&pandora_nand_data);
@@ -750,9 +931,33 @@ static int __init proc_pandora_init(void)
 fs_initcall(proc_pandora_init);
 #endif
 
+/* for debug.. */
+#include <../drivers/staging/android/persistent_ram.h>
+
+struct persistent_ram_descriptor ram_console_desc = {
+       .name           = "ram_console",
+       .size           = 0x20000,
+};
+
+struct persistent_ram ram_console_ram = {
+       .start          = 0x80fe0000,
+       .size           = 0x20000,
+       .num_descs      = 1,
+       .descs          = &ram_console_desc,
+};
+
+void __init pandora_reserve(void)
+{
+       omap_reserve();
+       dma_declare_contiguous(&pandora_c64_tools.dev, 4 * SZ_1M, 0x86000000, 0);
+#ifdef CONFIG_ANDROID_PERSISTENT_RAM
+       persistent_ram_early_init(&ram_console_ram);
+#endif
+}
+
 MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
        .atag_offset    = 0x100,
-       .reserve        = omap_reserve,
+       .reserve        = pandora_reserve,
        .map_io         = omap3_map_io,
        .init_early     = omap35xx_init_early,
        .init_irq       = omap3_init_irq,