gpio_keypad.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2008, Google Inc.
  3. * All rights reserved.
  4. *
  5. * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google, Inc. nor the names of its contributors
  17. * may be used to endorse or promote products derived from this
  18. * software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  30. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. */
  33. #ifndef __DEV_GPIO_KEYPAD_H
  34. #define __DEV_GPIO_KEYPAD_H
  35. #include <sys/types.h>
  36. /* unset: drive active output low, set: drive active output high */
  37. #define GPIOKPF_ACTIVE_HIGH (1U << 0)
  38. #define GPIOKPF_DRIVE_INACTIVE (1U << 1)
  39. struct gpio_keypad_info {
  40. /* size must be ninputs * noutputs */
  41. const uint16_t *keymap;
  42. unsigned *input_gpios;
  43. unsigned *output_gpios;
  44. int ninputs;
  45. int noutputs;
  46. /* time to wait before reading inputs after driving each output */
  47. time_t settle_time;
  48. time_t poll_time;
  49. unsigned flags;
  50. };
  51. void gpio_keypad_init(struct gpio_keypad_info *kpinfo);
  52. // GPIO configurations
  53. #define SSBI_REG_ADDR_GPIO_BASE 0x150
  54. #define QT_PMIC_GPIO_KYPD_SNS 0x008
  55. #define QT_PMIC_GPIO_KYPD_DRV 0x003
  56. #define SSBI_OFFSET_ADDR_GPIO_KYPD_SNS 0x000
  57. #define SSBI_OFFSET_ADDR_GPIO_KYPD_DRV 0x008
  58. #define SSBI_REG_ADDR_GPIO(n) (SSBI_REG_ADDR_GPIO_BASE + n)
  59. #define PM_GPIO_DIR_OUT 0x01
  60. #define PM_GPIO_DIR_IN 0x02
  61. #define PM_GPIO_DIR_BOTH (PM_GPIO_DIR_OUT | PM_GPIO_DIR_IN)
  62. #define PM_GPIO_PULL_UP1 2
  63. #define PM_GPIO_PULL_UP2 3
  64. #define PM_GPIO_PULL_DN 4
  65. #define PM_GPIO_PULL_NO 5
  66. #define PM_GPIO_STRENGTH_NO 0
  67. #define PM_GPIO_STRENGTH_HIGH 1
  68. #define PM_GPIO_STRENGTH_MED 2
  69. #define PM_GPIO_STRENGTH_LOW 3
  70. #define PM_GPIO_FUNC_NORMAL 0
  71. #define PM_GPIO_FUNC_PAIRED 1
  72. #define PM_GPIO_FUNC_1 2
  73. #define PM_GPIO_FUNC_2 3
  74. #define PM8058_GPIO_BANK_MASK 0x70
  75. #define PM8058_GPIO_BANK_SHIFT 4
  76. #define PM8058_GPIO_WRITE 0x80
  77. /* Bank 0 */
  78. #define PM8058_GPIO_VIN_MASK 0x0E
  79. #define PM8058_GPIO_VIN_SHIFT 1
  80. #define PM8058_GPIO_MODE_ENABLE 0x01
  81. /* Bank 1 */
  82. #define PM8058_GPIO_MODE_MASK 0x0C
  83. #define PM8058_GPIO_MODE_SHIFT 2
  84. #define PM8058_GPIO_OUT_BUFFER 0x02
  85. #define PM8058_GPIO_OUT_INVERT 0x01
  86. #define PM8058_GPIO_MODE_OFF 3
  87. #define PM8058_GPIO_MODE_OUTPUT 2
  88. #define PM8058_GPIO_MODE_INPUT 0
  89. #define PM8058_GPIO_MODE_BOTH 1
  90. /* Bank 2 */
  91. #define PM8058_GPIO_PULL_MASK 0x0E
  92. #define PM8058_GPIO_PULL_SHIFT 1
  93. /* Bank 3 */
  94. #define PM8058_GPIO_OUT_STRENGTH_MASK 0x0C
  95. #define PM8058_GPIO_OUT_STRENGTH_SHIFT 2
  96. /* Bank 4 */
  97. #define PM8058_GPIO_FUNC_MASK 0x0E
  98. #define PM8058_GPIO_FUNC_SHIFT 1
  99. struct pm8058_gpio {
  100. int direction;
  101. int pull;
  102. int vin_sel; /* 0..7 */
  103. int out_strength;
  104. int function;
  105. int inv_int_pol; /* invert interrupt polarity */
  106. };
  107. bool pm8058_gpio_get(unsigned int gpio);
  108. typedef int (*read_func)(unsigned char *, unsigned short, unsigned short);
  109. typedef int (*write_func)(unsigned char *, unsigned short, unsigned short);
  110. typedef int (*gpio_get_func)(uint8_t, uint8_t *);
  111. struct qwerty_keypad_info {
  112. unsigned int *keymap;
  113. unsigned int *gpiomap;
  114. unsigned int mapsize;
  115. unsigned char *old_keys;
  116. unsigned char *rec_keys;
  117. unsigned int rows;
  118. unsigned int columns;
  119. unsigned int num_of_reads;
  120. read_func rd_func;
  121. write_func wr_func;
  122. gpio_get_func key_gpio_get;
  123. /* time to wait before reading inputs after driving each output */
  124. time_t settle_time;
  125. time_t poll_time;
  126. unsigned flags;
  127. };
  128. void ssbi_keypad_init (struct qwerty_keypad_info *);
  129. #endif /* __DEV_GPIO_KEYPAD_H */