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 | */ | |
9c2816f7 CM |
26 | #include <linux/kernel.h> |
27 | #include <linux/init.h> | |
28 | #include <linux/platform_device.h> | |
29 | #include <linux/input.h> | |
2e3ee9f4 | 30 | #include <linux/delay.h> |
9c2816f7 | 31 | #include <linux/gpio.h> |
493c32a0 CM |
32 | #include <linux/gpio_keys.h> |
33 | #include <linux/i2c.h> | |
34 | #include <linux/i2c-gpio.h> | |
35 | #include <linux/htcpld.h> | |
36 | #include <linux/leds.h> | |
37 | #include <linux/spi/spi.h> | |
38 | #include <linux/spi/ads7846.h> | |
ddba6c7f | 39 | #include <linux/omapfb.h> |
9c2816f7 CM |
40 | |
41 | #include <asm/mach-types.h> | |
42 | #include <asm/mach/arch.h> | |
43 | ||
44 | #include <plat/omap7xx.h> | |
9c2816f7 CM |
45 | #include <plat/board.h> |
46 | #include <plat/keypad.h> | |
493c32a0 | 47 | #include <plat/mmc.h> |
9c2816f7 CM |
48 | |
49 | #include <mach/irqs.h> | |
b924b204 | 50 | #include <mach/usb.h> |
9c2816f7 | 51 | |
2e3ee9f4 | 52 | #include "common.h" |
9c2816f7 CM |
53 | |
54 | /* LCD register definition */ | |
55 | #define OMAP_LCDC_CONTROL (0xfffec000 + 0x00) | |
56 | #define OMAP_LCDC_STATUS (0xfffec000 + 0x10) | |
57 | #define OMAP_DMA_LCD_CCR (0xfffee300 + 0xc2) | |
58 | #define OMAP_DMA_LCD_CTRL (0xfffee300 + 0xc4) | |
59 | #define OMAP_LCDC_CTRL_LCD_EN (1 << 0) | |
60 | #define OMAP_LCDC_STAT_DONE (1 << 0) | |
61 | ||
493c32a0 CM |
62 | /* GPIO definitions for the power button and keyboard slide switch */ |
63 | #define HTCHERALD_GPIO_POWER 139 | |
64 | #define HTCHERALD_GPIO_SLIDE 174 | |
65 | #define HTCHERALD_GIRQ_BTNS 141 | |
9c2816f7 | 66 | |
493c32a0 CM |
67 | /* GPIO definitions for the touchscreen */ |
68 | #define HTCHERALD_GPIO_TS 76 | |
69 | ||
70 | /* HTCPLD definitions */ | |
71 | ||
72 | /* | |
73 | * CPLD Logic | |
74 | * | |
75 | * Chip 3 - 0x03 | |
76 | * | |
77 | * Function 7 6 5 4 3 2 1 0 | |
78 | * ------------------------------------ | |
79 | * DPAD light x x x x x x x 1 | |
80 | * SoundDev x x x x 1 x x x | |
81 | * Screen white 1 x x x x x x x | |
82 | * MMC power on x x x x x 1 x x | |
83 | * Happy times (n) 0 x x x x 1 x x | |
84 | * | |
85 | * Chip 4 - 0x04 | |
86 | * | |
87 | * Function 7 6 5 4 3 2 1 0 | |
88 | * ------------------------------------ | |
89 | * Keyboard light x x x x x x x 1 | |
90 | * LCD Bright (4) x x x x x 1 1 x | |
91 | * LCD Bright (3) x x x x x 0 1 x | |
92 | * LCD Bright (2) x x x x x 1 0 x | |
93 | * LCD Bright (1) x x x x x 0 0 x | |
94 | * LCD Off x x x x 0 x x x | |
95 | * LCD image (fb) 1 x x x x x x x | |
96 | * LCD image (white) 0 x x x x x x x | |
97 | * Caps lock LED x x 1 x x x x x | |
98 | * | |
99 | * Chip 5 - 0x05 | |
100 | * | |
101 | * Function 7 6 5 4 3 2 1 0 | |
102 | * ------------------------------------ | |
103 | * Red (solid) x x x x x 1 x x | |
104 | * Red (flash) x x x x x x 1 x | |
105 | * Green (GSM flash) x x x x 1 x x x | |
106 | * Green (GSM solid) x x x 1 x x x x | |
107 | * Green (wifi flash) x x 1 x x x x x | |
108 | * Blue (bt flash) x 1 x x x x x x | |
109 | * DPAD Int Enable 1 x x x x x x 0 | |
110 | * | |
111 | * (Combinations of the above can be made for different colors.) | |
112 | * The direction pad interrupt enable must be set each time the | |
113 | * interrupt is handled. | |
114 | * | |
115 | * Chip 6 - 0x06 | |
116 | * | |
117 | * Function 7 6 5 4 3 2 1 0 | |
118 | * ------------------------------------ | |
119 | * Vibrator x x x x 1 x x x | |
120 | * Alt LED x x x 1 x x x x | |
121 | * Screen white 1 x x x x x x x | |
122 | * Screen white x x 1 x x x x x | |
123 | * Screen white x 0 x x x x x x | |
124 | * Enable kbd dpad x x x x x x 0 x | |
125 | * Happy Times 0 1 0 x x x 0 x | |
126 | */ | |
127 | ||
128 | /* | |
129 | * HTCPLD GPIO lines start 16 after OMAP_MAX_GPIO_LINES to account | |
130 | * for the 16 MPUIO lines. | |
131 | */ | |
132 | #define HTCPLD_GPIO_START_OFFSET (OMAP_MAX_GPIO_LINES + 16) | |
133 | #define HTCPLD_IRQ(chip, offset) (OMAP_IRQ_END + 8 * (chip) + (offset)) | |
134 | #define HTCPLD_BASE(chip, offset) \ | |
135 | (HTCPLD_GPIO_START_OFFSET + 8 * (chip) + (offset)) | |
136 | ||
137 | #define HTCPLD_GPIO_LED_DPAD HTCPLD_BASE(0, 0) | |
138 | #define HTCPLD_GPIO_LED_KBD HTCPLD_BASE(1, 0) | |
139 | #define HTCPLD_GPIO_LED_CAPS HTCPLD_BASE(1, 5) | |
140 | #define HTCPLD_GPIO_LED_RED_FLASH HTCPLD_BASE(2, 1) | |
141 | #define HTCPLD_GPIO_LED_RED_SOLID HTCPLD_BASE(2, 2) | |
142 | #define HTCPLD_GPIO_LED_GREEN_FLASH HTCPLD_BASE(2, 3) | |
143 | #define HTCPLD_GPIO_LED_GREEN_SOLID HTCPLD_BASE(2, 4) | |
144 | #define HTCPLD_GPIO_LED_WIFI HTCPLD_BASE(2, 5) | |
145 | #define HTCPLD_GPIO_LED_BT HTCPLD_BASE(2, 6) | |
146 | #define HTCPLD_GPIO_LED_VIBRATE HTCPLD_BASE(3, 3) | |
147 | #define HTCPLD_GPIO_LED_ALT HTCPLD_BASE(3, 4) | |
148 | ||
149 | #define HTCPLD_GPIO_RIGHT_KBD HTCPLD_BASE(6, 7) | |
150 | #define HTCPLD_GPIO_UP_KBD HTCPLD_BASE(6, 6) | |
151 | #define HTCPLD_GPIO_LEFT_KBD HTCPLD_BASE(6, 5) | |
152 | #define HTCPLD_GPIO_DOWN_KBD HTCPLD_BASE(6, 4) | |
153 | ||
154 | #define HTCPLD_GPIO_RIGHT_DPAD HTCPLD_BASE(7, 7) | |
155 | #define HTCPLD_GPIO_UP_DPAD HTCPLD_BASE(7, 6) | |
156 | #define HTCPLD_GPIO_LEFT_DPAD HTCPLD_BASE(7, 5) | |
157 | #define HTCPLD_GPIO_DOWN_DPAD HTCPLD_BASE(7, 4) | |
158 | #define HTCPLD_GPIO_ENTER_DPAD HTCPLD_BASE(7, 3) | |
159 | ||
160 | /* | |
161 | * The htcpld chip requires a gpio write to a specific line | |
162 | * to re-enable interrupts after one has occurred. | |
163 | */ | |
164 | #define HTCPLD_GPIO_INT_RESET_HI HTCPLD_BASE(2, 7) | |
165 | #define HTCPLD_GPIO_INT_RESET_LO HTCPLD_BASE(2, 0) | |
166 | ||
167 | /* Chip 5 */ | |
168 | #define HTCPLD_IRQ_RIGHT_KBD HTCPLD_IRQ(0, 7) | |
169 | #define HTCPLD_IRQ_UP_KBD HTCPLD_IRQ(0, 6) | |
170 | #define HTCPLD_IRQ_LEFT_KBD HTCPLD_IRQ(0, 5) | |
171 | #define HTCPLD_IRQ_DOWN_KBD HTCPLD_IRQ(0, 4) | |
172 | ||
173 | /* Chip 6 */ | |
174 | #define HTCPLD_IRQ_RIGHT_DPAD HTCPLD_IRQ(1, 7) | |
175 | #define HTCPLD_IRQ_UP_DPAD HTCPLD_IRQ(1, 6) | |
176 | #define HTCPLD_IRQ_LEFT_DPAD HTCPLD_IRQ(1, 5) | |
177 | #define HTCPLD_IRQ_DOWN_DPAD HTCPLD_IRQ(1, 4) | |
178 | #define HTCPLD_IRQ_ENTER_DPAD HTCPLD_IRQ(1, 3) | |
9c2816f7 CM |
179 | |
180 | /* Keyboard definition */ | |
181 | ||
da1f026b | 182 | static const unsigned int htc_herald_keymap[] = { |
9c2816f7 | 183 | KEY(0, 0, KEY_RECORD), /* Mail button */ |
da1f026b JK |
184 | KEY(1, 0, KEY_CAMERA), /* Camera */ |
185 | KEY(2, 0, KEY_PHONE), /* Send key */ | |
186 | KEY(3, 0, KEY_VOLUMEUP), /* Volume up */ | |
187 | KEY(4, 0, KEY_F2), /* Right bar (landscape) */ | |
188 | KEY(5, 0, KEY_MAIL), /* Win key (portrait) */ | |
189 | KEY(6, 0, KEY_DIRECTORY), /* Right bar (protrait) */ | |
190 | KEY(0, 1, KEY_LEFTCTRL), /* Windows key */ | |
9c2816f7 | 191 | KEY(1, 1, KEY_COMMA), |
da1f026b JK |
192 | KEY(2, 1, KEY_M), |
193 | KEY(3, 1, KEY_K), | |
194 | KEY(4, 1, KEY_SLASH), /* OK key */ | |
195 | KEY(5, 1, KEY_I), | |
196 | KEY(6, 1, KEY_U), | |
197 | KEY(0, 2, KEY_LEFTALT), | |
198 | KEY(1, 2, KEY_TAB), | |
9c2816f7 | 199 | KEY(2, 2, KEY_N), |
da1f026b JK |
200 | KEY(3, 2, KEY_J), |
201 | KEY(4, 2, KEY_ENTER), | |
202 | KEY(5, 2, KEY_H), | |
203 | KEY(6, 2, KEY_Y), | |
204 | KEY(0, 3, KEY_SPACE), | |
205 | KEY(1, 3, KEY_L), | |
206 | KEY(2, 3, KEY_B), | |
9c2816f7 | 207 | KEY(3, 3, KEY_V), |
da1f026b JK |
208 | KEY(4, 3, KEY_BACKSPACE), |
209 | KEY(5, 3, KEY_G), | |
210 | KEY(6, 3, KEY_T), | |
211 | KEY(0, 4, KEY_CAPSLOCK), /* Shift */ | |
212 | KEY(1, 4, KEY_C), | |
213 | KEY(2, 4, KEY_F), | |
214 | KEY(3, 4, KEY_R), | |
9c2816f7 | 215 | KEY(4, 4, KEY_O), |
da1f026b JK |
216 | KEY(5, 4, KEY_E), |
217 | KEY(6, 4, KEY_D), | |
218 | KEY(0, 5, KEY_X), | |
219 | KEY(1, 5, KEY_Z), | |
220 | KEY(2, 5, KEY_S), | |
221 | KEY(3, 5, KEY_W), | |
222 | KEY(4, 5, KEY_P), | |
9c2816f7 | 223 | KEY(5, 5, KEY_Q), |
da1f026b JK |
224 | KEY(6, 5, KEY_A), |
225 | KEY(0, 6, KEY_CONNECT), /* Voice button */ | |
226 | KEY(2, 6, KEY_CANCEL), /* End key */ | |
227 | KEY(3, 6, KEY_VOLUMEDOWN), /* Volume down */ | |
228 | KEY(4, 6, KEY_F1), /* Left bar (landscape) */ | |
229 | KEY(5, 6, KEY_WWW), /* OK button (portrait) */ | |
9c2816f7 | 230 | KEY(6, 6, KEY_CALENDAR), /* Left bar (portrait) */ |
9c2816f7 CM |
231 | }; |
232 | ||
da1f026b JK |
233 | static const struct matrix_keymap_data htc_herald_keymap_data = { |
234 | .keymap = htc_herald_keymap, | |
235 | .keymap_size = ARRAY_SIZE(htc_herald_keymap), | |
236 | }; | |
237 | ||
238 | static struct omap_kp_platform_data htcherald_kp_data = { | |
9c2816f7 CM |
239 | .rows = 7, |
240 | .cols = 7, | |
241 | .delay = 20, | |
da1f026b JK |
242 | .rep = true, |
243 | .keymap_data = &htc_herald_keymap_data, | |
9c2816f7 CM |
244 | }; |
245 | ||
246 | static struct resource kp_resources[] = { | |
247 | [0] = { | |
248 | .start = INT_7XX_MPUIO_KEYPAD, | |
249 | .end = INT_7XX_MPUIO_KEYPAD, | |
250 | .flags = IORESOURCE_IRQ, | |
251 | }, | |
252 | }; | |
253 | ||
254 | static struct platform_device kp_device = { | |
255 | .name = "omap-keypad", | |
256 | .id = -1, | |
257 | .dev = { | |
258 | .platform_data = &htcherald_kp_data, | |
259 | }, | |
260 | .num_resources = ARRAY_SIZE(kp_resources), | |
261 | .resource = kp_resources, | |
262 | }; | |
263 | ||
493c32a0 CM |
264 | /* GPIO buttons for keyboard slide and power button */ |
265 | static struct gpio_keys_button herald_gpio_keys_table[] = { | |
266 | {BTN_0, HTCHERALD_GPIO_POWER, 1, "POWER", EV_KEY, 1, 20}, | |
267 | {SW_LID, HTCHERALD_GPIO_SLIDE, 0, "SLIDE", EV_SW, 1, 20}, | |
268 | ||
269 | {KEY_LEFT, HTCPLD_GPIO_LEFT_KBD, 1, "LEFT", EV_KEY, 1, 20}, | |
270 | {KEY_RIGHT, HTCPLD_GPIO_RIGHT_KBD, 1, "RIGHT", EV_KEY, 1, 20}, | |
271 | {KEY_UP, HTCPLD_GPIO_UP_KBD, 1, "UP", EV_KEY, 1, 20}, | |
272 | {KEY_DOWN, HTCPLD_GPIO_DOWN_KBD, 1, "DOWN", EV_KEY, 1, 20}, | |
273 | ||
274 | {KEY_LEFT, HTCPLD_GPIO_LEFT_DPAD, 1, "DLEFT", EV_KEY, 1, 20}, | |
275 | {KEY_RIGHT, HTCPLD_GPIO_RIGHT_DPAD, 1, "DRIGHT", EV_KEY, 1, 20}, | |
276 | {KEY_UP, HTCPLD_GPIO_UP_DPAD, 1, "DUP", EV_KEY, 1, 20}, | |
277 | {KEY_DOWN, HTCPLD_GPIO_DOWN_DPAD, 1, "DDOWN", EV_KEY, 1, 20}, | |
278 | {KEY_ENTER, HTCPLD_GPIO_ENTER_DPAD, 1, "DENTER", EV_KEY, 1, 20}, | |
279 | }; | |
280 | ||
281 | static struct gpio_keys_platform_data herald_gpio_keys_data = { | |
282 | .buttons = herald_gpio_keys_table, | |
283 | .nbuttons = ARRAY_SIZE(herald_gpio_keys_table), | |
da1f026b | 284 | .rep = true, |
493c32a0 CM |
285 | }; |
286 | ||
287 | static struct platform_device herald_gpiokeys_device = { | |
288 | .name = "gpio-keys", | |
289 | .id = -1, | |
290 | .dev = { | |
291 | .platform_data = &herald_gpio_keys_data, | |
292 | }, | |
293 | }; | |
294 | ||
295 | /* LEDs for the Herald. These connect to the HTCPLD GPIO device. */ | |
296 | static struct gpio_led gpio_leds[] = { | |
297 | {"dpad", NULL, HTCPLD_GPIO_LED_DPAD, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
298 | {"kbd", NULL, HTCPLD_GPIO_LED_KBD, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
299 | {"vibrate", NULL, HTCPLD_GPIO_LED_VIBRATE, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
300 | {"green_solid", NULL, HTCPLD_GPIO_LED_GREEN_SOLID, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
301 | {"green_flash", NULL, HTCPLD_GPIO_LED_GREEN_FLASH, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
302 | {"red_solid", "mmc0", HTCPLD_GPIO_LED_RED_SOLID, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
303 | {"red_flash", NULL, HTCPLD_GPIO_LED_RED_FLASH, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
304 | {"wifi", NULL, HTCPLD_GPIO_LED_WIFI, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
305 | {"bt", NULL, HTCPLD_GPIO_LED_BT, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
306 | {"caps", NULL, HTCPLD_GPIO_LED_CAPS, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
307 | {"alt", NULL, HTCPLD_GPIO_LED_ALT, 0, 0, LEDS_GPIO_DEFSTATE_OFF}, | |
308 | }; | |
309 | ||
310 | static struct gpio_led_platform_data gpio_leds_data = { | |
311 | .leds = gpio_leds, | |
312 | .num_leds = ARRAY_SIZE(gpio_leds), | |
313 | }; | |
314 | ||
315 | static struct platform_device gpio_leds_device = { | |
316 | .name = "leds-gpio", | |
317 | .id = 0, | |
318 | .dev = { | |
319 | .platform_data = &gpio_leds_data, | |
320 | }, | |
321 | }; | |
322 | ||
323 | /* HTC PLD chips */ | |
324 | ||
325 | static struct resource htcpld_resources[] = { | |
326 | [0] = { | |
493c32a0 CM |
327 | .flags = IORESOURCE_IRQ, |
328 | }, | |
329 | }; | |
330 | ||
140089da | 331 | static struct htcpld_chip_platform_data htcpld_chips[] = { |
493c32a0 CM |
332 | [0] = { |
333 | .addr = 0x03, | |
334 | .reset = 0x04, | |
335 | .num_gpios = 8, | |
336 | .gpio_out_base = HTCPLD_BASE(0, 0), | |
337 | .gpio_in_base = HTCPLD_BASE(4, 0), | |
338 | }, | |
339 | [1] = { | |
340 | .addr = 0x04, | |
341 | .reset = 0x8e, | |
342 | .num_gpios = 8, | |
343 | .gpio_out_base = HTCPLD_BASE(1, 0), | |
344 | .gpio_in_base = HTCPLD_BASE(5, 0), | |
345 | }, | |
346 | [2] = { | |
347 | .addr = 0x05, | |
348 | .reset = 0x80, | |
349 | .num_gpios = 8, | |
350 | .gpio_out_base = HTCPLD_BASE(2, 0), | |
351 | .gpio_in_base = HTCPLD_BASE(6, 0), | |
352 | .irq_base = HTCPLD_IRQ(0, 0), | |
353 | .num_irqs = 8, | |
354 | }, | |
355 | [3] = { | |
356 | .addr = 0x06, | |
357 | .reset = 0x40, | |
358 | .num_gpios = 8, | |
359 | .gpio_out_base = HTCPLD_BASE(3, 0), | |
360 | .gpio_in_base = HTCPLD_BASE(7, 0), | |
361 | .irq_base = HTCPLD_IRQ(1, 0), | |
362 | .num_irqs = 8, | |
363 | }, | |
364 | }; | |
365 | ||
140089da | 366 | static struct htcpld_core_platform_data htcpld_pfdata = { |
493c32a0 CM |
367 | .int_reset_gpio_hi = HTCPLD_GPIO_INT_RESET_HI, |
368 | .int_reset_gpio_lo = HTCPLD_GPIO_INT_RESET_LO, | |
369 | .i2c_adapter_id = 1, | |
370 | ||
371 | .chip = htcpld_chips, | |
372 | .num_chip = ARRAY_SIZE(htcpld_chips), | |
373 | }; | |
374 | ||
375 | static struct platform_device htcpld_device = { | |
376 | .name = "i2c-htcpld", | |
377 | .id = -1, | |
378 | .resource = htcpld_resources, | |
379 | .num_resources = ARRAY_SIZE(htcpld_resources), | |
380 | .dev = { | |
381 | .platform_data = &htcpld_pfdata, | |
382 | }, | |
383 | }; | |
384 | ||
106997c1 CM |
385 | /* USB Device */ |
386 | static struct omap_usb_config htcherald_usb_config __initdata = { | |
387 | .otg = 0, | |
388 | .register_host = 0, | |
389 | .register_dev = 1, | |
390 | .hmc_mode = 4, | |
391 | .pins[0] = 2, | |
392 | }; | |
393 | ||
9c2816f7 | 394 | /* LCD Device resources */ |
493c32a0 CM |
395 | static struct omap_lcd_config htcherald_lcd_config __initdata = { |
396 | .ctrl_name = "internal", | |
397 | }; | |
398 | ||
9c2816f7 CM |
399 | static struct platform_device lcd_device = { |
400 | .name = "lcd_htcherald", | |
401 | .id = -1, | |
402 | }; | |
403 | ||
493c32a0 CM |
404 | /* MMC Card */ |
405 | #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) | |
406 | static struct omap_mmc_platform_data htc_mmc1_data = { | |
407 | .nr_slots = 1, | |
408 | .switch_slot = NULL, | |
409 | .slots[0] = { | |
2a12400e | 410 | .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, |
493c32a0 CM |
411 | .name = "mmcblk", |
412 | .nomux = 1, | |
413 | .wires = 4, | |
414 | .switch_pin = -1, | |
415 | }, | |
416 | }; | |
417 | ||
418 | static struct omap_mmc_platform_data *htc_mmc_data[1]; | |
419 | #endif | |
420 | ||
421 | ||
422 | /* Platform devices for the Herald */ | |
9c2816f7 CM |
423 | static struct platform_device *devices[] __initdata = { |
424 | &kp_device, | |
425 | &lcd_device, | |
493c32a0 CM |
426 | &htcpld_device, |
427 | &gpio_leds_device, | |
428 | &herald_gpiokeys_device, | |
429 | }; | |
430 | ||
431 | /* | |
432 | * Touchscreen | |
433 | */ | |
434 | static const struct ads7846_platform_data htcherald_ts_platform_data = { | |
435 | .model = 7846, | |
436 | .keep_vref_on = 1, | |
437 | .x_plate_ohms = 496, | |
438 | .gpio_pendown = HTCHERALD_GPIO_TS, | |
16c8a3b0 | 439 | .pressure_max = 10000, |
493c32a0 CM |
440 | .pressure_min = 5000, |
441 | .x_min = 528, | |
442 | .x_max = 3760, | |
443 | .y_min = 624, | |
444 | .y_max = 3760, | |
445 | }; | |
446 | ||
447 | static struct spi_board_info __initdata htcherald_spi_board_info[] = { | |
448 | { | |
449 | .modalias = "ads7846", | |
450 | .platform_data = &htcherald_ts_platform_data, | |
493c32a0 CM |
451 | .max_speed_hz = 2500000, |
452 | .bus_num = 2, | |
453 | .chip_select = 1, | |
454 | } | |
9c2816f7 CM |
455 | }; |
456 | ||
457 | /* | |
458 | * Init functions from here on | |
459 | */ | |
460 | ||
461 | static void __init htcherald_lcd_init(void) | |
462 | { | |
463 | u32 reg; | |
464 | unsigned int tries = 200; | |
465 | ||
466 | /* disable controller if active */ | |
467 | reg = omap_readl(OMAP_LCDC_CONTROL); | |
468 | if (reg & OMAP_LCDC_CTRL_LCD_EN) { | |
469 | reg &= ~OMAP_LCDC_CTRL_LCD_EN; | |
470 | omap_writel(reg, OMAP_LCDC_CONTROL); | |
471 | ||
472 | /* wait for end of frame */ | |
473 | while (!(omap_readl(OMAP_LCDC_STATUS) & OMAP_LCDC_STAT_DONE)) { | |
474 | tries--; | |
475 | if (!tries) | |
476 | break; | |
477 | } | |
478 | if (!tries) | |
479 | printk(KERN_WARNING "Timeout waiting for end of frame " | |
480 | "-- LCD may not be available\n"); | |
481 | ||
482 | /* turn off DMA */ | |
483 | reg = omap_readw(OMAP_DMA_LCD_CCR); | |
484 | reg &= ~(1 << 7); | |
485 | omap_writew(reg, OMAP_DMA_LCD_CCR); | |
486 | ||
487 | reg = omap_readw(OMAP_DMA_LCD_CTRL); | |
488 | reg &= ~(1 << 8); | |
489 | omap_writew(reg, OMAP_DMA_LCD_CTRL); | |
490 | } | |
491 | } | |
492 | ||
493 | static void __init htcherald_map_io(void) | |
494 | { | |
7b88e62f | 495 | omap7xx_map_io(); |
9c2816f7 CM |
496 | |
497 | /* | |
498 | * The LCD panel must be disabled and DMA turned off here, as doing | |
499 | * it later causes the LCD never to reinitialize. | |
500 | */ | |
501 | htcherald_lcd_init(); | |
502 | ||
503 | printk(KERN_INFO "htcherald_map_io done.\n"); | |
504 | } | |
505 | ||
506 | static void __init htcherald_disable_watchdog(void) | |
507 | { | |
508 | /* Disable watchdog if running */ | |
509 | if (omap_readl(OMAP_WDT_TIMER_MODE) & 0x8000) { | |
510 | /* | |
511 | * disable a potentially running watchdog timer before | |
512 | * it kills us. | |
513 | */ | |
514 | printk(KERN_WARNING "OMAP850 Watchdog seems to be activated, disabling it for now.\n"); | |
515 | omap_writel(0xF5, OMAP_WDT_TIMER_MODE); | |
516 | omap_writel(0xA0, OMAP_WDT_TIMER_MODE); | |
517 | } | |
518 | } | |
519 | ||
106997c1 CM |
520 | #define HTCHERALD_GPIO_USB_EN1 33 |
521 | #define HTCHERALD_GPIO_USB_EN2 73 | |
522 | #define HTCHERALD_GPIO_USB_DM 35 | |
523 | #define HTCHERALD_GPIO_USB_DP 36 | |
524 | ||
525 | static void __init htcherald_usb_enable(void) | |
526 | { | |
527 | unsigned int tries = 20; | |
528 | unsigned int value = 0; | |
529 | ||
530 | /* Request the GPIOs we need to control here */ | |
531 | if (gpio_request(HTCHERALD_GPIO_USB_EN1, "herald_usb") < 0) | |
532 | goto err1; | |
533 | ||
534 | if (gpio_request(HTCHERALD_GPIO_USB_EN2, "herald_usb") < 0) | |
535 | goto err2; | |
536 | ||
537 | if (gpio_request(HTCHERALD_GPIO_USB_DM, "herald_usb") < 0) | |
538 | goto err3; | |
539 | ||
540 | if (gpio_request(HTCHERALD_GPIO_USB_DP, "herald_usb") < 0) | |
541 | goto err4; | |
542 | ||
543 | /* force USB_EN GPIO to 0 */ | |
544 | do { | |
545 | /* output low */ | |
546 | gpio_direction_output(HTCHERALD_GPIO_USB_EN1, 0); | |
547 | } while ((value = gpio_get_value(HTCHERALD_GPIO_USB_EN1)) == 1 && | |
548 | --tries); | |
549 | ||
550 | if (value == 1) | |
551 | printk(KERN_WARNING "Unable to reset USB, trying to continue\n"); | |
552 | ||
553 | gpio_direction_output(HTCHERALD_GPIO_USB_EN2, 0); /* output low */ | |
554 | gpio_direction_input(HTCHERALD_GPIO_USB_DM); /* input */ | |
555 | gpio_direction_input(HTCHERALD_GPIO_USB_DP); /* input */ | |
556 | ||
557 | goto done; | |
558 | ||
559 | err4: | |
560 | gpio_free(HTCHERALD_GPIO_USB_DM); | |
561 | err3: | |
562 | gpio_free(HTCHERALD_GPIO_USB_EN2); | |
563 | err2: | |
564 | gpio_free(HTCHERALD_GPIO_USB_EN1); | |
565 | err1: | |
566 | printk(KERN_ERR "Unabled to request GPIO for USB\n"); | |
567 | done: | |
568 | printk(KERN_INFO "USB setup complete.\n"); | |
569 | } | |
570 | ||
9c2816f7 CM |
571 | static void __init htcherald_init(void) |
572 | { | |
573 | printk(KERN_INFO "HTC Herald init.\n"); | |
574 | ||
493c32a0 | 575 | /* Do board initialization before we register all the devices */ |
46a0a540 TKD |
576 | htcpld_resources[0].start = gpio_to_irq(HTCHERALD_GIRQ_BTNS); |
577 | htcpld_resources[0].end = gpio_to_irq(HTCHERALD_GIRQ_BTNS); | |
9c2816f7 CM |
578 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
579 | ||
580 | htcherald_disable_watchdog(); | |
106997c1 CM |
581 | |
582 | htcherald_usb_enable(); | |
dd0cdd88 | 583 | omap1_usb_init(&htcherald_usb_config); |
493c32a0 | 584 | |
46a0a540 | 585 | htcherald_spi_board_info[0].irq = gpio_to_irq(HTCHERALD_GPIO_TS); |
493c32a0 CM |
586 | spi_register_board_info(htcherald_spi_board_info, |
587 | ARRAY_SIZE(htcherald_spi_board_info)); | |
588 | ||
589 | omap_register_i2c_bus(1, 100, NULL, 0); | |
590 | ||
591 | #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) | |
592 | htc_mmc_data[0] = &htc_mmc1_data; | |
593 | omap1_init_mmc(htc_mmc_data, 1); | |
594 | #endif | |
ddba6c7f TV |
595 | |
596 | omapfb_set_lcd_config(&htcherald_lcd_config); | |
9c2816f7 CM |
597 | } |
598 | ||
9c2816f7 CM |
599 | MACHINE_START(HERALD, "HTC Herald") |
600 | /* Maintainer: Cory Maccarrone <darkstar6262@gmail.com> */ | |
601 | /* Maintainer: wing-linux.sourceforge.net */ | |
246e389d | 602 | .atag_offset = 0x100, |
9c2816f7 | 603 | .map_io = htcherald_map_io, |
7b88e62f | 604 | .init_early = omap1_init_early, |
71ee7dad | 605 | .reserve = omap_reserve, |
7b88e62f | 606 | .init_irq = omap1_init_irq, |
9c2816f7 | 607 | .init_machine = htcherald_init, |
82c3bd03 | 608 | .init_late = omap1_init_late, |
e74984e4 | 609 | .timer = &omap1_timer, |
baa95883 | 610 | .restart = omap1_restart, |
9c2816f7 | 611 | MACHINE_END |