]>
Commit | Line | Data |
---|---|---|
9c2816f7 CM |
1 | /* |
2 | * HTC Herald board configuration | |
3 | * Copyright (C) 2009 Cory Maccarrone <darkstar6262@gmail.com> | |
4 | * Copyright (C) 2009 Wing Linux | |
5 | * | |
6 | * Based on the board-htcwizard.c file from the linwizard project: | |
7 | * Copyright (C) 2006 Unai Uribarri | |
8 | * Copyright (C) 2008 linwizard.sourceforge.net | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License as | |
12 | * published by the Free Software Foundation; either version 2 of the | |
13 | * License, or (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
23 | * 02110-1301, USA. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include <linux/kernel.h> | |
28 | #include <linux/init.h> | |
29 | #include <linux/platform_device.h> | |
30 | #include <linux/input.h> | |
9c2816f7 CM |
31 | #include <linux/io.h> |
32 | #include <linux/gpio.h> | |
33 | ||
34 | #include <asm/mach-types.h> | |
35 | #include <asm/mach/arch.h> | |
36 | ||
37 | #include <plat/omap7xx.h> | |
38 | #include <plat/common.h> | |
39 | #include <plat/board.h> | |
40 | #include <plat/keypad.h> | |
106997c1 | 41 | #include <plat/usb.h> |
9c2816f7 CM |
42 | |
43 | #include <mach/irqs.h> | |
44 | ||
45 | #include <linux/delay.h> | |
46 | ||
47 | /* LCD register definition */ | |
48 | #define OMAP_LCDC_CONTROL (0xfffec000 + 0x00) | |
49 | #define OMAP_LCDC_STATUS (0xfffec000 + 0x10) | |
50 | #define OMAP_DMA_LCD_CCR (0xfffee300 + 0xc2) | |
51 | #define OMAP_DMA_LCD_CTRL (0xfffee300 + 0xc4) | |
52 | #define OMAP_LCDC_CTRL_LCD_EN (1 << 0) | |
53 | #define OMAP_LCDC_STAT_DONE (1 << 0) | |
54 | ||
55 | static struct omap_lcd_config htcherald_lcd_config __initdata = { | |
56 | .ctrl_name = "internal", | |
57 | }; | |
58 | ||
59 | static struct omap_board_config_kernel htcherald_config[] __initdata = { | |
60 | { OMAP_TAG_LCD, &htcherald_lcd_config }, | |
61 | }; | |
62 | ||
63 | /* Keyboard definition */ | |
64 | ||
65 | static int htc_herald_keymap[] = { | |
66 | KEY(0, 0, KEY_RECORD), /* Mail button */ | |
67 | KEY(0, 1, KEY_CAMERA), /* Camera */ | |
68 | KEY(0, 2, KEY_PHONE), /* Send key */ | |
69 | KEY(0, 3, KEY_VOLUMEUP), /* Volume up */ | |
70 | KEY(0, 4, KEY_F2), /* Right bar (landscape) */ | |
71 | KEY(0, 5, KEY_MAIL), /* Win key (portrait) */ | |
72 | KEY(0, 6, KEY_DIRECTORY), /* Right bar (protrait) */ | |
73 | KEY(1, 0, KEY_LEFTCTRL), /* Windows key */ | |
74 | KEY(1, 1, KEY_COMMA), | |
75 | KEY(1, 2, KEY_M), | |
76 | KEY(1, 3, KEY_K), | |
77 | KEY(1, 4, KEY_SLASH), /* OK key */ | |
78 | KEY(1, 5, KEY_I), | |
79 | KEY(1, 6, KEY_U), | |
80 | KEY(2, 0, KEY_LEFTALT), | |
81 | KEY(2, 1, KEY_TAB), | |
82 | KEY(2, 2, KEY_N), | |
83 | KEY(2, 3, KEY_J), | |
84 | KEY(2, 4, KEY_ENTER), | |
85 | KEY(2, 5, KEY_H), | |
86 | KEY(2, 6, KEY_Y), | |
87 | KEY(3, 0, KEY_SPACE), | |
88 | KEY(3, 1, KEY_L), | |
89 | KEY(3, 2, KEY_B), | |
90 | KEY(3, 3, KEY_V), | |
91 | KEY(3, 4, KEY_BACKSPACE), | |
92 | KEY(3, 5, KEY_G), | |
93 | KEY(3, 6, KEY_T), | |
94 | KEY(4, 0, KEY_CAPSLOCK), /* Shift */ | |
95 | KEY(4, 1, KEY_C), | |
96 | KEY(4, 2, KEY_F), | |
97 | KEY(4, 3, KEY_R), | |
98 | KEY(4, 4, KEY_O), | |
99 | KEY(4, 5, KEY_E), | |
100 | KEY(4, 6, KEY_D), | |
101 | KEY(5, 0, KEY_X), | |
102 | KEY(5, 1, KEY_Z), | |
103 | KEY(5, 2, KEY_S), | |
104 | KEY(5, 3, KEY_W), | |
105 | KEY(5, 4, KEY_P), | |
106 | KEY(5, 5, KEY_Q), | |
107 | KEY(5, 6, KEY_A), | |
108 | KEY(6, 0, KEY_CONNECT), /* Voice button */ | |
109 | KEY(6, 2, KEY_CANCEL), /* End key */ | |
110 | KEY(6, 3, KEY_VOLUMEDOWN), /* Volume down */ | |
111 | KEY(6, 4, KEY_F1), /* Left bar (landscape) */ | |
112 | KEY(6, 5, KEY_WWW), /* OK button (portrait) */ | |
113 | KEY(6, 6, KEY_CALENDAR), /* Left bar (portrait) */ | |
114 | 0 | |
115 | }; | |
116 | ||
117 | struct omap_kp_platform_data htcherald_kp_data = { | |
118 | .rows = 7, | |
119 | .cols = 7, | |
120 | .delay = 20, | |
121 | .rep = 1, | |
122 | .keymap = htc_herald_keymap, | |
123 | }; | |
124 | ||
125 | static struct resource kp_resources[] = { | |
126 | [0] = { | |
127 | .start = INT_7XX_MPUIO_KEYPAD, | |
128 | .end = INT_7XX_MPUIO_KEYPAD, | |
129 | .flags = IORESOURCE_IRQ, | |
130 | }, | |
131 | }; | |
132 | ||
133 | static struct platform_device kp_device = { | |
134 | .name = "omap-keypad", | |
135 | .id = -1, | |
136 | .dev = { | |
137 | .platform_data = &htcherald_kp_data, | |
138 | }, | |
139 | .num_resources = ARRAY_SIZE(kp_resources), | |
140 | .resource = kp_resources, | |
141 | }; | |
142 | ||
106997c1 CM |
143 | /* USB Device */ |
144 | static struct omap_usb_config htcherald_usb_config __initdata = { | |
145 | .otg = 0, | |
146 | .register_host = 0, | |
147 | .register_dev = 1, | |
148 | .hmc_mode = 4, | |
149 | .pins[0] = 2, | |
150 | }; | |
151 | ||
9c2816f7 CM |
152 | /* LCD Device resources */ |
153 | static struct platform_device lcd_device = { | |
154 | .name = "lcd_htcherald", | |
155 | .id = -1, | |
156 | }; | |
157 | ||
158 | static struct platform_device *devices[] __initdata = { | |
159 | &kp_device, | |
160 | &lcd_device, | |
161 | }; | |
162 | ||
163 | /* | |
164 | * Init functions from here on | |
165 | */ | |
166 | ||
167 | static void __init htcherald_lcd_init(void) | |
168 | { | |
169 | u32 reg; | |
170 | unsigned int tries = 200; | |
171 | ||
172 | /* disable controller if active */ | |
173 | reg = omap_readl(OMAP_LCDC_CONTROL); | |
174 | if (reg & OMAP_LCDC_CTRL_LCD_EN) { | |
175 | reg &= ~OMAP_LCDC_CTRL_LCD_EN; | |
176 | omap_writel(reg, OMAP_LCDC_CONTROL); | |
177 | ||
178 | /* wait for end of frame */ | |
179 | while (!(omap_readl(OMAP_LCDC_STATUS) & OMAP_LCDC_STAT_DONE)) { | |
180 | tries--; | |
181 | if (!tries) | |
182 | break; | |
183 | } | |
184 | if (!tries) | |
185 | printk(KERN_WARNING "Timeout waiting for end of frame " | |
186 | "-- LCD may not be available\n"); | |
187 | ||
188 | /* turn off DMA */ | |
189 | reg = omap_readw(OMAP_DMA_LCD_CCR); | |
190 | reg &= ~(1 << 7); | |
191 | omap_writew(reg, OMAP_DMA_LCD_CCR); | |
192 | ||
193 | reg = omap_readw(OMAP_DMA_LCD_CTRL); | |
194 | reg &= ~(1 << 8); | |
195 | omap_writew(reg, OMAP_DMA_LCD_CTRL); | |
196 | } | |
197 | } | |
198 | ||
199 | static void __init htcherald_map_io(void) | |
200 | { | |
201 | omap1_map_common_io(); | |
202 | ||
203 | /* | |
204 | * The LCD panel must be disabled and DMA turned off here, as doing | |
205 | * it later causes the LCD never to reinitialize. | |
206 | */ | |
207 | htcherald_lcd_init(); | |
208 | ||
209 | printk(KERN_INFO "htcherald_map_io done.\n"); | |
210 | } | |
211 | ||
212 | static void __init htcherald_disable_watchdog(void) | |
213 | { | |
214 | /* Disable watchdog if running */ | |
215 | if (omap_readl(OMAP_WDT_TIMER_MODE) & 0x8000) { | |
216 | /* | |
217 | * disable a potentially running watchdog timer before | |
218 | * it kills us. | |
219 | */ | |
220 | printk(KERN_WARNING "OMAP850 Watchdog seems to be activated, disabling it for now.\n"); | |
221 | omap_writel(0xF5, OMAP_WDT_TIMER_MODE); | |
222 | omap_writel(0xA0, OMAP_WDT_TIMER_MODE); | |
223 | } | |
224 | } | |
225 | ||
106997c1 CM |
226 | #define HTCHERALD_GPIO_USB_EN1 33 |
227 | #define HTCHERALD_GPIO_USB_EN2 73 | |
228 | #define HTCHERALD_GPIO_USB_DM 35 | |
229 | #define HTCHERALD_GPIO_USB_DP 36 | |
230 | ||
231 | static void __init htcherald_usb_enable(void) | |
232 | { | |
233 | unsigned int tries = 20; | |
234 | unsigned int value = 0; | |
235 | ||
236 | /* Request the GPIOs we need to control here */ | |
237 | if (gpio_request(HTCHERALD_GPIO_USB_EN1, "herald_usb") < 0) | |
238 | goto err1; | |
239 | ||
240 | if (gpio_request(HTCHERALD_GPIO_USB_EN2, "herald_usb") < 0) | |
241 | goto err2; | |
242 | ||
243 | if (gpio_request(HTCHERALD_GPIO_USB_DM, "herald_usb") < 0) | |
244 | goto err3; | |
245 | ||
246 | if (gpio_request(HTCHERALD_GPIO_USB_DP, "herald_usb") < 0) | |
247 | goto err4; | |
248 | ||
249 | /* force USB_EN GPIO to 0 */ | |
250 | do { | |
251 | /* output low */ | |
252 | gpio_direction_output(HTCHERALD_GPIO_USB_EN1, 0); | |
253 | } while ((value = gpio_get_value(HTCHERALD_GPIO_USB_EN1)) == 1 && | |
254 | --tries); | |
255 | ||
256 | if (value == 1) | |
257 | printk(KERN_WARNING "Unable to reset USB, trying to continue\n"); | |
258 | ||
259 | gpio_direction_output(HTCHERALD_GPIO_USB_EN2, 0); /* output low */ | |
260 | gpio_direction_input(HTCHERALD_GPIO_USB_DM); /* input */ | |
261 | gpio_direction_input(HTCHERALD_GPIO_USB_DP); /* input */ | |
262 | ||
263 | goto done; | |
264 | ||
265 | err4: | |
266 | gpio_free(HTCHERALD_GPIO_USB_DM); | |
267 | err3: | |
268 | gpio_free(HTCHERALD_GPIO_USB_EN2); | |
269 | err2: | |
270 | gpio_free(HTCHERALD_GPIO_USB_EN1); | |
271 | err1: | |
272 | printk(KERN_ERR "Unabled to request GPIO for USB\n"); | |
273 | done: | |
274 | printk(KERN_INFO "USB setup complete.\n"); | |
275 | } | |
276 | ||
9c2816f7 CM |
277 | static void __init htcherald_init(void) |
278 | { | |
279 | printk(KERN_INFO "HTC Herald init.\n"); | |
280 | ||
281 | omap_gpio_init(); | |
282 | ||
283 | omap_board_config = htcherald_config; | |
284 | omap_board_config_size = ARRAY_SIZE(htcherald_config); | |
285 | platform_add_devices(devices, ARRAY_SIZE(devices)); | |
286 | ||
287 | htcherald_disable_watchdog(); | |
106997c1 CM |
288 | |
289 | htcherald_usb_enable(); | |
290 | omap_usb_init(&htcherald_usb_config); | |
9c2816f7 CM |
291 | } |
292 | ||
293 | static void __init htcherald_init_irq(void) | |
294 | { | |
295 | printk(KERN_INFO "htcherald_init_irq.\n"); | |
296 | omap1_init_common_hw(); | |
297 | omap_init_irq(); | |
298 | } | |
299 | ||
300 | MACHINE_START(HERALD, "HTC Herald") | |
301 | /* Maintainer: Cory Maccarrone <darkstar6262@gmail.com> */ | |
302 | /* Maintainer: wing-linux.sourceforge.net */ | |
303 | .phys_io = 0xfff00000, | |
304 | .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc, | |
305 | .boot_params = 0x10000100, | |
306 | .map_io = htcherald_map_io, | |
71ee7dad | 307 | .reserve = omap_reserve, |
9c2816f7 CM |
308 | .init_irq = htcherald_init_irq, |
309 | .init_machine = htcherald_init, | |
310 | .timer = &omap_timer, | |
311 | MACHINE_END |