[xburst] Fix usb gadget driver build
[openwrt.git] / target / linux / s3c24xx / files-2.6.30 / arch / arm / mach-s3c2442 / mach-gta02.c
index 3ae2a81..49ab6c4 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/serial_core.h>
 #include <linux/spi/spi.h>
-#include <linux/spi/glamo.h>
+#include <linux/spi/spi_gpio.h>
 #include <linux/spi/spi_bitbang.h>
 #include <linux/mmc/host.h>
+#include <linux/leds.h>
+#include <linux/gpio_keys.h>
 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
@@ -75,7 +77,6 @@
 #include <mach/spi.h>
 #include <mach/spi-gpio.h>
 #include <mach/regs-mem.h>
-#include <mach/spi-gpio.h>
 #include <plat/pwm.h>
 #include <mach/cpu.h>
 
@@ -90,6 +91,7 @@
 #include <plat/iic.h>
 #include <plat/usb-control.h>
 #include <plat/regs-timer.h>
+#include <plat/gpio-core.h>
 
 #include <mach/gta02-pm-gsm.h>
 #include <mach/gta02-pm-gps.h>
@@ -97,6 +99,7 @@
 
 #include <linux/jbt6k74.h>
 #include <linux/glamofb.h>
+#include <linux/mfd/glamo.h>
 
 #include <linux/hdq.h>
 #include <linux/bq27000_battery.h>
 #include <asm/fiq.h>
 
 #include <linux/gta02-vibrator.h>
-#include <linux/gta02-shadow.h>
 
 /* arbitrates which sensor IRQ owns the shared SPI bus */
 static spinlock_t motion_irq_lock;
@@ -275,7 +277,7 @@ static long gta02_panic_blink(long count)
 
        led ^= 1;
        s3c2410_gpio_cfgpin(GTA02_GPIO_AUX_LED, S3C2410_GPIO_OUTPUT);
-       gta02_gpb_setpin(GTA02_GPIO_AUX_LED, led);
+       s3c2410_gpio_setpin(GTA02_GPIO_AUX_LED, led);
 
        last_blink = count;
        return delay;
@@ -463,7 +465,7 @@ static void gta02_pmu_force_shutdown(struct pcf50633 *pcf)
 
 static void gta02_udc_vbus_draw(unsigned int ma)
 {
-        if (!gta02_pcf)
+       if (!gta02_pcf)
                return;
 
        gta02_usb_vbus_draw = ma;
@@ -535,16 +537,9 @@ static struct regulator_consumer_supply ldo5_consumers[] = {
        },
 };
 
-/*
- * We need this dummy thing to fill the regulator consumers
- */
-static struct platform_device gta02_mmc_dev = {
-       /* details filled in by glamo core */
-};
-
 static struct regulator_consumer_supply hcldo_consumers[] = {
        {
-               .dev = &gta02_mmc_dev.dev,
+               .dev = &gta02_glamo_dev.dev,
                .supply = "SD_3V3",
        },
 };
