Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg...
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-s3c2412 / mach-jive.c
index 7cfab868cce3aa68fb91c085ac6eee5cc4da7b38..30f613a79bfedb7ead2c164c73a25f1a11c52599 100644 (file)
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/sysdev.h>
+#include <linux/delay.h>
 #include <linux/serial_core.h>
 #include <linux/platform_device.h>
+#include <linux/i2c.h>
+
+#include <video/ili9320.h>
+
+#include <linux/spi/spi.h>
 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 
 #include <asm/plat-s3c/regs-serial.h>
 #include <asm/plat-s3c/nand.h>
+#include <asm/plat-s3c/iic.h>
 
-#include <asm/arch/regs-power.h>
-#include <asm/arch/regs-gpio.h>
-#include <asm/arch/regs-mem.h>
-#include <asm/arch/regs-lcd.h>
+#include <mach/regs-power.h>
+#include <mach/regs-gpio.h>
+#include <mach/regs-mem.h>
+#include <mach/regs-lcd.h>
+#include <mach/spi-gpio.h>
+#include <mach/fb.h>
 
 #include <asm/mach-types.h>
 
@@ -256,11 +265,218 @@ static int __init jive_mtdset(char *options)
 /* parse the mtdset= option given to the kernel command line */
 __setup("mtdset=", jive_mtdset);
 
