ARM: 6061/1: PL061 GPIO: Bug fix - setting gpio for HIGH_LEVEL interrupt is not working.
[pandora-kernel.git] / arch / arm / mach-omap2 / board-am3517evm.c
1 /*
2  * linux/arch/arm/mach-omap2/board-am3517evm.c
3  *
4  * Copyright (C) 2009 Texas Instruments Incorporated
5  * Author: Ranjith Lohithakshan <ranjithl@ti.com>
6  *
7  * Based on mach-omap2/board-omap3evm.c
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as  published by the
11  * Free Software Foundation version 2.
12  *
13  * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
14  * whether express or implied; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  */
18
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/gpio.h>
23 #include <linux/i2c/pca953x.h>
24
25 #include <mach/hardware.h>
26 #include <mach/am35xx.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30
31 #include <plat/board.h>
32 #include <plat/common.h>
33 #include <plat/usb.h>
34 #include <plat/display.h>
35
36 #include "mux.h"
37
38 #define LCD_PANEL_PWR           176
39 #define LCD_PANEL_BKLIGHT_PWR   182
40 #define LCD_PANEL_PWM           181
41
42 static struct i2c_board_info __initdata am3517evm_i2c_boardinfo[] = {
43         {
44                 I2C_BOARD_INFO("s35390a", 0x30),
45                 .type           = "s35390a",
46         },
47 };
48
49 /*
50  * RTC - S35390A
51  */
52 #define GPIO_RTCS35390A_IRQ     55
53
54 static void __init am3517_evm_rtc_init(void)
55 {
56         int r;
57
58         omap_mux_init_gpio(GPIO_RTCS35390A_IRQ, OMAP_PIN_INPUT_PULLUP);
59         r = gpio_request(GPIO_RTCS35390A_IRQ, "rtcs35390a-irq");
60         if (r < 0) {
61                 printk(KERN_WARNING "failed to request GPIO#%d\n",
62                                 GPIO_RTCS35390A_IRQ);
63                 return;
64         }
65         r = gpio_direction_input(GPIO_RTCS35390A_IRQ);
66         if (r < 0) {
67                 printk(KERN_WARNING "GPIO#%d cannot be configured as input\n",
68                                 GPIO_RTCS35390A_IRQ);
69                 gpio_free(GPIO_RTCS35390A_IRQ);
70                 return;
71         }
72         am3517evm_i2c_boardinfo[0].irq = gpio_to_irq(GPIO_RTCS35390A_IRQ);
73 }
74
75 /*
76  * I2C GPIO Expander - TCA6416
77  */
78
79 /* Mounted on Base-Board */
80 static struct pca953x_platform_data am3517evm_gpio_expander_info_0 = {
81         .gpio_base      = OMAP_MAX_GPIO_LINES,
82 };
83 static struct i2c_board_info __initdata am3517evm_tca6416_info_0[] = {
84         {
85                 I2C_BOARD_INFO("tca6416", 0x21),
86                 .platform_data = &am3517evm_gpio_expander_info_0,
87         },
88 };
89
90 /* Mounted on UI Card */
91 static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_1 = {
92         .gpio_base      = OMAP_MAX_GPIO_LINES + 16,
93 };
94 static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_2 = {
95         .gpio_base      = OMAP_MAX_GPIO_LINES + 32,
96 };
97 static struct i2c_board_info __initdata am3517evm_ui_tca6416_info[] = {
98         {
99                 I2C_BOARD_INFO("tca6416", 0x20),
100                 .platform_data = &am3517evm_ui_gpio_expander_info_1,
101         },
102         {
103                 I2C_BOARD_INFO("tca6416", 0x21),
104                 .platform_data = &am3517evm_ui_gpio_expander_info_2,
105         },
106 };
107
108 static int __init am3517_evm_i2c_init(void)
109 {
110         omap_register_i2c_bus(1, 400, NULL, 0);
111         omap_register_i2c_bus(2, 400, am3517evm_tca6416_info_0,
112                         ARRAY_SIZE(am3517evm_tca6416_info_0));
113         omap_register_i2c_bus(3, 400, am3517evm_ui_tca6416_info,
114                         ARRAY_SIZE(am3517evm_ui_tca6416_info));
115
116         return 0;
117 }
118
119 static int lcd_enabled;
120 static int dvi_enabled;
121
122 static void __init am3517_evm_display_init(void)
123 {
124         int r;
125
126         omap_mux_init_gpio(LCD_PANEL_PWR, OMAP_PIN_INPUT_PULLUP);
127         omap_mux_init_gpio(LCD_PANEL_BKLIGHT_PWR, OMAP_PIN_INPUT_PULLDOWN);
128         omap_mux_init_gpio(LCD_PANEL_PWM, OMAP_PIN_INPUT_PULLDOWN);
129         /*
130          * Enable GPIO 182 = LCD Backlight Power
131          */
132         r = gpio_request(LCD_PANEL_BKLIGHT_PWR, "lcd_backlight_pwr");
133         if (r) {
134                 printk(KERN_ERR "failed to get lcd_backlight_pwr\n");
135                 return;
136         }
137         gpio_direction_output(LCD_PANEL_BKLIGHT_PWR, 1);
138         /*
139          * Enable GPIO 181 = LCD Panel PWM
140          */
141         r = gpio_request(LCD_PANEL_PWM, "lcd_pwm");
142         if (r) {
143                 printk(KERN_ERR "failed to get lcd_pwm\n");
144                 goto err_1;
145         }
146         gpio_direction_output(LCD_PANEL_PWM, 1);
147         /*
148          * Enable GPIO 176 = LCD Panel Power enable pin
149          */
150         r = gpio_request(LCD_PANEL_PWR, "lcd_panel_pwr");
151         if (r) {
152                 printk(KERN_ERR "failed to get lcd_panel_pwr\n");
153                 goto err_2;
154         }
155         gpio_direction_output(LCD_PANEL_PWR, 1);
156
157         printk(KERN_INFO "Display initialized successfully\n");
158         return;
159
160 err_2:
161         gpio_free(LCD_PANEL_PWM);
162 err_1:
163         gpio_free(LCD_PANEL_BKLIGHT_PWR);
164 }
165
166 static int am3517_evm_panel_enable_lcd(struct omap_dss_device *dssdev)
167 {
168         if (dvi_enabled) {
169                 printk(KERN_ERR "cannot enable LCD, DVI is enabled\n");
170                 return -EINVAL;
171         }
172         gpio_set_value(LCD_PANEL_PWR, 1);
173         lcd_enabled = 1;
174
175         return 0;
176 }
177
178 static void am3517_evm_panel_disable_lcd(struct omap_dss_device *dssdev)
179 {
180         gpio_set_value(LCD_PANEL_PWR, 0);
181         lcd_enabled = 0;
182 }
183
184 static struct omap_dss_device am3517_evm_lcd_device = {
185         .type                   = OMAP_DISPLAY_TYPE_DPI,
186         .name                   = "lcd",
187         .driver_name            = "sharp_lq_panel",
188         .phy.dpi.data_lines     = 16,
189         .platform_enable        = am3517_evm_panel_enable_lcd,
190         .platform_disable       = am3517_evm_panel_disable_lcd,
191 };
192
193 static int am3517_evm_panel_enable_tv(struct omap_dss_device *dssdev)
194 {
195         return 0;
196 }
197
198 static void am3517_evm_panel_disable_tv(struct omap_dss_device *dssdev)
199 {
200 }
201
202 static struct omap_dss_device am3517_evm_tv_device = {
203         .type                   = OMAP_DISPLAY_TYPE_VENC,
204         .name                   = "tv",
205         .driver_name            = "venc",
206         .phy.venc.type          = OMAP_DSS_VENC_TYPE_SVIDEO,
207         .platform_enable        = am3517_evm_panel_enable_tv,
208         .platform_disable       = am3517_evm_panel_disable_tv,
209 };
210
211 static int am3517_evm_panel_enable_dvi(struct omap_dss_device *dssdev)
212 {
213         if (lcd_enabled) {
214                 printk(KERN_ERR "cannot enable DVI, LCD is enabled\n");
215                 return -EINVAL;
216         }
217         dvi_enabled = 1;
218
219         return 0;
220 }
221
222 static void am3517_evm_panel_disable_dvi(struct omap_dss_device *dssdev)
223 {
224         dvi_enabled = 0;
225 }
226
227 static struct omap_dss_device am3517_evm_dvi_device = {
228         .type                   = OMAP_DISPLAY_TYPE_DPI,
229         .name                   = "dvi",
230         .driver_name            = "generic_panel",
231         .phy.dpi.data_lines     = 24,
232         .platform_enable        = am3517_evm_panel_enable_dvi,
233         .platform_disable       = am3517_evm_panel_disable_dvi,
234 };
235
236 static struct omap_dss_device *am3517_evm_dss_devices[] = {
237         &am3517_evm_lcd_device,
238         &am3517_evm_tv_device,
239         &am3517_evm_dvi_device,
240 };
241
242 static struct omap_dss_board_info am3517_evm_dss_data = {
243         .num_devices    = ARRAY_SIZE(am3517_evm_dss_devices),
244         .devices        = am3517_evm_dss_devices,
245         .default_device = &am3517_evm_lcd_device,
246 };
247
248 struct platform_device am3517_evm_dss_device = {
249         .name           = "omapdss",
250         .id             = -1,
251         .dev            = {
252                 .platform_data  = &am3517_evm_dss_data,
253         },
254 };
255
256 /*
257  * Board initialization
258  */
259 static struct omap_board_config_kernel am3517_evm_config[] __initdata = {
260 };
261
262 static struct platform_device *am3517_evm_devices[] __initdata = {
263         &am3517_evm_dss_device,
264 };
265
266 static void __init am3517_evm_init_irq(void)
267 {
268         omap_board_config = am3517_evm_config;
269         omap_board_config_size = ARRAY_SIZE(am3517_evm_config);
270
271         omap2_init_common_hw(NULL, NULL);
272         omap_init_irq();
273         omap_gpio_init();
274 }
275
276 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
277         .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
278         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
279         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
280
281         .phy_reset  = true,
282         .reset_gpio_port[0]  = 57,
283         .reset_gpio_port[1]  = -EINVAL,
284         .reset_gpio_port[2]  = -EINVAL
285 };
286
287 #ifdef CONFIG_OMAP_MUX
288 static struct omap_board_mux board_mux[] __initdata = {
289         { .reg_offset = OMAP_MUX_TERMINATOR },
290 };
291 #else
292 #define board_mux       NULL
293 #endif
294
295 static void __init am3517_evm_init(void)
296 {
297         am3517_evm_i2c_init();
298
299         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
300         platform_add_devices(am3517_evm_devices,
301                                 ARRAY_SIZE(am3517_evm_devices));
302
303         omap_serial_init();
304
305         /* Configure GPIO for EHCI port */
306         omap_mux_init_gpio(57, OMAP_PIN_OUTPUT);
307         usb_ehci_init(&ehci_pdata);
308         /* DSS */
309         am3517_evm_display_init();
310
311         /* RTC - S35390A */
312         am3517_evm_rtc_init();
313
314         i2c_register_board_info(1, am3517evm_i2c_boardinfo,
315                                 ARRAY_SIZE(am3517evm_i2c_boardinfo));
316 }
317
318 static void __init am3517_evm_map_io(void)
319 {
320         omap2_set_globals_343x();
321         omap34xx_map_common_io();
322 }
323
324 MACHINE_START(OMAP3517EVM, "OMAP3517/AM3517 EVM")
325         .phys_io        = 0x48000000,
326         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
327         .boot_params    = 0x80000100,
328         .map_io         = am3517_evm_map_io,
329         .init_irq       = am3517_evm_init_irq,
330         .init_machine   = am3517_evm_init,
331         .timer          = &omap_timer,
332 MACHINE_END