Merge branch 'linux_next' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3pandora.c
index 9b62b62..89ed1be 100644 (file)
 #include <linux/regulator/machine.h>
 #include <linux/i2c/twl.h>
 #include <linux/wl12xx.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/nand.h>
 #include <linux/leds.h>
 #include <linux/input.h>
 #include <linux/input/matrix_keypad.h>
 #include <linux/gpio_keys.h>
+#include <linux/mmc/host.h>
+#include <linux/mmc/card.h>
+#include <linux/regulator/fixed.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <plat/mcspi.h>
 #include <plat/usb.h>
 #include <plat/display.h>
+#include <plat/nand.h>
 
 #include "mux.h"
 #include "sdram-micron-mt46h32m32lf-6.h"
 #include "hsmmc.h"
 
+#define PANDORA_WIFI_IRQ_GPIO          21
+#define PANDORA_WIFI_NRESET_GPIO       23
 #define OMAP3_PANDORA_TS_GPIO          94
 
-/* hardware debounce: (value + 1) * 31us */
-#define GPIO_DEBOUNCE_TIME             127
+#define NAND_BLOCK_SIZE                        SZ_128K
+
+static struct mtd_partition omap3pandora_nand_partitions[] = {
+       {
+               .name           = "xloader",
+               .offset         = 0,
+               .size           = 4 * NAND_BLOCK_SIZE,
+               .mask_flags     = MTD_WRITEABLE
+       }, {
+               .name           = "uboot",
+               .offset         = MTDPART_OFS_APPEND,
+               .size           = 15 * NAND_BLOCK_SIZE,
+       }, {
+               .name           = "uboot-env",
+               .offset         = MTDPART_OFS_APPEND,
+               .size           = 1 * NAND_BLOCK_SIZE,
+       }, {
+               .name           = "boot",
+               .offset         = MTDPART_OFS_APPEND,
+               .size           = 80 * NAND_BLOCK_SIZE,
+       }, {
+               .name           = "rootfs",
+               .offset         = MTDPART_OFS_APPEND,
+               .size           = MTDPART_SIZ_FULL,
+       },
+};
+
+static struct omap_nand_platform_data pandora_nand_data = {
+       .cs             = 0,
+       .devsize        = 1,    /* '0' for 8-bit, '1' for 16-bit device */
+       .parts          = omap3pandora_nand_partitions,
+       .nr_parts       = ARRAY_SIZE(omap3pandora_nand_partitions),
+};
 
 static struct gpio_led pandora_gpio_leds[] = {
        {
@@ -89,6 +128,7 @@ static struct platform_device pandora_leds_gpio = {
        .type           = ev_type,                              \
        .code           = ev_code,                              \
        .active_low     = act_low,                              \
+       .debounce_interval = 4,                                 \
        .desc           = "btn " descr,                         \
 }
 
@@ -100,14 +140,14 @@ static struct gpio_keys_button pandora_gpio_keys[] = {
        GPIO_BUTTON_LOW(103,    KEY_DOWN,       "down"),
        GPIO_BUTTON_LOW(96,     KEY_LEFT,       "left"),
        GPIO_BUTTON_LOW(98,     KEY_RIGHT,      "right"),
-       GPIO_BUTTON_LOW(109,    KEY_KP1,        "game 1"),
-       GPIO_BUTTON_LOW(111,    KEY_KP2,        "game 2"),
-       GPIO_BUTTON_LOW(106,    KEY_KP3,        "game 3"),
-       GPIO_BUTTON_LOW(101,    KEY_KP4,        "game 4"),
-       GPIO_BUTTON_LOW(102,    BTN_TL,         "l"),
-       GPIO_BUTTON_LOW(97,     BTN_TL2,        "l2"),
-       GPIO_BUTTON_LOW(105,    BTN_TR,         "r"),
-       GPIO_BUTTON_LOW(107,    BTN_TR2,        "r2"),
+       GPIO_BUTTON_LOW(109,    KEY_PAGEUP,     "game 1"),
+       GPIO_BUTTON_LOW(111,    KEY_END,        "game 2"),
+       GPIO_BUTTON_LOW(106,    KEY_PAGEDOWN,   "game 3"),
+       GPIO_BUTTON_LOW(101,    KEY_HOME,       "game 4"),
+       GPIO_BUTTON_LOW(102,    KEY_RIGHTSHIFT, "l"),
+       GPIO_BUTTON_LOW(97,     KEY_KPPLUS,     "l2"),
+       GPIO_BUTTON_LOW(105,    KEY_RIGHTCTRL,  "r"),
+       GPIO_BUTTON_LOW(107,    KEY_KPMINUS,    "r2"),
        GPIO_BUTTON_LOW(104,    KEY_LEFTCTRL,   "ctrl"),
        GPIO_BUTTON_LOW(99,     KEY_MENU,       "menu"),
        GPIO_BUTTON_LOW(176,    KEY_COFFEE,     "hold"),
@@ -128,14 +168,7 @@ static struct platform_device pandora_keys_gpio = {
        },
 };
 
-static void __init pandora_keys_gpio_init(void)
-{
-       /* set debounce time for GPIO banks 4 and 6 */
-       gpio_set_debounce(32 * 3, GPIO_DEBOUNCE_TIME);
-       gpio_set_debounce(32 * 5, GPIO_DEBOUNCE_TIME);
-}
-
-static int board_keymap[] = {
+static const uint32_t board_keymap[] = {
        /* row, col, code */
        KEY(0, 0, KEY_9),
        KEY(0, 1, KEY_8),
@@ -228,17 +261,31 @@ static struct platform_device pandora_dss_device = {
        },
 };
 
+static void pandora_wl1251_init_card(struct mmc_card *card)
+{
+       /*
+        * We have TI wl1251 attached to MMC3. Pass this information to
+        * SDIO core because it can't be probed by normal methods.
+        */
+       card->quirks |= MMC_QUIRK_NONSTD_SDIO;
+       card->cccr.wide_bus = 1;
+       card->cis.vendor = 0x104c;
+       card->cis.device = 0x9066;
+       card->cis.blksize = 512;
+       card->cis.max_dtr = 20000000;
+}
+
 static struct omap2_hsmmc_info omap3pandora_mmc[] = {
        {
                .mmc            = 1,
-               .wires          = 4,
+               .caps           = MMC_CAP_4_BIT_DATA,
                .gpio_cd        = -EINVAL,
                .gpio_wp        = 126,
                .ext_clock      = 0,
        },
        {
                .mmc            = 2,
-               .wires          = 4,
+               .caps           = MMC_CAP_4_BIT_DATA,
                .gpio_cd        = -EINVAL,
                .gpio_wp        = 127,
                .ext_clock      = 1,
@@ -246,9 +293,10 @@ static struct omap2_hsmmc_info omap3pandora_mmc[] = {
        },
        {
                .mmc            = 3,
-               .wires          = 4,
+               .caps           = MMC_CAP_4_BIT_DATA,
                .gpio_cd        = -EINVAL,
                .gpio_wp        = -EINVAL,
+               .init_card      = pandora_wl1251_init_card,
        },
        {}      /* Terminator */
 };
@@ -256,12 +304,33 @@ static struct omap2_hsmmc_info omap3pandora_mmc[] = {
 static int omap3pandora_twl_gpio_setup(struct device *dev,
                unsigned gpio, unsigned ngpio)
 {
+       int ret, gpio_32khz;
+
        /* gpio + {0,1} is "mmc{0,1}_cd" (input/IRQ) */
        omap3pandora_mmc[0].gpio_cd = gpio + 0;
        omap3pandora_mmc[1].gpio_cd = gpio + 1;
        omap2_hsmmc_init(omap3pandora_mmc);
 
+       /* gpio + 13 drives 32kHz buffer for wifi module */
+       gpio_32khz = gpio + 13;
+       ret = gpio_request(gpio_32khz, "wifi 32kHz");
+       if (ret < 0) {
+               pr_err("Cannot get GPIO line %d, ret=%d\n", gpio_32khz, ret);
+               goto fail;
+       }
+
+       ret = gpio_direction_output(gpio_32khz, 1);
+       if (ret < 0) {
+               pr_err("Cannot set GPIO line %d, ret=%d\n", gpio_32khz, ret);
+               goto fail_direction;
+       }
+
        return 0;
+
+fail_direction:
+       gpio_free(gpio_32khz);
+fail:
+       return -ENODEV;
 }
 
 static struct twl4030_gpio_platform_data omap3pandora_gpio_data = {
@@ -277,6 +346,9 @@ static struct regulator_consumer_supply pandora_vmmc1_supply =
 static struct regulator_consumer_supply pandora_vmmc2_supply =
        REGULATOR_SUPPLY("vmmc", "mmci-omap-hs.1");
 
+static struct regulator_consumer_supply pandora_vmmc3_supply =
+       REGULATOR_SUPPLY("vmmc", "mmci-omap-hs.2");
+
 static struct regulator_consumer_supply pandora_vdda_dac_supply =
        REGULATOR_SUPPLY("vdda_dac", "omapdss");
 
@@ -421,6 +493,33 @@ static struct regulator_init_data pandora_vsim = {
        .consumer_supplies      = &pandora_adac_supply,
 };
 
+/* Fixed regulator internal to Wifi module */
+static struct regulator_init_data pandora_vmmc3 = {
+       .constraints = {
+               .valid_ops_mask         = REGULATOR_CHANGE_STATUS,
+       },
+       .num_consumer_supplies  = 1,
+       .consumer_supplies      = &pandora_vmmc3_supply,
+};
+
+static struct fixed_voltage_config pandora_vwlan = {
+       .supply_name            = "vwlan",
+       .microvolts             = 1800000, /* 1.8V */
+       .gpio                   = PANDORA_WIFI_NRESET_GPIO,
+       .startup_delay          = 50000, /* 50ms */
+       .enable_high            = 1,
+       .enabled_at_boot        = 0,
+       .init_data              = &pandora_vmmc3,
+};
+
+static struct platform_device pandora_vwlan_device = {
+       .name           = "reg-fixed-voltage",
+       .id             = 1,
+       .dev = {
+               .platform_data = &pandora_vwlan,
+       },
+};
+
 static struct twl4030_usb_data omap3pandora_usb_data = {
        .usb_mode       = T2_USB_MODE_ULPI,
 };
@@ -434,6 +533,8 @@ static struct twl4030_codec_data omap3pandora_codec_data = {
        .audio = &omap3pandora_audio_data,
 };
 
+static struct twl4030_bci_platform_data pandora_bci_data;
+
 static struct twl4030_platform_data omap3pandora_twldata = {
        .irq_base       = TWL4030_IRQ_BASE,
        .irq_end        = TWL4030_IRQ_END,
@@ -449,6 +550,7 @@ static struct twl4030_platform_data omap3pandora_twldata = {
        .vaux4          = &pandora_vaux4,
        .vsim           = &pandora_vsim,
        .keypad         = &pandora_kp_data,
+       .bci            = &pandora_bci_data,
 };
 
 static struct i2c_board_info __initdata omap3pandora_i2c_boardinfo[] = {
@@ -540,10 +642,57 @@ static void __init omap3pandora_init_irq(void)
        omap_gpio_init();
 }
 
+static void pandora_wl1251_set_power(bool enable)
+{
+       /*
+        * Keep power always on until wl1251_sdio driver learns to re-init
+        * the chip after powering it down and back up.
+        */
+}
+
+static struct wl12xx_platform_data pandora_wl1251_pdata = {
+       .set_power      = pandora_wl1251_set_power,
+       .use_eeprom     = true,
+};
+
+static struct platform_device pandora_wl1251_data = {
+       .name           = "wl1251_data",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &pandora_wl1251_pdata,
+       },
+};
+
+static void pandora_wl1251_init(void)
+{
+       int ret;
+
+       ret = gpio_request(PANDORA_WIFI_IRQ_GPIO, "wl1251 irq");
+       if (ret < 0)
+               goto fail;
+
+       ret = gpio_direction_input(PANDORA_WIFI_IRQ_GPIO);
+       if (ret < 0)
+               goto fail_irq;
+
+       pandora_wl1251_pdata.irq = gpio_to_irq(PANDORA_WIFI_IRQ_GPIO);
+       if (pandora_wl1251_pdata.irq < 0)
+               goto fail_irq;
+
+       return;
+
+fail_irq:
+       gpio_free(PANDORA_WIFI_IRQ_GPIO);
+fail:
+       printk(KERN_ERR "wl1251 board initialisation failed\n");
+}
+
 static struct platform_device *omap3pandora_devices[] __initdata = {
        &pandora_leds_gpio,
        &pandora_keys_gpio,
        &pandora_dss_device,
+       &pandora_wl1251_data,
+       &pandora_vwlan_device,
 };
 
 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
@@ -576,6 +725,7 @@ static void __init omap3pandora_init(void)
 {
        omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
        omap3pandora_i2c_init();
+       pandora_wl1251_init();
        platform_add_devices(omap3pandora_devices,
                        ARRAY_SIZE(omap3pandora_devices));
        omap_serial_init();
@@ -583,25 +733,17 @@ static void __init omap3pandora_init(void)
                        ARRAY_SIZE(omap3pandora_spi_board_info));
        omap3pandora_ads7846_init();
        usb_ehci_init(&ehci_pdata);
-       pandora_keys_gpio_init();
        usb_musb_init(&musb_board_data);
+       gpmc_nand_init(&pandora_nand_data);
 
        /* Ensure SDRC pins are mux'd for self-refresh */
        omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
        omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
 }
 
-static void __init omap3pandora_map_io(void)
-{
-       omap2_set_globals_343x();
-       omap34xx_map_common_io();
-}
-
 MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
-       .phys_io        = 0x48000000,
-       .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
-       .map_io         = omap3pandora_map_io,
+       .map_io         = omap3_map_io,
        .reserve        = omap_reserve,
        .init_irq       = omap3pandora_init_irq,
        .init_machine   = omap3pandora_init,