board-htcherald.c 16 KB

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