+/* LCD timing and setup */
+
+#define LCD_XRES        (240)
+#define LCD_YRES        (320)
+#define LCD_LEFT_MARGIN  (12)
+#define LCD_RIGHT_MARGIN (12)
+#define LCD_LOWER_MARGIN (12)
+#define LCD_UPPER_MARGIN (12)
+#define LCD_VSYNC       (2)
+#define LCD_HSYNC       (2)
+
+#define LCD_REFRESH     (60)
+
+#define LCD_HTOT (LCD_HSYNC + LCD_LEFT_MARGIN + LCD_XRES + LCD_RIGHT_MARGIN)
+#define LCD_VTOT (LCD_VSYNC + LCD_LOWER_MARGIN + LCD_YRES + LCD_UPPER_MARGIN)
+
+struct s3c2410fb_display jive_vgg2432a4_display[] = {
+       [0] = {
+               .width          = LCD_XRES,
+               .height         = LCD_YRES,
+               .xres           = LCD_XRES,
+               .yres           = LCD_YRES,
+               .left_margin    = LCD_LEFT_MARGIN,
+               .right_margin   = LCD_RIGHT_MARGIN,
+               .upper_margin   = LCD_UPPER_MARGIN,
+               .lower_margin   = LCD_LOWER_MARGIN,
+               .hsync_len      = LCD_HSYNC,
+               .vsync_len      = LCD_VSYNC,
+
+               .pixclock       = (1000000000000LL /
+                                  (LCD_REFRESH * LCD_HTOT * LCD_VTOT)),
+
+               .bpp            = 16,
+               .type           = (S3C2410_LCDCON1_TFT16BPP |
+                                  S3C2410_LCDCON1_TFT),
+
+               .lcdcon5        = (S3C2410_LCDCON5_FRM565 |
+                                  S3C2410_LCDCON5_INVVLINE |
+                                  S3C2410_LCDCON5_INVVFRAME |
+                                  S3C2410_LCDCON5_INVVDEN |
+                                  S3C2410_LCDCON5_PWREN),
+       },
+};
+
+/* todo - put into gpio header */
+
+#define S3C2410_GPCCON_MASK(x) (3 << ((x) * 2))
+#define S3C2410_GPDCON_MASK(x) (3 << ((x) * 2))
+
+struct s3c2410fb_mach_info jive_lcd_config = {
+       .displays        = jive_vgg2432a4_display,
+       .num_displays    = ARRAY_SIZE(jive_vgg2432a4_display),
+       .default_display = 0,
+
+       /* Enable VD[2..7], VD[10..15], VD[18..23] and VCLK, syncs, VDEN
+        * and disable the pull down resistors on pins we are using for LCD
+        * data. */
+
+       .gpcup          = (0xf << 1) | (0x3f << 10),
+
+       .gpccon         = (S3C2410_GPC1_VCLK   | S3C2410_GPC2_VLINE |
+                          S3C2410_GPC3_VFRAME | S3C2410_GPC4_VM |
+                          S3C2410_GPC10_VD2   | S3C2410_GPC11_VD3 |
+                          S3C2410_GPC12_VD4   | S3C2410_GPC13_VD5 |
+                          S3C2410_GPC14_VD6   | S3C2410_GPC15_VD7),
+
+       .gpccon_mask    = (S3C2410_GPCCON_MASK(1)  | S3C2410_GPCCON_MASK(2)  |
+                          S3C2410_GPCCON_MASK(3)  | S3C2410_GPCCON_MASK(4)  |
+                          S3C2410_GPCCON_MASK(10) | S3C2410_GPCCON_MASK(11) |
+                          S3C2410_GPCCON_MASK(12) | S3C2410_GPCCON_MASK(13) |
+                          S3C2410_GPCCON_MASK(14) | S3C2410_GPCCON_MASK(15)),
+
+       .gpdup          = (0x3f << 2) | (0x3f << 10),
+
+       .gpdcon         = (S3C2410_GPD2_VD10  | S3C2410_GPD3_VD11 |
+                          S3C2410_GPD4_VD12  | S3C2410_GPD5_VD13 |
+                          S3C2410_GPD6_VD14  | S3C2410_GPD7_VD15 |
+                          S3C2410_GPD10_VD18 | S3C2410_GPD11_VD19 |
+                          S3C2410_GPD12_VD20 | S3C2410_GPD13_VD21 |
+                          S3C2410_GPD14_VD22 | S3C2410_GPD15_VD23),
+
+       .gpdcon_mask    = (S3C2410_GPDCON_MASK(2)  | S3C2410_GPDCON_MASK(3) |
+                          S3C2410_GPDCON_MASK(4)  | S3C2410_GPDCON_MASK(5) |
+                          S3C2410_GPDCON_MASK(6)  | S3C2410_GPDCON_MASK(7) |
+                          S3C2410_GPDCON_MASK(10) | S3C2410_GPDCON_MASK(11)|
+                          S3C2410_GPDCON_MASK(12) | S3C2410_GPDCON_MASK(13)|
+                          S3C2410_GPDCON_MASK(14) | S3C2410_GPDCON_MASK(15)),
+};
+
+/* ILI9320 support. */
+
+static void jive_lcm_reset(unsigned int set)
+{
+       printk(KERN_DEBUG "%s(%d)\n", __func__, set);
+
+       s3c2410_gpio_setpin(S3C2410_GPG13, set);
+       s3c2410_gpio_cfgpin(S3C2410_GPG13, S3C2410_GPIO_OUTPUT);
+}
+
+#undef LCD_UPPER_MARGIN
+#define LCD_UPPER_MARGIN 2
+
+static struct ili9320_platdata jive_lcm_config = {
+       .hsize          = LCD_XRES,
+       .vsize          = LCD_YRES,
+
+       .reset          = jive_lcm_reset,
+       .suspend        = ILI9320_SUSPEND_DEEP,
+
+       .entry_mode     = ILI9320_ENTRYMODE_ID(3) | ILI9320_ENTRYMODE_BGR,
+       .display2       = (ILI9320_DISPLAY2_FP(LCD_UPPER_MARGIN) |
+                          ILI9320_DISPLAY2_BP(LCD_LOWER_MARGIN)),
+       .display3       = 0x0,
+       .display4       = 0x0,
+       .rgb_if1        = (ILI9320_RGBIF1_RIM_RGB18 |
+                          ILI9320_RGBIF1_RM | ILI9320_RGBIF1_CLK_RGBIF),
+       .rgb_if2        = ILI9320_RGBIF2_DPL,
+       .interface2     = 0x0,
+       .interface3     = 0x3,
+       .interface4     = (ILI9320_INTERFACE4_RTNE(16) |
+                          ILI9320_INTERFACE4_DIVE(1)),
+       .interface5     = 0x0,
+       .interface6     = 0x0,
+};
+
+/* LCD SPI support */
+
+static void jive_lcd_spi_chipselect(struct s3c2410_spigpio_info *spi, int cs)
+{
+       s3c2410_gpio_setpin(S3C2410_GPB7, cs ? 0 : 1);
+}
+
+static struct s3c2410_spigpio_info jive_lcd_spi = {
+       .bus_num        = 0,
+       .pin_clk        = S3C2410_GPG8,
+       .pin_mosi       = S3C2410_GPB8,
+       .chip_select    = jive_lcd_spi_chipselect,
+};
+
+static struct platform_device jive_device_lcdspi = {
+       .name           = "s3c24xx-spi-gpio",
+       .id             = 1,
+       .num_resources  = 0,
+       .dev.platform_data = &jive_lcd_spi,
+};
+
+/* WM8750 audio code SPI definition */
+
+static void jive_wm8750_chipselect(struct s3c2410_spigpio_info *spi, int cs)
+{
+       s3c2410_gpio_setpin(S3C2410_GPH10, cs ? 0 : 1);
+}
+
+static struct s3c2410_spigpio_info jive_wm8750_spi = {
+       .bus_num        = 2,
+       .pin_clk        = S3C2410_GPB4,
+       .pin_mosi       = S3C2410_GPB9,
+       .chip_select    = jive_wm8750_chipselect,
+};
+
+static struct platform_device jive_device_wm8750 = {
+       .name           = "s3c24xx-spi-gpio",
+       .id             = 2,
+       .num_resources  = 0,
+       .dev.platform_data = &jive_wm8750_spi,
+};
+
+/* JIVE SPI devices. */
+
+static struct spi_board_info __initdata jive_spi_devs[] = {
+       [0] = {
+               .modalias       = "VGG2432A4",
+               .bus_num        = 1,
+               .chip_select    = 0,
+               .mode           = SPI_MODE_3,   /* CPOL=1, CPHA=1 */
+               .max_speed_hz   = 100000,
+               .platform_data  = &jive_lcm_config,
+       }, {
+               .modalias       = "WM8750",
+               .bus_num        = 2,
+               .chip_select    = 0,
+               .mode           = SPI_MODE_0,   /* CPOL=0, CPHA=0 */
+               .max_speed_hz   = 100000,
+       },
+};
+
+/* I2C bus and device configuration. */
+
+static struct s3c2410_platform_i2c jive_i2c_cfg = {
+       .max_freq       = 80 * 1000,
+       .bus_freq       = 50 * 1000,
+       .flags          = S3C_IICFLG_FILTER,
+       .sda_delay      = 2,
+};
+
+static struct i2c_board_info jive_i2c_devs[] = {
+       [0] = {
+               I2C_BOARD_INFO("lis302dl", 0x1c),
+               .irq    = IRQ_EINT14,
+       },
+};
+
+/* The platform devices being used. */
+
 static struct platform_device *jive_devices[] __initdata = {
        &s3c_device_usb,
        &s3c_device_rtc,
        &s3c_device_wdt,
        &s3c_device_i2c,
+       &s3c_device_lcd,
+       &jive_device_lcdspi,
+       &jive_device_wm8750,
        &s3c_device_nand,
        &s3c_device_usbgadget,
 };
