board-htcherald.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/input.h>
  30. #include <linux/io.h>
  31. #include <linux/gpio.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <plat/omap7xx.h>
  35. #include <plat/common.h>
  36. #include <plat/board.h>
  37. #include <plat/keypad.h>
  38. #include <plat/usb.h>
  39. #include <mach/irqs.h>
  40. #include <linux/delay.h>
  41. /* LCD register definition */
  42. #define OMAP_LCDC_CONTROL (0xfffec000 + 0x00)
  43. #define OMAP_LCDC_STATUS (0xfffec000 + 0x10)
  44. #define OMAP_DMA_LCD_CCR (0xfffee300 + 0xc2)
  45. #define OMAP_DMA_LCD_CTRL (0xfffee300 + 0xc4)
  46. #define OMAP_LCDC_CTRL_LCD_EN (1 << 0)
  47. #define OMAP_LCDC_STAT_DONE (1 << 0)
  48. static struct omap_lcd_config htcherald_lcd_config __initdata = {
  49. .ctrl_name = "internal",
  50. };
  51. static struct omap_board_config_kernel htcherald_config[] __initdata = {
  52. { OMAP_TAG_LCD, &htcherald_lcd_config },
  53. };
  54. /* Keyboard definition */
  55. static int htc_herald_keymap[] = {
  56. KEY(0, 0, KEY_RECORD), /* Mail button */
  57. KEY(0, 1, KEY_CAMERA), /* Camera */
  58. KEY(0, 2, KEY_PHONE), /* Send key */
  59. KEY(0, 3, KEY_VOLUMEUP), /* Volume up */
  60. KEY(0, 4, KEY_F2), /* Right bar (landscape) */
  61. KEY(0, 5, KEY_MAIL), /* Win key (portrait) */
  62. KEY(0, 6, KEY_DIRECTORY), /* Right bar (protrait) */
  63. KEY(1, 0, KEY_LEFTCTRL), /* Windows key */
  64. KEY(1, 1, KEY_COMMA),
  65. KEY(1, 2, KEY_M),
  66. KEY(1, 3, KEY_K),
  67. KEY(1, 4, KEY_SLASH), /* OK key */
  68. KEY(1, 5, KEY_I),
  69. KEY(1, 6, KEY_U),
  70. KEY(2, 0, KEY_LEFTALT),
  71. KEY(2, 1, KEY_TAB),
  72. KEY(2, 2, KEY_N),
  73. KEY(2, 3, KEY_J),
  74. KEY(2, 4, KEY_ENTER),
  75. KEY(2, 5, KEY_H),
  76. KEY(2, 6, KEY_Y),
  77. KEY(3, 0, KEY_SPACE),
  78. KEY(3, 1, KEY_L),
  79. KEY(3, 2, KEY_B),
  80. KEY(3, 3, KEY_V),
  81. KEY(3, 4, KEY_BACKSPACE),
  82. KEY(3, 5, KEY_G),
  83. KEY(3, 6, KEY_T),
  84. KEY(4, 0, KEY_CAPSLOCK), /* Shift */
  85. KEY(4, 1, KEY_C),
  86. KEY(4, 2, KEY_F),
  87. KEY(4, 3, KEY_R),
  88. KEY(4, 4, KEY_O),
  89. KEY(4, 5, KEY_E),
  90. KEY(4, 6, KEY_D),
  91. KEY(5, 0, KEY_X),
  92. KEY(5, 1, KEY_Z),
  93. KEY(5, 2, KEY_S),
  94. KEY(5, 3, KEY_W),
  95. KEY(5, 4, KEY_P),
  96. KEY(5, 5, KEY_Q),
  97. KEY(5, 6, KEY_A),
  98. KEY(6, 0, KEY_CONNECT), /* Voice button */
  99. KEY(6, 2, KEY_CANCEL), /* End key */
  100. KEY(6, 3, KEY_VOLUMEDOWN), /* Volume down */
  101. KEY(6, 4, KEY_F1), /* Left bar (landscape) */
  102. KEY(6, 5, KEY_WWW), /* OK button (portrait) */
  103. KEY(6, 6, KEY_CALENDAR), /* Left bar (portrait) */
  104. 0
  105. };
  106. struct omap_kp_platform_data htcherald_kp_data = {
  107. .rows = 7,
  108. .cols = 7,
  109. .delay = 20,
  110. .rep = 1,
  111. .keymap = htc_herald_keymap,
  112. };
  113. static struct resource kp_resources[] = {
  114. [0] = {
  115. .start = INT_7XX_MPUIO_KEYPAD,
  116. .end = INT_7XX_MPUIO_KEYPAD,
  117. .flags = IORESOURCE_IRQ,
  118. },
  119. };
  120. static struct platform_device kp_device = {
  121. .name = "omap-keypad",
  122. .id = -1,
  123. .dev = {
  124. .platform_data = &htcherald_kp_data,
  125. },
  126. .num_resources = ARRAY_SIZE(kp_resources),
  127. .resource = kp_resources,
  128. };
  129. /* USB Device */
  130. static struct omap_usb_config htcherald_usb_config __initdata = {
  131. .otg = 0,
  132. .register_host = 0,
  133. .register_dev = 1,
  134. .hmc_mode = 4,
  135. .pins[0] = 2,
  136. };
  137. /* LCD Device resources */
  138. static struct platform_device lcd_device = {
  139. .name = "lcd_htcherald",
  140. .id = -1,
  141. };
  142. static struct platform_device *devices[] __initdata = {
  143. &kp_device,
  144. &lcd_device,
  145. };
  146. /*
  147. * Init functions from here on
  148. */
  149. static void __init htcherald_lcd_init(void)
  150. {
  151. u32 reg;
  152. unsigned int tries = 200;
  153. /* disable controller if active */
  154. reg = omap_readl(OMAP_LCDC_CONTROL);
  155. if (reg & OMAP_LCDC_CTRL_LCD_EN) {
  156. reg &= ~OMAP_LCDC_CTRL_LCD_EN;
  157. omap_writel(reg, OMAP_LCDC_CONTROL);
  158. /* wait for end of frame */
  159. while (!(omap_readl(OMAP_LCDC_STATUS) & OMAP_LCDC_STAT_DONE)) {
  160. tries--;
  161. if (!tries)
  162. break;
  163. }
  164. if (!tries)
  165. printk(KERN_WARNING "Timeout waiting for end of frame "
  166. "-- LCD may not be available\n");
  167. /* turn off DMA */
  168. reg = omap_readw(OMAP_DMA_LCD_CCR);
  169. reg &= ~(1 << 7);
  170. omap_writew(reg, OMAP_DMA_LCD_CCR);
  171. reg = omap_readw(OMAP_DMA_LCD_CTRL);
  172. reg &= ~(1 << 8);
  173. omap_writew(reg, OMAP_DMA_LCD_CTRL);
  174. }
  175. }
  176. static void __init htcherald_map_io(void)
  177. {
  178. omap1_map_common_io();
  179. /*
  180. * The LCD panel must be disabled and DMA turned off here, as doing
  181. * it later causes the LCD never to reinitialize.
  182. */
  183. htcherald_lcd_init();
  184. printk(KERN_INFO "htcherald_map_io done.\n");
  185. }
  186. static void __init htcherald_disable_watchdog(void)
  187. {
  188. /* Disable watchdog if running */
  189. if (omap_readl(OMAP_WDT_TIMER_MODE) & 0x8000) {
  190. /*
  191. * disable a potentially running watchdog timer before
  192. * it kills us.
  193. */
  194. printk(KERN_WARNING "OMAP850 Watchdog seems to be activated, disabling it for now.\n");
  195. omap_writel(0xF5, OMAP_WDT_TIMER_MODE);
  196. omap_writel(0xA0, OMAP_WDT_TIMER_MODE);
  197. }
  198. }
  199. #define HTCHERALD_GPIO_USB_EN1 33
  200. #define HTCHERALD_GPIO_USB_EN2 73
  201. #define HTCHERALD_GPIO_USB_DM 35
  202. #define HTCHERALD_GPIO_USB_DP 36
  203. static void __init htcherald_usb_enable(void)
  204. {
  205. unsigned int tries = 20;
  206. unsigned int value = 0;
  207. /* Request the GPIOs we need to control here */
  208. if (gpio_request(HTCHERALD_GPIO_USB_EN1, "herald_usb") < 0)
  209. goto err1;
  210. if (gpio_request(HTCHERALD_GPIO_USB_EN2, "herald_usb") < 0)
  211. goto err2;
  212. if (gpio_request(HTCHERALD_GPIO_USB_DM, "herald_usb") < 0)
  213. goto err3;
  214. if (gpio_request(HTCHERALD_GPIO_USB_DP, "herald_usb") < 0)
  215. goto err4;
  216. /* force USB_EN GPIO to 0 */
  217. do {
  218. /* output low */
  219. gpio_direction_output(HTCHERALD_GPIO_USB_EN1, 0);
  220. } while ((value = gpio_get_value(HTCHERALD_GPIO_USB_EN1)) == 1 &&
  221. --tries);
  222. if (value == 1)
  223. printk(KERN_WARNING "Unable to reset USB, trying to continue\n");
  224. gpio_direction_output(HTCHERALD_GPIO_USB_EN2, 0); /* output low */
  225. gpio_direction_input(HTCHERALD_GPIO_USB_DM); /* input */
  226. gpio_direction_input(HTCHERALD_GPIO_USB_DP); /* input */
  227. goto done;
  228. err4:
  229. gpio_free(HTCHERALD_GPIO_USB_DM);
  230. err3:
  231. gpio_free(HTCHERALD_GPIO_USB_EN2);
  232. err2:
  233. gpio_free(HTCHERALD_GPIO_USB_EN1);
  234. err1:
  235. printk(KERN_ERR "Unabled to request GPIO for USB\n");
  236. done:
  237. printk(KERN_INFO "USB setup complete.\n");
  238. }
  239. static void __init htcherald_init(void)
  240. {
  241. printk(KERN_INFO "HTC Herald init.\n");
  242. omap_gpio_init();
  243. omap_board_config = htcherald_config;
  244. omap_board_config_size = ARRAY_SIZE(htcherald_config);
  245. platform_add_devices(devices, ARRAY_SIZE(devices));
  246. htcherald_disable_watchdog();
  247. htcherald_usb_enable();
  248. omap1_usb_init(&htcherald_usb_config);
  249. }
  250. static void __init htcherald_init_irq(void)
  251. {
  252. printk(KERN_INFO "htcherald_init_irq.\n");
  253. omap1_init_common_hw();
  254. omap_init_irq();
  255. }
  256. MACHINE_START(HERALD, "HTC Herald")
  257. /* Maintainer: Cory Maccarrone <darkstar6262@gmail.com> */
  258. /* Maintainer: wing-linux.sourceforge.net */
  259. .phys_io = 0xfff00000,
  260. .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
  261. .boot_params = 0x10000100,
  262. .map_io = htcherald_map_io,
  263. .reserve = omap_reserve,
  264. .init_irq = htcherald_init_irq,
  265. .init_machine = htcherald_init,
  266. .timer = &omap_timer,
  267. MACHINE_END