mtk_key.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <target/cust_key.h>
  11. extern int pmic_detect_powerkey(void);
  12. extern int pmic_detect_homekey(void);
  13. extern kal_uint16 pmic_get_register_value(PMU_FLAGS_LIST_ENUM flagname);
  14. extern kal_uint16 pmic_set_register_value(PMU_FLAGS_LIST_ENUM flagname,kal_uint32 val);
  15. void set_kpd_pmic_mode(void)
  16. {
  17. return;
  18. }
  19. void disable_PMIC_kpd_clock(void)
  20. {
  21. return;
  22. }
  23. void enable_PMIC_kpd_clock(void)
  24. {
  25. return;
  26. }
  27. BOOL mtk_detect_key(unsigned short key) /* key: HW keycode */
  28. {
  29. #ifdef MACH_FPGA
  30. return FALSE;
  31. #else
  32. //dprintf(ALWAYS, "mtk detect key function key = %d\n", key);
  33. unsigned short idx, bit, din;
  34. if (key >= KPD_NUM_KEYS)
  35. return FALSE;
  36. #if 0
  37. if (key % 9 == 8)
  38. key = 8;
  39. #endif
  40. if (key == MTK_PMIC_PWR_KEY) {
  41. /* Power key */
  42. if (1 == pmic_detect_powerkey()) {
  43. dprintf(ALWAYS, "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. //dprintf(INFO, "mtk detect key function pmic_detect_homekey MTK_PMIC_RST_KEY = %d\n", MTK_PMIC_RST_KEY);
  51. if (1 == pmic_detect_homekey()) {
  52. dprintf(ALWAYS, "mtk detect key function pmic_detect_homekey pressed\n");
  53. return TRUE;
  54. }
  55. return FALSE;
  56. }
  57. #endif
  58. idx = key / 16;
  59. bit = key % 16;
  60. din = DRV_Reg16(KP_MEM1 + (idx << 2)) & (1U << bit);
  61. if (!din) {
  62. dprintf(ALWAYS, "key %d is pressed\n", key);
  63. return TRUE;
  64. }
  65. return FALSE;
  66. #endif
  67. }
  68. BOOL mtk_detect_pmic_just_rst(void)
  69. {
  70. kal_uint32 just_rst = 0;
  71. dprintf(ALWAYS, "detecting pmic just reset\n");
  72. just_rst = pmic_get_register_value(PMIC_JUST_PWRKEY_RST);
  73. if (just_rst) {
  74. dprintf(ALWAYS, "Just recover from a reset\n");
  75. pmic_set_register_value(PMIC_CLR_JUST_RST, 0x01);
  76. return TRUE;
  77. }
  78. return FALSE;
  79. }