Merge remote branch 'alsa/devel' into topic/misc
[pandora-kernel.git] / arch / arm / mach-pxa / balloon3.c
index 91ad56d..9041340 100644 (file)
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/types.h>
+#include <linux/i2c/pcf857x.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/physmap.h>
+#include <linux/regulator/max1586.h>
 
 #include <asm/setup.h>
 #include <asm/mach-types.h>
@@ -375,15 +379,65 @@ static struct gpio_led_platform_data balloon3_gpio_led_info = {
 
 static struct platform_device balloon3_leds = {
        .name   = "leds-gpio",
-       .id     = -1,
+       .id     = 0,
        .dev    = {
                .platform_data  = &balloon3_gpio_led_info,
        }
 };
 
+struct gpio_led balloon3_pcf_gpio_leds[] = {
+       {
+               .name                   = "balloon3:green:led0",
+               .gpio                   = BALLOON3_PCF_GPIO_LED0,
+               .active_low             = 1,
+       }, {
+               .name                   = "balloon3:green:led1",
+               .gpio                   = BALLOON3_PCF_GPIO_LED1,
+               .active_low             = 1,
+       }, {
+               .name                   = "balloon3:orange:led2",
+               .gpio                   = BALLOON3_PCF_GPIO_LED2,
+               .active_low             = 1,
+       }, {
+               .name                   = "balloon3:orange:led3",
+               .gpio                   = BALLOON3_PCF_GPIO_LED3,
+               .active_low             = 1,
+       }, {
+               .name                   = "balloon3:orange:led4",
+               .gpio                   = BALLOON3_PCF_GPIO_LED4,
+               .active_low             = 1,
+       }, {
+               .name                   = "balloon3:orange:led5",
+               .gpio                   = BALLOON3_PCF_GPIO_LED5,
+               .active_low             = 1,
+       }, {
+               .name                   = "balloon3:red:led6",
+               .gpio                   = BALLOON3_PCF_GPIO_LED6,
+               .active_low             = 1,
+       }, {
+               .name                   = "balloon3:red:led7",
+               .gpio                   = BALLOON3_PCF_GPIO_LED7,
+               .active_low             = 1,
+       },
+};
+
+static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
+       .leds           = balloon3_pcf_gpio_leds,
+       .num_leds       = ARRAY_SIZE(balloon3_pcf_gpio_leds),
+};
+
+static struct platform_device balloon3_pcf_leds = {
+       .name   = "leds-gpio",
+       .id     = 1,
+       .dev    = {
+               .platform_data  = &balloon3_pcf_gpio_led_info,
+       }
+};
+
 static void __init balloon3_leds_init(void)
 {
        platform_device_register(&balloon3_leds);
+       platform_device_register(&balloon3_pcf_leds);
 }
 #else
 static inline void balloon3_leds_init(void) {}
@@ -450,6 +504,235 @@ static void __init balloon3_init_irq(void)
                "enabled\n", __func__, BALLOON3_AUX_NIRQ);
 }
 
