mtk_key.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2012 MediaTek Inc.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in
  11. * the documentation and/or other materials provided with the
  12. * distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  17. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  18. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  20. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  21. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  22. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  24. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #include <printf.h>
  28. #include <platform/mt_typedefs.h>
  29. #include <platform/mtk_key.h>
  30. #include <platform/boot_mode.h>
  31. #include <platform/mt_pmic.h>
  32. #include <platform/mt_gpio.h>
  33. #include <platform/mt_pmic_wrap_init.h>
  34. #include <platform/sync_write.h>
  35. #include <platform/upmu_common.h>
  36. #include <target/cust_key.h>
  37. extern int pmic_detect_powerkey(void);
  38. extern int pmic_detect_homekey(void);
  39. extern kal_uint16 pmic_get_register_value(PMU_FLAGS_LIST_ENUM flagname);
  40. extern kal_uint16 pmic_set_register_value(PMU_FLAGS_LIST_ENUM flagname,kal_uint32 val);
  41. void set_kpd_pmic_mode(void)
  42. {
  43. return;
  44. }
  45. void disable_PMIC_kpd_clock(void)
  46. {
  47. return;
  48. }
  49. void enable_PMIC_kpd_clock(void)
  50. {
  51. return;
  52. }
  53. BOOL mtk_detect_key(unsigned short key) /* key: HW keycode */
  54. {
  55. #ifdef MACH_FPGA
  56. return FALSE;
  57. #else
  58. dprintf(ALWAYS, "mtk detect key function key = %d\n", key);
  59. unsigned short idx, bit, din;
  60. if (key >= KPD_NUM_KEYS)
  61. return FALSE;
  62. #if 0
  63. if (key % 9 == 8)
  64. key = 8;
  65. #endif
  66. if (key == MTK_PMIC_PWR_KEY) {
  67. /* Power key */
  68. if (1 == pmic_detect_powerkey()) {
  69. //dbg_print ("power key is pressed\n");
  70. return TRUE;
  71. }
  72. return FALSE;
  73. }
  74. #ifdef MTK_PMIC_RST_KEY
  75. if (key == MTK_PMIC_RST_KEY) {
  76. dprintf(INFO, "mtk detect key function pmic_detect_homekey MTK_PMIC_RST_KEY = %d\n", MTK_PMIC_RST_KEY);
  77. if (1 == pmic_detect_homekey()) {
  78. dprintf(ALWAYS, "mtk detect key function pmic_detect_homekey pressed\n");
  79. return TRUE;
  80. }
  81. return FALSE;
  82. }
  83. #endif
  84. idx = key / 16;
  85. bit = key % 16;
  86. din = DRV_Reg16(KP_MEM1 + (idx << 2)) & (1U << bit);
  87. if (!din) {
  88. dprintf(ALWAYS, "key %d is pressed\n", key);
  89. return TRUE;
  90. }
  91. return FALSE;
  92. #endif
  93. }
  94. #if defined(PMIC_CHIP_MT6355) /*--for MT6757P (MT6355)--*/
  95. #define KPD_PMIC_JUST_PWRKEY_RST PMIC_JUST_PWRKEY_RST
  96. #define KPD_PMIC_CLR_JUST_RST PMIC_CLR_JUST_RST
  97. #else /*--for MT6757 (MT6351)--*/
  98. #define KPD_PMIC_JUST_PWRKEY_RST MT6351_PMIC_JUST_PWRKEY_RST
  99. #define KPD_PMIC_CLR_JUST_RST MT6351_PMIC_CLR_JUST_RST
  100. #endif
  101. BOOL mtk_detect_pmic_just_rst(void)
  102. {
  103. kal_uint32 just_rst = 0;
  104. dprintf(ALWAYS, "detecting pmic just reset\n");
  105. just_rst = pmic_get_register_value(KPD_PMIC_JUST_PWRKEY_RST);
  106. if (just_rst) {
  107. dprintf(ALWAYS, "Just recover from a reset\n");
  108. pmic_set_register_value(KPD_PMIC_CLR_JUST_RST, 0x01);
  109. return TRUE;
  110. }
  111. return FALSE;
  112. }