board-mop500-stuib.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * License terms: GNU General Public License (GPL), version 2
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/init.h>
  8. #include <linux/mfd/stmpe.h>
  9. #include <linux/input/bu21013.h>
  10. #include <linux/gpio.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/i2c.h>
  13. #include <linux/input/matrix_keypad.h>
  14. #include <asm/mach-types.h>
  15. #include "board-mop500.h"
  16. /* STMPE/SKE keypad use this key layout */
  17. static const unsigned int mop500_keymap[] = {
  18. KEY(2, 5, KEY_END),
  19. KEY(4, 1, KEY_POWER),
  20. KEY(3, 5, KEY_VOLUMEDOWN),
  21. KEY(1, 3, KEY_3),
  22. KEY(5, 2, KEY_RIGHT),
  23. KEY(5, 0, KEY_9),
  24. KEY(0, 5, KEY_MENU),
  25. KEY(7, 6, KEY_ENTER),
  26. KEY(4, 5, KEY_0),
  27. KEY(6, 7, KEY_2),
  28. KEY(3, 4, KEY_UP),
  29. KEY(3, 3, KEY_DOWN),
  30. KEY(6, 4, KEY_SEND),
  31. KEY(6, 2, KEY_BACK),
  32. KEY(4, 2, KEY_VOLUMEUP),
  33. KEY(5, 5, KEY_1),
  34. KEY(4, 3, KEY_LEFT),
  35. KEY(3, 2, KEY_7),
  36. };
  37. static const struct matrix_keymap_data mop500_keymap_data = {
  38. .keymap = mop500_keymap,
  39. .keymap_size = ARRAY_SIZE(mop500_keymap),
  40. };
  41. /*
  42. * STMPE1601
  43. */
  44. static struct stmpe_keypad_platform_data stmpe1601_keypad_data = {
  45. .debounce_ms = 64,
  46. .scan_count = 8,
  47. .no_autorepeat = true,
  48. .keymap_data = &mop500_keymap_data,
  49. };
  50. static struct stmpe_platform_data stmpe1601_data = {
  51. .id = 1,
  52. .blocks = STMPE_BLOCK_KEYPAD,
  53. .irq_trigger = IRQF_TRIGGER_FALLING,
  54. .irq_base = MOP500_STMPE1601_IRQ(0),
  55. .keypad = &stmpe1601_keypad_data,
  56. .autosleep = true,
  57. .autosleep_timeout = 1024,
  58. };
  59. static struct i2c_board_info __initdata mop500_i2c0_devices_stuib[] = {
  60. {
  61. I2C_BOARD_INFO("stmpe1601", 0x40),
  62. .irq = NOMADIK_GPIO_TO_IRQ(218),
  63. .platform_data = &stmpe1601_data,
  64. .flags = I2C_CLIENT_WAKE,
  65. },
  66. };
  67. /*
  68. * BU21013 ROHM touchscreen interface on the STUIBs
  69. */
  70. /* tracks number of bu21013 devices being enabled */
  71. static int bu21013_devices;
  72. #define TOUCH_GPIO_PIN 84
  73. #define TOUCH_XMAX 384
  74. #define TOUCH_YMAX 704
  75. #define PRCMU_CLOCK_OCR 0x1CC
  76. #define TSC_EXT_CLOCK_9_6MHZ 0x840000
  77. /**
  78. * bu21013_gpio_board_init : configures the touch panel.
  79. * @reset_pin: reset pin number
  80. * This function can be used to configures
  81. * the voltage and reset the touch panel controller.
  82. */
  83. static int bu21013_gpio_board_init(int reset_pin)
  84. {
  85. int retval = 0;
  86. bu21013_devices++;
  87. if (bu21013_devices == 1) {
  88. retval = gpio_request(reset_pin, "touchp_reset");
  89. if (retval) {
  90. printk(KERN_ERR "Unable to request gpio reset_pin");
  91. return retval;
  92. }
  93. retval = gpio_direction_output(reset_pin, 1);
  94. if (retval < 0) {
  95. printk(KERN_ERR "%s: gpio direction failed\n",
  96. __func__);
  97. return retval;
  98. }
  99. }
  100. return retval;
  101. }
  102. /**
  103. * bu21013_gpio_board_exit : deconfigures the touch panel controller
  104. * @reset_pin: reset pin number
  105. * This function can be used to deconfigures the chip selection
  106. * for touch panel controller.
  107. */
  108. static int bu21013_gpio_board_exit(int reset_pin)
  109. {
  110. int retval = 0;
  111. if (bu21013_devices == 1) {
  112. retval = gpio_direction_output(reset_pin, 0);
  113. if (retval < 0) {
  114. printk(KERN_ERR "%s: gpio direction failed\n",
  115. __func__);
  116. return retval;
  117. }
  118. gpio_set_value(reset_pin, 0);
  119. }
  120. bu21013_devices--;
  121. return retval;
  122. }
  123. /**
  124. * bu21013_read_pin_val : get the interrupt pin value
  125. * This function can be used to get the interrupt pin value for touch panel
  126. * controller.
  127. */
  128. static int bu21013_read_pin_val(void)
  129. {
  130. return gpio_get_value(TOUCH_GPIO_PIN);
  131. }
  132. static struct bu21013_platform_device tsc_plat_device = {
  133. .cs_en = bu21013_gpio_board_init,
  134. .cs_dis = bu21013_gpio_board_exit,
  135. .irq_read_val = bu21013_read_pin_val,
  136. .irq = NOMADIK_GPIO_TO_IRQ(TOUCH_GPIO_PIN),
  137. .touch_x_max = TOUCH_XMAX,
  138. .touch_y_max = TOUCH_YMAX,
  139. .ext_clk = false,
  140. .x_flip = false,
  141. .y_flip = true,
  142. };
  143. static struct bu21013_platform_device tsc_plat2_device = {
  144. .cs_en = bu21013_gpio_board_init,
  145. .cs_dis = bu21013_gpio_board_exit,
  146. .irq_read_val = bu21013_read_pin_val,
  147. .irq = NOMADIK_GPIO_TO_IRQ(TOUCH_GPIO_PIN),
  148. .touch_x_max = TOUCH_XMAX,
  149. .touch_y_max = TOUCH_YMAX,
  150. .ext_clk = false,
  151. .x_flip = false,
  152. .y_flip = true,
  153. };
  154. static struct i2c_board_info __initdata u8500_i2c3_devices_stuib[] = {
  155. {
  156. I2C_BOARD_INFO("bu21013_tp", 0x5C),
  157. .platform_data = &tsc_plat_device,
  158. },
  159. {
  160. I2C_BOARD_INFO("bu21013_tp", 0x5D),
  161. .platform_data = &tsc_plat2_device,
  162. },
  163. };
  164. void __init mop500_stuib_init(void)
  165. {
  166. if (machine_is_hrefv60()) {
  167. tsc_plat_device.cs_pin = HREFV60_TOUCH_RST_GPIO;
  168. tsc_plat2_device.cs_pin = HREFV60_TOUCH_RST_GPIO;
  169. } else {
  170. tsc_plat_device.cs_pin = GPIO_BU21013_CS;
  171. tsc_plat2_device.cs_pin = GPIO_BU21013_CS;
  172. }
  173. mop500_uib_i2c_add(0, mop500_i2c0_devices_stuib,
  174. ARRAY_SIZE(mop500_i2c0_devices_stuib));
  175. mop500_uib_i2c_add(3, u8500_i2c3_devices_stuib,
  176. ARRAY_SIZE(u8500_i2c3_devices_stuib));
  177. }