+/******************************************************************************
+ * GPIO expander
+ ******************************************************************************/
+#if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
+static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
+       .gpio_base      = BALLOON3_PCF_GPIO_BASE,
+       .n_latch        = 0,
+       .setup          = NULL,
+       .teardown       = NULL,
+       .context        = NULL,
+};
+
+static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
+       {
+               I2C_BOARD_INFO("pcf8574a", 0x38),
+               .platform_data  = &balloon3_pcf857x_pdata,
+       },
+};
+
+static void __init balloon3_i2c_init(void)
+{
+       pxa_set_i2c_info(NULL);
+       i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
+}
+#else
+static inline void balloon3_i2c_init(void) {}
+#endif
+
+/******************************************************************************
+ * NAND
+ ******************************************************************************/
+#if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
+static uint16_t balloon3_ctl =
+       BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
+       BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3 |
+       BALLOON3_NAND_CONTROL_FLWP;
+
+static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
+{
+       struct nand_chip *this = mtd->priv;
+
+       if (ctrl & NAND_CTRL_CHANGE) {
+               if (ctrl & NAND_CLE)
+                       balloon3_ctl |= BALLOON3_NAND_CONTROL_FLCLE;
+               else
+                       balloon3_ctl &= ~BALLOON3_NAND_CONTROL_FLCLE;
+
+               if (ctrl & NAND_ALE)
+                       balloon3_ctl |= BALLOON3_NAND_CONTROL_FLALE;
+               else
+                       balloon3_ctl &= ~BALLOON3_NAND_CONTROL_FLALE;
+
+               __raw_writel(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
+       }
+
+       if (cmd != NAND_CMD_NONE)
+               writeb(cmd, this->IO_ADDR_W);
+}
+
+static void balloon3_nand_select_chip(struct mtd_info *mtd, int chip)
+{
+       if (chip < 0 || chip > 3)
+               return;
+
+       balloon3_ctl |= BALLOON3_NAND_CONTROL_FLCE0 |
+                       BALLOON3_NAND_CONTROL_FLCE1 |
+                       BALLOON3_NAND_CONTROL_FLCE2 |
+                       BALLOON3_NAND_CONTROL_FLCE3;
+
+       /* Deassert correct nCE line */
+       balloon3_ctl &= ~(BALLOON3_NAND_CONTROL_FLCE0 << chip);
+
+       __raw_writew(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
+}
+
+static int balloon3_nand_probe(struct platform_device *pdev)
+{
+       void __iomem *temp_map;
+       uint16_t ver;
+       int ret;
+
+       __raw_writew(BALLOON3_NAND_CONTROL2_16BIT, BALLOON3_NAND_CONTROL2_REG);
+
+       ver = __raw_readw(BALLOON3_FPGA_VER);
+       if (ver > 0x0201)
+               pr_warn("The FPGA code, version 0x%04x, is newer than rel-0.3. "
+                       "NAND support might be broken in this version!", ver);
+
+       /* Power up the NAND chips */
+       ret = gpio_request(BALLOON3_GPIO_RUN_NAND, "NAND");
+       if (ret)
+               goto err1;
+
+       ret = gpio_direction_output(BALLOON3_GPIO_RUN_NAND, 1);
+       if (ret)
+               goto err2;
+
+       gpio_set_value(BALLOON3_GPIO_RUN_NAND, 1);
+
+       /* Deassert all nCE lines and write protect line */
+       __raw_writel(balloon3_ctl, BALLOON3_NAND_CONTROL_REG);
+       return 0;
+
+err2:
+       gpio_free(BALLOON3_GPIO_RUN_NAND);
+err1:
+       return ret;
+}
+
+static void balloon3_nand_remove(struct platform_device *pdev)
+{
+       /* Power down the NAND chips */
+       gpio_set_value(BALLOON3_GPIO_RUN_NAND, 0);
+       gpio_free(BALLOON3_GPIO_RUN_NAND);
+}
+
+static struct mtd_partition balloon3_partition_info[] = {
+       [0] = {
+               .name   = "Boot",
+               .offset = 0,
+               .size   = SZ_4M,
+       },
+       [1] = {
+               .name   = "RootFS",
+               .offset = MTDPART_OFS_APPEND,
+               .size   = MTDPART_SIZ_FULL
+       },
+};
+
+static const char *balloon3_part_probes[] = { "cmdlinepart", NULL };
+
+struct platform_nand_data balloon3_nand_pdata = {
+       .chip = {
+               .nr_chips       = 4,
+               .chip_offset    = 0,
+               .nr_partitions  = ARRAY_SIZE(balloon3_partition_info),
+               .partitions     = balloon3_partition_info,
+               .chip_delay     = 50,
+               .part_probe_types = balloon3_part_probes,
+       },
+       .ctrl = {
+               .hwcontrol      = 0,
+               .dev_ready      = 0,
+               .select_chip    = balloon3_nand_select_chip,
+               .cmd_ctrl       = balloon3_nand_cmd_ctl,
+               .probe          = balloon3_nand_probe,
+               .remove         = balloon3_nand_remove,
+       },
+};
+
+static struct resource balloon3_nand_resource[] = {
+       [0] = {
+               .start = BALLOON3_NAND_BASE,
+               .end   = BALLOON3_NAND_BASE + 0x4,
+               .flags = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device balloon3_nand = {
+       .name           = "gen_nand",
+       .num_resources  = ARRAY_SIZE(balloon3_nand_resource),
+       .resource       = balloon3_nand_resource,
+       .id             = -1,
+       .dev            = {
+               .platform_data = &balloon3_nand_pdata,
+       }
+};
+
+static void __init balloon3_nand_init(void)
+{
+       platform_device_register(&balloon3_nand);
+}
+#else
+static inline void balloon3_nand_init(void) {}
+#endif
+
+/******************************************************************************
+ * Core power regulator
+ ******************************************************************************/
+#if defined(CONFIG_REGULATOR_MAX1586) || \
+    defined(CONFIG_REGULATOR_MAX1586_MODULE)
+static struct regulator_consumer_supply balloon3_max1587a_consumers[] = {
+       {
+               .supply = "vcc_core",
+       }
+};
+
+static struct regulator_init_data balloon3_max1587a_v3_info = {
+       .constraints = {
+               .name           = "vcc_core range",
+               .min_uV         = 900000,
+               .max_uV         = 1705000,
+               .always_on      = 1,
+               .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
+       },
+       .consumer_supplies      = balloon3_max1587a_consumers,
+       .num_consumer_supplies  = ARRAY_SIZE(balloon3_max1587a_consumers),
+};
+
+static struct max1586_subdev_data balloon3_max1587a_subdevs[] = {
+       {
+               .name           = "vcc_core",
+               .id             = MAX1586_V3,
+               .platform_data  = &balloon3_max1587a_v3_info,
+       }
+};
+
+static struct max1586_platform_data balloon3_max1587a_info = {
+       .subdevs     = balloon3_max1587a_subdevs,
+       .num_subdevs = ARRAY_SIZE(balloon3_max1587a_subdevs),
+       .v3_gain     = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
+};
+
+static struct i2c_board_info __initdata balloon3_pi2c_board_info[] = {
+       {
+               I2C_BOARD_INFO("max1586", 0x14),
+               .platform_data  = &balloon3_max1587a_info,
+       },
+};
+
+static void __init balloon3_pmic_init(void)
+{
+       pxa27x_set_i2c_power_info(NULL);
+       i2c_register_board_info(1, ARRAY_AND_SIZE(balloon3_pi2c_board_info));
+}
+#else
+static inline void balloon3_pmic_init(void) {}
+#endif
+
 /******************************************************************************
  * Machine init
  ******************************************************************************/
@@ -463,13 +746,14 @@ static void __init balloon3_init(void)
        pxa_set_btuart_info(NULL);
        pxa_set_stuart_info(NULL);
 
-       pxa_set_i2c_info(NULL);
-
+       balloon3_i2c_init();
        balloon3_irda_init();
        balloon3_lcd_init();
        balloon3_leds_init();
        balloon3_mmc_init();
+       balloon3_nand_init();
        balloon3_nor_init();
+       balloon3_pmic_init();
        balloon3_ts_init();
        balloon3_udc_init();
        balloon3_uhc_init();