@@ -312,6 +528,14 @@ static void __init jive_map_io(void)
        s3c24xx_init_uarts(jive_uartcfgs, ARRAY_SIZE(jive_uartcfgs));
 }
 
+static void jive_power_off(void)
+{
+       printk(KERN_INFO "powering system down...\n");
+
+       s3c2410_gpio_setpin(S3C2410_GPC5, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPC5, S3C2410_GPIO_OUTPUT);
+}
+
 static void __init jive_machine_init(void)
 {
        /* register system devices for managing low level suspend */
@@ -411,6 +635,25 @@ static void __init jive_machine_init(void)
 
        s3c_device_nand.dev.platform_data = &jive_nand_info;
 
+       /* initialise the spi */
+
+       s3c2410_gpio_setpin(S3C2410_GPG13, 0);
+       s3c2410_gpio_cfgpin(S3C2410_GPG13, S3C2410_GPIO_OUTPUT);
+
+       s3c2410_gpio_setpin(S3C2410_GPB7, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPB7, S3C2410_GPIO_OUTPUT);
+
+       s3c2410_gpio_setpin(S3C2410_GPB6, 0);
+       s3c2410_gpio_cfgpin(S3C2410_GPB6, S3C2410_GPIO_OUTPUT);
+
+       s3c2410_gpio_setpin(S3C2410_GPG8, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPG8, S3C2410_GPIO_OUTPUT);
+
+       /* initialise the WM8750 spi */
+
+       s3c2410_gpio_setpin(S3C2410_GPH10, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPH10, S3C2410_GPIO_OUTPUT);
+
        /* Turn off suspend on both USB ports, and switch the
         * selectable USB port to USB device mode. */
 
@@ -419,6 +662,14 @@ static void __init jive_machine_init(void)
                              S3C2410_MISCCR_USBSUSPND1, 0x0);
 
        s3c24xx_udc_set_platdata(&jive_udc_cfg);
+       s3c24xx_fb_set_platdata(&jive_lcd_config);
+
+       spi_register_board_info(jive_spi_devs, ARRAY_SIZE(jive_spi_devs));
+
+       s3c_device_i2c.dev.platform_data = &jive_i2c_cfg;
+       i2c_register_board_info(0, jive_i2c_devs, ARRAY_SIZE(jive_i2c_devs));
+
+       pm_power_off = jive_power_off;
 
        platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices));
 }