board-mop500-stuib.c 4.4 KB

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