mtk_key.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <printf.h>
  2. #include <platform/mt_typedefs.h>
  3. #include <platform/mtk_key.h>
  4. #include <platform/boot_mode.h>
  5. #include <platform/mt_pmic.h>
  6. #include <platform/mt_gpio.h>
  7. #include <platform/mt_pmic_wrap_init.h>
  8. #include <platform/sync_write.h>
  9. #include <platform/upmu_common.h>
  10. #include <platform/upmu_hw.h>
  11. #include <target/cust_key.h>
  12. extern int pmic_detect_powerkey(void);
  13. extern int pmic_detect_homekey(void);
  14. void set_kpd_pmic_mode(void)
  15. {
  16. return;
  17. }
  18. void disable_PMIC_kpd_clock(void)
  19. {
  20. return;
  21. }
  22. void enable_PMIC_kpd_clock(void)
  23. {
  24. return;
  25. }
  26. BOOL mtk_detect_key(unsigned short key) /* key: HW keycode */
  27. {
  28. #ifdef MACH_FPGA
  29. return FALSE;
  30. #else
  31. dprintf(ALWAYS, "mtk detect key function key = %d\n", key);
  32. unsigned short idx, bit, din;
  33. if (key >= KPD_NUM_KEYS)
  34. return FALSE;
  35. #if 0
  36. if (key % 9 == 8)
  37. key = 8;
  38. #endif
  39. if (key == MTK_PMIC_PWR_KEY)
  40. { /* Power key */
  41. if (1 == pmic_detect_powerkey())
  42. {
  43. //dbg_print ("power key is pressed\n");
  44. return TRUE;
  45. }
  46. return FALSE;
  47. }
  48. #ifdef MTK_PMIC_RST_KEY
  49. if (key == MTK_PMIC_RST_KEY)
  50. {
  51. dprintf(INFO, "mtk detect key function pmic_detect_homekey MTK_PMIC_RST_KEY = %d\n", MTK_PMIC_RST_KEY);
  52. if (1 == pmic_detect_homekey())
  53. {
  54. dprintf(ALWAYS, "mtk detect key function pmic_detect_homekey pressed\n");
  55. return TRUE;
  56. }
  57. return FALSE;
  58. }
  59. #endif
  60. idx = key / 16;
  61. bit = key % 16;
  62. din = DRV_Reg16(KP_MEM1 + (idx << 2)) & (1U << bit);
  63. if (!din) {
  64. dprintf(ALWAYS, "key %d is pressed\n", key);
  65. return TRUE;
  66. }
  67. return FALSE;
  68. #endif
  69. }
  70. BOOL mtk_detect_pmic_just_rst(void)
  71. {
  72. kal_uint32 just_rst = 0;
  73. dprintf(ALWAYS, "detecting pmic just reset\n");
  74. just_rst=pmic_get_register_value(PMIC_JUST_PWRKEY_RST);
  75. if (just_rst)
  76. {
  77. dprintf(ALWAYS, "Just recover from a reset\n");
  78. pmic_set_register_value(PMIC_CLR_JUST_RST, 0x01);
  79. return TRUE;
  80. }
  81. return FALSE;
  82. }