board-sapphire-keypad.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* arch/arm/mach-msm/board-sapphire-keypad.c
  2. * Copyright (C) 2007-2009 HTC Corporation.
  3. * Author: Thomas Tsai <thomas_tsai@htc.com>
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/platform_device.h>
  15. #include <linux/input.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/gpio_event.h>
  18. #include <asm/mach-types.h>
  19. #include "gpio_chip.h"
  20. #include "board-sapphire.h"
  21. static char *keycaps = "--qwerty";
  22. #undef MODULE_PARAM_PREFIX
  23. #define MODULE_PARAM_PREFIX "board_sapphire."
  24. module_param_named(keycaps, keycaps, charp, 0);
  25. static unsigned int sapphire_col_gpios[] = { 35, 34 };
  26. /* KP_MKIN2 (GPIO40) is not used? */
  27. static unsigned int sapphire_row_gpios[] = { 42, 41 };
  28. #define KEYMAP_INDEX(col, row) ((col)*ARRAY_SIZE(sapphire_row_gpios) + (row))
  29. /*scan matrix key*/
  30. /* HOME(up) MENU (up) Back Search */
  31. static const unsigned short sapphire_keymap2[ARRAY_SIZE(sapphire_col_gpios) * ARRAY_SIZE(sapphire_row_gpios)] = {
  32. [KEYMAP_INDEX(0, 0)] = KEY_COMPOSE,
  33. [KEYMAP_INDEX(0, 1)] = KEY_BACK,
  34. [KEYMAP_INDEX(1, 0)] = KEY_MENU,
  35. [KEYMAP_INDEX(1, 1)] = KEY_SEND,
  36. };
  37. /* HOME(up) + MENU (down)*/
  38. static const unsigned short sapphire_keymap1[ARRAY_SIZE(sapphire_col_gpios) *
  39. ARRAY_SIZE(sapphire_row_gpios)] = {
  40. [KEYMAP_INDEX(0, 0)] = KEY_BACK,
  41. [KEYMAP_INDEX(0, 1)] = KEY_MENU,
  42. [KEYMAP_INDEX(1, 0)] = KEY_HOME,
  43. [KEYMAP_INDEX(1, 1)] = KEY_SEND,
  44. };
  45. /* MENU(up) + HOME (down)*/
  46. static const unsigned short sapphire_keymap0[ARRAY_SIZE(sapphire_col_gpios) *
  47. ARRAY_SIZE(sapphire_row_gpios)] = {
  48. [KEYMAP_INDEX(0, 0)] = KEY_BACK,
  49. [KEYMAP_INDEX(0, 1)] = KEY_HOME,
  50. [KEYMAP_INDEX(1, 0)] = KEY_MENU,
  51. [KEYMAP_INDEX(1, 1)] = KEY_SEND,
  52. };
  53. static struct gpio_event_matrix_info sapphire_keypad_matrix_info = {
  54. .info.func = gpio_event_matrix_func,
  55. .keymap = sapphire_keymap2,
  56. .output_gpios = sapphire_col_gpios,
  57. .input_gpios = sapphire_row_gpios,
  58. .noutputs = ARRAY_SIZE(sapphire_col_gpios),
  59. .ninputs = ARRAY_SIZE(sapphire_row_gpios),
  60. .settle_time.tv.nsec = 40 * NSEC_PER_USEC,
  61. .poll_time.tv.nsec = 20 * NSEC_PER_MSEC,
  62. .debounce_delay.tv.nsec = 50 * NSEC_PER_MSEC,
  63. .flags = GPIOKPF_LEVEL_TRIGGERED_IRQ |
  64. GPIOKPF_REMOVE_PHANTOM_KEYS |
  65. GPIOKPF_PRINT_UNMAPPED_KEYS /*| GPIOKPF_PRINT_MAPPED_KEYS*/
  66. };
  67. static struct gpio_event_direct_entry sapphire_keypad_nav_map[] = {
  68. { SAPPHIRE_POWER_KEY, KEY_END },
  69. { SAPPHIRE_VOLUME_UP, KEY_VOLUMEUP },
  70. { SAPPHIRE_VOLUME_DOWN, KEY_VOLUMEDOWN },
  71. };
  72. static struct gpio_event_input_info sapphire_keypad_nav_info = {
  73. .info.func = gpio_event_input_func,
  74. .flags = 0,
  75. .type = EV_KEY,
  76. .keymap = sapphire_keypad_nav_map,
  77. .debounce_time.tv.nsec = 20 * NSEC_PER_MSEC,
  78. .keymap_size = ARRAY_SIZE(sapphire_keypad_nav_map)
  79. };
  80. static struct gpio_event_info *sapphire_keypad_info[] = {
  81. &sapphire_keypad_matrix_info.info,
  82. &sapphire_keypad_nav_info.info,
  83. };
  84. static struct gpio_event_platform_data sapphire_keypad_data = {
  85. .name = "sapphire-keypad",
  86. .info = sapphire_keypad_info,
  87. .info_count = ARRAY_SIZE(sapphire_keypad_info)
  88. };
  89. static struct platform_device sapphire_keypad_device = {
  90. .name = GPIO_EVENT_DEV_NAME,
  91. .id = 0,
  92. .dev = {
  93. .platform_data = &sapphire_keypad_data,
  94. },
  95. };
  96. static int __init sapphire_init_keypad(void)
  97. {
  98. if (!machine_is_sapphire())
  99. return 0;
  100. switch (sapphire_get_hwid()) {
  101. case 0:
  102. sapphire_keypad_matrix_info.keymap = sapphire_keymap0;
  103. break;
  104. default:
  105. if(system_rev != 0x80)
  106. sapphire_keypad_matrix_info.keymap = sapphire_keymap1;
  107. break;
  108. }
  109. return platform_device_register(&sapphire_keypad_device);
  110. }
  111. device_initcall(sapphire_init_keypad);