@@ -580,6 +575,7 @@ struct pcf50633_platform_data gta02_pcf_pdata = {
                                .max_uV = 3300000,
                                .valid_modes_mask = REGULATOR_MODE_NORMAL,
                                .boot_on = 1,
+                               .always_on = 1,
                                .apply_uV = 1,
                                .state_mem = {
                                        .enabled = 1,
@@ -594,6 +590,7 @@ struct pcf50633_platform_data gta02_pcf_pdata = {
                                .max_uV = 1600000,
                                .valid_modes_mask = REGULATOR_MODE_NORMAL,
                                .boot_on = 1,
+                               .always_on = 1,
                                .apply_uV = 1,
                        },
                        .num_consumer_supplies = 0,
@@ -606,6 +603,7 @@ struct pcf50633_platform_data gta02_pcf_pdata = {
                                .valid_modes_mask = REGULATOR_MODE_NORMAL,
                                .apply_uV = 1,
                                .boot_on = 1,
+                               .always_on = 1,
                                .state_mem = {
                                        .enabled = 1,
                                },
@@ -627,8 +625,8 @@ struct pcf50633_platform_data gta02_pcf_pdata = {
                [PCF50633_REGULATOR_LDO1] = {
                        .constraints = {
                                .name = "GSENSOR_3V3",
-                               .min_uV = 1300000,
-                               .max_uV = 1300000,
+                               .min_uV = 3300000,
+                               .max_uV = 3300000,
                                .valid_modes_mask = REGULATOR_MODE_NORMAL,
                                .apply_uV = 1,
                        },
@@ -667,8 +665,8 @@ struct pcf50633_platform_data gta02_pcf_pdata = {
                [PCF50633_REGULATOR_LDO5] = {
                        .constraints = {
                                .name = "RF_3V",
-                               .min_uV = 1500000,
-                               .max_uV = 1500000,
+                               .min_uV = 3000000,
+                               .max_uV = 3000000,
                                .valid_modes_mask = REGULATOR_MODE_NORMAL,
                                .apply_uV = 1,
                                .state_mem = {
@@ -681,9 +679,11 @@ struct pcf50633_platform_data gta02_pcf_pdata = {
                [PCF50633_REGULATOR_LDO6] = {
                        .constraints = {
                                .name = "LCM_3V",
-                               .min_uV = 0,
-                               .max_uV = 3300000,
+                               .min_uV = 3000000,
+                               .max_uV = 3000000,
+                               .always_on = 1,
                                .valid_modes_mask = REGULATOR_MODE_NORMAL,
+                               .apply_uV = 1,
                        },
                        .num_consumer_supplies = 0,
                },
@@ -717,28 +717,21 @@ static void mangle_pmu_pdata_by_system_rev(void)
                /* FIXME: this is only in v1 due to wrong PMU variant */
                reg_init_data[PCF50633_REGULATOR_DOWN2]
                                        .constraints.state_mem.enabled = 1;
-               break;
-       case GTA02v2_SYSTEM_REV:
-       case GTA02v3_SYSTEM_REV:
-       case GTA02v4_SYSTEM_REV:
-       case GTA02v5_SYSTEM_REV:
-       case GTA02v6_SYSTEM_REV:
-               reg_init_data[PCF50633_REGULATOR_LDO1]
-                                       .constraints.min_uV = 3300000;
+
                reg_init_data[PCF50633_REGULATOR_LDO1]
-                                       .constraints.min_uV = 3300000;
+                                       .constraints.min_uV = 1300000;
                reg_init_data[PCF50633_REGULATOR_LDO1]
-                                       .constraints.state_mem.enabled = 0;
+                                       .constraints.max_uV = 1300000;
 
                reg_init_data[PCF50633_REGULATOR_LDO5]
-                                       .constraints.min_uV = 3000000;
+                                       .constraints.min_uV = 1500000;
                reg_init_data[PCF50633_REGULATOR_LDO5]
-                                       .constraints.max_uV = 3000000;
+                                       .constraints.max_uV = 1500000;
 
                reg_init_data[PCF50633_REGULATOR_LDO6]
-                                       .constraints.min_uV = 3000000;
+                                       .constraints.min_uV = 0;
                reg_init_data[PCF50633_REGULATOR_LDO6]
-                                       .constraints.max_uV = 3000000;
+                                       .constraints.max_uV = 3300000;
                reg_init_data[PCF50633_REGULATOR_LDO6]
                                        .constraints.apply_uV = 1;
                break;
@@ -947,11 +940,11 @@ static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
        switch (cmd) {
        case S3C2410_UDC_P_ENABLE:
                printk(KERN_DEBUG "%s S3C2410_UDC_P_ENABLE\n", __func__);
-           gta02_gpb_setpin(GTA02_GPIO_USB_PULLUP, 1);
+           s3c2410_gpio_setpin(GTA02_GPIO_USB_PULLUP, 1);
                break;
        case S3C2410_UDC_P_DISABLE:
                printk(KERN_DEBUG "%s S3C2410_UDC_P_DISABLE\n", __func__);
-               gta02_gpb_setpin(GTA02_GPIO_USB_PULLUP, 0);
+               s3c2410_gpio_setpin(GTA02_GPIO_USB_PULLUP, 0);
                break;
        case S3C2410_UDC_P_RESET:
                printk(KERN_DEBUG "%s S3C2410_UDC_P_RESET\n", __func__);
@@ -1089,8 +1082,8 @@ static struct platform_device gta02_bl_dev = {
 
 static void gta02_jbt6k74_reset(int devidx, int level)
 {
-       glamo_lcm_reset(level);
-}      
+       gpio_set_value(GTA02_GPIO_GLAMO(4), level);
+}
 
 static void gta02_jbt6k74_probe_completed(struct device *dev)
 {
@@ -1111,21 +1104,6 @@ const struct jbt6k74_platform_data jbt6k74_pdata = {
        .probe_completed = gta02_jbt6k74_probe_completed,
 };
 
-#if 0 /* currently this is not used and we use gpio spi */
-static struct glamo_spi_info glamo_spi_cfg = {
-       .board_size     = ARRAY_SIZE(gta02_spi_board_info),
-       .board_info     = gta02_spi_board_info,
-};
-#endif /* 0 */
-
-static struct glamo_spigpio_info glamo_spigpio_cfg = {
-       .pin_clk        = GLAMO_GPIO10_OUTPUT,
-       .pin_mosi       = GLAMO_GPIO11_OUTPUT,
-       .pin_cs         = GLAMO_GPIO12_OUTPUT,
-       .pin_miso       = 0,
-       .bus_num        = 2,
-};
-
 /*----------- SPI: Accelerometers attached to SPI of s3c244x ----------------- */
 
 void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
@@ -1183,13 +1161,12 @@ struct lis302dl_platform_data lis302_pdata_bottom = {
 static struct spi_board_info gta02_spi_board_info[] = {
        {
                .modalias       = "jbt6k74",
-               /* platform_data */
                .platform_data  = &jbt6k74_pdata,
-               /* controller_data */
+               .controller_data = (void*)GTA02_GPIO_GLAMO(12),
                /* irq */
                .max_speed_hz   = 100 * 1000,
                .bus_num        = 2,
-               /* chip_select */
+               .chip_select = 0
        },
        {
                .modalias       = "lis302dl",
@@ -1272,62 +1249,64 @@ static struct platform_device gta02_spi_gpio_dev = {
 
 /*----------- / SPI: Accelerometers attached to SPI of s3c244x ----------------- */
 
-static struct resource gta02_led_resources[] = {
+static struct gpio_led gta02_gpio_leds[] = {
        {
                .name   = "gta02-power:orange",
-               .start  = GTA02_GPIO_PWR_LED1,
-               .end    = GTA02_GPIO_PWR_LED1,
+               .gpio   = GTA02_GPIO_PWR_LED1,
        }, {
                .name   = "gta02-power:blue",
-               .start  = GTA02_GPIO_PWR_LED2,
-               .end    = GTA02_GPIO_PWR_LED2,
+               .gpio   = GTA02_GPIO_PWR_LED2,
        }, {
                .name   = "gta02-aux:red",
-               .start  = GTA02_GPIO_AUX_LED,
-               .end    = GTA02_GPIO_AUX_LED,
+               .gpio   = GTA02_GPIO_AUX_LED,
        },
 };
 
-struct platform_device gta02_led_dev = {
-       .name           = "gta02-led",
-       .num_resources  = ARRAY_SIZE(gta02_led_resources),
-       .resource       = gta02_led_resources,
+static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
+       .leds = gta02_gpio_leds,
+       .num_leds = ARRAY_SIZE(gta02_gpio_leds),
 };
 
-static struct resource gta02_button_resources[] = {
-       [0] = {
-               .start = GTA02_GPIO_AUX_KEY,
-               .end   = GTA02_GPIO_AUX_KEY,
-       },
-       [1] = {
-               .start = GTA02_GPIO_HOLD_KEY,
-               .end   = GTA02_GPIO_HOLD_KEY,
-       },
-       [2] = {
-               .start = GTA02_GPIO_JACK_INSERT,
-               .end   = GTA02_GPIO_JACK_INSERT,
+struct platform_device gta02_led_dev = {
+       .name = "leds-gpio",
+       .id   = -1,
+       .dev = {
+               .platform_data = &gta02_gpio_leds_pdata,
        },
-       [3] = {
-               .start = 0,
-               .end   = 0,
+};
+
+static struct gpio_keys_button gta02_buttons[] = {
+       {
+               .gpio = GTA02_GPIO_AUX_KEY,
+               .code = KEY_PHONE,
+               .desc = "Aux",
+               .type = EV_KEY,
        },
-       [4] = {
-               .start = 0,
-               .end   = 0,
+       {
+               .gpio = GTA02_GPIO_HOLD_KEY,
+               .code = KEY_PAUSE,
+               .desc = "Hold",
+               .type = EV_KEY,
        },
 };
 
+static struct gpio_keys_platform_data gta02_buttons_pdata = {
+       .buttons = gta02_buttons,
+       .nbuttons = ARRAY_SIZE(gta02_buttons),
+};
+
 static struct platform_device gta02_button_dev = {
-       .name           = "gta02-button",
-       .num_resources  = ARRAY_SIZE(gta02_button_resources),
-       .resource       = gta02_button_resources,
+       .name = "gpio-keys",
+       .id = -1,
+       .dev = {
+               .platform_data = &gta02_buttons_pdata,
+       },
 };
 
 static struct platform_device gta02_pm_usbhost_dev = {
        .name           = "gta02-pm-host",
 };
 
-
 /* USB */
 static struct s3c2410_hcd_info gta02_usb_info = {
        .port[0]        = {
@@ -1369,19 +1348,6 @@ static int glamo_irq_is_wired(void)
        return -ENODEV;
 }
 
-static int gta02_glamo_can_set_mmc_power(void)
-{
-       switch (S3C_SYSTEM_REV_ATAG) {
-               case GTA02v3_SYSTEM_REV:
-               case GTA02v4_SYSTEM_REV:
-               case GTA02v5_SYSTEM_REV:
-               case GTA02v6_SYSTEM_REV:
-                       return 1;
-       }
-
-       return 0;
-}
-
 /* Smedia Glamo 3362 */
 
 /*
@@ -1399,42 +1365,85 @@ static void gta02_glamo_external_reset(int level)
        s3c2410_gpio_cfgpin(GTA02_GPIO_3D_RESET, S3C2410_GPIO_OUTPUT);
 }
 
-static struct glamofb_platform_data gta02_glamo_pdata = {
-       .width          = 43,
-       .height         = 58,
-        /* 24.5MHz --> 40.816ns */
-       .pixclock       = 40816,
-       .left_margin    = 8,
-       .right_margin   = 16,
-       .upper_margin   = 2,
-       .lower_margin   = 16,
-       .hsync_len      = 8,
-       .vsync_len      = 2,
-       .fb_mem_size    = 0x400000, /* glamo has 8 megs of SRAM. we use 4 */
-       .xres           = {
-               .min    = 240,
-               .max    = 640,
-               .defval = 480,
-       },
-       .yres           = {
-               .min    = 320,
-               .max    = 640,
-               .defval = 640,
-       },
-       .bpp            = {
-               .min    = 16,
-               .max    = 16,
-               .defval = 16,
-       },
-       //.spi_info     = &glamo_spi_cfg,
-       .spigpio_info   = &glamo_spigpio_cfg,
+/*
+static struct fb_videomode gta02_glamo_modes[] = {
+       {
+               .name = "480x640",
+               .xres = 480,
+               .yres = 640,
+               .pixclock       = 40816,
+               .left_margin    = 8,
+               .right_margin   = 63,
+               .upper_margin   = 2,
+               .lower_margin   = 4,
+               .hsync_len      = 8,
+               .vsync_len      = 2,
+               .vmode = FB_VMODE_NONINTERLACED,
+       }, {
+               .name = "240x320",
+               .xres = 240,
+               .yres = 320,
+               .pixclock       = 40816,
+               .left_margin    = 8,
+               .right_margin   = 88,
+               .upper_margin   = 2,
+               .lower_margin   = 2,
+               .hsync_len      = 8,
+               .vsync_len      = 2,
+               .vmode = FB_VMODE_NONINTERLACED,
+       }
+};*/
+
+static struct fb_videomode gta02_glamo_modes[] = {
+       {
+               .name = "480x640",
+               .xres = 480,
+               .yres = 640,
+               .pixclock       = 40816,
+               .left_margin    = 8,
+               .right_margin   = 16,
+               .upper_margin   = 2,
+               .lower_margin   = 16,
+               .hsync_len      = 8,
+               .vsync_len      = 2,
+               .vmode = FB_VMODE_NONINTERLACED,
+       }, {
+               .name = "240x320",
+               .xres = 240,
+               .yres = 320,
+               .pixclock       = 40816,
+               .left_margin    = 8,
+               .right_margin   = 16,
+               .upper_margin   = 2,
+               .lower_margin   = 16,
+               .hsync_len      = 8,
+               .vsync_len      = 2,
+               .vmode = FB_VMODE_NONINTERLACED,
+       }
+};
+
+
+static struct glamo_fb_platform_data gta02_glamo_fb_pdata = {
+       .width  = 43,
+       .height = 58,
+
+       .num_modes = ARRAY_SIZE(gta02_glamo_modes),
+       .modes = gta02_glamo_modes,
+};
+
+static struct glamo_mmc_platform_data gta02_glamo_mmc_pdata = {
+       .glamo_mmc_use_slow = gta02_glamo_mci_use_slow,
+};
+
+static struct glamo_platform_data gta02_glamo_pdata = {
+       .fb_data   = &gta02_glamo_fb_pdata,
+       .mmc_data  = &gta02_glamo_mmc_pdata,
+       .gpio_base = GTA02_GPIO_GLAMO_BASE,
+
+       .osci_clock_rate = 32768,
 
-       /* glamo MMC function platform data */
-       .mmc_dev = &gta02_mmc_dev,
-       .glamo_can_set_mci_power = gta02_glamo_can_set_mmc_power,
-       .glamo_mci_use_slow = gta02_glamo_mci_use_slow,
        .glamo_irq_is_wired = glamo_irq_is_wired,
-       .glamo_external_reset = gta02_glamo_external_reset
+       .glamo_external_reset = gta02_glamo_external_reset,
 };
 
 static struct resource gta02_glamo_resources[] = {
@@ -1487,6 +1496,22 @@ static void mangle_glamo_res_by_system_rev(void)
        }
 }
 
+struct spi_gpio_platform_data spigpio_platform_data = {
+       .sck = GTA02_GPIO_GLAMO(10),
+       .mosi = GTA02_GPIO_GLAMO(11),
+       .miso = GTA02_GPIO_GLAMO(5),
+       .num_chipselect = 1,
+};
+
+static struct platform_device spigpio_device = {
+       .name = "spi_gpio",
+       .id   = 2,
+       .dev = {
+               .platform_data = &spigpio_platform_data,
+               .parent        = &gta02_glamo_dev.dev,
+       },
+};
+
 static void __init gta02_map_io(void)
 {
        s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
@@ -1534,7 +1559,6 @@ static struct platform_device *gta02_devices[] __initdata = {
        &s3c24xx_pwm_device,
        &gta02_led_dev,
        &gta02_pm_wlan_dev, /* not dependent on PMU */
-
        &s3c_device_iis,
        &s3c_device_i2c0,
 };
@@ -1550,6 +1574,16 @@ static struct platform_device *gta02_devices_pmu_children[] = {
        &gta02_resume_reason_device,
 };
 
+static void gta02_register_glamo(void)
+{
+       platform_device_register(&gta02_glamo_dev);
+       if (gpio_request(GTA02_GPIO_GLAMO(4), "jbt6k74 reset"))
+               printk("gta02: Failed to request jbt6k74 reset pin\n");
+       if (gpio_direction_output(GTA02_GPIO_GLAMO(4), 1))
+               printk("gta02: Failed to configure jbt6k74 reset pin\n");
+       platform_device_register(&spigpio_device);
+}
+
 static void gta02_pmu_regulator_registered(struct pcf50633 *pcf, int id)
 {
        struct platform_device *regulator, *pdev;
@@ -1566,10 +1600,10 @@ static void gta02_pmu_regulator_registered(struct pcf50633 *pcf, int id)
                        pdev = &gta02_pm_gps_dev;
                        break;
                case PCF50633_REGULATOR_HCLDO:
-                       pdev = &gta02_glamo_dev;
-                       break;
+                       gta02_register_glamo();
+                       return;
                default:
-            return;
+                       return;
        }
 
        pdev->dev.parent = &regulator->dev;
@@ -1594,7 +1628,7 @@ static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
        platform_add_devices(gta02_devices_pmu_children,
                                        ARRAY_SIZE(gta02_devices_pmu_children));
 
-/*    regulator_has_full_constraints();*/
+       regulator_has_full_constraints();
 }
 
 static void gta02_poweroff(void)
@@ -1603,6 +1637,57 @@ static void gta02_poweroff(void)
                  PCF50633_OOCSHDWN_GOSTDBY, PCF50633_OOCSHDWN_GOSTDBY);
 }
 
+
+/* On hardware rev 5 and earlier the leds are missing a resistor and reading
+ * from their gpio pins will always return 0, so we have to shadow the
+ * led states software */
+static unsigned long gpb_shadow;
+extern struct s3c_gpio_chip s3c24xx_gpios[];
+
+static void gta02_gpb_set(struct gpio_chip *chip,
+                           unsigned offset, int value)
+{
+       void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB0);
+       unsigned long flags;
+       unsigned long dat;
+
+       local_irq_save(flags);
+
+       dat = __raw_readl(base + 0x04) | gpb_shadow;
+       dat &= ~(1 << offset);
+       gpb_shadow &= ~(1 << offset);
+       if (value) {
+               dat |= 1 << offset;
+               switch (offset) {
+               case 0 ... 2:
+                       gpb_shadow |= 1 << offset;
+                       break;
+               default:
+                       break;
+               }
+       }
+       __raw_writel(dat, base + 0x04);
+
+       local_irq_restore(flags);
+}
+
+static int gta02_gpb_get(struct gpio_chip *chip, unsigned offset)
+{
+       void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB0);
+       unsigned long val;
+
+       val = __raw_readl(base + 0x04) | gpb_shadow;
+       val >>= offset;
+       val &= 1;
+
+       return val;
+}
+
+static void gta02_hijack_gpb(void) {
+    s3c24xx_gpios[1].chip.set = gta02_gpb_set;
+    s3c24xx_gpios[1].chip.get = gta02_gpb_get;
+}
+
 static void __init gta02_machine_init(void)
 {
        int rc;
@@ -1619,6 +1704,8 @@ static void __init gta02_machine_init(void)
        default:
                break;
        }
+       if (S3C_SYSTEM_REV_ATAG <= GTA02v5_SYSTEM_REV)
+               gta02_hijack_gpb();
 
        spin_lock_init(&motion_irq_lock);
 
@@ -1643,10 +1730,11 @@ static void __init gta02_machine_init(void)
        s3c2410_gpio_setpin(S3C2410_GPD13, 1);
        s3c2410_gpio_cfgpin(S3C2410_GPD13, S3C2410_GPIO_OUTPUT);
 
+
        s3c24xx_udc_set_platdata(&gta02_udc_cfg);
        s3c_i2c0_set_platdata(NULL);
        set_s3c2410ts_info(&gta02_ts_cfg);
-       
+
        mangle_glamo_res_by_system_rev();
 
        i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
@@ -1695,13 +1783,13 @@ void DEBUG_LED(int n)
 {
        switch (n) {
        case 0:
-               gta02_gpb_setpin(GTA02_GPIO_PWR_LED1, 1);
+               s3c2410_gpio_setpin(GTA02_GPIO_PWR_LED1, 1);
                break;
        case 1:
-               gta02_gpb_setpin(GTA02_GPIO_PWR_LED2, 1);
+               s3c2410_gpio_setpin(GTA02_GPIO_PWR_LED2, 1);
                break;
        default:
-               gta02_gpb_setpin(GTA02_GPIO_AUX_LED, 1);
+               s3c2410_gpio_setpin(GTA02_GPIO_AUX_LED, 1);
                break;
        }
 }
This page took 0.043169 seconds and 4 git commands to generate.