Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[pandora-kernel.git] / arch / arm / mach-omap2 / board-zoom-display.c
1 /*
2  * Copyright (C) 2010 Texas Instruments Inc.
3  *
4  * Modified from mach-omap2/board-zoom-peripherals.c
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/gpio.h>
15 #include <linux/i2c/twl.h>
16 #include <linux/spi/spi.h>
17 #include <plat/mcspi.h>
18 #include <plat/display.h>
19
20 #define LCD_PANEL_RESET_GPIO_PROD       96
21 #define LCD_PANEL_RESET_GPIO_PILOT      55
22 #define LCD_PANEL_QVGA_GPIO             56
23
24 static void zoom_lcd_panel_init(void)
25 {
26         int ret;
27         unsigned char lcd_panel_reset_gpio;
28
29         lcd_panel_reset_gpio = (omap_rev() > OMAP3430_REV_ES3_0) ?
30                         LCD_PANEL_RESET_GPIO_PROD :
31                         LCD_PANEL_RESET_GPIO_PILOT;
32
33         ret = gpio_request(lcd_panel_reset_gpio, "lcd reset");
34         if (ret) {
35                 pr_err("Failed to get LCD reset GPIO (gpio%d).\n",
36                         lcd_panel_reset_gpio);
37                 return;
38         }
39         gpio_direction_output(lcd_panel_reset_gpio, 1);
40
41         ret = gpio_request(LCD_PANEL_QVGA_GPIO, "lcd qvga");
42         if (ret) {
43                 pr_err("Failed to get LCD_PANEL_QVGA_GPIO (gpio%d).\n",
44                         LCD_PANEL_QVGA_GPIO);
45                 goto err0;
46         }
47         gpio_direction_output(LCD_PANEL_QVGA_GPIO, 1);
48
49         return;
50 err0:
51         gpio_free(lcd_panel_reset_gpio);
52 }
53
54 static int zoom_panel_enable_lcd(struct omap_dss_device *dssdev)
55 {
56         return 0;
57 }
58
59 static void zoom_panel_disable_lcd(struct omap_dss_device *dssdev)
60 {
61 }
62
63 /*
64  * PWMA/B register offsets (TWL4030_MODULE_PWMA)
65  */
66 #define TWL_INTBR_PMBR1 0xD
67 #define TWL_INTBR_GPBR1 0xC
68 #define TWL_LED_PWMON   0x0
69 #define TWL_LED_PWMOFF  0x1
70
71 static int zoom_set_bl_intensity(struct omap_dss_device *dssdev, int level)
72 {
73         unsigned char c;
74         u8 mux_pwm, enb_pwm;
75
76         if (level > 100)
77                 return -1;
78
79         twl_i2c_read_u8(TWL4030_MODULE_INTBR, &mux_pwm, TWL_INTBR_PMBR1);
80         twl_i2c_read_u8(TWL4030_MODULE_INTBR, &enb_pwm, TWL_INTBR_GPBR1);
81
82         if (level == 0) {
83                 /* disable pwm1 output and clock */
84                 enb_pwm = enb_pwm & 0xF5;
85                 /* change pwm1 pin to gpio pin */
86                 mux_pwm = mux_pwm & 0xCF;
87                 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
88                                         enb_pwm, TWL_INTBR_GPBR1);
89                 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
90                                         mux_pwm, TWL_INTBR_PMBR1);
91                 return 0;
92         }
93
94         if (!((enb_pwm & 0xA) && (mux_pwm & 0x30))) {
95                 /* change gpio pin to pwm1 pin */
96                 mux_pwm = mux_pwm | 0x30;
97                 /* enable pwm1 output and clock*/
98                 enb_pwm = enb_pwm | 0x0A;
99                 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
100                                         mux_pwm, TWL_INTBR_PMBR1);
101                 twl_i2c_write_u8(TWL4030_MODULE_INTBR,
102                                         enb_pwm, TWL_INTBR_GPBR1);
103         }
104
105         c = ((50 * (100 - level)) / 100) + 1;
106         twl_i2c_write_u8(TWL4030_MODULE_PWM1, 0x7F, TWL_LED_PWMOFF);
107         twl_i2c_write_u8(TWL4030_MODULE_PWM1, c, TWL_LED_PWMON);
108
109         return 0;
110 }
111
112 static struct omap_dss_device zoom_lcd_device = {
113         .name                   = "lcd",
114         .driver_name            = "NEC_8048_panel",
115         .type                   = OMAP_DISPLAY_TYPE_DPI,
116         .phy.dpi.data_lines     = 24,
117         .platform_enable        = zoom_panel_enable_lcd,
118         .platform_disable       = zoom_panel_disable_lcd,
119         .max_backlight_level    = 100,
120         .set_backlight          = zoom_set_bl_intensity,
121 };
122
123 static struct omap_dss_device *zoom_dss_devices[] = {
124         &zoom_lcd_device,
125 };
126
127 static struct omap_dss_board_info zoom_dss_data = {
128         .num_devices            = ARRAY_SIZE(zoom_dss_devices),
129         .devices                = zoom_dss_devices,
130         .default_device         = &zoom_lcd_device,
131 };
132
133 static struct platform_device zoom_dss_device = {
134         .name                           = "omapdss",
135         .id                             = -1,
136         .dev                            = {
137                 .platform_data          = &zoom_dss_data,
138         },
139 };
140
141 static struct omap2_mcspi_device_config dss_lcd_mcspi_config = {
142         .turbo_mode             = 1,
143         .single_channel = 1,  /* 0: slave, 1: master */
144 };
145
146 static struct spi_board_info nec_8048_spi_board_info[] __initdata = {
147         [0] = {
148                 .modalias               = "nec_8048_spi",
149                 .bus_num                = 1,
150                 .chip_select            = 2,
151                 .max_speed_hz           = 375000,
152                 .controller_data        = &dss_lcd_mcspi_config,
153         },
154 };
155
156 static struct platform_device *zoom_display_devices[] __initdata = {
157         &zoom_dss_device,
158 };
159
160 void __init zoom_display_init(void)
161 {
162         platform_add_devices(zoom_display_devices,
163                                 ARRAY_SIZE(zoom_display_devices));
164         spi_register_board_info(nec_8048_spi_board_info,
165                                 ARRAY_SIZE(nec_8048_spi_board_info));
166         zoom_lcd_panel_init();
167 }
168